public ModuleVersionIdentifier resolve(ProjectDependency dependency) { Project dependencyProject = dependency.getDependencyProject(); ((ProjectInternal) dependencyProject).evaluate(); PublishingExtension publishing = dependencyProject.getExtensions().findByType(PublishingExtension.class); if (publishing == null || publishing.getPublications().withType(PublicationInternal.class).isEmpty()) { // Project does not apply publishing (or has no publications): simply use the project name in place of the dependency name return new DefaultModuleVersionIdentifier(dependency.getGroup(), dependencyProject.getName(), dependency.getVersion()); } // See if all publications have the same identifier Set<? extends PublicationInternal> publications = publishing.getPublications().withType(PublicationInternal.class); Iterator<? extends PublicationInternal> iterator = publications.iterator(); ModuleVersionIdentifier candidate = iterator.next().getCoordinates(); while (iterator.hasNext()) { ModuleVersionIdentifier alternative = iterator.next().getCoordinates(); if (!candidate.equals(alternative)) { throw new UnsupportedOperationException("Publishing is not yet able to resolve a dependency on a project with multiple different publications."); } } return candidate; }
private Set<GradleLibrary> getLibrariesForFileDependencies( Configuration configuration, LibraryScope scope) { Set<GradleLibrary> libraries = new LinkedHashSet<GradleLibrary>(); for (Dependency dependency : configuration.getIncoming().getDependencies()) { if (dependency instanceof FileCollectionDependency) { FileCollectionDependency fileDependency = (FileCollectionDependency) dependency; for (File file : fileDependency.resolve()) { libraries.add( new GradleLibrary(fileDependency.getGroup(), file, scope)); } } else if (dependency instanceof ProjectDependency) { ProjectDependency projectDependency = (ProjectDependency) dependency; libraries.addAll(getLibrariesForFileDependencies( projectDependency.getProjectConfiguration(), scope)); } } return libraries; }
private void ensureConfigured(Configuration config) { for (Dependency dependency : config.getAllDependencies()) { if (dependency instanceof ProjectDependency) { ProjectDependency projectDependency = (ProjectDependency) dependency; project.evaluationDependsOn(projectDependency.getDependencyProject().getPath()); try { ensureConfigured(projectDependency.getProjectConfiguration()); } catch (Throwable e) { throw new UnknownProjectException(String.format( "Cannot evaluate module %s : %s", projectDependency.getName(), e.getMessage()), e); } } } }
private Collection<File> listProjectDepsSrcDirs(Project project) { ConfigurationContainer configs = project.getConfigurations(); Configuration compileConf = configs.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME); DependencySet depSet = compileConf.getAllDependencies(); List<File> result = Lists.newArrayList(); for (Dependency dep : depSet) { if (dep instanceof ProjectDependency) { Project projectDependency = ((ProjectDependency) dep).getDependencyProject(); if (projectDependency.getPlugins().hasPlugin(PwtLibPlugin.class)) { JavaPluginConvention javaConvention = projectDependency.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); result.addAll(mainSourceSet.getAllSource().getSrcDirs()); } } } return result; }
@Override protected void applyOnce(Project project) { ProjectDepsExtension extension = project.getExtensions().create(ProjectDepsExtension.NAME, ProjectDepsExtension.class); EclipseProjectPlugin.modifyEclipseProject(project, eclipseModel -> { // find the project's referenced projects and reference them explicitly in the eclipse model Task prepareEclipse = project.task("prepareEclipse"); prepareEclipse.doLast(task -> { Set<String> referencedProjects = eclipseModel.getProject().getReferencedProjects(); project.getConfigurations().stream() .flatMap(config -> config.getDependencies().stream()) .filter(dep -> dep instanceof ProjectDependency) .forEach(dep -> { referencedProjects.add(dep.getName()); }); }); // it's needed for generating the eclipseClasspath and eclipseProject Iterables.getOnlyElement(project.getTasksByName("eclipseClasspath", false)).dependsOn(prepareEclipse); Iterables.getOnlyElement(project.getTasksByName("eclipseProject", false)).dependsOn(prepareEclipse); // create robust classpath entries for all referenced projects eclipseModel.getClasspath().getFile().getXmlTransformer().addAction(xmlProvider -> { modifyClasspath(xmlProvider.asNode(), eclipseModel, extension); }); }); }
public void from(SoftwareComponent component) { if (this.component != null) { throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name)); } this.component = (SoftwareComponentInternal) component; for (Usage usage : this.component.getUsages()) { // TODO Need a smarter way to map usage to artifact classifier for (PublishArtifact publishArtifact : usage.getArtifacts()) { artifact(publishArtifact); } // TODO Need a smarter way to map usage to scope for (ModuleDependency dependency : usage.getDependencies()) { if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency); } else { addModuleDependency(dependency); } } } }
/** * Helper to get project dependent, optionally recursively. */ private static Set<Project> getProjectTypeDependencies(final Project project, boolean recursive) { //System.out.println("--------getProjectDependencies--------"); Set<Project> result = new HashSet<Project>(); //Set<ProjectDependency> set = new HashSet<ProjectDependency>(); DomainObjectSet<ProjectDependency> directProjectTypeDependent = getDirectProjectTypeDependencies(project); //System.out.println("--directDependentProjects.size(): " + directDependentProjects.size()); for (ProjectDependency projectTypeDependency : directProjectTypeDependent) { Project dependentProject = projectTypeDependency.getDependencyProject(); //System.out.println("------project: " + dependentProject); if (dependentProject!=null) { result.add(dependentProject); if (recursive) { result.addAll(getProjectTypeDependencies(dependentProject, recursive)); } } } return result; }
private static boolean doesConfigurationDependOnProject(Configuration configuration, Project project) { Set<ProjectDependency> projectDependencies = configuration.getAllDependencies().withType(ProjectDependency.class); for (ProjectDependency projectDependency : projectDependencies) { if (projectDependency.getDependencyProject().equals(project)) { return true; } } return false; }
void resolveProjectDependencies(TaskDependencyResolveContext context, Set<ProjectDependency> projectDependencies) { for (ProjectDependency projectDependency : projectDependencies) { projectAccessListener.beforeResolvingProjectDependency((ProjectInternal) projectDependency.getDependencyProject()); Task nextTask = projectDependency.getDependencyProject().getTasks().findByName(taskName); if (nextTask != null) { context.add(nextTask); } } }
public void from(SoftwareComponent component) { if (this.component != null) { throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name)); } this.component = (SoftwareComponentInternal) component; configurations.maybeCreate("default"); for (Usage usage : this.component.getUsages()) { String conf = usage.getName(); configurations.maybeCreate(conf); configurations.getByName("default").extend(conf); for (PublishArtifact publishArtifact : usage.getArtifacts()) { artifact(publishArtifact).setConf(conf); } for (ModuleDependency dependency : usage.getDependencies()) { // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id. String confMapping = String.format("%s->%s", conf, dependency.getTargetConfiguration() == null ? Dependency.DEFAULT_CONFIGURATION : dependency.getTargetConfiguration()); if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency, confMapping); } else { addModuleDependency(dependency, confMapping); } } } }
/** * Finds all external dependencies. * * @param configuration Configuration * @return External dependencies */ private List<SelfResolvingDependency> findAllExternalDependencies(List<SelfResolvingDependency> externalDependencies, List<Dependency> visited, Configuration configuration) { for (Dependency dependency : configuration.getAllDependencies()) { if(!visited.contains(dependency)){ visited.add(dependency); if(dependency instanceof ProjectDependency) { findAllExternalDependencies(externalDependencies, visited, getTargetConfiguration((ProjectDependency) dependency)); } else if (dependency instanceof SelfResolvingDependency) { externalDependencies.add((SelfResolvingDependency) dependency); } } } return externalDependencies; }
private Configuration getTargetConfiguration(ProjectDependency dependency) { String targetConfiguration = dependency.getTargetConfiguration(); if (targetConfiguration == null) { targetConfiguration = Dependency.DEFAULT_CONFIGURATION; } return dependency.getDependencyProject().getConfigurations().getByName(targetConfiguration); }
public boolean contentEquals(Dependency dependency) { if (this == dependency) { return true; } if (dependency == null || getClass() != dependency.getClass()) { return false; } ProjectDependency that = (ProjectDependency) dependency; if (!isCommonContentEquals(that)) { return false; } return dependencyProject.equals(that.getDependencyProject()); }
private void ensureConfigured(Configuration config) { for (Dependency dependency : config.getAllDependencies()) { if (dependency instanceof ProjectDependency) { ProjectDependency projectDependency = (ProjectDependency)dependency; project.evaluationDependsOn(projectDependency.getDependencyProject().getPath()); } } }
private void configureOverlay(WarOverlay overlay) { if (overlay.isDeferProvidedConfiguration()) { //Delay this to trick IntelliJ overlay.getWarTask().doFirst(w -> overlay.getWarCopySpec().exclude(element -> overlay.isProvided())); } else { overlay.getWarCopySpec().exclude(element -> overlay.isProvided()); } Object source = overlay.getSource(); if (source instanceof AbstractArchiveTask) { configureOverlay(overlay, (AbstractArchiveTask) source); } else if (source instanceof Project && overlay.getConfigureClosure() == null) { configureOverlay(overlay, (Project) source); } else { Closure configClosure = overlay.getConfigureClosure(); Dependency dependency; if (configClosure == null) { dependency = project.getDependencies().create(source); } else { dependency = project.getDependencies().create(source, configClosure); } if (dependency instanceof ProjectDependency) { configureOverlay(overlay, ((ProjectDependency) dependency).getDependencyProject()); } else if (dependency instanceof ExternalDependency) { configureOverlay(overlay, (ExternalDependency) dependency); } else { throw new GradleException("Unsupported dependency type: " + dependency.getClass().getName()); } } }
void resolveProjectDependencies(TaskDependencyResolveContext context, Set<ProjectDependency> projectDependencies) { for (ProjectDependency projectDependency : projectDependencies) { //in configure-on-demand we don't know if the project was configured, hence explicit evaluate. // Not especially tidy, we should clean this up while working on new configuration model. ((ProjectInternal) projectDependency.getDependencyProject()).evaluate(); Task nextTask = projectDependency.getDependencyProject().getTasks().findByName(taskName); if (nextTask != null) { context.add(nextTask); } } }
public void from(SoftwareComponent component) { if (this.component != null) { throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name)); } this.component = (SoftwareComponentInternal) component; configurations.maybeCreate("default"); for (Usage usage : this.component.getUsages()) { String conf = usage.getName(); configurations.maybeCreate(conf); configurations.getByName("default").extend(conf); for (PublishArtifact publishArtifact : usage.getArtifacts()) { artifact(publishArtifact).setConf(conf); } for (ModuleDependency dependency : usage.getDependencies()) { // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id. String confMapping = String.format("%s->%s", conf, dependency.getConfiguration()); if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency, confMapping); } else { addModuleDependency(dependency, confMapping); } } } }
public ProjectDependencyArtifactIdExtractorHack(ProjectDependency dependency) { this.project = dependency.getDependencyProject(); }
@Override public boolean isSatisfiedBy(DependencyMetadata element) { return element instanceof DslOriginDependencyMetadata && ((DslOriginDependencyMetadata) element).getSource() instanceof ProjectDependency; }
public boolean canConvert(ModuleDependency dependency) { return dependency instanceof ProjectDependency; }
private Module getProjectModule(ModuleDependency dependency) { ProjectDependency projectDependency = (ProjectDependency) dependency; return ((ProjectInternal) projectDependency.getDependencyProject()).getModule(); }
@Override public void visitDependencies(TaskDependencyResolveContext context) { resolveProjectDependencies(context, dependencies.withType(ProjectDependency.class)); }
public ProjectDependency createProjectDependencyFromMap(ProjectFinder projectFinder, Map<? extends String, ? extends Object> map) { return projectDependencyFactory.createFromMap(projectFinder, map); }
public ProjectDependency create(ProjectInternal project, String configuration) { return instantiator.newInstance(DefaultProjectDependency.class, project, configuration, projectAccessListener, buildProjectDependencies); }
public ProjectDependency create(Project project) { return instantiator.newInstance(DefaultProjectDependency.class, project, projectAccessListener, buildProjectDependencies); }
public ProjectDependency createFromMap(ProjectFinder projectFinder, Map<? extends String, ?> map) { return NotationParserBuilder.toType(ProjectDependency.class) .converter(new ProjectDependencyMapNotationConverter(projectFinder, factory)).toComposite().parseNotation(map); }
protected ProjectDependency parseMap(@MapKey("path") String path, @Optional @MapKey("configuration") String configuration) { return factory.create(projectFinder.getProject(path), configuration); }
public void convert(Project notation, NotationConvertResult<? super ProjectDependency> result) throws TypeConversionException { result.converted(factory.create(notation)); }
@Override public Set<? extends RenderableDependency> getChildren() { final DependencySet dependencies = configuration.getDependencies(); if (dependencies.isEmpty()) { return Collections.emptySet(); } Set<RenderableDependency> children = Sets.newLinkedHashSet(); for (final Dependency dependency : dependencies) { children.add(new RenderableDependency() { @Override public Object getId() { return dependency; } @Override public String getName() { String label; if (dependency instanceof ProjectDependency) { label = "project " + dependency.getName(); } else { label = Joiner.on(":").join(Iterables.filter(Arrays.asList(dependency.getGroup(), dependency.getName(), dependency.getVersion()), Predicates.<String>notNull())); } return label; } @Override public String getDescription() { return null; } @Override public ResolutionState getResolutionState() { return ResolutionState.UNRESOLVED; } @Override public Set<? extends RenderableDependency> getChildren() { return Collections.emptySet(); } }); } return children; }
private void addProjectDependency(ProjectDependency dependency, String confMapping) { ModuleVersionIdentifier identifier = projectDependencyResolver.resolve(dependency); ivyDependencies.add(new DefaultIvyDependency( identifier.getGroup(), identifier.getName(), identifier.getVersion(), confMapping, dependency.isTransitive(), Collections.<DependencyArtifact>emptyList(), dependency.getExcludeRules())); }