use of org.gradle.plugins.ide.idea.GenerateIdeaModule in project gradle-apt-plugin by tbroyer.
the class AptIdeaPlugin method configureIdeaModule.
private void configureIdeaModule(Project project, final SourceSet mainSourceSet, final SourceSet testSourceSet) {
final IdeaModule ideaModule = project.getExtensions().getByType(IdeaModel.class).getModule();
final ModuleApt apt = new ModuleApt();
new DslObject(ideaModule).getConvention().getPlugins().put("net.ltgt.apt-idea", new ModuleAptConvention(apt));
project.afterEvaluate(new Action<Project>() {
@Override
public void execute(Project project) {
if (apt.isAddGeneratedSourcesDirs()) {
Set<File> excl = new LinkedHashSet<>();
for (SourceSet sourceSet : new SourceSet[] { mainSourceSet, testSourceSet }) {
File generatedSourcesDir = new DslObject(sourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
for (File f = generatedSourcesDir; f != null && !f.equals(project.getProjectDir()); f = f.getParentFile()) {
excl.add(f);
}
}
// For some reason, modifying the existing collections doesn't work.
// We need to copy the values and then assign it back.
Set<File> excludeDirs = new LinkedHashSet<>(ideaModule.getExcludeDirs());
if (excl.contains(project.getBuildDir()) && excludeDirs.contains(project.getBuildDir())) {
excludeDirs.remove(project.getBuildDir());
// Race condition: many of these will actually be created afterwards…
File[] subdirs = project.getBuildDir().listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
if (subdirs != null) {
excludeDirs.addAll(Arrays.asList(subdirs));
}
}
excludeDirs.removeAll(excl);
ideaModule.setExcludeDirs(excludeDirs);
File mainGeneratedSourcesDir = new DslObject(mainSourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
File testGeneratedSourcesDir = new DslObject(testSourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
// For some reason, modifying the existing collections doesn't work.
// We need to copy the values and then assign it back.
ideaModule.setSourceDirs(addToSet(ideaModule.getSourceDirs(), mainGeneratedSourcesDir));
ideaModule.setTestSourceDirs(addToSet(ideaModule.getTestSourceDirs(), testGeneratedSourcesDir));
ideaModule.setGeneratedSourceDirs(addToSet(ideaModule.getGeneratedSourceDirs(), mainGeneratedSourcesDir, testGeneratedSourcesDir));
}
if (apt.isAddCompileOnlyDependencies() || apt.isAddAptDependencies()) {
final AptPlugin.AptSourceSetConvention mainSourceSetConvention = new DslObject(mainSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class);
final AptPlugin.AptSourceSetConvention testSourceSetConvention = new DslObject(testSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class);
final List<Configuration> mainConfigurations = new ArrayList<>();
final List<Configuration> testConfigurations = new ArrayList<>();
if (apt.isAddCompileOnlyDependencies()) {
mainConfigurations.add(project.getConfigurations().getByName(mainSourceSetConvention.getCompileOnlyConfigurationName()));
testConfigurations.add(project.getConfigurations().getByName(testSourceSetConvention.getCompileOnlyConfigurationName()));
}
if (apt.isAddAptDependencies()) {
mainConfigurations.add(project.getConfigurations().getByName(mainSourceSetConvention.getAnnotationProcessorConfigurationName()));
testConfigurations.add(project.getConfigurations().getByName(testSourceSetConvention.getAnnotationProcessorConfigurationName()));
}
ideaModule.getScopes().get(apt.getMainDependenciesScope()).get("plus").addAll(mainConfigurations);
ideaModule.getScopes().get("TEST").get("plus").addAll(testConfigurations);
project.getTasks().withType(GenerateIdeaModule.class, new Action<GenerateIdeaModule>() {
@Override
public void execute(GenerateIdeaModule generateIdeaModule) {
generateIdeaModule.dependsOn(mainConfigurations.toArray());
generateIdeaModule.dependsOn(testConfigurations.toArray());
}
});
}
}
private Set<File> addToSet(Set<File> sourceDirs, File... dirs) {
Set<File> newSet = new LinkedHashSet<>(sourceDirs);
newSet.addAll(Arrays.asList(dirs));
return newSet;
}
});
}
use of org.gradle.plugins.ide.idea.GenerateIdeaModule in project gradle by gradle.
the class PlayIdeaPlugin method configureIdeaModule.
@Mutate
public void configureIdeaModule(@Path("tasks.ideaModule") GenerateIdeaModule ideaModule, @Path("binaries.playBinary") final PlayApplicationBinarySpec playApplicationBinarySpec, @Path("buildDir") final File buildDir, ConfigurationContainer configurations, final FileResolver fileResolver) {
IdeaModule module = ideaModule.getModule();
module.setScopes(buildScopes(configurations));
ConventionMapping conventionMapping = conventionMappingFor(module);
conventionMapping.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
// TODO: Assets should probably be a source set too
Set<File> sourceDirs = Sets.newHashSet(playApplicationBinarySpec.getAssets().getAssetDirs());
return CollectionUtils.inject(sourceDirs, playApplicationBinarySpec.getInputs(), new Action<CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet>>() {
@Override
public void execute(CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet> step) {
step.getTarget().addAll(step.getItem().getSource().getSrcDirs());
}
});
}
});
conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
// TODO: This should be modeled as a source set
return Collections.singleton(fileResolver.resolve("test"));
}
});
conventionMapping.map("singleEntryLibraries", new Callable<Map<String, Iterable<File>>>() {
@Override
public Map<String, Iterable<File>> call() throws Exception {
return ImmutableMap.<String, Iterable<File>>builder().put("COMPILE", Collections.singleton(playApplicationBinarySpec.getClasses().getClassesDir())).put("RUNTIME", playApplicationBinarySpec.getClasses().getResourceDirs()).put("TEST", Collections.singleton(new File(buildDir, "playBinary/testClasses"))).build();
}
});
module.setScalaPlatform(playApplicationBinarySpec.getTargetPlatform().getScalaPlatform());
conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() throws Exception {
return getTargetJavaVersion(playApplicationBinarySpec);
}
});
conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() throws Exception {
return new IdeaLanguageLevel(getTargetJavaVersion(playApplicationBinarySpec));
}
});
ideaModule.dependsOn(playApplicationBinarySpec.getInputs());
ideaModule.dependsOn(playApplicationBinarySpec.getAssets());
}
Aggregations