List of usage examples for org.apache.maven.artifact.repository.metadata GroupRepositoryMetadata GroupRepositoryMetadata
public GroupRepositoryMetadata(String groupId)
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 a v a 2 s. c om*/ ((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: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 *//* w w w .ja v a 2 s . c om*/ // 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;// ww w . java2 s. co 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.codehaus.mojo.mockrepo.ProxyRepository.java
License:Apache License
public Metadata getMetadata(String path) { if (StringUtils.isEmpty(path) || path.length() < 13) { return null; }//from ww w . j a v a 2 s . c om String coordPath = StringUtils.chompLast(path, "/metadata.xml"); int index = coordPath.lastIndexOf('/'); String artifactId = index == -1 ? null : coordPath.substring(index + 1); String groupId = index == -1 ? null : coordPath.substring(0, index); String pluginGroupId = coordPath.replace('/', '.'); Metadata metadata = new Metadata(); // is this path a groupId:artifactId pair? if (!StringUtils.isEmpty(artifactId) && !StringUtils.isEmpty(groupId)) { final Artifact artifact = artifactFactory.createDependencyArtifact(groupId, artifactId, anyVersion, "pom", null, "compile"); final ArtifactRepositoryMetadata artifactRepositoryMetadata = new ArtifactRepositoryMetadata(artifact); try { repositoryMetadataManager.resolve(artifactRepositoryMetadata, remoteRepositories, localRepository); final Metadata artifactMetadata = artifactRepositoryMetadata.getMetadata(); if (artifactMetadata.getVersioning() != null) { metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); metadata.merge(artifactMetadata); } } catch (RepositoryMetadataResolutionException e) { log.debug(e); } } // if this path a groupId on its own? final GroupRepositoryMetadata groupRepositoryMetadata = new GroupRepositoryMetadata(pluginGroupId); try { repositoryMetadataManager.resolve(groupRepositoryMetadata, remotePluginRepositories, localRepository); metadata.merge(groupRepositoryMetadata.getMetadata()); } catch (RepositoryMetadataResolutionException e) { log.debug(e); } return metadata; }
From source file:org.codehaus.mojo.mrm.maven.ProxyArtifactStore.java
License:Apache License
/** * {@inheritDoc}/*from w w w . ja va 2 s . c o m*/ */ public Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { path = StringUtils.strip(path, "/"); int index = path.lastIndexOf('/'); int index2 = index == -1 ? -1 : path.lastIndexOf('/', index - 1); String version = index2 == -1 ? null : path.substring(index + 1); String artifactId = index2 == -1 ? null : path.substring(index2 + 1, index); String groupId = index2 == -1 ? null : path.substring(0, index2).replace('/', '.'); Metadata metadata = new Metadata(); boolean foundSomething = false; // is this path a groupId:artifactId pair? if (version != null && version.endsWith("-SNAPSHOT") && !StringUtils.isEmpty(artifactId) && !StringUtils.isEmpty(groupId)) { final org.apache.maven.artifact.Artifact artifact = artifactFactory.createDependencyArtifact(groupId, artifactId, VersionRange.createFromVersion(version), "pom", null, "compile"); final SnapshotArtifactRepositoryMetadata artifactRepositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact); try { repositoryMetadataManager.resolve(artifactRepositoryMetadata, remoteRepositories, localRepository); final Metadata artifactMetadata = artifactRepositoryMetadata.getMetadata(); if (artifactMetadata.getVersioning() != null && artifactMetadata.getVersioning().getSnapshot() != null) { foundSomething = true; metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); metadata.setVersion(version); metadata.merge(artifactMetadata); } try { if (artifactMetadata.getVersioning() != null && !artifactMetadata.getVersioning().getSnapshotVersions().isEmpty()) { // TODO up to and including Maven 3.0.3 we do not get a populated SnapshotVersions for (SnapshotVersion v : artifactMetadata.getVersioning().getSnapshotVersions()) { metadata.getVersioning().addSnapshotVersion(v); if (v.getVersion().endsWith("-SNAPSHOT")) { addResolved(new Artifact(groupId, artifactId, version, v.getClassifier(), v.getExtension())); } } } } catch (NoSuchMethodError e) { // ignore Maven 2.x doesn't give us the info } } catch (RepositoryMetadataResolutionException e) { log.debug(e); } } // is this path a groupId:artifactId pair? artifactId = index == -1 ? null : path.substring(index + 1); groupId = index == -1 ? null : path.substring(0, index).replace('/', '.'); if (!StringUtils.isEmpty(artifactId) && !StringUtils.isEmpty(groupId)) { final org.apache.maven.artifact.Artifact artifact = artifactFactory.createDependencyArtifact(groupId, artifactId, anyVersion, "pom", null, "compile"); final ArtifactRepositoryMetadata artifactRepositoryMetadata = new ArtifactRepositoryMetadata(artifact); try { repositoryMetadataManager.resolve(artifactRepositoryMetadata, remoteRepositories, localRepository); final Metadata artifactMetadata = artifactRepositoryMetadata.getMetadata(); if (artifactMetadata.getVersioning() != null) { foundSomething = true; if (StringUtils.isEmpty(metadata.getGroupId())) { metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); } metadata.merge(artifactMetadata); for (String v : artifactMetadata.getVersioning().getVersions()) { addResolved(path + "/" + v); } } } catch (RepositoryMetadataResolutionException e) { log.debug(e); } } // if this path a groupId on its own? groupId = path.replace('/', '.'); final GroupRepositoryMetadata groupRepositoryMetadata = new GroupRepositoryMetadata(groupId); try { repositoryMetadataManager.resolve(groupRepositoryMetadata, remotePluginRepositories, localRepository); foundSomething = true; metadata.merge(groupRepositoryMetadata.getMetadata()); for (Plugin plugin : groupRepositoryMetadata.getMetadata().getPlugins()) { addResolved(path + "/" + plugin.getArtifactId()); } } catch (RepositoryMetadataResolutionException e) { log.debug(e); } if (!foundSomething) { throw new MetadataNotFoundException(path); } addResolved(path); return metadata; }
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 w w w . ja v a 2 s. co 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()); } }