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

[sling-org-apache-sling-feature-applicationbuilder] 01/21: Move feature model to whiteboard git

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-applicationbuilder.git

commit bb26356cf550b539eb5f64b986cd07f7954cc527
Author: Carsten Ziegeler <cz...@adobe.com>
AuthorDate: Fri Nov 3 15:06:50 2017 +0100

    Move feature model to whiteboard git
---
 pom.xml                                            | 127 ++++++++++++
 .../feature/applicationbuilder/impl/Main.java      | 213 +++++++++++++++++++++
 2 files changed, 340 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..c30dc54
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,127 @@
+<?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>32</version>
+        <relativePath />
+    </parent>
+
+    <artifactId>org.apache.sling.feature.applicationbuilder</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Apache Sling Feature Application Builder</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-applicationbuilder</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/tooling/support/feature-applicationbuilder</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/tooling/support/feature-applicationbuilder</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                <execution>
+                    <id>unpack-dependencies</id>
+                    <phase>prepare-package</phase>
+                    <goals>
+                        <goal>unpack-dependencies</goal>
+                    </goals>
+                    <configuration>
+                        <excludes>META-INF/**</excludes>
+                        <outputDirectory>${project.build.directory}/classes</outputDirectory>
+                        <overWriteReleases>false</overWriteReleases>
+                        <overWriteSnapshots>true</overWriteSnapshots>
+                        <includeArtifactIds>commons-cli,org.apache.sling.feature,org.apache.sling.feature.support,org.apache.sling.commons.johnzon,slf4j-api,slf4j-simple,osgi.core,org.apache.felix.converter</includeArtifactIds>
+                    </configuration>
+                </execution>
+            </executions>
+            </plugin>
+                <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <mainClass>org.apache.sling.feature.applicationbuilder.impl.Main</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+             <groupId>commons-cli</groupId>
+             <artifactId>commons-cli</artifactId>
+             <version>1.3.1</version>
+        </dependency>
+        <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>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.johnzon</artifactId>
+            <version>1.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.converter</artifactId>
+            <version>0.1.0-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+      <!-- Testing -->
+        <dependency>
+        	<groupId>junit</groupId>
+        	<artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/feature/applicationbuilder/impl/Main.java b/src/main/java/org/apache/sling/feature/applicationbuilder/impl/Main.java
new file mode 100644
index 0000000..80c609d
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/applicationbuilder/impl/Main.java
@@ -0,0 +1,213 @@
+/*
+ * 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.applicationbuilder.impl;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.sling.feature.Application;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Bundles;
+import org.apache.sling.feature.Configurations;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Extensions;
+import org.apache.sling.feature.KeyValueMap;
+import org.apache.sling.feature.support.ArtifactHandler;
+import org.apache.sling.feature.support.ArtifactManager;
+import org.apache.sling.feature.support.ArtifactManagerConfig;
+import org.apache.sling.feature.support.FeatureUtil;
+import org.apache.sling.feature.support.json.ApplicationJSONReader;
+import org.apache.sling.feature.support.json.ApplicationJSONWriter;
+import org.apache.sling.feature.support.json.FeatureJSONWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Main {
+
+    private static Logger LOGGER;
+
+    private static String output;
+
+    private static String filesInput;
+
+    private static String dirsInput;
+
+    private static String repoUrls;
+
+    private static String propsFile;
+
+    /**
+     * Parse the command line parameters and update a configuration object.
+     * @param args Command line parameters
+     * @return Configuration object.
+     */
+    private static void parseArgs(final String[] args) {
+        final Option repoOption =  Option.builder("u").hasArg().argName("Set repository url")
+                .desc("repository url").build();
+
+        final Option filesOption =  new Option("f", true, "Set feature files (comma separated)");
+        final Option dirsOption = new Option("d", true, "Set feature file dirs (comma separated)");
+        final Option propsOption =  new Option("p", true, "sling.properties file");
+
+
+        final Option outputOption = Option.builder("o").hasArg().argName("Set output file")
+                .desc("output file").build();
+
+        final Options options = new Options();
+        options.addOption(repoOption);
+        options.addOption(filesOption);
+        options.addOption(dirsOption);
+        options.addOption(outputOption);
+        options.addOption(propsOption);
+
+        final CommandLineParser parser = new DefaultParser();
+        try {
+            final CommandLine cl = parser.parse(options, args);
+
+            if ( cl.hasOption(repoOption.getOpt()) ) {
+                repoUrls = cl.getOptionValue(repoOption.getOpt());
+            }
+            if ( cl.hasOption(filesOption.getOpt()) ) {
+                filesInput = cl.getOptionValue(filesOption.getOpt());
+            }
+            if ( cl.hasOption(dirsOption.getOpt()) ) {
+                dirsInput = cl.getOptionValue(dirsOption.getOpt());
+            }
+            if ( cl.hasOption(outputOption.getOpt()) ) {
+                output = cl.getOptionValue(outputOption.getOpt());
+            }
+            if ( cl.hasOption(propsOption.getOpt()) ) {
+                propsFile = cl.getOptionValue(propsOption.getOpt());
+            }
+        } catch ( final ParseException pe) {
+            LOGGER.error("Unable to parse command line: {}", pe.getMessage(), pe);
+            System.exit(1);
+        }
+        if ( filesInput == null && dirsInput == null) {
+            LOGGER.error("Required argument missing: model files or directory");
+            System.exit(1);
+        }
+    }
+
+    private static ArtifactManager getArtifactManager() {
+        final ArtifactManagerConfig amConfig = new ArtifactManagerConfig();
+        if ( repoUrls != null ) {
+            amConfig.setRepositoryUrls(repoUrls.split(","));
+        }
+        try {
+            return ArtifactManager.getArtifactManager(amConfig);
+        } catch ( IOException ioe) {
+            LOGGER.error("Unable to create artifact manager " + ioe.getMessage(), ioe);
+            System.exit(1);
+        }
+        // we never reach this, but have to keep the compiler happy
+        return null;
+    }
+
+    public static void main(final String[] args) {
+        // setup logging
+        System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
+        System.setProperty("org.slf4j.simpleLogger.showThreadName", "false");
+        System.setProperty("org.slf4j.simpleLogger.levelInBrackets", "true");
+        System.setProperty("org.slf4j.simpleLogger.showLogName", "false");
+
+        LOGGER = LoggerFactory.getLogger("applicationbuilder");
+
+        LOGGER.info("Apache Sling Feature Application Builder");
+        LOGGER.info("");
+
+        parseArgs(args);
+
+        final ArtifactManagerConfig amConfig = new ArtifactManagerConfig();
+        if ( repoUrls != null ) {
+            amConfig.setRepositoryUrls(repoUrls.split(","));
+        }
+
+        final ArtifactManager am = getArtifactManager();
+
+
+        final String[] files =
+                Stream.concat(
+                    Stream.of(filesInput != null ? filesInput.split(",") : new String[0])
+                        .map(path -> new File(path))
+                        .filter(File::isFile),
+                    Stream.of(dirsInput != null ? dirsInput.split(",") : new String[0])
+                        .map(path -> new File(path))
+                        .filter(File::isDirectory)
+                        .flatMap(dir ->
+                            Stream.of(dir.listFiles())))
+                .filter(file -> !file.getName().startsWith("."))
+                .sorted()
+                .map(File::getAbsolutePath)
+                .toArray(String[]::new);
+
+        if (files.length == 0) {
+            LOGGER.error("No feature files found.");
+            System.exit(1);
+        }
+
+        try {
+            writeApplication(buildApplication(FeatureUtil.assembleApplication(null, am, files)), output == null ? "application.json" : output);
+
+        } catch ( final IOException ioe) {
+            LOGGER.error("Unable to read feature/application files " + ioe.getMessage(), ioe);
+            System.exit(1);
+        }
+    }
+
+    private static Application buildApplication(final Application app) {
+        app.getBundles().add(1, new org.apache.sling.feature.Artifact(ArtifactId.fromMvnId("org.apache.sling/org.apache.sling.launchpad.api/1.2.0")));
+        // sling.properties (TODO)
+        if ( propsFile == null ) {
+            app.getFrameworkProperties().put("org.osgi.framework.bootdelegation", "sun.*,com.sun.*");
+        } else {
+
+        }
+        // felix framework hard coded for now
+        app.setFramework(FeatureUtil.getFelixFrameworkId(null));
+        return app;
+    }
+
+    private static void writeApplication(final Application app, final String out) {
+        LOGGER.info("Writing application...");
+        final File file = new File(out);
+        try ( final FileWriter writer = new FileWriter(file)) {
+            ApplicationJSONWriter.write(writer, app);
+        } catch ( final IOException ioe) {
+            LOGGER.error("Unable to write application to {} : {}", out, ioe.getMessage(), ioe);
+            System.exit(1);
+        }
+    }
+}

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