Search in sources :

Example 81 with TaskAction

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

the class CompareGradleBuilds method compare.

@SuppressWarnings("UnusedDeclaration")
@TaskAction
void compare() {
    GradleBuildInvocationSpec sourceBuild = getSourceBuild();
    GradleBuildInvocationSpec targetBuild = getTargetBuild();
    if (sourceBuild.equals(targetBuild)) {
        getLogger().warn("The source build and target build are identical. Set '{}.targetBuild.gradleVersion' if you want to compare with a different Gradle version.", getName());
    }
    ComparableGradleBuildExecuter sourceBuildExecuter = new ComparableGradleBuildExecuter(sourceBuild);
    ComparableGradleBuildExecuter targetBuildExecuter = new ComparableGradleBuildExecuter(targetBuild);
    Logger logger = getLogger();
    ProgressLogger progressLogger = getProgressLoggerFactory().newOperation(getClass());
    progressLogger.setDescription("Gradle Build Comparison");
    progressLogger.setShortDescription(getName());
    GradleBuildComparison comparison = new GradleBuildComparison(sourceBuildExecuter, targetBuildExecuter, logger, progressLogger, getProject().getGradle());
    comparison.registerType(GeneratedArchiveBuildOutcome.class, new GeneratedArchiveBuildOutcomeComparator(), new GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer(), new GeneratedArchiveBuildOutcomeHtmlRenderer());
    comparison.registerType(UnknownBuildOutcome.class, new UnknownBuildOutcomeComparator(), new UnknownBuildOutcomeComparisonResultHtmlRenderer(), new UnknownBuildOutcomeHtmlRenderer());
    File fileStoreTmpBase = getFileResolver().resolve(String.format(TMP_FILESTORAGE_PREFIX + "-%s-%s", getName(), System.currentTimeMillis()));
    MovableFileStore<String> fileStore = new Files(fileStoreTmpBase);
    Map<String, String> hostAttributes = new LinkedHashMap<String, String>(4);
    hostAttributes.put("Project", getProject().getRootDir().getAbsolutePath());
    hostAttributes.put("Task", getPath());
    hostAttributes.put("Gradle version", GradleVersion.current().getVersion());
    hostAttributes.put("Executed at", new SimpleDateFormat().format(new Date()));
    BuildComparisonResult result = comparison.compare(fileStore, getReportDir(), hostAttributes);
    communicateResult(result);
}
Also used : UnknownBuildOutcomeComparator(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcomeComparator) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) Logger(org.gradle.api.logging.Logger) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) GeneratedArchiveBuildOutcomeComparator(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeComparator) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) BuildComparisonResult(org.gradle.api.plugins.buildcomparison.compare.internal.BuildComparisonResult) DefaultGradleBuildInvocationSpec(org.gradle.api.plugins.buildcomparison.gradle.internal.DefaultGradleBuildInvocationSpec) GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer) ComparableGradleBuildExecuter(org.gradle.api.plugins.buildcomparison.gradle.internal.ComparableGradleBuildExecuter) UnknownBuildOutcomeHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcomeHtmlRenderer) GeneratedArchiveBuildOutcomeHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeHtmlRenderer) UnknownBuildOutcomeComparisonResultHtmlRenderer(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcomeComparisonResultHtmlRenderer) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) GradleBuildComparison(org.gradle.api.plugins.buildcomparison.gradle.internal.GradleBuildComparison) TaskAction(org.gradle.api.tasks.TaskAction)

Example 82 with TaskAction

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

the class Wrapper method generate.

@TaskAction
void generate() {
    File jarFileDestination = getJarFile();
    File unixScript = getScriptFile();
    FileResolver resolver = getFileLookup().getFileResolver(unixScript.getParentFile());
    String jarFileRelativePath = resolver.resolveAsRelativePath(jarFileDestination);
    writeProperties(getPropertiesFile());
    writeWrapperTo(jarFileDestination);
    StartScriptGenerator generator = new StartScriptGenerator();
    generator.setApplicationName("Gradle");
    generator.setMainClassName(GradleWrapperMain.class.getName());
    generator.setClasspath(WrapUtil.toList(jarFileRelativePath));
    generator.setOptsEnvironmentVar("GRADLE_OPTS");
    generator.setExitEnvironmentVar("GRADLE_EXIT_CONSOLE");
    generator.setAppNameSystemProperty("org.gradle.appname");
    generator.setScriptRelPath(unixScript.getName());
    generator.generateUnixScript(unixScript);
    generator.generateWindowsScript(getBatchScript());
}
Also used : GradleWrapperMain(org.gradle.wrapper.GradleWrapperMain) StartScriptGenerator(org.gradle.api.internal.plugins.StartScriptGenerator) FileResolver(org.gradle.api.internal.file.FileResolver) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) TaskAction(org.gradle.api.tasks.TaskAction)

Example 83 with TaskAction

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

the class GenerateSwiftPackageManagerManifest method generate.

@TaskAction
public void generate() {
    DefaultPackage srcPackage = (DefaultPackage) packageProperty.get();
    Path manifest = manifestFile.get().getAsFile().toPath();
    try {
        Path baseDir = manifest.getParent();
        Files.createDirectories(baseDir);
        PrintWriter writer = new PrintWriter(Files.newBufferedWriter(manifest, Charset.forName("utf-8")));
        try {
            writer.println("// swift-tools-version:4.0");
            writer.println("//");
            writer.println("// GENERATED FILE - do not edit");
            writer.println("//");
            writer.println("import PackageDescription");
            writer.println();
            writer.println("let package = Package(");
            writer.println("    name: \"" + getProject().getName() + "\",");
            writer.println("    products: [");
            for (AbstractProduct product : srcPackage.getProducts()) {
                if (product.isExecutable()) {
                    writer.print("        .executable(");
                    writer.print("name: \"");
                    writer.print(product.getName());
                    writer.print("\"");
                } else {
                    writer.print("        .library(");
                    writer.print("name: \"");
                    writer.print(product.getName());
                    DefaultLibraryProduct library = (DefaultLibraryProduct) product;
                    if (library.getLinkage() == Linkage.SHARED) {
                        writer.print("\", type: .dynamic");
                    } else {
                        writer.print("\", type: .static");
                    }
                }
                writer.print(", targets: [\"");
                writer.print(product.getTarget().getName());
                writer.println("\"]),");
            }
            writer.println("    ],");
            if (!srcPackage.getDependencies().isEmpty()) {
                writer.println("    dependencies: [");
                for (Dependency dependency : srcPackage.getDependencies()) {
                    writer.print("        .package(url: \"");
                    if (dependency.getUrl().getScheme().equals("file")) {
                        writer.print(baseDir.relativize(new File(dependency.getUrl()).toPath()));
                    } else {
                        writer.print(dependency.getUrl());
                    }
                    writer.print("\", ");
                    if (dependency instanceof VersionDependency) {
                        VersionDependency versionDependency = (VersionDependency) dependency;
                        if (versionDependency.getUpperBound() == null) {
                            writer.print("from: \"");
                            writer.print(versionDependency.getLowerBound());
                            writer.print("\"");
                        } else if (versionDependency.isUpperInclusive()) {
                            writer.print("\"");
                            writer.print(versionDependency.getLowerBound());
                            writer.print("\"...\"");
                            writer.print(versionDependency.getUpperBound());
                            writer.print("\"");
                        } else {
                            writer.print("\"");
                            writer.print(versionDependency.getLowerBound());
                            writer.print("\"..<\"");
                            writer.print(versionDependency.getUpperBound());
                            writer.print("\"");
                        }
                    } else {
                        writer.print(".branch(\"");
                        writer.print(((BranchDependency) dependency).getBranch());
                        writer.print("\")");
                    }
                    writer.println("),");
                }
                writer.println("    ],");
            }
            writer.println("    targets: [");
            for (DefaultTarget target : srcPackage.getTargets()) {
                writer.println("        .target(");
                writer.print("            name: \"");
                writer.print(target.getName());
                writer.println("\",");
                if (!target.getRequiredTargets().isEmpty() || !target.getRequiredProducts().isEmpty()) {
                    writer.println("            dependencies: [");
                    for (String dep : target.getRequiredTargets()) {
                        writer.print("                .target(name: \"");
                        writer.print(dep);
                        writer.println("\"),");
                    }
                    for (String dep : target.getRequiredProducts()) {
                        writer.print("                .product(name: \"");
                        writer.print(dep);
                        writer.println("\"),");
                    }
                    writer.println("            ],");
                }
                writer.print("            path: \"");
                Path productPath = target.getPath().toPath();
                String relPath = baseDir.relativize(productPath).toString();
                writer.print(relPath.isEmpty() ? "." : relPath);
                writer.println("\",");
                writer.println("            sources: [");
                Set<String> sorted = new TreeSet<String>();
                for (File sourceFile : target.getSourceFiles()) {
                    sorted.add(productPath.relativize(sourceFile.toPath()).toString());
                }
                for (String sourcePath : sorted) {
                    writer.print("                \"");
                    writer.print(sourcePath);
                    writer.println("\",");
                }
                writer.print("            ]");
                if (target.getPublicHeaderDir() != null) {
                    writer.println(",");
                    writer.print("            publicHeadersPath: \"");
                    writer.print(productPath.relativize(target.getPublicHeaderDir().toPath()));
                    writer.print("\"");
                }
                writer.println();
                writer.println("        ),");
            }
            writer.print("    ]");
            if (srcPackage.getSwiftLanguageVersion() != null) {
                writer.println(",");
                writer.print("    swiftLanguageVersions: [");
                writer.print(srcPackage.getSwiftLanguageVersion().getVersion());
                writer.print("]");
            }
            writer.println();
            writer.println(")");
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        throw new GradleException(String.format("Could not write manifest file %s.", manifest), e);
    }
}
Also used : Path(java.nio.file.Path) DefaultTarget(org.gradle.swiftpm.internal.DefaultTarget) AbstractProduct(org.gradle.swiftpm.internal.AbstractProduct) DefaultPackage(org.gradle.swiftpm.internal.DefaultPackage) VersionDependency(org.gradle.swiftpm.internal.VersionDependency) Dependency(org.gradle.swiftpm.internal.Dependency) BranchDependency(org.gradle.swiftpm.internal.BranchDependency) IOException(java.io.IOException) TreeSet(java.util.TreeSet) GradleException(org.gradle.api.GradleException) DefaultLibraryProduct(org.gradle.swiftpm.internal.DefaultLibraryProduct) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) VersionDependency(org.gradle.swiftpm.internal.VersionDependency) PrintWriter(java.io.PrintWriter) TaskAction(org.gradle.api.tasks.TaskAction)

Example 84 with TaskAction

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

the class ValidateTaskProperties method validateTaskClasses.

@TaskAction
public void validateTaskClasses() throws IOException {
    ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
    ClassPath classPath = new DefaultClassPath(Iterables.concat(getClasses(), getClasspath()));
    ClassLoader classLoader = getClassLoaderFactory().createIsolatedClassLoader(classPath);
    Thread.currentThread().setContextClassLoader(classLoader);
    try {
        validateTaskClasses(classLoader);
    } finally {
        Thread.currentThread().setContextClassLoader(previousContextClassLoader);
        ClassLoaderUtils.tryClose(classLoader);
    }
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) TaskAction(org.gradle.api.tasks.TaskAction)

Example 85 with TaskAction

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

the class SwiftCompile method compile.

@TaskAction
void compile(IncrementalTaskInputs inputs) {
    final List<File> removedFiles = Lists.newArrayList();
    final Set<File> changedFiles = Sets.newHashSet();
    boolean isIncremental = inputs.isIncremental();
    // which files changed and marking the compilation incremental or not.
    if (isIncremental) {
        inputs.outOfDate(new Action<InputFileDetails>() {

            @Override
            public void execute(InputFileDetails inputFileDetails) {
                if (inputFileDetails.isModified()) {
                    changedFiles.add(inputFileDetails.getFile());
                }
            }
        });
        inputs.removed(new Action<InputFileDetails>() {

            @Override
            public void execute(InputFileDetails removed) {
                removedFiles.add(removed.getFile());
            }
        });
        Set<File> allSourceFiles = getSource().getFiles();
        if (!allSourceFiles.containsAll(changedFiles)) {
            // If a non-source file changed, the compilation cannot be incremental
            // due to the way the Swift compiler detects changes from other modules
            isIncremental = false;
        }
    }
    BuildOperationLogger operationLogger = getServices().get(BuildOperationLoggerFactory.class).newOperationLogger(getName(), getTemporaryDir());
    NativePlatformInternal targetPlatform = Cast.cast(NativePlatformInternal.class, this.targetPlatform.get());
    SwiftCompileSpec spec = createSpec(operationLogger, isIncremental, changedFiles, removedFiles, targetPlatform);
    Compiler<SwiftCompileSpec> baseCompiler = new IncrementalSwiftCompiler(createCompiler(), getOutputs(), compilerOutputFileNamingSchemeFactory);
    Compiler<SwiftCompileSpec> loggingCompiler = BuildOperationLoggingCompilerDecorator.wrap(baseCompiler);
    WorkResult result = loggingCompiler.execute(spec);
    setDidWork(result.getDidWork());
}
Also used : BuildOperationLoggerFactory(org.gradle.internal.operations.logging.BuildOperationLoggerFactory) BuildOperationLogger(org.gradle.internal.operations.logging.BuildOperationLogger) InputFileDetails(org.gradle.api.tasks.incremental.InputFileDetails) DefaultSwiftCompileSpec(org.gradle.language.swift.tasks.internal.DefaultSwiftCompileSpec) SwiftCompileSpec(org.gradle.nativeplatform.toolchain.internal.compilespec.SwiftCompileSpec) IncrementalSwiftCompiler(org.gradle.nativeplatform.toolchain.internal.swift.IncrementalSwiftCompiler) NativePlatformInternal(org.gradle.nativeplatform.platform.internal.NativePlatformInternal) WorkResult(org.gradle.api.tasks.WorkResult) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File) 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