use of org.apache.ivy.plugins.matcher.ExactPatternMatcher 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