Search in sources :

Example 1 with FilteringZipDependencySelector

use of com.google.cloud.tools.opensource.dependencies.FilteringZipDependencySelector in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageCheckerRule method findProjectClasspath.

/**
 * Builds a class path for {@code mavenProject}.
 */
private static ClassPathResult findProjectClasspath(MavenProject mavenProject, RepositorySystemSession session, EnforcerRuleHelper helper) throws EnforcerRuleException {
    try {
        ProjectDependenciesResolver projectDependenciesResolver = helper.getComponent(ProjectDependenciesResolver.class);
        DefaultRepositorySystemSession fullDependencyResolutionSession = new DefaultRepositorySystemSession(session);
        // Clear artifact cache. Certain artifacts in the cache have dependencies without
        // ${os.detected.classifier} interpolated. They are instantiated before 'verify' phase:
        // https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/925
        fullDependencyResolutionSession.setCache(new DefaultRepositoryCache());
        // For netty-handler referencing its dependencies with ${os.detected.classifier}
        // allowing duplicate entries
        Map<String, String> properties = new HashMap<>();
        properties.putAll(fullDependencyResolutionSession.getSystemProperties());
        properties.putAll(OsProperties.detectOsProperties());
        fullDependencyResolutionSession.setSystemProperties(properties);
        fullDependencyResolutionSession.setDependencySelector(new AndDependencySelector(new NonTestDependencySelector(), new ExclusionDependencySelector(), new OptionalDependencySelector(), new FilteringZipDependencySelector()));
        DependencyResolutionRequest dependencyResolutionRequest = new DefaultDependencyResolutionRequest(mavenProject, fullDependencyResolutionSession);
        DependencyResolutionResult resolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest);
        return buildClassPathResult(resolutionResult);
    } catch (ComponentLookupException e) {
        throw new EnforcerRuleException("Unable to lookup a component " + e.getMessage(), e);
    } catch (DependencyResolutionException e) {
        return buildClasspathFromException(e);
    }
}
Also used : DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) HashMap(java.util.HashMap) ProjectDependenciesResolver(org.apache.maven.project.ProjectDependenciesResolver) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositoryCache(org.eclipse.aether.DefaultRepositoryCache) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) FilteringZipDependencySelector(com.google.cloud.tools.opensource.dependencies.FilteringZipDependencySelector) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) NonTestDependencySelector(com.google.cloud.tools.opensource.dependencies.NonTestDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)

Aggregations

FilteringZipDependencySelector (com.google.cloud.tools.opensource.dependencies.FilteringZipDependencySelector)1 NonTestDependencySelector (com.google.cloud.tools.opensource.dependencies.NonTestDependencySelector)1 HashMap (java.util.HashMap)1 EnforcerRuleException (org.apache.maven.enforcer.rule.api.EnforcerRuleException)1 DefaultDependencyResolutionRequest (org.apache.maven.project.DefaultDependencyResolutionRequest)1 DependencyResolutionException (org.apache.maven.project.DependencyResolutionException)1 DependencyResolutionRequest (org.apache.maven.project.DependencyResolutionRequest)1 DependencyResolutionResult (org.apache.maven.project.DependencyResolutionResult)1 ProjectDependenciesResolver (org.apache.maven.project.ProjectDependenciesResolver)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 DefaultRepositoryCache (org.eclipse.aether.DefaultRepositoryCache)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1 AndDependencySelector (org.eclipse.aether.util.graph.selector.AndDependencySelector)1 ExclusionDependencySelector (org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)1 OptionalDependencySelector (org.eclipse.aether.util.graph.selector.OptionalDependencySelector)1