Search in sources :

Example 6 with BundleList

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);
}
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)

Example 7 with BundleList

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;
}
Also used : BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ArrayList(java.util.ArrayList) DefaultCompositeOption(org.ops4j.pax.exam.options.DefaultCompositeOption) IOException(java.io.IOException) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) File(java.io.File)

Example 8 with BundleList

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;
}
Also used : Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ArrayList(java.util.ArrayList)

Example 9 with 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);
}
Also used : BundleListUtils.readBundleList(org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with BundleList

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.");
        }
    }
}
Also used : BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)

Aggregations

BundleList (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList)10 Bundle (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 StartLevel (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)7 IOException (java.io.IOException)6 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 BundleListXpp3Reader (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Reader)3 FileInputStream (java.io.FileInputStream)2 FileWriter (java.io.FileWriter)2 BundleListUtils.readBundleList (org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList)2 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)2 Sets (com.google.common.collect.Sets)1 BufferedReader (java.io.BufferedReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 Files (java.nio.file.Files)1