use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class IdePlugin method addWorkspace.
protected void addWorkspace(final IdeWorkspace workspace) {
lifecycleTask.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
System.out.println(String.format("Generated %s at %s", workspace.getDisplayName(), new ConsoleRenderer().asClickableFileUrl(workspace.getLocation().get().getAsFile())));
}
});
Task openTask = project.getTasks().create("open" + StringUtils.capitalize(getLifecycleTaskName()));
openTask.dependsOn(lifecycleTask);
openTask.setGroup("IDE");
openTask.setDescription("Opens the " + workspace.getDisplayName());
openTask.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
if (OperatingSystem.current().isMacOsX()) {
project.exec(new Action<ExecSpec>() {
@Override
public void execute(ExecSpec execSpec) {
execSpec.commandLine("open", workspace.getLocation().get());
}
});
} else {
try {
Desktop.getDesktop().open(workspace.getLocation().get().getAsFile());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
});
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class AbstractGradleExecuter method getResultAssertion.
protected Action<ExecutionResult> getResultAssertion() {
return new Action<ExecutionResult>() {
int expectedDeprecationWarnings = AbstractGradleExecuter.this.expectedDeprecationWarnings;
boolean expectStackTraces = !AbstractGradleExecuter.this.stackTraceChecksOn;
boolean checkDeprecations = AbstractGradleExecuter.this.checkDeprecations;
@Override
public void execute(ExecutionResult executionResult) {
String normalizedOutput = executionResult.getNormalizedOutput();
String error = executionResult.getError();
boolean executionFailure = isExecutionFailure(executionResult);
// for tests using rich console standard out and error are combined in output of execution result
if (executionFailure) {
normalizedOutput = removeExceptionStackTraceForFailedExecution(normalizedOutput);
}
validate(normalizedOutput, "Standard output");
if (executionFailure) {
error = removeExceptionStackTraceForFailedExecution(error);
}
validate(error, "Standard error");
if (expectedDeprecationWarnings > 0) {
throw new AssertionError(String.format("Expected %d more deprecation warnings", expectedDeprecationWarnings));
}
}
private boolean isErrorOutEmpty(String error) {
// See: https://github.com/gradle/performance/issues/375#issuecomment-315103861
return Strings.isNullOrEmpty(error.replaceAll("(?m)^SLF4J: .*", "").trim());
}
private boolean isExecutionFailure(ExecutionResult executionResult) {
return executionResult instanceof ExecutionFailure;
}
// Axe everything after the expected exception
private String removeExceptionStackTraceForFailedExecution(String text) {
int pos = text.indexOf("* Exception is:");
if (pos >= 0) {
text = text.substring(0, pos);
}
return text;
}
private void validate(String output, String displayName) {
List<String> lines;
try {
lines = CharSource.wrap(output).readLines();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
int i = 0;
while (i < lines.size()) {
String line = lines.get(i);
if (line.matches(".*use(s)? or override(s)? a deprecated API\\.")) {
// A javac warning, ignore
i++;
} else if (line.contains(UnsupportedJavaRuntimeException.JAVA7_DEPRECATION_WARNING)) {
if (!java7DeprecationWarningShouldExist()) {
throw new AssertionError(String.format("%s line %d contains unexpected deprecation warning: %s%n=====%n%s%n=====%n", displayName, i + 1, line, output));
}
// skip over stack trace
i++;
while (i < lines.size() && STACK_TRACE_ELEMENT.matcher(lines.get(i)).matches()) {
i++;
}
} else if (isJava7DeprecationTruncatedDaemonLog(lines, i, line)) {
// skip over stack trace
i++;
while (i < lines.size() && STACK_TRACE_ELEMENT.matcher(lines.get(i)).matches()) {
i++;
}
} else if (isDeprecationMessageInHelpDescription(line)) {
i++;
} else if (line.matches(".*\\s+deprecated.*")) {
if (checkDeprecations && expectedDeprecationWarnings <= 0) {
throw new AssertionError(String.format("%s line %d contains a deprecation warning: %s%n=====%n%s%n=====%n", displayName, i + 1, line, output));
}
expectedDeprecationWarnings--;
// skip over stack trace
i++;
while (i < lines.size() && STACK_TRACE_ELEMENT.matcher(lines.get(i)).matches()) {
i++;
}
} else if (!expectStackTraces && STACK_TRACE_ELEMENT.matcher(line).matches() && i < lines.size() - 1 && STACK_TRACE_ELEMENT.matcher(lines.get(i + 1)).matches()) {
// 2 or more lines that look like stack trace elements
throw new AssertionError(String.format("%s line %d contains an unexpected stack trace: %s%n=====%n%s%n=====%n", displayName, i + 1, line, output));
} else {
i++;
}
}
}
private boolean isDeprecationMessageInHelpDescription(String s) {
return s.matches(".*\\[deprecated.*]");
}
};
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class GroupedOutputFixture method stripAnsiCodes.
private String stripAnsiCodes(String output) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(new StringReader(output), new AnsiOutputStream(baos));
return baos.toString();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class GradleVsMavenBuildExperimentRunner method executeWithFileLogging.
private void executeWithFileLogging(MavenBuildExperimentSpec experiment, ExecAction mavenInvocation) {
File log = new File(experiment.getWorkingDirectory(), "log.txt");
OutputStream out = null;
try {
out = new FileOutputStream(log, true);
mavenInvocation.setErrorOutput(out);
mavenInvocation.setStandardOutput(out);
mavenInvocation.execute();
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
CompositeStoppable.stoppable(out).stop();
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class RhinoWorkerUtils method parse.
public static Scriptable parse(File source, String encoding, Action<Context> contextConfig) {
Context context = Context.enter();
if (contextConfig != null) {
contextConfig.execute(context);
}
Scriptable scope = context.initStandardObjects();
try {
Reader reader = new InputStreamReader(new FileInputStream(source), encoding);
try {
context.evaluateReader(scope, reader, source.getName(), 0, null);
} finally {
reader.close();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
Context.exit();
}
return scope;
}
Aggregations