use of org.apache.ivy.plugins.latest.ArtifactInfo in project ant-ivy by apache.
the class BasicResolver method findResource.
/**
* When the resolver has many choices, this function helps choosing one
*
* @param rress
* the list of resolved resource which the resolver found to fit the requirement
* @param rmdparser
* the parser of module descriptor
* @param mrid
* the module being resolved
* @param date
* the current date
* @return the selected resource
*/
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
String name = getName();
VersionMatcher versionMatcher = getSettings().getVersionMatcher();
ResolvedResource found = null;
List<ArtifactInfo> sorted = getLatestStrategy().sort(rress);
List<String> rejected = new ArrayList<>();
List<ModuleRevisionId> foundBlacklisted = new ArrayList<>();
IvyContext context = IvyContext.getContext();
ListIterator<ArtifactInfo> iter = sorted.listIterator(sorted.size());
while (iter.hasPrevious()) {
ResolvedResource rres = (ResolvedResource) iter.previous();
// name, blacklisting and first level version matching
if (filterNames(new ArrayList<>(Collections.singleton(rres.getRevision()))).isEmpty()) {
Message.debug("\t" + name + ": filtered by name: " + rres);
continue;
}
ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision());
ResolveData data = context.getResolveData();
if (data != null && data.getReport() != null && data.isBlacklisted(data.getReport().getConfiguration(), foundMrid)) {
Message.debug("\t" + name + ": blacklisted: " + rres);
rejected.add(rres.getRevision() + " (blacklisted)");
foundBlacklisted.add(foundMrid);
continue;
}
if (!versionMatcher.accept(mrid, foundMrid)) {
Message.debug("\t" + name + ": rejected by version matcher: " + rres);
rejected.add(rres.getRevision());
continue;
}
if (rres.getResource() != null && !rres.getResource().exists()) {
Message.debug("\t" + name + ": unreachable: " + rres + "; res=" + rres.getResource());
rejected.add(rres.getRevision() + " (unreachable)");
continue;
}
if (date != null && rres.getLastModified() > date.getTime()) {
Message.verbose("\t" + name + ": too young: " + rres);
rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
continue;
}
if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) {
ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision());
if (r == null) {
Message.debug("\t" + name + ": impossible to get module descriptor resource: " + rres);
rejected.add(rres.getRevision() + " (no or bad MD)");
continue;
}
ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision().getDescriptor();
if (md.isDefault()) {
Message.debug("\t" + name + ": default md rejected by version matcher" + "requiring module descriptor: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
}
if (!versionMatcher.accept(mrid, md)) {
Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
}
found = r;
} else {
found = rres;
}
if (found != null) {
break;
}
}
if (found == null && !rejected.isEmpty()) {
logAttempt(rejected.toString());
}
if (found == null && !foundBlacklisted.isEmpty()) {
// all acceptable versions have been blacklisted, this means that an unsolvable conflict
// has been found
DependencyDescriptor dd = context.getDependencyDescriptor();
IvyNode parentNode = context.getResolveData().getNode(dd.getParentRevisionId());
ConflictManager cm = parentNode.getConflictManager(mrid.getModuleId());
cm.handleAllBlacklistedRevisions(dd, foundBlacklisted);
}
return found;
}
use of org.apache.ivy.plugins.latest.ArtifactInfo in project ant-ivy by apache.
the class OsgiLatestStrategyTest method testFindLatest.
@Test
public void testFindLatest() {
ArtifactInfo[] revs = toMockAI(new String[] { "0.2.0.a", "0.2.0.b", "0.2.0.rc1", "0.2.0.final", "1.0.0.dev1", "1.0.0.dev2", "1.0.0.alpha1", "1.0.0.alpha2", "1.0.0.beta1", "1.0.0.beta2", "1.0.0.gamma", "1.0.0.rc1", "1.0.0.rc2", "1.0", "1.0.1", "2.0" });
List<ArtifactInfo> shuffled = new ArrayList<>(Arrays.asList(revs));
Collections.shuffle(shuffled);
ArtifactInfo[] shuffledRevs = shuffled.toArray(new ArtifactInfo[revs.length]);
OsgiLatestStrategy latestRevisionStrategy = new OsgiLatestStrategy();
ArtifactInfo latest = latestRevisionStrategy.findLatest(shuffledRevs, new Date());
assertNotNull(latest);
assertEquals("2.0", latest.getRevision());
}
use of org.apache.ivy.plugins.latest.ArtifactInfo in project ant-ivy by apache.
the class IvyBuildNumber method doExecute.
public void doExecute() throws BuildException {
if (organisation == null) {
throw new BuildException("no organisation provided for ivy buildnumber task");
}
if (module == null) {
throw new BuildException("no module name provided for ivy buildnumber task");
}
if (prefix == null) {
throw new BuildException("null prefix not allowed");
}
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
if (branch == null) {
branch = settings.getDefaultBranch(new ModuleId(organisation, module));
}
if (isNullOrEmpty(revision)) {
revision = "latest.integration";
} else if (!revision.endsWith("+")) {
revision += "+";
}
if (!prefix.endsWith(".") && !prefix.isEmpty()) {
prefix += ".";
}
SearchEngine searcher = new SearchEngine(settings);
PatternMatcher patternMatcher = new PatternMatcher() {
private PatternMatcher exact = new ExactPatternMatcher();
private PatternMatcher regexp = new ExactOrRegexpPatternMatcher();
public Matcher getMatcher(String expression) {
if (expression.equals(organisation) || expression.equals(module) || expression.equals(branch)) {
return exact.getMatcher(expression);
} else {
return regexp.getMatcher(expression);
}
}
public String getName() {
return "buildnumber-matcher";
}
};
String revisionPattern = ".*";
if (revision.endsWith("+")) {
revisionPattern = Pattern.quote(revision.substring(0, revision.length() - 1)) + ".*";
}
ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, branch, revisionPattern);
ModuleRevisionId[] revisions;
if (resolver == null) {
revisions = searcher.listModules(mrid, patternMatcher);
} else {
DependencyResolver depResolver = settings.getResolver(resolver);
if (depResolver == null) {
throw new BuildException("Unknown resolver: " + resolver);
}
revisions = searcher.listModules(depResolver, mrid, patternMatcher);
}
List<ArtifactInfo> infos = new ArrayList<>(revisions.length);
for (ModuleRevisionId rev : revisions) {
infos.add(new ResolvedModuleRevisionArtifactInfo(rev));
}
VersionMatcher matcher = settings.getVersionMatcher();
LatestStrategy latestStrategy = settings.getLatestStrategy("latest-revision");
List<ArtifactInfo> sorted = latestStrategy.sort(infos.toArray(new ArtifactInfo[revisions.length]));
ModuleRevisionId askedMrid = ModuleRevisionId.newInstance(organisation, module, branch, revision);
String foundRevision = null;
ListIterator<ArtifactInfo> iter = sorted.listIterator(sorted.size());
while (iter.hasPrevious()) {
ResolvedModuleRevisionArtifactInfo info = (ResolvedModuleRevisionArtifactInfo) iter.previous();
if (!matcher.accept(askedMrid, info.rmr)) {
continue;
}
if (matcher.needModuleDescriptor(askedMrid, info.rmr)) {
ResolvedModuleRevision rmr = ivy.findModule(info.rmr);
if (matcher.accept(askedMrid, rmr.getDescriptor())) {
foundRevision = info.rmr.getRevision();
}
} else {
foundRevision = info.rmr.getRevision();
}
if (foundRevision != null) {
break;
}
}
NewRevision newRevision = computeNewRevision(foundRevision);
setProperty("revision", newRevision.getRevision());
setProperty("new.revision", newRevision.getNewRevision());
setProperty("build.number", newRevision.getBuildNumber());
setProperty("new.build.number", newRevision.getNewBuildNumber());
}
Aggregations