Search in sources :

Example 1 with Version

use of org.apache.karaf.util.Version in project karaf by apache.

the class Builder method generateConsistencyReport.

/**
 * Produces human readable XML with <em>feature consistency report</em>.
 * @param repositories
 * @param result
 */
public void generateConsistencyReport(Map<String, Features> repositories, File result, boolean full) {
    Map<String, String> featureId2repository = new HashMap<>();
    // list of feature IDs containing given bundle URIs
    Map<String, Set<String>> bundle2featureId = new TreeMap<>(new URIAwareComparator());
    // map of groupId/artifactId to full URI list to detect "duplicates"
    Map<String, List<String>> ga2uri = new TreeMap<>();
    Set<String> haveDuplicates = new HashSet<>();
    // collect closure of bundles and features
    repositories.forEach((name, features) -> {
        if (full || !features.isBlacklisted()) {
            features.getFeature().forEach(feature -> {
                if (full || !feature.isBlacklisted()) {
                    featureId2repository.put(feature.getId(), name);
                    feature.getBundle().forEach(bundle -> {
                        // normal bundles of feature
                        bundle2featureId.computeIfAbsent(bundle.getLocation().trim(), k -> new TreeSet<>()).add(feature.getId());
                    });
                    feature.getConditional().forEach(cond -> {
                        cond.asFeature().getBundles().forEach(bundle -> {
                            // conditional bundles of feature
                            bundle2featureId.computeIfAbsent(bundle.getLocation().trim(), k -> new TreeSet<>()).add(feature.getId());
                        });
                    });
                }
            });
        }
    });
    // collect bundle URIs - for now, only wrap:mvn: and mvn: are interesting
    bundle2featureId.keySet().forEach(uri -> {
        String originalUri = uri;
        if (uri.startsWith("wrap:mvn:")) {
            uri = uri.substring(5);
            if (uri.indexOf(";") > 0) {
                uri = uri.substring(0, uri.indexOf(";"));
            }
            if (uri.indexOf("$") > 0) {
                uri = uri.substring(0, uri.indexOf("$"));
            }
        }
        if (uri.startsWith("mvn:")) {
            try {
                LocationPattern pattern = new LocationPattern(uri);
                String ga = String.format("%s/%s", pattern.getGroupId(), pattern.getArtifactId());
                ga2uri.computeIfAbsent(ga, k -> new LinkedList<>()).add(originalUri);
            } catch (IllegalArgumentException ignored) {
            /*
                        <!-- hibernate-validator-osgi-karaf-features-5.3.4.Final-features.xml -->
                        <feature name="hibernate-validator-paranamer" version="5.3.4.Final">
                            <feature>hibernate-validator</feature>
                            <bundle>wrap:mvn:com.thoughtworks.paranamer:paranamer:2.8</bundle>
                        </feature>
                     */
            }
        }
    });
    ga2uri.values().forEach(l -> {
        if (l.size() > 1) {
            haveDuplicates.addAll(l);
        }
    });
    if (result == null) {
        return;
    }
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(result))) {
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        writer.write("<?xml-stylesheet type=\"text/xsl\" href=\"bundle-report.xslt\"?>\n");
        writer.write("<consistency-report xmlns=\"urn:apache:karaf:consistency:1.0\">\n");
        writer.write("    <duplicates>\n");
        ga2uri.forEach((key, uris) -> {
            if (uris.size() > 1) {
                try {
                    writer.write(String.format("        <duplicate ga=\"%s\">\n", key));
                    for (String uri : uris) {
                        writer.write(String.format("            <bundle uri=\"%s\">\n", sanitize(uri)));
                        for (String fid : bundle2featureId.get(uri)) {
                            writer.write(String.format("                <feature repository=\"%s\">%s</feature>\n", featureId2repository.get(fid), fid));
                        }
                        writer.write("            </bundle>\n");
                    }
                    writer.write("        </duplicate>\n");
                } catch (IOException e) {
                }
            }
        });
        writer.write("    </duplicates>\n");
        writer.write("    <bundles>\n");
        for (String uri : bundle2featureId.keySet()) {
            writer.write(String.format("        <bundle uri=\"%s\" duplicate=\"%b\">\n", sanitize(uri), haveDuplicates.contains(uri)));
            for (String fid : bundle2featureId.get(uri)) {
                writer.write(String.format("            <feature>%s</feature>\n", fid));
            }
            writer.write("        </bundle>\n");
        }
        writer.write("    </bundles>\n");
        writer.write("</consistency-report>\n");
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : Manifest(java.util.jar.Manifest) Dependency(org.apache.karaf.features.internal.model.Dependency) Profile(org.apache.karaf.profile.Profile) Arrays(java.util.Arrays) MultiException(org.apache.karaf.features.internal.util.MultiException) FeaturesProcessorImpl(org.apache.karaf.features.internal.service.FeaturesProcessorImpl) Constants(org.osgi.framework.Constants) FeaturePattern(org.apache.karaf.features.FeaturePattern) KarafPropertiesEditor(org.apache.karaf.tools.utils.KarafPropertiesEditor) LoggerFactory(org.slf4j.LoggerFactory) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) FeaturesService(org.apache.karaf.features.FeaturesService) Collections.singletonList(java.util.Collections.singletonList) Clause(org.apache.felix.utils.manifest.Clause) ByteArrayInputStream(java.io.ByteArrayInputStream) JaxbUtil(org.apache.karaf.features.internal.model.JaxbUtil) Map(java.util.Map) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) URI(java.net.URI) Repository(org.osgi.service.repository.Repository) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) BundleRevision(org.osgi.framework.wiring.BundleRevision) MavenResolver(org.ops4j.pax.url.mvn.MavenResolver) BundleInfo(org.apache.karaf.features.BundleInfo) Blacklist(org.apache.karaf.features.internal.service.Blacklist) Deployer(org.apache.karaf.features.internal.service.Deployer) MapUtils(org.apache.karaf.features.internal.util.MapUtils) Collection(java.util.Collection) Set(java.util.Set) MANIFEST_NAME(java.util.jar.JarFile.MANIFEST_NAME) UUID(java.util.UUID) Library(org.apache.karaf.features.Library) FileSystem(java.nio.file.FileSystem) Attributes(java.util.jar.Attributes) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ThreadUtils(org.apache.karaf.util.ThreadUtils) List(java.util.List) PropertiesLoader(org.apache.karaf.util.config.PropertiesLoader) Properties(org.apache.felix.utils.properties.Properties) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) DownloadManager(org.apache.karaf.features.internal.download.DownloadManager) Features(org.apache.karaf.features.internal.model.Features) Dictionary(java.util.Dictionary) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DownloadCallback(org.apache.karaf.features.internal.download.DownloadCallback) HashMap(java.util.HashMap) ResourceBuilder(org.apache.karaf.features.internal.resolver.ResourceBuilder) Kar(org.apache.karaf.kar.internal.Kar) Function(java.util.function.Function) TreeSet(java.util.TreeSet) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StreamProvider(org.apache.karaf.features.internal.download.StreamProvider) ProfileBuilder(org.apache.karaf.profile.ProfileBuilder) Parser(org.apache.karaf.util.maven.Parser) BaseRepository(org.apache.karaf.features.internal.repository.BaseRepository) FeaturesProcessor(org.apache.karaf.features.internal.service.FeaturesProcessor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Bundle(org.apache.karaf.features.internal.model.Bundle) MavenResolvers(org.ops4j.pax.url.mvn.MavenResolvers) Downloader(org.apache.karaf.features.internal.download.Downloader) LinkedList(java.util.LinkedList) Hashtable(java.util.Hashtable) LinkedHashSet(java.util.LinkedHashSet) LocationPattern(org.apache.karaf.features.LocationPattern) Logger(org.slf4j.Logger) Profiles(org.apache.karaf.profile.impl.Profiles) MalformedURLException(java.net.MalformedURLException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) Conditional(org.apache.karaf.features.internal.model.Conditional) BufferedWriter(java.io.BufferedWriter) Resource(org.osgi.resource.Resource) Version(org.apache.karaf.util.Version) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Resolver(org.osgi.service.resolver.Resolver) KarafPropertyEdits(org.apache.karaf.tools.utils.model.KarafPropertyEdits) File(java.io.File) Overrides(org.apache.karaf.features.internal.service.Overrides) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) Feature(org.apache.karaf.features.internal.model.Feature) URLUtils(org.ops4j.net.URLUtils) Startup(org.apache.karaf.profile.assembly.Builder.Stage.Startup) Collections(java.util.Collections) FileSystems(java.nio.file.FileSystems) InputStream(java.io.InputStream) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FileWriter(java.io.FileWriter) IOException(java.io.IOException) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) BufferedWriter(java.io.BufferedWriter) LocationPattern(org.apache.karaf.features.LocationPattern) TreeSet(java.util.TreeSet) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 FileSystem (java.nio.file.FileSystem)1 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)1 FileSystems (java.nio.file.FileSystems)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1