Java Code Examples for org.eclipse.aether.repository.RemoteRepository#Builder

The following examples show how to use org.eclipse.aether.repository.RemoteRepository#Builder . 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: Deploy.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
public RemoteRepository remoteRepository(MavenProject project) throws MojoExecutionException {
  if (altDeploymentRepository != null) {
    Matcher matcher = Pattern.compile("(.+)::(.+)::(.+)").matcher(altDeploymentRepository);
    if (!matcher.matches()) {
      throw new MojoExecutionException(altDeploymentRepository, "Invalid syntax for repository.", "Invalid syntax for alternative repository. Use \"id::layout::url\".");
    }

    String id = matcher.group(1).trim();
    String layout = matcher.group(2).trim();
    String url = matcher.group(3).trim();

    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, layout, url);

    return builder.build();
  }

  return AetherUtils.toRepo(project.getDistributionManagementArtifactRepository());
}
 
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: ArtifactRetriever.java    From maven-repository-tools with Eclipse Public License 1.0 6 votes vote down vote up
public void retrieve( List<String> artifactCoordinates, String sourceUrl, String username, 
                     String password, boolean includeSources,
                     boolean includeJavadoc, boolean includeProvidedScope,
                     boolean includeTestScope, boolean includeRuntimeScope )
{
    RemoteRepository.Builder builder = new RemoteRepository.Builder( "central", "default", sourceUrl );
    builder.setProxy( ProxyHelper.getProxy( sourceUrl ) );
    
    Authentication auth = new AuthenticationBuilder()
        .addUsername( username )
        .addPassword( password )
        .build();
    builder.setAuthentication( auth );

    sourceRepository = builder.build();

    getArtifactResults( artifactCoordinates, includeProvidedScope, includeTestScope, includeRuntimeScope );

    getAdditionalArtifactsForRequest( artifactCoordinates );

    getAdditionalArtifactsForArtifactsInCache( includeSources, includeJavadoc );
}
 
Example 6
Source File: MavenArtifactResolvingHelper.java    From wildfly-swarm with Apache License 2.0 6 votes vote down vote up
protected static RemoteRepository buildRemoteRepository(final String id, final String url,
                                                        final Authentication auth, final Proxy proxy) {
    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());
    }

    if (proxy != null) {
        builder.setProxy(proxy);
    }

    return builder.build();
}
 
Example 7
Source File: AetherStubDownloader.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
private List<RemoteRepository> remoteRepositories(
		StubRunnerOptions stubRunnerOptions) {
	if (stubRunnerOptions.stubRepositoryRoot == null) {
		return new ArrayList<>();
	}
	final String[] repos = stubRunnerOptions.getStubRepositoryRootAsString()
			.split(",");
	final List<RemoteRepository> remoteRepos = new ArrayList<>();
	for (int i = 0; i < repos.length; i++) {
		if (StringUtils.hasText(repos[i])) {
			final RemoteRepository.Builder builder = new RemoteRepository.Builder(
					"remote" + i, "default", repos[i]).setAuthentication(
							resolveAuthentication(stubRunnerOptions));
			if (stubRunnerOptions.getProxyOptions() != null) {
				final StubRunnerProxyOptions p = stubRunnerOptions.getProxyOptions();
				builder.setProxy(new Proxy(null, p.getProxyHost(), p.getProxyPort()));
			}
			remoteRepos.add(builder.build());
		}
	}
	if (log.isDebugEnabled()) {
		log.debug("Using the following remote repos " + remoteRepos);
	}
	return remoteRepos;
}
 
Example 8
Source File: MavenConfig.java    From galleon with Apache License 2.0 6 votes vote down vote up
public RemoteRepository buildRemoteRepository(MavenRemoteRepository repo, MavenProxySelector selector, Proxy proxy) throws ArtifactException {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getName(),
            repo.getType(), repo.getUrl());
    builder.setSnapshotPolicy(new org.eclipse.aether.repository.RepositoryPolicy(repo.getEnableSnapshot() == null ? isSnapshotEnabled() : repo.getEnableSnapshot(),
            repo.getSnapshotUpdatePolicy() == null ? getDefaultSnapshotPolicy() : repo.getSnapshotUpdatePolicy(),
            CHECKSUM_POLICY_WARN));
    builder.setReleasePolicy(new org.eclipse.aether.repository.RepositoryPolicy(repo.getEnableRelease() == null ? isReleaseEnabled() : repo.getEnableRelease(),
            repo.getReleaseUpdatePolicy() == null ? getDefaultReleasePolicy() : repo.getReleaseUpdatePolicy(),
            CHECKSUM_POLICY_WARN));
    try {
        if (selector != null && selector.proxyFor(new URL(repo.getUrl()).getHost())) {
            builder.setProxy(proxy);
        }
    } catch (MalformedURLException ex) {
        throw new ArtifactException(ex.getMessage(), ex);
    }
    return builder.build();
}
 
Example 9
Source File: MavenInitializer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public static RemoteRepository buildRemoteRepository(final RepositorySystemSession session,
                                                     final String id, final String url, final String username, final String password) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (username != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(username)
                .addPassword(password).build());
    }

    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());
        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 10
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 11
Source File: Helper.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public static RemoteRepository newRemoteRepository ( final String id, final String url )
{
    final RemoteRepository.Builder builder = new RemoteRepository.Builder ( id, "default", url );

    builder.setProxy ( getProxy ( url ) );

    return builder.build ();
}
 
Example 12
Source File: MavenArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
public void remoteRepository(ArtifactRepository repo) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getId(), "default", repo.getUrl());
    final Authentication mavenAuth = repo.getAuthentication();
    if (mavenAuth != null && mavenAuth.getUsername() != null && mavenAuth.getPassword() != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(mavenAuth.getUsername())
                .addPassword(mavenAuth.getPassword()).build());
    }
    this.remoteRepositories.add(builder.build());
}
 
Example 13
Source File: MavenRepositories.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
static RemoteRepository convertToMavenRepo(final String id, String url, final Settings settings)
{
   RemoteRepository.Builder remoteRepositoryBuilder = new RemoteRepository.Builder(id, "default", url);
   Proxy activeProxy = settings.getActiveProxy();
   if (activeProxy != null)
   {
      Authentication auth = new AuthenticationBuilder().addUsername(activeProxy.getUsername())
               .addPassword(activeProxy.getPassword()).build();
      remoteRepositoryBuilder.setProxy(new org.eclipse.aether.repository.Proxy(activeProxy.getProtocol(),
               activeProxy
                        .getHost(),
               activeProxy.getPort(), auth));
   }
   return remoteRepositoryBuilder.build();
}
 
Example 14
Source File: AetherUtil.java    From vertx-deploy-tools with Apache License 2.0 5 votes vote down vote up
private static RemoteRepository newNexusRepo(DeployConfig deployConfig) {
    if (deployConfig.getNexusUrl() == null) {
        return null;
    }

    RemoteRepository.Builder builder = new RemoteRepository.Builder("nexus", "default", deployConfig.getNexusUrl().toString());
    if (deployConfig.isHttpAuthentication()) {
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(deployConfig.getHttpAuthUser())
                .addPassword(deployConfig.getHttpAuthPassword())
                .build());
    }

    return builder.build();
}
 
Example 15
Source File: DependencyResolver.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static List<RemoteRepository> centralRepository(RepositorySystem system) {
  RemoteRepository.Builder builder =
      new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2/");
  RemoteRepository repository = builder.build();
  List<RemoteRepository> repositories = new ArrayList<>();
  repositories.add(repository);
  return repositories;
}
 
Example 16
Source File: AetherUtils.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
public static RemoteRepository toRepo(ArtifactRepository repo) {
  RemoteRepository result = null;
  if (repo != null) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getId(), getLayout(repo), repo.getUrl());
    builder.setSnapshotPolicy(toPolicy(repo.getSnapshots()));
    builder.setReleasePolicy(toPolicy(repo.getReleases()));
    builder.setAuthentication(toAuthentication(repo.getAuthentication()));
    builder.setProxy(toProxy(repo.getProxy()));
    builder.setMirroredRepositories(toRepos(repo.getMirroredRepositories()));
    result = builder.build();
  }
  return result;
}
 
Example 17
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 18
Source File: DependencyResolver.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
private static RemoteRepository newMavenCentralRepository() {
    final String mavenCentral = MavenCentral.getAddress();
    RemoteRepository.Builder builder = new RemoteRepository.Builder("central", "default", mavenCentral);
    return builder.build();
}
 
Example 19
Source File: AetherUtils.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
public static RemoteRepository toRemoteRepository(Repository repository) {
  RemoteRepository.Builder builder = new RemoteRepository.Builder(repository.getId(), repository.getLayout(), repository.getUrl());
  builder.setSnapshotPolicy(toRepositoryPolicy(repository.getSnapshots()));
  builder.setReleasePolicy(toRepositoryPolicy(repository.getReleases()));
  return builder.build();
}