git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272438 13f79535-47bb-0310-9956-ffa450edef68master
@@ -63,6 +63,7 @@ import org.apache.tools.ant.types.Reference; | |||||
import org.apache.tools.ant.util.GlobPatternMapper; | import org.apache.tools.ant.util.GlobPatternMapper; | ||||
import org.apache.tools.ant.util.JavaEnvUtils; | import org.apache.tools.ant.util.JavaEnvUtils; | ||||
import org.apache.tools.ant.util.SourceFileScanner; | import org.apache.tools.ant.util.SourceFileScanner; | ||||
import org.apache.tools.ant.util.facade.FacadeTaskHelper; | |||||
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; | import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; | ||||
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; | import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; | ||||
@@ -135,7 +136,7 @@ public class Javac extends MatchingTask { | |||||
private boolean nowarn = false; | private boolean nowarn = false; | ||||
private String memoryInitialSize; | private String memoryInitialSize; | ||||
private String memoryMaximumSize; | private String memoryMaximumSize; | ||||
private Vector implementationSpecificArgs = new Vector(); | |||||
private FacadeTaskHelper facade = null; | |||||
protected boolean failOnError = true; | protected boolean failOnError = true; | ||||
protected boolean listFiles = false; | protected boolean listFiles = false; | ||||
@@ -144,14 +145,14 @@ public class Javac extends MatchingTask { | |||||
private String source; | private String source; | ||||
private String debugLevel; | private String debugLevel; | ||||
/** | |||||
* The compiler set via the compiler attribute. | |||||
* | |||||
* <p>default is null</p> | |||||
* | |||||
* @since Ant 1.5 | |||||
*/ | |||||
private String compiler = null; | |||||
public Javac() { | |||||
if (JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_1 && | |||||
JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_2) { | |||||
facade = new FacadeTaskHelper("modern"); | |||||
} else { | |||||
facade = new FacadeTaskHelper("classic"); | |||||
} | |||||
} | |||||
/** | /** | ||||
* Get the value of debugLevel. | * Get the value of debugLevel. | ||||
@@ -604,7 +605,7 @@ public class Javac extends MatchingTask { | |||||
public ImplementationSpecificArgument createCompilerArg() { | public ImplementationSpecificArgument createCompilerArg() { | ||||
ImplementationSpecificArgument arg = | ImplementationSpecificArgument arg = | ||||
new ImplementationSpecificArgument(); | new ImplementationSpecificArgument(); | ||||
implementationSpecificArgs.addElement(arg); | |||||
facade.addImplementationArgument(arg); | |||||
return arg; | return arg; | ||||
} | } | ||||
@@ -613,19 +614,10 @@ public class Javac extends MatchingTask { | |||||
* @return array of command line arguments, guaranteed to be non-null. | * @return array of command line arguments, guaranteed to be non-null. | ||||
*/ | */ | ||||
public String[] getCurrentCompilerArgs() { | public String[] getCurrentCompilerArgs() { | ||||
Vector args = new Vector(); | |||||
for (Enumeration enum = implementationSpecificArgs.elements(); | |||||
enum.hasMoreElements();) { | |||||
ImplementationSpecificArgument arg = | |||||
((ImplementationSpecificArgument) enum.nextElement()); | |||||
String[] curr = arg.getParts(); | |||||
for (int i = 0; i < curr.length; i++) { | |||||
args.addElement(curr[i]); | |||||
} | |||||
} | |||||
String[] res = new String[args.size()]; | |||||
args.copyInto(res); | |||||
return res; | |||||
// make sure facade knows about magic properties and fork setting | |||||
getCompiler(); | |||||
return facade.getArgs(); | |||||
} | } | ||||
/** | /** | ||||
@@ -708,7 +700,7 @@ public class Javac extends MatchingTask { | |||||
* @since Ant 1.5 | * @since Ant 1.5 | ||||
*/ | */ | ||||
public void setCompiler(String compiler) { | public void setCompiler(String compiler) { | ||||
this.compiler = compiler; | |||||
facade.setImplementation(compiler); | |||||
} | } | ||||
/** | /** | ||||
@@ -720,33 +712,19 @@ public class Javac extends MatchingTask { | |||||
* @since Ant 1.5 | * @since Ant 1.5 | ||||
*/ | */ | ||||
public String getCompiler() { | public String getCompiler() { | ||||
String compilerImpl = | |||||
this.compiler != null ? this.compiler | |||||
: project.getProperty("build.compiler"); | |||||
facade.setMagicValue(getProject().getProperty("build.compiler")); | |||||
String compilerImpl = facade.getImplementation(); | |||||
if (fork) { | if (fork) { | ||||
if (compilerImpl != null) { | |||||
if (isJdkCompiler(compilerImpl)) { | |||||
log("Since fork is true, ignoring compiler setting.", | |||||
Project.MSG_WARN); | |||||
compilerImpl = "extJavac"; | |||||
} | |||||
else { | |||||
log("Since compiler setting isn't classic or modern," | |||||
+ "ignoring fork setting.", Project.MSG_WARN); | |||||
} | |||||
} | |||||
else { | |||||
if (isJdkCompiler(compilerImpl)) { | |||||
log("Since fork is true, ignoring compiler setting.", | |||||
Project.MSG_WARN); | |||||
facade.setImplementation("extJavac"); | |||||
compilerImpl = "extJavac"; | compilerImpl = "extJavac"; | ||||
} | } | ||||
} | |||||
if (compilerImpl == null) { | |||||
if (JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_1 && | |||||
JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_2) { | |||||
compilerImpl = "modern"; | |||||
} else { | |||||
compilerImpl = "classic"; | |||||
else { | |||||
log("Since compiler setting isn't classic or modern," | |||||
+ "ignoring fork setting.", Project.MSG_WARN); | |||||
} | } | ||||
} | } | ||||
return compilerImpl; | return compilerImpl; | ||||
@@ -816,25 +794,15 @@ public class Javac extends MatchingTask { | |||||
} | } | ||||
/** | /** | ||||
* Adds an "implementation" attribute to Commandline$Attribute | |||||
* used to filter command line attributes based on the current | |||||
* Adds an "compiler" attribute to Commandline$Attribute used to | |||||
* filter command line attributes based on the current | |||||
* implementation. | * implementation. | ||||
*/ | */ | ||||
public class ImplementationSpecificArgument | |||||
extends Commandline.Argument { | |||||
private String impl; | |||||
public class ImplementationSpecificArgument extends | |||||
org.apache.tools.ant.util.facade.ImplementationSpecificArgument { | |||||
public void setCompiler(String impl) { | public void setCompiler(String impl) { | ||||
this.impl = impl; | |||||
} | |||||
public String[] getParts() { | |||||
if (impl == null || impl.equals(getCompiler())) { | |||||
return super.getParts(); | |||||
} else { | |||||
return new String[0]; | |||||
} | |||||
super.setImplementation(impl); | |||||
} | } | ||||
} | } | ||||
@@ -0,0 +1,160 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.util.facade; | |||||
import java.util.Enumeration; | |||||
import java.util.Vector; | |||||
/** | |||||
* Helper class for facade implementations - encapsulates treatment of | |||||
* explicit implementation choices, magic properties and | |||||
* implementation specific command line arguments. | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* | |||||
* @version $Revision$ | |||||
* | |||||
* @since Ant 1.5 | |||||
*/ | |||||
public class FacadeTaskHelper { | |||||
/** | |||||
* Command line arguments. | |||||
*/ | |||||
private Vector args = new Vector(); | |||||
/** | |||||
* The explicitly chosen implementation. | |||||
*/ | |||||
private String userChoice; | |||||
/** | |||||
* The magic property to consult. | |||||
*/ | |||||
private String magicValue; | |||||
/** | |||||
* The default value. | |||||
*/ | |||||
private String defaultValue; | |||||
/** | |||||
* @param defaultValue The default value for the implementation. | |||||
* Must not be null. | |||||
*/ | |||||
public FacadeTaskHelper(String defaultValue) { | |||||
this(defaultValue, null); | |||||
} | |||||
/** | |||||
* @param defaultValue The default value for the implementation. | |||||
* Must not be null. | |||||
* @param magic the value of a magic property that may hold a user | |||||
* choice. May be null. | |||||
*/ | |||||
public FacadeTaskHelper(String defaultValue, String magicValue) { | |||||
this.defaultValue = defaultValue; | |||||
this.magicValue = magicValue; | |||||
} | |||||
/** | |||||
* Used to set the value of the magic property. | |||||
*/ | |||||
public void setMagicValue(String magicValue) { | |||||
this.magicValue = magicValue; | |||||
} | |||||
/** | |||||
* Used for explicit user choices. | |||||
*/ | |||||
public void setImplementation(String userChoice) { | |||||
this.userChoice = userChoice; | |||||
} | |||||
/** | |||||
* Retrieves the implementation. | |||||
*/ | |||||
public String getImplementation() { | |||||
return userChoice != null ? userChoice | |||||
: (magicValue != null ? magicValue | |||||
: defaultValue); | |||||
} | |||||
/** | |||||
* Command line argument. | |||||
*/ | |||||
public void addImplementationArgument(ImplementationSpecificArgument arg) { | |||||
args.addElement(arg); | |||||
} | |||||
/** | |||||
* Retrieves the command line arguments enabled for the current | |||||
* facade implementation. | |||||
*/ | |||||
public String[] getArgs() { | |||||
Vector tmp = new Vector(args.size()); | |||||
for (Enumeration enum = args.elements(); enum.hasMoreElements();) { | |||||
ImplementationSpecificArgument arg = | |||||
((ImplementationSpecificArgument) enum.nextElement()); | |||||
String[] curr = arg.getParts(getImplementation()); | |||||
for (int i = 0; i < curr.length; i++) { | |||||
tmp.addElement(curr[i]); | |||||
} | |||||
} | |||||
String[] res = new String[tmp.size()]; | |||||
tmp.copyInto(res); | |||||
return res; | |||||
} | |||||
} |
@@ -0,0 +1,87 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2002 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.util.facade; | |||||
import org.apache.tools.ant.types.Commandline; | |||||
/** | |||||
* Extension of Commandline.Argument with a new attribute that choses | |||||
* a specific implementation of the facade. | |||||
* | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
* | |||||
* @version $Revision$ | |||||
* | |||||
* @since Ant 1.5 | |||||
*/ | |||||
public class ImplementationSpecificArgument extends Commandline.Argument { | |||||
private String impl; | |||||
public ImplementationSpecificArgument() { | |||||
super(); | |||||
} | |||||
public void setImplementation(String impl) { | |||||
this.impl = impl; | |||||
} | |||||
public final String[] getParts(String chosenImpl) { | |||||
if (impl == null || impl.equals(chosenImpl)) { | |||||
return super.getParts(); | |||||
} else { | |||||
return new String[0]; | |||||
} | |||||
} | |||||
} |
@@ -184,7 +184,8 @@ public class JavacTest extends TestCase { | |||||
assertEquals("extJavac", compiler); | assertEquals("extJavac", compiler); | ||||
// check build.compiler provides defaults | // check build.compiler provides defaults | ||||
javac.setFork(false); | |||||
javac = new Javac(); | |||||
javac.setProject(project); | |||||
project.setNewProperty("build.compiler", "jikes"); | project.setNewProperty("build.compiler", "jikes"); | ||||
compiler = javac.getCompiler(); | compiler = javac.getCompiler(); | ||||
assertNotNull(compiler); | assertNotNull(compiler); | ||||