@Override public Set<File> getFiles() { ensureResolved(true); final Set<File> result = new LinkedHashSet<File>(); resolveResult.artifactsResults.getArtifacts().visit(new ArtifactVisitor() { @Override public void visitArtifact(ResolvedArtifact artifact) { result.add(artifact.getFile()); } @Override public boolean includeFiles() { return true; } @Override public void visitFiles(@Nullable ComponentIdentifier componentIdentifier, Iterable<File> files) { for (File file : files) { result.add(file); } } }); return result; }
public int compare(ResolvedArtifact artifact1, ResolvedArtifact artifact2) { int diff = artifact1.getName().compareTo(artifact2.getName()); if (diff != 0) { return diff; } diff = ObjectUtils.compare(artifact1.getClassifier(), artifact2.getClassifier()); if (diff != 0) { return diff; } diff = ObjectUtils.compare(artifact1.getExtension(), artifact2.getExtension()); if (diff != 0) { return diff; } diff = artifact1.getType().compareTo(artifact2.getType()); if (diff != 0) { return diff; } // Use an arbitrary ordering when the artifacts have the same public attributes return artifact1.hashCode() - artifact2.hashCode(); }
/** * Gets IDE repository file dependencies. * * @param configuration Configuration * @return IDE repository file dependencies */ public List<IdeExtendedRepoFileDependency> getIdeRepoFileDependencies(Configuration configuration) { ResolutionResult result = getIncomingResolutionResult(configuration); final Set<ResolvedComponentResult> resolvedRepoFileComponents = CollectionUtils.filter(result.getAllComponents(), new Spec<ResolvedComponentResult>() { @Override public boolean isSatisfiedBy(ResolvedComponentResult element) { return element.getId() instanceof ModuleComponentIdentifier; } }); Set<ModuleVersionIdentifier> mappedResolvedDependencies = mapResolvedDependencies(resolvedRepoFileComponents); Set<ResolvedArtifact> artifacts = getExternalArtifacts(configuration); List<IdeExtendedRepoFileDependency> externalDependencies = new ArrayList<IdeExtendedRepoFileDependency>(); for (ResolvedArtifact artifact : artifacts) { if (mappedResolvedDependencies.contains(artifact.getModuleVersion().getId())) { IdeExtendedRepoFileDependency ideRepoFileDependency = new IdeExtendedRepoFileDependency(artifact.getFile()); ideRepoFileDependency.setId(artifact.getModuleVersion().getId()); externalDependencies.add(ideRepoFileDependency); } } return externalDependencies; }
private ImmutableMap<File, String> calculate() { ImmutableMap.Builder<File, String> files = ImmutableMap.builder(); for (ResolvedArtifact artifact : getResolvedArtifacts()) { boolean isProject = artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier; if (isProject) { // rename project dependencies ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier) artifact.getId().getComponentIdentifier(); files.put(artifact.getFile(), renameForProject(projectComponentIdentifier, artifact.getFile())); } else { boolean isExternalModule = artifact.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier; if (isExternalModule) { ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier) artifact.getId().getComponentIdentifier(); files.put(artifact.getFile(), renameForModule(moduleComponentIdentifier, artifact.getFile())); } else { // don't rename other types of dependencies files.put(artifact.getFile(), artifact.getFile().getName()); } } } return files.build(); }
@NonNull public static String computeArtifactPath(@NonNull ModuleVersionIdentifier moduleVersion, @NonNull ResolvedArtifact artifact) { StringBuilder pathBuilder = new StringBuilder(); pathBuilder.append(normalize(moduleVersion, moduleVersion.getGroup())) .append("/") .append(normalize(moduleVersion, moduleVersion.getName())) .append("/") .append(normalize(moduleVersion, moduleVersion.getVersion())); if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) { pathBuilder.append("/") .append(normalize(moduleVersion, artifact.getClassifier())); } return pathBuilder.toString(); }
@NonNull public static String computeArtifactName(@NonNull ModuleVersionIdentifier moduleVersion, @NonNull ResolvedArtifact artifact) { StringBuilder nameBuilder = new StringBuilder(); nameBuilder.append(moduleVersion.getGroup()) .append(":") .append(moduleVersion.getName()) .append(":") .append(moduleVersion.getVersion()); if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) { nameBuilder.append(":").append(artifact.getClassifier()); } return nameBuilder.toString(); }
private void collectArtifacts(Configuration configuration, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) { Set<ResolvedArtifact> allArtifacts; if (!extraModelInfo.getMode().equals(STANDARD)) { allArtifacts = configuration.getResolvedConfiguration().getLenientConfiguration().getArtifacts( Specs.satisfyAll()); } else { allArtifacts = configuration.getResolvedConfiguration().getResolvedArtifacts(); } for (ResolvedArtifact artifact : allArtifacts) { ModuleVersionIdentifier id = artifact.getModuleVersion().getId(); List<ResolvedArtifact> moduleArtifacts = artifacts.get(id); if (moduleArtifacts == null) { moduleArtifacts = Lists.newArrayList(); artifacts.put(id, moduleArtifacts); } if (!moduleArtifacts.contains(artifact)) { moduleArtifacts.add(artifact); } } }
@NonNull private String computeArtifactPath( @NonNull ModuleVersionIdentifier moduleVersion, @NonNull ResolvedArtifact artifact) { StringBuilder pathBuilder = new StringBuilder( moduleVersion.getGroup().length() + moduleVersion.getName().length() + moduleVersion.getVersion().length() + 10); // in case of classifier which is rare. pathBuilder.append(normalize(logger, moduleVersion, moduleVersion.getGroup())) .append(File.separatorChar) .append(normalize(logger, moduleVersion, moduleVersion.getName())) .append(File.separatorChar) .append(normalize(logger, moduleVersion, moduleVersion.getVersion())); if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) { pathBuilder.append(File.separatorChar).append(normalize(logger, moduleVersion, artifact.getClassifier())); } return pathBuilder.toString(); }
@NonNull private static String computeArtifactName( @NonNull ModuleVersionIdentifier moduleVersion, @NonNull ResolvedArtifact artifact) { StringBuilder nameBuilder = new StringBuilder( moduleVersion.getGroup().length() + moduleVersion.getName().length() + moduleVersion.getVersion().length() + 10); // in case of classifier which is rare. nameBuilder.append(moduleVersion.getGroup()) .append(':') .append(moduleVersion.getName()) .append(':') .append(moduleVersion.getVersion()); if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) { nameBuilder.append(':').append(artifact.getClassifier()); } return nameBuilder.toString(); }
/** * Simple transformations, no dependencies * * @param resolvedDependencyInfo * @return */ public static AndroidLibrary toAndroidLibrary(ResolvedDependencyInfo resolvedDependencyInfo, Project project, boolean bundle) { ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact(); AndroidDependency androidDependency = AndroidDependency.createExplodedAarLibrary(artifact.getFile(), convert(artifact), resolvedDependencyInfo .getDependencyName(), null, resolvedDependencyInfo .getExplodedDir()); List<File> localJars = new ArrayList<>(); return new AndroidLibraryImpl(androidDependency, false, false, ImmutableList.<AndroidLibrary>of(), ImmutableList.<JavaLibrary>of(), localJars); }
/** * Find a resolved artifact in a collection of projects * * @param projects Projects to search * @param configurationPredicate Predicate to test configurations * @param artifactPredicate Predicate to test artifacts * @return Found element or empty value */ public static Optional<ProjectElement<ResolvedArtifact>> findResolvedArtifact(Collection<@NonNull Project> projects, Predicate<@NonNull Configuration> configurationPredicate, Predicate<@NonNull ResolvedArtifact> artifactPredicate) { Optional<ProjectElement<ResolvedArtifact>> info = Optional.empty(); for (Project project : projects) { info = findResolvedArtifact(project, configurationPredicate, artifactPredicate); if (info.isPresent()) { break; } } return info; }
/** * Find a resolved artifact in a project * * @param project Project to search * @param configurationPredicate Predicate to test configurations * @param artifactPredicate Predicate to test artifacts * @return Found element or empty value */ public static Optional<ProjectElement<ResolvedArtifact>> findResolvedArtifact(Project project, Predicate<@NonNull Configuration> configurationPredicate, Predicate<@NonNull ResolvedArtifact> artifactPredicate) { Optional<ProjectElement<ResolvedArtifact>> info = Optional.empty(); for (@NonNull Configuration configuration : project.getConfigurations()) { if (configuration.isCanBeResolved() && configurationPredicate.test(configuration)) { info = findResolvedArtifact(project, configuration, artifactPredicate); if (info.isPresent()) { break; } } } return info; }
@TaskAction public void mix() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, IOException { LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); Configuration configuration = getProject().getConfigurations().getByName(Constants.COMPILE_MODS); List<File> mods = new ArrayList<>(); for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) { getProject().getLogger().lifecycle(":found mod to mix:" + artifact.getFile().getName()); mods.add(artifact.getFile()); } if (Constants.MINECRAFT_FINAL_JAR.get(extension).exists()) { Constants.MINECRAFT_FINAL_JAR.get(extension).delete(); } if (mods.size() == 0) { FileUtils.copyFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), Constants.MINECRAFT_FINAL_JAR.get(extension)); } else { downloadRequiredDeps(extension); new PreBakeMixins().proccess(getProject(), extension, mods); } }
@Override public ArtifactSpec resolve(final ArtifactSpec spec) { if (spec.file != null) { return spec; } final Iterator<ResolvedArtifact> iterator = doResolve(new HashSet<>(Collections.singletonList(spec)), false).iterator(); if (iterator.hasNext()) { spec.file = iterator.next().getFile(); return spec; } return null; }
@NonNull private String computeArtifactPath( @NonNull ModuleVersionIdentifier moduleVersion, @NonNull ResolvedArtifact artifact) { StringBuilder pathBuilder = new StringBuilder(); pathBuilder.append(normalize(logger, moduleVersion, moduleVersion.getGroup())) .append('/') .append(normalize(logger, moduleVersion, moduleVersion.getName())) .append('/') .append(normalize(logger, moduleVersion, moduleVersion.getVersion())); if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) { pathBuilder.append('/').append(normalize(logger, moduleVersion, artifact.getClassifier())); } return pathBuilder.toString(); }
@NonNull private static String computeArtifactName( @NonNull ModuleVersionIdentifier moduleVersion, @NonNull ResolvedArtifact artifact) { StringBuilder nameBuilder = new StringBuilder(); nameBuilder.append(moduleVersion.getGroup()) .append(':') .append(moduleVersion.getName()) .append(':') .append(moduleVersion.getVersion()); if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) { nameBuilder.append(':').append(artifact.getClassifier()); } return nameBuilder.toString(); }
public int compare(ResolvedArtifact artifact1, ResolvedArtifact artifact2) { int diff = artifact1.getName().compareTo(artifact2.getName()); if (diff != 0) { return diff; } diff = ObjectUtils.compare(artifact1.getClassifier(), artifact2.getClassifier()); if (diff != 0) { return diff; } diff = artifact1.getExtension().compareTo(artifact2.getExtension()); if (diff != 0) { return diff; } diff = artifact1.getType().compareTo(artifact2.getType()); if (diff != 0) { return diff; } // Use an arbitrary ordering when the artifacts have the same public attributes return artifact1.hashCode() - artifact2.hashCode(); }
private Set<ResolvedArtifact> filterUnresolved(final Set<ResolvedArtifact> artifacts) { return cacheLockingManager.useCache("retrieve artifacts from " + configuration, new Factory<Set<ResolvedArtifact>>() { public Set<ResolvedArtifact> create() { return CollectionUtils.filter(artifacts, new IgnoreMissingExternalArtifacts()); } }); }
private Set<File> getFiles(final Set<ResolvedArtifact> artifacts) { final Set<File> files = new LinkedHashSet<File>(); cacheLockingManager.useCache("resolve files from " + configuration, new Runnable() { public void run() { for (ResolvedArtifact artifact : artifacts) { File depFile = artifact.getFile(); if (depFile != null) { files.add(depFile); } } } }); 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(); }
public void addArtifacts() { for (ResolvedArtifact artifact : artifacts) { try { this.files.add(artifact.getFile()); } catch (Throwable t) { failures.add(t); } } }
@Override public void visitArtifact(ResolvedArtifact artifact) { try { if (seenArtifacts.add(artifact.getId())) { // Trigger download of file, if required File file = artifact.getFile(); this.artifacts.add(new DefaultResolvedArtifactResult(artifact.getId(), Artifact.class, file)); } } catch (Throwable t) { failures.add(t); } }
@Override public void getNodeValues(DependencyGraphNodeResult node, Collection<? super ResolvedArtifact> values, Collection<? super DependencyGraphNodeResult> connectedNodes) { connectedNodes.addAll(node.getOutgoingEdges()); if (artifactsVisitor.includeFiles()) { fileDependencyResults.getFiles(node.getNodeId()).visit(artifactsVisitor); } }
public boolean isSatisfiedBy(ResolvedArtifact element) { if (isExternalModuleArtifact(element)) { try { element.getFile(); } catch (org.gradle.internal.resolve.ArtifactResolveException e) { return false; } } return true; }
@Override public Set<ResolvedArtifact> getArtifacts() { try { return lenientConfiguration.getArtifacts(); } catch (Exception e) { throw wrapException(e, resolveContext); } }
@Override public Set<ResolvedArtifact> getArtifacts(Spec<? super Dependency> dependencySpec) { try { return lenientConfiguration.getArtifacts(dependencySpec); } catch (Throwable e) { throw wrapException(e, resolveContext); } }
public Set<ResolvedArtifact> getResolvedArtifacts() throws ResolveException { try { return resolvedConfiguration.getResolvedArtifacts(); } catch (Throwable e) { throw wrapException(e, configuration); } }
public static ResolvedArtifactSet of(Collection<? extends ResolvedArtifact> artifacts) { if (artifacts.isEmpty()) { return EMPTY; } if (artifacts.size() == 1) { return new SingletonSet(artifacts.iterator().next()); } return new ArtifactBackedArtifactSet(artifacts); }
public DefaultArtifactSet(ModuleVersionIdentifier ownerId, ModuleSource moduleSource, ModuleExclusion exclusions, Set<? extends VariantMetadata> variants, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvedArtifact> allResolvedArtifacts, long id) { this.moduleVersionIdentifier = ownerId; this.moduleSource = moduleSource; this.exclusions = exclusions; this.variants = variants; this.artifactResolver = artifactResolver; this.allResolvedArtifacts = allResolvedArtifacts; this.id = id; }
@Override public ArtifactSet snapshot() { ImmutableSet.Builder<ResolvedVariant> result = ImmutableSet.builder(); for (final VariantMetadata variant : variants) { Set<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts(); Set<ResolvedArtifact> resolvedArtifacts = new LinkedHashSet<ResolvedArtifact>(artifacts.size()); // Add artifact type as an implicit attribute when there is a single artifact AttributeContainerInternal attributes = variant.getAttributes(); if (artifacts.size() == 1 && !attributes.contains(ArtifactAttributes.ARTIFACT_FORMAT)) { DefaultAttributeContainer implicitAttributes = new DefaultAttributeContainer(attributes); implicitAttributes.attribute(ArtifactAttributes.ARTIFACT_FORMAT, artifacts.iterator().next().getName().getType()); attributes = implicitAttributes.asImmutable(); } for (ComponentArtifactMetadata artifact : artifacts) { IvyArtifactName artifactName = artifact.getName(); if (exclusions.excludeArtifact(moduleVersionIdentifier.getModule(), artifactName)) { continue; } ResolvedArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId()); if (resolvedArtifact == null) { Factory<File> artifactSource = new LazyArtifactSource(artifact, moduleSource, artifactResolver); resolvedArtifact = new DefaultResolvedArtifact(moduleVersionIdentifier, artifactName, artifact.getId(), artifact.getBuildDependencies(), artifactSource); allResolvedArtifacts.put(artifact.getId(), resolvedArtifact); } resolvedArtifacts.add(resolvedArtifact); } result.add(new DefaultResolvedVariant(attributes, ArtifactBackedArtifactSet.of(resolvedArtifacts))); } return new ArtifactSetSnapshot(id, result.build()); }
@Override public Set<ResolvedArtifact> getArtifacts() { Set<ResolvedArtifact> allArtifacts = new LinkedHashSet<ResolvedArtifact>(); for (ResolvedArtifactSet set : sets) { allArtifacts.addAll(set.getArtifacts()); } return allArtifacts; }
public Set<ResolvedArtifact> getAllModuleArtifacts() { if (allModuleArtifactsCache == null) { Set<ResolvedArtifact> allArtifacts = new LinkedHashSet<ResolvedArtifact>(); allArtifacts.addAll(getModuleArtifacts()); for (ResolvedDependency childResolvedDependency : getChildren()) { allArtifacts.addAll(childResolvedDependency.getAllModuleArtifacts()); } allModuleArtifactsCache = allArtifacts; } return allModuleArtifactsCache; }
public Set<ResolvedArtifact> getAllArtifacts(ResolvedDependency parent) { if (allArtifactsCache.get(parent) == null) { Set<ResolvedArtifact> allArtifacts = new LinkedHashSet<ResolvedArtifact>(); allArtifacts.addAll(getArtifacts(parent)); for (ResolvedDependency childResolvedDependency : getChildren()) { for (ResolvedDependency childParent : childResolvedDependency.getParents()) { allArtifacts.addAll(childResolvedDependency.getAllArtifacts(childParent)); } } allArtifactsCache.put(parent, allArtifacts); } return allArtifactsCache.get(parent); }
public DependencyResolver(Project project, VariantDependencies variantDeps, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, Map<String, Set<String>> bundleProvidedMap, ApDependencies apDependencies) { this.project = project; this.variantDeps = variantDeps; this.artifacts = artifacts; this.bundleProvidedMap = bundleProvidedMap; this.apDependencies = apDependencies; }
public AtlasDependencyTree parseDependencyTree(@NonNull VariantDependencies variantDeps) { String name = variantDeps.getName().toLowerCase(); if (!name.endsWith("debug") && !name.endsWith("release")) { return new AtlasDependencyTree(new ArrayList<>()); } Configuration compileClasspath = variantDeps.getCompileConfiguration(); Configuration packageClasspath = variantDeps.getPackageConfiguration(); Configuration bundleClasspath = project.getConfigurations().maybeCreate(AtlasPlugin.BUNDLE_COMPILE); ensureConfigured(compileClasspath); ensureConfigured(packageClasspath); ensureConfigured(bundleClasspath); Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts = Maps.newHashMap(); collectArtifacts(compileClasspath, artifacts); collectArtifacts(packageClasspath, artifacts); collectArtifacts(bundleClasspath, artifacts); //Rely on the group DependencyGroup dependencyGroup = new DependencyGroup(compileClasspath, bundleClasspath,artifacts); DependencyResolver dependencyResolver = new DependencyResolver(project, variantDeps, artifacts, dependencyGroup.bundleProvidedMap, apDependencies); mResolvedDependencies.addAll(dependencyResolver.resolve(dependencyGroup.compileDependencies, true)); for (DependencyResult dependencyResult : dependencyGroup.bundleDependencies) { mResolvedDependencies.addAll(dependencyResolver.resolve(Arrays.asList(dependencyResult), false)); } AtlasDependencyTree atlasDependencyTree = toAtlasDependencyTree(); check(atlasDependencyTree); return atlasDependencyTree; }
public SoLibrary(ResolvedDependencyInfo resolvedDependencyInfo) { ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact(); this.mResolvedCoordinates = DependencyConvertUtils.convert(artifact); this.mSoLibFile = artifact.getFile(); this.mSoLibFolder = resolvedDependencyInfo.getExplodedDir(); }
@NonNull private static MavenCoordinatesImpl createMavenCoordinates( @NonNull ResolvedArtifact resolvedArtifact) { return new MavenCoordinatesImpl( resolvedArtifact.getModuleVersion().getId().getGroup(), resolvedArtifact.getModuleVersion().getId().getName(), resolvedArtifact.getModuleVersion().getId().getVersion(), resolvedArtifact.getExtension(), resolvedArtifact.getClassifier()); }
/** * Convert to jar dependency * * @param resolvedDependencyInfo * @return */ public static JavaLibrary toJavaLib(ResolvedDependencyInfo resolvedDependencyInfo) { ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact(); JavaLibrary jarInfo = new JavaLibraryImpl(artifact.getFile(), null, ImmutableList.<JavaLibrary>of(), null, convert(artifact), false, false); return jarInfo; }
public static ApLibrary toApLibrary(ResolvedDependencyInfo resolvedDependencyInfo) { assertType(Type.AP, resolvedDependencyInfo); ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact(); ApLibrary apLibrary = new ApLibrary(convert(artifact), artifact.getFile(), resolvedDependencyInfo.getExplodedDir()); return apLibrary; }