Skip to content

Commit

Permalink
Do not throw TestAbortException from test deps (#27)
Browse files Browse the repository at this point in the history
* Do not throw TestAbortException from test deps

* Throw `IOException` from the model builder

* Reuse the existing try/catch block

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
BoykoAlex and timtebeek authored Nov 14, 2024
1 parent 250c5fb commit 8b72f12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@
import org.openrewrite.marker.OperatingSystemProvenance;
import org.openrewrite.properties.tree.Properties;
import org.openrewrite.test.UncheckedConsumer;
import org.opentest4j.TestAbortedException;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFilePermission;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
Expand Down Expand Up @@ -151,7 +154,7 @@ public static UncheckedConsumer<List<SourceFile>> withToolingApi(@Nullable Gradl
deleteDirectory(tempDirectory.toFile());
}
} catch (IOException e) {
throw new UncheckedIOException(e);
throw new TestAbortedException("Failed to load Gradle tooling API", e);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
public class OpenRewriteModelBuilder {

/**
* <b></b>Warning: This API is likely to change over time without notice</b>
* Build an OpenRewriteModel for a project directory, using the default Gradle init script bundled within this jar.
* The included init script accesses public artifact repositories (Maven Central, Nexus Snapshots) to be able to
* download rewrite dependencies, so public repositories must be accessible for this to work.
*/
public static OpenRewriteModel forProjectDirectory(File projectDir, @Nullable File buildFile) {
public static OpenRewriteModel forProjectDirectory(File projectDir, @Nullable File buildFile) throws IOException {
return forProjectDirectory(projectDir, buildFile, null);
}

/**
* <b></b>Warning: This API is likely to change over time without notice</b>
* Build an OpenRewriteModel for a project directory, using the init script contents passed to this function.
* When Maven Central / Nexus Snapshots are inaccessible this overload can be used with an alternate Groovy init script
* which applies the ToolingApiOpenRewriteModelPlugin to all projects.
Expand Down Expand Up @@ -74,7 +76,7 @@ public static OpenRewriteModel forProjectDirectory(File projectDir, @Nullable Fi
* }
* </pre>
*/
public static OpenRewriteModel forProjectDirectory(File projectDir, @Nullable File buildFile, @Nullable String initScript) {
public static OpenRewriteModel forProjectDirectory(File projectDir, @Nullable File buildFile, @Nullable String initScript) throws IOException {
DefaultGradleConnector connector = (DefaultGradleConnector)GradleConnector.newConnector();
if (Files.exists(projectDir.toPath().resolve("gradle/wrapper/gradle-wrapper.properties"))) {
connector.useBuildDistribution();
Expand Down Expand Up @@ -105,8 +107,6 @@ public static OpenRewriteModel forProjectDirectory(File projectDir, @Nullable Fi
}
customModelBuilder.withArguments(arguments);
return customModelBuilder.get();
} catch (IOException e) {
throw new TestAbortedException("Failed to load Gradle tooling API", e);
} finally {
try {
Files.delete(init);
Expand Down

0 comments on commit 8b72f12

Please sign in to comment.