final File artifactDirectory = pomFile.getParentFile();
final MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
final Model model = xpp3Reader.read(reader);
// Make the deployer deploy the pom itself.
final DeployRequest artifactInstallRequest = new DeployRequest();
artifactInstallRequest.setRepository(remoteRepository);
Artifact pomArtifact = new DefaultArtifact(
model.getGroupId(), model.getArtifactId(), "pom", model.getVersion());
pomArtifact = pomArtifact.setFile(pomFile);
artifactInstallRequest.addArtifact(pomArtifact);
// Add any additional files to this installation.
final String artifactBaseName = model.getArtifactId() + "-" + model.getVersion();
final File artifactFiles[] = artifactDirectory.listFiles(new ArtifactFilter());
for (final File artifactFile : artifactFiles) {
final String fileName = artifactFile.getName();
// Handle the case that some file might not start with the base-name.
if(!fileName.startsWith(artifactBaseName)) {
continue;
}
final String classifier;
// This file has a classifier.
if (fileName.charAt(artifactBaseName.length()) == '-') {
classifier = fileName.substring(artifactBaseName.length() + 1,
fileName.indexOf(".", artifactBaseName.length()));
}
// This file doesn't have a classifier.
else {
classifier = "";
}
final String extension = fileName.substring(
artifactBaseName.length() + 1 + ((classifier.length() > 0) ? classifier.length() + 1 : 0));
Artifact fileArtifact = new DefaultArtifact(model.getGroupId(), model.getArtifactId(),
classifier, extension, model.getVersion());
fileArtifact = fileArtifact.setFile(artifactFile);
artifactInstallRequest.addArtifact(fileArtifact);
}
// Actually install the artifact.
System.out.println("Installing Artifact: " + pomArtifact.getGroupId() + ":" +
pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion());
for (final Artifact artifact : artifactInstallRequest.getArtifacts()) {
System.out.println(" - File with extension " + artifact.getExtension() +
((artifact.getClassifier().length() > 0) ? " and classifier " + artifact.getClassifier() : ""));
}
repositorySystem.deploy(session, artifactInstallRequest);