org.gradle.api.artifacts.ModuleIdentifier Java Examples

The following examples show how to use org.gradle.api.artifacts.ModuleIdentifier. 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: CachingModuleVersionRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void localListModuleVersions(DependencyMetaData dependency, BuildableModuleVersionSelectionResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    final ModuleIdentifier moduleId = moduleExtractor.transform(requested);
    ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId);
    if (cachedModuleVersionList != null) {
        ModuleVersionListing versionList = cachedModuleVersionList.getModuleVersions();
        Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList.getVersions(), new Transformer<ModuleVersionIdentifier, Versioned>() {
            public ModuleVersionIdentifier transform(Versioned original) {
                return new DefaultModuleVersionIdentifier(moduleId, original.getVersion());
            }
        });
        if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) {
            LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName());
        } else {
            if (cachedModuleVersionList.getAgeMillis() == 0) {
                // Verified since the start of this build, assume still missing
                result.listed(versionList);
            } else {
                // Was missing last time we checked
                result.probablyListed(versionList);
            }
        }
    }
}
 
Example #2
Source File: CachingModuleComponentRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void listModuleVersionsFromCache(DependencyMetaData dependency, BuildableModuleComponentVersionSelectionResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    final ModuleIdentifier moduleId = getCacheKey(requested);
    ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId);
    if (cachedModuleVersionList != null) {
        ModuleVersionListing versionList = cachedModuleVersionList.getModuleVersions();
        Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList.getVersions(), new Transformer<ModuleVersionIdentifier, Versioned>() {
            public ModuleVersionIdentifier transform(Versioned original) {
                return new DefaultModuleVersionIdentifier(moduleId, original.getVersion());
            }
        });
        if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) {
            LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName());
        } else {
            result.listed(versionList);
            // When age == 0, verified since the start of this build, assume listing hasn't changed
            result.setAuthoritative(cachedModuleVersionList.getAgeMillis() == 0);
        }
    }
}
 
Example #3
Source File: ExternalResourceResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void listModuleVersions(DependencyMetaData dependency, BuildableModuleVersionSelectionResolveResult result) {
    ModuleIdentifier module  = new DefaultModuleIdentifier(dependency.getRequested().getGroup(), dependency.getRequested().getName());
    VersionList versionList = versionLister.getVersionList(module);
    // List modules based on metadata files
    ModuleVersionArtifactMetaData metaDataArtifact = getMetaDataArtifactFor(dependency);
    listVersionsForAllPatterns(getIvyPatterns(), metaDataArtifact, versionList);

    // List modules with missing metadata files
    if (isAllownomd()) {
        for (ModuleVersionArtifactMetaData otherArtifact : getDefaultMetaData(dependency).getArtifacts()) {
            listVersionsForAllPatterns(getArtifactPatterns(), otherArtifact, versionList);
        }
    }
    DefaultModuleVersionListing moduleVersions = new DefaultModuleVersionListing();
    for (VersionList.ListedVersion listedVersion : versionList.getVersions()) {
        moduleVersions.add(listedVersion.getVersion());
    }
    result.listed(moduleVersions);
}
 
Example #4
Source File: MavenVersionLister.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public VersionPatternVisitor newVisitor(final ModuleIdentifier module, final Collection<String> dest, final ResourceAwareResolveResult result) {
    return new VersionPatternVisitor() {
        final Set<ExternalResourceName> searched = new HashSet<ExternalResourceName>();

        public void visit(ResourcePattern pattern, IvyArtifactName artifact) throws ResourceException {
            ExternalResourceName metadataLocation = pattern.toModulePath(module).resolve("maven-metadata.xml");
            if (!searched.add(metadataLocation)) {
                return;
            }
            result.attempted(metadataLocation);
            MavenMetadata mavenMetaData = mavenMetadataLoader.load(metadataLocation.getUri());
            for (String version : mavenMetaData.versions) {
                dest.add(version);
            }
        }
    };
}
 
Example #5
Source File: MavenVersionLister.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public VersionList getVersionList(final ModuleIdentifier module) {
    return new DefaultVersionList() {
        final Set<String> searched = new HashSet<String>();

        public void visit(ResourcePattern resourcePattern, ModuleVersionArtifactMetaData artifact) throws ResourceException {
            String metadataLocation = resourcePattern.toModulePath(module) + "/maven-metadata.xml";
            if (!searched.add(metadataLocation)) {
                return;
            }
            MavenMetadata mavenMetaData = mavenMetadataLoader.load(metadataLocation);
            for (String version : mavenMetaData.versions) {
                add(new ListedVersion(version, resourcePattern));
            }
        }
    };
}
 
Example #6
Source File: MavenVersionLister.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public VersionPatternVisitor newVisitor(final ModuleIdentifier module, final Collection<String> dest, final ResourceAwareResolveResult result) {
    return new VersionPatternVisitor() {
        final Set<ExternalResourceName> searched = new HashSet<ExternalResourceName>();

        public void visit(ResourcePattern pattern, IvyArtifactName artifact) throws ResourceException {
            ExternalResourceName metadataLocation = pattern.toModulePath(module).resolve("maven-metadata.xml");
            if (!searched.add(metadataLocation)) {
                return;
            }
            result.attempted(metadataLocation);
            MavenMetadata mavenMetaData = mavenMetadataLoader.load(metadataLocation.getUri());
            for (String version : mavenMetaData.versions) {
                dest.add(version);
            }
        }
    };
}
 
Example #7
Source File: CachingModuleComponentRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void listModuleVersionsFromCache(DependencyMetaData dependency, BuildableModuleComponentVersionSelectionResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    final ModuleIdentifier moduleId = getCacheKey(requested);
    ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId);
    if (cachedModuleVersionList != null) {
        ModuleVersionListing versionList = cachedModuleVersionList.getModuleVersions();
        Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList.getVersions(), new Transformer<ModuleVersionIdentifier, Versioned>() {
            public ModuleVersionIdentifier transform(Versioned original) {
                return new DefaultModuleVersionIdentifier(moduleId, original.getVersion());
            }
        });
        if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) {
            LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName());
        } else {
            result.listed(versionList);
            // When age == 0, verified since the start of this build, assume listing hasn't changed
            result.setAuthoritative(cachedModuleVersionList.getAgeMillis() == 0);
        }
    }
}
 
Example #8
Source File: ComponentModuleMetadataContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ComponentModuleMetadataDetails module(final Object sourceModule) {
    final NotationParser<Object, ModuleIdentifier> parser = parser();
    final ModuleIdentifier source = parser.parseNotation(sourceModule);
    return new ComponentModuleMetadataDetails() {
        public void replacedBy(final Object targetModule) {
            ModuleIdentifier target = parser.parseNotation(targetModule);
            detectCycles(replacements, source, target);
            replacements.put(source, target);
        }

        public ModuleIdentifier getId() {
            return source;
        }

        public ModuleIdentifier getReplacedBy() {
            return replacements.get(source);
        }
    };
}
 
Example #9
Source File: ComponentModuleMetadataContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static void detectCycles(Map<ModuleIdentifier, ModuleIdentifier> replacements, ModuleIdentifier source, ModuleIdentifier target) {
    if (source.equals(target)) {
        throw new InvalidUserDataException(String.format("Cannot declare module replacement that replaces self: %s->%s", source, target));
    }

    ModuleIdentifier m = replacements.get(target);
    if (m == null) {
        //target does not exist in the map, there's no cycle for sure
        return;
    }
    Set<ModuleIdentifier> visited = new LinkedHashSet<ModuleIdentifier>();
    visited.add(source);
    visited.add(target);

    while(m != null) {
        if (!visited.add(m)) {
            //module was already visited, there is a cycle
            throw new InvalidUserDataException(
                    format("Cannot declare module replacement %s->%s because it introduces a cycle: %s",
                            source, target, Joiner.on("->").join(visited) + "->" + source));
        }
        m = replacements.get(m);
    }
}
 
Example #10
Source File: PotentialConflictFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static PotentialConflict potentialConflict(final ConflictContainer<ModuleIdentifier, ? extends ModuleRevisionResolveState>.Conflict conflict) {
    return new PotentialConflict() {
        public boolean conflictExists() {
            return conflict != null;
        }

        public void withParticipatingModules(Action<ModuleIdentifier> action) {
            assert conflictExists();
            for (ModuleIdentifier participant : conflict.participants) {
                action.execute(participant);
            }
        }
    };
}
 
Example #11
Source File: ModuleForcingResolveRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(DependencyResolveDetailsInternal details) {
    if (forcedModules == null) {
        return;
    }
    ModuleIdentifier key = new DefaultModuleIdentifier(details.getRequested().getGroup(), details.getRequested().getName());
    if (forcedModules.containsKey(key)) {
        details.useVersion(forcedModules.get(key), VersionSelectionReasons.FORCED);
    }
}
 
Example #12
Source File: M2ResourcePattern.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public String toModulePath(ModuleIdentifier module) {
    String pattern = getPattern();
    if (!pattern.endsWith(MavenPattern.M2_PATTERN)) {
        throw new UnsupportedOperationException("Cannot locate module for non-maven layout.");
    }
    String metaDataPattern = pattern.substring(0, pattern.length() - MavenPattern.M2_PER_MODULE_PATTERN.length() - 1);
    return IvyPatternHelper.substituteTokens(metaDataPattern, toAttributes(module));
}
 
Example #13
Source File: ExternalResourceResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void doListModuleVersions(DependencyMetaData dependency, BuildableModuleComponentVersionSelectionResolveResult result) {
    ModuleIdentifier module  = new DefaultModuleIdentifier(dependency.getRequested().getGroup(), dependency.getRequested().getName());
    Set<String> versions = new LinkedHashSet<String>();
    VersionPatternVisitor visitor = versionLister.newVisitor(module, versions, result);

    // List modules based on metadata files (artifact version is not considered in listVersionsForAllPatterns())
    IvyArtifactName metaDataArtifact = getMetaDataArtifactName(dependency.getRequested().getName());
    listVersionsForAllPatterns(ivyPatterns, metaDataArtifact, visitor);

    // List modules with missing metadata files
    for (IvyArtifactName otherArtifact : getDependencyArtifactNames(dependency)) {
        listVersionsForAllPatterns(artifactPatterns, otherArtifact, visitor);
    }
    result.listed(versions);
}
 
Example #14
Source File: CachingModuleComponentRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void listModuleVersions(DependencyMetaData dependency, BuildableModuleComponentVersionSelectionResolveResult result) {
    delegate.getRemoteAccess().listModuleVersions(dependency, result);
    switch (result.getState()) {
        case Listed:
            ModuleIdentifier moduleId = getCacheKey(dependency.getRequested());
            ModuleVersionListing versionList = result.getVersions();
            moduleVersionsCache.cacheModuleVersionList(delegate, moduleId, versionList);
            break;
        case Failed:
            break;
        default:
            throw new IllegalStateException("Unexpected state on listModuleVersions: " + result.getState());
    }
}
 
Example #15
Source File: CachingModuleComponentRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void listModuleVersions(DependencyMetaData dependency, BuildableModuleComponentVersionSelectionResolveResult result) {
    delegate.getRemoteAccess().listModuleVersions(dependency, result);
    switch (result.getState()) {
        case Listed:
            ModuleIdentifier moduleId = getCacheKey(dependency.getRequested());
            ModuleVersionListing versionList = result.getVersions();
            moduleVersionsCache.cacheModuleVersionList(delegate, moduleId, versionList);
            break;
        case Failed:
            break;
        default:
            throw new IllegalStateException("Unexpected state on listModuleVersions: " + result.getState());
    }
}
 
Example #16
Source File: SingleFileBackedModuleVersionsCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CachedModuleVersionList getCachedModuleResolution(ModuleVersionRepository repository, ModuleIdentifier moduleId) {
    ModuleVersionsCacheEntry moduleVersionsCacheEntry = getCache().get(createKey(repository, moduleId));
    if (moduleVersionsCacheEntry == null) {
        return null;
    }
    return new DefaultCachedModuleVersionList(moduleVersionsCacheEntry, timeProvider);
}
 
Example #17
Source File: ModuleForcingResolveRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(DependencyResolveDetailsInternal details) {
    if (forcedModules == null) {
        return;
    }
    ModuleIdentifier key = new DefaultModuleIdentifier(details.getRequested().getGroup(), details.getRequested().getName());
    if (forcedModules.containsKey(key)) {
        details.useVersion(forcedModules.get(key), VersionSelectionReasons.FORCED);
    }
}
 
Example #18
Source File: PotentialConflictFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static PotentialConflict potentialConflict(final ConflictContainer<ModuleIdentifier, ? extends ModuleRevisionResolveState>.Conflict conflict) {
    return new PotentialConflict() {
        public boolean conflictExists() {
            return conflict != null;
        }

        public void withParticipatingModules(Action<ModuleIdentifier> action) {
            assert conflictExists();
            for (ModuleIdentifier participant : conflict.participants) {
                action.execute(participant);
            }
        }
    };
}
 
Example #19
Source File: CachingModuleVersionRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CachingModuleVersionRepository(LocalArtifactsModuleVersionRepository delegate, ModuleVersionsCache moduleVersionsCache, ModuleMetaDataCache moduleMetaDataCache,
                                      ModuleArtifactsCache moduleArtifactsCache, CachedArtifactIndex artifactAtRepositoryCachedResolutionIndex,
                                      CachePolicy cachePolicy, BuildCommencedTimeProvider timeProvider,
                                      ModuleMetadataProcessor metadataProcessor, Transformer<ModuleIdentifier, ModuleVersionSelector> moduleExtractor) {
    this.delegate = delegate;
    this.moduleMetaDataCache = moduleMetaDataCache;
    this.moduleVersionsCache = moduleVersionsCache;
    this.moduleArtifactsCache = moduleArtifactsCache;
    this.artifactAtRepositoryCachedResolutionIndex = artifactAtRepositoryCachedResolutionIndex;
    this.timeProvider = timeProvider;
    this.cachePolicy = cachePolicy;
    this.metadataProcessor = metadataProcessor;
    this.moduleExtractor = moduleExtractor;
}
 
Example #20
Source File: ModuleForcingResolveRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ModuleForcingResolveRule(Collection<? extends ModuleVersionSelector> forcedModules) {
    if (!forcedModules.isEmpty()) {
        this.forcedModules = new HashMap<ModuleIdentifier, String>();
        for (ModuleVersionSelector module : forcedModules) {
            this.forcedModules.put(new DefaultModuleIdentifier(module.getGroup(), module.getName()), module.getVersion());
        }
    } else {
        this.forcedModules = null;
    }
}
 
Example #21
Source File: SingleFileBackedModuleVersionsCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CachedModuleVersionList getCachedModuleResolution(ModuleComponentRepository repository, ModuleIdentifier moduleId) {
    ModuleVersionsCacheEntry moduleVersionsCacheEntry = getCache().get(createKey(repository, moduleId));
    if (moduleVersionsCacheEntry == null) {
        return null;
    }
    return new DefaultCachedModuleVersionList(moduleVersionsCacheEntry, timeProvider);
}
 
Example #22
Source File: SingleFileBackedModuleVersionsCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CachedModuleVersionList getCachedModuleResolution(ModuleVersionRepository repository, ModuleIdentifier moduleId) {
    ModuleVersionsCacheEntry moduleVersionsCacheEntry = getCache().get(createKey(repository, moduleId));
    if (moduleVersionsCacheEntry == null) {
        return null;
    }
    return new DefaultCachedModuleVersionList(moduleVersionsCacheEntry, timeProvider);
}
 
Example #23
Source File: DefaultComponentSelectionRules.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private SpecRuleAction<? super ComponentSelection> createSpecRuleActionFromId(Object id, RuleAction<? super ComponentSelection> ruleAction) {
    final ModuleIdentifier moduleIdentifier;

    try {
        moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id);
    } catch (UnsupportedNotationException e) {
        throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e);
    }

    Spec<ComponentSelection> spec = new ComponentSelectionMatchingSpec(moduleIdentifier);
    return new SpecRuleAction<ComponentSelection>(ruleAction, spec);
}
 
Example #24
Source File: DefaultCachePolicy.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #25
Source File: ModuleForcingResolveRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ModuleForcingResolveRule(Collection<? extends ModuleVersionSelector> forcedModules) {
    if (!forcedModules.isEmpty()) {
        this.forcedModules = new HashMap<ModuleIdentifier, String>();
        for (ModuleVersionSelector module : forcedModules) {
            this.forcedModules.put(new DefaultModuleIdentifier(module.getGroup(), module.getName()), module.getVersion());
        }
    } else {
        this.forcedModules = null;
    }
}
 
Example #26
Source File: ModuleForcingResolveRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(DependencyResolveDetailsInternal details) {
    if (forcedModules == null) {
        return;
    }
    ModuleIdentifier key = new DefaultModuleIdentifier(details.getRequested().getGroup(), details.getRequested().getName());
    if (forcedModules.containsKey(key)) {
        details.useVersion(forcedModules.get(key), VersionSelectionReasons.FORCED);
    }
}
 
Example #27
Source File: ResolveIvyFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Transformer<ModuleIdentifier, ModuleVersionSelector> getModuleExtractor(ConfiguredModuleVersionRepository rootRepository) {
    // If the backing repository is a custom ivy resolver, then we don't get a full listing
    if (rootRepository instanceof IvyAwareModuleVersionRepository) {
        return new LegacyIvyResolverModuleIdExtractor();
    }
    return new DefaultModuleIdExtractor();
}
 
Example #28
Source File: ApDependency.java    From atlas with Apache License 2.0 5 votes vote down vote up
private Map<ModuleIdentifier, String> getAwbDependencies(String awb) {
    ParsedModuleStringNotation parsedNotation = new ParsedModuleStringNotation(awb,"awb");
    String group = parsedNotation.getGroup();
    String name = parsedNotation.getName();
    ModuleIdentifier moduleIdentifier = DefaultModuleIdentifier.newId(group, name);
    Map<ModuleIdentifier, String> awbDependencies = mAwbDependenciesMap.get(moduleIdentifier);
    if (awbDependencies == null) {
        awbDependencies = Maps.newHashMap();
        mAwbDependenciesMap.put(moduleIdentifier, awbDependencies);
    }
    return awbDependencies;
}
 
Example #29
Source File: CachingModuleVersionRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void listModuleVersions(DependencyMetaData dependency, BuildableModuleVersionSelectionResolveResult result) {
    delegate.listModuleVersions(dependency, result);
    switch (result.getState()) {
        case Listed:
            ModuleIdentifier moduleId = moduleExtractor.transform(dependency.getRequested());
            ModuleVersionListing versionList = result.getVersions();
            moduleVersionsCache.cacheModuleVersionList(delegate, moduleId, versionList);
            break;
        case Failed:
            break;
        default:
            throw new IllegalStateException("Unexpected state on listModuleVersions: " + result.getState());
    }
}
 
Example #30
Source File: ComponentModuleMetadataContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static NotationParser<Object, ModuleIdentifier> parser() {
    return NotationParserBuilder
            .toType(ModuleIdentifier.class)
            .parser(new ModuleIdentiferNotationParser())
            .toComposite();
}