List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptor getGoalPrefixFromArtifactId
public static String getGoalPrefixFromArtifactId(String artifactId)
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 w w . j av a 2 s. c o m ((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
/** * @return the goal prefix parameter or the goal prefix from the Plugin artifactId. *///from w w w . j a v a2 s .c o m private String getGoalPrefix() { if (goalPrefix == null) { goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId()); } return goalPrefix; }
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.j a va2 s. c o m 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.artifactory.maven.MavenPluginsMetadataCalculator.java
License:Open Source License
/** * Calculate maven metadata using folder as the base. * * @param localRepo Base folder to start calculating from. *//* www. ja v a2 s . c o m*/ public void calculate(LocalRepo localRepo) { if (!localRepo.isLocal() || localRepo.isCache()) { log.warn("Maven metadata calculation is allowed only on local non-cache repositories"); return; } log.debug("Calculating maven plugins metadata on repo '{}'", localRepo.getKey()); FileService fileService = ContextHelper.get().beanForType(FileService.class); List<FileInfo> pluginPoms = fileService.searchFilesByProperty(localRepo.getKey(), PropertiesService.MAVEN_PLUGIN_PROPERTY_NAME, Boolean.TRUE.toString()); log.debug("{} plugin poms found", pluginPoms.size()); // aggregate one pom for each plugin under the plugins metadata container HashMultimap<RepoPath, RepoPath> pluginsMetadataContainers = HashMultimap.create(); for (FileInfo pom : pluginPoms) { // great-grandparent is the plugins metadata container // eg, if the plugin pom is org/jfrog/maven/plugins/maven-test-plugin/1.0/maven-test-plugin-1.0.pom // the node that contains the plugins metadata is org/jfrog/maven/plugins RepoPath pluginsMetadataContainer = RepoPathUtils.getAncestor(pom.getRepoPath(), 3); if (pluginsMetadataContainer != null) { pluginsMetadataContainers.put(pluginsMetadataContainer, pom.getRepoPath()); } else { log.info("Found plugin pom without maven GAV path: '{}'. Ignoring...", pom.getRepoPath()); } } // for each plugins folder container, create plugins metadata on the parent Set<RepoPath> folders = pluginsMetadataContainers.keySet(); for (RepoPath pluginsMetadataContainer : folders) { //Metadata metadata = getOrCreatePluginMetadata(pluginsMetadataContainer); Metadata metadata = new Metadata(); for (RepoPath pomFile : pluginsMetadataContainers.get(pluginsMetadataContainer)) { String artifactId = RepoPathUtils.getAncestor(pomFile, 2).getName(); if (hasPlugin(metadata, artifactId)) { continue; } // extract the plugin details and add to the metadata String pomStr = getRepositoryService().getStringContent(pomFile); Model pomModel = MavenModelUtils.stringToMavenModel(pomStr); artifactId = pomModel.getArtifactId(); Plugin plugin = new Plugin(); plugin.setArtifactId(artifactId); plugin.setPrefix(PluginDescriptor.getGoalPrefixFromArtifactId(pomModel.getArtifactId())); String pluginName = pomModel.getName(); if (StringUtils.isBlank(pluginName)) { pluginName = "Unnamed - " + pomModel.getId(); } plugin.setName(pluginName); metadata.addPlugin(plugin); } // save only if something changed if (modified(getPluginMetadata(pluginsMetadataContainer), metadata)) { saveMetadata(pluginsMetadataContainer, metadata); } } log.debug("Finished maven plugins metadata calculation on '{}'", localRepo.getKey()); }