Skip to content

Commit c37f13d

Browse files
authored
Merge pull request #111 from twogee/magic-names
build.sysclasspath is a magic name
2 parents 2f0e194 + 814e95b commit c37f13d

File tree

11 files changed

+24
-23
lines changed

11 files changed

+24
-23
lines changed

src/main/org/apache/tools/ant/AntClassLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public void setThreadContextLoader() {
448448
if (LoaderUtils.isContextLoaderAvailable()) {
449449
savedContextLoader = LoaderUtils.getContextClassLoader();
450450
ClassLoader loader = this;
451-
if (project != null && "only".equals(project.getProperty("build.sysclasspath"))) {
451+
if (project != null && "only".equals(project.getProperty(MagicNames.BUILD_SYSCLASSPATH))) {
452452
loader = this.getClass().getClassLoader();
453453
}
454454
LoaderUtils.setContextClassLoader(loader);

src/main/org/apache/tools/ant/ComponentHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ private synchronized void checkNamespace(String componentName) {
824824
if (uri.isEmpty()) {
825825
uri = ProjectHelper.ANT_CORE_URI;
826826
}
827-
if (!uri.startsWith(ProjectHelper.ANTLIB_URI)) {
827+
if (!uri.startsWith(MagicNames.ANTLIB_PREFIX)) {
828828
return; // namespace that does not contain antlib
829829
}
830830
if (checkedNamespaces.contains(uri)) {

src/main/org/apache/tools/ant/MagicNames.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private MagicNames() {
218218
* Value: {@value}
219219
*/
220220
public static final String PROJECT_HELPER_SERVICE =
221-
"META-INF/services/org.apache.tools.ant.ProjectHelper";
221+
"META-INF/services/" + PROJECT_HELPER_CLASS;
222222

223223
/**
224224
* Name of ProjectHelper reference that we add to a project.

src/main/org/apache/tools/ant/ProjectHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
public class ProjectHelper {
4040
/** The URI for ant name space */
41-
public static final String ANT_CORE_URI = "antlib:org.apache.tools.ant";
41+
public static final String ANT_CORE_URI = MagicNames.ANTLIB_PREFIX + "org.apache.tools.ant";
4242

4343
/** The URI for antlib current definitions */
4444
public static final String ANT_CURRENT_URI = "ant:current";
@@ -49,7 +49,7 @@ public class ProjectHelper {
4949
public static final String ANT_ATTRIBUTE_URI = "ant:attribute";
5050

5151
/** The URI for defined types/tasks - the format is antlib:<package> */
52-
public static final String ANTLIB_URI = "antlib:";
52+
public static final String ANTLIB_URI = MagicNames.ANTLIB_PREFIX;
5353

5454
/** Polymorphic attribute */
5555
public static final String ANT_TYPE = "ant-type";

src/main/org/apache/tools/ant/taskdefs/Classloader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ public Path createClasspath() {
158158
public void execute() {
159159
try {
160160
// Gump friendly - don't mess with the core loader if only classpath
161-
if ("only".equals(getProject().getProperty("build.sysclasspath"))
161+
if ("only".equals(getProject().getProperty(MagicNames.BUILD_SYSCLASSPATH))
162162
&& (name == null || SYSTEM_LOADER_REF.equals(name))) {
163-
log("Changing the system loader is disabled by build.sysclasspath=only",
164-
Project.MSG_WARN);
163+
log("Changing the system loader is disabled by "
164+
+ MagicNames.BUILD_SYSCLASSPATH + "=only", Project.MSG_WARN);
165165
return;
166166
}
167167

src/main/org/apache/tools/ant/taskdefs/Definer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,12 @@ public void setAntlib(String antlib) {
463463
if (definerSet) {
464464
tooManyDefinitions();
465465
}
466-
if (!antlib.startsWith("antlib:")) {
466+
if (!antlib.startsWith(MagicNames.ANTLIB_PREFIX)) {
467467
throw new BuildException(
468-
"Invalid antlib attribute - it must start with antlib:");
468+
"Invalid antlib attribute - it must start with " + MagicNames.ANTLIB_PREFIX);
469469
}
470470
setURI(antlib);
471-
this.resource = antlib.substring("antlib:".length()).replace('.', '/')
471+
this.resource = antlib.substring(MagicNames.ANTLIB_PREFIX.length()).replace('.', '/')
472472
+ "/antlib.xml";
473473
definerSet = true;
474474
}

src/main/org/apache/tools/ant/taskdefs/Javac.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,9 @@ protected void checkParameters() throws BuildException {
13501350
+ destDir
13511351
+ "\" does not exist or is not a directory", getLocation());
13521352
}
1353-
if (includeAntRuntime == null && getProject().getProperty("build.sysclasspath") == null) {
1354-
log(getLocation()
1355-
+ "warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds",
1353+
if (includeAntRuntime == null && getProject().getProperty(MagicNames.BUILD_SYSCLASSPATH) == null) {
1354+
log(getLocation() + "warning: 'includeantruntime' was not set, defaulting to "
1355+
+ MagicNames.BUILD_SYSCLASSPATH + "=last; set to false for repeatable builds",
13561356
Project.MSG_WARN);
13571357
}
13581358
}

src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testJarWithManifestInDirWithSpace() {
7575
String extjarstring = buildRule.getProject().getProperty("ext.jar");
7676
Path myPath = new Path(buildRule.getProject());
7777
myPath.setLocation(new File(mainjarstring));
78-
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
78+
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
7979
loader = buildRule.getProject().createClassLoader(myPath);
8080
String path = loader.getClasspath();
8181
assertEquals(mainjarstring + File.pathSeparator + extjarstring, path);
@@ -87,7 +87,7 @@ public void testJarWithManifestInNonAsciiDir() {
8787
String extjarstring = buildRule.getProject().getProperty("ext.jar.nonascii");
8888
Path myPath = new Path(buildRule.getProject());
8989
myPath.setLocation(new File(mainjarstring));
90-
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
90+
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
9191
loader = buildRule.getProject().createClassLoader(myPath);
9292
String path = loader.getClasspath();
9393
assertEquals(mainjarstring + File.pathSeparator + extjarstring, path);
@@ -135,7 +135,7 @@ public void testGetPackage() throws Exception {
135135
buildRule.executeTarget("prepareGetPackageTest");
136136
Path myPath = new Path(buildRule.getProject());
137137
myPath.setLocation(new File(buildRule.getProject().getProperty("test.jar")));
138-
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
138+
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
139139
loader = buildRule.getProject().createClassLoader(myPath);
140140
assertNotNull("should find class", loader.findClass("org.example.Foo"));
141141
assertNotNull("should find package",
@@ -148,7 +148,7 @@ public void testCodeSource() throws Exception {
148148
Path myPath = new Path(buildRule.getProject());
149149
File testJar = new File(buildRule.getProject().getProperty("test.jar"));
150150
myPath.setLocation(testJar);
151-
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
151+
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
152152
loader = buildRule.getProject().createClassLoader(myPath);
153153
Class<?> foo = loader.findClass("org.example.Foo");
154154
URL codeSourceLocation =
@@ -164,7 +164,7 @@ public void testSignedJar() throws Exception {
164164

165165
Path myPath = new Path(buildRule.getProject());
166166
myPath.setLocation(jar);
167-
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
167+
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
168168
loader = buildRule.getProject().createClassLoader(myPath);
169169
Class<?> foo = loader.findClass("org.example.Foo");
170170

@@ -188,7 +188,7 @@ public void testInvalidZipException() {
188188

189189
Path myPath = new Path(buildRule.getProject());
190190
myPath.setLocation(jar);
191-
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
191+
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
192192
loader = buildRule.getProject().createClassLoader(myPath);
193193
PrintStream sysErr = System.err;
194194
try {

src/tests/junit/org/apache/tools/ant/ExecutorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private Project getProject(String e, boolean f) {
9292

9393
private Project getProject(String e, boolean f, boolean k) {
9494
Project p = buildRule.getProject();
95-
p.setNewProperty("ant.executor.class", e);
95+
p.setNewProperty(MagicNames.ANT_EXECUTOR_CLASSNAME, e);
9696
p.setKeepGoingMode(k);
9797
if (f) {
9898
p.setNewProperty("failfoo", "foo");

src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import org.apache.tools.ant.BuildException;
3939
import org.apache.tools.ant.BuildFileRule;
40+
import org.apache.tools.ant.MagicNames;
4041
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
4142
import org.junit.After;
4243
import org.junit.Before;
@@ -182,7 +183,7 @@ public void testWithRegex() {
182183
buildRule.executeTarget("testWithRegex");
183184
// the following line has been changed from checking ant.home to ant.version
184185
// so the test will still work when run outside of an Ant script
185-
assertThat(buildRule.getFullLog(), containsString("ant.version="));
186+
assertThat(buildRule.getFullLog(), containsString(MagicNames.ANT_VERSION + "="));
186187
}
187188

188189
private void testEchoPrefixVarious(String target) throws Exception {

src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void setUp() {
5353
if (System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY) != null) {
5454
project.setBasedir(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY));
5555
}
56-
project.setProperty("build.sysclasspath", "ignore");
56+
project.setProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
5757
cloneVm = System.getProperty("ant.build.clonevm");
5858
if (cloneVm != null) {
5959
System.setProperty("ant.build.clonevm", "false");

0 commit comments

Comments
 (0)