Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate exceptions from conjure #1369

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fileeditor
*.iws
.idea/
out/
.profileconfig.json

# Eclipse/IntelliJ APT
generated_src/
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1369.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Propagate exceptions from conjure
links:
- https://github.com/palantir/gradle-conjure/pull/1369
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static ConjureRunner createNewRunner(File executable) throws IOException {
URLClassLoader classLoader =
new ChildFirstUrlClassLoader(info.classpathUrls(), ConjureRunnerResource.class.getClassLoader());
try {
Optional<Method> mainMethod = getMainMethod(classLoader, info.mainClass());
Optional<Method> mainMethod = getInProcessOrMainMethod(classLoader, info.mainClass());
if (mainMethod.isPresent()) {
classLoaderMustBeClosed = false;
return new InProcessConjureRunner(executable, mainMethod.get(), classLoader);
Expand All @@ -97,6 +97,19 @@ static ConjureRunner createNewRunner(File executable) throws IOException {
return new ExternalProcessConjureRunner(executable);
}

private static Optional<Method> getInProcessOrMainMethod(URLClassLoader classLoader, String mainClassName) {
try {
Class<?> mainClass = classLoader.loadClass(mainClassName);
return Optional.of(mainClass.getMethod("inProcessExecution", String[].class));
} catch (ClassNotFoundException e) {
log.warn("Failed to get main method for class {}", mainClassName, e);
return Optional.empty();
} catch (NoSuchMethodException e) {
log.debug("Falling back to using the main method", mainClassName, e);
return getMainMethod(classLoader, mainClassName);
}
}

private static Optional<Method> getMainMethod(URLClassLoader classLoader, String mainClassName) {
try {
ClassFileLocator locator = new ClassFileLocator.ForUrl(classLoader.getURLs());
Expand Down Expand Up @@ -184,7 +197,6 @@ public void invoke(Project project, String failedTo, List<String> unloggedArgs,
.addAll(unloggedArgs)
.addAll(loggedArgs)
.build();

try {
String[] args = combinedArgs.toArray(new String[] {});
mainMethod.invoke(null, new Object[] {args});
Expand All @@ -201,7 +213,9 @@ public void invoke(Project project, String failedTo, List<String> unloggedArgs,
// Exit status zero, we're good to go!
} else {
throw new RuntimeException(
String.format("Failed to %s. The command '%s' failed.", failedTo, combinedArgs), t);
String.format(
"%s\n\nFailed to %s. The command '%s' failed.", rootCause, failedTo, combinedArgs),
t);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.palantir.gradle.conjure

import org.junit.internal.Throwables

import java.nio.file.Files
import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult
Expand Down Expand Up @@ -95,7 +97,8 @@ class ConjureBasePluginIntegrationSpec extends IntegrationSpec {
file('src/main/conjure/api.yml') << "foo"

then:
runTasksWithFailure('compileIr')
ExecutionResult result = runTasksWithFailure('compileIr')
com.google.common.base.Throwables.getRootCause(result.failure).message.contains "vjf"
}

def 'compileIr can get results from the build cache'() {
Expand Down