Search in sources :

Example 11 with TaskExecutionException

use of org.gradle.api.tasks.TaskExecutionException in project cayenne by apache.

the class DbImportTask method runImport.

@TaskAction
public void runImport() {
    dataSource.validate();
    final Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()), new DbImportModule(), binder -> binder.bind(ClassLoaderManager.class).toInstance(new DefaultClassLoaderManager()));
    final DbImportConfiguration config = createConfig();
    DataSourceFactory dataSourceFactory = injector.getInstance(DataSourceFactory.class);
    DbAdapterFactory dbAdapterFactory = injector.getInstance(DbAdapterFactory.class);
    DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
    try {
        DataSource dataSource = dataSourceFactory.getDataSource(dataNodeDescriptor);
        DbAdapter dbAdapter = dbAdapterFactory.createAdapter(dataNodeDescriptor, dataSource);
        config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering).dataSource(dataSource).dbAdapter(dbAdapter).build());
    } catch (Exception e) {
        throw new TaskExecutionException(this, e);
    }
    final DbImportConfigurationValidator validator = new DbImportConfigurationValidator(reverseEngineering, config, injector);
    try {
        validator.validate();
    } catch (Exception ex) {
        throw new TaskExecutionException(this, ex);
    }
    try {
        injector.getInstance(DbImportAction.class).execute(config);
    } catch (Exception ex) {
        final Throwable th = Util.unwindException(ex);
        String message = "Error importing database schema";
        if (th.getLocalizedMessage() != null) {
            message += ": " + th.getLocalizedMessage();
        }
        getLogger().error(message);
        throw new TaskExecutionException(this, th);
    }
}
Also used : DataSourceFactory(org.apache.cayenne.configuration.server.DataSourceFactory) DbImportConfigurationValidator(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DbImportAction(org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) DataSource(javax.sql.DataSource) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) DbAdapterFactory(org.apache.cayenne.configuration.server.DbAdapterFactory) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) DbAdapter(org.apache.cayenne.dba.DbAdapter) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DbImportModule(org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule) TaskAction(org.gradle.api.tasks.TaskAction)

Example 12 with TaskExecutionException

use of org.gradle.api.tasks.TaskExecutionException in project gradle by gradle.

the class DefaultExceptionAnalyserTest method prefersLocationAwareExceptionOverScriptException.

@Test
public void prefersLocationAwareExceptionOverScriptException() {
    Throwable cause = locationAwareException(new GradleScriptException("broken", new RuntimeException()));
    Throwable failure = new TaskExecutionException(null, cause);
    DefaultExceptionAnalyser analyser = analyser();
    assertThat(analyser.transform(failure), sameInstance(cause));
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) GradleScriptException(org.gradle.api.GradleScriptException) Test(org.junit.Test)

Example 13 with TaskExecutionException

use of org.gradle.api.tasks.TaskExecutionException in project gradle by gradle.

the class DefaultExceptionAnalyserTest method prefersScriptExceptionOverContextualException.

@Test
public void prefersScriptExceptionOverContextualException() {
    Throwable cause = new GradleScriptException("broken", new ContextualException());
    Throwable failure = new TaskExecutionException(null, cause);
    Throwable transformedFailure = analyser().transform(failure);
    assertThat(transformedFailure, instanceOf(LocationAwareException.class));
    LocationAwareException gse = (LocationAwareException) transformedFailure;
    assertThat(gse.getCause(), sameInstance(cause));
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) GradleScriptException(org.gradle.api.GradleScriptException) Test(org.junit.Test)

Example 14 with TaskExecutionException

use of org.gradle.api.tasks.TaskExecutionException in project gradle by gradle.

the class ExecuteActionsTaskExecuter method executeActions.

private GradleException executeActions(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    LOGGER.debug("Executing actions for {}.", task);
    final List<ContextAwareTaskAction> actions = new ArrayList<ContextAwareTaskAction>(task.getTaskActions());
    for (ContextAwareTaskAction action : actions) {
        state.setDidWork(true);
        task.getStandardOutputCapture().start();
        try {
            executeAction(action.getDisplayName(), task, action, context);
        } catch (StopActionException e) {
            // Ignore
            LOGGER.debug("Action stopped by some action with message: {}", e.getMessage());
        } catch (StopExecutionException e) {
            LOGGER.info("Execution stopped by some action with message: {}", e.getMessage());
            break;
        } catch (Throwable t) {
            return new TaskExecutionException(task, t);
        } finally {
            task.getStandardOutputCapture().stop();
        }
    }
    return null;
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) StopExecutionException(org.gradle.api.tasks.StopExecutionException) ContextAwareTaskAction(org.gradle.api.internal.tasks.ContextAwareTaskAction) StopActionException(org.gradle.api.tasks.StopActionException) ArrayList(java.util.ArrayList)

Example 15 with TaskExecutionException

use of org.gradle.api.tasks.TaskExecutionException 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

TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)20 TaskAction (org.gradle.api.tasks.TaskAction)9 IOException (java.io.IOException)5 File (java.io.File)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 GradleException (org.gradle.api.GradleException)2 GradleScriptException (org.gradle.api.GradleScriptException)2 TaskInternal (org.gradle.api.internal.TaskInternal)2 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 Test (org.junit.Test)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 GsonBuilder (com.google.gson.GsonBuilder)1 FunctionConfiguration (com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration)1 AnnotationHandler (com.microsoft.azure.gradle.functions.handlers.AnnotationHandler)1 FunctionTemplate (com.microsoft.azure.gradle.functions.template.FunctionTemplate)1 AzureAuthFailureException (com.microsoft.azure.gradle.webapp.auth.AzureAuthFailureException)1