本文整理汇总了Java中org.gradle.api.tasks.SourceSetContainer类的典型用法代码示例。如果您正苦于以下问题:Java SourceSetContainer类的具体用法?Java SourceSetContainer怎么用?Java SourceSetContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SourceSetContainer类属于org.gradle.api.tasks包,在下文中一共展示了SourceSetContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureExtensionRule
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
private void configureExtensionRule() {
final ConventionMapping extensionMapping = conventionMappingOf(extension);
extensionMapping.map("sourceSets", Callables.returning(new ArrayList()));
extensionMapping.map("reportsDir", new Callable<File>() {
@Override
public File call() {
return project.getExtensions().getByType(ReportingExtension.class).file(getReportName());
}
});
withBasePlugin(new Action<Plugin>() {
@Override
public void execute(Plugin plugin) {
extensionMapping.map("sourceSets", new Callable<SourceSetContainer>() {
@Override
public SourceSetContainer call() {
return getJavaPluginConvention().getSourceSets();
}
});
}
});
}
示例2: configureCompileTestJavaTask
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
private void configureCompileTestJavaTask(final Project project) {
final JavaCompile compileTestJava = (JavaCompile) project.getTasks()
.findByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
compileTestJava.getInputs().property("moduleName", module.geName());
compileTestJava.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
List<String> args = new ArrayList<>();
args.add("--module-path");
args.add(compileTestJava.getClasspath().getAsPath());
args.add("--add-modules");
args.add("junit");
args.add("--add-reads");
args.add(module.geName() + "=junit");
args.add("--patch-module");
args.add(module.geName() + "=" + test.getJava().getSourceDirectories().getAsPath());
compileTestJava.getOptions().setCompilerArgs(args);
compileTestJava.setClasspath(project.files());
}
});
}
示例3: configureTestTask
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
private void configureTestTask(final Project project) {
final Test testTask = (Test) project.getTasks().findByName(JavaPlugin.TEST_TASK_NAME);
final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
testTask.getInputs().property("moduleName", module.geName());
testTask.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
List<String> args = new ArrayList<>();
args.add("--module-path");
args.add(testTask.getClasspath().getAsPath());
args.add("--add-modules");
args.add("ALL-MODULE-PATH");
args.add("--add-reads");
args.add(module.geName() + "=junit");
args.add("--patch-module");
args.add(module.geName() + "=" + test.getJava().getOutputDir());
testTask.setJvmArgs(args);
testTask.setClasspath(project.files());
}
});
}
示例4: apply
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
@Override
public void apply(Project project) {
ParsecPluginExtension pluginExtension = project.getExtensions().create("parsec", ParsecPluginExtension.class);
PathUtils pathUtils = new PathUtils(project, pluginExtension);
TaskContainer tasks = project.getTasks();
// Create tasks (when applied as a plugin)
ParsecInitTask initTask = tasks.create("parsec-init", ParsecInitTask.class);
ParsecGenerateTask generateTask = tasks.create("parsec-generate", ParsecGenerateTask.class);
// Make generate trigger init.
generateTask.dependsOn(initTask);
project.getPlugins().withType(JavaPlugin.class, plugin -> {
SourceSet sourceSet = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("main");
// Add ${buildDir}/generated-sources/java to sources
sourceSet.getJava().srcDir(pathUtils.getGeneratedSourcesPath());
// Add ${buildDir}/generated-resources/parsec to resources
sourceSet.getResources().srcDir(pathUtils.getGeneratedResourcesPath());
// Make compileJava trigger generate
tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).dependsOn(generateTask);
});
}
示例5: apply
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
@Override
public void apply(final Project project) {
Logger logger = project.getLogger();
logger.info("applying jsweet plugin");
if (!project.getPlugins().hasPlugin(JavaPlugin.class) && !project.getPlugins().hasPlugin(WarPlugin.class)) {
logger.error("No java or war plugin detected. Enable java or war plugin.");
throw new IllegalStateException("No java or war plugin detected. Enable java or war plugin.");
}
JSweetPluginExtension extension = project.getExtensions().create("jsweet", JSweetPluginExtension.class);
JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSetContainer sourceSets = javaPluginConvention.getSourceSets();
SourceSet mainSources = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
JSweetTranspileTask task = project.getTasks().create("jsweet", JSweetTranspileTask.class);
task.setGroup("generate");
task.dependsOn(JavaPlugin.COMPILE_JAVA_TASK_NAME);
task.setConfiguration(extension);
task.setSources(mainSources.getAllJava());
task.setClasspath(mainSources.getCompileClasspath());
JSweetCleanTask cleanTask = project.getTasks().create("jsweetClean", JSweetCleanTask.class);
cleanTask.setConfiguration(extension);
}
示例6: establishSonarQubeSourceSet
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
public void establishSonarQubeSourceSet()
{
final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
final SourceSetContainer sourceSets = javaConvention.getSourceSets();
final ConfigurationContainer configs = project.getConfigurations();
final SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
final SourceSet sqSourceSet = sourceSets.create(BuildUtil.SONARQUBE_SOURCE_SET_NAME);
configs.getByName(testSourceSet.getImplementationConfigurationName()).extendsFrom(
configs.getByName(sqSourceSet.getImplementationConfigurationName()));
configs.getByName(testSourceSet.getRuntimeOnlyConfigurationName()).extendsFrom(
configs.getByName(sqSourceSet.getRuntimeOnlyConfigurationName()));
final TaskContainer tasks = project.getTasks();
tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).dependsOn(
tasks.getByName(sqSourceSet.getClassesTaskName()));
final FileCollection sqOutputs = sqSourceSet.getOutput().getClassesDirs().plus(
project.files(sqSourceSet.getOutput().getResourcesDir()));
testSourceSet.setCompileClasspath(testSourceSet.getCompileClasspath().plus(sqOutputs));
testSourceSet.setRuntimeClasspath(testSourceSet.getRuntimeClasspath().plus(sqOutputs));
}
示例7: configureForSourceSets
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
private void configureForSourceSets(SourceSetContainer sourceSets) {
sourceSets.all(new Action<SourceSet>() {
@Override
public void execute(SourceSet sourceSet) {
Task task = project.getTasks().create(sourceSet.getTaskName(getTaskBaseName(), null), getCastedTaskType());
configureForSourceSet(sourceSet, (T)task);
}
});
}
示例8: getProjectLibraries
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
public Set<File> getProjectLibraries() {
Set<File> classpath = new HashSet<>();
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
if (sourceSets != null) {
SortedSet<String> availableSourceSetNames = sourceSets.getNames();
for (String sourceSetName : Arrays.asList("main", "test", "integrationTest")) {
if (availableSourceSetNames.contains(sourceSetName)) {
SourceSet sourceSet = sourceSets.getByName(sourceSetName);
classpath.add(sourceSet.getOutput().getClassesDir());
}
}
}
// add dependencies from configured gradle configuration to url (usually test or integrationTest)
TSGeneratorConfig generatorConfiguration = project.getExtensions().getByType(TSGeneratorConfig.class);
String configurationName = generatorConfiguration.getRuntime().getConfiguration();
ConfigurationContainer configurations = project.getConfigurations();
Configuration runtimeConfiguration = configurations.findByName(configurationName + "Runtime");
if (runtimeConfiguration == null) {
runtimeConfiguration = configurations.getByName(configurationName);
}
classpath.addAll(runtimeConfiguration.getFiles());
for (File file : classpath) {
LOGGER.debug("classpath entry: {}", file);
}
return classpath;
}
示例9: apply
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
@Override
public void apply(Project project) {
GeneratePluginExtension generatePluginExtension = project.getExtensions().create(EXTENSION_NAME,
GeneratePluginExtension.class, project);
GenerateTask generateTask = project.getTasks().create(TASK_NAME, GenerateTask.class);
generateTask.setGroup(BasePlugin.BUILD_GROUP);
generateTask.setDescription("Generates DDL scripts based on JPA model.");
generateTask.setExtension(generatePluginExtension);
generateTask.dependsOn(JavaBasePlugin.BUILD_TASK_NAME);
project.afterEvaluate(evaluatedProject -> {
fillDefaults(evaluatedProject, generatePluginExtension);
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
Set<File> paths;
if (sourceSets != null) {
UnionFileCollection mainClasspath = (UnionFileCollection) sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
paths = mainClasspath.getSources()
.stream()
.filter(fileCollection -> fileCollection instanceof DefaultSourceSetOutput)
.map(DefaultSourceSetOutput.class::cast)
.flatMap(fileCollection -> fileCollection.getClassesDirs().getFiles().stream())
.collect(Collectors.toSet());
} else {
paths = new HashSet<>();
}
generateTask.setOutputClassesDirs(paths);
});
}
示例10: modernizer
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
@TaskAction
public void modernizer() throws Exception {
final ModernizerPluginExtension extension = getExtension();
if (extension.getJavaVersion() == null || extension.getJavaVersion().trim().isEmpty()) {
extension.setJavaVersion(getJavaVersion());
}
final SourceSetContainer sourceSets = (SourceSetContainer) getProject().getProperties().get("sourceSets");
executeForSourceSet(extension, sourceSets.getByName("main"));
if(extension.isIncludeTestClasses()) {
executeForSourceSet(extension, sourceSets.getByName("test"));
}
}
示例11: getSrcDirs
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
@Override
public List<String> getSrcDirs() {
SourceSetContainer sourceSets = javaConvention.getSourceSets();
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
return mainSourceSet.getAllSource().getSrcDirs().stream().map(f -> {
try {
return f.getCanonicalPath();
} catch (IOException e) {
return "";
}
}).collect(Collectors.toList());
}
示例12: getSrcDirs
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
@Override
public List<String> getSrcDirs() {
SourceSetContainer sourceSets = javaConvention.getSourceSets();
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
return mainSourceSet.getAllSource().getSrcDirs().stream().map(f -> {
try {
return f.getCanonicalPath();
} catch (IOException e) {
return "";
}
}).collect(Collectors.toList());
}
示例13: apply
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
@Override
public void apply(final Project project) {
project.getPlugins().apply(JavaPlugin.class);
// final JNAeratorPluginExtension extension = project.getExtensions().create(JNAeratorPluginExtension.NAME, JNAeratorPluginExtension.class);
// extension.setOutputDir(new File(project.getBuildDir(), "generated-sources/jnaerator"));
JNAeratorTask task = project.getTasks().create("jnaerator", JNAeratorTask.class);
task.setOutputDir(new File(project.getBuildDir(), "generated-sources/jnaerator"));
project.getTasks().getByName("compileJava").dependsOn(task);
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
final SourceSet mainSourceSet = sourceSets.getByName("main");
mainSourceSet.getJava().srcDir(task.getOutputDir());
}
示例14: getSourceSet
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
public SourceSet getSourceSet(SourceType sourceType) {
JavaPluginConvention javaPluginConvention;
try {
javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
} catch (IllegalStateException e) {
throw new RuntimeException("Gradle project apparently isn't a Java project--it doesn't use the Java plugin");
}
SourceSetContainer sourceSets = javaPluginConvention.getSourceSets();
return sourceSets.getByName(getSourceSetName(sourceType));
}
示例15: establishGeneralCompileOnlyCfg
import org.gradle.api.tasks.SourceSetContainer; //导入依赖的package包/类
public void establishGeneralCompileOnlyCfg()
{
final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
final SourceSetContainer sourceSets = javaConvention.getSourceSets();
final ConfigurationContainer configs = project.getConfigurations();
final Configuration generalCompileOnly = configs.create(GENERAL_COMPILE_ONLY_CONFIG_NAME);
Arrays.asList(SourceSet.MAIN_SOURCE_SET_NAME, BuildUtil.SONARQUBE_SOURCE_SET_NAME,
SourceSet.TEST_SOURCE_SET_NAME).forEach((@Nonnull final String pSourceSetName) -> {
final SourceSet sourceSet = sourceSets.getByName(pSourceSetName);
configs.getByName(sourceSet.getCompileOnlyConfigurationName()).extendsFrom(generalCompileOnly);
});
}