diff --git a/compiler/tests/org/jetbrains/jet/CompileBuiltinsTest.java b/compiler/tests/org/jetbrains/jet/CompileBuiltinsTest.java deleted file mode 100644 index 8a34e5db9c8..00000000000 --- a/compiler/tests/org/jetbrains/jet/CompileBuiltinsTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet; - -import org.jetbrains.jet.cli.KotlinCompiler; -import org.junit.Test; - -/** - * @author Stepan Koltsov - */ -public class CompileBuiltinsTest extends TestCaseWithTmpdirIndependentFromIdea { - - @Test - public void compile() { - KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec( - System.err, "-output", tmpdir.getPath(), "-src", "./compiler/frontend/src", "-mode", "builtins"); - if (exitCode != KotlinCompiler.ExitCode.OK) { - throw new IllegalStateException("jdk headers compilation failed: " + exitCode); - } - } -} diff --git a/compiler/tests/org/jetbrains/jet/CompileStdlibTest.java b/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java similarity index 65% rename from compiler/tests/org/jetbrains/jet/CompileStdlibTest.java rename to compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java index 4978cdc4737..8e69566607e 100644 --- a/compiler/tests/org/jetbrains/jet/CompileStdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/CompileCompilerDependenciesTest.java @@ -16,16 +16,28 @@ package org.jetbrains.jet; +import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileBuiltins; +import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileJdkHeaders; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; import org.junit.Test; /** * @author Stepan Koltsov */ -public class CompileStdlibTest { +public class CompileCompilerDependenciesTest { @Test - public void compile() { + public void compileBuiltins() { + ForTestCompileBuiltins.builtinsJarForTests(); + } + + @Test + public void compileJdkHeaders() { + ForTestCompileJdkHeaders.jdkHeadersForTests(); + } + + @Test + public void compileRuntime() { ForTestCompileRuntime.runtimeJarForTests(); } diff --git a/compiler/tests/org/jetbrains/jet/CompileJdkHeadersTest.java b/compiler/tests/org/jetbrains/jet/CompileJdkHeadersTest.java deleted file mode 100644 index eff01db9a6a..00000000000 --- a/compiler/tests/org/jetbrains/jet/CompileJdkHeadersTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet; - -import org.jetbrains.jet.cli.KotlinCompiler; -import org.junit.Test; - -/** - * @author Stepan Koltsov - */ -public class CompileJdkHeadersTest extends TestCaseWithTmpdirIndependentFromIdea { - - @Test - public void compile() { - KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec( - System.err, "-output", tmpdir.getPath(), "-src", "./jdk-headers/src", "-mode", "jdkHeaders"); - if (exitCode != KotlinCompiler.ExitCode.OK) { - throw new IllegalStateException("jdk headers compilation failed: " + exitCode); - } - } -} diff --git a/compiler/tests/org/jetbrains/jet/TestCaseWithTmpdirIndependentFromIdea.java b/compiler/tests/org/jetbrains/jet/TestCaseWithTmpdirIndependentFromIdea.java index 8693fb52c7b..890e070b3d8 100644 --- a/compiler/tests/org/jetbrains/jet/TestCaseWithTmpdirIndependentFromIdea.java +++ b/compiler/tests/org/jetbrains/jet/TestCaseWithTmpdirIndependentFromIdea.java @@ -30,7 +30,7 @@ public abstract class TestCaseWithTmpdirIndependentFromIdea { @Before public void before() throws Exception { - tmpdir = JetTestUtils.tmpDir(CompileJdkHeadersTest.class.getName()); + tmpdir = JetTestUtils.tmpDir(TestCaseWithTmpdirIndependentFromIdea.class.getName()); } @After diff --git a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileBuiltins.java b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileBuiltins.java new file mode 100644 index 00000000000..717df3be623 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileBuiltins.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.codegen.forTestCompile; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.KotlinCompiler; + +import java.io.File; + +/** + * @author Stepan Koltsov + */ +public class ForTestCompileBuiltins { + + private ForTestCompileBuiltins() { + } + + private static class Builtins extends ForTestCompileSomething { + + Builtins() { + super("builtins"); + } + + @Override + protected void doCompile(@NotNull File classesDir) throws Exception { + KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec( + System.err, "-output", classesDir.getPath(), "-src", "./compiler/frontend/src", "-mode", "builtins"); + if (exitCode != KotlinCompiler.ExitCode.OK) { + throw new IllegalStateException("jdk headers compilation failed: " + exitCode); + } + } + + private static final Builtins builtins = new Builtins(); + } + + @NotNull + public static File builtinsJarForTests() { + return Builtins.builtins.getJarFile(); + } +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileJdkHeaders.java b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileJdkHeaders.java new file mode 100644 index 00000000000..b12d967c733 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileJdkHeaders.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.codegen.forTestCompile; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.KotlinCompiler; + +import java.io.File; + +/** + * @author Stepan Koltsov + */ +public class ForTestCompileJdkHeaders { + + private ForTestCompileJdkHeaders() { + } + + private static class JdkHeaders extends ForTestCompileSomething { + + JdkHeaders() { + super("jdkHeaders"); + } + + @Override + protected void doCompile(@NotNull File classesDir) throws Exception { + KotlinCompiler.ExitCode exitCode = new KotlinCompiler().exec( + System.err, "-output", classesDir.getPath(), "-src", "./jdk-headers/src", "-mode", "jdkHeaders"); + if (exitCode != KotlinCompiler.ExitCode.OK) { + throw new IllegalStateException("jdk headers compilation failed: " + exitCode); + } + } + + private static final JdkHeaders jdkHeaders = new JdkHeaders(); + } + + @NotNull + public static File jdkHeadersForTests() { + return JdkHeaders.jdkHeaders.getJarFile(); + } +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java index 93c7716fad4..d7d5c37bf02 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java +++ b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileRuntime.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.codegen.forTestCompile; import com.google.common.io.Files; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.cli.KotlinCompiler; import org.junit.Assert; @@ -43,57 +44,21 @@ import java.util.jar.JarOutputStream; * @author Stepan Koltsov */ public class ForTestCompileRuntime { - private static File runtimeJarFile; private ForTestCompileRuntime() { } - private static File doCompile() throws Exception { - File tmpDir = JetTestUtils.tmpDir("runtimejar"); - - File jarFile = new File(tmpDir, "runtime.jar"); - - File classesDir = new File(tmpDir, "classes"); - - FileUtil.createParentDirs(new File(classesDir, "dummy")); - compileJavaPartOfBuiltins(classesDir); - compileStdlib(classesDir); - - FileOutputStream stdlibJar = new FileOutputStream(jarFile); - try { - JarOutputStream jarOutputStream = new JarOutputStream(stdlibJar); - try { - copyToJar(classesDir, jarOutputStream); - } - finally { - jarOutputStream.close(); - } + private static class Runtime extends ForTestCompileSomething { + private Runtime() { + super("runtime"); } - finally { - stdlibJar.close(); - } - - FileUtil.delete(classesDir); - return jarFile; - } - private static void copyToJar(File root, JarOutputStream os) throws IOException { - Stack> toCopy = new Stack>(); - toCopy.add(new Pair("", root)); - while (!toCopy.empty()) { - Pair pop = toCopy.pop(); - File file = pop.getSecond(); - if (file.isFile()) { - os.putNextEntry(new JarEntry(pop.getFirst())); - Files.copy(file, os); - } else if (file.isDirectory()) { - for (File child : file.listFiles()) { - String path = pop.getFirst().isEmpty() ? child.getName() : pop.getFirst() + "/" + child.getName(); - toCopy.add(new Pair(path, child)); - } - } else { - throw new IllegalStateException(); - } + private static final Runtime runtime = new Runtime(); + + @Override + protected void doCompile(@NotNull File classesDir) throws Exception { + compileJavaPartOfBuiltins(classesDir); + compileStdlib(classesDir); } } @@ -142,24 +107,9 @@ public class ForTestCompileRuntime { } - private static Throwable compilationException; - + @NotNull public static File runtimeJarForTests() { - synchronized (ForTestCompileRuntime.class) { - if (compilationException != null) { - throw new RuntimeException("runtime compilation failed in previous tests: " + compilationException, compilationException); - } - if (runtimeJarFile == null || !runtimeJarFile.exists()) { - try { - runtimeJarFile = doCompile(); - } catch (Throwable e) { - compilationException = e; - throw new RuntimeException(e); - } - } - return runtimeJarFile; - } - + return Runtime.runtime.getJarFile(); } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileSomething.java b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileSomething.java new file mode 100644 index 00000000000..ed732a88a5a --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/codegen/forTestCompile/ForTestCompileSomething.java @@ -0,0 +1,104 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.codegen.forTestCompile; + +import com.google.common.io.Files; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.JetTestUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Stack; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; + +/** + * @author Stepan Koltsov + */ +abstract class ForTestCompileSomething { + + @NotNull + private final String jarName; + private Throwable error; + private File jarFile; + + ForTestCompileSomething(@NotNull String jarName) { + this.jarName = jarName; + try { + File tmpDir = JetTestUtils.tmpDir("runtimejar"); + + jarFile = new File(tmpDir, "runtime.jar"); + + File classesDir = new File(tmpDir, "classes"); + + FileUtil.createParentDirs(new File(classesDir, "dummy")); + + doCompile(classesDir); + + FileOutputStream stdlibJar = new FileOutputStream(jarFile); + try { + JarOutputStream jarOutputStream = new JarOutputStream(stdlibJar); + try { + copyToJar(classesDir, jarOutputStream); + } + finally { + jarOutputStream.close(); + } + } + finally { + stdlibJar.close(); + } + + FileUtil.delete(classesDir); + } catch (Throwable e) { + error = e; + } + } + + private static void copyToJar(File root, JarOutputStream os) throws IOException { + Stack> toCopy = new Stack>(); + toCopy.add(new Pair("", root)); + while (!toCopy.empty()) { + Pair pop = toCopy.pop(); + File file = pop.getSecond(); + if (file.isFile()) { + os.putNextEntry(new JarEntry(pop.getFirst())); + Files.copy(file, os); + } else if (file.isDirectory()) { + for (File child : file.listFiles()) { + String path = pop.getFirst().isEmpty() ? child.getName() : pop.getFirst() + "/" + child.getName(); + toCopy.add(new Pair(path, child)); + } + } else { + throw new IllegalStateException(); + } + } + } + + protected abstract void doCompile(@NotNull File classesDir) throws Exception; + + @NotNull + public File getJarFile() { + if (error != null) { + throw new IllegalStateException("compilation of " + jarName + " failed: " + error, error); + } + return jarFile; + } +}