Search in sources :

Example 36 with TaskAction

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

the class DbGenerateTask method generateDb.

@TaskAction
public void generateDb() throws GradleException {
    dataSource.validate();
    getLogger().info("connection settings - [driver: {}, url: {}, username: {}]", dataSource.getDriver(), dataSource.getUrl(), dataSource.getUsername());
    getLogger().info("generator options - " + "[dropTables: {}, dropPK: {}, createTables: {}, createPK: {}, createFK: {}]", dropTables, dropPK, createTables, createPK, createFK);
    Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()));
    try {
        DbGenerator generator = createGenerator(loadDataMap(injector));
        generator.runGenerator(createDataSource());
    } catch (Exception ex) {
        Throwable th = Util.unwindException(ex);
        String message = "Error generating database";
        if (th.getLocalizedMessage() != null) {
            message += ": " + th.getLocalizedMessage();
        }
        getLogger().error(message);
        throw new GradleException(message, th);
    }
}
Also used : Injector(org.apache.cayenne.di.Injector) GradleException(org.gradle.api.GradleException) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) DbGenerator(org.apache.cayenne.access.DbGenerator) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) GradleException(org.gradle.api.GradleException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 37 with TaskAction

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

the class DbImportTask method runImport.

@TaskAction
public void runImport() {
    dataSource.validate();
    DbImportConfiguration config = createConfig();
    Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()), new DbImportModule());
    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) {
        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 : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) Injector(org.apache.cayenne.di.Injector) DbImportConfigurationValidator(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) DbImportAction(org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) DbImportModule(org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 38 with TaskAction

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

the class InstallXCTestBundle method install.

@TaskAction
void install() throws IOException {
    File bundleFile = bundleBinaryFile.get().getAsFile();
    File bundleDir = installDirectory.get().file(bundleFile.getName() + ".xctest").getAsFile();
    installToDir(bundleDir, bundleFile);
    File runScript = getRunScriptFile().get().getAsFile();
    String runScriptText = "#!/bin/sh" + "\nAPP_BASE_NAME=`dirname \"$0\"`" + "\nXCTEST_LOCATION=`xcrun --find xctest`" + "\nexec \"$XCTEST_LOCATION\" \"$@\" \"$APP_BASE_NAME/" + bundleDir.getName() + "\"" + "\n";
    GFileUtils.writeFile(runScriptText, runScript);
    getFileSystem().chmod(runScript, 0755);
}
Also used : File(java.io.File) RegularFile(org.gradle.api.file.RegularFile) InputFile(org.gradle.api.tasks.InputFile) TaskAction(org.gradle.api.tasks.TaskAction)

Example 39 with TaskAction

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

the class AbstractTestTask method executeTests.

@TaskAction
public void executeTests() {
    if (getFilter().isFailOnNoMatchingTests() && (!getFilter().getIncludePatterns().isEmpty() || !filter.getCommandLineIncludePatterns().isEmpty())) {
        addTestListener(new NoMatchingTestsReporter(createNoMatchingTestErrorMessage()));
    }
    LogLevel currentLevel = determineCurrentLogLevel();
    TestLogging levelLogging = getTestLogging().get(currentLevel);
    TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
    TestEventLogger eventLogger = new TestEventLogger(getTextOutputFactory(), currentLevel, levelLogging, exceptionFormatter);
    addTestListener(eventLogger);
    addTestOutputListener(eventLogger);
    TestExecutionSpec executionSpec = createTestExecutionSpec();
    File binaryResultsDir = getBinResultsDir();
    getProject().delete(binaryResultsDir);
    getProject().mkdir(binaryResultsDir);
    Map<String, TestClassResult> results = new HashMap<String, TestClassResult>();
    TestOutputStore testOutputStore = new TestOutputStore(binaryResultsDir);
    TestOutputStore.Writer outputWriter = testOutputStore.writer();
    TestReportDataCollector testReportDataCollector = new TestReportDataCollector(results, outputWriter);
    addTestListener(testReportDataCollector);
    addTestOutputListener(testReportDataCollector);
    TestCountLogger testCountLogger = new TestCountLogger(getProgressLoggerFactory());
    addTestListener(testCountLogger);
    getTestListenerInternalBroadcaster().add(new TestListenerAdapter(testListenerBroadcaster.getSource(), getTestOutputListenerBroadcaster().getSource()));
    ProgressLogger parentProgressLogger = getProgressLoggerFactory().newOperation(AbstractTestTask.class);
    parentProgressLogger.setDescription("Test Execution");
    parentProgressLogger.started();
    TestWorkerProgressListener testWorkerProgressListener = new TestWorkerProgressListener(getProgressLoggerFactory(), parentProgressLogger);
    getTestListenerInternalBroadcaster().add(testWorkerProgressListener);
    TestExecuter testExecuter = createTestExecuter();
    TestListenerInternal resultProcessorDelegate = getTestListenerInternalBroadcaster().getSource();
    if (failFast) {
        resultProcessorDelegate = new FailFastTestListenerInternal(testExecuter, resultProcessorDelegate);
    }
    TestResultProcessor resultProcessor = new StateTrackingTestResultProcessor(resultProcessorDelegate);
    try {
        testExecuter.execute(executionSpec, resultProcessor);
    } finally {
        parentProgressLogger.completed();
        testWorkerProgressListener.completeAll();
        testListenerBroadcaster.removeAll();
        getTestOutputListenerBroadcaster().removeAll();
        getTestListenerInternalBroadcaster().removeAll();
        outputWriter.close();
    }
    new TestResultSerializer(binaryResultsDir).write(results.values());
    createReporting(results, testOutputStore);
    if (testCountLogger.hadFailures()) {
        handleTestFailures();
    }
}
Also used : TestResultSerializer(org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer) TestLogging(org.gradle.api.tasks.testing.logging.TestLogging) NoMatchingTestsReporter(org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter) HashMap(java.util.HashMap) TestResultProcessor(org.gradle.api.internal.tasks.testing.TestResultProcessor) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestClassResult(org.gradle.api.internal.tasks.testing.junit.result.TestClassResult) TestCountLogger(org.gradle.api.internal.tasks.testing.logging.TestCountLogger) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) TestExecuter(org.gradle.api.internal.tasks.testing.TestExecuter) TestListenerInternal(org.gradle.api.internal.tasks.testing.results.TestListenerInternal) FailFastTestListenerInternal(org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestExecutionSpec(org.gradle.api.internal.tasks.testing.TestExecutionSpec) LogLevel(org.gradle.api.logging.LogLevel) TestListenerAdapter(org.gradle.api.internal.tasks.testing.results.TestListenerAdapter) TestEventLogger(org.gradle.api.internal.tasks.testing.logging.TestEventLogger) TestWorkerProgressListener(org.gradle.api.internal.tasks.testing.logging.TestWorkerProgressListener) TestOutputStore(org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore) TestExceptionFormatter(org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter) FailFastTestListenerInternal(org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal) File(java.io.File) TestReportDataCollector(org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector) TaskAction(org.gradle.api.tasks.TaskAction)

Example 40 with TaskAction

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

Aggregations

TaskAction (org.gradle.api.tasks.TaskAction)167 File (java.io.File)66 GradleException (org.gradle.api.GradleException)38 IOException (java.io.IOException)35 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)32 ArrayList (java.util.ArrayList)29 Project (org.gradle.api.Project)18 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)16 InputFile (org.gradle.api.tasks.InputFile)16 OutputFile (org.gradle.api.tasks.OutputFile)15 FileCollection (org.gradle.api.file.FileCollection)13 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)12 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)12 Map (java.util.Map)12 DefaultTask (org.gradle.api.DefaultTask)12 HashMap (java.util.HashMap)10 InvalidUserDataException (org.gradle.api.InvalidUserDataException)9 AndroidLibrary (com.android.builder.model.AndroidLibrary)8 URLClassLoader (java.net.URLClassLoader)8 WorkResult (org.gradle.api.tasks.WorkResult)8