use of org.apache.ivy.util.PropertiesFile in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method saveArtifactOrigin.
void saveArtifactOrigin(Artifact artifact, ArtifactOrigin origin) {
// should always be called with a lock on module metadata artifact
PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
cdf.setProperty(getIsLocalKey(artifact), String.valueOf(origin.isLocal()));
cdf.setProperty(getLocationKey(artifact), origin.getLocation());
cdf.setProperty(getOriginalKey(artifact), getPrefixKey(origin.getArtifact()));
if (origin.getLastChecked() != null) {
cdf.setProperty(getLastCheckedKey(artifact), origin.getLastChecked().toString());
}
cdf.setProperty(getExistsKey(artifact), Boolean.toString(origin.isExists()));
cdf.save();
}
use of org.apache.ivy.util.PropertiesFile in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method saveResolvers.
/**
* Saves the information of which resolver was used to resolve a md, so that this info can be
* retrieve later (even after a jvm restart) by getSavedArtResolverName(ModuleDescriptor md)
*
* @param md
* the module descriptor resolved
* @param metadataResolverName
* metadata resolver name
* @param artifactResolverName
* artifact resolver name
*/
public void saveResolvers(ModuleDescriptor md, String metadataResolverName, String artifactResolverName) {
ModuleRevisionId mrid = md.getResolvedModuleRevisionId();
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return;
}
try {
PropertiesFile cdf = getCachedDataFile(md);
cdf.setProperty("resolver", metadataResolverName);
cdf.setProperty("artifact.resolver", artifactResolverName);
cdf.save();
} finally {
unlockMetadataArtifact(mrid);
}
}
use of org.apache.ivy.util.PropertiesFile in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method removeSavedArtifactOrigin.
private void removeSavedArtifactOrigin(Artifact artifact) {
// should always be called with a lock on module metadata artifact
PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
cdf.remove(getLocationKey(artifact));
cdf.remove(getIsLocalKey(artifact));
cdf.remove(getLastCheckedKey(artifact));
cdf.remove(getOriginalKey(artifact));
cdf.save();
}
use of org.apache.ivy.util.PropertiesFile in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method getResolvedRevision.
/**
* Called by doFindModuleInCache to lookup the dynamic {@code mrid} in the ivycache's ivydata
* file.
*/
private String getResolvedRevision(String expectedResolver, ModuleRevisionId mrid, CacheMetadataOptions options) {
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return null;
}
try {
if (options.isForce()) {
Message.verbose("refresh mode: no check for cached resolved revision for " + mrid);
return null;
}
// If a resolver is asking for its specific dynamic revision, avoid looking at a different one
PropertiesFile cachedResolvedRevision;
if (expectedResolver != null) {
cachedResolvedRevision = getCachedDataFile(expectedResolver, mrid);
} else {
cachedResolvedRevision = getCachedDataFile(mrid);
}
String resolvedRevision = cachedResolvedRevision.getProperty("resolved.revision");
if (resolvedRevision == null) {
Message.verbose(getName() + ": no cached resolved revision for " + mrid);
return null;
}
String resolvedTime = cachedResolvedRevision.getProperty("resolved.time");
if (resolvedTime == null) {
Message.verbose(getName() + ": inconsistent or old cache: no cached resolved time for " + mrid);
saveResolvedRevision(expectedResolver, mrid, resolvedRevision);
return resolvedRevision;
}
if (options.isCheckTTL()) {
long expiration = Long.parseLong(resolvedTime) + getTTL(mrid);
// negative expiration means that Long.MAX_VALUE has been exceeded
if (expiration > 0 && System.currentTimeMillis() > expiration) {
Message.verbose(getName() + ": cached resolved revision expired for " + mrid);
return null;
}
}
return resolvedRevision;
} finally {
unlockMetadataArtifact(mrid);
}
}
use of org.apache.ivy.util.PropertiesFile in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method getSavedArtifactOrigin.
public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) {
ModuleRevisionId mrid = artifact.getModuleRevisionId();
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return ArtifactOrigin.unknown(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);
if (location == null) {
// origin has not been specified, return null
return ArtifactOrigin.unknown(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 {
// 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.
String ownLocationKey = getLocationKey(artifact);
for (Map.Entry<Object, Object> entry : cdf.entrySet()) {
if (entry.getValue().equals(location) && !ownLocationKey.equals(entry.getKey())) {
// found a match, key is
// artifact:[name]#[type]#[ext]#[hashcode].location
java.util.regex.Matcher m = ARTIFACT_KEY_PATTERN.matcher((String) entry.getKey());
if (m.matches()) {
String origName = m.group(1);
String origType = m.group(2);
String origExt = m.group(3);
// first check: the type should end in .original
if (!origType.endsWith(".original")) {
continue;
}
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);
}
}
break;
}
}
}
}
}
ArtifactOrigin origin = new ArtifactOrigin(artifact, isLocal, location);
if (lastChecked != null) {
origin.setLastChecked(Long.valueOf(lastChecked));
}
if (exists != null) {
origin.setExist(Boolean.valueOf(exists));
}
return origin;
} finally {
unlockMetadataArtifact(mrid);
}
}
Aggregations