diff --git a/buildSrc/src/main/java/lfformat/LfFormatStep.java b/buildSrc/src/main/java/lfformat/LfFormatStep.java index 60ed3ddb9f..ca0b780383 100644 --- a/buildSrc/src/main/java/lfformat/LfFormatStep.java +++ b/buildSrc/src/main/java/lfformat/LfFormatStep.java @@ -1,23 +1,15 @@ package lfformat; -import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Serializable; import java.io.Writer; -import java.lang.ProcessBuilder.Redirect; import java.net.URL; import java.net.URLClassLoader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Locale; @@ -41,6 +33,7 @@ private static class Step implements FormatterStep { // The use of the static keyword here is a workaround for serialization difficulties. /** The path to the lingua-franca repository. */ private static Path projectRoot; + private static Step instance; private static Process formatter; @@ -56,16 +49,19 @@ public static Step getInstance() throws IOException { private Step() throws IOException { initializeFormatter(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - writer.close(); - formatter.waitFor(); - reader.close(); - error.close(); - } catch (IOException | InterruptedException e) { - throw new RuntimeException(e); - } - })); + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + try { + writer.close(); + formatter.waitFor(); + reader.close(); + error.close(); + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); + } + })); } @Override @@ -81,7 +77,10 @@ public String format( formatter.waitFor(); error.lines().forEach(System.out::println); initializeFormatter(); - throw new RuntimeException("Failed to format " + file + ".\nPlease ensure that this file passes validator checks."); + throw new RuntimeException( + "Failed to format " + + file + + ".\nPlease ensure that this file passes validator checks."); } String line = reader.readLine(); while (line != null && !line.endsWith("\0")) { @@ -105,28 +104,29 @@ private void initializeFormatter() throws IOException { "build", "libs", String.format("org.lflang-%s.jar", properties.getString("VERSION"))); - formatter = new ProcessBuilder( - List.of( - "java", - "-cp", - lffPath.toString(), - "org.lflang.cli.Lff", - "--dry-run", - "--stdin")) - .start(); + formatter = + new ProcessBuilder( + List.of( + "java", + "-cp", + lffPath.toString(), + "org.lflang.cli.Lff", + "--dry-run", + "--stdin")) + .start(); writer = new BufferedWriter(new OutputStreamWriter(formatter.getOutputStream())); reader = new BufferedReader(new InputStreamReader(formatter.getInputStream())); error = new BufferedReader(new InputStreamReader(formatter.getErrorStream())); } -// /** Run the formatter on the given file and return the resulting process handle. */ -// private Process runFormatter(File file) throws IOException { -// // It looks silly to invoke Java from Java, but it is necessary in -// // order to break the circularity of needing the program to be built -// // in order for it to be built. -// var formatter = getFormatter(); -// return formatter; -// } + // /** Run the formatter on the given file and return the resulting process handle. */ + // private Process runFormatter(File file) throws IOException { + // // It looks silly to invoke Java from Java, but it is necessary in + // // order to break the circularity of needing the program to be built + // // in order for it to be built. + // var formatter = getFormatter(); + // return formatter; + // } @SuppressWarnings("NullableProblems") @Override diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/src/org/lflang/cli/CliBase.java index 8a92619193..6c7cad18fc 100644 --- a/org.lflang/src/org/lflang/cli/CliBase.java +++ b/org.lflang/src/org/lflang/cli/CliBase.java @@ -7,7 +7,6 @@ import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; - import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; @@ -186,8 +185,7 @@ protected List<Path> getInputPaths() { if (line == null) return List.of(); return List.of(Path.of(line)); } else { - paths = - topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList()); + paths = topLevelArg.files.stream().map(io.getWd()::resolve).collect(Collectors.toList()); } for (Path path : paths) {