Debian Codegraph @

src/main/java/net/sf/antcontrib/walls/Package.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.antcontrib.walls;
17
18 import java.io.File;
19 import java.util.StringTokenizer;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Location;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.types.FileSet;
25 import org.apache.tools.ant.types.Path;
26
27
28 /*
29 * Created on Aug 24, 2003
30 *
31 * To change the template for this generated file go to
32 * Window>Preferences>Java>Code Generation>Code and Comments
33 */
34 /**
35 * FILL IN JAVADOC HERE
36 *
37 * @author Dean Hiller([email protected])
38 */
39 public class Package {
40
41 private String name;
42 private String pack;
43
44 //signifies the package did not end with .* or .**
45 private boolean badPackage = false;
46 private String failureReason = null;
47
48 //holds the name attribute of the package element of each
49 //package this package depends on.
50 private String[] depends;
51
52 public void setName(String name) {
53 this.name = name;
54 }
55 public String getName() {
56 return name;
57 }
58
59 public void setPackage(String pack) {
60 this.pack = pack;
61 }
62 public String getPackage() {
63 return pack;
64 }
65
66 public void setDepends(String d) {
67 if(d == null) {
68 throw new RuntimeException("depends cannot be set to null");
69 }
70
71 //parse this first.
72 StringTokenizer tok = new StringTokenizer(d, ", \t");
73 depends = new String[tok.countTokens()];
74 int i = 0;
75 while(tok.hasMoreTokens()) {
76 depends[i] = tok.nextToken();
77 i++;
78 }
79 }
80
81 public String[] getDepends() {
82 return depends;
83 }
84
85 /**
86 * FILL IN JAVADOC HERE
87 *
88 */
89 public FileSet getJavaCopyFileSet(Project p, Location l) throws BuildException {
90
91 if(failureReason != null)
92 throw new BuildException(failureReason, l);
93 else if(pack.indexOf("/") != -1 || pack.indexOf("\\") != -1)
94 throw new BuildException("A package name cannot contain '\\' or '/' like package="+pack
95 +"\nIt must look like biz.xsoftware.* for example", l);
96 FileSet set = new FileSet();
97
98 String match = getMatch(p, pack, ".java");
99 //log("match="+match+" pack="+pack);
100 //first exclude the compilation module, then exclude all it's
101 //dependencies too.
102 set.setIncludes(match);
103
104 return set;
105 }
106
107 /**
108 * FILL IN JAVADOC HERE
109 *
110 */
111 public FileSet getClassCopyFileSet(Project p, Location l) throws BuildException {
112 FileSet set = new FileSet();
113 set.setIncludes("**/*.class");
114 return set;
115 }
116
117 public File getBuildSpace(File baseDir) {
118 return new File(baseDir, name);
119 }
120
121 /**
122 * @return the source path
123 */
124 public Path getSrcPath(File baseDir, Project p) {
125 Path path = new Path(p);
126
127 path.setLocation(getBuildSpace(baseDir));
128 return path;
129 }
130
131 /**
132 * @return the classpath
133 */
134 public Path getClasspath(File baseDir, Project p) {
135 Path path = new Path(p);
136
137 if(depends != null) {
138 for(int i = 0; i < depends.length; i++) {
139 String buildSpace = (String)depends[i];
140
141 File dependsDir = new File(baseDir, buildSpace);
142 path.setLocation(dependsDir);
143 }
144 }
145 return path;
146 }
147
148 private String getMatch(Project p, String pack, String postFix) {
149 pack = p.replaceProperties(pack);
150
151
152 pack = pack.replace('.', File.separatorChar);
153
154 String match;
155 String classMatch;
156 if(pack.endsWith("**")) {
157 match = pack + File.separatorChar+"*"+postFix;
158 }
159 else if(pack.endsWith("*")) {
160 match = pack + postFix;
161 }
162 else
163 throw new RuntimeException("Please report this bug");
164
165 return match;
166 }
167
168 /**
169 * FILL IN JAVADOC HERE
170 * @param r a fault reason string
171 */
172 public void setFaultReason(String r) {
173 failureReason = r;
174 }
175 }