Browse Source

provide magic properties to control javac

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@393282 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 19 years ago
parent
commit
eeda02e875
9 changed files with 118 additions and 9 deletions
  1. +5
    -1
      WHATSNEW
  2. +11
    -2
      docs/manual/CoreTasks/javac.html
  3. +5
    -1
      docs/manual/CoreTasks/javadoc.html
  4. +1
    -0
      docs/manual/conceptstypeslist.html
  5. +39
    -0
      docs/manual/javacprops.html
  6. +16
    -0
      src/main/org/apache/tools/ant/MagicNames.java
  7. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  8. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  9. +30
    -1
      src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java

+ 5
- 1
WHATSNEW View File

@@ -376,7 +376,11 @@ Other changes:
dare not change for fear of breaking complex SQL operations in
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
===================================


+ 11
- 2
docs/manual/CoreTasks/javac.html View File

@@ -241,7 +241,12 @@ invoking the compiler.</p>
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
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>
</tr>
<tr>
@@ -322,7 +327,11 @@ invoking the compiler.</p>
at all.<br>
<b>Note that the default value depends on the JVM that is running
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>
</tr>


+ 5
- 1
docs/manual/CoreTasks/javadoc.html View File

@@ -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
present in J2SE v 1.4 source code. Set this to &quot;1.4&quot; to
documents code that compiles using <code>&quot;javac -source
1.4&quot;</code>.</td>
1.4&quot;</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">No</td>
</tr>


+ 1
- 0
docs/manual/conceptstypeslist.html View File

@@ -14,6 +14,7 @@
<h3>Concepts</h3>
<a href="clonevm.html">ant.build.clonevm</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>

<h3>Core Types</h3>


+ 39
- 0
docs/manual/javacprops.html View File

@@ -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>&lt;javac&gt;</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>&lt;javac&gt;</code>'s and
<code>&lt;javadoc&gt;</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>&lt;javac&gt;</code>'s target
attribute.</p>

<hr>
<p align="center">Copyright &copy; 2006 The Apache Software Foundation. All rights
Reserved.</p>
</body>
</html>


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

@@ -128,5 +128,21 @@ public final class MagicNames {
*/
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";

}


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

@@ -20,6 +20,7 @@ package org.apache.tools.ant.taskdefs;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
@@ -161,7 +162,8 @@ public class Javac extends MatchingTask {
* @return value of source.
*/
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
*/
public String getTarget() {
return targetAttribute;
return targetAttribute != null
? targetAttribute
: getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET);
}

/**


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -33,6 +33,7 @@ import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
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(sourceArg);
}

if (linksource && doclet == null) {


+ 30
- 1
src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java View File

@@ -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");
* 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);
}

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());
}
}

Loading…
Cancel
Save