private void configureUploadArchivesTask() { configurationActionContainer.add(new Action<Project>() { public void execute(Project project) { Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(BasePlugin.UPLOAD_ARCHIVES_TASK_NAME); if (uploadArchives == null) { return; } ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration(); Module module = configuration.getModule(); for (MavenResolver resolver : uploadArchives.getRepositories().withType(MavenResolver.class)) { MavenPom pom = resolver.getPom(); ModuleVersionIdentifier publicationId = new DefaultModuleVersionIdentifier( pom.getGroupId().equals(MavenProject.EMPTY_PROJECT_GROUP_ID) ? module.getGroup() : pom.getGroupId(), pom.getArtifactId().equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID) ? module.getName() : pom.getArtifactId(), pom.getVersion().equals(MavenProject.EMPTY_PROJECT_VERSION) ? module.getVersion() : pom.getVersion() ); publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(publicationId)); } } }); }
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 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(); }
/** * 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; }
@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(); }
/** * A recursive approach to dependency resolution * * @param parentDependency * @param resolvedDependenciesMap */ private void addResolvedDependencyInfo(ResolvedDependencyInfo parentDependency, Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap) { int indent = parentDependency.getIndent(); ModuleVersionIdentifier identifier = parentDependency.getModuleVersionIdentifier(); Collection<ResolvedDependencyInfo> childDependencies = resolvedDependenciesMap.get(identifier); //TODO here for (ResolvedDependencyInfo childDependency : childDependencies) { if (childDependency.getIndent() > indent) { // System.out.println(parentDependency + " indent " + indent + "->" + childDependency // + " indent " + childDependency.getIndent()); parentDependency.getChildren().add(childDependency); if (childDependency.getIndent() <= 1) { addResolvedDependencyInfo(childDependency, resolvedDependenciesMap); } } } }
public static boolean isAwbDependency(DependencyResult dependencyResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) { if (dependencyResult instanceof ResolvedDependencyResult) { ResolvedDependencyResult resolvedDependencyResult = (ResolvedDependencyResult)dependencyResult; ModuleVersionIdentifier moduleVersionIdentifier = resolvedDependencyResult.getSelected().getModuleVersion(); List<ResolvedArtifact> resolvedArtifacts = artifacts.get(moduleVersionIdentifier); if (resolvedArtifacts.size() > 0) { ResolvedArtifact resolvedArtifact = resolvedArtifacts.get(0); return ("awb".equals(resolvedArtifact.getType())); } } return false; }
public boolean mustRefreshVersionList(final ModuleIdentifier moduleIdentifier, Set<ModuleVersionIdentifier> matchingVersions, long ageMillis) { CachedDependencyResolutionControl dependencyResolutionControl = new CachedDependencyResolutionControl(moduleIdentifier, matchingVersions, ageMillis); for (Action<? super DependencyResolutionControl> rule : dependencyCacheRules) { rule.execute(dependencyResolutionControl); if (dependencyResolutionControl.ruleMatch()) { return dependencyResolutionControl.mustCheck(); } } return false; }
private boolean mustRefreshModule(ModuleVersionIdentifier moduleVersionId, ResolvedModuleVersion version, long ageMillis, boolean changingModule) { CachedModuleResolutionControl moduleResolutionControl = new CachedModuleResolutionControl(moduleVersionId, version, changingModule, ageMillis); for (Action<? super ModuleResolutionControl> rule : moduleCacheRules) { rule.execute(moduleResolutionControl); if (moduleResolutionControl.ruleMatch()) { return moduleResolutionControl.mustCheck(); } } return false; }
public boolean mustRefreshModuleArtifacts(ModuleVersionIdentifier moduleVersionId, Set<ArtifactIdentifier> artifacts, long ageMillis, boolean belongsToChangingModule, boolean moduleDescriptorInSync) { if (belongsToChangingModule && !moduleDescriptorInSync) { return true; } return mustRefreshModule(moduleVersionId, new DefaultResolvedModuleVersion(moduleVersionId), ageMillis, belongsToChangingModule); }
/** * dependent * @param identifier * @return */ private String getIdentifier(ModuleVersionIdentifier identifier) { StringBuilder sb = new StringBuilder(); sb.append(identifier.getGroup()).append(":"); sb.append(identifier.getName()).append(":"); sb.append(identifier.getVersion()); return sb.toString(); }
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; }
public ComponentResult read(Decoder decoder) throws IOException { long resultId = decoder.readSmallLong(); ModuleVersionIdentifier id = idSerializer.read(decoder); ComponentSelectionReason reason = reasonSerializer.read(decoder); ComponentIdentifier componentId = componentIdSerializer.read(decoder); return new DefaultComponentResult(resultId, id, reason, componentId); }
public ModuleVersionResolveState getVersion(ModuleVersionIdentifier id) { ModuleVersionResolveState moduleRevision = versions.get(id); if (moduleRevision == null) { moduleRevision = new ModuleVersionResolveState(idGenerator.generateId(), this, id, metaDataResolver); versions.put(id, moduleRevision); } return moduleRevision; }
public DefaultResolvedArtifact(ModuleVersionIdentifier owner, IvyArtifactName artifact, ComponentArtifactIdentifier artifactId, TaskDependency buildDependencies, Factory<File> artifactSource) { this.owner = owner; this.artifact = artifact; this.artifactId = artifactId; this.buildDependencies = buildDependencies; this.artifactSource = artifactSource; this.attributes = DefaultArtifactAttributes.forIvyArtifactName(artifact); }
public DefaultResolvedArtifact(ModuleVersionIdentifier owner, IvyArtifactName artifact, ComponentArtifactIdentifier artifactId, TaskDependency buildDependencies, File artifactFile) { this.owner = owner; this.artifact = artifact; this.artifactId = artifactId; this.buildDependencies = buildDependencies; this.attributes = DefaultArtifactAttributes.forIvyArtifactName(artifact); this.file = artifactFile; }
public ComponentResolveMetadata toRootComponentMetaData() { Module module = getModule(); ComponentIdentifier componentIdentifier = componentIdentifierFactory.createComponentIdentifier(module); ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(module); ProjectInternal project = projectFinder.findProject(module.getProjectPath()); AttributesSchema schema = project == null ? null : project.getAttributesSchema(); DefaultLocalComponentMetadata metaData = new DefaultLocalComponentMetadata(moduleVersionIdentifier, componentIdentifier, module.getStatus(), schema); configurationComponentMetaDataBuilder.addConfigurations(metaData, configurationsProvider.getAll()); return metaData; }
public DefaultArtifactIdentifier(ModuleVersionIdentifier moduleVersionIdentifier, String name, String type, String extension, String classifier) { this.moduleVersionIdentifier = moduleVersionIdentifier; this.name = name; this.type = type; this.extension = extension; this.classifier = classifier; }
public DefaultResolvedComponentResult(ModuleVersionIdentifier moduleVersion, ComponentSelectionReason selectionReason, ComponentIdentifier componentId) { assert moduleVersion != null; assert selectionReason != null; this.moduleVersion = moduleVersion; this.selectionReason = selectionReason; this.componentId = componentId; }
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; }
@Override protected boolean checkForExclusion(@NonNull VariantDependencies configDependencies, ModuleVersionIdentifier moduleVersion, ResolvedComponentResult resolvedComponentResult) { return super.checkForExclusion(configDependencies, moduleVersion, resolvedComponentResult) || ( apDependencies != null && apDependencies.hasSameResolvedDependency(moduleVersion) && !(resolvedComponentResult.getId() instanceof ProjectComponentIdentifier)); }
private void validateMetadata(IvyNormalizedPublication publication) { IvyPublicationIdentity identity = publication.getProjectIdentity(); IvyFieldValidator organisation = field(publication, "organisation", identity.getOrganisation()) .notEmpty() .validInFileName(); IvyFieldValidator moduleName = field(publication, "module name", identity.getModule()) .notEmpty() .validInFileName(); IvyFieldValidator revision = field(publication, "revision", identity.getRevision()) .notEmpty() .validInFileName(); MutableModuleComponentResolveMetadata metadata = parseIvyFile(publication); ModuleVersionIdentifier moduleId = metadata.getId(); organisation.matches(moduleId.getGroup()); moduleName.matches(moduleId.getName()); revision.matches(moduleId.getVersion()); field(publication, "branch", metadata.getDescriptor().getBranch()) .optionalNotEmpty() .doesNotContainSpecialCharacters(true); field(publication, "status", metadata.getStatus()) .optionalNotEmpty() .validInFileName(); }
private static AbstractLibrary createLibraryEntry(File binary, File source, File javadoc, EclipseClasspath classpath, ModuleVersionIdentifier id) { FileReferenceFactory referenceFactory = classpath.getFileReferenceFactory(); FileReference binaryRef = referenceFactory.fromFile(binary); FileReference sourceRef = referenceFactory.fromFile(source); FileReference javadocRef = referenceFactory.fromFile(javadoc); final AbstractLibrary out = binaryRef.isRelativeToPathVariable() ? new Variable(binaryRef) : new Library(binaryRef); out.setJavadocPath(javadocRef); out.setSourcePath(sourceRef); out.setExported(false); out.setModuleVersion(id); return out; }
public DefaultEclipseExternalDependency(File file, File javadoc, File source, ModuleVersionIdentifier identifier, boolean exported, List<DefaultClasspathAttribute> attributes, List<DefaultAccessRule> accessRules) { super(exported, attributes, accessRules); this.file = file; this.javadoc = javadoc; this.source = source; this.identifier = identifier; this.moduleVersion = (identifier == null)? null : new DefaultGradleModuleVersion(identifier); }
/** * Maps resolved dependencies by module version identifier. * * @param components Resolved dependencies * @return Mapped, resolved dependencies */ private Set<ModuleVersionIdentifier> mapResolvedDependencies(Set<ResolvedComponentResult> components) { Set<ModuleVersionIdentifier> mappedResolvedDependencies = new LinkedHashSet<ModuleVersionIdentifier>(); for (ResolvedComponentResult component : components) { mappedResolvedDependencies.add(component.getModuleVersion()); } return mappedResolvedDependencies; }
/** * Join the rely on * @param identifier * @param parent * @param ident * @return Determine if there is a circular dependency, and if any, return true */ public DependencyNode addDependency(ModuleVersionIdentifier identifier, DependencyNode parent, int ident) { String name = getIdentifier(identifier); DependencyNode node = new DependencyNode(name, ident); node.parent = parent; if (null != parent) { parent.children.add(node); } return node; }
public boolean hasSameResolvedDependency(ModuleVersionIdentifier moduleVersion) { String mainVersion = mFlatDependenciesMap.get(moduleVersion.getModule()); if (mainVersion == null) { return false; } return versionComparator.compare(moduleVersion.getVersion(), mainVersion) <= 0; }
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 List<ResolvedDependencyInfo> resolve(List<DependencyResult> dependencyResults, boolean mainBundle) { Multimap<String, ResolvedDependencyInfo> dependenciesMap = LinkedHashMultimap.create(); // Instead of using the official flat dependency treatment, you can use your own tree dependence; For application dependencies, we only take compile dependencies Set<ModuleVersionIdentifier> directDependencies = new HashSet<ModuleVersionIdentifier>(); Set<String> resolveSets = new HashSet<>(); for (DependencyResult dependencyResult : dependencyResults) { if (dependencyResult instanceof ResolvedDependencyResult) { ModuleVersionIdentifier moduleVersion = ((ResolvedDependencyResult)dependencyResult).getSelected() .getModuleVersion(); CircleDependencyCheck circleDependencyCheck = new CircleDependencyCheck(moduleVersion); if (!directDependencies.contains(moduleVersion)) { directDependencies.add(moduleVersion); resolveDependency(null, ((ResolvedDependencyResult)dependencyResult).getSelected(), artifacts, variantDeps, 0, circleDependencyCheck, circleDependencyCheck.getRootDependencyNode(), dependenciesMap, resolveSets); } } } List<ResolvedDependencyInfo> mainResolvdInfo = resolveAllDependencies(dependenciesMap); if (mainBundle) { for (ResolvedDependencyInfo resolvedDependencyInfo : mainResolvdInfo) { addMainDependencyInfo(resolvedDependencyInfo); } } return mainResolvdInfo; }
private boolean checkForExclusion(VariantDependencies configDependencies, ModuleVersionIdentifier moduleVersion, ResolvedComponentResult resolvedComponentResult) { if (configDependencies.getChecker().checkForExclusion(moduleVersion) || (apDependencies != null && apDependencies .hasSameResolvedDependency( moduleVersion) && !(resolvedComponentResult .getId() instanceof ProjectComponentIdentifier))) { return true; } return false; }
private DefaultLibraryLocalComponentMetadata(ModuleVersionIdentifier id, ComponentIdentifier componentIdentifier) { super(id, componentIdentifier, Project.DEFAULT_STATUS, new DefaultAttributesSchema()); }
public DefaultResolvedModuleVersion(ModuleVersionIdentifier identifier) { this.identifier = identifier; }
public ModuleVersionIdentifier getId() { return identifier; }
protected boolean checkForExclusion(@NonNull VariantDependencies configDependencies, ModuleVersionIdentifier moduleVersion, ResolvedComponentResult resolvedComponentResult) {return configDependencies.getChecker().checkForExclusion(moduleVersion);}
public DefaultProjectPublication(ModuleVersionIdentifier id) { this.id = id; }
public ModuleVersionIdentifier getId() { return id; }
public ModuleVersionIdentifier getModuleVersionIdentifier() { return new DefaultModuleVersionIdentifier(group, name, version); }