use of org.gradle.plugins.ide.idea.model.PathFactory in project gradle by gradle.
the class IdeaPlugin method configureIdeaModule.
private void configureIdeaModule(final Project project) {
final GenerateIdeaModule task = project.getTasks().create("ideaModule", GenerateIdeaModule.class);
task.setDescription("Generates IDEA module files (IML)");
IdeaModuleIml iml = new IdeaModuleIml(task.getXmlTransformer(), project.getProjectDir());
final IdeaModule module = instantiator.newInstance(IdeaModule.class, project, iml);
task.setModule(module);
ideaModel.setModule(module);
ConventionMapping conventionMapping = ((IConventionAware) module).getConventionMapping();
conventionMapping.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return Sets.newHashSet();
}
});
conventionMapping.map("name", new Callable<String>() {
@Override
public String call() throws Exception {
return project.getName();
}
});
conventionMapping.map("contentRoot", new Callable<File>() {
@Override
public File call() throws Exception {
return project.getProjectDir();
}
});
conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return Sets.newHashSet();
}
});
conventionMapping.map("excludeDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return Sets.newHashSet(project.getBuildDir(), project.file(".gradle"));
}
});
conventionMapping.map("pathFactory", new Callable<PathFactory>() {
@Override
public PathFactory call() throws Exception {
final PathFactory factory = new PathFactory();
factory.addPathVariable("MODULE_DIR", task.getOutputFile().getParentFile());
for (Map.Entry<String, File> entry : module.getPathVariables().entrySet()) {
factory.addPathVariable(entry.getKey(), entry.getValue());
}
return factory;
}
});
addWorker(task);
}
use of org.gradle.plugins.ide.idea.model.PathFactory in project gradle by gradle.
the class IdeaPlugin method configureIdeaModule.
private void configureIdeaModule(final ProjectInternal project) {
IdeaModuleIml iml = new IdeaModuleIml(new XmlTransformer(), project.getProjectDir());
final IdeaModule module = instantiator.newInstance(IdeaModule.class, project, iml);
final TaskProvider<GenerateIdeaModule> task = project.getTasks().register(IDEA_MODULE_TASK_NAME, GenerateIdeaModule.class, module);
task.configure(new Action<GenerateIdeaModule>() {
@Override
public void execute(GenerateIdeaModule task) {
task.setDescription("Generates IDEA module files (IML)");
}
});
ideaModel.setModule(module);
final String defaultModuleName = uniqueProjectNameProvider.getUniqueName(project);
module.setName(defaultModuleName);
ConventionMapping conventionMapping = ((IConventionAware) module).getConventionMapping();
Set<File> sourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
return sourceDirs;
}
});
conventionMapping.map("contentRoot", new Callable<File>() {
@Override
public File call() {
return project.getProjectDir();
}
});
Set<File> testSourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
return testSourceDirs;
}
});
Set<File> resourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("resourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return resourceDirs;
}
});
Set<File> testResourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("testResourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return testResourceDirs;
}
});
Set<File> excludeDirs = Sets.newLinkedHashSet();
conventionMapping.map("excludeDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
excludeDirs.add(project.file(".gradle"));
excludeDirs.add(project.getBuildDir());
return excludeDirs;
}
});
conventionMapping.map("pathFactory", new Callable<PathFactory>() {
@Override
public PathFactory call() {
final PathFactory factory = new PathFactory();
factory.addPathVariable("MODULE_DIR", task.get().getOutputFile().getParentFile());
for (Map.Entry<String, File> entry : module.getPathVariables().entrySet()) {
factory.addPathVariable(entry.getKey(), entry.getValue());
}
return factory;
}
});
artifactRegistry.registerIdeProject(new IdeaModuleMetadata(module, task));
addWorker(task, IDEA_MODULE_TASK_NAME);
}
use of org.gradle.plugins.ide.idea.model.PathFactory 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