Example usage for org.apache.maven.project MavenProject getRemoteArtifactRepositories

List of usage examples for org.apache.maven.project MavenProject getRemoteArtifactRepositories

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getRemoteArtifactRepositories.

Prototype

public List<ArtifactRepository> getRemoteArtifactRepositories() 

Source Link

Usage

From source file:org.deegree.maven.utils.ClasspathHelper.java

License:Open Source License

private static Set<?> resolveDeps(MavenProject project, ArtifactResolver artifactResolver,
        ArtifactFactory artifactFactory, ArtifactMetadataSource metadataSource,
        ArtifactRepository localRepository)
        throws InvalidDependencyVersionException, ArtifactResolutionException, ArtifactNotFoundException {

    List<?> dependencies = project.getDependencies();

    Set<Artifact> dependencyArtifacts = createArtifacts(artifactFactory, dependencies, null, null, null);

    dependencyArtifacts.add(project.getArtifact());

    ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts,
            project.getArtifact(), EMPTY_MAP, localRepository, project.getRemoteArtifactRepositories(),
            metadataSource, null, EMPTY_LIST);

    return result.getArtifacts();
}

From source file:org.echocat.jomon.maven.boot.ArtifactFactory.java

License:Mozilla Public License

@Nonnull
protected ArtifactResolutionRequest createRequestFor(@Nonnull MavenProject project,
        @Nonnull Artifact artifact) {// w  w  w. ja  v a 2 s  .  c o m
    final MavenExecutionRequest request = _containerAndRequest.getRequest();
    final ArtifactResolutionRequest result = new ArtifactResolutionRequest();
    result.setArtifact(artifact);
    result.setLocalRepository(getLocalRepository());
    result.setRemoteRepositories(project.getRemoteArtifactRepositories());
    result.setServers(request.getServers());
    result.setOffline(request.isOffline());
    result.setMirrors(request.getMirrors());
    result.setProxies(request.getProxies());
    return result;
}

From source file:org.echocat.jomon.maven.boot.ArtifactFactory.java

License:Mozilla Public License

@Nonnull
protected String getLatestVersionOf(@Nonnull MavenProject project, @Nonnull Artifact artifact)
        throws ArtifactResolutionException {
    String latestVersion = null;//ww  w  . j  a va2  s  . com
    try {
        final ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata(artifact);
        _repositoryMetadataManager.resolve(repositoryMetadata, project.getRemoteArtifactRepositories(),
                getLocalRepository());
        latestVersion = selectLatestMatchingVersion(repositoryMetadata, artifact);
    } catch (final Exception ignored) {
    }

    if (latestVersion == null || latestVersion.isEmpty()) {
        throw new ArtifactResolutionException(
                "Could not find a version in the remote repositories but also no latestVersion in the local repository. Stop resolving now.",
                artifact);
    }
    return latestVersion;
}

From source file:org.eclipse.che.maven.server.MavenServerImpl.java

License:Open Source License

private MavenResult internalResolveProject(File pom, List<String> activeProfiles, List<String> inactiveProfiles,
        List<ResolutionListener> dependencyTreeResolutionListeners) {

    MavenExecutionRequest request = newMavenRequest(pom, activeProfiles, inactiveProfiles,
            Collections.emptyList());
    request.setUpdateSnapshots(updateSnapshots);

    AtomicReference<MavenResult> reference = new AtomicReference<>();
    runMavenRequest(request, () -> {/*from w  w w.  j  a  v a  2s  .  c o m*/
        try {
            ProjectBuilder builder = getMavenComponent(ProjectBuilder.class);

            List<ProjectBuildingResult> resultList = builder.build(Collections.singletonList(pom), false,
                    request.getProjectBuildingRequest());
            ProjectBuildingResult result = resultList.get(0);
            MavenProject mavenProject = result.getProject();
            RepositorySystemSession repositorySession = getMavenComponent(LegacySupport.class)
                    .getRepositorySession();
            if (repositorySession instanceof DefaultRepositorySystemSession) {
                ((DefaultRepositorySystemSession) repositorySession)
                        .setTransferListener(new ArtifactTransferListener(mavenProgressNotifier));
                if (workspaceCache != null) {
                    ((DefaultRepositorySystemSession) repositorySession)
                            .setWorkspaceReader(new MavenWorkspaceReader(workspaceCache));
                }

            }

            List<Exception> exceptions = new ArrayList<>();

            loadExtensions(mavenProject, exceptions);
            mavenProject.setDependencyArtifacts(
                    mavenProject.createArtifacts(getMavenComponent(ArtifactFactory.class), null, null));

            ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
            resolutionRequest.setArtifact(mavenProject.getArtifact());
            resolutionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
            resolutionRequest.setArtifactDependencies(mavenProject.getDependencyArtifacts());
            resolutionRequest.setListeners(dependencyTreeResolutionListeners);
            resolutionRequest.setLocalRepository(localRepo);
            resolutionRequest.setManagedVersionMap(mavenProject.getManagedVersionMap());
            resolutionRequest.setResolveTransitively(true);
            resolutionRequest.setResolveRoot(false);
            ArtifactResolver resolver = getMavenComponent(ArtifactResolver.class);
            ArtifactResolutionResult resolve = resolver.resolve(resolutionRequest);
            mavenProject.setArtifacts(resolve.getArtifacts());
            reference.set(new MavenResult(mavenProject, exceptions));

        } catch (Exception e) {
            reference.set(new MavenResult(null, null, Collections.singletonList(e)));
        }
    });
    return reference.get();
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java

License:Open Source License

MavenProject resolveParentProject(RepositorySystemSession repositorySession, MavenProject child,
        ProjectBuildingRequest configuration) throws CoreException {
    configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    configuration.setRepositorySession(repositorySession);

    try {/*from   w  w w  .j  a v  a  2s .  com*/
        configuration.setRemoteRepositories(child.getRemoteArtifactRepositories());

        File parentFile = child.getParentFile();
        if (parentFile != null) {
            return lookup(ProjectBuilder.class).build(parentFile, configuration).getProject();
        }

        Artifact parentArtifact = child.getParentArtifact();
        if (parentArtifact != null) {
            return lookup(ProjectBuilder.class).build(parentArtifact, configuration).getProject();
        }
    } catch (ProjectBuildingException ex) {
        log.error("Could not read parent project", ex);
    }

    return null;
}

From source file:org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.java

License:Open Source License

/**
 * Returns metadata sources referenced by this project in the order they are specified in pom.xml. Returns empty list
 * if no metadata sources are referenced in pom.xml.
 *//*from ww  w .j a v  a2 s  . c  o m*/
private static List<LifecycleMappingMetadataSource> getReferencedMetadataSources(Set<String> referenced,
        MavenProject mavenProject, IProgressMonitor monitor) throws CoreException {
    List<LifecycleMappingMetadataSource> metadataSources = new ArrayList<LifecycleMappingMetadataSource>();

    PluginManagement pluginManagement = getPluginManagement(mavenProject);
    for (Plugin plugin : pluginManagement.getPlugins()) {
        if (!LIFECYCLE_MAPPING_PLUGIN_KEY.equals(plugin.getKey())) {
            continue;
        }
        Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
        if (configuration != null) {
            checkCompatibleVersion(plugin);
            Xpp3Dom sources = configuration.getChild(ELEMENT_SOURCES);
            if (sources != null) {
                for (Xpp3Dom source : sources.getChildren(ELEMENT_SOURCE)) {
                    String groupId = null;
                    Xpp3Dom child = source.getChild(ATTR_GROUPID);
                    if (child != null) {
                        groupId = child.getValue();
                    }
                    String artifactId = null;
                    child = source.getChild(ATTR_ARTIFACTID);
                    if (child != null) {
                        artifactId = child.getValue();
                    }
                    String version = null;
                    child = source.getChild(ATTR_VERSION);
                    if (child != null) {
                        version = child.getValue();
                    }
                    if (referenced.add(groupId + ":" + artifactId)) {
                        try {
                            LifecycleMappingMetadataSource lifecycleMappingMetadataSource = getLifecycleMappingMetadataSource(
                                    groupId, artifactId, version, mavenProject.getRemoteArtifactRepositories(),
                                    monitor);
                            metadataSources.add(lifecycleMappingMetadataSource);
                        } catch (LifecycleMappingConfigurationException e) {
                            SourceLocation location = SourceLocationHelper.findLocation(plugin,
                                    SourceLocationHelper.CONFIGURATION);
                            e.setLocation(location);
                            throw e;
                        }
                    }
                }
            }
        }
    }

    return metadataSources;
}

From source file:org.eclipse.m2e.core.internal.project.registry.MavenProjectFacade.java

License:Open Source License

public MavenProjectFacade(ProjectRegistryManager manager, IFile pom, MavenProject mavenProject,
        Map<String, List<MojoExecution>> executionPlans, ResolverConfiguration resolverConfiguration) {
    this.manager = manager;
    this.pom = pom;
    IPath location = pom.getLocation();/*  ww w  .  ja  va2  s. c  om*/
    this.pomFile = location == null ? null : location.toFile(); // save pom file
    this.resolverConfiguration = resolverConfiguration;

    this.mavenProject = mavenProject;
    this.executionPlans = executionPlans;

    this.artifactKey = new ArtifactKey(mavenProject.getArtifact());
    this.packaging = mavenProject.getPackaging();
    this.modules = mavenProject.getModules();

    this.resourceLocations = MavenProjectUtils.getResourceLocations(getProject(), mavenProject.getResources());
    this.testResourceLocations = MavenProjectUtils.getResourceLocations(getProject(),
            mavenProject.getTestResources());
    this.compileSourceLocations = MavenProjectUtils.getSourceLocations(getProject(),
            mavenProject.getCompileSourceRoots());
    this.testCompileSourceLocations = MavenProjectUtils.getSourceLocations(getProject(),
            mavenProject.getTestCompileSourceRoots());

    IPath fullPath = getProject().getFullPath();

    IPath path = getProjectRelativePath(mavenProject.getBuild().getOutputDirectory());
    this.outputLocation = (path != null) ? fullPath.append(path) : null;

    path = getProjectRelativePath(mavenProject.getBuild().getTestOutputDirectory());
    this.testOutputLocation = path != null ? fullPath.append(path) : null;

    this.artifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>();
    for (ArtifactRepository repository : mavenProject.getRemoteArtifactRepositories()) {
        this.artifactRepositories.add(new ArtifactRepositoryRef(repository));
    }

    this.pluginArtifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>();
    for (ArtifactRepository repository : mavenProject.getPluginArtifactRepositories()) {
        this.pluginArtifactRepositories.add(new ArtifactRepositoryRef(repository));
    }

    setMavenProjectArtifacts();

    updateTimestamp();
}

From source file:org.eclipse.m2e.jdt.internal.BuildPathManager.java

License:Open Source License

private void scheduleDownload(IProject project, MavenProject mavenProject, ArtifactKey artifact,
        boolean downloadSources, boolean downloadJavadoc) throws CoreException {
    ArtifactKey[] attached = getAttachedSourcesAndJavadoc(artifact,
            mavenProject.getRemoteArtifactRepositories(), downloadSources, downloadJavadoc);

    if (attached[0] != null || attached[1] != null) {
        downloadSourcesJob.scheduleDownload(project, artifact, downloadSources, downloadJavadoc);
    }//w w w  . j a  v  a  2s  .co  m
}

From source file:org.eclipse.m2e.jdt.internal.DownloadSourcesJob.java

License:Open Source License

private void downloadMaven(IMavenProjectFacade projectFacade, ArtifactKey artifact, boolean downloadSources,
        boolean downloadJavadoc, IProgressMonitor monitor) throws CoreException {
    MavenProject mavenProject = projectFacade.getMavenProject(monitor);
    List<ArtifactRepository> repositories = mavenProject.getRemoteArtifactRepositories();

    if (artifact != null) {
        downloadAttachments(artifact, repositories, downloadSources, downloadJavadoc, monitor);
    } else {//from   w  w w . ja va 2 s . c om
        for (Artifact a : mavenProject.getArtifacts()) {
            ArtifactKey aKey = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(),
                    a.getClassifier());
            downloadAttachments(aKey, repositories, downloadSources, downloadJavadoc, monitor);
        }
    }
}

From source file:org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader.java

License:Open Source License

private void setTarget(TargetPlatformConfiguration result, MavenSession session, MavenProject project,
        Xpp3Dom configuration) {/*from   ww w  . ja v  a2 s  .c  om*/
    Xpp3Dom targetDom = configuration.getChild("target");
    if (targetDom == null) {
        return;
    }

    Xpp3Dom artifactDom = targetDom.getChild("artifact");
    if (artifactDom == null) {
        return;
    }

    Xpp3Dom groupIdDom = artifactDom.getChild("groupId");
    Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId");
    Xpp3Dom versionDom = artifactDom.getChild("version");
    if (groupIdDom == null || artifactIdDom == null || versionDom == null) {
        return;
    }
    Xpp3Dom classifierDom = artifactDom.getChild("classifier");

    String groupId = groupIdDom.getValue();
    String artifactId = artifactIdDom.getValue();
    String version = versionDom.getValue();
    String classifier = classifierDom != null ? classifierDom.getValue() : null;

    File targetFile = null;
    for (MavenProject otherProject : session.getProjects()) {
        if (groupId.equals(otherProject.getGroupId()) && artifactId.equals(otherProject.getArtifactId())
                && version.equals(otherProject.getVersion())) {
            targetFile = new File(otherProject.getBasedir(), classifier + ".target");
            break;
        }
    }

    if (targetFile == null) {
        Artifact artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version,
                "target", classifier);
        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(project.getRemoteArtifactRepositories());
        repositorySystem.resolve(request);

        if (!artifact.isResolved()) {
            throw new RuntimeException("Could not resolve target platform specification artifact " + artifact);
        }

        targetFile = artifact.getFile();
    }

    result.setTarget(targetFile);
}