Commit 2279b143 authored by Emmanuel Bourg's avatar Emmanuel Bourg

Automatically set the value of the javac --release attribute

parent 468c8d50
ant (1.10.3-2) UNRELEASED; urgency=medium
* Team upload.
* Automatically set the value of the javac --release attribute to improve
the backward compatibility of the code compiled with Java 9 or later.
* Standards-Version updated to 4.1.4
* Use salsa.debian.org Vcs-* URLs
......
......@@ -3,40 +3,58 @@ Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
--- a/src/main/org/apache/tools/ant/taskdefs/Javac.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java
@@ -213,7 +213,10 @@
@@ -213,7 +213,7 @@
*/
public String getSource() {
return source != null
- ? source : getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE);
+ ? source : LanguageLevel.adjust(
+ getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE),
+ MagicNames.BUILD_JAVAC_SOURCE,
+ this);
+ ? source : LanguageLevel.adjust(getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE), MagicNames.BUILD_JAVAC_SOURCE, this);
}
/**
@@ -792,7 +795,10 @@
@@ -792,7 +792,7 @@
public String getTarget() {
return targetAttribute != null
? targetAttribute
- : getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET);
+ : LanguageLevel.adjust(
+ getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET),
+ MagicNames.BUILD_JAVAC_TARGET,
+ this);
+ : LanguageLevel.adjust(getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET), MagicNames.BUILD_JAVAC_TARGET, this);
}
/**
@@ -1121,6 +1127,9 @@
@@ -1120,7 +1120,7 @@
public void execute() throws BuildException {
checkParameters();
resetFileLists();
+ source = LanguageLevel.adjust(source, "javac -source", this);
+ targetAttribute = LanguageLevel.adjust(targetAttribute, "javac -target", this);
+
-
+ adjustLevels();
// scan source directories and dest directory to build up
// compile list
if (hasPath(src)) {
@@ -1722,4 +1722,24 @@
0x00, 0x00, 0x00, 0x02, 0x00, 0x04
};
+ /**
+ * Adjusts the value of the source/target/release attributes.
+ */
+ private void adjustLevels() {
+ source = LanguageLevel.adjust(source, "javac -source", this);
+ targetAttribute = LanguageLevel.adjust(targetAttribute, "javac -target", this);
+ release = LanguageLevel.adjust(release, "javac --release", this);
+ if (LanguageLevel.isDebianBuild()) {
+ if (release == null && targetAttribute != null) {
+ log("Release attribute not specified, defaulting to the value of the target attribute (" + targetAttribute + ")");
+ release = targetAttribute;
+ } else if (release == null && targetAttribute != null) {
+ log("Release attribute not specified, defaulting to the value of the source attribute (" + source + ")");
+ release = source;
+ }
+ if (release != null && release.startsWith("1.")) {
+ release = release.substring(2);
+ }
+ }
+ }
}
--- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
@@ -2174,7 +2174,7 @@
......@@ -62,7 +80,7 @@ Forwarded: no
+class LanguageLevel {
+
+ /** The minimum language level supported by the current javac */
+ private static final String MIN_LEVEL = "1.7";
+ private static final String MIN_LEVEL = "7";
+
+ /** The list of language levels no longer supported by the current javac */
+ private static final List<String> UNSUPPORTED_LEVELS = Arrays.asList(new String[]{"1.1", "1.2", "1.3", "1.4", "1.5", "5", "1.6", "6"});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment