Search in sources :

Example 1 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository 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 ArtifactRepository

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

the class Maven3ServerIndexFetcher method connect.

@Override
public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
    ArtifactRepository artifactRepository = myRepositorySystem.createArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null, null, null);
    final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(artifactRepository);
    String mirrorUrl = mirrorRepository.getUrl();
    String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
    Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
    try {
        myWagon = myWagonManager.getWagon(repository);
        myWagon.addTransferListener(myListener);
        myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
    } catch (AuthenticationException e) {
        IOException newEx = new IOException("Authentication exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    } catch (WagonException e) {
        IOException newEx = new IOException("Wagon exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    }
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) WagonException(org.apache.maven.wagon.WagonException)

Example 3 with ArtifactRepository

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

the class Maven2ServerIndexFetcher method connect.

public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
    final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(new DefaultArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null));
    String mirrorUrl = mirrorRepository.getUrl();
    String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
    Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
    try {
        myWagon = myWagonManager.getWagon(repository);
        myWagon.addTransferListener(myListener);
        myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
    } catch (AuthenticationException e) {
        IOException newEx = new IOException("Authentication exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    } catch (WagonException e) {
        IOException newEx = new IOException("Wagon exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    }
}
Also used : DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) WagonException(org.apache.maven.wagon.WagonException)

Example 4 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository 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 5 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class ResourceResolver method resolveAndUnpack.

private List<String> resolveAndUnpack(final List<Artifact> artifacts, final SourceResolverConfig config, final List<String> validClassifiers, final boolean propagateErrors) throws ArtifactResolutionException, ArtifactNotFoundException {
    // NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually 
    // resolve transitively...this is just used to aggregate resolution failures into a single 
    // exception.
    final Set<Artifact> artifactSet = new LinkedHashSet<Artifact>(artifacts);
    final Artifact pomArtifact = config.project().getArtifact();
    final ArtifactRepository localRepo = config.localRepository();
    final List<ArtifactRepository> remoteRepos = config.project().getRemoteArtifactRepositories();
    final ArtifactFilter filter;
    if (config.filter() != null) {
        filter = new ArtifactIncludeFilterTransformer().transform(config.filter());
    } else {
        filter = null;
    }
    ArtifactFilter resolutionFilter = null;
    if (filter != null) {
        // Wrap the filter in a ProjectArtifactFilter in order to always include the pomArtifact for resolution.
        // NOTE that this is necessary, b/c the -sources artifacts are added dynamically to the pomArtifact
        // and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has
        // to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved.
        resolutionFilter = new ProjectArtifactFilter(pomArtifact, filter);
    }
    Map<String, Artifact> managed = config.project().getManagedVersionMap();
    final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(artifactSet, pomArtifact, managed, localRepo, remoteRepos, artifactMetadataSource, resolutionFilter);
    final List<String> result = new ArrayList<String>(artifacts.size());
    for (final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts()) {
        if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
            continue;
        }
        final File d = new File(config.outputBasedir(), a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier());
        if (!d.exists()) {
            d.mkdirs();
        }
        try {
            final UnArchiver unArchiver = archiverManager.getUnArchiver(a.getType());
            unArchiver.setDestDirectory(d);
            unArchiver.setSourceFile(a.getFile());
            unArchiver.extract();
            result.add(d.getAbsolutePath());
        } catch (final NoSuchArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException("Failed to retrieve valid un-archiver component: " + a.getType(), a, e);
            }
        } catch (final ArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException("Failed to unpack: " + a.getId(), a, e);
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Collection(java.util.Collection) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Aggregations

ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)108 File (java.io.File)46 Artifact (org.apache.maven.artifact.Artifact)26 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)26 ArrayList (java.util.ArrayList)23 MavenProject (org.apache.maven.project.MavenProject)20 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 IOException (java.io.IOException)13 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)13 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)11 Properties (java.util.Properties)10 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)9 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)9 Model (org.apache.maven.model.Model)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)8 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7