List of usage examples for org.apache.maven.artifact DefaultArtifact getType
public String getType()
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 www . ja v a 2s. com 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()); } }