Skip to content

Commit

Permalink
Fix for ceylon/ceylon-compiler#638: detect Java 7
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Jun 19, 2012
1 parent 79fe2ef commit afbfdc9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
19 changes: 19 additions & 0 deletions bootstrap/src/main/java/ceylon/modules/bootstrap/Java7Checker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ceylon.modules.bootstrap;

public class Java7Checker {

public static void check() {
String version = System.getProperty("java.version");
if(version == null || version.isEmpty()){
System.err.println("Unable to determine Java version (java.version property missing or empty). Aborting.");
System.exit(1);
}
if(!version.startsWith("1.7")){
System.err.println("Your Java version is not supported: "+version);
System.err.println("Ceylon needs Java 7. Please install it from http://www.java.com");
System.err.println("Aborting.");
System.exit(1);
}
}

}
8 changes: 8 additions & 0 deletions bootstrap/src/main/java/ceylon/modules/bootstrap/Main5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ceylon.modules.bootstrap;

public class Main5 {
public static void main(String[] args) throws Throwable{
Java7Checker.check();
org.jboss.modules.Main.main(args);
}
}
19 changes: 18 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<property name="runtime-api.src" location="${basedir}/api/src/main/java"/>
<property name="runtime-impl.src" location="${basedir}/impl/src/main/java"/>
<property name="runtime-spi.src" location="${basedir}/spi/src/main/java"/>
<property name="runtime-bootstrap.src" location="${basedir}/bootstrap/src/main/java"/>

<!-- jar generated -->
<property name="bootstrap.jar" value="ceylon-runtime-bootstrap.jar"/>
Expand Down Expand Up @@ -102,6 +103,7 @@
<!-- Rule to clean everything up -->
<target name="clean" description="Clean up everything">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}/lib"/>
</target>

<target name="dist"
Expand Down Expand Up @@ -162,10 +164,25 @@
<target name="bootstrap.classes">
<mkdir dir="${build.bootstrap}"/>
<javac debug="true"
srcdir="${runtime-spi.src}"
srcdir="${runtime-bootstrap.src}"
destdir="${build.bootstrap}"
classpathref="compiler.classpath"
includeantruntime="false"/>
<!-- Need an extra pass for Java 7 testing -->
<delete dir="${build.bootstrap}">
<include name="**/*Main5.class"/>
<include name="**/Java7Checker.class"/>
</delete>
<javac debug="true"
srcdir="${runtime-bootstrap.src}"
destdir="${build.bootstrap}"
classpathref="compiler.classpath"
source="1.5"
target="1.5"
includeantruntime="false">
<include name="**/*Main5.java"/>
<include name="**/Java7Checker.java"/>
</javac>
</target>

<!-- Rule to build runtime jar -->
Expand Down
2 changes: 1 addition & 1 deletion dist/bin/ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUNTIME_REPO="$CEYLON_HOME/runtime-repo"
java \
-cp $LIB/jboss-modules.jar:$LIB/ceylon-runtime-bootstrap.jar \
"-Dcelon.home=$CEYLON_HOME" \
org.jboss.modules.Main \
ceylon.modules.bootstrap.Main5 \
-mp $RUNTIME_REPO ceylon.runtime \
+executable ceylon.modules.jboss.runtime.JBossRuntime \
$@
2 changes: 1 addition & 1 deletion dist/bin/ceylon.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set "RUNTIME_REPO=%CEYLON_HOME%\runtime-repo"
"%JAVA%" ^
-cp "%LIB%\jboss-modules.jar;%LIB%\ceylon-runtime-bootstrap.jar" ^
"-Dceylon.home=%CEYLON_HOME%" ^
org.jboss.modules.Main ^
ceylon.modules.bootstrap.Main5 ^
-mp "%RUNTIME_REPO%" ceylon.runtime ^
+executable ceylon.modules.jboss.runtime.JBossRuntime ^
%ARGS%
Expand Down

13 comments on commit afbfdc9

@alesj
Copy link
Member

@alesj alesj commented on afbfdc9 Jun 25, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need JDK7?
We have it working on OpenShift, which only has JDK6.

@gavinking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need JDK7?

It's an interesting question. I'm not sure if the language module needs it. Certainly ceylon.file needs it. And the neither the compiler nor IDE will run on Java 6.

@chochos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can't update the web runner anymore. AFAIK the compiler is the only one which really requires Java 7 (don't know why though); but since ceylon-js now uses code that's in ceylon-compiler, we need to use java 7 as well, and the web runner depends on ceylon-js, so...

A solution would be to move some of that code from ceylon-compiler to either ceylon-common or to the CMR (actually what ceylon-js uses from ceylon-compiler are some convenience methods to use the CMR so it would make sense to move them to CMR; if ceylon-js doesn't depend on ceylon-compiler anymore, then we can have a build of all the required projects for the web runner using Java 6 and update it).

@gavinking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's really the case that the web runner can't be updated to Ceylon M3 (I had thought that it was possible to install Java 7 on OpenShift), then we should take it offline for now. I mean we should do that right now, before people get the wrong impression about the JS compiler.

@alesj
Copy link
Member

@alesj alesj commented on afbfdc9 Jun 25, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought that it was possible to install Java 7 on OpenShift

Hmmm, I think it needs to be a decision made by the OpenShift guys.
Afaik, it's not something a user can do.

But we have the Ceylon servlet approach working on OpenShift:

--- from recent email discussion ---

ceylonc passes parameters to javac.

This is the command I use to compile Ceylon sources on OpenShift.

${CEYLON_HOME}bin/ceylonc -target 1.6 -source 1.6 -src ${ceyonSrc} -rep ${CEYLON_RUNTIME_REPO} -out ${CEYLON_RUNTIME_REPO} ${srcFilesInLine}

I'm not sure if everything works correct, simple examples that I tried are working.

Afair, it can actually run on JDK6 as well, you just need to configure it properly?
(compile compiler with 1.6 flag)


@tombentley
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's correct that ceylonc will pass the -target (and -source) options on the javac, so that should indeed work currently even though it's not really documented or tested.

There are some places where we'd like to start using 1.7 features in the emitted bytecode though:

  • It should be possible to add default members to interfaces without breaking implementors, which would require using invokedynamic
  • As I recall, try with resources (if we end up implementing it) would be much easier using Java 7 improved try.

Does anyone know when OpenShift might start supporting Java 7?

@quintesse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tombentley Take a look at this blog http://datumedge.blogspot.co.uk/2012/06/java-8-lambdas.html?m=1, it talks a bit about default implementations on interfaces for Java 8 and has pointers to articles to go more in depth. Maybe there's something interesting there?

@tombentley
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was meaning to push my 'indy' branch to github (though not merge it yet) after we got M3 out, because then we'd at least be able to experiment with invokedynamic. But it needs a bit of tidy up first, so if it turns out we need to be targetting java 6 bytecode then it can wait.

@quintesse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I'm not sure we should be targeting JDK6, especially if it means not being able to use any new features that we might need/want.

@quintesse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the JDK6 is an OpenShift limitation, if there's no way to get around that we might just have to look for other hosting options.

@gavinking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As several people pointed out to me, it's not just OpenShift. GAE has the same limitation.

@chochos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys, ceylon-js and ceylon-spec and ceylon.language compile fine in JDK 6. The only project that really requires JDK 7 is ceylon-compiler. The problem is that ceylon-js now depends on ceylon-compiler because it uses some convenience methods that I found there to use the CMR. If we move that CMR-related code to the CMR (I don't know why it wasn't there in the first place), then we can eliminate this dependency and then make a build of ceylon-spec, ceylon.language and ceylon-js on JDK 6 to update the web runner. I don't want to do this all by myself because I don't know how much shit will break if I move that code and I don't want to make a copy; it should be a clean refactoring so if someone can help me move at least those two methods I use from com.redhat.ceylon.compiler.java.util.Util (makeRepositoryManager and makeOutputRepositoryManager) to the CMR where I believe they belong, we'll be on our way to updating the web runner.

@FroMage
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OpenShift guys told us it's easy for us to add a cartridge for Java 7. @alesj said he had someone working on this too, so I expect this issue to be resolved soon.

Please sign in to comment.