use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class LaunchpadComparer method run.
public void run() throws Exception {
System.out.format("Computing differences between Launchpad versions %s and %s...%n", firstVersion, secondVersion);
// 1. download artifacts
AetherSetup aether = new AetherSetup();
File fromFile = aether.download(Artifacts.launchpadCoordinates(firstVersion));
File toFile = aether.download(Artifacts.launchpadCoordinates(secondVersion));
// 2. parse artifact definitions
Model model;
try (BufferedReader reader = Files.newBufferedReader(toFile.toPath())) {
model = ModelUtility.getEffectiveModel(ModelReader.read(reader, null));
}
Map<ArtifactKey, Artifact> to = model.getFeatures().stream().flatMap(f -> f.getRunModes().stream()).flatMap(r -> r.getArtifactGroups().stream()).flatMap(g -> StreamSupport.stream(g.spliterator(), false)).collect(Collectors.toMap(a -> new ArtifactKey(a), Function.identity()));
BundleList readBundleList = BundleListUtils.readBundleList(fromFile);
Map<ArtifactKey, Artifact> from = readBundleList.getStartLevels().stream().flatMap(sl -> sl.getBundles().stream()).collect(Collectors.toMap(b -> new ArtifactKey(b), LaunchpadComparer::newArtifact));
// 3. generate added / removed / changed
Set<Artifact> removed = Sets.difference(from.keySet(), to.keySet()).stream().map(k -> from.get(k)).collect(Collectors.toSet());
Set<Artifact> added = Sets.difference(to.keySet(), from.keySet()).stream().map(k -> to.get(k)).collect(Collectors.toSet());
Map<ArtifactKey, VersionChange> changed = to.values().stream().filter(k -> !added.contains(k) && !removed.contains(k)).map(k -> new ArtifactKey(k)).filter(k -> !Objects.equals(to.get(k).getVersion(), from.get(k).getVersion())).collect(Collectors.toMap(Function.identity(), k -> new VersionChange(from.get(k).getVersion(), to.get(k).getVersion())));
// 4. output changes
System.out.println("Added ");
added.stream().sorted().forEach(LaunchpadComparer::outputFormatted);
System.out.println("Removed ");
removed.stream().sorted().forEach(LaunchpadComparer::outputFormatted);
System.out.println("Changed");
changed.entrySet().stream().sorted((a, b) -> a.getKey().compareTo(b.getKey())).forEach(LaunchpadComparer::outputFormatted);
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class SlingPaxOptions method slingBundleList.
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;
int ignored = 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()) {
if (ignore(b)) {
log.info("Bundle ignored due to setIgnoredBundles: {}", b);
ignored++;
continue;
}
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() });
}
}
log.info("Got {} bundles ({} ignored) from {}", new Object[] { counter, ignored, paxUrl });
} catch (Exception e) {
throw new RuntimeException("Error getting bundle list " + paxUrl, e);
} finally {
if (tmp != null) {
tmp.delete();
}
}
return result;
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class ArtifactDefinition method toBundleList.
public List<Bundle> toBundleList() {
ArrayList<Bundle> bundleList = new ArrayList<Bundle>();
if (bundles == null) {
Bundle bnd = new Bundle();
bnd.setArtifactId(artifactId);
bnd.setGroupId(groupId);
bnd.setVersion(version);
if (type != null) {
bnd.setType(type);
}
bnd.setClassifier(classifier);
bnd.setStartLevel(startLevel);
bundleList.add(bnd);
} else {
for (ArtifactDefinition bundle : bundles) {
bundleList.addAll(bundle.toBundleList());
}
}
return bundleList;
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class AbstractUsingBundleListMojo method initBundleList.
private final void initBundleList() throws IOException, XmlPullParserException, MojoExecutionException {
initArtifactDefinitions();
if (BundleListUtils.isCurrentArtifact(project, defaultBundleList)) {
initializedBundleList = readBundleList(bundleListFile);
} else {
initializedBundleList = new BundleList();
if (includeDefaultBundles) {
Artifact defBndListArtifact = getArtifact(defaultBundleList.getGroupId(), defaultBundleList.getArtifactId(), defaultBundleList.getVersion(), defaultBundleList.getType(), defaultBundleList.getClassifier());
getLog().info("Using bundle list file from " + defBndListArtifact.getFile().getAbsolutePath());
initializedBundleList = readBundleList(defBndListArtifact.getFile());
}
if (bundleListFile.exists()) {
initializedBundleList.merge(readBundleList(bundleListFile));
}
}
// add additional bundles
if (additionalBundles != null) {
for (ArtifactDefinition def : additionalBundles) {
initializedBundleList.add(def.toBundleList());
}
}
interpolateProperties(initializedBundleList, project, mavenSession);
// check for partial bundle lists
final Set<Artifact> dependencies = project.getDependencyArtifacts();
for (Artifact artifact : dependencies) {
if (PARTIAL.equals(artifact.getType())) {
getLog().info(String.format("Merging partial bundle list %s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()));
initializedBundleList.merge(readBundleList(artifact.getFile()));
}
}
// handle exclusions
if (bundleExclusions != null) {
for (ArtifactDefinition def : bundleExclusions) {
initializedBundleList.remove(def.toBundleList(), false);
}
}
initBundleList(initializedBundleList);
interpolateProperties(initializedBundleList, project, mavenSession);
rewriteBundleList(initializedBundleList);
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class CheckBundleListForSnapshotsMojo method executeWithArtifacts.
@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
List<Bundle> snapshots = new ArrayList<Bundle>();
BundleList bundleList = getInitializedBundleList();
for (StartLevel level : bundleList.getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
if (isSnapshot(bundle)) {
snapshots.add(bundle);
}
}
}
if (!snapshots.isEmpty()) {
getLog().error("The following entries in the bundle list file are SNAPSHOTs:");
for (Bundle bundle : snapshots) {
getLog().error(String.format(" %s:%s:%s", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion()));
}
if (failOnSnapshot) {
throw new MojoFailureException("SNAPSHOTs were found in the bundle list. See log.");
}
}
}
Aggregations