if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return ArtifactOrigin.unkwnown(artifact);
}
try {
PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
String location = cdf.getProperty(getLocationKey(artifact));
String local = cdf.getProperty(getIsLocalKey(artifact));
String lastChecked = cdf.getProperty(getLastCheckedKey(artifact));
String exists = cdf.getProperty(getExistsKey(artifact));
String original = cdf.getProperty(getOriginalKey(artifact));
boolean isLocal = Boolean.valueOf(local).booleanValue();
if (location == null) {
// origin has not been specified, return null
return ArtifactOrigin.unkwnown(artifact);
}
if (original != null) {
// original artifact key artifact:[name]#[type]#[ext]#[hashcode]
java.util.regex.Matcher m = ARTIFACT_KEY_PATTERN.matcher(original);
if (m.matches()) {
String origName = m.group(1);
String origType = m.group(2);
String origExt = m.group(3);
ArtifactRevisionId originArtifactId = ArtifactRevisionId.newInstance(
artifact.getModuleRevisionId(), origName, origType, origExt);
// second check: verify the hashcode of the cached artifact
if (m.group(4).equals("" + originArtifactId.hashCode())) {
try {
artifact = new DefaultArtifact(originArtifactId,
artifact.getPublicationDate(), new URL(location), true);
} catch (MalformedURLException e) {
Message.debug(e);
}
}
}
} else {
// Fallback if cached with old version:
// if the origin artifact has another extension (e.g. .pom) then make a synthetic
// origin artifact for it
if (!location.endsWith("." + artifact.getExt())) {
// try to find other cached artifact info with same location. This must be the
// origin. We must parse the key as we do not know for sure what the original
// artifact is named.
Iterator it = cdf.entrySet().iterator();
String ownLocationKey = getLocationKey(artifact);
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
if (entry.getValue().equals(location)
&& !ownLocationKey.equals(entry.getKey())) {