use of org.gradle.api.GradleException in project gradle by gradle.
the class BuildInvocationsBuilder method buildAll.
@Override
@SuppressWarnings("StringEquality")
public DefaultBuildInvocations buildAll(String modelName, Project project) {
if (!canBuild(modelName)) {
throw new GradleException("Unknown model name " + modelName);
}
DefaultProjectIdentifier projectIdentifier = getProjectIdentifier(project);
// construct task selectors
List<LaunchableGradleTaskSelector> selectors = Lists.newArrayList();
Map<String, LaunchableGradleTaskSelector> selectorsByName = Maps.newTreeMap(Ordering.natural());
Set<String> visibleTasks = Sets.newLinkedHashSet();
findTasks(project, selectorsByName, visibleTasks);
for (String selectorName : selectorsByName.keySet()) {
LaunchableGradleTaskSelector selector = selectorsByName.get(selectorName);
selectors.add(selector.setName(selectorName).setTaskName(selectorName).setProjectIdentifier(projectIdentifier).setDisplayName(selectorName + " in " + project + " and subprojects.").setPublic(visibleTasks.contains(selectorName)));
}
// construct project tasks
List<LaunchableGradleTask> projectTasks = tasks(project);
// construct build invocations from task selectors and project tasks
return new DefaultBuildInvocations().setSelectors(selectors).setTasks(projectTasks).setProjectIdentifier(projectIdentifier);
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class OsXInstalledJvmLocator method findJvms.
public Collection<JvmInstallation> findJvms() {
try {
ExecHandleBuilder execHandleBuilder = execHandleFactory.newExec();
execHandleBuilder.workingDir(new File(".").getAbsoluteFile());
execHandleBuilder.commandLine("/usr/libexec/java_home", "-V");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// verbose output is written to stderr for some reason
execHandleBuilder.setErrorOutput(outputStream);
execHandleBuilder.setStandardOutput(new ByteArrayOutputStream());
execHandleBuilder.build().start().waitForFinish().assertNormalExitValue();
return new OsXJavaHomeParser().parse(new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray())));
} catch (Exception e) {
throw new GradleException("Could not locate installed JVMs.", e);
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class RunTestExecutable method handleTestFailures.
private void handleTestFailures(Exception e) {
String message = "There were failing tests";
String resultsUrl = new ConsoleRenderer().asClickableFileUrl(getOutputDir());
message = message.concat(". See the results at: " + resultsUrl);
if (isIgnoreFailures()) {
getLogger().warn(message);
} else {
throw new GradleException(message, e);
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class Wrapper method writeWrapperTo.
private void writeWrapperTo(File destination) {
InputStream gradleWrapperJar = Wrapper.class.getResourceAsStream("/gradle-wrapper.jar");
if (gradleWrapperJar == null) {
throw new GradleException("Cannot locate wrapper JAR resource.");
}
ZipInputStream zipInputStream = null;
ZipOutputStream zipOutputStream = null;
try {
zipInputStream = new ZipInputStream(gradleWrapperJar);
zipOutputStream = new ZipOutputStream(new FileOutputStream(destination));
for (ZipEntry entry = zipInputStream.getNextEntry(); entry != null; entry = zipInputStream.getNextEntry()) {
zipOutputStream.putNextEntry(entry);
if (!entry.isDirectory()) {
ByteStreams.copy(zipInputStream, zipOutputStream);
}
zipOutputStream.closeEntry();
}
addBuildReceipt(zipOutputStream);
} catch (IOException e) {
throw UncheckedException.throwAsUncheckedException(e);
} finally {
IoActions.closeQuietly(zipInputStream);
IoActions.closeQuietly(zipOutputStream);
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class BuildScriptBuilder method create.
public TemplateOperation create() {
return new TemplateOperation() {
@Override
public void generate() {
try {
PrintWriter writer = new PrintWriter(new FileWriter(target));
try {
// Generate the file header
writer.println("/*");
writer.println(" * This build file was generated by the Gradle 'init' task.");
if (!headerLines.isEmpty()) {
writer.println(" *");
for (String headerLine : headerLines) {
writer.println(" * " + headerLine);
}
}
writer.println(" */");
// Plugins
for (Map.Entry<String, String> entry : plugins.entrySet()) {
writer.println();
writer.println("// " + entry.getValue());
writer.println("apply plugin: '" + entry.getKey() + "'");
}
// Dependencies and repositories
if (!dependencies.isEmpty()) {
writer.println();
writer.println("// In this section you declare where to find the dependencies of your project");
writer.println("repositories {");
writer.println(" // Use jcenter for resolving your dependencies.");
writer.println(" // You can declare any Maven/Ivy/file repository here.");
writer.println(" jcenter()");
writer.println("}");
writer.println();
writer.println("dependencies {");
boolean firstDep = true;
for (String config : dependencies.keySet()) {
for (DepSpec depSpec : dependencies.get(config)) {
if (firstDep) {
firstDep = false;
} else {
writer.println();
}
writer.println(" // " + depSpec.comment);
for (String dep : depSpec.deps) {
writer.println(" " + config + " '" + dep + "'");
}
}
}
writer.println("}");
}
for (ConfigSpec configSpec : config) {
writer.println();
writer.println("// " + configSpec.comment);
for (String line : configSpec.configLines) {
writer.println(line);
}
}
writer.println();
} finally {
writer.close();
}
} catch (Exception e) {
throw new GradleException("Could not generate file " + target + ".", e);
}
}
};
}
Aggregations