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