use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.
the class AbstractOSGiResolver method findResource.
@Override
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
ResolvedResource found = super.findResource(rress, rmdparser, mrid, date);
if (found == null) {
return null;
}
String osgiType = mrid.getOrganisation();
// for non bundle requirement : log the selected bundle
if (!BundleInfo.BUNDLE_TYPE.equals(osgiType)) {
// several candidates with different symbolic name : make an warning about the ambiguity
if (rress.length != 1) {
// several candidates with different symbolic name ?
Map<String, List<MDResolvedResource>> matching = new HashMap<>();
for (ResolvedResource rres : rress) {
String name = ((MDResolvedResource) rres).getResolvedModuleRevision().getDescriptor().getExtraAttribute(CAPABILITY_EXTRA_ATTR);
List<MDResolvedResource> list = matching.get(name);
if (list == null) {
list = new ArrayList<>();
matching.put(name, list);
}
list.add((MDResolvedResource) rres);
}
if (matching.keySet().size() != 1) {
if (requirementStrategy == RequirementStrategy.first) {
Message.warn("Ambiguity for the '" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision());
for (Map.Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
Message.warn("\t" + entry.getKey());
for (MDResolvedResource c : entry.getValue()) {
Message.warn("\t\t" + c.getRevision() + (found == c ? " (selected)" : ""));
}
}
} else if (requirementStrategy == RequirementStrategy.noambiguity) {
Message.error("Ambiguity for the '" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision());
for (Map.Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
Message.error("\t" + entry.getKey());
for (MDResolvedResource c : entry.getValue()) {
Message.error("\t\t" + c.getRevision() + (found == c ? " (best match)" : ""));
}
}
return null;
}
}
}
Message.info("'" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision() + " satisfied by " + ((MDResolvedResource) found).getResolvedModuleRevision().getId().getName() + ";" + found.getRevision());
}
return found;
}
use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.
the class UpdateSiteResolver method init.
protected void init() {
if (url == null) {
throw new RuntimeException("Missing url");
}
CacheResourceOptions options = new CacheResourceOptions();
if (metadataTtl != null) {
options.setTtl(metadataTtl);
}
if (forceMetadataUpdate != null) {
options.setForce(forceMetadataUpdate);
}
final int log;
if (logLevel != null) {
if ("debug".equalsIgnoreCase(logLevel)) {
log = Message.MSG_DEBUG;
} else if ("verbose".equalsIgnoreCase(logLevel)) {
log = Message.MSG_VERBOSE;
} else if ("info".equalsIgnoreCase(logLevel)) {
log = Message.MSG_INFO;
} else if ("warn".equalsIgnoreCase(logLevel)) {
log = Message.MSG_WARN;
} else if ("error".equalsIgnoreCase(logLevel)) {
log = Message.MSG_ERR;
} else {
throw new RuntimeException("Unknown log level: " + logLevel);
}
} else {
log = Message.MSG_INFO;
}
options.setListener(new DownloadListener() {
public void startArtifactDownload(RepositoryCacheManager cache, ResolvedResource rres, Artifact artifact, ArtifactOrigin origin) {
if (log <= Message.MSG_INFO) {
Message.info("\tdownloading " + rres.getResource().getName());
}
}
public void needArtifact(RepositoryCacheManager cache, Artifact artifact) {
if (log <= Message.MSG_VERBOSE) {
Message.verbose("\ttrying to download " + artifact);
}
}
public void endArtifactDownload(RepositoryCacheManager cache, Artifact artifact, ArtifactDownloadReport adr, File archiveFile) {
if (log <= Message.MSG_VERBOSE) {
if (adr.isDownloaded()) {
Message.verbose("\tdownloaded to " + archiveFile.getAbsolutePath());
} else {
Message.verbose("\tnothing to download");
}
}
}
});
final UpdateSiteLoader loader = new UpdateSiteLoader(getRepositoryCacheManager(), getEventManager(), options, this.getTimeoutConstraint());
loader.setLogLevel(log);
RepoDescriptor repoDescriptor;
try {
repoDescriptor = loader.load(new URI(url));
} catch (IOException e) {
throw new RuntimeException("IO issue while trying to read the update site (" + e.getMessage() + ")");
} catch (ParseException e) {
throw new RuntimeException("Failed to parse the updatesite (" + e.getMessage() + ")", e);
} catch (SAXException e) {
throw new RuntimeException("Ill-formed updatesite (" + e.getMessage() + ")", e);
} catch (URISyntaxException e) {
throw new RuntimeException("Ill-formed url (" + e.getMessage() + ")", e);
}
if (repoDescriptor == null) {
setRepoDescriptor(FAILING_REPO_DESCRIPTOR);
throw new RuntimeException("No update site was found at the location: " + url);
}
setRepoDescriptor(repoDescriptor);
}
use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.
the class PackagerResolver method findArtifactRef.
// @Override
public synchronized ResolvedResource findArtifactRef(Artifact artifact, Date date) {
// For our special packager.xml file, defer to superclass
if (PACKAGER_ARTIFACT_NAME.equals(artifact.getName()) && PACKAGER_ARTIFACT_TYPE.equals(artifact.getType()) && PACKAGER_ARTIFACT_EXT.equals(artifact.getExt())) {
return super.findArtifactRef(artifact, date);
}
// Check the cache
ModuleRevisionId mr = artifact.getModuleRevisionId();
PackagerCacheEntry entry = packagerCache.get(mr);
// Ignore invalid entries
if (entry != null && !entry.isBuilt()) {
packagerCache.remove(mr);
entry.cleanup();
entry = null;
}
// Build the artifacts (if not done already)
if (entry == null) {
ResolvedResource packager = findArtifactRef(new DefaultArtifact(mr, null, PACKAGER_ARTIFACT_NAME, PACKAGER_ARTIFACT_TYPE, PACKAGER_ARTIFACT_EXT), date);
if (packager == null) {
return null;
}
entry = new PackagerCacheEntry(mr, this.buildRoot, this.resourceCache, this.resourceURL, this.validate, this.preserve, this.restricted, this.verbose, this.quiet);
try {
entry.build(packager.getResource(), properties);
} catch (IOException e) {
throw new RuntimeException("can't build artifact " + artifact, e);
}
packagerCache.put(mr, entry);
}
// Return reference to desired artifact
return entry.getBuiltArtifact(artifact);
}
use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.
the class FileSystemResolverTest method testFindIvyFileRefWithMultipleIvyPatterns.
/**
* Test case for IVY-676.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-676">IVY-676</a>
*/
@Test
public void testFindIvyFileRefWithMultipleIvyPatterns() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/multi-ivypattern/ivy1/ivy-[revision].xml");
resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/multi-ivypattern/ivy2/ivy-[revision].xml");
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0+");
ResolvedResource ivyRef = resolver.findIvyFileRef(new DefaultDependencyDescriptor(mrid, false), data);
// check that the found ivy file is the one from the first pattern!
assertEquals(new File("test/repositories/multi-ivypattern/ivy1/ivy-1.0.xml").getCanonicalPath(), new File(ivyRef.getResource().getName()).getCanonicalPath());
}
use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.
the class BasicResolver method locate.
@Override
public ArtifactOrigin locate(Artifact artifact) {
ArtifactOrigin origin = getRepositoryCacheManager().getSavedArtifactOrigin(toSystem(artifact));
if (!ArtifactOrigin.isUnknown(origin)) {
return origin;
}
ResolvedResource artifactRef = getArtifactRef(artifact, null);
if (artifactRef != null && artifactRef.getResource().exists()) {
return new ArtifactOrigin(artifact, artifactRef.getResource().isLocal(), artifactRef.getResource().getName());
}
return null;
}
Aggregations