use of org.gradle.api.file.FileCollection in project gradle by gradle.
the class JavaGradlePluginPlugin method createAndConfigurePluginUnderTestMetadataTask.
private PluginUnderTestMetadata createAndConfigurePluginUnderTestMetadataTask(final Project project, final GradlePluginDevelopmentExtension extension) {
final PluginUnderTestMetadata pluginUnderTestMetadataTask = project.getTasks().create(PLUGIN_UNDER_TEST_METADATA_TASK_NAME, PluginUnderTestMetadata.class);
final Configuration gradlePluginConfiguration = project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi());
ConventionMapping conventionMapping = new DslObject(pluginUnderTestMetadataTask).getConventionMapping();
conventionMapping.map("pluginClasspath", new Callable<Object>() {
public Object call() throws Exception {
FileCollection gradleApi = gradlePluginConfiguration.getIncoming().getFiles();
return extension.getPluginSourceSet().getRuntimeClasspath().minus(gradleApi);
}
});
conventionMapping.map("outputDirectory", new Callable<Object>() {
public Object call() throws Exception {
return new File(project.getBuildDir(), pluginUnderTestMetadataTask.getName());
}
});
return pluginUnderTestMetadataTask;
}
use of org.gradle.api.file.FileCollection in project gradle by gradle.
the class WarPlugin method apply.
public void apply(final Project project) {
project.getPluginManager().apply(JavaPlugin.class);
final WarPluginConvention pluginConvention = new WarPluginConvention(project);
project.getConvention().getPlugins().put("war", pluginConvention);
project.getTasks().withType(War.class, new Action<War>() {
public void execute(War task) {
task.from(new Callable() {
public Object call() throws Exception {
return pluginConvention.getWebAppDir();
}
});
task.dependsOn(new Callable() {
public Object call() throws Exception {
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
}
});
task.classpath(new Object[] { new Callable() {
public Object call() throws Exception {
FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
Configuration providedRuntime = project.getConfigurations().getByName(PROVIDED_RUNTIME_CONFIGURATION_NAME);
return runtimeClasspath.minus(providedRuntime);
}
} });
}
});
War war = project.getTasks().create(WAR_TASK_NAME, War.class);
war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
war.setGroup(BasePlugin.BUILD_GROUP);
ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war);
project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
configureConfigurations(project.getConfigurations());
configureComponent(project, warArtifact);
}
use of org.gradle.api.file.FileCollection in project gradle by gradle.
the class DefaultTaskInputs method prepareValue.
private Object prepareValue(Object value) {
while (true) {
if (value instanceof Callable) {
Callable callable = (Callable) value;
value = uncheckedCall(callable);
} else if (value instanceof FileCollection) {
FileCollection fileCollection = (FileCollection) value;
return fileCollection.getFiles();
} else {
return avoidGString(value);
}
}
}
use of org.gradle.api.file.FileCollection in project webpieces by deanhiller.
the class TemplateCompilerTask method compileImpl.
public void compileImpl(TemplateCompileOptions options) throws IOException {
File buildDir = getProject().getBuildDir();
//need to make customizable...
File groovySrcGen = new File(buildDir, "groovysrc");
System.out.println("groovy src directory=" + groovySrcGen);
Charset encoding = Charset.forName(options.getEncoding());
TemplateCompileConfig config = new TemplateCompileConfig(false);
config.setFileEncoding(encoding);
config.setPluginClient(true);
config.setGroovySrcWriteDirectory(groovySrcGen);
System.out.println("custom tags=" + options.getCustomTags());
config.setCustomTagsFromPlugin(options.getCustomTags());
LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
File destinationDir = getDestinationDir();
System.out.println("destDir=" + destinationDir);
File routeIdFile = new File(destinationDir, ProdTemplateModule.ROUTE_META_FILE);
if (routeIdFile.exists())
routeIdFile.delete();
routeIdFile.createNewFile();
System.out.println("routeId.txt file=" + routeIdFile.getAbsolutePath());
FileCollection srcCollection = getSource();
Set<File> files = srcCollection.getFiles();
File firstFile = files.iterator().next();
File baseDir = findBase(firstFile);
try (FileOutputStream routeOut = new FileOutputStream(routeIdFile);
OutputStreamWriter write = new OutputStreamWriter(routeOut, encoding.name());
BufferedWriter bufWrite = new BufferedWriter(write)) {
Injector injector = Guice.createInjector(new StubModule(), new DevTemplateModule(config, new PluginCompileCallback(destinationDir, bufWrite)));
HtmlToJavaClassCompiler compiler = injector.getInstance(HtmlToJavaClassCompiler.class);
GroovyClassLoader cl = new GroovyClassLoader();
for (File f : files) {
System.out.println("file=" + f);
String fullName = findFullName(baseDir, f);
System.out.println("name=" + fullName);
String source = readSource(f);
compiler.compile(cl, fullName, source);
}
}
setDidWork(true);
}
use of org.gradle.api.file.FileCollection in project gradle by gradle.
the class SkipEmptySourceFilesTaskExecuter method execute.
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
FileCollection sourceFiles = task.getInputs().getSourceFiles();
if (task.getInputs().getHasSourceFiles() && sourceFiles.isEmpty()) {
TaskArtifactState taskArtifactState = context.getTaskArtifactState();
FileCollection outputFiles = taskArtifactState.getExecutionHistory().getOutputFiles();
if (outputFiles == null) {
state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
LOGGER.info("Skipping {} as it has no source files and no history of previous output files.", task);
} else if (outputFiles.isEmpty()) {
state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
LOGGER.info("Skipping {} as it has no source files and no previous output files.", task);
} else {
Set<File> outputFileSet = outputFiles.getFiles();
boolean deletedFiles = false;
boolean debugEnabled = LOGGER.isDebugEnabled();
for (File file : outputFileSet) {
if (file.isFile()) {
if (file.delete()) {
if (debugEnabled) {
LOGGER.debug("Deleted stale output file '{}'.", file.getAbsolutePath());
}
} else {
state.setOutcome(new GradleException(String.format("Could not delete file: '%s'.", file.getAbsolutePath())));
return;
}
deletedFiles = true;
}
}
if (deletedFiles) {
LOGGER.info("Cleaned previous output of {} as it has no source files.", task);
state.setOutcome(TaskExecutionOutcome.EXECUTED);
} else {
state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
}
}
taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, sourceFiles));
return;
} else {
taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, task.getInputs().getFiles()));
}
executer.execute(task, state, context);
}
Aggregations