Browse Source

Merge pull request #111 from twogee/magic-names

build.sysclasspath is a magic name
master
Stefan Bodewig GitHub 5 years ago
parent
commit
c37f13d422
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 24 additions and 23 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/AntClassLoader.java
  2. +1
    -1
      src/main/org/apache/tools/ant/ComponentHelper.java
  3. +1
    -1
      src/main/org/apache/tools/ant/MagicNames.java
  4. +2
    -2
      src/main/org/apache/tools/ant/ProjectHelper.java
  5. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Classloader.java
  6. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Definer.java
  7. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  8. +6
    -6
      src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
  9. +1
    -1
      src/tests/junit/org/apache/tools/ant/ExecutorTest.java
  10. +2
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
  11. +1
    -1
      src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java

+ 1
- 1
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -448,7 +448,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener, Clo
if (LoaderUtils.isContextLoaderAvailable()) { if (LoaderUtils.isContextLoaderAvailable()) {
savedContextLoader = LoaderUtils.getContextClassLoader(); savedContextLoader = LoaderUtils.getContextClassLoader();
ClassLoader loader = this; ClassLoader loader = this;
if (project != null && "only".equals(project.getProperty("build.sysclasspath"))) {
if (project != null && "only".equals(project.getProperty(MagicNames.BUILD_SYSCLASSPATH))) {
loader = this.getClass().getClassLoader(); loader = this.getClass().getClassLoader();
} }
LoaderUtils.setContextClassLoader(loader); LoaderUtils.setContextClassLoader(loader);


+ 1
- 1
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -824,7 +824,7 @@ public class ComponentHelper {
if (uri.isEmpty()) { if (uri.isEmpty()) {
uri = ProjectHelper.ANT_CORE_URI; uri = ProjectHelper.ANT_CORE_URI;
} }
if (!uri.startsWith(ProjectHelper.ANTLIB_URI)) {
if (!uri.startsWith(MagicNames.ANTLIB_PREFIX)) {
return; // namespace that does not contain antlib return; // namespace that does not contain antlib
} }
if (checkedNamespaces.contains(uri)) { if (checkedNamespaces.contains(uri)) {


+ 1
- 1
src/main/org/apache/tools/ant/MagicNames.java View File

@@ -218,7 +218,7 @@ public final class MagicNames {
* Value: {@value} * Value: {@value}
*/ */
public static final String PROJECT_HELPER_SERVICE = public static final String PROJECT_HELPER_SERVICE =
"META-INF/services/org.apache.tools.ant.ProjectHelper";
"META-INF/services/" + PROJECT_HELPER_CLASS;


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


+ 2
- 2
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -38,7 +38,7 @@ import org.xml.sax.AttributeList;
*/ */
public class ProjectHelper { public class ProjectHelper {
/** The URI for ant name space */ /** The URI for ant name space */
public static final String ANT_CORE_URI = "antlib:org.apache.tools.ant";
public static final String ANT_CORE_URI = MagicNames.ANTLIB_PREFIX + "org.apache.tools.ant";


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


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


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


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Classloader.java View File

@@ -158,10 +158,10 @@ public class Classloader extends Task {
public void execute() { public void execute() {
try { try {
// Gump friendly - don't mess with the core loader if only classpath // Gump friendly - don't mess with the core loader if only classpath
if ("only".equals(getProject().getProperty("build.sysclasspath"))
if ("only".equals(getProject().getProperty(MagicNames.BUILD_SYSCLASSPATH))
&& (name == null || SYSTEM_LOADER_REF.equals(name))) { && (name == null || SYSTEM_LOADER_REF.equals(name))) {
log("Changing the system loader is disabled by build.sysclasspath=only",
Project.MSG_WARN);
log("Changing the system loader is disabled by "
+ MagicNames.BUILD_SYSCLASSPATH + "=only", Project.MSG_WARN);
return; return;
} }




+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Definer.java View File

@@ -463,12 +463,12 @@ public abstract class Definer extends DefBase {
if (definerSet) { if (definerSet) {
tooManyDefinitions(); tooManyDefinitions();
} }
if (!antlib.startsWith("antlib:")) {
if (!antlib.startsWith(MagicNames.ANTLIB_PREFIX)) {
throw new BuildException( throw new BuildException(
"Invalid antlib attribute - it must start with antlib:");
"Invalid antlib attribute - it must start with " + MagicNames.ANTLIB_PREFIX);
} }
setURI(antlib); setURI(antlib);
this.resource = antlib.substring("antlib:".length()).replace('.', '/')
this.resource = antlib.substring(MagicNames.ANTLIB_PREFIX.length()).replace('.', '/')
+ "/antlib.xml"; + "/antlib.xml";
definerSet = true; definerSet = true;
} }


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -1350,9 +1350,9 @@ public class Javac extends MatchingTask {
+ destDir + destDir
+ "\" does not exist or is not a directory", getLocation()); + "\" does not exist or is not a directory", getLocation());
} }
if (includeAntRuntime == null && getProject().getProperty("build.sysclasspath") == null) {
log(getLocation()
+ "warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds",
if (includeAntRuntime == null && getProject().getProperty(MagicNames.BUILD_SYSCLASSPATH) == null) {
log(getLocation() + "warning: 'includeantruntime' was not set, defaulting to "
+ MagicNames.BUILD_SYSCLASSPATH + "=last; set to false for repeatable builds",
Project.MSG_WARN); Project.MSG_WARN);
} }
} }


+ 6
- 6
src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java View File

@@ -75,7 +75,7 @@ public class AntClassLoaderTest {
String extjarstring = buildRule.getProject().getProperty("ext.jar"); String extjarstring = buildRule.getProject().getProperty("ext.jar");
Path myPath = new Path(buildRule.getProject()); Path myPath = new Path(buildRule.getProject());
myPath.setLocation(new File(mainjarstring)); myPath.setLocation(new File(mainjarstring));
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
loader = buildRule.getProject().createClassLoader(myPath); loader = buildRule.getProject().createClassLoader(myPath);
String path = loader.getClasspath(); String path = loader.getClasspath();
assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); assertEquals(mainjarstring + File.pathSeparator + extjarstring, path);
@@ -87,7 +87,7 @@ public class AntClassLoaderTest {
String extjarstring = buildRule.getProject().getProperty("ext.jar.nonascii"); String extjarstring = buildRule.getProject().getProperty("ext.jar.nonascii");
Path myPath = new Path(buildRule.getProject()); Path myPath = new Path(buildRule.getProject());
myPath.setLocation(new File(mainjarstring)); myPath.setLocation(new File(mainjarstring));
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
loader = buildRule.getProject().createClassLoader(myPath); loader = buildRule.getProject().createClassLoader(myPath);
String path = loader.getClasspath(); String path = loader.getClasspath();
assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); assertEquals(mainjarstring + File.pathSeparator + extjarstring, path);
@@ -135,7 +135,7 @@ public class AntClassLoaderTest {
buildRule.executeTarget("prepareGetPackageTest"); buildRule.executeTarget("prepareGetPackageTest");
Path myPath = new Path(buildRule.getProject()); Path myPath = new Path(buildRule.getProject());
myPath.setLocation(new File(buildRule.getProject().getProperty("test.jar"))); myPath.setLocation(new File(buildRule.getProject().getProperty("test.jar")));
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
loader = buildRule.getProject().createClassLoader(myPath); loader = buildRule.getProject().createClassLoader(myPath);
assertNotNull("should find class", loader.findClass("org.example.Foo")); assertNotNull("should find class", loader.findClass("org.example.Foo"));
assertNotNull("should find package", assertNotNull("should find package",
@@ -148,7 +148,7 @@ public class AntClassLoaderTest {
Path myPath = new Path(buildRule.getProject()); Path myPath = new Path(buildRule.getProject());
File testJar = new File(buildRule.getProject().getProperty("test.jar")); File testJar = new File(buildRule.getProject().getProperty("test.jar"));
myPath.setLocation(testJar); myPath.setLocation(testJar);
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
loader = buildRule.getProject().createClassLoader(myPath); loader = buildRule.getProject().createClassLoader(myPath);
Class<?> foo = loader.findClass("org.example.Foo"); Class<?> foo = loader.findClass("org.example.Foo");
URL codeSourceLocation = URL codeSourceLocation =
@@ -164,7 +164,7 @@ public class AntClassLoaderTest {


Path myPath = new Path(buildRule.getProject()); Path myPath = new Path(buildRule.getProject());
myPath.setLocation(jar); myPath.setLocation(jar);
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
loader = buildRule.getProject().createClassLoader(myPath); loader = buildRule.getProject().createClassLoader(myPath);
Class<?> foo = loader.findClass("org.example.Foo"); Class<?> foo = loader.findClass("org.example.Foo");


@@ -188,7 +188,7 @@ public class AntClassLoaderTest {


Path myPath = new Path(buildRule.getProject()); Path myPath = new Path(buildRule.getProject());
myPath.setLocation(jar); myPath.setLocation(jar);
buildRule.getProject().setUserProperty("build.sysclasspath", "ignore");
buildRule.getProject().setUserProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
loader = buildRule.getProject().createClassLoader(myPath); loader = buildRule.getProject().createClassLoader(myPath);
PrintStream sysErr = System.err; PrintStream sysErr = System.err;
try { try {


+ 1
- 1
src/tests/junit/org/apache/tools/ant/ExecutorTest.java View File

@@ -92,7 +92,7 @@ public class ExecutorTest implements BuildListener {


private Project getProject(String e, boolean f, boolean k) { private Project getProject(String e, boolean f, boolean k) {
Project p = buildRule.getProject(); Project p = buildRule.getProject();
p.setNewProperty("ant.executor.class", e);
p.setNewProperty(MagicNames.ANT_EXECUTOR_CLASSNAME, e);
p.setKeepGoingMode(k); p.setKeepGoingMode(k);
if (f) { if (f) {
p.setNewProperty("failfoo", "foo"); p.setNewProperty("failfoo", "foo");


+ 2
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java View File

@@ -37,6 +37,7 @@ import java.util.Properties;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -182,7 +183,7 @@ public class EchoPropertiesTest {
buildRule.executeTarget("testWithRegex"); buildRule.executeTarget("testWithRegex");
// the following line has been changed from checking ant.home to ant.version // the following line has been changed from checking ant.home to ant.version
// so the test will still work when run outside of an Ant script // so the test will still work when run outside of an Ant script
assertThat(buildRule.getFullLog(), containsString("ant.version="));
assertThat(buildRule.getFullLog(), containsString(MagicNames.ANT_VERSION + "="));
} }


private void testEchoPrefixVarious(String target) throws Exception { private void testEchoPrefixVarious(String target) throws Exception {


+ 1
- 1
src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java View File

@@ -53,7 +53,7 @@ public class CommandlineJavaTest {
if (System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY) != null) { if (System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY) != null) {
project.setBasedir(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY)); project.setBasedir(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY));
} }
project.setProperty("build.sysclasspath", "ignore");
project.setProperty(MagicNames.BUILD_SYSCLASSPATH, "ignore");
cloneVm = System.getProperty("ant.build.clonevm"); cloneVm = System.getProperty("ant.build.clonevm");
if (cloneVm != null) { if (cloneVm != null) {
System.setProperty("ant.build.clonevm", "false"); System.setProperty("ant.build.clonevm", "false");


Loading…
Cancel
Save