use of org.apache.ivy.core.report.MetadataArtifactDownloadReport in project ant-ivy by apache.
the class NameSpaceHelper method transform.
public static MetadataArtifactDownloadReport transform(MetadataArtifactDownloadReport report, NamespaceTransformer t) {
if (t.isIdentity()) {
return report;
}
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(transform(report.getArtifact(), t));
madr.setSearched(report.isSearched());
madr.setDownloadStatus(report.getDownloadStatus());
madr.setDownloadDetails(report.getDownloadDetails());
madr.setArtifactOrigin(report.getArtifactOrigin());
madr.setDownloadTimeMillis(report.getDownloadTimeMillis());
madr.setOriginalLocalFile(report.getOriginalLocalFile());
madr.setLocalFile(report.getLocalFile());
madr.setSize(report.getSize());
return madr;
}
use of org.apache.ivy.core.report.MetadataArtifactDownloadReport in project ant-ivy by apache.
the class AbstractOSGiResolver method buildResolvedCapabilityMd.
private MDResolvedResource buildResolvedCapabilityMd(DependencyDescriptor dd, ModuleDescriptor md) {
String org = dd.getDependencyRevisionId().getOrganisation();
String name = dd.getDependencyRevisionId().getName();
String rev = md.getExtraInfoContentByTagName(BundleInfoAdapter.EXTRA_INFO_EXPORT_PREFIX + name);
ModuleRevisionId capabilityRev = ModuleRevisionId.newInstance(org, name, rev, Collections.singletonMap(CAPABILITY_EXTRA_ATTR, md.getModuleRevisionId().toString()));
DefaultModuleDescriptor capabilityMd = new DefaultModuleDescriptor(capabilityRev, getSettings().getStatusManager().getDefaultStatus(), new Date());
String useConf = BundleInfoAdapter.CONF_USE_PREFIX + dd.getDependencyRevisionId().getName();
capabilityMd.addConfiguration(BundleInfoAdapter.CONF_DEFAULT);
capabilityMd.addConfiguration(BundleInfoAdapter.CONF_OPTIONAL);
capabilityMd.addConfiguration(BundleInfoAdapter.CONF_TRANSITIVE_OPTIONAL);
capabilityMd.addConfiguration(new Configuration(useConf));
DefaultDependencyDescriptor capabilityDD = new DefaultDependencyDescriptor(md.getModuleRevisionId(), false);
capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_DEFAULT, BundleInfoAdapter.CONF_NAME_DEFAULT);
capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_OPTIONAL, BundleInfoAdapter.CONF_NAME_OPTIONAL);
capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL, BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL);
capabilityDD.addDependencyConfiguration(useConf, useConf);
capabilityMd.addDependency(capabilityDD);
MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
report.setDownloadStatus(DownloadStatus.NO);
report.setSearched(true);
ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, capabilityMd, report);
return new MDResolvedResource(null, capabilityMd.getRevision(), rmr);
}
use of org.apache.ivy.core.report.MetadataArtifactDownloadReport in project ant-ivy by apache.
the class AbstractOSGiResolver method findBundle.
public ResolvedResource[] findBundle(DependencyDescriptor dd, ResolveData data, Collection<ModuleDescriptor> mds) {
ResolvedResource[] ret = new ResolvedResource[mds.size()];
int i = 0;
for (ModuleDescriptor md : mds) {
MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
report.setDownloadStatus(DownloadStatus.NO);
report.setSearched(true);
ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, md, report);
MDResolvedResource mdrr = new MDResolvedResource(null, md.getRevision(), rmr);
ret[i++] = mdrr;
}
return ret;
}
use of org.apache.ivy.core.report.MetadataArtifactDownloadReport in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method cacheModuleDescriptor.
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, final ResolvedResource mdRef, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException {
Date cachedPublicationDate = null;
ArtifactDownloadReport report;
ModuleRevisionId mrid = moduleArtifact.getModuleRevisionId();
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return null;
}
BackupResourceDownloader backupDownloader = new BackupResourceDownloader(downloader);
try {
if (!moduleArtifact.isMetadata()) {
// just make sure the old artifacts are deleted...
if (isChanging(dd, mrid, options)) {
long repoLastModified = mdRef.getLastModified();
Artifact transformedArtifact = NameSpaceHelper.transform(moduleArtifact, options.getNamespace().getToSystemTransformer());
ArtifactOrigin origin = getSavedArtifactOrigin(transformedArtifact);
File artFile = getArchiveFileInCache(transformedArtifact, origin, false);
if (artFile.exists() && repoLastModified > artFile.lastModified()) {
// artifacts have changed, they should be downloaded again
Message.verbose(mrid + " has changed: deleting old artifacts");
Message.debug("deleting " + artFile);
if (!artFile.delete()) {
Message.error("Couldn't delete outdated artifact from cache: " + artFile);
return null;
}
removeSavedArtifactOrigin(transformedArtifact);
}
}
return null;
}
// now let's see if we can find it in cache and if it is up to date
ResolvedModuleRevision rmr = doFindModuleInCache(mrid, options, null);
if (rmr != null) {
if (rmr.getDescriptor().isDefault() && rmr.getResolver() != resolver) {
Message.verbose("\t" + getName() + ": found revision in cache: " + mrid + " (resolved by " + rmr.getResolver().getName() + "): but it's a default one, maybe we can find a better one");
} else {
if (!isCheckmodified(dd, mrid, options) && !isChanging(dd, mrid, options)) {
Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
rmr.getReport().setSearched(true);
return rmr;
}
long repLastModified = mdRef.getLastModified();
long cacheLastModified = rmr.getDescriptor().getLastModified();
if (!rmr.getDescriptor().isDefault() && repLastModified <= cacheLastModified) {
Message.verbose("\t" + getName() + ": revision in cache (not updated): " + mrid);
rmr.getReport().setSearched(true);
return rmr;
}
Message.verbose("\t" + getName() + ": revision in cache is not up to date: " + mrid);
if (isChanging(dd, mrid, options)) {
// ivy file has been updated, we should see if it has a new publication
// date to see if a new download is required (in case the dependency is
// a changing one)
cachedPublicationDate = rmr.getDescriptor().getResolvedPublicationDate();
}
}
}
Artifact originalMetadataArtifact = getOriginalMetadataArtifact(moduleArtifact);
// now download module descriptor and parse it
report = download(originalMetadataArtifact, new ArtifactResourceResolver() {
public ResolvedResource resolve(Artifact artifact) {
return mdRef;
}
}, backupDownloader, new CacheDownloadOptions().setListener(options.getListener()).setForce(true));
Message.verbose("\t" + report);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
Message.warn("problem while downloading module descriptor: " + mdRef.getResource() + ": " + report.getDownloadDetails() + " (" + report.getDownloadTimeMillis() + "ms)");
return null;
}
try {
ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(mdRef.getResource());
ParserSettings parserSettings = settings;
if (resolver instanceof AbstractResolver) {
parserSettings = ((AbstractResolver) resolver).getParserSettings();
}
ModuleDescriptor md = getStaledMd(parser, options, report.getLocalFile(), parserSettings);
if (md == null) {
throw new IllegalStateException("module descriptor parser returned a null module descriptor, which is not allowed. parser=" + parser + "; parser class=" + parser.getClass().getName() + "; module descriptor resource=" + mdRef.getResource());
}
Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid + "; parsed=" + md.getModuleRevisionId());
// check if we should delete old artifacts
boolean deleteOldArtifacts = false;
if (cachedPublicationDate != null && !cachedPublicationDate.equals(md.getResolvedPublicationDate())) {
// artifacts have changed, they should be downloaded again
Message.verbose(mrid + " has changed: deleting old artifacts");
deleteOldArtifacts = true;
}
if (deleteOldArtifacts) {
for (String conf : md.getConfigurationsNames()) {
for (Artifact art : md.getArtifacts(conf)) {
Artifact transformedArtifact = NameSpaceHelper.transform(art, options.getNamespace().getToSystemTransformer());
ArtifactOrigin origin = getSavedArtifactOrigin(transformedArtifact);
File artFile = getArchiveFileInCache(transformedArtifact, origin, false);
if (artFile.exists()) {
Message.debug("deleting " + artFile);
if (!artFile.delete()) {
// Old artifacts couldn't get deleted!
// Restore the original ivy file so the next time we
// resolve the old artifacts are deleted again
backupDownloader.restore();
Message.error("Couldn't delete outdated artifact from cache: " + artFile);
return null;
}
}
removeSavedArtifactOrigin(transformedArtifact);
}
}
} else if (isChanging(dd, mrid, options)) {
Message.verbose(mrid + " is changing, but has not changed: will trust cached artifacts if any");
}
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
madr.setSearched(true);
madr.setDownloadStatus(report.getDownloadStatus());
madr.setDownloadDetails(report.getDownloadDetails());
madr.setArtifactOrigin(report.getArtifactOrigin());
madr.setDownloadTimeMillis(report.getDownloadTimeMillis());
madr.setOriginalLocalFile(report.getLocalFile());
madr.setSize(report.getSize());
Artifact transformedMetadataArtifact = NameSpaceHelper.transform(md.getMetadataArtifact(), options.getNamespace().getToSystemTransformer());
saveArtifactOrigin(transformedMetadataArtifact, report.getArtifactOrigin());
return new ResolvedModuleRevision(resolver, resolver, md, madr);
} catch (IOException ex) {
Message.warn("io problem while parsing ivy file: " + mdRef.getResource(), ex);
return null;
}
} finally {
unlockMetadataArtifact(mrid);
backupDownloader.cleanUp();
}
}
use of org.apache.ivy.core.report.MetadataArtifactDownloadReport in project ant-ivy by apache.
the class MockResolver method buildMockResolver.
static MockResolver buildMockResolver(ResolverSettings settings, String name, boolean findRevision, final ModuleRevisionId mrid, final Date publicationDate, final boolean isdefault) {
final MockResolver r = new MockResolver();
r.setName(name);
r.setSettings(settings);
if (findRevision) {
DefaultModuleDescriptor md = new DefaultModuleDescriptor(mrid, "integration", publicationDate, isdefault);
r.rmr = new ResolvedModuleRevision(r, r, md, new MetadataArtifactDownloadReport(md.getMetadataArtifact()));
}
return r;
}
Aggregations