Search in sources :

Example 21 with TaskAction

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

the class ScalaDoc method generate.

@TaskAction
protected void generate() {
    ScalaDocOptions options = getScalaDocOptions();
    if (!GUtil.isTrue(options.getDocTitle())) {
        options.setDocTitle(getTitle());
    }
    AntScalaDoc antScalaDoc = new AntScalaDoc(getAntBuilder());
    antScalaDoc.execute(getSource(), getDestinationDir(), getClasspath(), getScalaClasspath(), options);
}
Also used : AntScalaDoc(org.gradle.api.internal.tasks.scala.AntScalaDoc) TaskAction(org.gradle.api.tasks.TaskAction)

Example 22 with TaskAction

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

the class PublishToMavenLocal method publish.

@TaskAction
public void publish() {
    final MavenPublicationInternal publication = getPublicationInternal();
    if (publication == null) {
        throw new InvalidUserDataException("The 'publication' property is required");
    }
    new PublishOperation(publication, "mavenLocal") {

        @Override
        protected void publish() throws Exception {
            MavenPublisher localPublisher = new MavenLocalPublisher(getLoggingManagerFactory(), getMavenRepositoryLocator());
            MavenPublisher staticLockingPublisher = new StaticLockingMavenPublisher(localPublisher);
            MavenPublisher validatingPublisher = new ValidatingMavenPublisher(staticLockingPublisher);
            validatingPublisher.publish(publication.asNormalisedPublication(), null);
        }
    }.run();
}
Also used : MavenLocalPublisher(org.gradle.api.publish.maven.internal.publisher.MavenLocalPublisher) InvalidUserDataException(org.gradle.api.InvalidUserDataException) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) ValidatingMavenPublisher(org.gradle.api.publish.maven.internal.publisher.ValidatingMavenPublisher) PublishOperation(org.gradle.api.publish.internal.PublishOperation) InvalidUserDataException(org.gradle.api.InvalidUserDataException) StaticLockingMavenPublisher(org.gradle.api.publish.maven.internal.publisher.StaticLockingMavenPublisher) MavenPublisher(org.gradle.api.publish.maven.internal.publisher.MavenPublisher) StaticLockingMavenPublisher(org.gradle.api.publish.maven.internal.publisher.StaticLockingMavenPublisher) ValidatingMavenPublisher(org.gradle.api.publish.maven.internal.publisher.ValidatingMavenPublisher) TaskAction(org.gradle.api.tasks.TaskAction)

Example 23 with TaskAction

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

the class PublishToMavenRepository method publish.

@TaskAction
public void publish() {
    MavenPublicationInternal publicationInternal = getPublicationInternal();
    if (publicationInternal == null) {
        throw new InvalidUserDataException("The 'publication' property is required");
    }
    MavenArtifactRepository repository = getRepository();
    if (repository == null) {
        throw new InvalidUserDataException("The 'repository' property is required");
    }
    doPublish(publicationInternal, repository);
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) TaskAction(org.gradle.api.tasks.TaskAction)

Example 24 with TaskAction

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

the class Test method executeTests.

@TaskAction
public void executeTests() {
    LogLevel currentLevel = determineCurrentLogLevel();
    TestLogging levelLogging = testLogging.get(currentLevel);
    TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
    TestEventLogger eventLogger = new TestEventLogger(getTextOutputFactory(), currentLevel, levelLogging, exceptionFormatter);
    addTestListener(eventLogger);
    addTestOutputListener(eventLogger);
    if (getFilter().isFailOnNoMatchingTests() && !getFilter().getIncludePatterns().isEmpty()) {
        addTestListener(new NoMatchingTestsReporter("No tests found for given includes: " + getFilter().getIncludePatterns()));
    }
    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);
    testListenerInternalBroadcaster.add(new TestListenerAdapter(testListenerBroadcaster.getSource(), testOutputListenerBroadcaster.getSource()));
    TestResultProcessor resultProcessor = new StateTrackingTestResultProcessor(testListenerInternalBroadcaster.getSource());
    if (testExecuter == null) {
        testExecuter = new DefaultTestExecuter(getProcessBuilderFactory(), getActorFactory(), getModuleRegistry(), getServices().get(BuildOperationWorkerRegistry.class), getServices().get(BuildOperationExecutor.class), getServices().get(StartParameter.class).getMaxWorkerCount());
    }
    JavaVersion javaVersion = getJavaVersion();
    if (!javaVersion.isJava6Compatible()) {
        throw new UnsupportedJavaRuntimeException("Support for test execution using Java 5 or earlier was removed in Gradle 3.0.");
    }
    try {
        testExecuter.execute(this, resultProcessor);
    } finally {
        testExecuter = null;
        testListenerBroadcaster.removeAll();
        testOutputListenerBroadcaster.removeAll();
        testListenerInternalBroadcaster.removeAll();
        outputWriter.close();
    }
    new TestResultSerializer(binaryResultsDir).write(results.values());
    TestResultsProvider testResultsProvider = new InMemoryTestResultsProvider(results.values(), testOutputStore);
    try {
        if (testReporter == null) {
            testReporter = new DefaultTestReport(getBuildOperationProcessor());
        }
        JUnitXmlReport junitXml = reports.getJunitXml();
        if (junitXml.isEnabled()) {
            TestOutputAssociation outputAssociation = junitXml.isOutputPerTestCase() ? TestOutputAssociation.WITH_TESTCASE : TestOutputAssociation.WITH_SUITE;
            Binary2JUnitXmlReportGenerator binary2JUnitXmlReportGenerator = new Binary2JUnitXmlReportGenerator(junitXml.getDestination(), testResultsProvider, outputAssociation, getBuildOperationProcessor(), getInetAddressFactory().getHostname());
            binary2JUnitXmlReportGenerator.generate();
        }
        DirectoryReport html = reports.getHtml();
        if (!html.isEnabled()) {
            getLogger().info("Test report disabled, omitting generation of the HTML test report.");
        } else {
            testReporter.generateReport(testResultsProvider, html.getDestination());
        }
    } finally {
        CompositeStoppable.stoppable(testResultsProvider).stop();
        testReporter = null;
        testFramework = null;
    }
    if (testCountLogger.hadFailures()) {
        handleTestFailures();
    }
}
Also used : TestResultSerializer(org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer) InMemoryTestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider) TestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.TestResultsProvider) InMemoryTestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider) 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) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) JavaVersion(org.gradle.api.JavaVersion) LogLevel(org.gradle.api.logging.LogLevel) TestEventLogger(org.gradle.api.internal.tasks.testing.logging.TestEventLogger) TestReportDataCollector(org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector) StartParameter(org.gradle.StartParameter) TestOutputAssociation(org.gradle.api.internal.tasks.testing.junit.result.TestOutputAssociation) TestLogging(org.gradle.api.tasks.testing.logging.TestLogging) NoMatchingTestsReporter(org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter) UnsupportedJavaRuntimeException(org.gradle.internal.jvm.UnsupportedJavaRuntimeException) TestListenerAdapter(org.gradle.api.internal.tasks.testing.results.TestListenerAdapter) DefaultTestExecuter(org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter) Binary2JUnitXmlReportGenerator(org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator) TestOutputStore(org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore) TestExceptionFormatter(org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter) File(java.io.File) DefaultTestReport(org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport) DirectoryReport(org.gradle.api.reporting.DirectoryReport) TaskAction(org.gradle.api.tasks.TaskAction)

Example 25 with TaskAction

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

the class AbstractFlywayTask method runTask.

@TaskAction
public Object runTask() {
    try {
        List<URL> extraURLs = new ArrayList<URL>();
        if (isJavaProject()) {
            JavaPluginConvention plugin = getProject().getConvention().getPlugin(JavaPluginConvention.class);
            for (SourceSet sourceSet : plugin.getSourceSets()) {
                URL classesUrl = sourceSet.getOutput().getClassesDir().toURI().toURL();
                getLogger().debug("Adding directory to Classpath: " + classesUrl);
                extraURLs.add(classesUrl);
                URL resourcesUrl = sourceSet.getOutput().getResourcesDir().toURI().toURL();
                getLogger().debug("Adding directory to Classpath: " + resourcesUrl);
                extraURLs.add(resourcesUrl);
            }
            addDependenciesWithScope(extraURLs, "compile");
            addDependenciesWithScope(extraURLs, "runtime");
            addDependenciesWithScope(extraURLs, "testCompile");
            addDependenciesWithScope(extraURLs, "testRuntime");
        }
        ClassLoader classLoader = new URLClassLoader(extraURLs.toArray(new URL[extraURLs.size()]), getProject().getBuildscript().getClassLoader());
        Flyway flyway = new Flyway();
        flyway.setClassLoader(classLoader);
        flyway.configure(createFlywayConfig());
        return run(flyway);
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Flyway(org.flywaydb.core.Flyway) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) FlywayException(org.flywaydb.core.api.FlywayException) IOException(java.io.IOException) 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