use of org.gradle.plugins.ide.idea.model.IdeaProject in project gradle by gradle.
the class IdeaModelBuilder method appendModule.
private void appendModule(Map<String, DefaultIdeaModule> modules, IdeaModule ideaModule, DefaultIdeaProject ideaProject, DefaultGradleProject rootGradleProject) {
DefaultIdeaContentRoot contentRoot = new DefaultIdeaContentRoot().setRootDirectory(ideaModule.getContentRoot()).setSourceDirectories(srcDirs(ideaModule.getSourceDirs(), ideaModule.getGeneratedSourceDirs())).setTestDirectories(srcDirs(ideaModule.getTestSourceDirs(), ideaModule.getGeneratedSourceDirs())).setExcludeDirectories(ideaModule.getExcludeDirs());
Project project = ideaModule.getProject();
DefaultIdeaModule defaultIdeaModule = new DefaultIdeaModule().setName(ideaModule.getName()).setParent(ideaProject).setGradleProject(rootGradleProject.findByPath(ideaModule.getProject().getPath())).setContentRoots(Collections.singletonList(contentRoot)).setJdkName(ideaModule.getJdkName()).setCompilerOutput(new DefaultIdeaCompilerOutput().setInheritOutputDirs(ideaModule.getInheritOutputDirs() != null ? ideaModule.getInheritOutputDirs() : false).setOutputDir(ideaModule.getOutputDir()).setTestOutputDir(ideaModule.getTestOutputDir()));
JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
if (javaPluginConvention != null) {
final IdeaLanguageLevel ideaModuleLanguageLevel = ideaModule.getLanguageLevel();
JavaVersion moduleSourceLanguageLevel = convertIdeaLanguageLevelToJavaVersion(ideaModuleLanguageLevel);
JavaVersion moduleTargetBytecodeVersion = ideaModule.getTargetBytecodeVersion();
defaultIdeaModule.setJavaLanguageSettings(new DefaultIdeaJavaLanguageSettings().setSourceLanguageLevel(moduleSourceLanguageLevel).setTargetBytecodeVersion(moduleTargetBytecodeVersion));
}
modules.put(ideaModule.getName(), defaultIdeaModule);
}
use of org.gradle.plugins.ide.idea.model.IdeaProject in project gradle-apt-plugin by tbroyer.
the class AptIdeaPlugin method configureIdeaProject.
private void configureIdeaProject(final Project project) {
if (project.getParent() == null) {
final IdeaProject ideaProject = project.getExtensions().getByType(IdeaModel.class).getProject();
final ProjectAptConvention apt = new ProjectAptConvention();
new DslObject(ideaProject).getConvention().getPlugins().put("net.ltgt.apt-idea", apt);
ideaProject.getIpr().withXml(// withXml(Action) overload was added in Gradle 2.14
new MethodClosure(new Action<XmlProvider>() {
@Override
public void execute(XmlProvider xmlProvider) {
if (!apt.isConfigureAnnotationProcessing()) {
return;
}
for (Object it : (NodeList) xmlProvider.asNode().get("component")) {
Node compilerConfiguration = (Node) it;
if (!Objects.equals(compilerConfiguration.attribute("name"), "CompilerConfiguration")) {
continue;
}
for (Object n : (NodeList) compilerConfiguration.get("annotationProcessing")) {
compilerConfiguration.remove((Node) n);
}
Node annotationProcessing = compilerConfiguration.appendNode("annotationProcessing");
Map<String, Object> profileAttributes = new LinkedHashMap<>();
profileAttributes.put("name", "Default");
profileAttributes.put("enabled", true);
profileAttributes.put("default", true);
Node profile = annotationProcessing.appendNode("profile", profileAttributes);
// XXX: this assumes that all subprojects use the same name for their
// buildDir
profile.appendNode("sourceOutputDir", Collections.singletonMap("name", project.relativePath(project.getBuildDir()) + "/generated/source/apt/" + SourceSet.MAIN_SOURCE_SET_NAME));
profile.appendNode("sourceTestOutputDir", Collections.singletonMap("name", project.relativePath(project.getBuildDir()) + "/generated/source/apt/" + SourceSet.TEST_SOURCE_SET_NAME));
profile.appendNode("outputRelativeToContentRoot", Collections.singletonMap("value", true));
profile.appendNode("processorPath", Collections.singletonMap("useClasspath", true));
}
}
}, "execute"));
}
}
use of org.gradle.plugins.ide.idea.model.IdeaProject in project gradle by gradle.
the class IdeaModelBuilder method createModule.
private DefaultIdeaModule createModule(IdeaModule ideaModule, DefaultIdeaProject ideaProject, DefaultGradleProject rootGradleProject) {
DefaultIdeaContentRoot contentRoot = new DefaultIdeaContentRoot().setRootDirectory(ideaModule.getContentRoot()).setSourceDirectories(srcDirs(ideaModule.getSourceDirs(), ideaModule.getGeneratedSourceDirs())).setTestDirectories(srcDirs(ideaModule.getTestSources().getFiles(), ideaModule.getGeneratedSourceDirs())).setResourceDirectories(srcDirs(ideaModule.getResourceDirs(), ideaModule.getGeneratedSourceDirs())).setTestResourceDirectories(srcDirs(ideaModule.getTestResources().getFiles(), ideaModule.getGeneratedSourceDirs())).setExcludeDirectories(ideaModule.getExcludeDirs());
Project project = ideaModule.getProject();
DefaultIdeaModule defaultIdeaModule = new DefaultIdeaModule().setName(ideaModule.getName()).setParent(ideaProject).setGradleProject(rootGradleProject.findByPath(ideaModule.getProject().getPath())).setContentRoots(Collections.singletonList(contentRoot)).setJdkName(ideaModule.getJdkName()).setCompilerOutput(new DefaultIdeaCompilerOutput().setInheritOutputDirs(ideaModule.getInheritOutputDirs() != null ? ideaModule.getInheritOutputDirs() : false).setOutputDir(ideaModule.getOutputDir()).setTestOutputDir(ideaModule.getTestOutputDir()));
JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
if (javaPluginExtension != null) {
final IdeaLanguageLevel ideaModuleLanguageLevel = ideaModule.getLanguageLevel();
JavaVersion moduleSourceLanguageLevel = convertIdeaLanguageLevelToJavaVersion(ideaModuleLanguageLevel);
JavaVersion moduleTargetBytecodeVersion = ideaModule.getTargetBytecodeVersion();
defaultIdeaModule.setJavaLanguageSettings(new DefaultIdeaJavaLanguageSettings().setSourceLanguageLevel(moduleSourceLanguageLevel).setTargetBytecodeVersion(moduleTargetBytecodeVersion));
}
buildDependencies(defaultIdeaModule, ideaModule);
return defaultIdeaModule;
}
use of org.gradle.plugins.ide.idea.model.IdeaProject in project gradle by gradle.
the class IdeaModelBuilder method build.
private DefaultIdeaProject build(Project project, DefaultGradleProject rootGradleProject) {
IdeaModel ideaModel = ideaPluginFor(project).getModel();
IdeaProject projectModel = ideaModel.getProject();
JavaVersion projectSourceLanguageLevel = convertIdeaLanguageLevelToJavaVersion(projectModel.getLanguageLevel());
JavaVersion projectTargetBytecodeLevel = projectModel.getTargetBytecodeVersion();
DefaultIdeaProject out = new DefaultIdeaProject().setName(projectModel.getName()).setJdkName(projectModel.getJdkName()).setLanguageLevel(new DefaultIdeaLanguageLevel(projectModel.getLanguageLevel().getLevel())).setJavaLanguageSettings(new DefaultIdeaJavaLanguageSettings().setSourceLanguageLevel(projectSourceLanguageLevel).setTargetBytecodeVersion(projectTargetBytecodeLevel).setJdk(DefaultInstalledJdk.current()));
List<DefaultIdeaModule> ideaModules = Lists.newArrayList();
for (IdeaModule module : projectModel.getModules()) {
ideaModules.add(createModule(module, out, rootGradleProject));
}
out.setChildren(new LinkedList<>(ideaModules));
return out;
}
use of org.gradle.plugins.ide.idea.model.IdeaProject in project gradle by gradle.
the class IdeaPlugin method configureIdeaProject.
private void configureIdeaProject(final Project project) {
if (isRoot()) {
XmlFileContentMerger ipr = new XmlFileContentMerger(new XmlTransformer());
final IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
final TaskProvider<GenerateIdeaProject> projectTask = project.getTasks().register(IDEA_PROJECT_TASK_NAME, GenerateIdeaProject.class, ideaProject);
projectTask.configure(new Action<GenerateIdeaProject>() {
@Override
public void execute(GenerateIdeaProject projectTask) {
projectTask.setDescription("Generates IDEA project file (IPR)");
}
});
ideaModel.setProject(ideaProject);
ideaProject.setOutputFile(new File(project.getProjectDir(), project.getName() + ".ipr"));
ConventionMapping conventionMapping = ((IConventionAware) ideaProject).getConventionMapping();
conventionMapping.map("jdkName", new Callable<String>() {
@Override
public String call() {
return JavaVersion.current().toString();
}
});
conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() {
JavaVersion maxSourceCompatibility = getMaxJavaModuleCompatibilityVersionFor(SOURCE_COMPATIBILITY);
return new IdeaLanguageLevel(maxSourceCompatibility);
}
});
conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
return getMaxJavaModuleCompatibilityVersionFor(TARGET_COMPATIBILITY);
}
});
ideaProject.getWildcards().addAll(Arrays.asList("!?*.class", "!?*.scala", "!?*.groovy", "!?*.java"));
conventionMapping.map("modules", new Callable<List<IdeaModule>>() {
@Override
public List<IdeaModule> call() {
return Lists.newArrayList(Iterables.transform(Sets.filter(project.getRootProject().getAllprojects(), new Predicate<Project>() {
@Override
public boolean apply(Project p) {
return p.getPlugins().hasPlugin(IdeaPlugin.class);
}
}), new Function<Project, IdeaModule>() {
@Override
public IdeaModule apply(Project p) {
return ideaModelFor(p).getModule();
}
}));
}
});
conventionMapping.map("pathFactory", new Callable<PathFactory>() {
@Override
public PathFactory call() {
return new PathFactory().addPathVariable("PROJECT_DIR", projectTask.get().getOutputFile().getParentFile());
}
});
addWorker(projectTask, IDEA_PROJECT_TASK_NAME);
addWorkspace(ideaProject);
}
}
Aggregations