use of org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseJavaSourceSettings 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