Search in sources :

Example 41 with TaskAction

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

the class GenerateDefaultImportsTask method generate.

@TaskAction
public void generate() throws IOException {
    SimpleClassMetaDataRepository<ClassMetaData> repository = new SimpleClassMetaDataRepository<>();
    repository.load(getMetaDataFile().getAsFile().get());
    final Set<String> excludedPrefixes = new HashSet<>();
    final Set<String> excludedPackages = new HashSet<>();
    for (String excludePattern : excludePatterns) {
        if (excludePattern.endsWith(".**")) {
            String baseName = excludePattern.substring(0, excludePattern.length() - 3);
            excludedPrefixes.add(baseName + '.');
            excludedPackages.add(baseName);
        } else {
            excludedPackages.add(excludePattern);
        }
    }
    final Set<String> packages = new LinkedHashSet<>();
    final Multimap<String, String> simpleNames = LinkedHashMultimap.create();
    repository.each(new Action<ClassMetaData>() {

        public void execute(ClassMetaData classMetaData) {
            if (classMetaData.getOuterClassName() != null) {
                // Ignore inner classes
                return;
            }
            String packageName = classMetaData.getPackageName();
            if (excludedPackages.contains(packageName)) {
                return;
            }
            for (String excludedPrefix : excludedPrefixes) {
                if (packageName.startsWith(excludedPrefix)) {
                    return;
                }
            }
            simpleNames.put(classMetaData.getSimpleName(), classMetaData.getClassName());
            packages.add(packageName);
        }
    });
    try (PrintWriter mappingFileWriter = new PrintWriter(new FileWriter(getMappingDestFile().getAsFile().get()))) {
        for (Map.Entry<String, Collection<String>> entry : simpleNames.asMap().entrySet()) {
            if (entry.getValue().size() > 1) {
                System.out.println(String.format("Multiple DSL types have short name '%s'", entry.getKey()));
                for (String className : entry.getValue()) {
                    System.out.println("    * " + className);
                }
            }
            mappingFileWriter.print(entry.getKey());
            mappingFileWriter.print(":");
            for (String className : entry.getValue()) {
                mappingFileWriter.print(className);
                mappingFileWriter.print(";");
            }
            mappingFileWriter.println();
        }
    }
    try (PrintWriter writer = new PrintWriter(new FileWriter(getImportsDestFile().getAsFile().get()))) {
        for (String packageName : packages) {
            writer.print("import ");
            writer.print(packageName);
            writer.println(".*");
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileWriter(java.io.FileWriter) Collection(java.util.Collection) Map(java.util.Map) ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData) SimpleClassMetaDataRepository(org.gradle.build.docs.model.SimpleClassMetaDataRepository) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) PrintWriter(java.io.PrintWriter) TaskAction(org.gradle.api.tasks.TaskAction)

Example 42 with TaskAction

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

the class Assemble method assemble.

@TaskAction
public void assemble() {
    BuildOperationLogger operationLogger = getOperationLoggerFactory().newOperationLogger(getName(), getTemporaryDir());
    SimpleStaleClassCleaner cleaner = new SimpleStaleClassCleaner(getOutputs());
    cleaner.setDestinationDir(getObjectFileDir());
    cleaner.execute();
    DefaultAssembleSpec spec = new DefaultAssembleSpec();
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(getObjectFileDir());
    spec.source(getSource());
    spec.include(getIncludes());
    spec.args(getAssemblerArgs());
    spec.setOperationLogger(operationLogger);
    NativeToolChainInternal nativeToolChain = (NativeToolChainInternal) toolChain.get();
    NativePlatformInternal nativePlatform = (NativePlatformInternal) targetPlatform.get();
    Compiler<AssembleSpec> compiler = nativeToolChain.select(nativePlatform).newCompiler(AssembleSpec.class);
    WorkResult result = BuildOperationLoggingCompilerDecorator.wrap(compiler).execute(spec);
    setDidWork(result.getDidWork());
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) AssembleSpec(org.gradle.nativeplatform.toolchain.internal.compilespec.AssembleSpec) DefaultAssembleSpec(org.gradle.language.assembler.internal.DefaultAssembleSpec) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) DefaultAssembleSpec(org.gradle.language.assembler.internal.DefaultAssembleSpec) WorkResult(org.gradle.api.tasks.WorkResult) SimpleStaleClassCleaner(org.gradle.language.base.internal.tasks.SimpleStaleClassCleaner) TaskAction(org.gradle.api.tasks.TaskAction)

Example 43 with TaskAction

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

the class AbstractNativeCompileTask method compile.

@TaskAction
public void compile(IncrementalTaskInputs inputs) {
    BuildOperationLogger operationLogger = getOperationLoggerFactory().newOperationLogger(getName(), getTemporaryDir());
    NativeCompileSpec spec = createCompileSpec();
    spec.setTargetPlatform(targetPlatform.get());
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(objectFileDir.get().getAsFile());
    spec.include(includes);
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs().get());
    spec.setPositionIndependentCode(isPositionIndependentCode());
    spec.setDebuggable(isDebuggable());
    spec.setOptimized(isOptimized());
    spec.setIncrementalCompile(inputs.isIncremental());
    spec.setOperationLogger(operationLogger);
    configureSpec(spec);
    NativeToolChainInternal nativeToolChain = (NativeToolChainInternal) toolChain.get();
    NativePlatformInternal nativePlatform = (NativePlatformInternal) targetPlatform.get();
    PlatformToolProvider platformToolProvider = nativeToolChain.select(nativePlatform);
    setDidWork(doCompile(spec, platformToolProvider).getDidWork());
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativeCompileSpec(org.gradle.nativeplatform.toolchain.internal.NativeCompileSpec) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) TaskAction(org.gradle.api.tasks.TaskAction)

Example 44 with TaskAction

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

the class WindowsResourceCompile method compile.

@TaskAction
public void compile(IncrementalTaskInputs inputs) {
    BuildOperationLogger operationLogger = getOperationLoggerFactory().newOperationLogger(getName(), getTemporaryDir());
    NativeCompileSpec spec = new DefaultWindowsResourceCompileSpec();
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(getOutputDir());
    spec.include(getIncludes());
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs());
    spec.setIncrementalCompile(inputs.isIncremental());
    spec.setOperationLogger(operationLogger);
    NativeToolChainInternal nativeToolChain = (NativeToolChainInternal) toolChain.get();
    NativePlatformInternal nativePlatform = (NativePlatformInternal) targetPlatform.get();
    PlatformToolProvider platformToolProvider = nativeToolChain.select(nativePlatform);
    WorkResult result = doCompile(spec, platformToolProvider);
    setDidWork(result.getDidWork());
}
Also used : NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) DefaultWindowsResourceCompileSpec(org.gradle.language.rc.internal.DefaultWindowsResourceCompileSpec) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativeCompileSpec(org.gradle.nativeplatform.toolchain.internal.NativeCompileSpec) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) WorkResult(org.gradle.api.tasks.WorkResult) TaskAction(org.gradle.api.tasks.TaskAction)

Example 45 with TaskAction

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

the class UnexportMainSymbol method unexport.

@TaskAction
public void unexport() {
    final File mainObjectFile = getMainObject();
    if (mainObjectFile != null) {
        final File relocatedMainObject = outputDirectory.file(mainObjectFile.getName()).get().getAsFile();
        getProject().exec(new Action<ExecSpec>() {

            @Override
            public void execute(ExecSpec execSpec) {
                if (OperatingSystem.current().isMacOsX()) {
                    // TODO: Locate this tool from a tool provider
                    execSpec.executable("ld");
                    execSpec.args(mainObjectFile);
                    execSpec.args("-o", relocatedMainObject);
                    // relink, produce another object file
                    execSpec.args("-r");
                    // hide _main symbol
                    execSpec.args("-unexported_symbol", "_main");
                } else if (OperatingSystem.current().isLinux()) {
                    // TODO: Locate this tool from a tool provider
                    execSpec.executable("objcopy");
                    // hide main symbol
                    execSpec.args("-L", "main");
                    execSpec.args(mainObjectFile);
                    execSpec.args(relocatedMainObject);
                } else {
                    throw new IllegalStateException("Do not know how to hide a main symbol on " + OperatingSystem.current());
                }
            }
        });
        setDidWork(true);
    } else {
        setDidWork(getProject().delete(outputDirectory));
    }
}
Also used : ExecSpec(org.gradle.process.ExecSpec) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) 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