Author: cziegeler
Date: Tue Aug 15 14:28:59 2017
New Revision: 1805082

URL: http://svn.apache.org/viewvc?rev=1805082&view=rev
Log:
Clean up repoinit content

Modified:
    
sling/whiteboard/cziegeler/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/Main.java

Modified: 
sling/whiteboard/cziegeler/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/Main.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/Main.java?rev=1805082&r1=1805081&r2=1805082&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/Main.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/Main.java
 Tue Aug 15 14:28:59 2017
@@ -20,6 +20,8 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -63,7 +65,6 @@ import org.apache.sling.provisioning.mod
 import org.apache.sling.provisioning.model.Section;
 import org.apache.sling.provisioning.model.Traceable;
 import org.apache.sling.provisioning.model.io.ModelReader;
-import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -83,6 +84,8 @@ public class Main {
 
     private static String repoUrls;
 
+    private static String propsFile;
+
     /**
      * Parse the command line parameters and update a configuration object.
      * @param args Command line parameters
@@ -93,6 +96,7 @@ public class Main {
 
         final Option repoOption =  new Option("u", true, "Set repository url");
         final Option modelOption =  new Option("f", true, "Set feature 
files/directories");
+        final Option propsOption =  new Option("p", true, "sling.properties 
file");
         final Option runModeOption =  new Option("r", true, "Set run modes 
(comma separated)");
         final Option createAppOption = new Option("a", false, "If enabled, 
create application json");
         createAppOption.setArgs(0);
@@ -104,6 +108,7 @@ public class Main {
         options.addOption(createAppOption);
         options.addOption(outputOption);
         options.addOption(includeModelOption);
+        options.addOption(propsOption);
 
         final CommandLineParser clp = new BasicParser();
         try {
@@ -127,6 +132,9 @@ public class Main {
             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);
@@ -218,10 +226,16 @@ public class Main {
             buildFromFeature(feature, app.getBundles(), 
app.getConfigurations(), app.getExtensions(), app.getFrameworkProperties());
         }
 
-        // TODO - parse launchpad base to get sling.properties
-        // hard coded for now
+        // hard coded dependency to launchpad api
+        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));
-        
app.getFrameworkProperties().put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, 
"org.apache.sling.launchpad.api;version=\"1.2.0\"");
         return app;
     }
 
@@ -291,6 +305,30 @@ public class Main {
                 repoExtension.setText(repoExtension.getText() + "\n\n" + text);
             }
         }
+        if ( repoExtension != null ) {
+            // remove trailing comments and empty lines
+            final List<String> lines = new ArrayList<>();
+            try ( final LineNumberReader lnr = new LineNumberReader(new 
StringReader(repoExtension.getText()))) {
+                String line = null;
+                while ( (line = lnr.readLine()) != null ) {
+                    lines.add(line);
+                }
+            } catch ( final IOException ioe ) {
+                LOGGER.error("Unable to read repoinit", ioe);
+                System.exit(1);
+            }
+            int index = lines.size() - 1;
+            while ( index >= 0 ) {
+                final String line = lines.get(index).trim();
+                if ( line.isEmpty() || line.startsWith("#") ) {
+                    lines.remove(index);
+                    index--;
+                } else {
+                    index = -1;
+                }
+            }
+            repoExtension.setText(String.join("\n", lines));
+        }
     }
 
     private static void writeApplication(final Application app, final String 
out) {


Reply via email to