);
}
public static CompositeOption slingBundleList(String groupId, String artifactId, String version, String type, String classifier) {
final DefaultCompositeOption result = new DefaultCompositeOption();
final String paxUrl = new StringBuilder()
.append("mvn:")
.append(groupId)
.append("/")
.append(artifactId)
.append("/")
.append(version == null ? "" : version)
.append("/")
.append(type == null ? "" : type)
.append("/")
.append(classifier == null ? "" : classifier)
.toString();
// TODO BundleList should take an InputStream - for now copy to a tmp file for parsing
log.info("Getting bundle list {}", paxUrl);
File tmp = null;
final Collection<String> testRunModes = getTestRunModes();
try {
tmp = dumpMvnUrlToTmpFile(paxUrl);
final BundleList list = BundleListUtils.readBundleList(tmp);
int counter = 0;
for(StartLevel s : list.getStartLevels()) {
// Start level < 0 means bootstrap in our bundle lists
final int startLevel = s.getStartLevel() < 0 ? 1 : s.getStartLevel();
for(Bundle b : s.getBundles()) {
counter++;
// TODO need better fragment detection
// (but pax exam should really detect that by itself?)
final List<String> KNOWN_FRAGMENTS = new ArrayList<String>();
KNOWN_FRAGMENTS.add("org.apache.sling.extensions.webconsolebranding");
final boolean isFragment = b.getArtifactId().contains("fragment") || KNOWN_FRAGMENTS.contains(b.getArtifactId());
// Ignore bundles with run modes that do not match ours
final String bundleRunModes = b.getRunModes();
if(bundleRunModes != null && bundleRunModes.length() > 0) {
boolean active = false;
for(String m : bundleRunModes.split(",")) {
if(testRunModes.contains(m)) {
active = true;
break;
}
}
if(!active) {
log.info("Ignoring bundle {} as none of its run modes [{}] are active in this test run {}",
new Object[] { b.getArtifactId(), bundleRunModes, testRunModes} );
continue;
}
}
if(isFragment) {
result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).noStart());
} else if(startLevel == 0){
result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()));
} else {
result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).startLevel(startLevel));
}
log.info("Bundle added: {}/{}/{}", new Object [] { b.getGroupId(), b.getArtifactId(), b.getVersion()});
}
}