You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2018/04/06 07:17:50 UTC

[sling-org-apache-sling-installer-hc] branch master updated: SLING-7573 update to newest parent

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-hc.git


The following commit(s) were added to refs/heads/master by this push:
     new 104e223  SLING-7573 update to newest parent
104e223 is described below

commit 104e2234541282f82206490816f3d144da9e0fda
Author: Konrad Windszus <ko...@netcentric.biz>
AuthorDate: Fri Apr 6 09:17:30 2018 +0200

    SLING-7573 update to newest parent
    
    migrate to OSGi annotations
    leverage bnd-maven-plugin
---
 bnd.bnd                                            |  9 +++
 pom.xml                                            | 69 ++++++++--------
 .../installer/hc/OsgiInstallerHealthCheck.java     | 93 ++++++++++------------
 3 files changed, 88 insertions(+), 83 deletions(-)

diff --git a/bnd.bnd b/bnd.bnd
new file mode 100644
index 0000000..d04ebf4
--- /dev/null
+++ b/bnd.bnd
@@ -0,0 +1,9 @@
+Bundle-Category: sling
+
+Bundle-Description: ${project.description}
+
+Bundle-DocURL: https://sling.apache.org
+
+Bundle-License: Apache License, Version 2.0
+
+Bundle-Vendor: The Apache Software Foundation
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3bd5e8d..2a6e998 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,27 +1,27 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- 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 
+<!-- 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">
+<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.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>29</version>
-        <relativePath />
+        <version>33</version>
+        <relativePath/>
     </parent>
 
     <artifactId>org.apache.sling.installer.hc</artifactId>
-    <version>1.0.1-SNAPSHOT</version>
-    <packaging>bundle</packaging>
+    <version>2.0.0-SNAPSHOT</version>
 
     <name>Apache Sling Installer Health Checks</name>
     <description> 
@@ -34,7 +34,7 @@
         <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-installer-hc.git</url>
     </scm>
 
-    <!-- make compile with java 7 -->
+    <!-- compile with java 7 -->
     <properties>
         <sling.java.version>7</sling.java.version>
     </properties>
@@ -42,13 +42,12 @@
     <build>
         <plugins>
             <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-scr-plugin</artifactId>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
             </plugin>
             <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-baseline-maven-plugin</artifactId>
             </plugin>
         </plugins>
     </build>
@@ -61,7 +60,22 @@
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>osgi.cmpn</artifactId>
+            <artifactId>org.osgi.service.component</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.metatype.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.cm</artifactId>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -70,7 +84,7 @@
             <version>2.2.0</version>
             <scope>provided</scope>
         </dependency>
-        <!-- reference old API bundle to generate broader import ranges making 
+        <!-- reference old API bundle to generate broader import ranges making
             this HC bundle compliant with older versions as well -->
         <dependency>
             <groupId>org.apache.sling</groupId>
@@ -90,21 +104,10 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.hc.core</artifactId>
             <version>1.0.4</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.hc.annotations</artifactId>
-            <version>1.0.4</version>
-            <scope>provided</scope>
-        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/installer/hc/OsgiInstallerHealthCheck.java b/src/main/java/org/apache/sling/installer/hc/OsgiInstallerHealthCheck.java
index 52a7d8b..27e84f8 100644
--- a/src/main/java/org/apache/sling/installer/hc/OsgiInstallerHealthCheck.java
+++ b/src/main/java/org/apache/sling/installer/hc/OsgiInstallerHealthCheck.java
@@ -20,13 +20,7 @@ package org.apache.sling.installer.hc;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.hc.annotations.SlingHealthCheck;
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
 import org.apache.sling.hc.util.FormattingResultLog;
@@ -35,19 +29,20 @@ import org.apache.sling.installer.api.info.InfoProvider;
 import org.apache.sling.installer.api.info.InstallationState;
 import org.apache.sling.installer.api.info.Resource;
 import org.apache.sling.installer.api.info.ResourceGroup;
+import org.apache.sling.installer.hc.OsgiInstallerHealthCheck.Configuration;
 import org.osgi.framework.Version;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@SlingHealthCheck(
-    name = OsgiInstallerHealthCheck.HC_NAME,
-    description = "Checks that all OSGi configurations/bundles are successfully installed by the OSGi Installer (and are not skipped for some reason).",
-    tags = {
-        "installer",
-        "osgi"
-    }
-)
+@Component(property={ HealthCheck.NAME+"="+OsgiInstallerHealthCheck.HC_NAME })
+@Designate(ocd=Configuration.class)
 public class OsgiInstallerHealthCheck implements HealthCheck {
     protected static final String HC_NAME = "OSGi Installer Health Check";
 
@@ -56,44 +51,42 @@ public class OsgiInstallerHealthCheck implements HealthCheck {
 
     private static final Logger LOG = LoggerFactory.getLogger(OsgiInstallerHealthCheck.class);
 
-    private static final String DEFAULT_URL_PREFIX = "jcrinstall:/apps/";
-
-    @Property(label = "URL Prefixes to consider", description = "Only those OSGi configurations/bundles whose location are starting with one of the given URL prefixes are checked (whether they are installed correctly). Open /system/console/osgi-installer for a list of valid prefixes.", cardinality = 1, value = DEFAULT_URL_PREFIX)
-    static final String PROP_URL_PREFIXES = "urlPrefixes";
-
-    @Property(label = "Check Bundles", description = "If enabled bundles are checked (restricted to the ones matching one of the prefixes)", boolValue = true)
-    static final String PROP_CHECK_BUNDLES = "checkBundles";
-
-    @Property(label = "Check Configurations", description = "If enabled configurations are checked (restricted to the ones matching one of the prefixes)", boolValue = true)
-    static final String PROP_CHECK_CONFIGURATIONS = "checkConfigurations";
-
-    @Property(label = "Allow not installed artifacts in a group", description="If true there is no warning reported if at least one artifact in the same group (i.e. with the same entity id) is installed matching one of the configured URL prefixes. Otherwise there is a warning for every not installed artifact", boolValue=false)
-    static final String PROP_CHECK_ALLOW_NOT_INSTALLED_ARTIFACTS_IN_GROUP = "allowNotInstalledArtifactsInAGroup";
-    
-    @Property(label = "Skip entity ids", description="The given entity ids should be skipped for the health check. Each entry has the format '<entity id> [<version>]", cardinality = 1)
-    static final String PROP_SKIP_ENTITY_IDS = "skipEntityIds";
-    
-    private String[] urlPrefixes;
+    private Configuration configuration;
     private Map<String, Version> skipEntityIdsWithVersions;
-    private boolean checkBundles;
-    private boolean checkConfigurations;
-    private boolean allowNotInstalledArtifactsInAGroup;
     
     private final static String DOCUMENTATION_URL = "https://sling.apache.org/documentation/bundles/osgi-installer.html#health-check";
 
     @Reference
     private ConfigurationAdmin configurationAdmin;
+    
+    @ObjectClassDefinition(name = HC_NAME, 
+            description="Checks that all OSGi configurations/bundles are successfully installed by the OSGi Installer (and are not skipped for some reason).")
+    protected static @interface Configuration {
+        @AttributeDefinition(name="Tags", description="Tags with which this healthcheck is associated")
+        String[] tags() default {"installer", "osgi"};
+        
+        @AttributeDefinition(name="URL Prefixes to consider", description = "Only those OSGi configurations/bundles whose location are starting with one of the given URL prefixes are checked (whether they are installed correctly). Open /system/console/osgi-installer for a list of valid prefixes.")
+        String[] urlPrefixes() default "jcrinstall:/apps/";
+        
+        @AttributeDefinition(name="Check Bundles", description = "If enabled bundles are checked (restricted to the ones matching one of the prefixes)")
+        boolean checkBundles() default true;
+        
+        @AttributeDefinition(name="Check Configurations", description = "If enabled configurations are checked (restricted to the ones matching one of the prefixes)")
+        boolean checkConfigurations() default true;
+        
+        @AttributeDefinition(name="Allow ignored artifacts in a group", description = "If true there is no warning reported for not installed artifacts if at least one artifact in the same group (i.e. with the same entity id) is installed matching one of the configured URL prefixes. Otherwise there is a warning for every ignored artifact.")
+        boolean allowIgnoredArtifactsInGroup() default false;
+        
+        @AttributeDefinition(name="Skip entity ids", description = "The given entity ids should be skipped for the health check. Each entry has the format '<entity id> [<version>]'.")
+        String[] skipEntityIds();
+    }
 
     @Activate
-    public void activate(Map<String, ?> properties) {
-        urlPrefixes = PropertiesUtil.toStringArray(properties.get(PROP_URL_PREFIXES),
-                new String[] { DEFAULT_URL_PREFIX });
-        checkBundles = PropertiesUtil.toBoolean(properties.get(PROP_CHECK_BUNDLES), true);
-        checkConfigurations = PropertiesUtil.toBoolean(properties.get(PROP_CHECK_CONFIGURATIONS), true);
-        allowNotInstalledArtifactsInAGroup = PropertiesUtil.toBoolean(properties.get(PROP_CHECK_ALLOW_NOT_INSTALLED_ARTIFACTS_IN_GROUP), false);
-        skipEntityIdsWithVersions = parseEntityIdsWithVersions(PropertiesUtil.toStringArray(properties.get(PROP_SKIP_ENTITY_IDS), null));
+    protected void activate(Configuration configuration) {
+        this.configuration = configuration;
+        skipEntityIdsWithVersions = parseEntityIdsWithVersions(configuration.skipEntityIds());
     }
-    
+
     private Map<String, Version> parseEntityIdsWithVersions(String[] entityIdsAndVersions) throws IllegalArgumentException {
         Map<String, Version> entityIdsWithVersions = new HashMap<>();
         if (entityIdsAndVersions != null) {
@@ -156,13 +149,13 @@ public class OsgiInstallerHealthCheck implements HealthCheck {
             resourceType = resource.getType();
             switch (resourceType) {
             case InstallableResource.TYPE_CONFIG:
-                if (!checkConfigurations) {
+                if (!configuration.checkConfigurations()) {
                     LOG.debug("Skip resource '{}', configuration checks are disabled", resource.getEntityId());
                     return "";
                 }
                 break;
             case InstallableResource.TYPE_BUNDLE:
-                if (!checkBundles) {
+                if (!configuration.checkBundles()) {
                     LOG.debug("Skip resource '{}', bundle checks are disabled", resource.getEntityId());
                     return "";
                 }
@@ -172,13 +165,13 @@ public class OsgiInstallerHealthCheck implements HealthCheck {
                         resource.getEntityId(), resourceType);
                 return "";
             }
-            if (StringUtils.startsWithAny(resource.getURL(), urlPrefixes)) {
+            if (StringUtils.startsWithAny(resource.getURL(), configuration.urlPrefixes())) {
                 isGroupRelevant = true;
                 switch (resource.getState()) {
                 case IGNORED: // means a considered resource was found and it is invalid
                     // still the other resources need to be evaluated
                 case INSTALL:
-                    if (!allowNotInstalledArtifactsInAGroup) {
+                    if (!configuration.allowIgnoredArtifactsInGroup()) {
                         reportInvalidResource(resource, resourceType, hcLog);
                     } else {
                         if (invalidResource == null) {
@@ -187,7 +180,7 @@ public class OsgiInstallerHealthCheck implements HealthCheck {
                     }
                     break;
                 default:
-                    if (allowNotInstalledArtifactsInAGroup) {
+                    if (configuration.allowIgnoredArtifactsInGroup()) {
                         // means a considered resource was found and it is valid
                         // no need to evaluate other resources from this group
                         return resourceType;
@@ -195,10 +188,10 @@ public class OsgiInstallerHealthCheck implements HealthCheck {
                 }
             } else {
                 LOG.debug("Skipping resource '{}' as its URL is not starting with any of these prefixes'{}'", resource,
-                        StringUtils.join(urlPrefixes, ","));
+                        StringUtils.join(configuration.urlPrefixes(), ","));
             }
         }
-        if (invalidResource != null && allowNotInstalledArtifactsInAGroup) {
+        if (invalidResource != null && configuration.allowIgnoredArtifactsInGroup()) {
             reportInvalidResource(invalidResource, resourceType, hcLog);
         }
         

-- 
To stop receiving notification emails like this one, please contact
kwin@apache.org.