Roberto Lublinerman has submitted this change and it was merged.

Change subject: Chooses a default GWT source level to match the current java runtime.
......................................................................


Chooses a default GWT source level to match the current java runtime.

Now the GWT default source compatibility level will try to match the
system property java.specification.version.

A small refactor in SourceLevel and a fix to apicheck have been made to
allow specifing the java source compatibility level when processing apis
in order to avoid a compile error on an old version of emul.Enum.

Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
---
M dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
M dev/core/src/com/google/gwt/dev/CompileTaskOptionsImpl.java
M dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java
M dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
M dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
M dev/core/src/com/google/gwt/dev/javac/testing/GeneratorContextBuilder.java
M dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
M dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerSource.java
M dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
M dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
M dev/core/src/com/google/gwt/util/tools/Utility.java
M dev/core/test/com/google/gwt/dev/CompilerTest.java
M dev/core/test/com/google/gwt/dev/javac/CompilationStateTestBase.java
M dev/core/test/com/google/gwt/dev/jjs/impl/JJSTestBase.java
M dev/core/test/com/google/gwt/dev/util/UtilityTest.java
M tools/api-checker/config/gwt25_26userApi.conf
M tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java
M tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java
18 files changed, 171 insertions(+), 48 deletions(-)

Approvals:
  Roberto Lublinerman: Looks good to me, approved
  Leeroy Jenkins: Verified



diff --git a/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java b/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
index e16534f..de9e3fc 100644
--- a/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
+++ b/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
@@ -50,7 +50,7 @@
   private int port = 9876;
   private RecompileListener recompileListener = RecompileListener.NONE;
   // Use the same default as the GWT compiler.
-  private SourceLevel sourceLevel = OptionSource.DEFAULT_SOURCE_LEVEL;
+  private SourceLevel sourceLevel = SourceLevel.DEFAULT_SOURCE_LEVEL;

   /**
* Sets each option to the appropriate value, based on command-line arguments. diff --git a/dev/core/src/com/google/gwt/dev/CompileTaskOptionsImpl.java b/dev/core/src/com/google/gwt/dev/CompileTaskOptionsImpl.java
index 34cceb6..978cff9 100644
--- a/dev/core/src/com/google/gwt/dev/CompileTaskOptionsImpl.java
+++ b/dev/core/src/com/google/gwt/dev/CompileTaskOptionsImpl.java
@@ -16,7 +16,6 @@
 package com.google.gwt.dev;

 import com.google.gwt.core.ext.TreeLogger.Type;
-import com.google.gwt.dev.util.arg.OptionSource;
 import com.google.gwt.dev.util.arg.SourceLevel;

 import java.io.File;
@@ -31,7 +30,7 @@
   private Type logLevel;
   private final List<String> moduleNames = new ArrayList<String>();
   private File workDir;
-  private SourceLevel sourceLevel = OptionSource.DEFAULT_SOURCE_LEVEL;
+  private SourceLevel sourceLevel = SourceLevel.DEFAULT_SOURCE_LEVEL;

   public CompileTaskOptionsImpl() {
   }
diff --git a/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java b/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java
index 579275d..63016d1 100644
--- a/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java
+++ b/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java
@@ -33,7 +33,6 @@
 import com.google.gwt.dev.resource.impl.ResourceOracleImpl;
 import com.google.gwt.dev.util.Empty;
 import com.google.gwt.dev.util.Util;
-import com.google.gwt.dev.util.arg.OptionSource;
 import com.google.gwt.dev.util.arg.SourceLevel;
 import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
 import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
@@ -366,7 +365,7 @@
   }

public CompilationState getCompilationState(TreeLogger logger) throws UnableToCompleteException { - return getCompilationState(logger, false, OptionSource.DEFAULT_SOURCE_LEVEL); + return getCompilationState(logger, false, SourceLevel.DEFAULT_SOURCE_LEVEL);
   }

public synchronized CompilationState getCompilationState(TreeLogger logger, diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java b/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
index fc359db..d450ca7 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
@@ -25,7 +25,6 @@
 import com.google.gwt.dev.js.ast.JsRootScope;
 import com.google.gwt.dev.resource.Resource;
 import com.google.gwt.dev.util.StringInterner;
-import com.google.gwt.dev.util.arg.OptionSource;
 import com.google.gwt.dev.util.arg.SourceLevel;
 import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
 import com.google.gwt.dev.util.log.speedtracer.DevModeEventType;
@@ -406,7 +405,7 @@

public static CompilationState buildFrom(TreeLogger logger, Set<Resource> resources)
       throws UnableToCompleteException {
- return buildFrom(logger, resources, null, false, OptionSource.DEFAULT_SOURCE_LEVEL); + return buildFrom(logger, resources, null, false, SourceLevel.DEFAULT_SOURCE_LEVEL);
   }

public static CompilationState buildFrom(TreeLogger logger, Set<Resource> resources, diff --git a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
index 512a871..2f7e90d 100644
--- a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
@@ -21,7 +21,6 @@
 import com.google.gwt.dev.jjs.InternalCompilerException;
 import com.google.gwt.dev.jjs.ast.JDeclaredType;
 import com.google.gwt.dev.util.Name.BinaryName;
-import com.google.gwt.dev.util.arg.OptionSource;
 import com.google.gwt.dev.util.arg.SourceLevel;
 import com.google.gwt.dev.util.collect.Lists;
 import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
@@ -597,7 +596,7 @@
   public static List<CompilationUnit> compile(TreeLogger logger,
       Collection<CompilationUnitBuilder> builders)
       throws UnableToCompleteException {
-    return compile(logger, builders, OptionSource.DEFAULT_SOURCE_LEVEL);
+    return compile(logger, builders, SourceLevel.DEFAULT_SOURCE_LEVEL);
   }

   public static List<CompilationUnit> compile(TreeLogger logger,
@@ -623,7 +622,7 @@
       }
     };

- long jdtSourceLevel = jdtLevelByGwtLevel.get(OptionSource.DEFAULT_SOURCE_LEVEL); + long jdtSourceLevel = jdtLevelByGwtLevel.get(SourceLevel.DEFAULT_SOURCE_LEVEL);

     options.originalSourceLevel = jdtSourceLevel;
     options.complianceLevel = jdtSourceLevel;
diff --git a/dev/core/src/com/google/gwt/dev/javac/testing/GeneratorContextBuilder.java b/dev/core/src/com/google/gwt/dev/javac/testing/GeneratorContextBuilder.java
index d13d733..e014558 100644
--- a/dev/core/src/com/google/gwt/dev/javac/testing/GeneratorContextBuilder.java +++ b/dev/core/src/com/google/gwt/dev/javac/testing/GeneratorContextBuilder.java
@@ -24,7 +24,7 @@
 import com.google.gwt.dev.javac.testing.impl.JavaResourceBase;
 import com.google.gwt.dev.javac.testing.impl.MockResource;
 import com.google.gwt.dev.resource.Resource;
-import com.google.gwt.dev.util.arg.OptionSource;
+import com.google.gwt.dev.util.arg.SourceLevel;
 import com.google.gwt.dev.util.collect.HashSet;
 import com.google.gwt.dev.util.log.PrintWriterTreeLogger;

@@ -106,7 +106,7 @@
private CompilationState buildCompilationState() throws UnableToCompleteException {
     TreeLogger logger = treeLogger != null ? treeLogger : createLogger();
return new CompilationStateBuilder().doBuildFrom(logger, resources, null, false,
-          OptionSource.DEFAULT_SOURCE_LEVEL);
+          SourceLevel.DEFAULT_SOURCE_LEVEL);
   }

   private TreeLogger createLogger() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java b/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
index 9435635..fcc52bb 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/JJSOptionsImpl.java
@@ -16,7 +16,6 @@
 package com.google.gwt.dev.jjs;

 import com.google.gwt.dev.util.arg.OptionOptimize;
-import com.google.gwt.dev.util.arg.OptionSource;
 import com.google.gwt.dev.util.arg.SourceLevel;

 import java.io.Serializable;
@@ -47,7 +46,7 @@
   private boolean soycExtra = false;
   private boolean soycHtmlDisabled = false;
   private boolean strict = false;
-  private SourceLevel sourceLevel = OptionSource.DEFAULT_SOURCE_LEVEL;
+  private SourceLevel sourceLevel = SourceLevel.DEFAULT_SOURCE_LEVEL;

   public JJSOptionsImpl() {
   }
diff --git a/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerSource.java b/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerSource.java
index 927f7e5..0344448 100644
--- a/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerSource.java
+++ b/dev/core/src/com/google/gwt/dev/util/arg/ArgHandlerSource.java
@@ -16,26 +16,12 @@
 package com.google.gwt.dev.util.arg;

 import com.google.gwt.thirdparty.guava.common.base.Joiner;
-import com.google.gwt.thirdparty.guava.common.collect.ImmutableMap;
 import com.google.gwt.util.tools.ArgHandlerString;
-
-import java.util.Map;

 /**
  * Set the Java source level compatibility.
  */
 public class ArgHandlerSource extends ArgHandlerString {
-  private static final Map<String, SourceLevel> sourceLevelsByString;
-
-  static {
- ImmutableMap.Builder<String, SourceLevel> builder = ImmutableMap.<String, SourceLevel>builder();
-    for (SourceLevel sourceLevel : SourceLevel.values()) {
-      builder.put(sourceLevel.getStringValue(), sourceLevel);
-      builder.put(sourceLevel.getAltStringValue(), sourceLevel);
-    }
-    sourceLevelsByString = builder.build();
-  }
-
   private final OptionSource options;

   public ArgHandlerSource(OptionSource options) {
@@ -44,12 +30,12 @@

   @Override
   public String[] getDefaultArgs() {
- return new String[]{getTag(), OptionSource.DEFAULT_SOURCE_LEVEL.getStringValue()}; + return new String[]{getTag(), SourceLevel.DEFAULT_SOURCE_LEVEL.getStringValue()};
   }

   @Override
   public String getPurpose() {
- return "Specifies Java source level (defaults to " + OptionSource.DEFAULT_SOURCE_LEVEL + ")"; + return "Specifies Java source level (defaults to " + SourceLevel.DEFAULT_SOURCE_LEVEL + ")";
   }

   @Override
@@ -64,7 +50,7 @@

   @Override
   public boolean setString(String value) {
-    SourceLevel level = sourceLevelsByString.get(value);
+    SourceLevel level = SourceLevel.fromString(value);
     if (value == null) {
       System.err.println("Source level must be one of [" +
           Joiner.on(",").join(SourceLevel.values()) + "].");
diff --git a/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java b/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
index 15f238f..d57c7e7 100644
--- a/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
+++ b/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
@@ -20,8 +20,6 @@
  */
 public interface OptionSource {

-  static final SourceLevel DEFAULT_SOURCE_LEVEL = SourceLevel.JAVA6;
-
   SourceLevel getSourceLevel();

   void setSourceLevel(SourceLevel level);
diff --git a/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java b/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
index 63c2fc2..b2d5309 100644
--- a/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
+++ b/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.dev.util.arg;

+import com.google.gwt.util.tools.Utility;
+
 /**
  * Java source level compatibility constants.
  * Java versions range from 1.0 to 1.7.
@@ -23,8 +25,13 @@
  * Both names can be used indistinctly.
  */
 public enum SourceLevel {
+  // Source levels must appear in ascending order in order.
   JAVA6("1.6", "6"),
   JAVA7("1.7", "7");
+  /**
+ * The default GWT source level is the one that matches best that of the runtime environment.
+   */
+  public static final SourceLevel DEFAULT_SOURCE_LEVEL;

   private final String stringValue;
   private final String altStringValue;
@@ -52,4 +59,37 @@
   public String toString() {
     return stringValue;
   }
+
+  static {
+    SourceLevel result = SourceLevel.values()[0];
+ String javaSpecLevel = System.getProperty("java.specification.version");
+    try {
+      for (SourceLevel sourceLevel : SourceLevel.values()) {
+ if (Utility.versionCompare(javaSpecLevel, sourceLevel.stringValue)
= 0) {
+          result = sourceLevel;
+        }
+      }
+    } catch (IllegalArgumentException e) {
+    }
+
+    DEFAULT_SOURCE_LEVEL = result;
+  }
+
+  /**
+ * Returns the SourceLevel given the string or alternate string representation;
+   * returns {@code null} if none is found.
+   */
+  public static SourceLevel fromString(String sourceLevelString) {
+    if (sourceLevelString == null) {
+      return null;
+    }
+    for (SourceLevel sourceLevel : SourceLevel.values()) {
+      if (sourceLevel.stringValue.equals(sourceLevelString) ||
+          sourceLevel.altStringValue.equals(sourceLevelString)) {
+        return sourceLevel;
+      }
+    }
+    return null;
+  }
+
 }
diff --git a/dev/core/src/com/google/gwt/util/tools/Utility.java b/dev/core/src/com/google/gwt/util/tools/Utility.java
index 966be1e..586fe87 100644
--- a/dev/core/src/com/google/gwt/util/tools/Utility.java
+++ b/dev/core/src/com/google/gwt/util/tools/Utility.java
@@ -36,6 +36,8 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;

 /**
  * A smattering of useful functions.
@@ -44,6 +46,15 @@


   private static String sInstallPath = null;
+  /**
+ * A pattern that expresses version strings. It has two groups the prefix (a dotted integer
+   * sequence) and a suffix (a regular string)
+   *
+   * Examples: 1.6.7, 1.2_b10
+   *
+   */
+  private static Pattern versionPattern =
+      Pattern.compile("([0-9]+(?:\\.[0-9]+)*)((?:_[a-zA-Z0-9]+)?)");

   /**
* Helper that ignores exceptions during close, because what are you going to
@@ -375,4 +386,45 @@
     }
   }

+  /**
+   * Handles comparison between version numbers (the right way(TM)).
+   *
+   * Examples of version strings: 1.6.7, 1.2_b10
+   *
+   * @param v1 the first version to compare.
+   * @param v2 the second version to compare.
+ * @return a negative integer, zero, or a positive integer as the first argument is less than,
+   *         equal to, or greater than the second.
+ * @throws IllegalArgumentException if the version number are not proper (i.e. the do not comply
+   *                                  with the following regular expression
+   *                                  [0-9]+(.[0-9]+)*(_[a-zA-Z0-9]+)?
+   */
+  public static int versionCompare(String v1, String v2) {
+    Matcher v1Matcher = versionPattern.matcher(v1);
+    Matcher v2Matcher = versionPattern.matcher(v2);
+    if (!v1Matcher.matches() || !v2Matcher.matches()) {
+ throw new IllegalArgumentException(v1Matcher.matches() ? v2 : v1 + " is not a proper version"
+          + " string");
+    }
+
+    String[] v1Prefix = v1Matcher.group(1).split("\\.");
+    String[] v2Prefix = v2Matcher.group(1).split("\\.");
+    for (int i = 0; i < v1Prefix.length; i++) {
+      if (v2Prefix.length <= i) {
+        return 1; // v1 > v2
+      }
+ int compare = Integer.parseInt(v1Prefix[i]) - Integer.parseInt(v2Prefix[i]);
+      if (compare != 0) {
+        return compare;
+      }
+    }
+    // So far they are equal (or v2 is longer than v1)
+    if (v2Prefix.length == v1Prefix.length) {
+      // then it is up to the suffixes
+      return v1Matcher.group(2).compareTo(v2Matcher.group(2));
+    }
+
+    // v2 is greater than v1,
+    return -1;
+  }
 }
diff --git a/dev/core/test/com/google/gwt/dev/CompilerTest.java b/dev/core/test/com/google/gwt/dev/CompilerTest.java
index fc31312..c297f50 100644
--- a/dev/core/test/com/google/gwt/dev/CompilerTest.java
+++ b/dev/core/test/com/google/gwt/dev/CompilerTest.java
@@ -18,6 +18,7 @@
 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.dev.Compiler.CompilerOptionsImpl;
 import com.google.gwt.dev.jjs.JsOutputOption;
+import com.google.gwt.dev.util.Util;
 import com.google.gwt.dev.util.arg.SourceLevel;

 import java.io.File;
diff --git a/dev/core/test/com/google/gwt/dev/javac/CompilationStateTestBase.java b/dev/core/test/com/google/gwt/dev/javac/CompilationStateTestBase.java
index d909f1c..2abbd3e 100644
--- a/dev/core/test/com/google/gwt/dev/javac/CompilationStateTestBase.java
+++ b/dev/core/test/com/google/gwt/dev/javac/CompilationStateTestBase.java
@@ -22,7 +22,7 @@
 import com.google.gwt.dev.javac.testing.impl.MockResourceOracle;
 import com.google.gwt.dev.resource.Resource;
 import com.google.gwt.dev.util.Util;
-import com.google.gwt.dev.util.arg.OptionSource;
+import com.google.gwt.dev.util.arg.SourceLevel;
 import com.google.gwt.dev.util.log.AbstractTreeLogger;
 import com.google.gwt.dev.util.log.PrintWriterTreeLogger;

@@ -125,7 +125,7 @@
   protected void rebuildCompilationState() {
     try {
state = isolatedBuilder.doBuildFrom(createTreeLogger(), oracle.getResources(), false,
-          OptionSource.DEFAULT_SOURCE_LEVEL);
+          SourceLevel.DEFAULT_SOURCE_LEVEL);
     } catch (UnableToCompleteException e) {
       throw new RuntimeException(e);
     }
diff --git a/dev/core/test/com/google/gwt/dev/jjs/impl/JJSTestBase.java b/dev/core/test/com/google/gwt/dev/jjs/impl/JJSTestBase.java
index a17a51e..7117d29 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/impl/JJSTestBase.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/impl/JJSTestBase.java
@@ -31,7 +31,6 @@
 import com.google.gwt.dev.jjs.ast.JProgram;
 import com.google.gwt.dev.jjs.ast.JVisitor;
 import com.google.gwt.dev.util.Strings;
-import com.google.gwt.dev.util.arg.OptionSource;
 import com.google.gwt.dev.util.arg.SourceLevel;
 import com.google.gwt.dev.util.log.AbstractTreeLogger;
 import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
@@ -305,5 +304,5 @@
   /**
    * Java source level compatibility option.
    */
-  protected SourceLevel sourceLevel = OptionSource.DEFAULT_SOURCE_LEVEL;
+  protected SourceLevel sourceLevel = SourceLevel.DEFAULT_SOURCE_LEVEL;
 }
diff --git a/dev/core/test/com/google/gwt/dev/util/UtilityTest.java b/dev/core/test/com/google/gwt/dev/util/UtilityTest.java
index 4b47ca6..8120815 100644
--- a/dev/core/test/com/google/gwt/dev/util/UtilityTest.java
+++ b/dev/core/test/com/google/gwt/dev/util/UtilityTest.java
@@ -1,11 +1,13 @@
 package com.google.gwt.dev.util;

+import com.google.gwt.util.tools.Utility;
+
 import junit.framework.TestCase;

 import java.net.URL;

 /** Pure junit test of Utility functionality*/
-public class UtilityTest extends TestCase{
+public class UtilityTest extends TestCase {



@@ -20,6 +22,28 @@
     assertEquals(x[0],a);
     assertEquals(x[1],'\u597D');
   }
-
-
+
+
+  public void testVersionNumberComparisons() {
+    assertTrue(Utility.versionCompare("1.4.3.22", "1.04.3.22") == 0);
+    assertTrue(Utility.versionCompare("1.4.3.22.1", "1.4.3.22") > 0);
+    assertTrue(Utility.versionCompare("1.4.3.22.1", "1.4.3.32") < 0);
+    assertTrue(Utility.versionCompare("1.4.3.22", "1.4.3.22.1") < 0);
+    assertTrue(Utility.versionCompare("1.4.3.22.1", "1.4.3.22.2") < 0);
+
+    assertTrue(Utility.versionCompare("1.4.3.22.1_b4", "1.4.3.22_b2") > 0);
+ assertTrue(Utility.versionCompare("1.4.3.22_b11", "01.04.3.22_b1") > 0);
+
+    try {
+      Utility.versionCompare("1.4.3.22.1.dodo", "1.4.3.22.1");
+      fail("Should have trown a IllegalArgumentException") ;
+    } catch (IllegalArgumentException e) {
+    }
+    try {
+      Utility.versionCompare("1.4.3.22.1", "1.4.3.22.1.dodo");
+      fail("Should have trown a IllegalArgumentException");
+    } catch (IllegalArgumentException e) {
+    }
+
+  }
 }
diff --git a/tools/api-checker/config/gwt25_26userApi.conf b/tools/api-checker/config/gwt25_26userApi.conf
index 23bcc69..c151c41 100644
--- a/tools/api-checker/config/gwt25_26userApi.conf
+++ b/tools/api-checker/config/gwt25_26userApi.conf
@@ -2,6 +2,8 @@

 # dirRoot_old is missing because refJars are being supplied
 name_old gwt25userApi
+# GWT 2.5 emulation library does not compile under source level 1.7
+sourceLevel_old 1.6
 #sourceFiles is specified as colon-separated list of files
 sourceFiles_old com/google/gwt\
 :com/google/web\
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java
index 9eb92dc..20cd0c2 100644
--- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiCompatibilityChecker.java
@@ -21,6 +21,7 @@
 import com.google.gwt.dev.javac.Shared;
 import com.google.gwt.dev.resource.Resource;
 import com.google.gwt.dev.util.Util;
+import com.google.gwt.dev.util.arg.SourceLevel;
 import com.google.gwt.dev.util.log.AbstractTreeLogger;
 import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
 import com.google.gwt.util.tools.ArgHandlerFlag;
@@ -526,9 +527,11 @@
.getConfigPropertyAsSet("excludedFiles_new"), logger).getResources()); resources.addAll(checker.getJavaxValidationCompilationUnits(logger));
         resources.addAll(checker.getGwtCompilationUnits(logger));
+        SourceLevel newSourceLevel =
+ SourceLevel.fromString(checker.configProperties.getProperty("sourceLevel_new"));
         newApi =
new ApiContainer(checker.configProperties.getProperty("name_new"), resources,
-                excludedPackages, logger);
+                excludedPackages, logger, newSourceLevel);
         if (checker.printAllApi) {
           logger.log(TreeLogger.INFO, newApi.getApiAsString());
         }
@@ -546,9 +549,11 @@
         }
resources.addAll(checker.getJavaxValidationCompilationUnits(logger));
         resources.addAll(checker.getGwtCompilationUnits(logger));
+        SourceLevel oldSourceLevel =
+ SourceLevel.fromString(checker.configProperties.getProperty("sourceLevel_old"));
         existingApi =
new ApiContainer(checker.configProperties.getProperty("name_old"), resources,
-                excludedPackages, logger);
+                excludedPackages, logger, oldSourceLevel);
         if (checker.printAllApi) {
           logger.log(TreeLogger.INFO, existingApi.getApiAsString());
         }
@@ -858,6 +863,7 @@
sb.append("dirRoot optional argument that specifies the base directory of all other file/directory names\n"); sb.append("sourceFiles a colon-separated list of files/directories that specify the roots of the the filesystem trees to be included.\n"); sb.append("excludeFiles a colon-separated lists of ant patterns to exclude");
+    sb.append("sourceLevel      Java source level compatibility");

     sb.append("\n\n");
     sb.append("Example api.conf file:\n");
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java
index 3e72821..ddc9c97 100644
--- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java +++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiContainer.java
@@ -28,6 +28,7 @@
 import com.google.gwt.dev.javac.JdtCompiler;
 import com.google.gwt.dev.javac.TypeOracleMediatorFromSource;
 import com.google.gwt.dev.resource.Resource;
+import com.google.gwt.dev.util.arg.SourceLevel;

 import java.util.ArrayList;
 import java.util.Arrays;
@@ -50,8 +51,23 @@
   private final Set<String> excludedPackages;
   private final TreeLogger logger;
   private final String name;
-
+  private final SourceLevel sourceLevel;
   private final TypeOracle typeOracle;
+
+
+  /**
+   * A public constructor used for programmatic invocation and testing.
+   *
+   * @param name Api name
+   * @param resources a set of Resources
+   * @param excludedPackages a set of excludedPackages
+   * @param logger TreeLogger for logging messages
+   * @throws UnableToCompleteException if there is a TypeOracle exception
+   */
+ ApiContainer(String name, Set<Resource> resources, Set<String> excludedPackages, TreeLogger logger)
+      throws UnableToCompleteException {
+    this(name, resources, excludedPackages, logger, null);
+  }

   /**
    * A public constructor used for programmatic invocation and testing.
@@ -60,16 +76,19 @@
    * @param resources a set of Resources
    * @param excludedPackages a set of excludedPackages
    * @param logger TreeLogger for logging messages
-   * @throws IllegalArgumentException if one of the arguments is illegal
+   * @param sourceLevel Java source compatibility level
    * @throws UnableToCompleteException if there is a TypeOracle exception
    */
- ApiContainer(String name, Set<Resource> resources, Set<String> excludedPackages, TreeLogger logger) + ApiContainer(String name, Set<Resource> resources, Set<String> excludedPackages, TreeLogger logger,
+      SourceLevel sourceLevel)
       throws UnableToCompleteException {
     this.name = name;
     this.logger = logger;
logger.log(TreeLogger.INFO, "name = " + name + ", builders.size = " + resources.size(), null);
-    this.typeOracle = createTypeOracle(resources);
+ this.sourceLevel = sourceLevel == null ? SourceLevel.DEFAULT_SOURCE_LEVEL : sourceLevel;
+    this.typeOracle = createTypeOracle(resources, this.sourceLevel);
     this.excludedPackages = excludedPackages;
+
     initializeApiPackages();
   }

@@ -178,13 +197,14 @@
     return false;
   }

- private TypeOracle createTypeOracle(Set<Resource> resources) throws UnableToCompleteException { + private TypeOracle createTypeOracle(Set<Resource> resources, SourceLevel sourceLevel)
+      throws UnableToCompleteException {
List<CompilationUnitBuilder> builders = new ArrayList<CompilationUnitBuilder>();
     for (Resource resource : resources) {
CompilationUnitBuilder builder = CompilationUnitBuilder.create(resource);
       builders.add(builder);
     }
-    List<CompilationUnit> units = JdtCompiler.compile(logger, builders);
+ List<CompilationUnit> units = JdtCompiler.compile(logger, builders, sourceLevel);
     boolean anyError = false;
TreeLogger branch = logger.branch(TreeLogger.TRACE, "Checking for compile errors");
     for (CompilationUnit unit : units) {

--
To view, visit https://gwt-review.googlesource.com/2910
To unsubscribe, visit https://gwt-review.googlesource.com/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 8
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jenk...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdemp...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.bro...@gmail.com>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to