From 905e3a808fee974603a3fc9b07a6a64412dfbf1b Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Wed, 12 Jun 2024 13:28:12 +0100 Subject: [PATCH] Handle palantir/gradle-consistent-versions plugin --- cli/src/main/java/org/jboss/gm/cli/Main.java | 18 +++++++++++++----- .../org/jboss/gm/cli/DifferentJVMTest.java | 3 +-- .../test/java/org/jboss/gm/cli/MainTest.java | 13 +++++++++++-- cli/src/test/resources/versions.lock | 3 +++ 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 cli/src/test/resources/versions.lock diff --git a/cli/src/main/java/org/jboss/gm/cli/Main.java b/cli/src/main/java/org/jboss/gm/cli/Main.java index dd296a76..cc809217 100644 --- a/cli/src/main/java/org/jboss/gm/cli/Main.java +++ b/cli/src/main/java/org/jboss/gm/cli/Main.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.io.PrintWriter; import java.lang.management.ManagementFactory; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -251,8 +252,7 @@ private void executeGradle(OutputStream out, boolean quiet, List current cause = cause.getCause(); } logger.debug("Hit https://github.com/gradle/gradle/issues/9339 ", e); - logger.error( - "Build exception but unable to transfer message due to mix of JDK versions. Examine log for problems"); + logger.error("Build exception. Examine log for problems"); throw new ManipulationException("Problem executing build", cause); } else { logger.error("Caught exception running build", e); @@ -262,12 +262,10 @@ private void executeGradle(OutputStream out, boolean quiet, List current // Unable to do instanceof comparison due to different classloader if ("org.gradle.api.UncheckedIOException".equals(e.getCause().getClass().getName())) { logger.debug("Hit https://github.com/gradle/gradle/issues/9339 ", e); - logger.error( - "Build exception but unable to transfer message due to mix of JDK versions. Examine log for problems"); + logger.error("Build exception. Examine log for problems"); } else { logger.error("Gradle connection exception", e); } - throw new ManipulationException("Problem executing build"); } catch (RuntimeException e) { logger.error("Fatal problem executing build", e); @@ -343,6 +341,16 @@ public Void call() throws ManipulationException { GroovyUtils.runCustomGroovyScript(logger, InvocationStage.FIRST, target, configuration, null, null); + File lockFile = new File(target, "versions.lock"); + if (lockFile.exists()) { + logger.info("Found gradle-consistent-versions lock file {}", lockFile); + try { + new PrintWriter(lockFile).close(); + } catch (IOException e) { + throw new ManipulationException("Unable to handle versions.lock", e); + } + } + PluginUtils.pluginRemoval(logger, target, configuration.pluginRemoval()); if (configuration.disableGME()) { diff --git a/cli/src/test/java/org/jboss/gm/cli/DifferentJVMTest.java b/cli/src/test/java/org/jboss/gm/cli/DifferentJVMTest.java index e7201da1..ccc6ed29 100644 --- a/cli/src/test/java/org/jboss/gm/cli/DifferentJVMTest.java +++ b/cli/src/test/java/org/jboss/gm/cli/DifferentJVMTest.java @@ -260,8 +260,7 @@ public void runWithJDK8Fails() throws Exception { + "project"); } - assertThat(systemErrRule.getLog()).contains( - "Build exception but unable to transfer message due to mix of JDK versions. Examine log for problems"); + assertThat(systemErrRule.getLog()).contains("Build exception. Examine log for problems"); assertThat(systemOutRule.getLog()).contains("Java home overridden to: " + JDK8_DIR); } } diff --git a/cli/src/test/java/org/jboss/gm/cli/MainTest.java b/cli/src/test/java/org/jboss/gm/cli/MainTest.java index 51eb2a4b..8c84801a 100644 --- a/cli/src/test/java/org/jboss/gm/cli/MainTest.java +++ b/cli/src/test/java/org/jboss/gm/cli/MainTest.java @@ -322,7 +322,6 @@ public void testGradleInvalidTarget1() throws IOException { m.run(args); fail("No exception thrown"); } catch (Exception e) { - e.printStackTrace(); assertTrue(e.getMessage().contains("Pass project root as directory not file")); } } @@ -335,7 +334,6 @@ public void testGradleInvalidTarget2() { m.run(args); fail("No exception thrown"); } catch (Exception e) { - e.printStackTrace(); assertTrue(e.getMessage().contains("Unable to locate target directory")); } } @@ -351,4 +349,15 @@ public void testSetEnvironmentVariables() throws Exception { assertThat(systemOutRule.getLog()).contains("LETTERS"); } + + @Test + public void testWipeLock() throws Exception { + final File projectRoot = new File(MainTest.class.getClassLoader().getResource("build.gradle").getPath()); + Main m = new Main(); + String[] args = new String[] { "-d", "-t", projectRoot.getParentFile().toString(), "help" }; + m.run(args); + assertTrue(systemOutRule.getLog().contains("Found gradle-consistent-versions lock file")); + File lockFile = new File(projectRoot.getParentFile(), "versions.lock"); + assertEquals(0, lockFile.length()); + } } diff --git a/cli/src/test/resources/versions.lock b/cli/src/test/resources/versions.lock new file mode 100644 index 00000000..24eac41a --- /dev/null +++ b/cli/src/test/resources/versions.lock @@ -0,0 +1,3 @@ +# Run ./gradlew --write-locks to regenerate this file +com.carrotsearch:hppc:0.9.1 (1 constraints: 0c050736) +com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.8.1 (1 constraints: 0d050e36)