in src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java [232:385]
public void execute() throws MojoExecutionException, MojoFailureException {
if (Boolean.parseBoolean(skip)
|| ("releases".equals(skip) && !ArtifactUtils.isSnapshot(version))
|| ("snapshots".equals(skip) && ArtifactUtils.isSnapshot(version))) {
getLog().info("Skipping artifact deployment");
return;
}
if (!file.exists()) {
throw new MojoExecutionException(file.getPath() + " not found.");
}
initProperties();
RemoteRepository remoteRepository = getRemoteRepository(repositoryId, url);
if (StringUtils.isEmpty(remoteRepository.getProtocol())) {
throw new MojoExecutionException("No transfer protocol found.");
}
if (groupId == null || artifactId == null || version == null || packaging == null) {
throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', "
+ "'version' and 'packaging' are required.");
}
if (!isValidId(groupId) || !isValidId(artifactId) || !isValidVersion(version)) {
throw new MojoExecutionException("The artifact information is not valid: uses invalid characters.");
}
failIfOffline();
warnIfAffectedPackagingAndMaven(packaging);
DeployRequest deployRequest = new DeployRequest();
deployRequest.setRepository(remoteRepository);
boolean isFilePom = classifier == null && "pom".equals(packaging);
if (!isFilePom) {
ArtifactType artifactType =
session.getRepositorySession().getArtifactTypeRegistry().get(packaging);
if (artifactType != null
&& (classifier == null || classifier.isEmpty())
&& !StringUtils.isEmpty(artifactType.getClassifier())) {
classifier = artifactType.getClassifier();
}
}
Artifact mainArtifact = new DefaultArtifact(
groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
.setFile(file);
deployRequest.addArtifact(mainArtifact);
File artifactLocalFile = getLocalRepositoryFile(session.getRepositorySession(), mainArtifact);
if (file.equals(artifactLocalFile)) {
throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
}
File temporaryPom = null;
if (!"pom".equals(packaging)) {
if (pomFile != null) {
deployRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", pomFile));
} else if (generatePom) {
temporaryPom = generatePomFile();
getLog().debug("Deploying generated POM");
deployRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", temporaryPom));
} else {
getLog().debug("Skipping deploying POM");
}
}
if (sources != null) {
deployRequest.addArtifact(new SubArtifact(mainArtifact, "sources", "jar", sources));
}
if (javadoc != null) {
deployRequest.addArtifact(new SubArtifact(mainArtifact, "javadoc", "jar", 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(files.substring(fi, nfi));
}
if (file.isFile()) {
String extension = getExtension(file);
ArtifactType artifactType = session.getRepositorySession()
.getArtifactTypeRegistry()
.get(types.substring(ti, nti).trim());
if (artifactType != null && !Objects.equals(extension, artifactType.getExtension())) {
extension = artifactType.getExtension();
}
deployRequest.addArtifact(new SubArtifact(
mainArtifact, classifiers.substring(ci, nci).trim(), extension, 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'");
}
}
try {
repositorySystem.deploy(session.getRepositorySession(), deployRequest);
} catch (DeploymentException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
if (temporaryPom != null) {
// noinspection ResultOfMethodCallIgnored
temporaryPom.delete();
}
}
}