Change in gwt[master]: Chooses a default gwt source level to match the current java...

45 views
Skip to first unread message

Roberto Lublinerman

unread,
May 21, 2013, 2:00:30 PM5/21/13
to Matthew Dempsky, Rodrigo Chandia, Goktug Gokdogan, Roberto Lublinerman
Roberto Lublinerman has uploaded a new change for review.

https://gwt-review.googlesource.com/2910


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.

Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
---
M dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
M dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
2 files changed, 42 insertions(+), 1 deletion(-)



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..da05070 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,7 +20,10 @@
*/
public interface OptionSource {

- static final SourceLevel DEFAULT_SOURCE_LEVEL = SourceLevel.JAVA6;
+ /**
+ * The default GWT source level is the one that matches best that of the
runtime environment.
+ */
+ static final SourceLevel DEFAULT_SOURCE_LEVEL =
SourceLevel.getDefaultSourceLevel();

SourceLevel getSourceLevel();

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..230f5a60 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,10 @@
*/
package com.google.gwt.dev.util.arg;

+import com.google.gwt.thirdparty.guava.common.collect.ImmutableMap;
+
+import java.util.Map;
+
/**
* Java source level compatibility constants.
* Java versions range from 1.0 to 1.7.
@@ -28,10 +32,12 @@

private final String stringValue;
private final String altStringValue;
+ private final Double javaLevel;

SourceLevel(String stringValue, String altStringValue) {
this.stringValue = stringValue;
this.altStringValue = altStringValue;
+ this.javaLevel = Double.parseDouble(stringValue);
}

/**
@@ -52,4 +58,36 @@
public String toString() {
return stringValue;
}
+
+ /**
+ * Maps from Java source compatibility level to the GWT compiler Java
source compatibility levels.
+ */
+ private static final Map<Double, SourceLevel> gwtLevelByJavaLevel;
+
+ static {
+ ImmutableMap.Builder<Double, SourceLevel> builder =
ImmutableMap.<Double, SourceLevel>builder();
+ for (SourceLevel sourceLevel : SourceLevel.values()) {
+ builder.put(sourceLevel.javaLevel, sourceLevel);
+ }
+ gwtLevelByJavaLevel = builder.build();
+ }
+
+ /**
+ * Provides a SourceLevel that best matches the runtime environment (to
be used as a default).
+ *
+ * @return a SourceLevel that best matches the Java source level of the
runtime environment.
+ */
+ static SourceLevel getDefaultSourceLevel() {
+ SourceLevel result = SourceLevel.JAVA6;
+ try {
+ double javaSpecLevel =
Double.parseDouble(System.getProperty("java.specification.version"));
+ for (double javaLevel : gwtLevelByJavaLevel.keySet() ) {
+ if (javaSpecLevel >= javaLevel && javaSpecLevel >result.javaLevel)
{
+ result = gwtLevelByJavaLevel.get(javaLevel);
+ }
+ }
+ } catch (NumberFormatException e) {
+ }
+ return result;
+ }
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Roberto Lublinerman

unread,
May 21, 2013, 2:12:20 PM5/21/13
to Roberto Lublinerman, Leeroy Jenkins, Matthew Dempsky
Hello Leeroy Jenkins,

I'd like you to reexamine a change. Please visit

https://gwt-review.googlesource.com/2910

to look at the new patch set (#2).

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.

Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
---
M dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
M dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
2 files changed, 42 insertions(+), 1 deletion(-)


Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 2
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>

Matthew Dempsky

unread,
May 21, 2013, 2:17:36 PM5/21/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins
Matthew Dempsky has posted comments on this change.

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


Patch Set 1:

(1 comment)

....................................................
File dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
Line 83: double javaSpecLevel =
Double.parseDouble(System.getProperty("java.specification.version"));
It looks like java.specification.version will give values like "1.6"
and "1.7", so couldn't you just do a direct string equality comparison
against stringValue instead of needing the Double parsing?

Also, I'd probably just iterate through SourceLevel.values() and try to
match each one. There's not that many SourceLevels currently, so no need
to get fancy with hash maps to optimize it. :)
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-HasComments: Yes

Roberto Lublinerman

unread,
May 21, 2013, 2:40:13 PM5/21/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Roberto Lublinerman has posted comments on this change.

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


Patch Set 2:

I just noticed that the ApiChecker fails if you are running with source
compatibility 7 due to the fact that Enum.java in emul does not compile in
java 7.

I was thinking of updating the old source jar gwt25userApi. It is a minor
update (adds a cast) that does not affect the api in any way:

public final int compareTo(E other) {
// TODO: will a bridge method do the cast for us?
// if (this.getDeclaringClass() != other.getDeclaringClass()) {
// throw new ClassCastException();
// }
- return this.ordinal - other.ordinal;
+ return this.ordinal - ((Enum) other).ordinal;
}

Any thoughts about it?
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 2
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: No

Matthew Dempsky

unread,
May 21, 2013, 3:03:46 PM5/21/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Matthew Dempsky has posted comments on this change.

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


Patch Set 2:

The code should still compile the same as before with either JDK6 or JDK7,
right? If so, I'm okay with making that change to the GWT 2.5.1 reference
jar. People shouldn't really be using that jar for anything else anyway.
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 2
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Roberto Lublinerman

unread,
May 21, 2013, 3:04:58 PM5/21/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Roberto Lublinerman has posted comments on this change.

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


Patch Set 1:

(1 comment)

....................................................
File dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
Line 83: double javaSpecLevel =
Double.parseDouble(System.getProperty("java.specification.version"));
Hashmaps: yes, at fist I was not storing the java version value in the
enum, will remove the hashmap :)

I was trying to make it future proof, i.e. if you are running under 1.8 gwt
should choose 1.7 (the best match) and for that relying in the numerical
ordering seemed appropriate. We could rely on the string ordering and avoid
all parsing, although it is only done once.
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: Yes

Roberto Lublinerman

unread,
May 21, 2013, 3:11:27 PM5/21/13
to Roberto Lublinerman, Leeroy Jenkins, Matthew Dempsky, Thomas Broyer
Hello Leeroy Jenkins,

I'd like you to reexamine a change. Please visit

https://gwt-review.googlesource.com/2910

to look at the new patch set (#3).

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.

Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
---
M dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
M dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
2 files changed, 25 insertions(+), 1 deletion(-)
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 3
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Matthew Dempsky

unread,
May 21, 2013, 3:23:46 PM5/21/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Matthew Dempsky has posted comments on this change.

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


Patch Set 3:

(1 comment)

....................................................
File dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
Line 68: if (javaSpecLevel >= sourceLevel.javaLevel &&
javaSpecLevel > result.javaLevel) {
I think you mean "sourceLevel.javaLevel > result.javaLevel" for the second
conditional?
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 3
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: Yes

Roberto Lublinerman

unread,
May 21, 2013, 7:29:53 PM5/21/13
to Roberto Lublinerman, Leeroy Jenkins, Matthew Dempsky, Thomas Broyer
Hello Leeroy Jenkins,

I'd like you to reexamine a change. Please visit

https://gwt-review.googlesource.com/2910

to look at the new patch set (#4).

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/Util.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/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, 169 insertions(+), 47 deletions(-)
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 4
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Roberto Lublinerman

unread,
May 21, 2013, 7:31:17 PM5/21/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Roberto Lublinerman has posted comments on this change.

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


Patch Set 3:

(1 comment)

....................................................
File dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
Line 68: if (javaSpecLevel >= sourceLevel.javaLevel &&
javaSpecLevel > result.javaLevel) {
Will fix.
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 3
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: Yes

Roberto Lublinerman

unread,
May 24, 2013, 1:05:57 AM5/24/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Roberto Lublinerman has posted comments on this change.

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


Patch Set 4:

@Matthew, I ended up fixing ApiCompatibilityChecker to accept also the java
source level in the configuration file so there is no need now to change
the old file.
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 4
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: No

Roberto Lublinerman

unread,
May 24, 2013, 6:34:11 PM5/24/13
to Roberto Lublinerman, Leeroy Jenkins, Matthew Dempsky, Thomas Broyer
Hello Leeroy Jenkins,

I'd like you to reexamine a change. Please visit

https://gwt-review.googlesource.com/2910

to look at the new patch set (#5).

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/Util.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
19 files changed, 171 insertions(+), 47 deletions(-)
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 5
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Roberto Lublinerman

unread,
May 24, 2013, 6:35:43 PM5/24/13
to Roberto Lublinerman, Leeroy Jenkins, Matthew Dempsky, Thomas Broyer
Hello Leeroy Jenkins,

I'd like you to reexamine a change. Please visit

https://gwt-review.googlesource.com/2910

to look at the new patch set (#6).

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, 169 insertions(+), 47 deletions(-)


Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 6
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Roberto Lublinerman

unread,
May 24, 2013, 6:37:14 PM5/24/13
to Roberto Lublinerman, Leeroy Jenkins, Matthew Dempsky, Thomas Broyer
Hello Leeroy Jenkins,

I'd like you to reexamine a change. Please visit

https://gwt-review.googlesource.com/2910

to look at the new patch set (#7).

Change subject: Chooses a default GWT source level to match the current
java runtime.
......................................................................
18 files changed, 170 insertions(+), 48 deletions(-)
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 7
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Matthew Dempsky

unread,
May 24, 2013, 6:46:28 PM5/24/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Matthew Dempsky has posted comments on this change.

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


Patch Set 4:

(2 comments)

Argh, apparently these comments didn't get posted when I reviewed patch set
5. Frustrating.

....................................................
File dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
Line 30: /**
Nit: Blank line before the javadoc.


Line 67: if (Util.versionCompare(javaSpecLevel,
sourceLevel.stringValue) >= 0) {
I like Util.versionCompare() a lot more than the double parsing from
before. :) [Edit: Renaming to Utility is fine by me too.]

However, the "last match wins" strategy seems to assume that the
SourceLevels will be in increasing order? If so, I think that's worth
adding as a quick comment like "Static initializer for DEFAULT_SOURCE_LEVEL
depends on these being in increasing order" right before JAVA6 and JAVA7
above.
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 4
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: Yes

Matthew Dempsky

unread,
May 24, 2013, 6:48:09 PM5/24/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Matthew Dempsky has posted comments on this change.

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


Patch Set 7: Code-Review+2

Nice.
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 7
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: No

Roberto Lublinerman

unread,
May 26, 2013, 5:42:56 AM5/26/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Hello Matthew Dempsky, Leeroy Jenkins,

I'd like you to reexamine a change. Please visit

https://gwt-review.googlesource.com/2910

to look at the new patch set (#8).

Change subject: Chooses a default GWT source level to match the current
java runtime.
......................................................................
18 files changed, 171 insertions(+), 48 deletions(-)
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 8
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

Roberto Lublinerman

unread,
May 26, 2013, 5:53:15 AM5/26/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Roberto Lublinerman has posted comments on this change.

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


Patch Set 8: Code-Review+2

Patch is the same as #7 approved by mdempsky. Only added a comment.
Gerrit-MessageType: comment
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 8
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jen...@gwtproject.org>
Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
Gerrit-Reviewer: Roberto Lublinerman <rlu...@google.com>
Gerrit-Reviewer: Thomas Broyer <t.br...@gmail.com>
Gerrit-HasComments: No

Roberto Lublinerman

unread,
May 26, 2013, 5:53:21 AM5/26/13
to Roberto Lublinerman, Matthew Dempsky, Leeroy Jenkins, Thomas Broyer
Roberto Lublinerman has submitted this change and it was merged.

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

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) {
Gerrit-MessageType: merged
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 8
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>
Reply all
Reply to author
Forward
0 new messages