You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2018/01/24 16:57:49 UTC

svn commit: r1822123 - in /felix/trunk/osgi-r7/configurator/src/main/java/org: apache/felix/configurator/impl/json/JSONUtil.java osgi/service/configurator/ConfiguratorConstants.java

Author: cziegeler
Date: Wed Jan 24 16:57:49 2018
New Revision: 1822123

URL: http://svn.apache.org/viewvc?rev=1822123&view=rev
Log:
Require version and symbolic name for initial configurations (not in a bundle)

Modified:
    felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
    felix/trunk/osgi-r7/configurator/src/main/java/org/osgi/service/configurator/ConfiguratorConstants.java

Modified: felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java?rev=1822123&r1=1822122&r2=1822123&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java (original)
+++ felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java Wed Jan 24 16:57:49 2018
@@ -53,13 +53,12 @@ import org.apache.felix.configurator.imp
 import org.apache.felix.configurator.impl.model.Config;
 import org.apache.felix.configurator.impl.model.ConfigPolicy;
 import org.apache.felix.configurator.impl.model.ConfigurationFile;
+import org.osgi.service.configurator.ConfiguratorConstants;
 
 public class JSONUtil {
 
     private static final String INTERNAL_PREFIX = ":configurator:";
 
-    private static final String PROP_VERSION = INTERNAL_PREFIX + "resource-version";
-
     private static final String PROP_RANKING = "ranking";
 
     private static final String PROP_POLICY = "policy";
@@ -161,7 +160,7 @@ public class JSONUtil {
             final Report report) {
         final String identifier = (url == null ? name : url.toString());
         final JsonObject json = parseJSON(name, contents, report);
-        final Map<String, ?> configs = verifyJSON(name, json, report);
+        final Map<String, ?> configs = verifyJSON(name, json, url != null, report);
         if ( configs != null ) {
             final List<Config> list = readConfigurationsJSON(converter, bundleId, identifier, configs, report);
             if ( !list.isEmpty() ) {
@@ -431,21 +430,44 @@ public class JSONUtil {
     @SuppressWarnings("unchecked")
     public static Map<String, ?> verifyJSON(final String name,
             final JsonObject root,
+            final boolean bundleResource,
             final Report report) {
         if ( root == null ) {
             return null;
         }
-        final Object version = getValue(root, PROP_VERSION);
+        final Object version = getValue(root, ConfiguratorConstants.PROPERTY_RESOURCE_VERSION);
         if ( version != null ) {
 
             final int v = TypeConverter.getConverter().convert(version).defaultValue(-1).to(Integer.class);
             if ( v == -1 ) {
-                report.errors.add("Invalid version information in " + name + " : " + version);
+                report.errors.add("Invalid resource version information in " + name + " : " + version);
                 return null;
             }
             // we only support version 1
             if ( v != 1 ) {
-                report.errors.add("Invalid version number in " + name + " : " + version);
+                report.errors.add("Invalid resource version number in " + name + " : " + version);
+                return null;
+            }
+        }
+        if ( !bundleResource) {
+            // if this is not a bundle resource
+            // then version and symbolic name must be set
+            final Object rsrcVersion = getValue(root, ConfiguratorConstants.PROPERTY_VERSION);
+            if ( rsrcVersion == null ) {
+                report.errors.add("Missing version information in " + name);
+                return null;
+            }
+            if ( !(rsrcVersion instanceof String) ) {
+                report.errors.add("Invalid version information in " + name + " : " + rsrcVersion);
+                return null;
+            }
+            final Object rsrcName = getValue(root, ConfiguratorConstants.PROPERTY_SYMBOLIC_NAME);
+            if ( rsrcName == null ) {
+                report.errors.add("Missing symbolic name information in " + name);
+                return null;
+            }
+            if ( !(rsrcName instanceof String) ) {
+                report.errors.add("Invalid symbolic name information in " + name + " : " + rsrcName);
                 return null;
             }
         }

Modified: felix/trunk/osgi-r7/configurator/src/main/java/org/osgi/service/configurator/ConfiguratorConstants.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/main/java/org/osgi/service/configurator/ConfiguratorConstants.java?rev=1822123&r1=1822122&r2=1822123&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/main/java/org/osgi/service/configurator/ConfiguratorConstants.java (original)
+++ felix/trunk/osgi-r7/configurator/src/main/java/org/osgi/service/configurator/ConfiguratorConstants.java Wed Jan 24 16:57:49 2018
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) OSGi Alliance (2017). All Rights Reserved.
- *
+ * 
  * Licensed 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
@@ -18,7 +18,7 @@ package org.osgi.service.configurator;
 
 /**
  * Defines standard constants for the Configurator services.
- *
+ * 
  * @author $Id$
  */
 public final class ConfiguratorConstants {
@@ -54,30 +54,38 @@ public final class ConfiguratorConstants
 
 	/**
 	 * Prefix to mark properties as input for the Configurator when processing a
-	 * configuration.
+	 * configuration resource.
 	 */
 	public static final String	PROPERTY_PREFIX			= ":configurator:";
 
 	/**
-	 * Global property in the configuration JSON specifying the version of the
-	 * JSON format.
+	 * Global property in the configuration resource specifying the version of
+	 * the resource format.
 	 * <p>
 	 * Currently only version {@code 1} is defined for the JSON format and
 	 * therefore the only allowed value is {@code 1} for this property. If this
 	 * property is not specified, {@code 1} is assumed.
 	 */
-	public static final String	PROPERTY_JSON_VERSION	= PROPERTY_PREFIX
-			+ "json-version";
+	public static final String	PROPERTY_RESOURCE_VERSION	= PROPERTY_PREFIX
+			+ "resource-version";
 
 	/**
-	 * Configuration property holding the optional information about the
-	 * environments where the configuration applies.
-	 * <p>
-	 * The value of this property must either be of type {@code String} or {code
-	 * String[]}.
+	 * Global property in the configuration resource specifying the symbolic
+	 * name of the configuration resource. If not specified the symbolic name of
+	 * the bundle containing the resource is used. Mandatory for configuration
+	 * resources that do not reside in a bundle
+	 */
+	public static final String	PROPERTY_SYMBOLIC_NAME		= PROPERTY_PREFIX
+			+ "symbolic-name";
+
+	/**
+	 * Global property in the configuration resource specifying the version of
+	 * the resource. If not specified the version of the bundle containing the
+	 * resource is used. Mandatory for configuration resources that do not
+	 * reside in a bundle.
 	 */
-	public static final String	PROPERTY_ENVIRONMENTS	= PROPERTY_PREFIX
-			+ "environments";
+	public static final String	PROPERTY_VERSION			= PROPERTY_PREFIX
+			+ "version";
 
 	/**
 	 * Configuration property for the configuration ranking.
@@ -91,7 +99,7 @@ public final class ConfiguratorConstants
 	 * Configuration property for the configuration policy.
 	 * <p>
 	 * Allowed values are {@link #POLICY_DEFAULT} and {@link #POLICY_FORCE}
-	 *
+	 * 
 	 * @see #POLICY_DEFAULT
 	 * @see #POLICY_FORCE
 	 */
@@ -100,14 +108,14 @@ public final class ConfiguratorConstants
 
 	/**
 	 * Value for defining the default policy.
-	 *
+	 * 
 	 * @see #PROPERTY_POLICY
 	 */
 	public static final String	POLICY_DEFAULT			= "default";
 
 	/**
 	 * Value for defining the force policy.
-	 *
+	 * 
 	 * @see #PROPERTY_POLICY
 	 */
 	public static final String	POLICY_FORCE			= "force";