use of org.apache.maven.shared.artifact.deploy.ArtifactDeployerException in project maven-plugins by apache.
the class DeployFileMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (uniqueVersion != null) {
throw new MojoExecutionException("You are using 'uniqueVersion' which has been removed" + " from the maven-deploy-plugin. " + "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site.");
}
failIfOffline();
if (!file.exists()) {
throw new MojoExecutionException(file.getPath() + " not found.");
}
initProperties();
ArtifactRepository deploymentRepository = createDeploymentArtifactRepository(repositoryId, url);
String protocol = deploymentRepository.getProtocol();
if (StringUtils.isEmpty(protocol)) {
throw new MojoExecutionException("No transfer protocol found.");
}
MavenProject project = createMavenProject();
Artifact artifact = project.getArtifact();
if (file.equals(getLocalRepoFile())) {
throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
}
List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
if (classifier == null) {
artifact.setFile(file);
deployableArtifacts.add(artifact);
} else {
projectHelper.attachArtifact(project, packaging, classifier, file);
}
// Upload the POM if requested, generating one if need be
if (!"pom".equals(packaging)) {
File pom = pomFile;
if (pom == null && generatePom) {
pom = generatePomFile();
}
if (pom != null) {
if (classifier == null) {
ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pom);
artifact.addMetadata(metadata);
} else {
artifact.setFile(pom);
deployableArtifacts.add(artifact);
}
}
}
if (updateReleaseInfo) {
artifact.setRelease(true);
}
artifact.setRepository(deploymentRepository);
if (sources != null) {
projectHelper.attachArtifact(project, "jar", "sources", sources);
}
if (javadoc != null) {
projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
}
if (files != null) {
if (types == null) {
throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
}
if (classifiers == null) {
throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
}
int filesLength = StringUtils.countMatches(files, ",");
int typesLength = StringUtils.countMatches(types, ",");
int classifiersLength = StringUtils.countMatches(classifiers, ",");
if (typesLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
}
if (classifiersLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
}
int fi = 0;
int ti = 0;
int ci = 0;
for (int i = 0; i <= filesLength; i++) {
int nfi = files.indexOf(',', fi);
if (nfi == -1) {
nfi = files.length();
}
int nti = types.indexOf(',', ti);
if (nti == -1) {
nti = types.length();
}
int nci = classifiers.indexOf(',', ci);
if (nci == -1) {
nci = classifiers.length();
}
File file = new File(files.substring(fi, nfi));
if (!file.isFile()) {
// try relative to the project basedir just in case
file = new File(project.getBasedir(), files.substring(fi, nfi));
}
if (file.isFile()) {
if (StringUtils.isWhitespace(classifiers.substring(ci, nci))) {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), file);
} else {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), classifiers.substring(ci, nci).trim(), file);
}
} else {
throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
}
fi = nfi + 1;
ti = nti + 1;
ci = nci + 1;
}
} else {
if (types != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
}
if (classifiers != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
}
}
List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
for (Artifact attached : attachedArtifacts) {
deployableArtifacts.add(attached);
}
try {
artifactDeployer.deploy(getSession().getProjectBuildingRequest(), deploymentRepository, deployableArtifacts);
} catch (ArtifactDeployerException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
Aggregations