org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier Java Examples

The following examples show how to use org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier. 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: MavenPlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
            ModuleInternal 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));
            }
        }
    });
}
 
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
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 #4
Source Project: pushfish-android   Author: PushFish   File: DependencyResolverIvyPublisher.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void publish(IvyNormalizedPublication publication, PublicationAwareRepository repository) {
    ModuleVersionPublisher publisher = repository.createPublisher();
    IvyPublicationIdentity projectIdentity = publication.getProjectIdentity();
    ModuleRevisionId moduleRevisionId = IvyUtil.createModuleRevisionId(projectIdentity.getOrganisation(), projectIdentity.getModule(), projectIdentity.getRevision());
    ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(moduleRevisionId);
    DefaultIvyModulePublishMetaData publishMetaData = new DefaultIvyModulePublishMetaData(moduleVersionIdentifier);

    try {
        for (IvyArtifact publishArtifact : publication.getArtifacts()) {
            Artifact ivyArtifact = createIvyArtifact(publishArtifact, moduleRevisionId);
            publishMetaData.addArtifact(ivyArtifact, publishArtifact.getFile());
        }

        Artifact artifact = DefaultArtifact.newIvyArtifact(moduleRevisionId, null);
        publishMetaData.addArtifact(artifact, publication.getDescriptorFile());

        publisher.publish(publishMetaData);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #5
Source Project: pushfish-android   Author: PushFish   File: BasePlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureUploadArchivesTask() {
    configurationActionContainer.add(new Action<Project>() {
        public void execute(Project project) {
            Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(UPLOAD_ARCHIVES_TASK_NAME);
            if (uploadArchives == null) { return; }

            boolean hasIvyRepo = !uploadArchives.getRepositories().withType(IvyArtifactRepository.class).isEmpty();
            if (!hasIvyRepo) { return; } // Maven repos are handled by MavenPlugin

            ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration();
            ModuleInternal module = configuration.getModule();
            ModuleVersionIdentifier publicationId =
                    new DefaultModuleVersionIdentifier(module.getGroup(), module.getName(), module.getVersion());
            publicationRegistry.registerPublication(module.getProjectPath(), new DefaultProjectPublication(publicationId));
        }
    });
}
 
Example #6
Source Project: pushfish-android   Author: PushFish   File: MavenPlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
            ModuleInternal 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));
            }
        }
    });
}
 
Example #7
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 #8
Source Project: pushfish-android   Author: PushFish   File: CachingModuleVersionRepository.java    License: 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 #9
Source Project: pushfish-android   Author: PushFish   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 #10
Source Project: pushfish-android   Author: PushFish   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 #11
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 #12
Source Project: pushfish-android   Author: PushFish   File: DependencyResolverIvyPublisher.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void publish(IvyNormalizedPublication publication, PublicationAwareRepository repository) {
    ModuleVersionPublisher publisher = repository.createPublisher();
    IvyPublicationIdentity projectIdentity = publication.getProjectIdentity();
    ModuleRevisionId moduleRevisionId = IvyUtil.createModuleRevisionId(projectIdentity.getOrganisation(), projectIdentity.getModule(), projectIdentity.getRevision());
    ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(moduleRevisionId);
    DefaultModuleVersionPublishMetaData publishMetaData = new DefaultModuleVersionPublishMetaData(moduleVersionIdentifier);

    try {
        for (IvyArtifact publishArtifact : publication.getArtifacts()) {
            Artifact ivyArtifact = createIvyArtifact(publishArtifact, moduleRevisionId);
            publishMetaData.addArtifact(ivyArtifact, publishArtifact.getFile());
        }

        Artifact artifact = DefaultArtifact.newIvyArtifact(moduleRevisionId, null);
        publishMetaData.addArtifact(artifact, publication.getDescriptorFile());

        publisher.publish(publishMetaData);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #13
Source Project: pushfish-android   Author: PushFish   File: BasePlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureUploadArchivesTask() {
    configurationActionContainer.add(new Action<Project>() {
        public void execute(Project project) {
            Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(UPLOAD_ARCHIVES_TASK_NAME);
            if (uploadArchives == null) { return; }

            boolean hasIvyRepo = !uploadArchives.getRepositories().withType(IvyArtifactRepository.class).isEmpty();
            if (!hasIvyRepo) { return; } // Maven repos are handled by MavenPlugin

            ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration();
            ModuleInternal module = configuration.getModule();
            ModuleVersionIdentifier publicationId =
                    new DefaultModuleVersionIdentifier(module.getGroup(), module.getName(), module.getVersion());
            publicationRegistry.registerPublication(module.getProjectPath(), new DefaultProjectPublication(publicationId));
        }
    });
}
 
Example #14
Source Project: javaide   Author: tranleduy2000   File: BasePlugin.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void configureUploadArchivesTask() {
    configurationActionContainer.add(new Action<Project>() {
        public void execute(Project project) {
            Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(UPLOAD_ARCHIVES_TASK_NAME);
            if (uploadArchives == null) {
                return;
            }

            boolean hasIvyRepo = !uploadArchives.getRepositories().withType(IvyArtifactRepository.class).isEmpty();
            if (!hasIvyRepo) {
                return;
            } // Maven repos are handled by MavenPlugin

            ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration();
            Module module = configuration.getModule();
            ModuleVersionIdentifier publicationId =
                    new DefaultModuleVersionIdentifier(module.getGroup(), module.getName(), module.getVersion());
            publicationRegistry.registerPublication(module.getProjectPath(), new DefaultProjectPublication(publicationId));
        }
    });
}
 
Example #15
Source Project: Pushjet-Android   Author: Pushjet   File: MavenPlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
            ModuleInternal 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));
            }
        }
    });
}
 
Example #16
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 #17
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 #18
Source Project: Pushjet-Android   Author: Pushjet   File: DependencyResolverIvyPublisher.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void publish(IvyNormalizedPublication publication, PublicationAwareRepository repository) {
    ModuleVersionPublisher publisher = repository.createPublisher();
    IvyPublicationIdentity projectIdentity = publication.getProjectIdentity();
    ModuleRevisionId moduleRevisionId = IvyUtil.createModuleRevisionId(projectIdentity.getOrganisation(), projectIdentity.getModule(), projectIdentity.getRevision());
    ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(moduleRevisionId);
    DefaultIvyModulePublishMetaData publishMetaData = new DefaultIvyModulePublishMetaData(moduleVersionIdentifier);

    try {
        for (IvyArtifact publishArtifact : publication.getArtifacts()) {
            Artifact ivyArtifact = createIvyArtifact(publishArtifact, moduleRevisionId);
            publishMetaData.addArtifact(ivyArtifact, publishArtifact.getFile());
        }

        Artifact artifact = DefaultArtifact.newIvyArtifact(moduleRevisionId, null);
        publishMetaData.addArtifact(artifact, publication.getDescriptorFile());

        publisher.publish(publishMetaData);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #19
Source Project: Pushjet-Android   Author: Pushjet   File: BasePlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureUploadArchivesTask() {
    configurationActionContainer.add(new Action<Project>() {
        public void execute(Project project) {
            Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(UPLOAD_ARCHIVES_TASK_NAME);
            if (uploadArchives == null) { return; }

            boolean hasIvyRepo = !uploadArchives.getRepositories().withType(IvyArtifactRepository.class).isEmpty();
            if (!hasIvyRepo) { return; } // Maven repos are handled by MavenPlugin

            ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration();
            ModuleInternal module = configuration.getModule();
            ModuleVersionIdentifier publicationId =
                    new DefaultModuleVersionIdentifier(module.getGroup(), module.getName(), module.getVersion());
            publicationRegistry.registerPublication(module.getProjectPath(), new DefaultProjectPublication(publicationId));
        }
    });
}
 
Example #20
Source Project: Pushjet-Android   Author: Pushjet   File: MavenPlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
            ModuleInternal 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));
            }
        }
    });
}
 
Example #21
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 #22
Source Project: Pushjet-Android   Author: Pushjet   File: CachingModuleVersionRepository.java    License: 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 #23
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 #24
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 #25
Source Project: Pushjet-Android   Author: Pushjet   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 #26
Source Project: Pushjet-Android   Author: Pushjet   File: DependencyResolverIvyPublisher.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void publish(IvyNormalizedPublication publication, PublicationAwareRepository repository) {
    ModuleVersionPublisher publisher = repository.createPublisher();
    IvyPublicationIdentity projectIdentity = publication.getProjectIdentity();
    ModuleRevisionId moduleRevisionId = IvyUtil.createModuleRevisionId(projectIdentity.getOrganisation(), projectIdentity.getModule(), projectIdentity.getRevision());
    ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(moduleRevisionId);
    DefaultModuleVersionPublishMetaData publishMetaData = new DefaultModuleVersionPublishMetaData(moduleVersionIdentifier);

    try {
        for (IvyArtifact publishArtifact : publication.getArtifacts()) {
            Artifact ivyArtifact = createIvyArtifact(publishArtifact, moduleRevisionId);
            publishMetaData.addArtifact(ivyArtifact, publishArtifact.getFile());
        }

        Artifact artifact = DefaultArtifact.newIvyArtifact(moduleRevisionId, null);
        publishMetaData.addArtifact(artifact, publication.getDescriptorFile());

        publisher.publish(publishMetaData);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #27
Source Project: Pushjet-Android   Author: Pushjet   File: BasePlugin.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureUploadArchivesTask() {
    configurationActionContainer.add(new Action<Project>() {
        public void execute(Project project) {
            Upload uploadArchives = project.getTasks().withType(Upload.class).findByName(UPLOAD_ARCHIVES_TASK_NAME);
            if (uploadArchives == null) { return; }

            boolean hasIvyRepo = !uploadArchives.getRepositories().withType(IvyArtifactRepository.class).isEmpty();
            if (!hasIvyRepo) { return; } // Maven repos are handled by MavenPlugin

            ConfigurationInternal configuration = (ConfigurationInternal) uploadArchives.getConfiguration();
            ModuleInternal module = configuration.getModule();
            ModuleVersionIdentifier publicationId =
                    new DefaultModuleVersionIdentifier(module.getGroup(), module.getName(), module.getVersion());
            publicationRegistry.registerPublication(module.getProjectPath(), new DefaultProjectPublication(publicationId));
        }
    });
}
 
Example #28
public void resolve(DependencyMetaData dependency, BuildableComponentResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    LOGGER.debug("Attempting to resolve {} using repositories {}", requested, repositoryNames);
    ModuleComponentIdentifier moduleComponentIdentifier = new DefaultModuleComponentIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());
    ModuleVersionIdentifier moduleVersionIdentifier = new DefaultModuleVersionIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());

    List<Throwable> errors = new ArrayList<Throwable>();

    List<ComponentMetaDataResolveState> resolveStates = new ArrayList<ComponentMetaDataResolveState>();
    for (ModuleComponentRepository repository : repositories) {
        resolveStates.add(new ComponentMetaDataResolveState(dependency, moduleComponentIdentifier, repository, componentChooser));
    }

    final RepositoryChainModuleResolution latestResolved = findBestMatch(resolveStates, errors);
    if (latestResolved != null) {
        LOGGER.debug("Using {} from {}", latestResolved.module.getId(), latestResolved.repository);
        for (Throwable error : errors) {
            LOGGER.debug("Discarding resolve failure.", error);
        }

        result.resolved(metaDataFactory.transform(latestResolved));
        return;
    }
    if (!errors.isEmpty()) {
        result.failed(new ModuleVersionResolveException(moduleComponentIdentifier, errors));
    } else {
        for (ComponentMetaDataResolveState resolveState : resolveStates) {
            resolveState.applyTo(result);
        }
        result.notFound(moduleVersionIdentifier);
    }
}
 
Example #29
Source Project: pushfish-android   Author: PushFish   File: RepositoryChainAdapter.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void resolve(DependencyMetaData dependency, BuildableComponentIdResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    if (versionMatcher.isDynamic(requested.getVersion())) {
        dynamicRevisionResolver.resolve(dependency, result);
    } else {
        DefaultModuleComponentIdentifier id = new DefaultModuleComponentIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());
        DefaultModuleVersionIdentifier mvId = new DefaultModuleVersionIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());
        result.resolved(id, mvId);
    }
}
 
Example #30
public void resolve(ConfigurationInternal configuration,
                    List<? extends ResolutionAwareRepository> repositories,
                    GlobalDependencyResolutionRules metadataHandler,
                    ResolverResults results) throws ResolveException {
    if (configuration.getAllDependencies().isEmpty()) {
        ModuleVersionIdentifier id = DefaultModuleVersionIdentifier.newId(configuration.getModule());
        ComponentIdentifier componentIdentifier = componentIdentifierFactory.createComponentIdentifier(configuration.getModule());
        ResolutionResult emptyResult = new DefaultResolutionResultBuilder().start(id, componentIdentifier).complete();
        results.resolved(new EmptyResolvedConfiguration(), emptyResult);
    } else {
        dependencyResolver.resolve(configuration, repositories, metadataHandler, results);
    }
}