git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@393282 13f79535-47bb-0310-9956-ffa450edef68master
@@ -376,7 +376,11 @@ Other changes: | |||||
dare not change for fear of breaking complex SQL operations in | dare not change for fear of breaking complex SQL operations in | ||||
existing files. | existing files. | ||||
* <javadoc>'s packagenames attribute is now optional and default to "*". | |||||
* <javadoc>'s packagenames attribute is now optional and defaults to "*". | |||||
* <javac>'s source and target attributes as well as <javadoc>'s source | |||||
attribute will read default values from the properties | |||||
ant.build.javac.source and ant.build.javac.target. | |||||
Changes from Ant 1.6.4 to Ant 1.6.5 | Changes from Ant 1.6.4 to Ant 1.6.5 | ||||
=================================== | =================================== | ||||
@@ -241,7 +241,12 @@ invoking the compiler.</p> | |||||
particular, if you use JDK 1.4+ the generated classes will not be | particular, if you use JDK 1.4+ the generated classes will not be | ||||
usable for a 1.1 Java VM unless you explicitly set this attribute | usable for a 1.1 Java VM unless you explicitly set this attribute | ||||
to the value 1.1 (which is the default value for JDK 1.1 to | to the value 1.1 (which is the default value for JDK 1.1 to | ||||
1.3). We highly recommend to always specify this attribute.</b></td> | |||||
1.3). We highly recommend to always specify this | |||||
attribute.</b><br> | |||||
A default value for this attribute can be provided using the magic | |||||
<a | |||||
href="../javacprops.html#target"><code>ant.build.javac.target</code></a> | |||||
property.</td> | |||||
<td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
@@ -322,7 +327,11 @@ invoking the compiler.</p> | |||||
at all.<br> | at all.<br> | ||||
<b>Note that the default value depends on the JVM that is running | <b>Note that the default value depends on the JVM that is running | ||||
Ant. We highly recommend to always specify this | Ant. We highly recommend to always specify this | ||||
attribute.</b></td> | |||||
attribute.</b><br> | |||||
A default value for this attribute can be provided using the magic | |||||
<a | |||||
href="../javacprops.html#source"><code>ant.build.javac.source</code></a> | |||||
property.</td> | |||||
<td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
</tr> | </tr> | ||||
@@ -407,7 +407,11 @@ to ensure that this command supports the attributes you wish to use.</p> | |||||
<td valign="top">Necessary to enable javadoc to handle assertions | <td valign="top">Necessary to enable javadoc to handle assertions | ||||
present in J2SE v 1.4 source code. Set this to "1.4" to | present in J2SE v 1.4 source code. Set this to "1.4" to | ||||
documents code that compiles using <code>"javac -source | documents code that compiles using <code>"javac -source | ||||
1.4"</code>.</td> | |||||
1.4"</code>.<br> | |||||
A default value for this attribute can be provided using the magic | |||||
<a | |||||
href="../javacprops.html#source"><code>ant.build.javac.source</code></a> | |||||
property.</td> | |||||
<td align="center" valign="top">1.4+</td> | <td align="center" valign="top">1.4+</td> | ||||
<td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
</tr> | </tr> | ||||
@@ -14,6 +14,7 @@ | |||||
<h3>Concepts</h3> | <h3>Concepts</h3> | ||||
<a href="clonevm.html">ant.build.clonevm</a><br> | <a href="clonevm.html">ant.build.clonevm</a><br> | ||||
<a href="sysclasspath.html">build.sysclasspath</a><br> | <a href="sysclasspath.html">build.sysclasspath</a><br> | ||||
<a href="javacprops.html">Ant properties controlling javac</a><br> | |||||
<a href="CoreTasks/common.html">Common Attributes</a><br> | <a href="CoreTasks/common.html">Common Attributes</a><br> | ||||
<h3>Core Types</h3> | <h3>Core Types</h3> | ||||
@@ -0,0 +1,39 @@ | |||||
<html> | |||||
<head> | |||||
<meta http-equiv="Content-Language" content="en-us"> | |||||
<link rel="stylesheet" type="text/css" href="stylesheets/style.css"> | |||||
<title>Properties controlling javac</title> | |||||
</head> | |||||
<body> | |||||
<p>The source and target attributes of <code><javac></code> | |||||
don't have any default values for historical reasons. Since the | |||||
underlying javac compiler's default depends on the JDK you use, you | |||||
may encounter build files that don't explicitly set those attributes | |||||
and that will no longer compile using a newer JDK. If you cannot | |||||
change the build file, Ant provides two properties that help you | |||||
setting default values for these attributes. If the attributes have | |||||
been set explicitly, the properties listed here will be ignored.</p> | |||||
<h2><a name="source">ant.build.javac.source</a></h2> | |||||
<p><em>Since Ant 1.7</em></p> | |||||
<p>Provides a default value for <code><javac></code>'s and | |||||
<code><javadoc></code>'s source attribute.</p> | |||||
<h2><a name="target">ant.build.javac.target</a></h2> | |||||
<p><em>Since Ant 1.7</em></p> | |||||
<p>Provides a default value for <code><javac></code>'s target | |||||
attribute.</p> | |||||
<hr> | |||||
<p align="center">Copyright © 2006 The Apache Software Foundation. All rights | |||||
Reserved.</p> | |||||
</body> | |||||
</html> | |||||
@@ -128,5 +128,21 @@ public final class MagicNames { | |||||
*/ | */ | ||||
public static final String REGEXP_IMPL = "ant.regexp.regexpimpl"; | public static final String REGEXP_IMPL = "ant.regexp.regexpimpl"; | ||||
/** | |||||
* property that provides the default value for javac's and | |||||
* javadoc's source attribute. | |||||
* @since Ant 1.7 | |||||
* Value: {@value} | |||||
*/ | |||||
public static final String BUILD_JAVAC_SOURCE = "ant.build.javac.source"; | |||||
/** | |||||
* property that provides the default value for javac's target | |||||
* attribute. | |||||
* @since Ant 1.7 | |||||
* Value: {@value} | |||||
*/ | |||||
public static final String BUILD_JAVAC_TARGET = "ant.build.javac.target"; | |||||
} | } | ||||
@@ -20,6 +20,7 @@ package org.apache.tools.ant.taskdefs; | |||||
import java.io.File; | import java.io.File; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.MagicNames; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
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; | ||||
@@ -161,7 +162,8 @@ public class Javac extends MatchingTask { | |||||
* @return value of source. | * @return value of source. | ||||
*/ | */ | ||||
public String getSource() { | public String getSource() { | ||||
return source; | |||||
return source != null | |||||
? source : getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE); | |||||
} | } | ||||
/** | /** | ||||
@@ -586,7 +588,9 @@ public class Javac extends MatchingTask { | |||||
* @return the target VM | * @return the target VM | ||||
*/ | */ | ||||
public String getTarget() { | public String getTarget() { | ||||
return targetAttribute; | |||||
return targetAttribute != null | |||||
? targetAttribute | |||||
: getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET); | |||||
} | } | ||||
/** | /** | ||||
@@ -33,6 +33,7 @@ import java.util.StringTokenizer; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.MagicNames; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
@@ -1912,9 +1913,11 @@ public class Javadoc extends Task { | |||||
} | } | ||||
} | } | ||||
if (source != null) { | |||||
String sourceArg = source != null ? source | |||||
: getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE); | |||||
if (sourceArg != null) { | |||||
toExecute.createArgument().setValue("-source"); | toExecute.createArgument().setValue("-source"); | ||||
toExecute.createArgument().setValue(source); | |||||
toExecute.createArgument().setValue(sourceArg); | |||||
} | } | ||||
if (linksource && doclet == null) { | if (linksource && doclet == null) { | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2006 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -212,4 +212,33 @@ public class JavacTest extends TestCase { | |||||
assertTrue(adapter instanceof JavacExternal); | assertTrue(adapter instanceof JavacExternal); | ||||
} | } | ||||
public void testSourceNoDefault() { | |||||
assertNull(javac.getSource()); | |||||
} | |||||
public void testSourceWithDefault() { | |||||
project.setNewProperty("ant.build.javac.source", "1.4"); | |||||
assertEquals("1.4", javac.getSource()); | |||||
} | |||||
public void testSourceOverridesDefault() { | |||||
project.setNewProperty("ant.build.javac.source", "1.4"); | |||||
javac.setSource("1.5"); | |||||
assertEquals("1.5", javac.getSource()); | |||||
} | |||||
public void testTargetNoDefault() { | |||||
assertNull(javac.getTarget()); | |||||
} | |||||
public void testTargetWithDefault() { | |||||
project.setNewProperty("ant.build.javac.target", "1.4"); | |||||
assertEquals("1.4", javac.getTarget()); | |||||
} | |||||
public void testTargetOverridesDefault() { | |||||
project.setNewProperty("ant.build.javac.target", "1.4"); | |||||
javac.setTarget("1.5"); | |||||
assertEquals("1.5", javac.getTarget()); | |||||
} | |||||
} | } |