Search in sources :

Example 86 with TaskAction

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

the class PlayRun method run.

@TaskAction
public void run() {
    String deploymentId = getPath();
    DeploymentRegistry deploymentRegistry = getDeploymentRegistry();
    PlayApplicationDeploymentHandle deploymentHandle = deploymentRegistry.get(deploymentId, PlayApplicationDeploymentHandle.class);
    if (deploymentHandle == null) {
        PlayRunSpec spec = new DefaultPlayRunSpec(runtimeClasspath, changingClasspath, applicationJar, assetsJar, assetsDirs, workingDir.get().getAsFile(), getForkOptions(), getHttpPort());
        PlayApplicationRunner playApplicationRunner = playToolProvider.get(PlayApplicationRunner.class);
        deploymentHandle = deploymentRegistry.start(deploymentId, DeploymentRegistry.ChangeBehavior.BLOCK, PlayApplicationDeploymentHandle.class, spec, playApplicationRunner);
        InetSocketAddress playAppAddress = deploymentHandle.getPlayAppAddress();
        String playUrl = "http://localhost:" + playAppAddress.getPort() + "/";
        LOGGER.warn("Running Play App ({}) at {}", getPath(), playUrl);
    }
}
Also used : DefaultPlayRunSpec(org.gradle.play.internal.run.DefaultPlayRunSpec) DeploymentRegistry(org.gradle.deployment.internal.DeploymentRegistry) PlayApplicationRunner(org.gradle.play.internal.run.PlayApplicationRunner) InetSocketAddress(java.net.InetSocketAddress) PlayRunSpec(org.gradle.play.internal.run.PlayRunSpec) DefaultPlayRunSpec(org.gradle.play.internal.run.DefaultPlayRunSpec) PlayApplicationDeploymentHandle(org.gradle.play.internal.run.PlayApplicationDeploymentHandle) TaskAction(org.gradle.api.tasks.TaskAction)

Example 87 with TaskAction

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

the class ApiJar method createApiJar.

@TaskAction
public void createApiJar() throws IOException {
    // Make sure all entries are always written in the same order
    final List<File> sourceFiles = sortedSourceFiles();
    final ApiClassExtractor apiClassExtractor = new ApiClassExtractor(getExportedPackages());
    withResource(new JarOutputStream(new BufferedOutputStream(new FileOutputStream(getOutputFile()), 65536)), new ErroringAction<JarOutputStream>() {

        @Override
        protected void doExecute(final JarOutputStream jos) throws Exception {
            writeManifest(jos);
            writeClasses(jos);
        }

        private void writeManifest(JarOutputStream jos) throws IOException {
            writeEntry(jos, "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n".getBytes());
        }

        private void writeClasses(JarOutputStream jos) throws Exception {
            for (File sourceFile : sourceFiles) {
                if (!isClassFile(sourceFile)) {
                    continue;
                }
                ClassReader classReader = new PatchedClassReader(readFileToByteArray(sourceFile));
                if (!apiClassExtractor.shouldExtractApiClassFrom(classReader)) {
                    continue;
                }
                byte[] apiClassBytes = apiClassExtractor.extractApiClassFrom(classReader);
                if (apiClassBytes == null) {
                    // Should be excluded
                    continue;
                }
                String internalClassName = classReader.getClassName();
                String entryPath = internalClassName + ".class";
                writeEntry(jos, entryPath, apiClassBytes);
            }
        }

        private void writeEntry(JarOutputStream jos, String name, byte[] bytes) throws IOException {
            JarEntry je = new JarEntry(name);
            // Setting time to 0 because we need API jars to be identical independently of
            // the timestamps of class files
            je.setTime(0);
            je.setSize(bytes.length);
            jos.putNextEntry(je);
            jos.write(bytes);
            jos.closeEntry();
        }
    });
}
Also used : JarOutputStream(java.util.jar.JarOutputStream) ApiClassExtractor(org.gradle.api.internal.tasks.compile.ApiClassExtractor) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) PatchedClassReader(org.gradle.util.internal.PatchedClassReader) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) PatchedClassReader(org.gradle.util.internal.PatchedClassReader) ClassReader(org.objectweb.asm.ClassReader) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) BufferedOutputStream(java.io.BufferedOutputStream) TaskAction(org.gradle.api.tasks.TaskAction)

Example 88 with TaskAction

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

the class CreateStaticLibrary method link.

// TODO: Need to track version/implementation of ar tool.
@TaskAction
public void link() {
    StaticLibraryArchiverSpec spec = new DefaultStaticLibraryArchiverSpec();
    spec.setTempDir(getTemporaryDir());
    spec.setOutputFile(getOutputFile().get().getAsFile());
    spec.objectFiles(getSource());
    spec.args(getStaticLibArgs().get());
    BuildOperationLogger operationLogger = getOperationLoggerFactory().newOperationLogger(getName(), getTemporaryDir());
    spec.setOperationLogger(operationLogger);
    Compiler<StaticLibraryArchiverSpec> compiler = createCompiler();
    WorkResult result = BuildOperationLoggingCompilerDecorator.wrap(compiler).execute(spec);
    setDidWork(result.getDidWork());
}
Also used : DefaultStaticLibraryArchiverSpec(org.gradle.nativeplatform.internal.DefaultStaticLibraryArchiverSpec) StaticLibraryArchiverSpec(org.gradle.nativeplatform.internal.StaticLibraryArchiverSpec) DefaultStaticLibraryArchiverSpec(org.gradle.nativeplatform.internal.DefaultStaticLibraryArchiverSpec) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) WorkResult(org.gradle.api.tasks.WorkResult) TaskAction(org.gradle.api.tasks.TaskAction)

Example 89 with TaskAction

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

the class StripSymbols method stripSymbols.

// TODO: Need to track version/implementation of symbol strip tool.
@TaskAction
public void stripSymbols() {
    BuildOperationLogger operationLogger = getServices().get(BuildOperationLoggerFactory.class).newOperationLogger(getName(), getTemporaryDir());
    StripperSpec spec = new DefaultStripperSpec();
    spec.setBinaryFile(binaryFile.get().getAsFile());
    spec.setOutputFile(outputFile.get().getAsFile());
    spec.setOperationLogger(operationLogger);
    Compiler<StripperSpec> symbolStripper = createCompiler();
    symbolStripper = BuildOperationLoggingCompilerDecorator.wrap(symbolStripper);
    WorkResult result = symbolStripper.execute(spec);
    setDidWork(result.getDidWork());
}
Also used : BuildOperationLoggerFactory(org.gradle.internal.operations.logging.BuildOperationLoggerFactory) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) DefaultStripperSpec(org.gradle.nativeplatform.internal.DefaultStripperSpec) StripperSpec(org.gradle.nativeplatform.internal.StripperSpec) WorkResult(org.gradle.api.tasks.WorkResult) DefaultStripperSpec(org.gradle.nativeplatform.internal.DefaultStripperSpec) TaskAction(org.gradle.api.tasks.TaskAction)

Example 90 with TaskAction

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

the class GenerateMavenPom method doGenerate.

@TaskAction
public void doGenerate() {
    MavenPomInternal pomInternal = (MavenPomInternal) getPom();
    MavenPomFileGenerator pomGenerator = new MavenPomFileGenerator(pomInternal.getProjectIdentity(), getVersionRangeMapper());
    pomGenerator.setPackaging(pomInternal.getPackaging());
    for (MavenDependency mavenDependency : pomInternal.getApiDependencyManagement()) {
        pomGenerator.addApiDependencyManagement(mavenDependency);
    }
    for (MavenDependency mavenDependency : pomInternal.getRuntimeDependencyManagement()) {
        pomGenerator.addRuntimeDependencyManagement(mavenDependency);
    }
    for (MavenDependencyInternal runtimeDependency : pomInternal.getApiDependencies()) {
        pomGenerator.addApiDependency(runtimeDependency);
    }
    for (MavenDependencyInternal runtimeDependency : pomInternal.getRuntimeDependencies()) {
        pomGenerator.addRuntimeDependency(runtimeDependency);
    }
    pomGenerator.withXml(pomInternal.getXmlAction());
    pomGenerator.writeTo(getDestination());
}
Also used : MavenPomInternal(org.gradle.api.publish.maven.internal.publication.MavenPomInternal) MavenPomFileGenerator(org.gradle.api.publish.maven.internal.tasks.MavenPomFileGenerator) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal) MavenDependency(org.gradle.api.publish.maven.MavenDependency) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

TaskAction (org.gradle.api.tasks.TaskAction)92 File (java.io.File)40 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)22 GradleException (org.gradle.api.GradleException)15 ArrayList (java.util.ArrayList)11 InputFile (org.gradle.api.tasks.InputFile)11 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)10 OutputFile (org.gradle.api.tasks.OutputFile)10 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)9 IOException (java.io.IOException)8 Project (org.gradle.api.Project)8 WorkResult (org.gradle.api.tasks.WorkResult)8 BuildOperationLogger (org.gradle.internal.operations.logging.BuildOperationLogger)8 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)7 InvalidUserDataException (org.gradle.api.InvalidUserDataException)7 HashSet (java.util.HashSet)6 SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)5 AndroidLibrary (com.android.builder.model.AndroidLibrary)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4