Search in sources :

Example 1 with Artifacts

use of org.apache.sling.tooling.lc.aether.Artifacts 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);
}
Also used : IssueFinder(org.apache.sling.tooling.lc.jira.IssueFinder) AetherSetup(org.apache.sling.tooling.lc.aether.AetherSetup) ArtifactKey(org.apache.sling.tooling.lc.aether.ArtifactKey) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Function(java.util.function.Function) BundleListUtils(org.apache.sling.maven.projectsupport.BundleListUtils) Artifact(org.apache.sling.provisioning.model.Artifact) Matcher(java.util.regex.Matcher) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) VersionChange(org.apache.sling.tooling.lc.aether.VersionChange) Files(java.nio.file.Files) SVNException(org.tmatesoft.svn.core.SVNException) Set(java.util.Set) IOException(java.io.IOException) Artifacts(org.apache.sling.tooling.lc.aether.Artifacts) Collectors(java.util.stream.Collectors) File(java.io.File) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) ModelUtility(org.apache.sling.provisioning.model.ModelUtility) SvnChangeLogFinder(org.apache.sling.tooling.lc.svn.SvnChangeLogFinder) Model(org.apache.sling.provisioning.model.Model) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ModelReader(org.apache.sling.provisioning.model.io.ModelReader) ArtifactKey(org.apache.sling.tooling.lc.aether.ArtifactKey) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) VersionChange(org.apache.sling.tooling.lc.aether.VersionChange) Artifact(org.apache.sling.provisioning.model.Artifact) Model(org.apache.sling.provisioning.model.Model) BufferedReader(java.io.BufferedReader) File(java.io.File) AetherSetup(org.apache.sling.tooling.lc.aether.AetherSetup)

Aggregations

Sets (com.google.common.collect.Sets)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 BundleListUtils (org.apache.sling.maven.projectsupport.BundleListUtils)1 Bundle (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle)1 BundleList (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList)1 Artifact (org.apache.sling.provisioning.model.Artifact)1 Model (org.apache.sling.provisioning.model.Model)1 ModelUtility (org.apache.sling.provisioning.model.ModelUtility)1