Search in sources :

Example 91 with ArtifactRepository

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

the class DeployFileMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (uniqueVersion != null) {
        throw new MojoExecutionException("You are using 'uniqueVersion' which has been removed" + " from the maven-deploy-plugin. " + "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site.");
    }
    failIfOffline();
    if (!file.exists()) {
        throw new MojoExecutionException(file.getPath() + " not found.");
    }
    initProperties();
    ArtifactRepository deploymentRepository = createDeploymentArtifactRepository(repositoryId, url);
    String protocol = deploymentRepository.getProtocol();
    if (StringUtils.isEmpty(protocol)) {
        throw new MojoExecutionException("No transfer protocol found.");
    }
    MavenProject project = createMavenProject();
    Artifact artifact = project.getArtifact();
    if (file.equals(getLocalRepoFile())) {
        throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
    }
    List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
    if (classifier == null) {
        artifact.setFile(file);
        deployableArtifacts.add(artifact);
    } else {
        projectHelper.attachArtifact(project, packaging, classifier, file);
    }
    // Upload the POM if requested, generating one if need be
    if (!"pom".equals(packaging)) {
        File pom = pomFile;
        if (pom == null && generatePom) {
            pom = generatePomFile();
        }
        if (pom != null) {
            if (classifier == null) {
                ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pom);
                artifact.addMetadata(metadata);
            } else {
                artifact.setFile(pom);
                deployableArtifacts.add(artifact);
            }
        }
    }
    if (updateReleaseInfo) {
        artifact.setRelease(true);
    }
    artifact.setRepository(deploymentRepository);
    if (sources != null) {
        projectHelper.attachArtifact(project, "jar", "sources", sources);
    }
    if (javadoc != null) {
        projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
    }
    if (files != null) {
        if (types == null) {
            throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
        }
        if (classifiers == null) {
            throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
        }
        int filesLength = StringUtils.countMatches(files, ",");
        int typesLength = StringUtils.countMatches(types, ",");
        int classifiersLength = StringUtils.countMatches(classifiers, ",");
        if (typesLength != filesLength) {
            throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
        }
        if (classifiersLength != filesLength) {
            throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
        }
        int fi = 0;
        int ti = 0;
        int ci = 0;
        for (int i = 0; i <= filesLength; i++) {
            int nfi = files.indexOf(',', fi);
            if (nfi == -1) {
                nfi = files.length();
            }
            int nti = types.indexOf(',', ti);
            if (nti == -1) {
                nti = types.length();
            }
            int nci = classifiers.indexOf(',', ci);
            if (nci == -1) {
                nci = classifiers.length();
            }
            File file = new File(files.substring(fi, nfi));
            if (!file.isFile()) {
                // try relative to the project basedir just in case
                file = new File(project.getBasedir(), files.substring(fi, nfi));
            }
            if (file.isFile()) {
                if (StringUtils.isWhitespace(classifiers.substring(ci, nci))) {
                    projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), file);
                } else {
                    projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), classifiers.substring(ci, nci).trim(), file);
                }
            } else {
                throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
            }
            fi = nfi + 1;
            ti = nti + 1;
            ci = nci + 1;
        }
    } else {
        if (types != null) {
            throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
        }
        if (classifiers != null) {
            throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
        }
    }
    List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
    for (Artifact attached : attachedArtifacts) {
        deployableArtifacts.add(attached);
    }
    try {
        artifactDeployer.deploy(getSession().getProjectBuildingRequest(), deploymentRepository, deployableArtifacts);
    } catch (ArtifactDeployerException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProject(org.apache.maven.project.MavenProject) ArtifactDeployerException(org.apache.maven.shared.artifact.deploy.ArtifactDeployerException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 92 with ArtifactRepository

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

the class MavenProject4CopyConstructor method initializeParentFields.

// to prevent the MavenProject copy constructor from blowing up
private void initializeParentFields() {
    // the pom should be located in the isolated dummy root
    super.setFile(new File(getBasedir(), "pom.xml"));
    super.setDependencyArtifacts(new HashSet<Artifact>());
    super.setArtifacts(new HashSet<Artifact>());
    super.setExtensionArtifacts(new HashSet<Artifact>());
    super.setRemoteArtifactRepositories(new LinkedList<ArtifactRepository>());
    super.setPluginArtifactRepositories(new LinkedList<ArtifactRepository>());
    super.setCollectedProjects(new LinkedList<MavenProject>());
    super.setActiveProfiles(new LinkedList<Profile>());
    super.setOriginalModel(null);
    super.setExecutionProject(this);
    super.setBuild(getBuild());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) Profile(org.apache.maven.model.Profile)

Example 93 with ArtifactRepository

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

the class DefaultDependencyResolver method aggregateRemoteArtifactRepositories.

List<ArtifactRepository> aggregateRemoteArtifactRepositories(final List<ArtifactRepository> remoteRepositories, final Set<MavenProject> projects) {
    final List<List<ArtifactRepository>> repoLists = new ArrayList<List<ArtifactRepository>>();
    repoLists.add(remoteRepositories);
    for (final MavenProject project : projects) {
        repoLists.add(project.getRemoteArtifactRepositories());
    }
    final List<ArtifactRepository> remoteRepos = new ArrayList<ArtifactRepository>();
    final Set<String> encounteredUrls = new HashSet<String>();
    for (final List<ArtifactRepository> repositoryList : repoLists) {
        if ((repositoryList != null) && !repositoryList.isEmpty()) {
            for (final ArtifactRepository repo : repositoryList) {
                if (!encounteredUrls.contains(repo.getUrl())) {
                    remoteRepos.add(repo);
                    encounteredUrls.add(repo.getUrl());
                }
            }
        }
    }
    return remoteRepos;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 94 with ArtifactRepository

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

the class DefaultDependencyResolver method resolve.

private void resolve(Assembly assembly, AssemblerConfigurationSource configSource, Map<DependencySet, Set<Artifact>> result, DependencySet dependencySet, ResolutionManagementInfo info) throws DependencyResolutionException {
    Set<Artifact> artifacts;
    if (info.isResolutionRequired()) {
        final List<ArtifactRepository> repos = aggregateRemoteArtifactRepositories(configSource.getRemoteRepositories(), info.getEnabledProjects());
        artifacts = info.getArtifacts();
        if (info.isResolvedTransitively()) {
            getLogger().debug("Resolving project dependencies transitively.");
            ArtifactFilter filter = new ArtifactIncludeFilterTransformer().transform(info.getScopeFilter());
            artifacts = resolveTransitively(artifacts, repos, filter, configSource);
        } else {
            getLogger().debug("Resolving project dependencies ONLY. " + "Transitive dependencies WILL NOT be included in the results.");
            artifacts = resolveNonTransitively(assembly, artifacts, configSource, repos);
        }
    } else {
        artifacts = new HashSet<Artifact>();
    }
    result.put(dependencySet, artifacts);
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 95 with ArtifactRepository

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

the class GetMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("Skipping plugin execution");
        return;
    }
    if (coordinate.getArtifactId() == null && artifact == null) {
        throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
    }
    if (artifact != null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length < 3 || tokens.length > 5) {
            throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        coordinate.setGroupId(tokens[0]);
        coordinate.setArtifactId(tokens[1]);
        coordinate.setVersion(tokens[2]);
        if (tokens.length >= 4) {
            coordinate.setType(tokens[3]);
        }
        if (tokens.length == 5) {
            coordinate.setClassifier(tokens[4]);
        }
    }
    ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
    if (pomRemoteRepositories != null) {
        repoList.addAll(pomRemoteRepositories);
    }
    if (remoteRepositories != null) {
        // Use the same format as in the deploy plugin id::layout::url
        List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
        for (String repo : repos) {
            repoList.add(parseRepository(repo, always));
        }
    }
    try {
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(repoList);
        if (transitive) {
            getLog().info("Resolving " + coordinate + " with transitive dependencies");
            dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
        } else {
            getLog().info("Resolving " + coordinate);
            artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
        }
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    } catch (DependencyResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

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