Search in sources :

Example 16 with LocalRepository

use of org.eclipse.aether.repository.LocalRepository in project spring-boot by spring-projects.

the class ModifiedClassPathClassLoader method resolveCoordinates.

private static List<URL> resolveCoordinates(String[] coordinates) {
    Exception latestFailure = null;
    DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator();
    serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class);
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
    RemoteRepository remoteRepository = new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build();
    session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
    for (int i = 0; i < MAX_RESOLUTION_ATTEMPTS; i++) {
        CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(remoteRepository));
        collectRequest.setDependencies(createDependencies(coordinates));
        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
        try {
            DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest);
            List<URL> resolvedArtifacts = new ArrayList<>();
            for (ArtifactResult artifact : result.getArtifactResults()) {
                resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
            }
            return resolvedArtifacts;
        } catch (Exception ex) {
            latestFailure = ex;
        }
    }
    throw new IllegalStateException("Resolution failed after " + MAX_RESOLUTION_ATTEMPTS + " attempts", latestFailure);
}
Also used : DependencyResult(org.eclipse.aether.resolution.DependencyResult) LocalRepository(org.eclipse.aether.repository.LocalRepository) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) CollectRequest(org.eclipse.aether.collection.CollectRequest) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest)

Example 17 with LocalRepository

use of org.eclipse.aether.repository.LocalRepository in project spring-boot by spring-projects.

the class SettingsXmlRepositorySystemSessionAutoConfigurationTests method propertyInterpolation.

@Test
void propertyInterpolation() {
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    given(this.repositorySystem.newLocalRepositoryManager(eq(session), any(LocalRepository.class))).willAnswer((invocation) -> {
        LocalRepository localRepository = invocation.getArgument(1);
        return new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepository);
    });
    TestPropertyValues.of("user.home:src/test/resources/maven-settings/property-interpolation", "foo:bar").applyToSystemProperties(() -> {
        new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session, SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem);
        return null;
    });
    assertThat(session.getLocalRepository().getBasedir().getAbsolutePath()).endsWith(File.separatorChar + "bar" + File.separatorChar + "repository");
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LocalRepository(org.eclipse.aether.repository.LocalRepository) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) Test(org.junit.jupiter.api.Test)

Example 18 with LocalRepository

use of org.eclipse.aether.repository.LocalRepository in project zeppelin by apache.

the class Booter method newRepositorySystemSession.

public static RepositorySystemSession newRepositorySystemSession(RepositorySystem system, String localRepoPath) {
    Validate.notNull(localRepoPath, "localRepoPath should have a value");
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepo = new LocalRepository(resolveLocalRepoPath(localRepoPath));
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    if (LOGGER.isDebugEnabled()) {
        session.setTransferListener(new TransferListener());
        session.setRepositoryListener(new RepositoryListener());
    }
    return session;
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LocalRepository(org.eclipse.aether.repository.LocalRepository)

Example 19 with LocalRepository

use of org.eclipse.aether.repository.LocalRepository in project drools by kiegroup.

the class MavenRepository method removeLocalArtifact.

/**
 * Utility method specifically suggested for testing purposes only.
 */
public void removeLocalArtifact(ReleaseId releaseId) {
    // Taken by analogy of build-helper-maven-plugin
    Artifact artifact = new DefaultArtifact(releaseId.getGroupId(), releaseId.getArtifactId(), null, releaseId.getVersion());
    LocalRepository localRepo = new LocalRepository(getMavenRepositoryConfiguration().getLocalRepository());
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepositoryManager localRepositoryManager = aether.getSystem().newLocalRepositoryManager(session, localRepo);
    session.setLocalRepositoryManager(localRepositoryManager);
    session.setOffline(true);
    String pathForLocalArtifact = localRepositoryManager.getPathForLocalArtifact(artifact);
    File localArtifactDir = // File .jar
    new File(localRepo.getBasedir(), pathForLocalArtifact).getParentFile();
    if (!localArtifactDir.exists()) {
        log.warn("The expected local maven repo dir for {} does not exist {}, nothing to delete.", releaseId, localArtifactDir);
        return;
    }
    log.info("Erasing directory from local maven repository {}", localArtifactDir);
    try {
        FileUtils.deleteDirectory(localArtifactDir);
    } catch (Exception e) {
        log.error("Error while trying to erase directory from local maven repository {}", localArtifactDir);
    }
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LocalRepository(org.eclipse.aether.repository.LocalRepository) File(java.io.File) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) InstallationException(org.eclipse.aether.installation.InstallationException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) IOException(java.io.IOException) DeploymentException(org.eclipse.aether.deployment.DeploymentException)

Example 20 with LocalRepository

use of org.eclipse.aether.repository.LocalRepository in project drools by kiegroup.

the class Aether method newRepositorySystemSession.

private RepositorySystemSession newRepositorySystemSession(Settings settings, RepositorySystem system) {
    LocalRepository localRepo = new LocalRepository(localRepoDir);
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    session.setOffline(offline);
    configureProxiesOnSession(settings, session);
    configureHttpHeadersOnSession(settings, session);
    return session;
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LocalRepository(org.eclipse.aether.repository.LocalRepository)

Aggregations

LocalRepository (org.eclipse.aether.repository.LocalRepository)42 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)34 File (java.io.File)15 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 RepositorySystem (org.eclipse.aether.RepositorySystem)6 JarFile (java.util.jar.JarFile)5 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 SimpleLocalRepositoryManagerFactory (org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory)5 LocalRepositoryManager (org.eclipse.aether.repository.LocalRepositoryManager)5 MalformedURLException (java.net.MalformedURLException)4 LinkedList (java.util.LinkedList)4 Artifact (org.eclipse.aether.artifact.Artifact)4 DefaultServiceLocator (org.eclipse.aether.impl.DefaultServiceLocator)4 URL (java.net.URL)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)3 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)3 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)3 VersionConstraint (org.eclipse.aether.version.VersionConstraint)3