Search in sources :

Example 91 with GradleException

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

the class DefaultLegacyTypesSupport method injectEmptyInterfacesIntoClassLoader.

/**
 * Injects the interfaces into an arbitrary classloader via
 * {@link ClassLoader#defineClass(String, byte[], int, int)}.
 */
@Override
public void injectEmptyInterfacesIntoClassLoader(ClassLoader classLoader) {
    try {
        for (String name : syntheticClasses) {
            byte[] bytes = generateSyntheticClass(name);
            ClassLoaderUtils.define(classLoader, name, bytes);
        }
    } catch (Exception e) {
        throw new GradleException("Could not inject synthetic classes.", e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException)

Example 92 with GradleException

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

the class ExecuteActionsTaskExecuter method execute.

public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    listener.beforeActions(task);
    if (task.hasTaskActions()) {
        outputsGenerationListener.beforeTaskOutputChanged();
    }
    state.setExecuting(true);
    try {
        GradleException failure = executeActions(task, state, context);
        if (failure != null) {
            state.setOutcome(failure);
        } else {
            state.setOutcome(state.getDidWork() ? TaskExecutionOutcome.EXECUTED : TaskExecutionOutcome.UP_TO_DATE);
        }
        context.getTaskArtifactState().snapshotAfterTaskExecution(failure, buildInvocationScopeId.getId(), context);
    } finally {
        state.setExecuting(false);
        listener.afterActions(task);
    }
}
Also used : GradleException(org.gradle.api.GradleException)

Example 93 with GradleException

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

the class ResolveTaskOutputCachingStateExecuter method execute.

@Override
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    if (taskOutputCacheEnabled) {
        try {
            TaskOutputCachingState taskOutputCachingState = task.getOutputs().getCachingState(context.getTaskProperties());
            state.setTaskOutputCaching(taskOutputCachingState);
            if (!taskOutputCachingState.isEnabled()) {
                LOGGER.info("Caching disabled for {}: {}", task, taskOutputCachingState.getDisabledReason());
            }
        } catch (Exception t) {
            throw new GradleException(String.format("Could not evaluate TaskOutputs.getCachingState().isEnabled() for %s.", task), t);
        }
    } else {
        state.setTaskOutputCaching(DefaultTaskOutputs.DISABLED);
    }
    delegate.execute(task, state, context);
}
Also used : TaskOutputCachingState(org.gradle.api.internal.TaskOutputCachingState) GradleException(org.gradle.api.GradleException) GradleException(org.gradle.api.GradleException)

Example 94 with GradleException

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

the class InProcessGradleExecuter method doRunWithFailure.

@Override
protected ExecutionFailure doRunWithFailure() {
    if (isForkRequired()) {
        return createGradleHandle().waitForFailure();
    }
    StandardOutputListener outputListener = new OutputListenerImpl();
    BuildListenerImpl buildListener = new BuildListenerImpl();
    try {
        doRun(outputListener, buildListener).rethrowFailure();
        throw new AssertionError("expected build to fail but it did not.");
    } catch (GradleException e) {
        return assertResult(new InProcessExecutionFailure(buildListener.executedTasks, buildListener.skippedTasks, OutputScrapingExecutionFailure.from(outputListener.toString(), ""), e));
    }
}
Also used : StandardOutputListener(org.gradle.api.logging.StandardOutputListener) GradleException(org.gradle.api.GradleException)

Example 95 with GradleException

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

the class JsHint method doJsHint.

@TaskAction
public void doJsHint() {
    RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(getWorkerProcessBuilderFactory());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    JsHintProtocol worker = handleFactory.create(getRhinoClasspath(), JsHintProtocol.class, JsHintWorker.class, logLevel, getProject().getProjectDir());
    JsHintSpec spec = new JsHintSpec();
    // flatten because we need to serialize
    spec.setSource(getSource().getFiles());
    spec.setEncoding(getEncoding());
    spec.setJsHint(getJsHint().getSingleFile());
    JsHintResult result = worker.process(spec);
    setDidWork(true);
    // TODO - this is all terribly lame. We need some proper reporting here (which means implementing Reporting).
    Logger logger = getLogger();
    boolean anyErrors = false;
    Map<String, Map<?, ?>> reportData = new LinkedHashMap<String, Map<?, ?>>(result.getResults().size());
    for (Map.Entry<File, Map<String, Object>> fileEntry : result.getResults().entrySet()) {
        File file = fileEntry.getKey();
        Map<String, Object> data = fileEntry.getValue();
        reportData.put(file.getAbsolutePath(), data);
        if (data.containsKey("errors")) {
            anyErrors = true;
            URI projectDirUri = getProject().getProjectDir().toURI();
            @SuppressWarnings("unchecked") Map<String, Object> errors = (Map<String, Object>) data.get("errors");
            if (!errors.isEmpty()) {
                URI relativePath = projectDirUri.relativize(file.toURI());
                logger.warn("JsHint errors for file: {}", relativePath.getPath());
                for (Map.Entry<String, Object> errorEntry : errors.entrySet()) {
                    @SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) errorEntry.getValue();
                    int line = Float.valueOf(error.get("line").toString()).intValue();
                    int character = Float.valueOf(error.get("character").toString()).intValue();
                    String reason = error.get("reason").toString();
                    logger.warn("  {}:{} > {}", new Object[] { line, character, reason });
                }
            }
        }
    }
    File jsonReportFile = getJsonReport();
    if (jsonReportFile != null) {
        try {
            FileWriter reportWriter = new FileWriter(jsonReportFile);
            new GsonBuilder().setPrettyPrinting().create().toJson(reportData, reportWriter);
            reportWriter.close();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    if (anyErrors) {
        throw new TaskExecutionException(this, new GradleException("JsHint detected errors"));
    }
}
Also used : DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) FileWriter(java.io.FileWriter) UncheckedIOException(org.gradle.api.UncheckedIOException) Logger(org.gradle.api.logging.Logger) URI(java.net.URI) LogLevel(org.gradle.api.logging.LogLevel) LinkedHashMap(java.util.LinkedHashMap) JsHintSpec(org.gradle.plugins.javascript.jshint.internal.JsHintSpec) JsHintResult(org.gradle.plugins.javascript.jshint.internal.JsHintResult) GsonBuilder(com.google.gson.GsonBuilder) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) GradleException(org.gradle.api.GradleException) JsHintProtocol(org.gradle.plugins.javascript.jshint.internal.JsHintProtocol) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) TaskAction(org.gradle.api.tasks.TaskAction)

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