org.eclipse.aether.repository.RepositoryPolicy Java Examples

The following examples show how to use org.eclipse.aether.repository.RepositoryPolicy. 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: BootstrapMavenContext.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void addProfileRepos(final org.apache.maven.model.Profile profile, final List<RemoteRepository> all) {
    final List<org.apache.maven.model.Repository> repositories = profile.getRepositories();
    for (org.apache.maven.model.Repository repo : repositories) {
        final RemoteRepository.Builder repoBuilder = new RemoteRepository.Builder(repo.getId(), repo.getLayout(),
                repo.getUrl());
        org.apache.maven.model.RepositoryPolicy policy = repo.getReleases();
        if (policy != null) {
            repoBuilder.setReleasePolicy(toAetherRepoPolicy(policy));
        }
        policy = repo.getSnapshots();
        if (policy != null) {
            repoBuilder.setSnapshotPolicy(toAetherRepoPolicy(policy));
        }
        all.add(repoBuilder.build());
    }
}
 
Example #2
Source File: AetherUtil.java    From buck with Apache License 2.0 6 votes vote down vote up
public static RemoteRepository toRemoteRepository(
    String repoUrl, Optional<String> username, Optional<String> password) {
  RemoteRepository.Builder repo =
      new RemoteRepository.Builder(null, "default", repoUrl)
          .setPolicy(new RepositoryPolicy(true, null, CHECKSUM_POLICY_FAIL));

  if (username.isPresent() && password.isPresent()) {
    Authentication authentication =
        new AuthenticationBuilder()
            .addUsername(username.get())
            .addPassword(password.get())
            .build();
    repo.setAuthentication(authentication);
  }

  return repo.build();
}
 
Example #3
Source File: AetherUtils.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
public static RepositoryPolicy toRepositoryPolicy(org.apache.maven.model.RepositoryPolicy policy) {
  boolean enabled = true;
  String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
  String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;

  if (policy != null) {
    enabled = policy.isEnabled();
    if (policy.getUpdatePolicy() != null) {
      updates = policy.getUpdatePolicy();
    }
    if (policy.getChecksumPolicy() != null) {
      checksums = policy.getChecksumPolicy();
    }
  }

  return new RepositoryPolicy(enabled, updates, checksums);
}
 
Example #4
Source File: MavenPluginRepository.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public MavenPluginRepository() {
	Settings settings = loadDefaultUserSettings();

	system = newRepositorySystem();
	String userHome = System.getProperty("user.home");
	File localRepository = new File(settings.getLocalRepository() == null ? userHome + "/.m2/repository" : settings.getLocalRepository());
	session = newRepositorySystemSession(system, localRepository, settings);

	localRepositories = new ArrayList<>();

	RemoteRepository.Builder localRepoBuilder = new RemoteRepository.Builder("local", "default", "file://" + localRepository.toString());
	localRepoBuilder.setPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":60", RepositoryPolicy.CHECKSUM_POLICY_FAIL));
	local = localRepoBuilder.build();
	repositories.add(local);
	localRepositories.add(local);

	addRepository("central", "default", "https://repo1.maven.org/maven2/");
}
 
Example #5
Source File: MavenArtifactResolvingHelperTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
// SWARM-1173: swarm-plugin trying to download SNAPSHOTs from Maven Central
public void propagateRepositoryPolicies() {
    MavenArtifactResolvingHelper artifactResolverHelper = new MavenArtifactResolvingHelper(null, null, sessionMock, null);
    ArtifactRepositoryPolicy testSnapshotPolicy = new ArtifactRepositoryPolicy(false, "hourly", "warn");
    ArtifactRepositoryPolicy testReleasesPolicy = new ArtifactRepositoryPolicy(true, "never", "warn");
    ArtifactRepository testingRepo = new MavenArtifactRepository("testing-repo", "http://testing-repo.org", new DefaultRepositoryLayout(), testSnapshotPolicy, testReleasesPolicy);
    artifactResolverHelper.remoteRepository(testingRepo);

    List<RemoteRepository> remoteRepos = artifactResolverHelper.getRemoteRepositories();

    Assert.assertTrue("Remote repositories " + remoteRepos + " do not contain expected testing repo " + testingRepo,
                      remoteRepos.stream().anyMatch(
                              remoteRepo -> {
                                  RepositoryPolicy snapshotsPolicy = remoteRepo.getPolicy(true);
                                  RepositoryPolicy releasesPolicy = remoteRepo.getPolicy(false);
                                  return remoteRepo.getId().equals(testingRepo.getId()) &&
                                          !snapshotsPolicy.isEnabled() &&
                                          snapshotsPolicy.getUpdatePolicy().equals(testSnapshotPolicy.getUpdatePolicy()) &&
                                          snapshotsPolicy.getChecksumPolicy().equals(testSnapshotPolicy.getChecksumPolicy()) &&
                                          releasesPolicy.isEnabled() &&
                                          releasesPolicy.getUpdatePolicy().equals(testReleasesPolicy.getUpdatePolicy()) &&
                                          releasesPolicy.getChecksumPolicy().equals(testReleasesPolicy.getChecksumPolicy());
                              })
    );
}
 
Example #6
Source File: AetherFactories.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
public static RepositorySystemSession newSession(RepositorySystem system,
		boolean workOffline) {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	session.setOffline(workOffline);
	if (!workOffline) {
		session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
	}
	session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
	String localRepositoryDirectory = localRepositoryDirectory(workOffline);
	if (log.isDebugEnabled()) {
		log.debug("Local Repository Directory set to [" + localRepositoryDirectory
				+ "]. Work offline: [" + workOffline + "]");
	}
	LocalRepository localRepo = new LocalRepository(localRepositoryDirectory);
	session.setLocalRepositoryManager(
			system.newLocalRepositoryManager(session, localRepo));
	return session;
}
 
Example #7
Source File: MavenArtifactResolvingHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private RemoteRepository buildRemoteRepository(final String id, final String url, final Authentication auth,
                                               final ArtifactRepositoryPolicy releasesPolicy, final ArtifactRepositoryPolicy snapshotsPolicy) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (auth != null
            && auth.getUsername() != null
            && auth.getPassword() != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                                          .addUsername(auth.getUsername())
                                          .addPassword(auth.getPassword()).build());
    }

    builder.setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()));
    builder.setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));

    RemoteRepository repository = builder.build();

    final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);

    if (mirror != null) {
        final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector()
                .getAuthentication(mirror);
        RemoteRepository.Builder mirrorBuilder = new RemoteRepository.Builder(mirror)
                .setId(repository.getId())
                .setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()))
                .setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
        if (mirrorAuth != null) {
            mirrorBuilder.setAuthentication(mirrorAuth);
        }
        repository = mirrorBuilder.build();
    }

    Proxy proxy = session.getProxySelector().getProxy(repository);

    if (proxy != null) {
        repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
    }

    return repository;
}
 
Example #8
Source File: DependencyResolver.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static Collection<Dependency> _getManagedDependencies(
    IMavenExecutionContext context,
    RepositorySystem system,
    String groupId,
    String artifactId,
    String version,
    SubMonitor monitor)
    throws CoreException {
  ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
  String coords = groupId + ":" + artifactId + ":" + version;
  Artifact artifact = new DefaultArtifact(coords);
  request.setArtifact(artifact);
  request.setRepositories(centralRepository(system));

  // ensure checksum errors result in failure
  DefaultRepositorySystemSession session =
      new DefaultRepositorySystemSession(context.getRepositorySession());
  session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);

  try {
    List<Dependency> managedDependencies =
        system.readArtifactDescriptor(session, request).getManagedDependencies();
    
    return managedDependencies;
  } catch (RepositoryException ex) {
    IStatus status = StatusUtil.error(DependencyResolver.class, ex.getMessage(), ex);
    throw new CoreException(status);
  }
}
 
Example #9
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public DefaultRepositorySystemSession setupRepoSession(final RepositorySystem repoSystem, final Settings settings)
{
   DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
   session.setOffline(false);

   Proxy activeProxy = settings.getActiveProxy();
   if (activeProxy != null)
   {
      DefaultProxySelector dps = new DefaultProxySelector();
      dps.add(convertFromMavenProxy(activeProxy), activeProxy.getNonProxyHosts());
      session.setProxySelector(dps);
   }

   final DefaultMirrorSelector mirrorSelector = createMirrorSelector(settings);
   final LazyAuthenticationSelector authSelector = createAuthSelector(settings, mirrorSelector);

   session.setMirrorSelector(mirrorSelector);
   session.setAuthenticationSelector(authSelector);

   LocalRepository localRepo = new LocalRepository(new File(settings.getLocalRepository()));
   session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
   session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
   session.setCache(new DefaultRepositoryCache());
   boolean cacheNotFoundArtifacts = true;
   boolean cacheTransferErrors = true;
   session.setResolutionErrorPolicy(new SimpleResolutionErrorPolicy(cacheNotFoundArtifacts, cacheTransferErrors));
   session.setWorkspaceReader(new ClasspathWorkspaceReader());
   if (Boolean.getBoolean("org.apache.maven.log_transfer"))
   {
      session.setTransferListener(new JULMavenTransferListener());
   }
   return session;
}
 
Example #10
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static RepositoryPolicy toAetherRepoPolicy(org.apache.maven.model.RepositoryPolicy modelPolicy) {
    return new RepositoryPolicy(modelPolicy.isEnabled(),
            StringUtils.isEmpty(modelPolicy.getUpdatePolicy()) ? RepositoryPolicy.UPDATE_POLICY_DAILY
                    : modelPolicy.getUpdatePolicy(),
            StringUtils.isEmpty(modelPolicy.getChecksumPolicy()) ? RepositoryPolicy.CHECKSUM_POLICY_WARN
                    : modelPolicy.getChecksumPolicy());
}
 
Example #11
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
@Nullable
private RepositoryPolicy toPolicy(org.apache.maven.model.RepositoryPolicy policy) {
  if (policy != null) {
    return new RepositoryPolicy(
        policy.isEnabled(), policy.getUpdatePolicy(), policy.getChecksumPolicy());
  }
  return null;
}
 
Example #12
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static RemoteRepository newDefaultRepository() {
    return new RemoteRepository.Builder(DEFAULT_REMOTE_REPO_ID, "default", DEFAULT_REMOTE_REPO_URL)
            .setReleasePolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY,
                    RepositoryPolicy.CHECKSUM_POLICY_WARN))
            .setSnapshotPolicy(new RepositoryPolicy(false, RepositoryPolicy.UPDATE_POLICY_DAILY,
                    RepositoryPolicy.CHECKSUM_POLICY_WARN))
            .build();
}
 
Example #13
Source File: AetherUtil.java    From buck with Apache License 2.0 5 votes vote down vote up
public static RemoteRepository toRemoteRepository(Repository repo) {
  RemoteRepository.Builder builder =
      new RemoteRepository.Builder(repo.getUrl(), "default", repo.getUrl())
          .setPolicy(new RepositoryPolicy(true, null, CHECKSUM_POLICY_FAIL));

  if (repo.user != null && repo.password != null) {
    builder.setAuthentication(
        new AuthenticationBuilder().addUsername(repo.user).addPassword(repo.password).build());
  }

  return builder.build();
}
 
Example #14
Source File: MavenResourceTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
@Test
public void checkRepositoryPolicies() {
	MavenProperties mavenProperties = new MavenProperties();
	mavenProperties.setChecksumPolicy("always");
	mavenProperties.setUpdatePolicy("fail");
	Map<String, MavenProperties.RemoteRepository> remoteRepositoryMap = new HashMap<>();
	MavenProperties.RemoteRepository remoteRepo1 = new MavenProperties.RemoteRepository(
			"https://repo.spring.io/libs-snapshot-local");
	MavenProperties.RepositoryPolicy snapshotPolicy = new MavenProperties.RepositoryPolicy();
	snapshotPolicy.setEnabled(true);
	snapshotPolicy.setUpdatePolicy("always");
	snapshotPolicy.setChecksumPolicy("warn");
	remoteRepo1.setSnapshotPolicy(snapshotPolicy);
	MavenProperties.RepositoryPolicy releasePolicy = new MavenProperties.RepositoryPolicy();
	releasePolicy.setEnabled(true);
	releasePolicy.setUpdatePolicy("interval");
	releasePolicy.setChecksumPolicy("ignore");
	remoteRepo1.setReleasePolicy(releasePolicy);
	remoteRepositoryMap.put("repo1", remoteRepo1);
	MavenProperties.RemoteRepository remoteRepo2 = new MavenProperties.RemoteRepository(
			"https://repo.spring.io/libs-milestone-local");
	MavenProperties.RepositoryPolicy policy = new MavenProperties.RepositoryPolicy();
	policy.setEnabled(true);
	policy.setUpdatePolicy("daily");
	policy.setChecksumPolicy("fail");
	remoteRepo2.setPolicy(policy);
	remoteRepositoryMap.put("repo2", remoteRepo2);
	mavenProperties.setRemoteRepositories(remoteRepositoryMap);
	MavenArtifactResolver artifactResolver = new MavenArtifactResolver(mavenProperties);
	Field remoteRepositories = ReflectionUtils.findField(MavenArtifactResolver.class, "remoteRepositories");
	ReflectionUtils.makeAccessible(remoteRepositories);
	List<RemoteRepository> remoteRepositoryList = (List<RemoteRepository>) ReflectionUtils
			.getField(remoteRepositories, artifactResolver);
	Field repositorySystem = ReflectionUtils.findField(MavenArtifactResolver.class, "repositorySystem");
	ReflectionUtils.makeAccessible(repositorySystem);
	RepositorySystem repositorySystem1 = (RepositorySystem) ReflectionUtils.getField(repositorySystem, artifactResolver);
	Method repositorySystemSessionMethod = ReflectionUtils.findMethod(MavenArtifactResolver.class, "newRepositorySystemSession", RepositorySystem.class, String.class);
	ReflectionUtils.makeAccessible(repositorySystemSessionMethod);
	RepositorySystemSession repositorySystemSession = (RepositorySystemSession)
			ReflectionUtils.invokeMethod(repositorySystemSessionMethod, artifactResolver, repositorySystem1, "file://local");
	assertEquals("always", repositorySystemSession.getChecksumPolicy());
	assertEquals("fail", repositorySystemSession.getUpdatePolicy());
	for (RemoteRepository remoteRepository : remoteRepositoryList) {
		assertEquals(2, remoteRepositoryList.size());
		assertEquals(true, remoteRepositoryList.get(0).getId().equals("repo1")
				|| remoteRepositoryList.get(0).getId().equals("repo2"));
		assertEquals(true, remoteRepositoryList.get(1).getId().equals("repo2")
				|| remoteRepositoryList.get(1).getId().equals("repo1"));
		if (remoteRepository.getId().equals("repo1")) {
			RepositoryPolicy snapshotPolicy1 = remoteRepository.getPolicy(true);
			assertEquals(true, snapshotPolicy1.isEnabled());
			assertEquals("always", snapshotPolicy1.getUpdatePolicy());
			assertEquals("warn", snapshotPolicy1.getChecksumPolicy());
			RepositoryPolicy releasePolicy1 = remoteRepository.getPolicy(false);
			assertEquals(true, releasePolicy1.isEnabled());
			assertEquals("interval", releasePolicy1.getUpdatePolicy());
			assertEquals("ignore", releasePolicy1.getChecksumPolicy());
		}
		else if (remoteRepository.getId().equals("repo2")) {
			RepositoryPolicy snapshotPolicy2 = remoteRepository.getPolicy(true);
			assertEquals(true, snapshotPolicy2.isEnabled());
			assertEquals("daily", snapshotPolicy2.getUpdatePolicy());
			assertEquals("fail", snapshotPolicy2.getChecksumPolicy());
			RepositoryPolicy releasePolicy2 = remoteRepository.getPolicy(false);
			assertEquals(true, releasePolicy2.isEnabled());
			assertEquals("daily", releasePolicy2.getUpdatePolicy());
			assertEquals("fail", releasePolicy2.getChecksumPolicy());
		}
	}
	MavenResource resource = MavenResource
			.parse("org.springframework.cloud.task.app:timestamp-task:jar:1.0.0.BUILD-SNAPSHOT", mavenProperties);
	assertEquals(resource.exists(), true);
}
 
Example #15
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public static ShrinkwrapArtifactResolvingHelper defaultInstance() {
    return INSTANCE.updateAndGet(e -> {
        if (e != null) {
            return e;
        }

        MavenRemoteRepository jbossPublic =
                MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group",
                                                               "https://repository.jboss.org/nexus/content/groups/public/",
                                                               MAVEN_LAYOUT_DEFAULT);
        jbossPublic.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        jbossPublic.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

        MavenRemoteRepository redhatGa =
                MavenRemoteRepositories.createRemoteRepository("redhat-ga",
                                                               "https://maven.repository.redhat.com/ga/",
                                                               MAVEN_LAYOUT_DEFAULT);
        redhatGa.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        redhatGa.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

        MavenRemoteRepository gradleTools =
                MavenRemoteRepositories.createRemoteRepository("gradle",
                                                               "https://repo.gradle.org/gradle/libs-releases-local",
                                                               MAVEN_LAYOUT_DEFAULT);
        gradleTools.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        gradleTools.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

        Boolean offline = Boolean.valueOf(System.getProperty("thorntail.resolver.offline", "false"));
        final ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
                .withMavenCentralRepo(true)
                .withRemoteRepo(jbossPublic)
                .withRemoteRepo(redhatGa)
                .withRemoteRepo(gradleTools)
                .workOffline(offline);

        final String additionalRepos = System.getProperty(SwarmInternalProperties.BUILD_REPOS);
        if (additionalRepos != null) {
            Arrays.asList(additionalRepos.split(","))
                    .forEach(r -> {
                        MavenRemoteRepository repo =
                                MavenRemoteRepositories.createRemoteRepository(r, r, MAVEN_LAYOUT_DEFAULT);
                        repo.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
                        repo.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);
                        resolver.withRemoteRepo(repo);
                    });
        }


        ShrinkwrapArtifactResolvingHelper helper = new ShrinkwrapArtifactResolvingHelper(resolver);
        helper.session().setCache(new SimpleRepositoryCache());
        helper.session().setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
        helper.session().setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);

        return helper;
    });
}
 
Example #16
Source File: ReportAggregateMojo.java    From revapi with Apache License 2.0 4 votes vote down vote up
private ProjectVersions getRunConfig(MavenProject project) {
    ProjectVersions ret = new ProjectVersions();
    Plugin revapiPlugin = findRevapi(project);
    if (revapiPlugin == null) {
        return ret;
    }

    Xpp3Dom pluginConfig = (Xpp3Dom) revapiPlugin.getConfiguration();

    String[] oldArtifacts = getArtifacts(pluginConfig, "oldArtifacts");
    String[] newArtifacts = getArtifacts(pluginConfig, "newArtifacts");
    String oldVersion = getValueOfChild(pluginConfig, "oldVersion");
    if (oldVersion == null) {
        oldVersion = System.getProperties().getProperty(Props.oldVersion.NAME, Props.oldVersion.DEFAULT_VALUE);
    }
    String newVersion = getValueOfChild(pluginConfig, "newVersion");
    if (newVersion == null) {
        newVersion = System.getProperties().getProperty(Props.newVersion.NAME, project.getVersion());
    }

    String defaultOldArtifact = Analyzer.getProjectArtifactCoordinates(project, oldVersion);
    String defaultNewArtifact = Analyzer.getProjectArtifactCoordinates(project, newVersion);

    if (oldArtifacts == null || oldArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        oldArtifacts = new String[]{defaultOldArtifact};
    }
    if (newArtifacts == null || newArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        newArtifacts = new String[]{defaultNewArtifact};
    }
    String versionRegexString = getValueOfChild(pluginConfig, "versionFormat");
    Pattern versionRegex = versionRegexString == null ? null : Pattern.compile(versionRegexString);

    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
    session.setDependencySelector(getRevapiDependencySelector(resolveProvidedDependencies, resolveTransitiveProvidedDependencies));
    session.setDependencyTraverser(getRevapiDependencyTraverser(resolveProvidedDependencies, resolveTransitiveProvidedDependencies));

    if (alwaysCheckForReleaseVersion) {
        session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
    }

    ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session,
            mavenSession.getCurrentProject().getRemoteProjectRepositories());

    Function<String, Artifact> resolve = gav -> {
        try {
            return Analyzer.resolveConstrained(project, gav, versionRegex, resolver);
        } catch (VersionRangeResolutionException | ArtifactResolutionException e) {
            getLog().warn("Could not resolve artifact '" + gav + "' with message: " + e.getMessage());
            return null;
        }
    };

    ret.oldGavs = Stream.of(oldArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
    ret.newGavs = Stream.of(newArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);

    return ret;
}
 
Example #17
Source File: Analyzer.java    From revapi with Apache License 2.0 4 votes vote down vote up
Analyzer(PlexusConfiguration pipelineConfiguration, PlexusConfiguration analysisConfiguration,
        Object[] analysisConfigurationFiles, Artifact[] oldArtifacts, Artifact[] newArtifacts, String[] oldGavs,
        String[] newGavs, MavenProject project, RepositorySystem repositorySystem,
        RepositorySystemSession repositorySystemSession, Class<? extends Reporter> reporterType,
        Map<String, Object> contextData, Locale locale, Log log, boolean failOnMissingConfigurationFiles,
        boolean failOnMissingArchives, boolean failOnMissingSupportArchives, boolean alwaysUpdate,
        boolean resolveDependencies, boolean resolveProvidedDependencies,
        boolean resolveTransitiveProvidedDependencies, String versionRegex,
        Consumer<PipelineConfiguration.Builder> pipelineModifier, Revapi sharedRevapi) {

    this.pipelineConfiguration = pipelineConfiguration;
    this.analysisConfiguration = analysisConfiguration;
    this.analysisConfigurationFiles = analysisConfigurationFiles;
    this.oldGavs = oldGavs;
    this.newGavs = newGavs;
    this.oldArtifacts = oldArtifacts;
    this.newArtifacts = newArtifacts;
    this.project = project;
    this.repositorySystem = repositorySystem;

    this.resolveDependencies = resolveDependencies;

    this.versionRegex = versionRegex == null ? null : Pattern.compile(versionRegex);

    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);

    session.setDependencySelector(getRevapiDependencySelector(resolveProvidedDependencies, resolveTransitiveProvidedDependencies));
    session.setDependencyTraverser(getRevapiDependencyTraverser(resolveProvidedDependencies, resolveTransitiveProvidedDependencies));

    if (alwaysUpdate) {
        session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
    }

    this.repositorySystemSession = session;

    this.reporterType = reporterType;
    this.contextData = contextData;
    this.locale = locale;
    this.log = log;
    this.failOnMissingConfigurationFiles = failOnMissingConfigurationFiles;
    this.failOnMissingArchives = failOnMissingArchives;
    this.failOnMissingSupportArchives = failOnMissingSupportArchives;
    this.revapi = sharedRevapi;
    this.pipelineModifier = pipelineModifier;
}