1 /* FOREGEJ - FOrmatting REfactoring GEnerating Java
2 *
3 * Copyright (C) 2003 Andreas Arrgard
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 package com.octagroup.foregej.ant;
20 import org.apache.regexp.RESyntaxException;
21 import org.apache.tools.ant.BuildException;
22 import com.octagroup.foregej.java.tools.copyright.CopyrightTool;
23 /***
24 * A task that changes some copyrights in files.
25 */
26 public class CopyrightTask extends ToolTask
27 {
28 /***
29 * Structure used to enable xml node in ant configuration file.
30 */
31 public class Copyright
32 {
33 public String copyright_;
34 public String packageRe_;
35 public String removeRe_;
36 public void addText(String copyright)
37 {
38 copyright_=copyright;
39 }
40 public void setPackage(String packageRe)
41 {
42 packageRe_=packageRe;
43 }
44 public void setRemove(String removeRe)
45 {
46 removeRe_=removeRe;
47 }
48 }
49
50 /***
51 * This is the last copyright definition..
52 */
53 private Copyright copyright_;
54 /***
55 * Used by ANT to create a nested copyright holder.
56 *
57 * @return the copyright holder.
58 */
59 public Copyright createCopyright()
60 {
61 if(copyright_!=null) {
62 addCopyright(copyright_);
63 }
64 copyright_=new Copyright();
65 return copyright_;
66 }
67 /***
68 * Adds a new copyright container.
69 *
70 * @param copyright
71 */
72 public void addCopyright(Copyright copyright)
73 {
74 try{
75 CopyrightTool.addCopyright(copyright.packageRe_,
76 copyright.copyright_,
77 copyright.removeRe_);
78 }catch (RESyntaxException e) {
79 throw new BuildException("CopyrightTask: Failed to add copyright:",
80 e);
81 }
82 }
83 /***
84 * Performs the work
85 */
86 public void execute()
87 {
88 if(copyright_==null) {
89 throw new BuildException("CopyrightTask: No copyright specified...");
90 }
91 addCopyright(copyright_);
92 super.execute();
93 }
94 }
This page was automatically generated by Maven