use of org.gradle.plugins.ide.eclipse.model.BuildCommand in project gradle by gradle.
the class EclipsePlugin method configureEclipseProject.
private void configureEclipseProject(final Project project, final EclipseModel model) {
maybeAddTask(project, this, ECLIPSE_PROJECT_TASK_NAME, GenerateEclipseProject.class, new Action<GenerateEclipseProject>() {
@Override
public void execute(GenerateEclipseProject task) {
final EclipseProject projectModel = task.getProjectModel();
//task properties:
task.setDescription("Generates the Eclipse project file.");
task.setInputFile(project.file(".project"));
task.setOutputFile(project.file(".project"));
//model:
model.setProject(projectModel);
projectModel.setName(project.getName());
final ConventionMapping convention = ((IConventionAware) projectModel).getConventionMapping();
convention.map("comment", new Callable<String>() {
@Override
public String call() {
return project.getDescription();
}
});
project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {
@Override
public void execute(JavaBasePlugin javaBasePlugin) {
if (!project.getPlugins().hasPlugin(EarPlugin.class)) {
projectModel.buildCommand("org.eclipse.jdt.core.javabuilder");
}
projectModel.natures("org.eclipse.jdt.core.javanature");
convention.map("linkedResources", new Callable<Set<Link>>() {
@Override
public Set<Link> call() {
return new LinkedResourcesCreator().links(project);
}
});
}
});
project.getPlugins().withType(GroovyBasePlugin.class, new Action<GroovyBasePlugin>() {
@Override
public void execute(GroovyBasePlugin groovyBasePlugin) {
projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.eclipse.jdt.groovy.core.groovyNature");
}
});
project.getPlugins().withType(ScalaBasePlugin.class, new Action<ScalaBasePlugin>() {
@Override
public void execute(ScalaBasePlugin scalaBasePlugin) {
projectModel.getBuildCommands().set(Iterables.indexOf(projectModel.getBuildCommands(), new Predicate<BuildCommand>() {
@Override
public boolean apply(BuildCommand buildCommand) {
return buildCommand.getName().equals("org.eclipse.jdt.core.javabuilder");
}
}), new BuildCommand("org.scala-ide.sdt.core.scalabuilder"));
projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.scala-ide.sdt.core.scalanature");
}
});
}
});
}
use of org.gradle.plugins.ide.eclipse.model.BuildCommand in project gradle by gradle.
the class EclipseModelBuilder method populate.
private void populate(Project project) {
EclipseModel eclipseModel = project.getExtensions().getByType(EclipseModel.class);
EclipseClasspath eclipseClasspath = eclipseModel.getClasspath();
eclipseClasspath.setProjectDependenciesOnly(projectDependenciesOnly);
List<ClasspathEntry> classpathEntries;
if (eclipseClasspath.getFile() == null) {
classpathEntries = eclipseClasspath.resolveDependencies();
} else {
Classpath classpath = new Classpath(eclipseClasspath.getFileReferenceFactory());
eclipseClasspath.mergeXmlClasspath(classpath);
classpathEntries = classpath.getEntries();
}
final List<DefaultEclipseExternalDependency> externalDependencies = new LinkedList<DefaultEclipseExternalDependency>();
final List<DefaultEclipseProjectDependency> projectDependencies = new LinkedList<DefaultEclipseProjectDependency>();
final List<DefaultEclipseSourceDirectory> sourceDirectories = new LinkedList<DefaultEclipseSourceDirectory>();
final List<DefaultEclipseClasspathContainer> classpathContainers = new LinkedList<DefaultEclipseClasspathContainer>();
DefaultEclipseOutputLocation outputLocation = null;
for (ClasspathEntry entry : classpathEntries) {
//and it would probably push us to add support in the tooling api to retrieve the variable mappings.
if (entry instanceof Library) {
AbstractLibrary library = (AbstractLibrary) entry;
final File file = library.getLibrary().getFile();
final File source = library.getSourcePath() == null ? null : library.getSourcePath().getFile();
final File javadoc = library.getJavadocPath() == null ? null : library.getJavadocPath().getFile();
DefaultEclipseExternalDependency dependency = new DefaultEclipseExternalDependency(file, javadoc, source, library.getModuleVersion(), library.isExported(), createAttributes(library), createAccessRules(library));
externalDependencies.add(dependency);
} else if (entry instanceof ProjectDependency) {
final ProjectDependency projectDependency = (ProjectDependency) entry;
// By removing the leading "/", this is no longer a "path" as defined by Eclipse
final String path = StringUtils.removeStart(projectDependency.getPath(), "/");
DefaultEclipseProjectDependency dependency = new DefaultEclipseProjectDependency(path, projectDependency.isExported(), createAttributes(projectDependency), createAccessRules(projectDependency));
// Find the EclipseProject model, if it's in the same build. May be null for a composite.
dependency.setTargetProject(findEclipseProjectByName(path));
projectDependencies.add(dependency);
} else if (entry instanceof SourceFolder) {
final SourceFolder sourceFolder = (SourceFolder) entry;
String path = sourceFolder.getPath();
List<String> excludes = sourceFolder.getExcludes();
List<String> includes = sourceFolder.getIncludes();
String output = sourceFolder.getOutput();
sourceDirectories.add(new DefaultEclipseSourceDirectory(path, sourceFolder.getDir(), excludes, includes, output, createAttributes(sourceFolder), createAccessRules(sourceFolder)));
} else if (entry instanceof Container) {
final Container container = (Container) entry;
classpathContainers.add(new DefaultEclipseClasspathContainer(container.getPath(), container.isExported(), createAttributes(container), createAccessRules(container)));
} else if (entry instanceof Output) {
outputLocation = new DefaultEclipseOutputLocation(((Output) entry).getPath());
}
}
DefaultEclipseProject eclipseProject = findEclipseProject(project);
eclipseProject.setClasspath(externalDependencies);
eclipseProject.setProjectDependencies(projectDependencies);
eclipseProject.setSourceDirectories(sourceDirectories);
List<DefaultEclipseLinkedResource> linkedResources = new LinkedList<DefaultEclipseLinkedResource>();
for (Link r : eclipseModel.getProject().getLinkedResources()) {
linkedResources.add(new DefaultEclipseLinkedResource(r.getName(), r.getType(), r.getLocation(), r.getLocationUri()));
}
eclipseProject.setLinkedResources(linkedResources);
List<DefaultEclipseTask> tasks = new ArrayList<DefaultEclipseTask>();
for (Task t : tasksFactory.getTasks(project)) {
tasks.add(new DefaultEclipseTask(eclipseProject, t.getPath(), t.getName(), t.getDescription()));
}
eclipseProject.setTasks(tasks);
List<DefaultEclipseProjectNature> natures = new ArrayList<DefaultEclipseProjectNature>();
for (String n : eclipseModel.getProject().getNatures()) {
natures.add(new DefaultEclipseProjectNature(n));
}
eclipseProject.setProjectNatures(natures);
List<DefaultEclipseBuildCommand> buildCommands = new ArrayList<DefaultEclipseBuildCommand>();
for (BuildCommand b : eclipseModel.getProject().getBuildCommands()) {
Map<String, String> arguments = Maps.newLinkedHashMap();
for (Map.Entry<String, String> entry : b.getArguments().entrySet()) {
arguments.put(convertGString(entry.getKey()), convertGString(entry.getValue()));
}
buildCommands.add(new DefaultEclipseBuildCommand(b.getName(), arguments));
}
eclipseProject.setBuildCommands(buildCommands);
EclipseJdt jdt = eclipseModel.getJdt();
if (jdt != null) {
eclipseProject.setJavaSourceSettings(new DefaultEclipseJavaSourceSettings().setSourceLanguageLevel(jdt.getSourceCompatibility()).setTargetBytecodeVersion(jdt.getTargetCompatibility()).setJdk(DefaultInstalledJdk.current()));
}
eclipseProject.setClasspathContainers(classpathContainers);
eclipseProject.setOutputLocation(outputLocation != null ? outputLocation : new DefaultEclipseOutputLocation("bin"));
for (Project childProject : project.getChildProjects().values()) {
populate(childProject);
}
}
Aggregations