use of org.gradle.plugins.ide.eclipse.model.ProjectDependency in project gradle by gradle.
the class EclipseModelBuilder method gatherClasspathElements.
public static ClasspathElements gatherClasspathElements(Map<String, Boolean> projectOpenStatus, EclipseClasspath eclipseClasspath, boolean projectDependenciesOnly) {
ClasspathElements classpathElements = new ClasspathElements();
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 Map<String, DefaultEclipseProjectDependency> projectDependencyMap = new HashMap<>();
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;
if (entry instanceof UnresolvedLibrary) {
UnresolvedLibrary unresolvedLibrary = (UnresolvedLibrary) entry;
dependency = DefaultEclipseExternalDependency.createUnresolved(file, javadoc, source, library.getModuleVersion(), library.isExported(), createAttributes(library), createAccessRules(library), unresolvedLibrary.getAttemptedSelector().getDisplayName());
} else {
dependency = DefaultEclipseExternalDependency.createResolved(file, javadoc, source, library.getModuleVersion(), library.isExported(), createAttributes(library), createAccessRules(library));
}
classpathElements.getExternalDependencies().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(), "/");
boolean isProjectOpen = projectOpenStatus.getOrDefault(path, true);
if (!isProjectOpen) {
final File source = projectDependency.getPublicationSourcePath() == null ? null : projectDependency.getPublicationSourcePath().getFile();
final File javadoc = projectDependency.getPublicationJavadocPath() == null ? null : projectDependency.getPublicationJavadocPath().getFile();
classpathElements.getExternalDependencies().add(DefaultEclipseExternalDependency.createResolved(projectDependency.getPublication().getFile(), javadoc, source, null, projectDependency.isExported(), createAttributes(projectDependency), createAccessRules(projectDependency)));
classpathElements.getBuildDependencies().add(projectDependency.getBuildDependencies());
} else {
projectDependencyMap.put(path, new DefaultEclipseProjectDependency(path, projectDependency.isExported(), createAttributes(projectDependency), createAccessRules(projectDependency)));
}
} 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();
classpathElements.getSourceDirectories().add(new DefaultEclipseSourceDirectory(path, sourceFolder.getDir(), excludes, includes, output, createAttributes(sourceFolder), createAccessRules(sourceFolder)));
} else if (entry instanceof Container) {
final Container container = (Container) entry;
classpathElements.getClasspathContainers().add(new DefaultEclipseClasspathContainer(container.getPath(), container.isExported(), createAttributes(container), createAccessRules(container)));
} else if (entry instanceof Output) {
classpathElements.setEclipseOutputLocation(new DefaultEclipseOutputLocation(((Output) entry).getPath()));
}
}
classpathElements.getProjectDependencies().addAll(projectDependencyMap.values());
return classpathElements;
}
use of org.gradle.plugins.ide.eclipse.model.ProjectDependency in project gradle by gradle.
the class ProjectDependencyBuilder method buildProjectDependency.
private ProjectDependency buildProjectDependency(String path) {
final ProjectDependency out = new ProjectDependency(path);
out.setExported(false);
return out;
}
use of org.gradle.plugins.ide.eclipse.model.ProjectDependency in project gradle by gradle.
the class ProjectDependencyBuilder method build.
public ProjectDependency build(ProjectComponentIdentifier componentIdentifier, FileReference publication, TaskDependency buildDependencies, boolean testDependency, boolean asJavaModule) {
ProjectDependency dependency = buildProjectDependency(determineTargetProjectPath(componentIdentifier));
dependency.setPublication(publication);
if (buildDependencies != null) {
dependency.buildDependencies(buildDependencies);
}
if (testDependency) {
dependency.getEntryAttributes().put(EclipsePluginConstants.TEST_SOURCES_ATTRIBUTE_KEY, EclipsePluginConstants.TEST_SOURCES_ATTRIBUTE_VALUE);
}
if (asJavaModule) {
dependency.getEntryAttributes().put(EclipsePluginConstants.MODULE_ATTRIBUTE_KEY, EclipsePluginConstants.MODULE_ATTRIBUTE_VALUE);
}
if (containsTestFixtures(componentIdentifier)) {
dependency.getEntryAttributes().put(EclipsePluginConstants.WITHOUT_TEST_CODE_ATTRIBUTE_KEY, "false");
} else {
dependency.getEntryAttributes().put(EclipsePluginConstants.WITHOUT_TEST_CODE_ATTRIBUTE_KEY, "true");
}
return dependency;
}
Aggregations