Example usage for org.apache.maven.artifact.repository.metadata GroupRepositoryMetadata addPluginMapping

List of usage examples for org.apache.maven.artifact.repository.metadata GroupRepositoryMetadata addPluginMapping

Introduction

In this page you can find the example usage for org.apache.maven.artifact.repository.metadata GroupRepositoryMetadata addPluginMapping.

Prototype

public void addPluginMapping(String goalPrefix, String artifactId, String name) 

Source Link

Usage

From source file:hudson.gridmaven.reporters.MavenArtifactRecord.java

License:Open Source License

@Override
public void deploy(MavenEmbedder embedder, ArtifactRepository deploymentRepository, TaskListener listener)
        throws MavenEmbedderException, IOException, ComponentLookupException, ArtifactDeploymentException {
    ArtifactHandlerManager handlerManager = embedder.lookup(ArtifactHandlerManager.class);

    ArtifactFactory artifactFactory = embedder.lookup(ArtifactFactory.class);
    PrintStream logger = listener.getLogger();
    boolean maven3orLater = MavenUtil.maven3orLater(parent.getModuleSetBuild().getMavenVersionUsed());
    boolean uniqueVersion = true;
    if (!deploymentRepository.isUniqueVersion()) {
        if (maven3orLater) {
            logger.println("[ERROR] uniqueVersion == false is not anymore supported in maven 3");
        } else {//from  w  ww.  j ava  2s.com
            ((WrappedArtifactRepository) deploymentRepository).setUniqueVersion(false);
            uniqueVersion = false;
        }
    } else {
        ((WrappedArtifactRepository) deploymentRepository).setUniqueVersion(true);
    }
    Artifact main = mainArtifact.toArtifact(handlerManager, artifactFactory, parent);
    if (!isPOM())
        main.addMetadata(new ProjectArtifactMetadata(main, pomArtifact.getFile(parent)));

    if (main.getType().equals("maven-plugin")) {
        GroupRepositoryMetadata metadata = new GroupRepositoryMetadata(main.getGroupId());
        String goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(main.getArtifactId());
        metadata.addPluginMapping(goalPrefix, main.getArtifactId(), null);
        main.addMetadata(metadata);
    }

    ArtifactDeployer deployer = embedder.lookup(ArtifactDeployer.class, uniqueVersion ? "default" : "maven2");
    logger.println("[INFO] Deployment in " + deploymentRepository.getUrl() + " (id="
            + deploymentRepository.getId() + ",uniqueVersion=" + deploymentRepository.isUniqueVersion() + ")");

    // deploy the main artifact. This also deploys the POM
    logger.println(Messages.MavenArtifact_DeployingMainArtifact(main.getFile().getName()));
    deployer.deploy(main.getFile(), main, deploymentRepository, embedder.getLocalRepository());

    for (MavenArtifact aa : attachedArtifacts) {
        Artifact a = aa.toArtifact(handlerManager, artifactFactory, parent);
        logger.println(Messages.MavenArtifact_DeployingMainArtifact(a.getFile().getName()));
        deployer.deploy(a.getFile(), a, deploymentRepository, embedder.getLocalRepository());
    }
}

From source file:io.takari.maven.plugins.plugin.AddPluginArtifactMetadataMojo.java

License:Apache License

@Override
protected void executeMojo() throws MojoExecutionException {
    Artifact projectArtifact = project.getArtifact();

    Versioning versioning = new Versioning();
    versioning.setLatest(projectArtifact.getVersion());
    versioning.updateTimestamp();/*from   ww  w . ja v  a  2 s .  c o  m*/
    ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(projectArtifact, versioning);
    projectArtifact.addMetadata(metadata);

    GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata(project.getGroupId());
    groupMetadata.addPluginMapping(getGoalPrefix(), project.getArtifactId(), project.getName());

    projectArtifact.addMetadata(groupMetadata);
}

From source file:net.oneandone.maven.embedded.Maven.java

License:Apache License

/**
 * You'll usually pass one jar artifact and the corresponding pom artifact.
 * @param pluginName null if you deploy normal artifacts; none-null for Maven Plugins, that you wish to add a plugin mapping for;
 *                   specifies the plugin name in this case.
 *                   See http://svn.apache.org/viewvc/maven/plugin-tools/tags/maven-plugin-tools-3.2/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java?revision=1406624&view=markup
 *//*from   w  w  w .  j av  a  2 s  .  co m*/
// CHECKSTYLE:ON
public void deploy(RemoteRepository target, String pluginName, List<Artifact> artifacts)
        throws DeploymentException {
    DeployRequest request;
    GroupRepositoryMetadata gm;
    String prefix;

    request = new DeployRequest();
    for (Artifact artifact : artifacts) {
        if (artifact.getFile() == null) {
            throw new IllegalArgumentException(artifact.toString() + " without file");
        }
        request.addArtifact(artifact);
        if (pluginName != null) {
            gm = new GroupRepositoryMetadata(artifact.getGroupId());
            prefix = getGoalPrefixFromArtifactId(artifact.getArtifactId());
            gm.addPluginMapping(prefix, artifact.getArtifactId(), pluginName);
            request.addMetadata(new MetadataBridge(gm));
        }
    }
    request.setRepository(target);
    repositorySystem.deploy(repositorySession, request);
}

From source file:net.oneandone.maven.plugins.prerelease.util.PromoteExecutionListener.java

License:Apache License

@Override
public void projectStarted(ExecutionEvent event) {
    MavenProject project;//from  w w w  . jav a 2  s.c  om
    Artifact projectArtifact;
    Versioning versioning;
    ArtifactRepositoryMetadata metadata;
    GroupRepositoryMetadata groupMetadata;

    project = event.getSession().getCurrentProject();
    try {
        prerelease.artifactFiles(project, projectHelper);
        project.getProperties().putAll(prerelease.descriptor.deployProperties);
        if (prerelease.descriptor.deployPluginMetadata) {
            // from http://svn.apache.org/viewvc/maven/plugin-tools/tags/maven-plugin-tools-3.2/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java

            projectArtifact = project.getArtifact();
            versioning = new Versioning();
            versioning.setLatest(projectArtifact.getVersion());
            versioning.updateTimestamp();
            metadata = new ArtifactRepositoryMetadata(projectArtifact, versioning);
            projectArtifact.addMetadata(metadata);
            groupMetadata = new GroupRepositoryMetadata(project.getGroupId());
            groupMetadata.addPluginMapping(
                    PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId()),
                    project.getArtifactId(), project.getName());

            projectArtifact.addMetadata(groupMetadata);
        }
    } catch (IOException e) {
        throw new RuntimeException("TODO", e);
    }
    super.projectStarted(event);
}

From source file:org.sonatype.nexus.maven.staging.deploy.strategy.AbstractDeployStrategy.java

License:Open Source License

protected void deployUp(final MavenSession mavenSession, final File sourceDirectory,
        ArtifactRepository remoteRepository) throws ArtifactDeploymentException, IOException {
    // I'd need Aether RepoSystem and create one huge DeployRequest will _all_ artifacts (would be FAST as it would
    // go parallel), but we need to work in Maven2 too, so old compat and slow method remains: deploy one by one...
    final FileInputStream fis = new FileInputStream(new File(sourceDirectory, ".index"));
    final Properties index = new Properties();
    try {/*from ww  w.jav a 2s.  c  o  m*/
        index.load(fis);
    } finally {
        Closeables.closeQuietly(fis);
    }
    ArtifactRepository repoToUse = remoteRepository;
    for (String includedFilePath : index.stringPropertyNames()) {
        final File includedFile = new File(sourceDirectory, includedFilePath);
        final String includedFileProps = index.getProperty(includedFilePath);
        final Matcher matcher = indexProps.matcher(includedFileProps);
        if (!matcher.matches()) {
            throw new ArtifactDeploymentException("Internal error! Line \"" + includedFileProps
                    + "\" does not match pattern \"" + indexProps.toString() + "\"?");
        }

        final String groupId = matcher.group(1);
        final String artifactId = matcher.group(2);
        final String version = matcher.group(3);
        final String classifier = "n/a".equals(matcher.group(4)) ? null : matcher.group(4);
        final String packaging = matcher.group(5);
        final String extension = matcher.group(6);
        final String pomFileName = "n/a".equals(matcher.group(7)) ? null : matcher.group(7);
        final String pluginPrefix = "n/a".equals(matcher.group(8)) ? null : matcher.group(8);
        final String repoId = "n/a".equals(matcher.group(9)) ? null : matcher.group(9);
        final String repoUrl = "n/a".equals(matcher.group(10)) ? null : matcher.group(10);
        if (remoteRepository == null) {
            if (repoUrl != null && repoId != null) {
                repoToUse = createDeploymentArtifactRepository(repoId, repoUrl);
            } else {
                throw new ArtifactDeploymentException(
                        "Internal error! Remote repository for deployment not defined.");
            }
        }

        // just a synthetic one, to properly set extension
        final FakeArtifactHandler artifactHandler = new FakeArtifactHandler(packaging, extension);

        final DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId,
                VersionRange.createFromVersion(version), null, packaging, classifier, artifactHandler);
        if (pomFileName != null) {
            final File pomFile = new File(includedFile.getParentFile(), pomFileName);
            final ProjectArtifactMetadata pom = new ProjectArtifactMetadata(artifact, pomFile);
            artifact.addMetadata(pom);
            if ("maven-plugin".equals(artifact.getType())) {
                // So, we have a "main" artifact with type of "maven-plugin"
                // Hence, this is a Maven Plugin, Group level MD needs to be added too
                final GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata(groupId);
                // TODO: we "simulate" the name with artifactId, same what maven-plugin-plugin
                // would do. Impact is minimal, as we don't know any tool that _uses_ the name
                // from Plugin entries. Once the "index file" is properly solved,
                // or, we are able to properly persist Artifact instances above
                // (to preserve attached metadatas like this G level, and reuse
                // deployer without reimplementing it), all this will become unneeded.
                groupMetadata.addPluginMapping(pluginPrefix, artifactId, artifactId);
                artifact.addMetadata(groupMetadata);
            }
        }
        artifactDeployer.deploy(includedFile, artifact, repoToUse, mavenSession.getLocalRepository());
    }
}