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 Project: pushfish-android   Author: PushFish   File: MavenResolver.java    License: 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
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 Project: Pushjet-Android   Author: Pushjet   File: CachingModuleVersionRepository.java    License: 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 #4
Source Project: cyclonedx-gradle-plugin   Author: CycloneDX   File: MavenHelper.java    License: 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 #5
Source Project: Pushjet-Android   Author: Pushjet   File: ExternalResourceResolver.java    License: 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 #6
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 #7
Source Project: pushfish-android   Author: PushFish   File: DefaultCachePolicy.java    License: 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 #8
Source Project: atlas   Author: alibaba   File: DependencyConvertUtils.java    License: 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 #9
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 #10
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 #11
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultArtifactIdentifier.java    License: 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 #12
Source Project: Pushjet-Android   Author: Pushjet   File: CachingModuleVersionRepository.java    License: 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 #13
Source Project: Pushjet-Android   Author: Pushjet   File: ModuleVersionResolveException.java    License: 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 #14
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 #15
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 Project: Pushjet-Android   Author: Pushjet   File: DefaultCachePolicy.java    License: 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 #17
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultModuleArtifactsCache.java    License: 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 #18
Source Project: pushfish-android   Author: PushFish   File: DefaultResolvedDependency.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedModuleVersion getModule() {
    return new ResolvedModuleVersion() {
        public ModuleVersionIdentifier getId() {
            return id.getId();
        }
    };
}
 
Example #19
Source Project: Pushjet-Android   Author: Pushjet   File: MavenResolver.java    License: 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 #20
Source Project: pushfish-android   Author: PushFish   File: DefaultCachePolicy.java    License: 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 #21
public AbstractModuleDescriptorBackedMetaData(ModuleVersionIdentifier moduleVersionIdentifier, ModuleDescriptor moduleDescriptor, ComponentIdentifier componentIdentifier) {
    this.moduleVersionIdentifier = moduleVersionIdentifier;
    this.moduleDescriptor = moduleDescriptor;
    this.componentIdentifier = componentIdentifier;
    status = moduleDescriptor.getStatus();
}
 
Example #22
Source Project: pushfish-android   Author: PushFish   File: DefaultMavenPublication.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionIdentifier getCoordinates() {
    return new DefaultModuleVersionIdentifier(getGroupId(), getArtifactId(), getVersion());
}
 
Example #23
Source Project: Pushjet-Android   Author: Pushjet   File: InternalDependencyResult.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Nullable
ModuleVersionIdentifier getSelected();
 
Example #24
public DefaultModuleVersionArtifactIdentifier(ModuleVersionIdentifier moduleVersionIdentifier, String name, String type, @Nullable String extension) {
    this(DefaultModuleComponentIdentifier.newId(moduleVersionIdentifier), name, type, extension, Collections.<String, String>emptyMap());
}
 
Example #25
public ModuleVersionIdentifier read(Decoder decoder) throws IOException {
    String group = decoder.readString();
    String module = decoder.readString();
    String version = decoder.readString();
    return DefaultModuleVersionIdentifier.newId(group, module, version);
}
 
Example #26
public ModuleVersionSelection read(Decoder decoder) throws IOException {
    ModuleVersionIdentifier id = idSerializer.read(decoder);
    ComponentSelectionReason reason = reasonSerializer.read(decoder);
    ComponentIdentifier componentId = componentIdSerializer.read(decoder);
    return new DefaultModuleVersionSelection(id, reason, componentId);
}
 
Example #27
Source Project: pushfish-android   Author: PushFish   File: IvyUtil.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ModuleRevisionId createModuleRevisionId(ModuleVersionIdentifier id) {
    return createModuleRevisionId(id.getGroup(), id.getName(), id.getVersion());
}
 
Example #28
Source Project: pushfish-android   Author: PushFish   File: ModuleVersionNotFoundException.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ModuleVersionNotFoundException(ModuleVersionIdentifier id) {
    super(id, "Could not find %s.");
}
 
Example #29
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultCachePolicy.java    License: 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 #30
public AbstractModuleComponentResolveMetaData(ModuleVersionIdentifier moduleVersionIdentifier, ModuleDescriptor moduleDescriptor, ModuleComponentIdentifier componentIdentifier) {
    super(moduleVersionIdentifier, moduleDescriptor, componentIdentifier);
}