sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1797769 - in /sling/whiteboard/cziegeler/feature-support/src: main/java/org/apache/sling/feature/support/ test/java/org/apache/sling/feature/support/
Date Tue, 06 Jun 2017 10:20:37 GMT
Author: cziegeler
Date: Tue Jun  6 10:20:37 2017
New Revision: 1797769

URL: http://svn.apache.org/viewvc?rev=1797769&view=rev
Log:
Add support to create a configurator bundle out of configurations

Added:
    sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/ConfigurationUtil.java
  (with props)
    sling/whiteboard/cziegeler/feature-support/src/test/java/org/apache/sling/feature/support/FeatureUtilTest.java
  (with props)
Modified:
    sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java

Added: sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/ConfigurationUtil.java?rev=1797769&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/ConfigurationUtil.java
(added)
+++ sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/ConfigurationUtil.java
Tue Jun  6 10:20:37 2017
@@ -0,0 +1,74 @@
+/*
+ * 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.sling.feature.support;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.List;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.apache.sling.feature.Configuration;
+import org.apache.sling.feature.json.ConfigurationJSONWriter;
+
+
+public class ConfigurationUtil {
+
+    /**
+     * Create a bundle containing the configurations to be processed the
+     * OSGi configurator
+     *
+     * @param os The output stream. The stream is not closed
+     * @param configurations The list of configurations
+     * @param symbolicName The symbolic name for the generated bundle
+     * @param version The version for the generated bundle
+     * @throws IOException If something goes wrong
+     */
+    public static void createConfiguratorBundle(final OutputStream os,
+            final List<Configuration> configurations,
+            final String symbolicName,
+            final String version) throws IOException {
+
+        final Manifest mf = new Manifest();
+        mf.getMainAttributes().putValue("Manifest-Version", "1.0");
+        mf.getMainAttributes().putValue("Bundle-ManifestVersion", "2");
+        mf.getMainAttributes().putValue("Bundle-SymbolicName", symbolicName);
+        mf.getMainAttributes().putValue("Bundle-Version", version);
+        mf.getMainAttributes().putValue("Bundle-Vendor", "The Apache Software Foundation");
+        // Require configurator
+        mf.getMainAttributes().putValue("Require-Capability",  "osgi.implementation;filter:=\"(&(osgi.implementation=osgi.configurator)(version>=1.0)(!(version>=2.0)))\"");
+        // TODO additional attributes
+
+        final JarOutputStream jos = new JarOutputStream(os, mf);
+
+        final ZipEntry ze = new ZipEntry("OSGI-INF/configurator/configurations.json");
+        jos.putNextEntry(ze);
+        final Writer w = new OutputStreamWriter(jos, "UTF-8");
+        w.write("{\n");
+        w.write("\"configurations\" : ");
+        ConfigurationJSONWriter.write(w, configurations);
+        w.write("\n}\n");
+        w.flush();
+        jos.closeEntry();
+
+        jos.flush();
+        jos.finish();
+    }
+}

Propchange: sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/ConfigurationUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/ConfigurationUtil.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Modified: sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java?rev=1797769&r1=1797768&r2=1797769&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
(original)
+++ sling/whiteboard/cziegeler/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
Tue Jun  6 10:20:37 2017
@@ -48,7 +48,7 @@ public class FeatureUtil {
                 version != null ? version : "5.6.4", null, null);
     }
 
-    private static final Comparator<String> FEATURE_PATH_COMP = new Comparator<String>()
{
+    static final Comparator<String> FEATURE_PATH_COMP = new Comparator<String>()
{
 
         @Override
         public int compare(final String o1, final String o2) {

Added: sling/whiteboard/cziegeler/feature-support/src/test/java/org/apache/sling/feature/support/FeatureUtilTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-support/src/test/java/org/apache/sling/feature/support/FeatureUtilTest.java?rev=1797769&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-support/src/test/java/org/apache/sling/feature/support/FeatureUtilTest.java
(added)
+++ sling/whiteboard/cziegeler/feature-support/src/test/java/org/apache/sling/feature/support/FeatureUtilTest.java
Tue Jun  6 10:20:37 2017
@@ -0,0 +1,49 @@
+/*
+ * 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.sling.feature.support;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+
+public class FeatureUtilTest {
+
+    @Test public void testFileSort() {
+        final String[] files = new String[] {
+            "/different/path/app.json",
+            "/path/to/base.json",
+            "/path/to/feature.json",
+            "/path/to/amode/feature.json",
+            "/path/to/later/feature.json",
+            "http://sling.apache.org/features/one.json",
+            "http://sling.apache.org/features/two.json",
+            "http://sling.apache.org/features/amode/feature.json"
+        };
+
+        final List<String> l = new ArrayList<>(Arrays.asList(files));
+        Collections.sort(l, FeatureUtil.FEATURE_PATH_COMP);
+        for(int i=0; i<files.length; i++) {
+            assertEquals(files[i], l.get(i));
+        }
+    }
+
+}

Propchange: sling/whiteboard/cziegeler/feature-support/src/test/java/org/apache/sling/feature/support/FeatureUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/cziegeler/feature-support/src/test/java/org/apache/sling/feature/support/FeatureUtilTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url



Mime
View raw message