Search in sources :

Example 21 with GradleException

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);
}
Also used : LaunchableGradleTask(org.gradle.plugins.ide.internal.tooling.model.LaunchableGradleTask) DefaultBuildInvocations(org.gradle.plugins.ide.internal.tooling.model.DefaultBuildInvocations) GradleException(org.gradle.api.GradleException) LaunchableGradleTaskSelector(org.gradle.plugins.ide.internal.tooling.model.LaunchableGradleTaskSelector) DefaultProjectIdentifier(org.gradle.tooling.internal.gradle.DefaultProjectIdentifier)

Example 22 with GradleException

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) GradleException(org.gradle.api.GradleException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecHandleBuilder(org.gradle.process.internal.ExecHandleBuilder) File(java.io.File) GradleException(org.gradle.api.GradleException)

Example 23 with GradleException

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);
    }
}
Also used : GradleException(org.gradle.api.GradleException) ConsoleRenderer(org.gradle.internal.logging.ConsoleRenderer)

Example 24 with GradleException

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);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipOutputStream(java.util.zip.ZipOutputStream) GradleException(org.gradle.api.GradleException) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 25 with GradleException

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);
            }
        }
    };
}
Also used : FileWriter(java.io.FileWriter) GradleException(org.gradle.api.GradleException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GradleException(org.gradle.api.GradleException) PrintWriter(java.io.PrintWriter)

Aggregations

GradleException (org.gradle.api.GradleException)99 File (java.io.File)33 IOException (java.io.IOException)25 TaskAction (org.gradle.api.tasks.TaskAction)12 ArrayList (java.util.ArrayList)10 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)8 UncheckedIOException (org.gradle.api.UncheckedIOException)7 HashSet (java.util.HashSet)6 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)5 FileOutputStream (java.io.FileOutputStream)5 Method (java.lang.reflect.Method)5 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)4 URL (java.net.URL)4 List (java.util.List)4 Map (java.util.Map)4 ConsoleRenderer (org.gradle.internal.logging.ConsoleRenderer)4 ClassReader (org.objectweb.asm.ClassReader)4 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)3 MalformedURLException (java.net.MalformedURLException)3