in indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java [298:382]
protected IteratorSearchResponse getArtifacts(TreeNode root, TreeViewRequest request) throws IOException {
if (request.hasFieldHints()) {
return getHintedArtifacts(root, request);
}
String path = root.getPath();
IteratorSearchResponse result;
String g;
String a;
String v;
// "working copy" of path
String wp;
// remove last / from path
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
// 1st try, let's consider path is a group
// reset wp
wp = path;
g = wp.substring(1).replace('/', '.');
result = getArtifactsByG(g, request);
if (result.getTotalHitsCount() > 0) {
return result;
} else {
result.close();
}
// 2nd try, lets consider path a group + artifactId, we must ensure there is at least one / but not as root
if (path.lastIndexOf('/') > 0) {
// reset wp
wp = path;
a = wp.substring(wp.lastIndexOf('/') + 1);
g = wp.substring(1, wp.lastIndexOf('/')).replace('/', '.');
result = getArtifactsByGA(g, a, request);
if (result.getTotalHitsCount() > 0) {
return result;
} else {
result.close();
}
// 3rd try, let's consider path a group + artifactId + version. There is no 100% way to detect this!
try {
// reset wp
wp = path;
v = wp.substring(wp.lastIndexOf('/') + 1);
wp = wp.substring(0, wp.lastIndexOf('/'));
a = wp.substring(wp.lastIndexOf('/') + 1);
g = wp.substring(1, wp.lastIndexOf('/')).replace('/', '.');
result = getArtifactsByGAV(g, a, v, request);
if (result.getTotalHitsCount() > 0) {
return result;
} else {
result.close();
}
} catch (StringIndexOutOfBoundsException e) {
// nothing
}
}
// if we are here, no hits found
return IteratorSearchResponse.empty(result.getQuery());
}