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);
}
}
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));
}
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));
}
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;
}
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"));
}
}
Aggregations