felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1485173 - in /felix/sandbox/fmeschbe/version-report: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/versionreport/ src/main/java/org/apache/felix...
Date Wed, 22 May 2013 12:14:47 GMT
Author: fmeschbe
Date: Wed May 22 12:14:47 2013
New Revision: 1485173

URL: http://svn.apache.org/r1485173
Log:
Simple Bundle and Package Export check reporter

Added:
    felix/sandbox/fmeschbe/version-report/   (with props)
    felix/sandbox/fmeschbe/version-report/pom.xml   (with props)
    felix/sandbox/fmeschbe/version-report/src/
    felix/sandbox/fmeschbe/version-report/src/main/
    felix/sandbox/fmeschbe/version-report/src/main/java/
    felix/sandbox/fmeschbe/version-report/src/main/java/org/
    felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/
    felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/
    felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/versionreport/
    felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/versionreport/impl/
    felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/versionreport/impl/VersionReport.java

Propchange: felix/sandbox/fmeschbe/version-report/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed May 22 12:14:47 2013
@@ -0,0 +1,4 @@
+.classpath
+.settings
+.project
+target

Added: felix/sandbox/fmeschbe/version-report/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/version-report/pom.xml?rev=1485173&view=auto
==============================================================================
--- felix/sandbox/fmeschbe/version-report/pom.xml (added)
+++ felix/sandbox/fmeschbe/version-report/pom.xml Wed May 22 12:14:47 2013
@@ -0,0 +1,112 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+    http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>felix-parent</artifactId>
+        <version>2.1</version>
+    </parent>
+
+    <artifactId>org.apache.felix.version-report</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Apache Felix Version Report Inventory Printer</name>
+    <description>
+        Inventory Printer which analyzes the versions of resolved
+        bundles:
+          * Release bundles have even micro version number
+          * SNAPSHOT bundles have odd micro version number
+          * Exported Package is not the same as bundle version
+          * Exported Package is exported with a version
+    </description>
+
+    <!--
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/webconsole</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/trunk/webconsole</developerConnection>
+        <url>http://svn.apache.org/viewvc/felix/trunk/webconsole</url>
+    </scm>
+    -->
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.9.0</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-scrdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                        <configuration>
+                            <properties>
+                                <service.vendor>The Apache Software Foundation</service.vendor>
+                            </properties>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.3.7</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>core</artifactId>
+            <version>4.3.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.inventory</artifactId>
+            <version>1.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.7.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

Propchange: felix/sandbox/fmeschbe/version-report/pom.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/versionreport/impl/VersionReport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/versionreport/impl/VersionReport.java?rev=1485173&view=auto
==============================================================================
--- felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/versionreport/impl/VersionReport.java
(added)
+++ felix/sandbox/fmeschbe/version-report/src/main/java/org/apache/felix/versionreport/impl/VersionReport.java
Wed May 22 12:14:47 2013
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.versionreport.impl;
+
+import java.io.PrintWriter;
+
+import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+@Component()
+@Service
+@Properties({
+    @Property(name = InventoryPrinter.NAME, value = "version-report"),
+    @Property(name = InventoryPrinter.TITLE, value = "Bundle/Package Version Report"),
+    @Property(name = InventoryPrinter.FORMAT, value = {
+        "text", "HTML"
+    })
+})
+public class VersionReport implements InventoryPrinter {
+
+    @Reference
+    private PackageAdmin packageAdmin;
+
+    private BundleContext bundleContext;
+
+    @Activate
+    private void activate(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
+    @Deactivate
+    private void deactivate() {
+        this.bundleContext = null;
+    }
+
+    public void print(PrintWriter pw, Format format, boolean isZip) {
+
+        final String preamble;
+        final String lineFormat;
+        final String postamble;
+        if (format == Format.HTML) {
+            preamble = "<table class='ui-widget nicetable'><tr class='ui-widget-header'><th>Bundle</th><th>Bundle
Version</th><th>No Export Version</th><th>Same Export Version</th></tr>";
+            lineFormat = "<tr class='ui-widget-content'><td>%s (%s, %s)</td><td>%s</td><td>%s</td><td>%s</td></tr>%n";
+            postamble = "</table>";
+        } else {
+            preamble = "Bundle;Bundle Version;No Export Version;Same Export Version"; //
CSV headers ??
+            lineFormat = "%s (%s, %s);%s;%s;%s%n";
+            postamble = "";
+        }
+
+        Bundle[] bundles = getBundles();
+
+        pw.println(preamble);
+
+        for (final Bundle bundle : bundles) {
+            final Version bundleVersion = bundle.getVersion();
+            final String[] msg = checkBundleVersion(bundleVersion);
+
+            final ExportedPackage[] exports = this.packageAdmin.getExportedPackages(bundle);
+            boolean isEmpty = false;
+            boolean isSame = false;
+            if (exports != null) {
+                for (final ExportedPackage export : exports) {
+                    final Version exportVersion = export.getVersion();
+                    final boolean[] check = checkExportVersion(exportVersion, bundleVersion);
+                    isEmpty |= check[0];
+                    isSame |= check[1];
+                }
+            }
+
+            if (msg[1].length() > 0 || isEmpty || isSame) {
+                final String empty = isEmpty ? "YES" : "";
+                final String same = isSame ? "YES" : "";
+                pw.printf(lineFormat, bundle.getHeaders().get(Constants.BUNDLE_NAME), bundle.getSymbolicName(),
+                    bundleVersion, msg[1], empty, same);
+            }
+        }
+
+        pw.println(postamble);
+    }
+
+    private Bundle[] getBundles() {
+        if (this.bundleContext == null) {
+            return new Bundle[0];
+        }
+
+        return this.bundleContext.getBundles();
+    }
+
+    private String[] checkBundleVersion(final Version bundleVersion) {
+        final boolean isOddMicro = (bundleVersion.getMicro() & 0x1) == 1;
+        final boolean isSnapshot = bundleVersion.getQualifier().contains("SNAPSHOT");
+
+        if (isSnapshot) {
+            return new String[] {
+                "snapshot", (isOddMicro) ? "" : "Must be Odd"
+            };
+        }
+
+        return new String[] {
+            "release", (isOddMicro) ? "Must be Even" : ""
+        };
+    }
+
+    private boolean[] checkExportVersion(final Version exportVersion, final Version bundleVersion)
{
+        if (exportVersion.equals(Version.emptyVersion)) {
+            return new boolean[] {
+                true, false
+            };
+        }
+
+        if (exportVersion.equals(bundleVersion)) {
+            return new boolean[] {
+                false, true
+            };
+        }
+
+        return new boolean[] {
+            false, false
+        };
+    }
+}



Mime
View raw message