You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/06/06 15:43:22 UTC
svn commit: r1797796 - in /sling/whiteboard/cziegeler: feature-karaf/
feature-karaf/src/ feature-karaf/src/main/ feature-karaf/src/main/java/
feature-karaf/src/main/java/org/ feature-karaf/src/main/java/org/apache/
feature-karaf/src/main/java/org/apach...
Author: cziegeler
Date: Tue Jun 6 15:43:22 2017
New Revision: 1797796
URL: http://svn.apache.org/viewvc?rev=1797796&view=rev
Log:
Add karaf kar export
Added:
sling/whiteboard/cziegeler/feature-karaf/
sling/whiteboard/cziegeler/feature-karaf/pom.xml (with props)
sling/whiteboard/cziegeler/feature-karaf/src/
sling/whiteboard/cziegeler/feature-karaf/src/main/
sling/whiteboard/cziegeler/feature-karaf/src/main/java/
sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/
sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/
sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/
sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/
sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/
sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/KarafFeatureWriter.java (with props)
sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/package-info.java (with props)
sling/whiteboard/cziegeler/feature-karaf/src/test/
Modified:
sling/whiteboard/cziegeler/feature/pom.xml
Added: sling/whiteboard/cziegeler/feature-karaf/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-karaf/pom.xml?rev=1797796&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-karaf/pom.xml (added)
+++ sling/whiteboard/cziegeler/feature-karaf/pom.xml Tue Jun 6 15:43:22 2017
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+ <!--
+ 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.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>30</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>org.apache.sling.feature.karaf</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Feature</name>
+ <description>
+ A feature describes an OSGi system
+ </description>
+
+ <properties>
+ <sling.java.version>8</sling.java.version>
+ </properties>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/tooling/support/feature-karaf</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/tooling/support/feature-karaf</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/tooling/support/feature-karaf</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.feature</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.feature.support</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: sling/whiteboard/cziegeler/feature-karaf/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-karaf/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/KarafFeatureWriter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/KarafFeatureWriter.java?rev=1797796&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/KarafFeatureWriter.java (added)
+++ sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/KarafFeatureWriter.java Tue Jun 6 15:43:22 2017
@@ -0,0 +1,172 @@
+/*
+ * 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.karaf;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.support.ArtifactHandler;
+import org.apache.sling.feature.support.ArtifactManager;
+import org.apache.sling.feature.support.ConfigurationUtil;
+
+
+/**
+ * This writer writes out a Karaf feature XML.
+ *
+ */
+public class KarafFeatureWriter {
+
+ public static void writeKAR(final OutputStream os,
+ final Feature feature,
+ final ArtifactManager artifactManager)
+ throws IOException {
+ File configurationBundleFile = null;
+ Artifact configuratorBundle = null;
+ try {
+ if ( !feature.getConfigurations().isEmpty() ) {
+ configurationBundleFile = Files.createTempFile(null, null).toFile();
+
+ try ( final FileOutputStream fos = new FileOutputStream(configurationBundleFile)) {
+ ConfigurationUtil.createConfiguratorBundle(os, feature.getConfigurations(),
+ feature.getId().getGroupId() + "." + feature.getId().getArtifactId(),
+ feature.getId().getOSGiVersion().toString());
+ configuratorBundle = new Artifact(new ArtifactId(feature.getId().getGroupId(),
+ feature.getId().getArtifactId(),
+ feature.getId().getVersion(), "configurator", null));
+ }
+ }
+
+ try ( final ZipOutputStream jos = new ZipOutputStream(os) ) {
+ // repository/features.xml
+ // repository/{maven-path-to-bundle}
+ final ZipEntry xmlEntry = new ZipEntry("repository/features.xml");
+ jos.putNextEntry(xmlEntry);
+
+ final Writer writer = new OutputStreamWriter(jos);
+ writeFeaturesXML(writer, feature, configuratorBundle);
+ writer.flush();
+
+ jos.closeEntry();
+
+ for(final Map.Entry<Integer, List<Artifact>> entry : feature.getBundles().getBundlesByStartLevel().entrySet()) {
+ for(final Artifact artifact : entry.getValue()) {
+ final ArtifactHandler handler = artifactManager.getArtifactHandler(artifact.getId().toMvnUrl());
+
+ addEntry(jos, artifact, handler.getFile());
+ }
+ }
+
+ if ( configuratorBundle != null ) {
+ addEntry(jos, configuratorBundle, configurationBundleFile);
+ }
+ }
+ } finally {
+ if ( configurationBundleFile != null ) {
+ configurationBundleFile.delete();
+ }
+ }
+ }
+
+ private static void addEntry(final ZipOutputStream jos, final Artifact artifact, final File file)
+ throws IOException {
+ final ZipEntry bundleEntry = new ZipEntry("repository/" + artifact.getId().toMvnPath());
+ jos.putNextEntry(bundleEntry);
+
+ final byte[] buffer = new byte[16384];
+ try ( final FileInputStream fis = new FileInputStream(file)) {
+ int l = 0;
+ while ( (l = fis.read(buffer)) > 0 ) {
+ jos.write(buffer, 0, l);
+ }
+ }
+
+ jos.closeEntry();
+ }
+
+ /**
+ * Writes the feature XML to the writer.
+ * The writer is not closed.
+ * @param writer Writer
+ * @param model Model
+ * @throws IOException
+ */
+ private static void writeFeaturesXML(final Writer writer,
+ final Feature feature,
+ final Artifact configuratorBundle)
+ throws IOException {
+ final PrintWriter w = new PrintWriter(writer);
+
+ w.print("<features name=\"");
+ w.print(feature.getId().getArtifactId());
+ w.print("-repo-");
+ w.print(feature.getId().getVersion());
+ w.println("\" xmlns=\"http://karaf.apache.org/xmlns/features/v1.4.0\">");
+
+ write(w, feature, configuratorBundle);
+
+ w.println("</features>");
+ w.flush();
+ }
+
+ private static void write(final PrintWriter w, final Feature feature, final Artifact configuratorBundle)
+ throws IOException {
+ w.print(" <feature name=\"");
+ w.print(feature.getId().getGroupId());
+ w.print('.');
+ w.print(feature.getId().getArtifactId());
+ if ( feature.getId().getClassifier() != null ) {
+ w.print('.');
+ w.print(feature.getId().getClassifier());
+ }
+ w.print("\" version=\"");
+ w.print(feature.getId().getVersion());
+ w.println("\">");
+
+ if ( configuratorBundle != null ) {
+ w.print(" <bundle start-level=\"1\">");
+ w.print(configuratorBundle.getId().toMvnUrl());
+ w.println("</bundle>");
+ }
+
+ // bundles
+ for(final Map.Entry<Integer, List<Artifact>> entry : feature.getBundles().getBundlesByStartLevel().entrySet()) {
+ for(final Artifact artifact : entry.getValue()) {
+ w.print(" <bundle start-level=\"");
+ w.print(entry.getKey().toString());
+ w.print("\">");
+ w.print(artifact.getId().toMvnUrl());
+ w.println("</bundle>");
+ }
+ }
+
+ w.println(" </feature>");
+ }
+}
Propchange: sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/KarafFeatureWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/KarafFeatureWriter.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/package-info.java?rev=1797796&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/package-info.java (added)
+++ sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/package-info.java Tue Jun 6 15:43:22 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.feature.karaf;
+
+
Propchange: sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-karaf/src/main/java/org/apache/sling/feature/karaf/package-info.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Modified: sling/whiteboard/cziegeler/feature/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/pom.xml?rev=1797796&r1=1797795&r2=1797796&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature/pom.xml (original)
+++ sling/whiteboard/cziegeler/feature/pom.xml Tue Jun 6 15:43:22 2017
@@ -67,7 +67,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.converter</artifactId>
- <version>0.1-SNAPSHOT</version>
+ <version>0.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>