KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > classycle > ant > ClassycleTask


1 /*
2  * Copyright (c) 2003-2006, Franz-Josef Elmer, All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
15  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */

25 package classycle.ant;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.LinkedList JavaDoc;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.DirectoryScanner;
33 import org.apache.tools.ant.Task;
34 import org.apache.tools.ant.types.FileSet;
35
36 import classycle.util.AndStringPattern;
37 import classycle.util.NotStringPattern;
38 import classycle.util.StringPattern;
39 import classycle.util.TrueStringPattern;
40 import classycle.util.WildCardPattern;
41
42 /**
43  * Common attributes of all Classyle Ant tasks.
44  *
45  * @author Franz-Josef Elmer
46  */

47 public abstract class ClassycleTask extends Task
48 {
49   private boolean _mergeInnerClasses;
50   private StringPattern _includingClasses = new TrueStringPattern();
51   private StringPattern _excludingClasses = new TrueStringPattern();
52   private StringPattern _reflectionPattern;
53   private LinkedList JavaDoc _fileSets = new LinkedList JavaDoc();
54
55   public void setMergeInnerClasses(boolean mergeInnerClasses)
56   {
57     _mergeInnerClasses = mergeInnerClasses;
58   }
59   
60   public void setIncludingClasses(String JavaDoc patternList)
61   {
62     _includingClasses = WildCardPattern.createFromsPatterns(patternList, ", ");
63   }
64
65   public void setExcludingClasses(String JavaDoc patternList)
66   {
67     _excludingClasses = new NotStringPattern(
68                         WildCardPattern.createFromsPatterns(patternList, ", "));
69   }
70   
71   public void setReflectionPattern(String JavaDoc patternList)
72   {
73     if ("".equals(patternList))
74     {
75       _reflectionPattern = new TrueStringPattern();
76     } else
77     {
78       _reflectionPattern
79           = WildCardPattern.createFromsPatterns(patternList, ", ");
80     }
81   }
82
83   public void addConfiguredFileset(FileSet set)
84   {
85     _fileSets.add(set);
86   }
87   
88   public void execute() throws BuildException
89   {
90     super.execute();
91
92     if (_fileSets.size() == 0)
93     {
94       throw new BuildException("at least one file set is required");
95     }
96   }
97
98   protected String JavaDoc[] getClassFileNames()
99   {
100     ArrayList JavaDoc fileNames = new ArrayList JavaDoc();
101     String JavaDoc fileSeparator = System.getProperty("file.separator");
102     for (Iterator JavaDoc i = _fileSets.iterator(); i.hasNext();)
103     {
104       FileSet set = (FileSet) i.next();
105       DirectoryScanner scanner = set.getDirectoryScanner(getProject());
106       String JavaDoc path = scanner.getBasedir().getAbsolutePath();
107       String JavaDoc[] localFiles = scanner.getIncludedFiles();
108       for (int j = 0; j < localFiles.length; j++)
109       {
110         fileNames.add(path + fileSeparator + localFiles[j]);
111       }
112     }
113     String JavaDoc[] classFiles = new String JavaDoc[fileNames.size()];
114     return (String JavaDoc[]) fileNames.toArray(classFiles);
115   }
116
117   protected StringPattern getPattern()
118   {
119     AndStringPattern pattern = new AndStringPattern();
120     pattern.appendPattern(_includingClasses);
121     pattern.appendPattern(_excludingClasses);
122     return pattern;
123   }
124   
125   protected StringPattern getReflectionPattern()
126   {
127     return _reflectionPattern;
128   }
129
130   protected boolean isMergeInnerClasses()
131   {
132     return _mergeInnerClasses;
133   }
134   
135  
136 }
137
Popular Tags