Skip to content

Commit

Permalink
Handle palantir/gradle-consistent-versions plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Jun 12, 2024
1 parent 91a753a commit 6e1b532
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
20 changes: 14 additions & 6 deletions cli/src/main/java/org/jboss/gm/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -251,8 +252,7 @@ private void executeGradle(OutputStream out, boolean quiet, List<String> 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);
Expand All @@ -262,13 +262,11 @@ private void executeGradle(OutputStream out, boolean quiet, List<String> 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 connection exception. Examine log for problems");
} else {
logger.error("Gradle connection exception", e);
}

throw new ManipulationException("Problem executing build");
throw new ManipulationException("Problem executing build", e);
} catch (RuntimeException e) {
logger.error("Fatal problem executing build", e);
throw new ManipulationException("Fatal problem executing build", e);
Expand Down Expand Up @@ -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);

Check warning on line 350 in cli/src/main/java/org/jboss/gm/cli/Main.java

View check run for this annotation

Codecov / codecov/patch

cli/src/main/java/org/jboss/gm/cli/Main.java#L349-L350

Added lines #L349 - L350 were not covered by tests
}
}

PluginUtils.pluginRemoval(logger, target, configuration.pluginRemoval());

if (configuration.disableGME()) {
Expand Down
3 changes: 1 addition & 2 deletions cli/src/test/java/org/jboss/gm/cli/DifferentJVMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
13 changes: 11 additions & 2 deletions cli/src/test/java/org/jboss/gm/cli/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Expand All @@ -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"));
}
}
Expand All @@ -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());
}
}
3 changes: 3 additions & 0 deletions cli/src/test/resources/versions.lock
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6e1b532

Please sign in to comment.