private Set<String> getBundleDependencies(Configuration compileClasspath, Set<? extends DependencyResult> bundleDependencies) { Set<String> bundleSets = new HashSet<>(); for (DependencyResult dependencyResult : bundleDependencies) { bundleSets.add(dependencyResult.toString()); } for (Dependency dependency : compileClasspath.getAllDependencies()) { if (dependency instanceof DefaultExternalModuleDependency) { DefaultExternalModuleDependency externalModuleDependency = (DefaultExternalModuleDependency)dependency; if (!((DefaultExternalModuleDependency)dependency).getArtifacts().isEmpty()) { if (StringUtils.equalsIgnoreCase("awb", ((DefaultExternalModuleDependency)dependency).getArtifacts() .iterator().next().getType())) { bundleSets.add( dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion()); } } } } return bundleSets; }
private ClassPath resolvePluginDependencies(final PluginUseMetaData metadata) { DependencyResolutionServices resolution = dependencyResolutionServicesFactory.create(); RepositoryHandler repositories = resolution.getResolveRepositoryHandler(); final String repoUrl = metadata.implementation.get("repo"); repositories.maven(new Action<MavenArtifactRepository>() { public void execute(MavenArtifactRepository mavenArtifactRepository) { mavenArtifactRepository.setUrl(repoUrl); } }); Dependency dependency = resolution.getDependencyHandler().create(metadata.implementation.get("gav")); ConfigurationContainerInternal configurations = (ConfigurationContainerInternal) resolution.getConfigurationContainer(); ConfigurationInternal configuration = configurations.detachedConfiguration(dependency); try { Set<File> files = configuration.getResolvedConfiguration().getFiles(Specs.satisfyAll()); return new DefaultClassPath(files); } catch (ResolveException e) { throw new DependencyResolutionException("Failed to resolve all plugin dependencies from " + repoUrl, e.getCause()); } }
private TaskDependency doGetTaskDependency(Spec<? super Dependency> dependencySpec, AttributeContainerInternal requestedAttributes) { synchronized (resolutionLock) { if (resolutionStrategy.resolveGraphToDetermineTaskDependencies()) { // Force graph resolution as this is required to calculate build dependencies resolveToStateOrLater(GRAPH_RESOLVED); } ResolverResults results; if (getState() == State.UNRESOLVED) { // Traverse graph results = new DefaultResolverResults(); resolver.resolveBuildDependencies(this, results); } else { // Otherwise, already have a result, so reuse it results = cachedResolverResults; } List<Object> buildDependencies = new ArrayList<Object>(); results.getVisitedArtifacts().select(dependencySpec, requestedAttributes).collectBuildDependencies(buildDependencies); return TaskDependencies.of(buildDependencies); } }
/** * Gets IDE local file dependencies. * * @param configuration Configuration * @return IDE local file dependencies */ public List<IdeLocalFileDependency> getIdeLocalFileDependencies(Configuration configuration) { List<SelfResolvingDependency> externalDependencies = new ArrayList<SelfResolvingDependency>(); findAllExternalDependencies(externalDependencies, new ArrayList<Dependency>(), configuration); List<IdeLocalFileDependency> ideLocalFileDependencies = new ArrayList<IdeLocalFileDependency>(); for (SelfResolvingDependency externalDependency : externalDependencies) { Set<File> resolvedFiles = externalDependency.resolve(); for (File resolvedFile : resolvedFiles) { IdeLocalFileDependency ideLocalFileDependency = new IdeLocalFileDependency(resolvedFile); ideLocalFileDependencies.add(ideLocalFileDependency); } } return ideLocalFileDependencies; }
private File getBaseApFile(Project project, TBuildType tBuildType) { File apBaseFile; File buildTypeBaseApFile = tBuildType.getBaseApFile(); if (null != buildTypeBaseApFile && buildTypeBaseApFile.exists()) { apBaseFile = buildTypeBaseApFile; } else if (!isNullOrEmpty(tBuildType.getBaseApDependency())) { String apDependency = tBuildType.getBaseApDependency(); // Preconditions.checkNotNull(apDependency, // "You have to specify the baseApFile property or the baseApDependency // dependency"); Dependency dependency = project.getDependencies().create(apDependency); Configuration configuration = project.getConfigurations().detachedConfiguration(dependency); configuration.setTransitive(false); apBaseFile = Iterables.getOnlyElement(Collections2.filter(configuration.getFiles(), new Predicate<File>() { @Override public boolean apply(@Nullable File file) { return file.getName().endsWith(".ap"); } })); } else { throw new IllegalStateException("AP is missing"); } return apBaseFile; }
private void configureInstall(Project project) { Upload installUpload = project.getTasks().create(INSTALL_TASK_NAME, Upload.class); Configuration configuration = project.getConfigurations().getByName(Dependency.ARCHIVES_CONFIGURATION); installUpload.setConfiguration(configuration); MavenRepositoryHandlerConvention repositories = new DslObject(installUpload.getRepositories()).getConvention().getPlugin(MavenRepositoryHandlerConvention.class); repositories.mavenInstaller(); installUpload.setDescription("Installs the 'archives' artifacts into the local Maven repository."); }
private void configureConfigurations(final Project project) { ConfigurationContainer configurations = project.getConfigurations(); Configuration moduleConfiguration = configurations.create(DEPLOY_CONFIGURATION_NAME).setVisible(false) .setTransitive(false).setDescription("Classpath for deployable modules, not transitive."); Configuration earlibConfiguration = configurations.create(EARLIB_CONFIGURATION_NAME).setVisible(false) .setDescription("Classpath for module dependencies."); configurations.getByName(Dependency.DEFAULT_CONFIGURATION) .extendsFrom(moduleConfiguration, earlibConfiguration); }
public Configuration addConfiguration(ConfigurationContainer configurations, final DependencyHandler dependencies, final EnvJsExtension extension) { Configuration configuration = configurations.create(EnvJsExtension.CONFIGURATION_NAME); configuration.defaultDependencies(new Action<DependencySet>() { @Override public void execute(DependencySet configDependencies) { String notation = EnvJsExtension.DEFAULT_DEPENDENCY_GROUP + ":" + EnvJsExtension.DEFAULT_DEPENDENCY_MODULE + ":" + extension.getVersion() + "@js"; Dependency dependency = dependencies.create(notation); configDependencies.add(dependency); } }); return configuration; }
private Configuration addJsConfiguration(ConfigurationContainer configurations, final DependencyHandler dependencies, final CoffeeScriptExtension extension) { Configuration configuration = configurations.create(CoffeeScriptExtension.JS_CONFIGURATION_NAME); configuration.defaultDependencies(new Action<DependencySet>() { @Override public void execute(DependencySet configDependencies) { String notation = CoffeeScriptExtension.DEFAULT_JS_DEPENDENCY_GROUP + ":" + CoffeeScriptExtension.DEFAULT_JS_DEPENDENCY_MODULE + ":" + extension.getVersion() + "@js"; Dependency dependency = dependencies.create(notation); configDependencies.add(dependency); } }); return configuration; }
private boolean exists(PluginRequest request) { // This works because the corresponding BackedByArtifactRepository PluginRepository sets // registers an ArtifactRepository in the DependencyResolutionServices instance which is // exclusively used by this ArtifactRepositoryPluginResolver. If the plugin marker // doesn't exist in that isolated ArtifactRepository, this resolver won't look anywhere else. Dependency dependency = resolution.getDependencyHandler().create(getMarkerCoordinates(request)); ConfigurationContainer configurations = resolution.getConfigurationContainer(); Configuration configuration = configurations.detachedConfiguration(dependency); configuration.setTransitive(false); return !configuration.getResolvedConfiguration().hasError(); }
public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) { Set<ResolvedDependency> matches = new LinkedHashSet<ResolvedDependency>(); for (DependencyGraphNodeResult node : getFirstLevelNodes(dependencySpec)) { matches.add(node.getPublicView()); } return matches; }
private Set<DependencyGraphNodeResult> getFirstLevelNodes(Spec<? super Dependency> dependencySpec) { Set<DependencyGraphNodeResult> matches = new LinkedHashSet<DependencyGraphNodeResult>(); TransientConfigurationResults graphResults = loadTransientGraphResults(selectedArtifacts); for (Map.Entry<ModuleDependency, DependencyGraphNodeResult> entry : graphResults.getFirstLevelDependencies().entrySet()) { if (dependencySpec.isSatisfiedBy(entry.getKey())) { matches.add(entry.getValue()); } } return matches; }
/** * Recursive but excludes unsuccessfully resolved artifacts. */ public Set<File> getFiles(Spec<? super Dependency> dependencySpec) { Set<File> files = Sets.newLinkedHashSet(); FilesAndArtifactCollectingVisitor visitor = new FilesAndArtifactCollectingVisitor(files); visitArtifacts(dependencySpec, configuration.getAttributes(), selectedArtifacts, selectedFileDependencies, visitor); files.addAll(getFiles(filterUnresolved(visitor.artifacts))); return files; }
/** * Recursive, includes unsuccessfully resolved artifacts * * @param dependencySpec dependency spec */ private void visitArtifacts(Spec<? super Dependency> dependencySpec, AttributeContainerInternal requestedAttributes, SelectedArtifactResults artifactResults, SelectedFileDependencyResults fileDependencyResults, ArtifactVisitor visitor) { ArtifactVisitor transformingVisitor = artifactTransformer.visitor(visitor, requestedAttributes); //this is not very nice might be good enough until we get rid of ResolvedConfiguration and friends //avoid traversing the graph causing the full ResolvedDependency graph to be loaded for the most typical scenario if (dependencySpec == Specs.SATISFIES_ALL) { if (transformingVisitor.includeFiles()) { fileDependencyResults.getFiles().visit(transformingVisitor); } artifactResults.getArtifacts().visit(transformingVisitor); return; } if (transformingVisitor.includeFiles()) { for (Map.Entry<FileCollectionDependency, ResolvedArtifactSet> entry: fileDependencyResults.getFirstLevelFiles().entrySet()) { if (dependencySpec.isSatisfiedBy(entry.getKey())) { entry.getValue().visit(transformingVisitor); } } } CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact> walker = new CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact>(new ResolvedDependencyArtifactsGraph(transformingVisitor, fileDependencyResults)); DependencyGraphNodeResult rootNode = loadTransientGraphResults(artifactResults).getRootNode(); for (DependencyGraphNodeResult node : getFirstLevelNodes(dependencySpec)) { node.getArtifactsForIncomingEdge(rootNode).visit(transformingVisitor); walker.add(node); } walker.findValues(); }
@Override public Set<ResolvedArtifact> getArtifacts(Spec<? super Dependency> dependencySpec) { try { return lenientConfiguration.getArtifacts(dependencySpec); } catch (Throwable e) { throw wrapException(e, resolveContext); } }
@Override public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) { try { return lenientConfiguration.getFirstLevelModuleDependencies(dependencySpec); } catch (Throwable e) { throw wrapException(e, resolveContext); } }
@Override public Set<File> getFiles(Spec<? super Dependency> dependencySpec) { try { return lenientConfiguration.getFiles(dependencySpec); } catch (Throwable e) { throw wrapException(e, resolveContext); } }
public Set<File> getFiles(Spec<? super Dependency> dependencySpec) throws ResolveException { try { return resolvedConfiguration.getFiles(dependencySpec); } catch (Throwable e) { throw wrapException(e, configuration); } }
public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) throws ResolveException { try { return resolvedConfiguration.getFirstLevelModuleDependencies(dependencySpec); } catch (Throwable e) { throw wrapException(e, configuration); } }
private void addDependencies(BuildableLocalComponentMetadata metaData, ConfigurationInternal configuration) { AttributeContainerInternal attributes = configuration.getAttributes().asImmutable(); for (Dependency dependency : configuration.getDependencies()) { if (dependency instanceof ModuleDependency) { ModuleDependency moduleDependency = (ModuleDependency) dependency; metaData.addDependency(dependencyDescriptorFactory.createDependencyDescriptor(configuration.getName(), attributes, moduleDependency)); } else if (dependency instanceof FileCollectionDependency) { final FileCollectionDependency fileDependency = (FileCollectionDependency) dependency; metaData.addFiles(configuration.getName(), new DefaultLocalFileDependencyMetadata(fileDependency)); } else { throw new IllegalArgumentException("Cannot convert dependency " + dependency + " to local component dependency metadata."); } } }
private void ensureConfigured(Configuration config) { for (Dependency dependency : config.getAllDependencies()) { if (dependency instanceof ProjectDependency) { ProjectDependency projectDependency = (ProjectDependency)dependency; project.evaluationDependsOn(projectDependency.getDependencyProject().getPath()); } } }
private ConfigurationFileCollection(final Set<Dependency> dependencies) { this(new Spec<Dependency>() { public boolean isSatisfiedBy(Dependency element) { return dependencies.contains(element); } }); }
@Override public void registerWatchPoints(FileSystemSubset.Builder builder) { for (Dependency dependency : allDependencies) { if (dependency instanceof FileCollectionDependency) { FileCollection files = ((FileCollectionDependency) dependency).getFiles(); ((FileCollectionInternal) files).registerWatchPoints(builder); } } super.registerWatchPoints(builder); }
private Map<String, DependencyExtraInfo> getExtraMap() { Map<String, DependencyExtraInfo> dependencyExtraInfoMap = new HashMap<>(); DependencySet dependencies = project.getConfigurations().getByName("compile").getDependencies(); dependencies.forEach(new Consumer<Dependency>() { @Override public void accept(Dependency dependency) { String group = dependency.getGroup(); String name = dependency.getName(); String scope = "compile"; String type = ""; if (dependency instanceof DefaultProjectDependency) { DefaultProjectDependency projectDependency = (DefaultProjectDependency)dependency; if (projectDependency.getDependencyProject().getPlugins().hasPlugin(LibraryPlugin.class)) { type = "aar"; } } dependencyExtraInfoMap.put(group + ":" + name, new DependencyExtraInfo(type, scope)); } }); return dependencyExtraInfoMap; }
public static NotationParser<Object, Dependency> parser(Instantiator instantiator, DefaultProjectDependencyFactory dependencyFactory, ClassPathRegistry classPathRegistry, FileLookup fileLookup, RuntimeShadedJarFactory runtimeShadedJarFactory, CurrentGradleInstallation currentGradleInstallation) { return NotationParserBuilder .toType(Dependency.class) .fromCharSequence(new DependencyStringNotationConverter<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class)) .converter(new DependencyMapNotationConverter<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class)) .fromType(FileCollection.class, new DependencyFilesNotationConverter(instantiator)) .fromType(Project.class, new DependencyProjectNotationConverter(dependencyFactory)) .fromType(DependencyFactory.ClassPathNotation.class, new DependencyClassPathNotationConverter(instantiator, classPathRegistry, fileLookup.getFileResolver(), runtimeShadedJarFactory, currentGradleInstallation)) .invalidNotationMessage("Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type.") .toComposite(); }
private void addArtifacts(Project project, List<GradleFileBuildOutcome> outcomes) { Configuration configuration = project.getConfigurations().findByName(Dependency.ARCHIVES_CONFIGURATION); if (configuration != null) { for (PublishArtifact artifact : configuration.getArtifacts()) { GradleFileBuildOutcome outcome = artifactTransformer.transform(artifact, project); outcomes.add(outcome); } } }
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); } } } }
private static void configureScalaDependencies(final Project project, final GenerateEclipseClasspath task) { project.getPlugins().withType(ScalaBasePlugin.class, new Action<ScalaBasePlugin>() { @Override public void execute(ScalaBasePlugin scalaBasePlugin) { task.getClasspath().containers("org.scala-ide.sdt.launching.SCALA_CONTAINER"); // exclude the dependencies already provided by SCALA_CONTAINER; prevents problems with Eclipse Scala plugin project.getGradle().addBuildListener(new BuildAdapter() { @Override public void projectsEvaluated(Gradle gradle) { final List<String> provided = Lists.newArrayList("scala-library", "scala-swing", "scala-dbc"); Predicate<Dependency> dependencyInProvided = new Predicate<Dependency>() { @Override public boolean apply(Dependency dependency) { return provided.contains(dependency.getName()); } }; List<Dependency> dependencies = Lists.newArrayList(Iterables.filter(Iterables.concat(Iterables.transform(task.getClasspath().getPlusConfigurations(), new Function<Configuration, Iterable<Dependency>>() { @Override public Iterable<Dependency> apply(Configuration config) { return config.getAllDependencies(); } })), dependencyInProvided)); if (!dependencies.isEmpty()) { task.getClasspath().getMinusConfigurations().add(project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[0]))); } } }); } }); }
/** * 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); }
private Dependency doAdd(Configuration configuration, Object dependencyNotation, Closure configureClosure) { if (dependencyNotation instanceof Configuration) { Configuration other = (Configuration) dependencyNotation; if (!configurationContainer.contains(other)) { throw new UnsupportedOperationException("Currently you can only declare dependencies on configurations from the same project."); } configuration.extendsFrom(other); return null; } Dependency dependency = create(dependencyNotation, configureClosure); configuration.getDependencies().add(dependency); return dependency; }
private Configuration resolveToolClasspath(Object... dependencyNotations) { List<Dependency> dependencies = CollectionUtils.collect(dependencyNotations, new Transformer<Dependency, Object>() { public Dependency transform(Object dependencyNotation) { return dependencyHandler.create(dependencyNotation); } }); Dependency[] dependenciesArray = dependencies.toArray(new Dependency[0]); return configurationContainer.detachedConfiguration(dependenciesArray); }
public boolean contentEquals(Dependency dependency) { if (this == dependency) { return true; } if (dependency == null || getClass() != dependency.getClass()) { return false; } ExternalModuleDependency that = (ExternalModuleDependency) dependency; return isContentEqualsFor(that); }
@Override public void resolve(DependencyResolveContext context) { boolean transitive = isTransitive() && context.isTransitive(); if (transitive) { for (Dependency dependency : findProjectConfiguration().getAllDependencies()) { context.add(dependency); } } }
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()); }
@Override public boolean contentEquals(Dependency dependency) { if (!(dependency instanceof DefaultSelfResolvingDependency)) { return false; } DefaultSelfResolvingDependency selfResolvingDependency = (DefaultSelfResolvingDependency) dependency; return source.equals(selfResolvingDependency.source); }
public boolean contentEquals(Dependency dependency) { if (this == dependency) { return true; } if (dependency == null || getClass() != dependency.getClass()) { return false; } ClientModule that = (ClientModule) dependency; return isContentEqualsFor(that) && dependencies.equals(that.getDependencies()); }
void configureConfigurations(Project project) { ConfigurationContainer configurations = project.getConfigurations(); Configuration compileConfiguration = configurations.getByName(COMPILE_CONFIGURATION_NAME); Configuration runtimeConfiguration = configurations.getByName(RUNTIME_CONFIGURATION_NAME); Configuration compileTestsConfiguration = configurations.getByName(TEST_COMPILE_CONFIGURATION_NAME); compileTestsConfiguration.extendsFrom(compileConfiguration); configurations.getByName(TEST_RUNTIME_CONFIGURATION_NAME).extendsFrom(runtimeConfiguration, compileTestsConfiguration); configurations.getByName(Dependency.DEFAULT_CONFIGURATION).extendsFrom(runtimeConfiguration); }
/** * Searches the specified class path for Groovy Jars ({@code groovy(-indy)}, {@code groovy-all(-indy)}) and returns a corresponding class path for executing Groovy tools such as the Groovy * compiler and Groovydoc tool. The tool versions will match those of the Groovy Jars found. If no Groovy Jars are found on the specified class path, a class path with the contents of the {@code * groovy} configuration will be returned. * * <p>The returned class path may be empty, or may fail to resolve when asked for its contents. * * @param classpath a class path containing Groovy Jars * @return a corresponding class path for executing Groovy tools such as the Groovy compiler and Groovydoc tool */ public FileCollection inferGroovyClasspath(final Iterable<File> classpath) { // alternatively, we could return project.files(Runnable) // would differ in at least the following ways: 1. live 2. no autowiring return new LazilyInitializedFileCollection() { @Override public String getDisplayName() { return "Groovy runtime classpath"; } @Override public FileCollection createDelegate() { GroovyJarFile groovyJar = findGroovyJarFile(classpath); if (groovyJar == null) { throw new GradleException(String.format("Cannot infer Groovy class path because no Groovy Jar was found on class path: %s", classpath)); } if (groovyJar.isGroovyAll()) { return Cast.cast(FileCollectionInternal.class, project.files(groovyJar.getFile())); } if (project.getRepositories().isEmpty()) { throw new GradleException("Cannot infer Groovy class path because no repository is declared for the project."); } String notation = groovyJar.getDependencyNotation(); List<Dependency> dependencies = Lists.newArrayList(); // project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier dependencies.add(project.getDependencies().create(notation)); if (groovyJar.getVersion().getMajor() >= 2) { // add groovy-ant to bring in Groovydoc dependencies.add(project.getDependencies().create(notation.replace(":groovy:", ":groovy-ant:"))); } return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[0])); } // let's override this so that delegate isn't created at autowiring time (which would mean on every build) @Override public void visitDependencies(TaskDependencyResolveContext context) { if (classpath instanceof Buildable) { context.add(classpath); } } }; }
@Override public Set<File> getFiles() { return getFiles(Specs.<Dependency>satisfyAll()); }