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);
}
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());
}
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);
}
}
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);
}
}
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());
}
Aggregations