From 4fa75f34f8bcdd9d8df17c56acb60e6a13c71b93 Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 16:09:55 -0400 Subject: [PATCH 1/9] Compiles but cannot compile any kotline code --- blaze-kotlin/pom.xml | 2 +- .../kotlin/CountingSLF4JMessageCollector.java | 35 +++++++++++++++++-- .../fizzed/blaze/kotlin/Kotlin1Compiler.java | 30 +++++++++------- pom.xml | 6 ++-- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/blaze-kotlin/pom.xml b/blaze-kotlin/pom.xml index 48d8e35c..56b42187 100644 --- a/blaze-kotlin/pom.xml +++ b/blaze-kotlin/pom.xml @@ -30,7 +30,7 @@ org.jetbrains.kotlin - kotlin-runtime + kotlin-stdlib diff --git a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/CountingSLF4JMessageCollector.java b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/CountingSLF4JMessageCollector.java index 9016caf5..e49dfee9 100644 --- a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/CountingSLF4JMessageCollector.java +++ b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/CountingSLF4JMessageCollector.java @@ -16,8 +16,12 @@ package com.fizzed.blaze.kotlin; import java.util.concurrent.atomic.AtomicInteger; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation; import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity; +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation; import org.jetbrains.kotlin.cli.common.messages.MessageCollector; import org.slf4j.Logger; @@ -46,7 +50,7 @@ public int getWarnings() { return warnings.get(); } - @Override + /*@Override public void report(CompilerMessageSeverity severity, String message, CompilerMessageLocation location) { switch (severity) { case INFO: @@ -62,6 +66,33 @@ public void report(CompilerMessageSeverity severity, String message, CompilerMes this.logger.error("{} @ {}", message, location); break; } + }*/ + + @Override + public void clear() { + + } + + @Override + public boolean hasErrors() { + return false; + } + + @Override + public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageSourceLocation location) { + switch (severity) { + case INFO: + this.logger.info("{} @ {}", message, location); + break; + case WARNING: + this.warnings.incrementAndGet(); + this.logger.warn("{} @ {}", message, location); + break; + case ERROR: + case EXCEPTION: + this.errors.incrementAndGet(); + this.logger.error("{} @ {}", message, location); + break; + } } - } diff --git a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java index 46965ff0..1291bd28 100644 --- a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java +++ b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java @@ -17,24 +17,24 @@ import com.fizzed.blaze.core.CompilationException; import com.fizzed.blaze.internal.ClassLoaderHelper; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.util.Disposer; import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys; +import org.jetbrains.kotlin.cli.common.config.ContentRootsKt; import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt; -import org.jetbrains.kotlin.cli.jvm.config.JVMConfigurationKeys; +import org.jetbrains.kotlin.com.intellij.openapi.Disposable; +import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer; +import org.jetbrains.kotlin.config.CommonConfigurationKeys; import org.jetbrains.kotlin.config.CompilerConfiguration; -import org.jetbrains.kotlin.config.ContentRootsKt; +import org.jetbrains.kotlin.config.JVMConfigurationKeys; import org.jetbrains.kotlin.utils.PathUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import java.nio.file.Path; import java.util.ArrayList; -import org.jetbrains.kotlin.config.CommonConfigurationKeys; -import org.jetbrains.kotlin.load.java.JvmAbi; -import org.jetbrains.kotlin.script.StandardScriptDefinition; +import java.util.Collections; /** * Compiles .kt and .kts files to .class files that are saved on the filesystem @@ -61,23 +61,27 @@ public void compile(Path file, Path classesDir, boolean isScript) throws Compila // build kotline compiler configuration CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector); - compilerConfiguration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME); - JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, PathUtil.getJdkClassesRoots()); + //compilerConfiguration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME); + JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, PathUtil.getJdkClassesRootsFromCurrentJre()); JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, ClassLoaderHelper.buildClassPathAsFiles(classLoader)); ContentRootsKt.addKotlinSourceRoot(compilerConfiguration, file.toAbsolutePath().toString()); // NOTE: Kotlin v1.0.2+ moved this config key around and will break // when we bump up the version down the road. Kotlin is a moving target // with changing how its compiler internally is called - compilerConfiguration.add(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY, StandardScriptDefinition.INSTANCE); - + //compilerConfiguration.add(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY, StandardScriptDefinition.INSTANCE); + + compilerConfiguration.put(JVMConfigurationKeys.FRIEND_PATHS, new ArrayList<>()); + compilerConfiguration.put(CommonConfigurationKeys.MODULE_NAME, "blaze"); + Disposable disposable = Disposer.newDisposable(); try { KotlinCoreEnvironment env = KotlinCoreEnvironment.createForProduction( disposable, compilerConfiguration, EnvironmentConfigFiles.JVM_CONFIG_FILES); + + env.addKotlinSourceRoots(Collections.singletonList(file.toAbsolutePath().toFile())); boolean compiled = - KotlinToJVMBytecodeCompiler.INSTANCE.compileBunchOfSources( - env, null, classesDir.toFile(), new ArrayList<>(), false); + KotlinToJVMBytecodeCompiler.INSTANCE.compileBunchOfSources(env); if (!compiled) { throw new CompilationException("Unable to cleanly compile " + file diff --git a/pom.xml b/pom.xml index 3bcee3c2..023f3fb0 100644 --- a/pom.xml +++ b/pom.xml @@ -181,13 +181,13 @@ org.jetbrains.kotlin kotlin-compiler-embeddable - 1.0.2 + 1.9.10 org.jetbrains.kotlin - kotlin-runtime - 1.0.2 + kotlin-stdlib + 1.9.10 From 2d6ad39275be3421daf5980c23569d0c8757b687 Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 16:33:48 -0400 Subject: [PATCH 2/9] Working version on Java 8! --- .../fizzed/blaze/kotlin/Kotlin1Compiler.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java index 1291bd28..daf5c638 100644 --- a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java +++ b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java @@ -32,9 +32,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; /** * Compiles .kt and .kts files to .class files that are saved on the filesystem @@ -62,16 +69,37 @@ public void compile(Path file, Path classesDir, boolean isScript) throws Compila CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector); //compilerConfiguration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME); - JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, PathUtil.getJdkClassesRootsFromCurrentJre()); + + List jdkClassesRootsFromCurrentJre = PathUtil.getJdkClassesRootsFromCurrentJre(); + System.out.println("jdkClassesRootsFromCurrentJre: " + jdkClassesRootsFromCurrentJre); + + List jvmClassPath = ClassLoaderHelper.buildJvmClassPath(); + System.out.println("jvmClassPath: " + jvmClassPath); + + List modFiles; + try { + modFiles = Files.list(Paths.get("/usr/lib/jvm/current/jmods/")) + .map(v -> v.toFile()) + .collect(Collectors.toList()); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, modFiles); + + JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, jdkClassesRootsFromCurrentJre); JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, ClassLoaderHelper.buildClassPathAsFiles(classLoader)); + JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, ClassLoaderHelper.buildJvmClassPath()); ContentRootsKt.addKotlinSourceRoot(compilerConfiguration, file.toAbsolutePath().toString()); // NOTE: Kotlin v1.0.2+ moved this config key around and will break // when we bump up the version down the road. Kotlin is a moving target // with changing how its compiler internally is called //compilerConfiguration.add(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY, StandardScriptDefinition.INSTANCE); + //List classRoots = PathUtil.getJdkClassesRootsFromCurrentJre().stream().map(v -> v.toString()).collect(Collectors.toList()); + compilerConfiguration.put(JVMConfigurationKeys.FRIEND_PATHS, new ArrayList<>()); compilerConfiguration.put(CommonConfigurationKeys.MODULE_NAME, "blaze"); + compilerConfiguration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, classesDir.toFile()); Disposable disposable = Disposer.newDisposable(); try { From 674b752e2f9fe6f07a4ae1e87cc1941e4006b07d Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 16:35:51 -0400 Subject: [PATCH 3/9] More log output --- .../src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java index daf5c638..45be4775 100644 --- a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java +++ b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java @@ -81,6 +81,7 @@ public void compile(Path file, Path classesDir, boolean isScript) throws Compila modFiles = Files.list(Paths.get("/usr/lib/jvm/current/jmods/")) .map(v -> v.toFile()) .collect(Collectors.toList()); + System.out.println("modFiles: " + modFiles); } catch (IOException e) { throw new UncheckedIOException(e); } From 493a9e985d8c0b2f6770b34c3a2fe09cfb80b700 Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 17:08:41 -0400 Subject: [PATCH 4/9] Working version of kotlin --- .../com/fizzed/blaze/kotlin/Kotlin1Compiler.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java index 45be4775..6b6e4934 100644 --- a/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java +++ b/blaze-kotlin/src/main/java/com/fizzed/blaze/kotlin/Kotlin1Compiler.java @@ -70,13 +70,13 @@ public void compile(Path file, Path classesDir, boolean isScript) throws Compila compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector); //compilerConfiguration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME); - List jdkClassesRootsFromCurrentJre = PathUtil.getJdkClassesRootsFromCurrentJre(); + /*List jdkClassesRootsFromCurrentJre = ; System.out.println("jdkClassesRootsFromCurrentJre: " + jdkClassesRootsFromCurrentJre); List jvmClassPath = ClassLoaderHelper.buildJvmClassPath(); - System.out.println("jvmClassPath: " + jvmClassPath); + System.out.println("jvmClassPath: " + jvmClassPath);*/ - List modFiles; + /*List modFiles; try { modFiles = Files.list(Paths.get("/usr/lib/jvm/current/jmods/")) .map(v -> v.toFile()) @@ -85,9 +85,10 @@ public void compile(Path file, Path classesDir, boolean isScript) throws Compila } catch (IOException e) { throw new UncheckedIOException(e); } - JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, modFiles); + JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, modFiles);*/ - JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, jdkClassesRootsFromCurrentJre); + // java 8 requires this for its .jars to compile kotlin, for anything else only the "JDK_HOME" set below was key + JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, PathUtil.getJdkClassesRootsFromCurrentJre()); JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, ClassLoaderHelper.buildClassPathAsFiles(classLoader)); JvmContentRootsKt.addJvmClasspathRoots(compilerConfiguration, ClassLoaderHelper.buildJvmClassPath()); ContentRootsKt.addKotlinSourceRoot(compilerConfiguration, file.toAbsolutePath().toString()); @@ -101,6 +102,9 @@ public void compile(Path file, Path classesDir, boolean isScript) throws Compila compilerConfiguration.put(JVMConfigurationKeys.FRIEND_PATHS, new ArrayList<>()); compilerConfiguration.put(CommonConfigurationKeys.MODULE_NAME, "blaze"); compilerConfiguration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, classesDir.toFile()); +// compilerConfiguration.put(JVMConfigurationKeys.JDK_HOME, Paths.get("/usr/lib/jvm/current").toFile()); + // java 9, 11+ this is apparently needed for a "modular" jdk + compilerConfiguration.put(JVMConfigurationKeys.JDK_HOME, Paths.get(System.getProperty("java.home")).toFile()); Disposable disposable = Disposer.newDisposable(); try { From f390ae27e0eca4456b898e57017c9293f3f35b0d Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 18:30:55 -0400 Subject: [PATCH 5/9] Fixed unit tests for kotlin and java engines --- .../com/fizzed/blaze/util/BlazeRunner.java | 59 ++++++++ .../fizzed/blaze/jdk/BlazeJdkEngineTest.java | 128 +++++++----------- blaze-kotlin/pom.xml | 1 + .../blaze/kotlin/BlazeKotlinEngineTest.java | 96 +++++-------- .../java/com/fizzed/blaze/kotlin/TryIt.java | 2 +- .../src/test/resources/kotlin/hello.kt | 7 + .../src/test/resources/kotlin/hello.kts | 5 - pom.xml | 2 +- 8 files changed, 153 insertions(+), 147 deletions(-) create mode 100644 blaze-core/src/main/java/com/fizzed/blaze/util/BlazeRunner.java create mode 100755 blaze-kotlin/src/test/resources/kotlin/hello.kt delete mode 100755 blaze-kotlin/src/test/resources/kotlin/hello.kts diff --git a/blaze-core/src/main/java/com/fizzed/blaze/util/BlazeRunner.java b/blaze-core/src/main/java/com/fizzed/blaze/util/BlazeRunner.java new file mode 100644 index 00000000..17560b9d --- /dev/null +++ b/blaze-core/src/main/java/com/fizzed/blaze/util/BlazeRunner.java @@ -0,0 +1,59 @@ +package com.fizzed.blaze.util; + +import org.zeroturnaround.exec.ProcessExecutor; +import org.zeroturnaround.exec.ProcessResult; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class BlazeRunner { + + static public ProcessResult invokeWithCurrentJvmHome(File blazeScriptFile, List blazeArgs, List scriptArgs) throws IOException, InterruptedException, TimeoutException { + return invokeWithCurrentJvmHome(blazeScriptFile, blazeArgs, scriptArgs, null); + } + + static public ProcessResult invokeWithCurrentJvmHome(File blazeScriptFile, List blazeArgs, List scriptArgs, File workingDirectory) throws IOException, InterruptedException, TimeoutException { + // get current classpath + String classpath = System.getProperty("java.class.path"); + + // build a temporary home directory (that classes will be compiled to) + //Path tempHomeDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("blaze-test-"+ UUID.randomUUID()); + //Files.createDirectories(tempHomeDir); + try { + final List commands = new ArrayList<>(); + + commands.add("java"); + commands.add("-cp"); + commands.add(classpath); + commands.add(com.fizzed.blaze.cli.Bootstrap.class.getCanonicalName()); + + if (blazeArgs != null) { + commands.addAll(blazeArgs); + } + + if (blazeScriptFile != null) { + commands.add(blazeScriptFile.getAbsolutePath()); + } + + if (scriptArgs != null) { + commands.addAll(scriptArgs); + } + + return new ProcessExecutor() + .command(commands) + .redirectOutput(System.out) + .readOutput(true) + .directory(workingDirectory) + //.environment("HOME", tempHomeDir.toAbsolutePath().toString()) + .timeout(10, TimeUnit.SECONDS) + .execute(); + } finally { + //Systems.remove(tempHomeDir).recursive().force().run(); + } + } + +} \ No newline at end of file diff --git a/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java b/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java index 3bdf9a6d..5568b183 100644 --- a/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java +++ b/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java @@ -16,29 +16,29 @@ package com.fizzed.blaze.jdk; import com.fizzed.blaze.Context; -import com.fizzed.blaze.core.Blaze; -import com.fizzed.blaze.core.BlazeTask; import com.fizzed.blaze.internal.ConfigHelper; import com.fizzed.blaze.internal.ContextImpl; -import static com.fizzed.blaze.system.ShellTestHelper.getBinDirAsResource; -import static com.fizzed.blaze.internal.FileHelper.resourceAsPath; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; +import com.fizzed.blaze.util.BlazeRunner; import org.apache.commons.io.FileUtils; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemOutRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.zeroturnaround.exec.ProcessResult; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static com.fizzed.blaze.internal.FileHelper.resourceAsFile; +import static com.fizzed.blaze.system.ShellTestHelper.getBinDirAsResource; +import static java.util.Arrays.asList; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; /** * @@ -63,82 +63,56 @@ static public void clearCache() throws IOException { FileUtils.deleteDirectory(classesDir.toFile()); } - @Test @Ignore + @Test public void hello() throws Exception { - Blaze blaze = new Blaze.Builder() - .file(resourceAsPath("/jdk/hello.java")) - .build(); - - systemOutRule.clearLog(); - - blaze.execute(); - - assertThat(systemOutRule.getLog(), containsString("Hello World!")); + final File scriptFile = resourceAsFile("/jdk/hello.java"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("Hello World!\n")); } - @Test @Ignore + @Test public void tasks() throws Exception { - Blaze blaze = new Blaze.Builder() - .file(resourceAsPath("/jdk/only_public.java")) - .build(); - - systemOutRule.clearLog(); - - List tasks = blaze.tasks(); - - assertThat(tasks, hasSize(1)); - assertThat(tasks.get(0).getName(), is("main")); + final File scriptFile = resourceAsFile("/jdk/only_public.java"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, asList("-l"), null); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("tasks =>\n" + + " main")); } - @Test @Ignore + @Test public void defaultBlazeInWorkingDir() throws Exception { - Blaze blaze = new Blaze.Builder() - .directory(resourceAsPath("/jdk/project0")) - .build(); - - systemOutRule.clearLog(); - - blaze.execute(); - - assertThat(systemOutRule.getLog(), containsString("worked")); - - assertThat(blaze.context().scriptFile(), is(resourceAsPath("/jdk/project0/blaze.java"))); - assertThat(blaze.context().baseDir(), is(resourceAsPath("/jdk/project0"))); - assertThat(blaze.context().withBaseDir("test"), is(resourceAsPath("/jdk/project0").resolve("test"))); + final File workingDir = resourceAsFile("/jdk/project0"); + final File scriptFile = resourceAsFile("/jdk/project0/blaze.java"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null, workingDir); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("worked\n")); } - @Test @Ignore + @Test public void defaultBlazeInSubBlazeDir() throws Exception { - Blaze blaze = new Blaze.Builder() - .directory(resourceAsPath("/jdk/project1")) - .build(); - - systemOutRule.clearLog(); - - blaze.execute(); - - assertThat(systemOutRule.getLog(), containsString("worked")); - - assertThat(blaze.context().scriptFile(), is(resourceAsPath("/jdk/project1/blaze/blaze.java"))); - assertThat(blaze.context().baseDir(), is(resourceAsPath("/jdk/project1/blaze"))); - assertThat(blaze.context().withBaseDir("../test"), is(resourceAsPath("/jdk/project1").resolve("test"))); + final File workingDir = resourceAsFile("/jdk/project1"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("worked\n")); } - @Test @Ignore + @Test public void defaultBlazeInSubDotBlazeDir() throws Exception { - Blaze blaze = new Blaze.Builder() - .directory(resourceAsPath("/jdk/project2")) - .build(); - - systemOutRule.clearLog(); - - blaze.execute(); - - assertThat(systemOutRule.getLog(), containsString("worked")); - - assertThat(blaze.context().scriptFile(), is(resourceAsPath("/jdk/project2/.blaze/blaze.js"))); - assertThat(blaze.context().baseDir(), is(resourceAsPath("/jdk/project2/.blaze"))); - assertThat(blaze.context().withBaseDir("../test"), is(resourceAsPath("/jdk/project2").resolve("test"))); + final File workingDir = resourceAsFile("/jdk/project2"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("worked\n")); } } diff --git a/blaze-kotlin/pom.xml b/blaze-kotlin/pom.xml index 56b42187..c743e21b 100644 --- a/blaze-kotlin/pom.xml +++ b/blaze-kotlin/pom.xml @@ -34,6 +34,7 @@ + org.hamcrest hamcrest diff --git a/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java b/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java index bd90173c..126f928b 100644 --- a/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java +++ b/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java @@ -16,30 +16,28 @@ package com.fizzed.blaze.kotlin; import com.fizzed.blaze.Context; -import com.fizzed.blaze.core.Blaze; -import com.fizzed.blaze.core.BlazeTask; -import com.fizzed.blaze.core.CompilationException; import com.fizzed.blaze.internal.ConfigHelper; import com.fizzed.blaze.internal.ContextImpl; -import static com.fizzed.blaze.internal.FileHelper.resourceAsFile; -import com.fizzed.blaze.internal.NoopDependencyResolver; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; +import com.fizzed.blaze.util.BlazeRunner; import org.apache.commons.io.FileUtils; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemOutRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.hamcrest.Matchers.hasSize; +import org.zeroturnaround.exec.ProcessResult; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static com.fizzed.blaze.internal.FileHelper.resourceAsFile; +import static java.util.Arrays.asList; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import org.junit.Ignore; public class BlazeKotlinEngineTest { final static private Logger log = LoggerFactory.getLogger(BlazeKotlinEngineTest.class); @@ -54,62 +52,34 @@ static public void clearCache() throws IOException { @Rule public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - @Test @Ignore + @Test public void hello() throws Exception { - Blaze blaze = new Blaze.Builder() - // to prevent tests failing on new version not being installed locally yet - .dependencyResolver(new NoopDependencyResolver()) - .file(resourceAsFile("/kotlin/hello.kts")) - .build(); - - systemOutRule.clearLog(); - - blaze.execute(); - - assertThat(systemOutRule.getLog(), containsString("Hello World!")); - } - - @Test @Ignore("Not sure we should support this style") - public void noclazz() throws Exception { - Blaze blaze = new Blaze.Builder() - .dependencyResolver(new NoopDependencyResolver()) - .file(resourceAsFile("/kotlin/noclazz.kt")) - .build(); - - systemOutRule.clearLog(); - - blaze.execute(); - - assertThat(systemOutRule.getLog(), containsString("Hello World!")); + final File scriptFile = resourceAsFile("/kotlin/hello.kt"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("Hello World!\n")); } - @Test @Ignore + @Test public void nocompile() throws Exception { - try { - Blaze blaze - = new Blaze.Builder() - .dependencyResolver(new NoopDependencyResolver()) - .file(resourceAsFile("/kotlin/nocompile.kt")) - .build(); - fail(); - } catch (CompilationException e) { - assertThat(e.getMessage(), containsString("Unable to cleanly compile")); - } + final File scriptFile = resourceAsFile("/kotlin/nocompile.kt"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null); + + assertThat(result.getExitValue(), is(1)); } - @Test @Ignore + @Test public void tasks() throws Exception { - Blaze blaze = new Blaze.Builder() - .dependencyResolver(new NoopDependencyResolver()) - .file(resourceAsFile("/kotlin/only_public.kt")) - .build(); - - systemOutRule.clearLog(); - - List tasks = blaze.tasks(); - - assertThat(tasks, hasSize(1)); - assertThat(tasks.get(0), is(new BlazeTask("main"))); + final File scriptFile = resourceAsFile("/kotlin/only_public.kt"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, asList("-l"), null); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("tasks =>\n" + + " main")); } } diff --git a/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/TryIt.java b/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/TryIt.java index f02b93f0..70b9841e 100644 --- a/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/TryIt.java +++ b/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/TryIt.java @@ -32,7 +32,7 @@ public class TryIt { static public void main(String[] args) throws Exception { //File scriptFile = FileHelper.resourceAsFile("/jdk/hello.java"); - File scriptFile = new File("src/test/resources/kotlin/hello.kts"); + File scriptFile = new File("src/test/resources/kotlin/hello.kt"); Context context = new ContextImpl(null, null, scriptFile.toPath(), null); ContextHolder.set(context); diff --git a/blaze-kotlin/src/test/resources/kotlin/hello.kt b/blaze-kotlin/src/test/resources/kotlin/hello.kt new file mode 100755 index 00000000..9ce44fe9 --- /dev/null +++ b/blaze-kotlin/src/test/resources/kotlin/hello.kt @@ -0,0 +1,7 @@ +class hello { + + fun main() { + System.out.println("Hello World!") + } + +} diff --git a/blaze-kotlin/src/test/resources/kotlin/hello.kts b/blaze-kotlin/src/test/resources/kotlin/hello.kts deleted file mode 100755 index 5a7ae930..00000000 --- a/blaze-kotlin/src/test/resources/kotlin/hello.kts +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env blaze - -fun main() { - System.out.println("Hello World!") -} diff --git a/pom.xml b/pom.xml index 023f3fb0..ceb88fd7 100644 --- a/pom.xml +++ b/pom.xml @@ -103,7 +103,7 @@ org.zeroturnaround zt-exec - 1.11 + 1.12 commons-io From 6f359718babc227d425cc4670b0ea0180f4f9086 Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 15:44:43 -0700 Subject: [PATCH 6/9] Fix unit tests on windows --- .../com/fizzed/blaze/jdk/BlazeJdkEngineTest.java | 12 ++++++------ .../fizzed/blaze/kotlin/BlazeKotlinEngineTest.java | 7 ++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java b/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java index 5568b183..851563c6 100644 --- a/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java +++ b/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java @@ -20,6 +20,7 @@ import com.fizzed.blaze.internal.ContextImpl; import com.fizzed.blaze.util.BlazeRunner; import org.apache.commons.io.FileUtils; +import org.hamcrest.CoreMatchers; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -70,7 +71,7 @@ public void hello() throws Exception { final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null); assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("Hello World!\n")); + assertThat(result.outputUTF8(), containsString("Hello World!" + System.lineSeparator())); } @Test @@ -80,8 +81,7 @@ public void tasks() throws Exception { final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, asList("-l"), null); assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("tasks =>\n" + - " main")); + assertThat(result.outputUTF8(), containsString("tasks =>" + System.lineSeparator() + " main")); } @Test @@ -92,7 +92,7 @@ public void defaultBlazeInWorkingDir() throws Exception { final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null, workingDir); assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("worked\n")); + assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); } @Test @@ -102,7 +102,7 @@ public void defaultBlazeInSubBlazeDir() throws Exception { final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("worked\n")); + assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); } @Test @@ -112,7 +112,7 @@ public void defaultBlazeInSubDotBlazeDir() throws Exception { final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("worked\n")); + assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); } } diff --git a/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java b/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java index 126f928b..17af0510 100644 --- a/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java +++ b/blaze-kotlin/src/test/java/com/fizzed/blaze/kotlin/BlazeKotlinEngineTest.java @@ -49,9 +49,6 @@ static public void clearCache() throws IOException { FileUtils.deleteDirectory(classesDir.toFile()); } - @Rule - public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - @Test public void hello() throws Exception { final File scriptFile = resourceAsFile("/kotlin/hello.kt"); @@ -59,7 +56,7 @@ public void hello() throws Exception { final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null); assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("Hello World!\n")); + assertThat(result.outputUTF8(), containsString("Hello World!" + System.lineSeparator())); } @Test @@ -78,7 +75,7 @@ public void tasks() throws Exception { final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, asList("-l"), null); assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("tasks =>\n" + + assertThat(result.outputUTF8(), containsString("tasks =>" + System.lineSeparator() + " main")); } From 3286b64705c0b07088837820bcdcd56f6671f827 Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 16:29:12 -0700 Subject: [PATCH 7/9] More windows fixes --- .../blaze/internal/EngineHelperTest.java | 4 +- .../fizzed/blaze/jdk/BlazeJdkEngineTest.java | 118 ------------------ .../blaze/jdk/{TryIt.java => DemoMain.java} | 4 +- 3 files changed, 4 insertions(+), 122 deletions(-) delete mode 100644 blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java rename blaze-core/src/test/java/com/fizzed/blaze/jdk/{TryIt.java => DemoMain.java} (93%) diff --git a/blaze-core/src/test/java/com/fizzed/blaze/internal/EngineHelperTest.java b/blaze-core/src/test/java/com/fizzed/blaze/internal/EngineHelperTest.java index f6cd2f83..6151ab76 100644 --- a/blaze-core/src/test/java/com/fizzed/blaze/internal/EngineHelperTest.java +++ b/blaze-core/src/test/java/com/fizzed/blaze/internal/EngineHelperTest.java @@ -31,9 +31,9 @@ public class EngineHelperTest { @Test @Ignore("service loader does return same instance") public void newInstanceReturned() { - Engine engine0 = EngineHelper.findByFileExtension(".js", false); + Engine engine0 = EngineHelper.findByFileExtension(".java", false); - Engine engine1 = EngineHelper.findByFileExtension(".js", false); + Engine engine1 = EngineHelper.findByFileExtension(".java", false); assertThat(engine0, not(sameInstance(engine1))); } diff --git a/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java b/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java deleted file mode 100644 index 851563c6..00000000 --- a/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2015 Fizzed, Inc. - * - * 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 com.fizzed.blaze.jdk; - -import com.fizzed.blaze.Context; -import com.fizzed.blaze.internal.ConfigHelper; -import com.fizzed.blaze.internal.ContextImpl; -import com.fizzed.blaze.util.BlazeRunner; -import org.apache.commons.io.FileUtils; -import org.hamcrest.CoreMatchers; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.SystemOutRule; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeroturnaround.exec.ProcessResult; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; - -import static com.fizzed.blaze.internal.FileHelper.resourceAsFile; -import static com.fizzed.blaze.system.ShellTestHelper.getBinDirAsResource; -import static java.util.Arrays.asList; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -/** - * - * @author joelauer - */ -public class BlazeJdkEngineTest { - final static private Logger log = LoggerFactory.getLogger(BlazeJdkEngineTest.class); - - @Rule - public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - - @BeforeClass - static public void forceBinResourceExecutable() throws Exception { - // this makes the files in the "bin" sample directory executable - getBinDirAsResource(); - } - - @BeforeClass - static public void clearCache() throws IOException { - Context context = new ContextImpl(null, Paths.get(System.getProperty("user.home")), null, null); - Path classesDir = ConfigHelper.userBlazeEngineDir(context, "java"); - FileUtils.deleteDirectory(classesDir.toFile()); - } - - @Test - public void hello() throws Exception { - final File scriptFile = resourceAsFile("/jdk/hello.java"); - - final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null); - - assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("Hello World!" + System.lineSeparator())); - } - - @Test - public void tasks() throws Exception { - final File scriptFile = resourceAsFile("/jdk/only_public.java"); - - final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, asList("-l"), null); - - assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("tasks =>" + System.lineSeparator() + " main")); - } - - @Test - public void defaultBlazeInWorkingDir() throws Exception { - final File workingDir = resourceAsFile("/jdk/project0"); - final File scriptFile = resourceAsFile("/jdk/project0/blaze.java"); - - final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null, workingDir); - - assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); - } - - @Test - public void defaultBlazeInSubBlazeDir() throws Exception { - final File workingDir = resourceAsFile("/jdk/project1"); - - final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); - - assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); - } - - @Test - public void defaultBlazeInSubDotBlazeDir() throws Exception { - final File workingDir = resourceAsFile("/jdk/project2"); - - final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); - - assertThat(result.getExitValue(), is(0)); - assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); - } - -} diff --git a/blaze-core/src/test/java/com/fizzed/blaze/jdk/TryIt.java b/blaze-core/src/test/java/com/fizzed/blaze/jdk/DemoMain.java similarity index 93% rename from blaze-core/src/test/java/com/fizzed/blaze/jdk/TryIt.java rename to blaze-core/src/test/java/com/fizzed/blaze/jdk/DemoMain.java index 2b2bca4b..25981672 100644 --- a/blaze-core/src/test/java/com/fizzed/blaze/jdk/TryIt.java +++ b/blaze-core/src/test/java/com/fizzed/blaze/jdk/DemoMain.java @@ -27,8 +27,8 @@ * * @author joelauer */ -public class TryIt { - static private final Logger log = LoggerFactory.getLogger(TryIt.class); +public class DemoMain { + static private final Logger log = LoggerFactory.getLogger(DemoMain.class); static public void main(String[] args) throws Exception { File scriptFile = FileHelper.resourceAsFile("/jdk/hello.java"); From 7c7805b9f702a16a12ea87327cb136e4893ff4d9 Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 16:55:01 -0700 Subject: [PATCH 8/9] Fix surefire plugin socket factory for unit tests --- blaze-core/pom.xml | 10 ++ .../fizzed/blaze/jdk/BlazeJdkEngineTest.java | 113 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java diff --git a/blaze-core/pom.xml b/blaze-core/pom.xml index 2d1edb6e..83626e07 100644 --- a/blaze-core/pom.xml +++ b/blaze-core/pom.xml @@ -50,6 +50,16 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + + diff --git a/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java b/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java new file mode 100644 index 00000000..0e0450ea --- /dev/null +++ b/blaze-core/src/test/java/com/fizzed/blaze/jdk/BlazeJdkEngineTest.java @@ -0,0 +1,113 @@ +/* + * Copyright 2015 Fizzed, Inc. + * + * 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 com.fizzed.blaze.jdk; + +import com.fizzed.blaze.Context; +import com.fizzed.blaze.internal.ConfigHelper; +import com.fizzed.blaze.internal.ContextImpl; +import com.fizzed.blaze.util.BlazeRunner; +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.SystemOutRule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.zeroturnaround.exec.ProcessResult; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static com.fizzed.blaze.internal.FileHelper.resourceAsFile; +import static com.fizzed.blaze.system.ShellTestHelper.getBinDirAsResource; +import static java.util.Arrays.asList; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class BlazeJdkEngineTest { + final static private Logger log = LoggerFactory.getLogger(BlazeJdkEngineTest.class); + + @Rule + public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); + + @BeforeClass + static public void forceBinResourceExecutable() throws Exception { + // this makes the files in the "bin" sample directory executable + getBinDirAsResource(); + } + + @BeforeClass + static public void clearCache() throws IOException { + Context context = new ContextImpl(null, Paths.get(System.getProperty("user.home")), null, null); + Path classesDir = ConfigHelper.userBlazeEngineDir(context, "java"); + FileUtils.deleteDirectory(classesDir.toFile()); + } + + @Test + public void hello() throws Exception { + final File scriptFile = resourceAsFile("/jdk/hello.java"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("Hello World!" + System.lineSeparator())); + } + + @Test + public void tasks() throws Exception { + final File scriptFile = resourceAsFile("/jdk/only_public.java"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, asList("-l"), null); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("tasks =>" + System.lineSeparator() + " main")); + } + + @Test + public void defaultBlazeInWorkingDir() throws Exception { + final File workingDir = resourceAsFile("/jdk/project0"); + final File scriptFile = resourceAsFile("/jdk/project0/blaze.java"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(scriptFile, null, null, workingDir); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); + } + + @Test + public void defaultBlazeInSubBlazeDir() throws Exception { + final File workingDir = resourceAsFile("/jdk/project1"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); + } + + @Test + public void defaultBlazeInSubDotBlazeDir() throws Exception { + final File workingDir = resourceAsFile("/jdk/project2"); + + final ProcessResult result = BlazeRunner.invokeWithCurrentJvmHome(null, null, null, workingDir); + + assertThat(result.getExitValue(), is(0)); + assertThat(result.outputUTF8(), containsString("worked" + System.lineSeparator())); + } + +} From c5dd85115acdc62d92b19d611e4fcba0738c52bb Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Thu, 26 Oct 2023 17:00:16 -0700 Subject: [PATCH 9/9] Fix test issue on windows --- blaze-core/pom.xml | 10 ---------- pom.xml | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/blaze-core/pom.xml b/blaze-core/pom.xml index 83626e07..2d1edb6e 100644 --- a/blaze-core/pom.xml +++ b/blaze-core/pom.xml @@ -50,16 +50,6 @@ - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - - - - - diff --git a/pom.xml b/pom.xml index ceb88fd7..056a668f 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,26 @@ blaze-lite + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.1 + + + +