Search in sources :

Example 51 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class SimpleTemplateOperation method generate.

@Override
public void generate() {
    try {
        target.getParentFile().mkdirs();
        SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
        String templateText = Resources.asCharSource(templateURL, CharsetToolkit.getDefaultSystemCharset()).read();
        Template template = templateEngine.createTemplate(templateText);
        Writer writer = Files.asCharSink(target, Charsets.UTF_8).openStream();
        try {
            template.make(bindings).writeTo(writer);
        } finally {
            writer.close();
        }
    } catch (Exception ex) {
        throw new GradleException("Could not generate file " + target + ".", ex);
    }
}
Also used : GradleException(org.gradle.api.GradleException) Writer(java.io.Writer) GradleException(org.gradle.api.GradleException) SimpleTemplateEngine(groovy.text.SimpleTemplateEngine) Template(groovy.text.Template)

Example 52 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class InitBuild method setupProjectLayout.

@TaskAction
public void setupProjectLayout() {
    final String type = getType();
    BuildInitDsl dsl = BuildInitDsl.fromName(getDsl());
    BuildInitTestFramework testFramework = BuildInitTestFramework.fromName(getTestFramework());
    final ProjectLayoutSetupRegistry projectLayoutRegistry = getProjectLayoutRegistry();
    if (!projectLayoutRegistry.supports(type)) {
        String supportedTypes = Joiner.on(", ").join(Iterables.transform(projectLayoutRegistry.getSupportedTypes(), new Function<String, String>() {

            @Override
            public String apply(String input) {
                return "'" + input + "'";
            }
        }));
        throw new GradleException("The requested build setup type '" + type + "' is not supported. Supported types: " + supportedTypes + ".");
    }
    ProjectInitDescriptor initDescriptor = projectLayoutRegistry.get(type);
    if (!testFramework.equals(BuildInitTestFramework.NONE) && !initDescriptor.supports(testFramework)) {
        throw new GradleException("The requested test framework '" + testFramework.getId() + "' is not supported in '" + type + "' setup type");
    }
    initDescriptor.generate(dsl, testFramework);
}
Also used : BuildInitDsl(org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl) ProjectLayoutSetupRegistry(org.gradle.buildinit.plugins.internal.ProjectLayoutSetupRegistry) Function(com.google.common.base.Function) GradleException(org.gradle.api.GradleException) ProjectInitDescriptor(org.gradle.buildinit.plugins.internal.ProjectInitDescriptor) BuildInitTestFramework(org.gradle.buildinit.plugins.internal.modifiers.BuildInitTestFramework) TaskAction(org.gradle.api.tasks.TaskAction)

Example 53 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class JavadocConverter method parse.

public DocComment parse(final PropertyMetaData propertyMetaData, final GenerationListener listener) {
    listener.start(String.format("property %s", propertyMetaData));
    try {
        ClassMetaData ownerClass = propertyMetaData.getOwnerClass();
        String rawCommentText = propertyMetaData.getRawCommentText();
        try {
            CommentSource commentSource = new InheritedPropertyCommentSource(propertyMetaData, listener);
            DocCommentImpl docComment = parse(rawCommentText, ownerClass, commentSource, listener);
            adjustGetterComment(docComment);
            return docComment;
        } catch (Exception e) {
            throw new GradleException(String.format("Could not convert javadoc comment to docbook.%nClass: %s%nProperty: %s%nComment: %s", ownerClass.getClassName(), propertyMetaData.getName(), rawCommentText), e);
        }
    } finally {
        listener.finish();
    }
}
Also used : GradleException(org.gradle.api.GradleException) ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData) GradleException(org.gradle.api.GradleException)

Example 54 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class AbstractClasspathSnapshotBuilder method visitFileTreeSnapshot.

@Override
public void visitFileTreeSnapshot(Collection<FileSnapshot> descendants) {
    ClasspathEntrySnapshotBuilder entryResourceCollectionBuilder = newClasspathEntrySnapshotBuilder();
    try {
        new FileTree(descendants).visit(entryResourceCollectionBuilder);
    } catch (IOException e) {
        throw new GradleException("Error while snapshotting directory in classpath", e);
    }
    entryResourceCollectionBuilder.collectNormalizedSnapshots(builder);
}
Also used : GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 55 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class JavadocGenerator method execute.

@Override
public WorkResult execute(JavadocSpec spec) {
    JavadocExecHandleBuilder javadocExecHandleBuilder = new JavadocExecHandleBuilder(execActionFactory);
    javadocExecHandleBuilder.setExecutable(spec.getExecutable());
    javadocExecHandleBuilder.execDirectory(spec.getWorkingDir()).options(spec.getOptions()).optionsFile(spec.getOptionsFile());
    ExecAction execAction = javadocExecHandleBuilder.getExecHandle();
    if (spec.isIgnoreFailures()) {
        execAction.setIgnoreExitValue(true);
    }
    try {
        execAction.execute();
    } catch (ExecException e) {
        LOG.info("Problems generating Javadoc." + "\n  Command line issued: " + execAction.getCommandLine() + "\n  Generated Javadoc options file has following contents:\n------\n{}------", GFileUtils.readFileQuietly(spec.getOptionsFile()));
        throw new GradleException(String.format("Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '%s'", spec.getOptionsFile()), e);
    }
    return WorkResults.didWork(true);
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) JavadocExecHandleBuilder(org.gradle.external.javadoc.internal.JavadocExecHandleBuilder) ExecException(org.gradle.process.internal.ExecException) GradleException(org.gradle.api.GradleException)

Aggregations

GradleException (org.gradle.api.GradleException)114 File (java.io.File)40 IOException (java.io.IOException)32 TaskAction (org.gradle.api.tasks.TaskAction)16 ArrayList (java.util.ArrayList)10 UncheckedIOException (org.gradle.api.UncheckedIOException)10 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)8 HashSet (java.util.HashSet)8 FileOutputStream (java.io.FileOutputStream)6 Method (java.lang.reflect.Method)6 UncheckedException (org.gradle.internal.UncheckedException)6 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)5 URL (java.net.URL)5 List (java.util.List)5 ConsoleRenderer (org.gradle.internal.logging.ConsoleRenderer)5 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)4 FileInputStream (java.io.FileInputStream)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MalformedURLException (java.net.MalformedURLException)4