use of org.gradle.api.GradleScriptException in project gradle by gradle.
the class DefaultScriptRunnerFactoryTest method wrapsExecutionExceptionAndRestoresStateWhenScriptFails.
@Test
public void wrapsExecutionExceptionAndRestoresStateWhenScriptFails() {
final RuntimeException failure = new RuntimeException();
ScriptRunner<?, Void> scriptRunner = factory.create(compiledScriptMock, scriptSourceDummy, classLoaderDummy);
expectScriptInstantiated();
context.checking(new Expectations() {
{
Sequence sequence = context.sequence("seq");
allowing(compiledScriptMock).getRunDoesSomething();
will(returnValue(true));
one(scriptExecutionListenerMock).scriptClassLoaded(scriptSourceDummy, Script.class);
inSequence(sequence);
one(scriptMock).init(target, scriptServices);
inSequence(sequence);
one(standardOutputCaptureMock).start();
inSequence(sequence);
one(scriptMock).run();
inSequence(sequence);
will(throwException(failure));
one(standardOutputCaptureMock).stop();
inSequence(sequence);
}
});
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
assertThat(originalClassLoader, not(sameInstance(classLoaderDummy)));
try {
scriptRunner.run(target, scriptServices);
fail();
} catch (GradleScriptException e) {
assertThat(e.getMessage(), equalTo("A problem occurred evaluating <script-to-string>."));
assertThat(e.getCause(), sameInstance((Throwable) failure));
}
assertThat(Thread.currentThread().getContextClassLoader(), sameInstance(originalClassLoader));
}
use of org.gradle.api.GradleScriptException in project gradle by gradle.
the class DefaultExceptionAnalyser method collectFailures.
@Override
public void collectFailures(Throwable exception, Collection<? super Throwable> failures) {
if (exception instanceof ProjectConfigurationException) {
ProjectConfigurationException projectConfigurationException = (ProjectConfigurationException) exception;
List<Throwable> additionalFailures = new ArrayList<>();
for (Throwable cause : projectConfigurationException.getCauses()) {
// TODO: remove this special case
if (cause instanceof GradleScriptException) {
failures.add(transform(cause));
} else {
additionalFailures.add(cause);
}
}
if (!additionalFailures.isEmpty()) {
projectConfigurationException.initCauses(additionalFailures);
failures.add(transform(projectConfigurationException));
}
} else if (exception instanceof ServiceCreationException) {
failures.add(transform(new InitializationException(exception)));
} else {
failures.add(transform(exception));
}
}
use of org.gradle.api.GradleScriptException in project gradle by gradle.
the class IdeaScalaConfigurer method findIdeaTargetVersion.
private VersionNumber findIdeaTargetVersion() {
VersionNumber targetVersion = null;
String targetVersionString = rootProject.getExtensions().getByType(IdeaModel.class).getTargetVersion();
if (targetVersionString != null) {
targetVersion = VersionNumber.parse(targetVersionString);
if (targetVersion.equals(VersionNumber.UNKNOWN)) {
throw new GradleScriptException("String '" + targetVersionString + "' is not a valid value for IdeaModel.targetVersion.", null);
}
}
return targetVersion;
}
use of org.gradle.api.GradleScriptException in project gradle by gradle.
the class DefaultExceptionAnalyserTest method prefersLocationAwareExceptionOverScriptException.
@Test
public void prefersLocationAwareExceptionOverScriptException() {
Throwable cause = locationAwareException(new GradleScriptException("broken", new RuntimeException()));
Throwable failure = new TaskExecutionException(null, cause);
DefaultExceptionAnalyser analyser = analyser();
assertThat(analyser.transform(failure), sameInstance(cause));
}
use of org.gradle.api.GradleScriptException in project gradle by gradle.
the class DefaultExceptionAnalyserTest method prefersScriptExceptionOverContextualException.
@Test
public void prefersScriptExceptionOverContextualException() {
Throwable cause = new GradleScriptException("broken", new ContextualException());
Throwable failure = new TaskExecutionException(null, cause);
Throwable transformedFailure = analyser().transform(failure);
assertThat(transformedFailure, instanceOf(LocationAwareException.class));
LocationAwareException gse = (LocationAwareException) transformedFailure;
assertThat(gse.getCause(), sameInstance(cause));
}
Aggregations