is = fi.getInputStream();
}
try {
// parse and read GAVs from stored POM, fill in them all into context
final ArtifactCoordinate coords = pomManager.getArtifactCoordinateFromTempPomFile();
uploadContext.setGroupId(coords.getGroupId());
uploadContext.setArtifactId(coords.getArtifactId());
uploadContext.setVersion(coords.getVersion());
uploadContext.setPackaging(coords.getPackaging());
}
catch (IOException e) {
getLogger().info("Error occurred while reading the POM file. Malformed POM?", e);
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
"Error occurred while reading the POM file. Malformed POM?", e);
}
if (isPom) {
uploadGavParametersAvailable(request, uploadContext);
gavRequest =
getResourceStoreRequest(request, true, false, uploadContext.getRepositoryId(),
uploadContext.getGroupId(), uploadContext.getArtifactId(),
uploadContext.getVersion(), uploadContext.getPackaging(), null, null);
}
else {
gavRequest =
getResourceStoreRequest(request, true, false, uploadContext.getRepositoryId(),
uploadContext.getGroupId(), uploadContext.getArtifactId(),
uploadContext.getVersion(), uploadContext.getPackaging(),
uploadContext.getClassifier(), uploadContext.getExtension());
}
}
else {
uploadGavParametersAvailable(request, uploadContext);
is = fi.getInputStream();
gavRequest =
getResourceStoreRequest(request, true, false, uploadContext.getRepositoryId(),
uploadContext.getGroupId(), uploadContext.getArtifactId(), uploadContext.getVersion(),
uploadContext.getPackaging(), uploadContext.getClassifier(),
uploadContext.getExtension());
}
final MavenRepository mr = gavRequest.getMavenRepository();
final ArtifactStoreHelper helper = mr.getArtifactStoreHelper();
// temporarily we disable SNAPSHOT upload
// check is it a Snapshot repo
if (RepositoryPolicy.SNAPSHOT.equals(mr.getRepositoryPolicy())) {
getLogger().info("Upload to SNAPSHOT maven repository {} attempted, returning Bad Request.",
mr);
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
"This is a Maven SNAPSHOT repository, and manual upload against it is forbidden!");
}
if (!versionMatchesPolicy(gavRequest.getVersion(), mr.getRepositoryPolicy())) {
getLogger().info("Artifact version {} and {} Repository Policy {} mismatch",
gavRequest.getVersion(), mr, mr.getRepositoryPolicy());
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "The version "
+ gavRequest.getVersion() + " does not match the repository policy!");
}
if (isPom) {
helper.storeArtifactPom(gavRequest, is, null);
isPom = false;
}
else {
if (uploadContext.isPomAvailable()) {
helper.storeArtifact(gavRequest, is, null);
}
else {
helper.storeArtifactWithGeneratedPom(gavRequest, uploadContext.getPackaging(), is, null);
}
}
}
}
}
catch (Exception t) {
return buildUploadFailedHtmlResponse(t, request, response);
}
finally {
if (uploadContext.isPomAvailable()) {
pomManager.removeTempPomFile();
}
}
final ArtifactCoordinate coords = new ArtifactCoordinate();
coords.setGroupId(uploadContext.getGroupId());
coords.setArtifactId(uploadContext.getArtifactId());
coords.setVersion(uploadContext.getVersion());
coords.setPackaging(uploadContext.getPackaging());
return coords;
}