// a file, this means NO parameters will income anymore
// we either received all the GAVs as params, or we have a POM to work with (file1)
boolean isPom = fi.getName().endsWith(".pom") || fi.getName().endsWith("pom.xml");
InputStream is = null;
ArtifactStoreRequest gavRequest = null;
if (uploadContext.isPomAvailable()) {
if (isPom) {
// this is file1, the POM file content
// let it "thru" the pomManager to be able to get GAV from it on later pass
pomManager.storeTempPomFile(fi.getInputStream());
is = pomManager.getTempPomFileInputStream();
}
else {
// this is file2, POM already stored into pomManager
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;