org.gradle.api.artifacts.ModuleVersionIdentifier Java Examples

The following examples show how to use org.gradle.api.artifacts.ModuleVersionIdentifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private TimestampedModuleSource findUniqueSnapshotVersion(ModuleRevisionId moduleRevisionId) {
    ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(moduleRevisionId);
    ModuleVersionArtifactIdentifier artifactId = new DefaultModuleVersionArtifactIdentifier(moduleVersionIdentifier, moduleVersionIdentifier.getName(), "pom", "pom");
    DefaultModuleVersionArtifactMetaData pomArtifact = new DefaultModuleVersionArtifactMetaData(artifactId);
    String metadataLocation = toResourcePattern(getWholePattern()).toModuleVersionPath(pomArtifact) + "/maven-metadata.xml";
    MavenMetadata mavenMetadata = parseMavenMetadata(metadataLocation);

    if (mavenMetadata.timestamp != null) {
        // we have found a timestamp, so this is a snapshot unique version
        String rev = moduleRevisionId.getRevision();
        rev = rev.substring(0, rev.length() - "SNAPSHOT".length());
        rev = rev + mavenMetadata.timestamp + "-" + mavenMetadata.buildNumber;
        return new TimestampedModuleSource(rev);
    }
    return null;
}
 
Example #2
Source File: ProjectDependencyPublicationResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;

}
 
Example #3
Source File: MavenHelper.java    From cyclonedx-gradle-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts a pom from an artifacts jar file and creates a MavenProject from it.
 * @param artifact the artifact to extract the pom from
 * @return a Maven project
 */
MavenProject extractPom(ResolvedArtifact artifact) {
    if (!isDescribedArtifact(artifact)) {
        return null;
    }
    if (artifact.getFile() != null) {
        try {
            final JarFile jarFile = new JarFile(artifact.getFile());
            final ModuleVersionIdentifier mid = artifact.getModuleVersion().getId();
            final JarEntry entry = jarFile.getJarEntry("META-INF/maven/"+ mid.getGroup() + "/" + mid.getName() + "/pom.xml");
            if (entry != null) {
                try (final InputStream input = jarFile.getInputStream(entry)) {
                    return readPom(input);
                }
            }
        } catch (IOException e) {
            logger.error("An error occurred attempting to extract POM from artifact", e);
        }
    }
    return null;
}
 
Example #4
Source File: CachingModuleVersionRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void getDependency(DependencyMetaData dependency, BuildableModuleVersionMetaDataResolveResult result) {
    DependencyMetaData forced = dependency.withChanging();
    delegate.getDependency(forced, result);
    switch (result.getState()) {
        case Missing:
            ModuleRevisionId dependencyRevisionId = dependency.getDescriptor().getDependencyRevisionId();
            ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(dependencyRevisionId);
            moduleMetaDataCache.cacheMissing(delegate, moduleVersionIdentifier);
            break;
        case Resolved:
            MutableModuleVersionMetaData metaData = result.getMetaData();
            ModuleSource moduleSource = result.getModuleSource();
            ModuleMetaDataCache.CachedMetaData cachedMetaData = moduleMetaDataCache.cacheMetaData(delegate, metaData, moduleSource);
            metadataProcessor.process(metaData);
            result.setModuleSource(new CachingModuleSource(cachedMetaData.getDescriptorHash(), dependency.isChanging() || metaData.isChanging(), moduleSource));
            break;
        case Failed:
            break;
        default:
            throw new IllegalStateException("Unexpected resolve state: " + result.getState());
    }
}
 
Example #5
Source File: StreamingResolutionResultBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void resolvedConfiguration(final ModuleVersionIdentifier from, final Collection<? extends InternalDependencyResult> dependencies) {
    if (!dependencies.isEmpty()) {
        store.write(new BinaryStore.WriteAction() {
            public void write(Encoder encoder) throws IOException {
                encoder.writeByte(DEPENDENCY);
                moduleVersionIdentifierSerializer.write(encoder, from);
                encoder.writeSmallInt(dependencies.size());
                for (InternalDependencyResult dependency : dependencies) {
                    internalDependencyResultSerializer.write(encoder, dependency);
                    if (dependency.getFailure() != null) {
                        //by keying the failures only be 'requested' we lose some precision
                        //at edge case we'll lose info about a different exception if we have different failure for the same requested version
                        failures.put(dependency.getRequested(), dependency.getFailure());
                    }
                }
            }
        });
    }
}
 
Example #6
Source File: ExternalResourceResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected MutableModuleVersionMetaData findMetaDataArtifact(DependencyMetaData dependency, ArtifactResolver artifactResolver) {
    ModuleVersionArtifactMetaData artifact = getMetaDataArtifactFor(dependency);
    if (artifact == null) {
        return null;
    }
    ExternalResource metaDataResource = artifactResolver.resolveMetaDataArtifact(artifact);
    if (metaDataResource == null) {
        return null;
    }
    MutableModuleVersionMetaData moduleVersionMetaData = getArtifactMetadata(artifact, metaDataResource);

    if (isCheckconsistency()) {
        ModuleVersionSelector requested = dependency.getRequested();
        ModuleVersionIdentifier requestedId = DefaultModuleVersionIdentifier.newId(requested.getGroup(), requested.getName(), requested.getVersion());
        checkMetadataConsistency(requestedId, moduleVersionMetaData);
    }
    return moduleVersionMetaData;
}
 
Example #7
Source File: InternalDependencyResultSerializer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public InternalDependencyResult read(Decoder decoder, Map<ComponentSelector, ModuleVersionResolveException> failures) throws IOException {
    ComponentSelector requested = componentSelectorSerializer.read(decoder);
    byte resultByte = decoder.readByte();
    if (resultByte == SUCCESSFUL) {
        ModuleVersionIdentifier selected = moduleVersionIdentifierSerializer.read(decoder);
        return new DefaultInternalDependencyResult(requested, selected, null, null);
    } else if (resultByte == FAILED) {
        ComponentSelectionReason reason = componentSelectionReasonSerializer.read(decoder);
        ModuleVersionResolveException failure = failures.get(requested);
        return new DefaultInternalDependencyResult(requested, null, reason, failure);
    } else {
        throw new IllegalArgumentException("Unknown result byte: " + resultByte);
    }
}
 
Example #8
Source File: MavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected ModuleVersionArtifactMetaData getMetaDataArtifactFor(ModuleVersionIdentifier moduleVersionIdentifier) {
    if (isUsepoms()) {
        DefaultModuleVersionArtifactIdentifier artifactId = new DefaultModuleVersionArtifactIdentifier(moduleVersionIdentifier, moduleVersionIdentifier.getName(), "pom", "pom");
        return new DefaultModuleVersionArtifactMetaData(artifactId);
    }

    return null;
}
 
Example #9
Source File: DefaultModuleArtifactsCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CachedArtifacts getCachedArtifacts(ModuleComponentRepository repository, ModuleVersionIdentifier moduleMetaDataId, String context) {
    ModuleArtifactsKey key = new ModuleArtifactsKey(repository.getId(), moduleMetaDataId, context);
    ModuleArtifactsCacheEntry entry = getCache().get(key);
    if (entry == null) {
        return null;
    }
    return createCacheArtifacts(entry);
}
 
Example #10
Source File: DefaultCachePolicy.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #11
Source File: DefaultResolvedDependency.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedModuleVersion getModule() {
    return new ResolvedModuleVersion() {
        public ModuleVersionIdentifier getId() {
            return id.getId();
        }
    };
}
 
Example #12
Source File: DefaultCachePolicy.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #13
Source File: DefaultCachePolicy.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #14
Source File: DependencyConvertUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static boolean isAwbDependency(DependencyResult dependencyResult,
                                      Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, Set<String>awbs) {
    if (dependencyResult instanceof ResolvedDependencyResult) {
        ResolvedDependencyResult resolvedDependencyResult = (ResolvedDependencyResult)dependencyResult;
        ModuleVersionIdentifier moduleVersionIdentifier = resolvedDependencyResult.getSelected().getModuleVersion();
        List<ResolvedArtifact> resolvedArtifacts = artifacts.get(moduleVersionIdentifier);

        if (resolvedArtifacts != null && resolvedArtifacts.size() > 0) {
            ResolvedArtifact resolvedArtifact = resolvedArtifacts.get(0);
            return ("awb".equals(resolvedArtifact.getType()) || awbs.contains(resolvedArtifact.getModuleVersion().getId().getGroup()+":"+resolvedArtifact.getModuleVersion().getId().getName()));
        }
    }
    return false;
}
 
Example #15
Source File: InternalDependencyResultSerializer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public InternalDependencyResult read(Decoder decoder, Map<ComponentSelector, ModuleVersionResolveException> failures) throws IOException {
    ComponentSelector requested = componentSelectorSerializer.read(decoder);
    byte resultByte = decoder.readByte();
    if (resultByte == SUCCESSFUL) {
        ModuleVersionIdentifier selected = moduleVersionIdentifierSerializer.read(decoder);
        return new DefaultInternalDependencyResult(requested, selected, null, null);
    } else if (resultByte == FAILED) {
        ComponentSelectionReason reason = componentSelectionReasonSerializer.read(decoder);
        ModuleVersionResolveException failure = failures.get(requested);
        return new DefaultInternalDependencyResult(requested, null, reason, failure);
    } else {
        throw new IllegalArgumentException("Unknown result byte: " + resultByte);
    }
}
 
Example #16
Source File: ExternalResourceResolverDescriptorParseContext.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private File resolveMetaDataArtifactFile(ModuleVersionIdentifier moduleVersionIdentifier, DependencyToComponentResolver dependencyResolver,
                                         ArtifactResolver artifactResolver, ArtifactType artifactType) {
    BuildableComponentResolveResult moduleVersionResolveResult = new DefaultBuildableComponentResolveResult();
    dependencyResolver.resolve(new DefaultDependencyMetaData(moduleVersionIdentifier), moduleVersionResolveResult);

    BuildableArtifactSetResolveResult moduleArtifactsResolveResult = new DefaultBuildableArtifactSetResolveResult();
    artifactResolver.resolveModuleArtifacts(moduleVersionResolveResult.getMetaData(), artifactType, moduleArtifactsResolveResult);

    BuildableArtifactResolveResult artifactResolveResult = new DefaultBuildableArtifactResolveResult();
    ComponentArtifactMetaData artifactMetaData = moduleArtifactsResolveResult.getArtifacts().iterator().next();
    artifactResolver.resolveArtifact(artifactMetaData, moduleVersionResolveResult.getMetaData().getSource(), artifactResolveResult);
    return artifactResolveResult.getFile();
}
 
Example #17
Source File: ModuleVersionResolveException.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a copy of this exception, with the given incoming paths.
 */
public ModuleVersionResolveException withIncomingPaths(Collection<? extends List<ModuleVersionIdentifier>> paths) {
    ModuleVersionResolveException copy = createCopy();
    copy.paths.addAll(paths);
    copy.initCauses(getCauses());
    copy.setStackTrace(getStackTrace());
    return copy;
}
 
Example #18
Source File: CachingModuleVersionRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void lookupModuleInCache(ModuleVersionRepository repository, DependencyMetaData dependency, BuildableModuleVersionMetaDataResolveResult result) {
    ModuleRevisionId resolvedModuleVersionId = dependency.getDescriptor().getDependencyRevisionId();
    ModuleVersionIdentifier moduleVersionIdentifier = newId(resolvedModuleVersionId);
    ModuleMetaDataCache.CachedMetaData cachedMetaData = moduleMetaDataCache.getCachedModuleDescriptor(repository, moduleVersionIdentifier);
    if (cachedMetaData == null) {
        return;
    }
    if (cachedMetaData.isMissing()) {
        if (cachePolicy.mustRefreshModule(moduleVersionIdentifier, null, resolvedModuleVersionId, cachedMetaData.getAgeMillis())) {
            LOGGER.debug("Cached meta-data for missing module is expired: will perform fresh resolve of '{}' in '{}'", resolvedModuleVersionId, repository.getName());
            return;
        }
        LOGGER.debug("Detected non-existence of module '{}' in resolver cache '{}'", resolvedModuleVersionId, repository.getName());
        if (cachedMetaData.getAgeMillis() == 0) {
            // Verified since the start of this build, assume still missing
            result.missing();
        } else {
            // Was missing last time we checked
            result.probablyMissing();
        }
        return;
    }
    MutableModuleVersionMetaData metaData = cachedMetaData.getMetaData();
    metadataProcessor.process(metaData);
    if (dependency.isChanging() || metaData.isChanging()) {
        if (cachePolicy.mustRefreshChangingModule(moduleVersionIdentifier, cachedMetaData.getModuleVersion(), cachedMetaData.getAgeMillis())) {
            LOGGER.debug("Cached meta-data for changing module is expired: will perform fresh resolve of '{}' in '{}'", resolvedModuleVersionId, repository.getName());
            return;
        }
        LOGGER.debug("Found cached version of changing module '{}' in '{}'", resolvedModuleVersionId, repository.getName());
    } else {
        if (cachePolicy.mustRefreshModule(moduleVersionIdentifier, cachedMetaData.getModuleVersion(), null, cachedMetaData.getAgeMillis())) {
            LOGGER.debug("Cached meta-data for module must be refreshed: will perform fresh resolve of '{}' in '{}'", resolvedModuleVersionId, repository.getName());
            return;
        }
    }

    LOGGER.debug("Using cached module metadata for module '{}' in '{}'", resolvedModuleVersionId, repository.getName());
    result.resolved(metaData, new CachingModuleSource(cachedMetaData.getDescriptorHash(), metaData.isChanging(), cachedMetaData.getModuleSource()));
}
 
Example #19
Source File: StreamingResolutionResultBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolutionResultBuilder start(final ModuleVersionIdentifier root, final ComponentIdentifier componentIdentifier) {
    store.write(new BinaryStore.WriteAction() {
        public void write(Encoder encoder) throws IOException {
            encoder.writeByte(ROOT);
            moduleVersionIdentifierSerializer.write(encoder, root);
            componentIdentifierSerializer.write(encoder, componentIdentifier);
        }
    });
    return this;
}
 
Example #20
Source File: DefaultArtifactIdentifier.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #21
Source File: DefaultBuildableComponentResolveResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionIdentifier getId() throws ModuleVersionResolveException {
    assertResolved();
    return metaData.getId();
}
 
Example #22
Source File: DefaultCachePolicy.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private CachedModuleResolutionControl(ModuleVersionIdentifier moduleVersionId, ResolvedModuleVersion cachedVersion, boolean changing, long ageMillis) {
    super(moduleVersionId, cachedVersion, ageMillis);
    this.changing = changing;
}
 
Example #23
Source File: ModuleDescriptorAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleDescriptorAdapter(ModuleVersionIdentifier identifier, ModuleDescriptor moduleDescriptor) {
    this(identifier, moduleDescriptor, DefaultModuleComponentIdentifier.newId(identifier));
}
 
Example #24
Source File: ComponentMetadataDetailsAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionIdentifier getId() {
    return metadata.getId();
}
 
Example #25
Source File: AbstractModuleDescriptorBackedMetaData.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public AbstractModuleDescriptorBackedMetaData(ModuleVersionIdentifier moduleVersionIdentifier, ModuleDescriptor moduleDescriptor, ComponentIdentifier componentIdentifier) {
    this.moduleVersionIdentifier = moduleVersionIdentifier;
    this.moduleDescriptor = moduleDescriptor;
    this.componentIdentifier = componentIdentifier;
    status = moduleDescriptor.getStatus();
}
 
Example #26
Source File: DefaultProjectPublication.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultProjectPublication(ModuleVersionIdentifier id) {
    this.id = id;
}
 
Example #27
Source File: LazyDependencyToModuleResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionIdentifier getId() throws ModuleVersionResolveException {
    return id;
}
 
Example #28
Source File: DefaultModuleVersionSelection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultModuleVersionSelection(ModuleVersionIdentifier id, ComponentSelectionReason reason, ComponentIdentifier componentIdentifier) {
    this.id = id;
    this.reason = reason;
    this.componentIdentifier = componentIdentifier;
}
 
Example #29
Source File: DefaultModuleVersionArtifactIdentifier.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultModuleVersionArtifactIdentifier(ModuleVersionIdentifier moduleVersionIdentifier, String name, String type, @Nullable String extension) {
    this(DefaultModuleComponentIdentifier.newId(moduleVersionIdentifier), name, type, extension, Collections.<String, String>emptyMap());
}
 
Example #30
Source File: ResolvedConfigurationDependencyGraphVisitor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void attachFailures(ResolvedConfigurationBuilder result) {
    for (Map.Entry<ModuleVersionSelector, BrokenDependency> entry : failuresByRevisionId.entrySet()) {
        Collection<List<ModuleVersionIdentifier>> paths = calculatePaths(entry.getValue());
        result.addUnresolvedDependency(new DefaultUnresolvedDependency(entry.getKey(), entry.getValue().failure.withIncomingPaths(paths)));
    }
}