Search in sources :

Example 1 with InvalidRepositoryException

use of org.apache.maven.artifact.InvalidRepositoryException in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method convertRepositories.

@NotNull
protected List<ArtifactRepository> convertRepositories(List<MavenRemoteRepository> repositories) throws RemoteException {
    List<ArtifactRepository> result = new ArrayList<ArtifactRepository>();
    for (MavenRemoteRepository each : repositories) {
        try {
            ArtifactRepositoryFactory factory = getComponent(ArtifactRepositoryFactory.class);
            result.add(ProjectUtils.buildArtifactRepository(MavenModelConverter.toNativeRepository(each), factory, myContainer));
        } catch (InvalidRepositoryException e) {
            Maven3ServerGlobals.getLogger().warn(e);
        }
    }
    return result;
}
Also used : InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with InvalidRepositoryException

use of org.apache.maven.artifact.InvalidRepositoryException in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method createLocalRepository.

private ArtifactRepository createLocalRepository() {
    try {
        final ArtifactRepository localRepository = getComponent(RepositorySystem.class).createLocalRepository(new File(myMavenSettings.getLocalRepository()));
        final String customRepoId = System.getProperty("maven3.localRepository.id", "localIntelliJ");
        if (customRepoId != null) {
            // see details at https://youtrack.jetbrains.com/issue/IDEA-121292
            localRepository.setId(customRepoId);
        }
        return localRepository;
    } catch (InvalidRepositoryException e) {
        throw new RuntimeException(e);
    // Legacy code.
    }
//ArtifactRepositoryLayout layout = getComponent(ArtifactRepositoryLayout.class, "default");
//ArtifactRepositoryFactory factory = getComponent(ArtifactRepositoryFactory.class);
//
//String url = myMavenSettings.getLocalRepository();
//if (!url.startsWith("file:")) url = "file://" + url;
//
//ArtifactRepository localRepository = factory.createArtifactRepository("local", url, layout, null, null);
//
//boolean snapshotPolicySet = myMavenSettings.isOffline();
//if (!snapshotPolicySet && snapshotUpdatePolicy == MavenServerSettings.UpdatePolicy.ALWAYS_UPDATE) {
//  factory.setGlobalUpdatePolicy(ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS);
//}
//factory.setGlobalChecksumPolicy(ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
//
//return localRepository;
}
Also used : DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) RepositorySystem(org.apache.maven.repository.RepositorySystem) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File)

Example 3 with InvalidRepositoryException

use of org.apache.maven.artifact.InvalidRepositoryException in project sts4 by spring-projects.

the class MavenBridge method createArtifactRepository.

public ArtifactRepository createArtifactRepository(String id, String url) throws MavenException {
    Repository repository = new Repository();
    repository.setId(id);
    repository.setUrl(url);
    // $NON-NLS-1$
    repository.setLayout("default");
    ArtifactRepository repo;
    try {
        repo = lookup(RepositorySystem.class).buildArtifactRepository(repository);
        ArrayList<ArtifactRepository> repos = new ArrayList<ArtifactRepository>(Arrays.asList(repo));
        injectSettings(repos);
    } catch (InvalidRepositoryException ex) {
        throw new MavenException(ex);
    }
    return repo;
}
Also used : Repository(org.apache.maven.model.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 4 with InvalidRepositoryException

use of org.apache.maven.artifact.InvalidRepositoryException in project che by eclipse.

the class MavenServerImpl method resolveArtifact.

@Override
public MavenArtifact resolveArtifact(MavenArtifactKey artifactKey, List<MavenRemoteRepository> repositories) throws RemoteException {
    Artifact artifact = getMavenComponent(ArtifactFactory.class).createArtifactWithClassifier(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), artifactKey.getClassifier());
    List<ArtifactRepository> repos = new ArrayList<>();
    ArtifactRepositoryFactory factory = getMavenComponent(ArtifactRepositoryFactory.class);
    for (MavenRemoteRepository repository : repositories) {
        try {
            ArtifactRepository artifactRepository = ProjectUtils.buildArtifactRepository(MavenModelUtil.convertToMavenRepository(repository), factory, container);
            repos.add(artifactRepository);
        } catch (InvalidRepositoryException e) {
            MavenServerContext.getLogger().error(e);
        }
    }
    MavenExecutionRequest request = newMavenRequest(null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    repos.forEach(request::addRemoteRepository);
    DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
    RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
    org.eclipse.aether.impl.ArtifactResolver artifactResolver = getMavenComponent(org.eclipse.aether.impl.ArtifactResolver.class);
    InternalLoggerFactory loggerFactory = new InternalLoggerFactory();
    if (artifactResolver instanceof DefaultArtifactResolver) {
        ((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
    }
    org.eclipse.aether.RepositorySystem repositorySystem = getMavenComponent(org.eclipse.aether.RepositorySystem.class);
    if (repositorySystem instanceof DefaultRepositorySystem) {
        ((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
    }
    List<RemoteRepository> remoteRepositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
    remoteRepositories = repositorySystem.newResolutionRepositories(repositorySystemSession, remoteRepositories);
    try {
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null));
        return MavenModelUtil.convertArtifact(RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
    } catch (ArtifactResolutionException e) {
        MavenServerContext.getLogger().info(e);
    }
    return MavenModelUtil.convertArtifact(artifact, localRepository);
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArrayList(java.util.ArrayList) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) DefaultMaven(org.apache.maven.DefaultMaven) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository)

Example 5 with InvalidRepositoryException

use of org.apache.maven.artifact.InvalidRepositoryException in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method convertRepositories.

@NotNull
protected List<ArtifactRepository> convertRepositories(List<MavenRemoteRepository> repositories) throws RemoteException {
    List<ArtifactRepository> result = new ArrayList<ArtifactRepository>();
    for (MavenRemoteRepository each : repositories) {
        try {
            ArtifactRepositoryFactory factory = getComponent(ArtifactRepositoryFactory.class);
            result.add(ProjectUtils.buildArtifactRepository(MavenModelConverter.toNativeRepository(each), factory, myContainer));
        } catch (InvalidRepositoryException e) {
            Maven3ServerGlobals.getLogger().warn(e);
        }
    }
    return result;
}
Also used : InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)9 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)8 ArtifactRepositoryFactory (org.apache.maven.artifact.repository.ArtifactRepositoryFactory)4 RepositorySystem (org.apache.maven.repository.RepositorySystem)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Repository (org.apache.maven.model.Repository)2 DefaultRepositorySystem (org.eclipse.aether.internal.impl.DefaultRepositorySystem)2 NotNull (org.jetbrains.annotations.NotNull)2 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)1 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 Mirror (org.apache.maven.settings.Mirror)1 Proxy (org.apache.maven.settings.Proxy)1 Repository (org.apache.maven.settings.Repository)1 Server (org.apache.maven.settings.Server)1