From b1d3aa145f2dd8c6116a4095951bc1534ce27bb6 Mon Sep 17 00:00:00 2001
From: Andrei Pozolotin <Andrei.Pozolotin@gmail.com>
Date: Sat, 18 Aug 2012 13:38:03 -0500
Subject: [PATCH] delivery

---
 demos/command/pom.xml                              |   14 ++++--
 .../features/internal/FeatureValidationUtil.java   |   10 ++--
 .../features/internal/FeaturesNamespaces.java      |   41 +++++++++++++++++
 .../karaf/features/internal/model/JaxbUtil.java    |   18 +++-----
 .../features/internal/model/package-info.java      |    4 +-
 pom.xml                                            |   10 ++--
 .../tooling/features/GenerateDescriptorMojo.java   |   20 +++++++-
 .../features/GenerateDescriptorMojoTest.java       |   48 +++++++++++++++++---
 .../src/test/resources/input-features-1.0.0.xml    |   20 ++++++++
 .../src/test/resources/input-features-1.1.0.xml    |   27 +++++++++++
 .../src/test/resources/input-features.xml          |   20 --------
 11 files changed, 174 insertions(+), 58 deletions(-)
 create mode 100644 features/core/src/main/java/org/apache/karaf/features/internal/FeaturesNamespaces.java
 create mode 100644 tooling/karaf-maven-plugin/src/test/resources/input-features-1.0.0.xml
 create mode 100644 tooling/karaf-maven-plugin/src/test/resources/input-features-1.1.0.xml
 delete mode 100644 tooling/karaf-maven-plugin/src/test/resources/input-features.xml

diff --git a/demos/command/pom.xml b/demos/command/pom.xml
index b95ef74..c314e40 100644
--- a/demos/command/pom.xml
+++ b/demos/command/pom.xml
@@ -35,9 +35,17 @@
     <name>Apache Karaf :: Demos :: Command :: Extend Console</name>
 
     <dependencies>
+    
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+		    <scope>provided</scope>
+        </dependency>
+        
         <dependency>
             <groupId>org.apache.karaf.shell</groupId>
             <artifactId>org.apache.karaf.shell.console</artifactId>
+		    <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -47,16 +55,12 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.karaf</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-
-        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>3.8.1</version>
             <scope>test</scope>
         </dependency>
+        
     </dependencies>
 
     <build>
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/FeatureValidationUtil.java b/features/core/src/main/java/org/apache/karaf/features/internal/FeatureValidationUtil.java
index c083f33..6130e66 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/FeatureValidationUtil.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/FeatureValidationUtil.java
@@ -39,10 +39,6 @@ import org.xml.sax.SAXException;
  */
 public class FeatureValidationUtil {
 
-    public static final QName FEATURES_0_0 = new QName("features");
-    public static final QName FEATURES_1_0 = new QName("http://karaf.apache.org/xmlns/features/v1.0.0", "features");
-    public static final QName FEATURES_1_1 = new QName("http://karaf.apache.org/xmlns/features/v1.1.0", "features");
-
     private static final Logger log = LoggerFactory.getLogger(FeatureValidationUtil.class);
 
     /**
@@ -56,12 +52,12 @@ public class FeatureValidationUtil {
 
         QName name = new QName(doc.getDocumentElement().getNamespaceURI(), doc.getDocumentElement().getLocalName());
 
-        if (FEATURES_0_0.equals(name)) {
+        if (FeaturesNamespaces.FEATURES_0_0_0.equals(name)) {
             log.warn("Old style feature file without namespace found (URI: {}). This format is deprecated and support for it will soon be removed", uri);
             return;
-        } else if (FEATURES_1_0.equals(name)) {
+        } else if (FeaturesNamespaces.FEATURES_1_0_0.equals(name)) {
             validate(doc, "/org/apache/karaf/features/karaf-features-1.0.0.xsd");
-        } else if (FEATURES_1_1.equals(name)) {
+        } else if (FeaturesNamespaces.FEATURES_1_1_0.equals(name)) {
             validate(doc, "/org/apache/karaf/features/karaf-features-1.1.0.xsd");
         } else {
             throw new IllegalArgumentException("Unrecognized root element: " + name);
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesNamespaces.java b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesNamespaces.java
new file mode 100644
index 0000000..530f937
--- /dev/null
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesNamespaces.java
@@ -0,0 +1,41 @@
+/*
+ * 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.karaf.features.internal;
+
+import javax.xml.namespace.QName;
+
+/** 
+ * features xml/xsd namespace constants 
+ */
+public interface FeaturesNamespaces {
+
+	String URI_0_0_0 = "";
+	String URI_1_0_0 = "http://karaf.apache.org/xmlns/features/v1.0.0";
+	String URI_1_1_0 = "http://karaf.apache.org/xmlns/features/v1.1.0";
+
+	/** current release xmlns uri */
+	String URI_CURRENT = URI_1_1_0;
+
+	QName FEATURES_0_0_0 = new QName("features");
+	QName FEATURES_1_0_0 = new QName(URI_1_0_0, "features");
+	QName FEATURES_1_1_0 = new QName(URI_1_1_0, "features");
+
+	/** current release qualified name */
+	QName FEATURES_CURRENT = FEATURES_1_1_0;
+
+}
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java b/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
index 7668dc7..26d61f5 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
@@ -35,6 +35,7 @@ import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.transform.sax.SAXSource;
 
+import org.apache.karaf.features.internal.FeaturesNamespaces;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -122,7 +123,7 @@ public class JaxbUtil {
      * compatible to the new format
      */
     public static class NoSourceAndNamespaceFilter extends XMLFilterImpl {
-        private static final String FEATURES_NAMESPACE = "http://karaf.apache.org/xmlns/features/v1.0.0";
+    	
         private static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new byte[0]));
 
         public NoSourceAndNamespaceFilter(XMLReader xmlReader) {
@@ -135,22 +136,15 @@ public class JaxbUtil {
         }
 
         @Override
-        public void startElement(String uri, String localName, String qname, Attributes atts) throws SAXException {
-            if ("".equals(uri)) {
-                super.startElement(FEATURES_NAMESPACE, localName, qname, atts);
-            } else {
-                super.startElement(uri, localName, qname, atts);
-            }
+        public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+        	super.startElement(FeaturesNamespaces.URI_CURRENT, localName, qName, atts);
         }
 
         @Override
         public void endElement(String uri, String localName, String qName) throws SAXException {
-            if ("".equals(uri)) {
-                super.endElement(FEATURES_NAMESPACE, localName, qName);
-            } else {
-                super.endElement(uri, localName, qName);
-            }
+        	super.endElement(FeaturesNamespaces.URI_CURRENT, localName, qName);
         }
+        
     }
 
 
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java b/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java
index 09c0bfe8..bebf24a 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java
@@ -17,5 +17,7 @@
  * under the License.
  */
 
-@javax.xml.bind.annotation.XmlSchema(namespace = "http://karaf.apache.org/xmlns/features/v1.0.0", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+@javax.xml.bind.annotation.XmlSchema(namespace = FeaturesNamespaces.URI_CURRENT, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
 package org.apache.karaf.features.internal.model;
+import org.apache.karaf.features.internal.FeaturesNamespaces;
+
diff --git a/pom.xml b/pom.xml
index d7c9e3f..4ba708f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1986,7 +1986,7 @@
                                     <pluginExecutionFilter>
                                         <groupId>org.apache.felix</groupId>
                                         <artifactId>maven-bundle-plugin</artifactId>
-                                        <versionRange>[2.3.7,)</versionRange>
+                                        <versionRange>[0,)</versionRange>
                                         <goals>
                                             <goal>cleanVersions</goal>
                                         </goals>
@@ -1999,7 +1999,7 @@
                                     <pluginExecutionFilter>
                                         <groupId>org.apache.maven.plugins</groupId>
                                         <artifactId>maven-dependency-plugin</artifactId>
-                                        <versionRange>[2.4,)</versionRange>
+                                        <versionRange>[0,)</versionRange>
                                         <goals>
                                             <goal>copy</goal>
                                             <goal>unpack</goal>
@@ -2013,7 +2013,7 @@
                                     <pluginExecutionFilter>
                                         <groupId>org.apache.karaf.tooling</groupId>
                                         <artifactId>karaf-maven-plugin</artifactId>
-                                        <versionRange>[3.0.0,)</versionRange>
+                                        <versionRange>[0,)</versionRange>
                                         <goals>
                                             <goal>commands-generate-help</goal>
                                         </goals>
@@ -2026,7 +2026,7 @@
                                     <pluginExecutionFilter>
                                         <groupId>org.fusesource.scalate</groupId>
                                         <artifactId>maven-scalate-plugin</artifactId>
-                                        <versionRange>[1.4.0,)</versionRange>
+                                        <versionRange>[0,)</versionRange>
                                         <goals>
                                             <goal>sitegen</goal>
                                         </goals>
@@ -2039,7 +2039,7 @@
                                     <pluginExecutionFilter>
                                         <groupId>org.apache.servicemix.tooling</groupId>
                                         <artifactId>depends-maven-plugin</artifactId>
-                                        <versionRange>[1.2,)</versionRange>
+                                        <versionRange>[0,)</versionRange>
                                         <goals>
                                             <goal>generate-depends-file</goal>
                                         </goals>
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
index cc96379..86a80ca 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
@@ -149,6 +149,21 @@ public class GenerateDescriptorMojo extends AbstractLogEnabled implements Mojo {
     private Integer startLevel;
 
     /**
+     * Installation mode. If present, generate "feature.install" attribute:
+     * 
+     * <a href="https://github.com/apache/karaf/blob/trunk/features/core/src/main/resources/org/apache/karaf/features/karaf-features-1.1.0.xsd">
+     * Installation mode.
+     * </a>
+     *
+     * Can be either manual or auto. Specifies whether the feature should be automatically installed when
+     * dropped inside the deploy folder. Note: This attribute doesn't affect feature descriptors that are installed from the
+     * command line or as part of the org.apache.karaf.features.cfg.
+     *
+     * @parameter
+     */
+    private String installMode;
+
+    /**
      * Flag indicating whether transitive dependencies should be included (<code>true</code>) or not (<code>false</code>).
      * <p/>
      * N.B. Note the default value of this is true, but is suboptimal in cases where specific <code>&lt;feature/&gt;</code> dependencies are
@@ -278,7 +293,7 @@ public class GenerateDescriptorMojo extends AbstractLogEnabled implements Mojo {
             throw new MojoExecutionException("Unable to create features.xml file: " + e, e);
         }
     }
-
+    
     /*
      * Write all project dependencies as feature
      */
@@ -317,6 +332,9 @@ public class GenerateDescriptorMojo extends AbstractLogEnabled implements Mojo {
         if (resolver != null) {
             feature.setResolver(resolver);
         }
+        if (installMode != null) {
+            feature.setInstall(installMode);
+        }
         if (project.getDescription() != null && feature.getDetails() == null) {
             feature.setDetails(project.getDescription());
         }
diff --git a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java
index e72eb5b..f8899e1 100644
--- a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java
+++ b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java
@@ -20,29 +20,63 @@
 
 package org.apache.karaf.tooling.features;
 
+import static org.junit.Assert.*;
+
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
+import java.util.List;
 
 import javax.xml.bind.JAXBException;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
+
+import org.apache.karaf.features.internal.FeaturesNamespaces;
+import org.apache.karaf.features.internal.model.Feature;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.JaxbUtil;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.xml.sax.SAXException;
 
 public class GenerateDescriptorMojoTest {
 
     @Test
-    public void testReadXml() throws JAXBException, SAXException, ParserConfigurationException, XMLStreamException {
-        InputStream in = getClass().getClassLoader().getResourceAsStream("input-features.xml");
+    public void testReadXml0() throws JAXBException, SAXException, ParserConfigurationException, XMLStreamException {
+    	
+        InputStream in = getClass().getClassLoader().getResourceAsStream("input-features-1.0.0.xml");
+        
         Features featuresRoot = JaxbUtil.unmarshal(in, false);
-        assert featuresRoot.getRepository().size() == 1;
+
+        assertEquals(featuresRoot.getRepository().size(), 1);
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        
         JaxbUtil.marshal(featuresRoot, baos);
-        String s = new String(baos.toByteArray());
-        assert s.indexOf("repository") > -1;
-        assert s.indexOf("http://karaf.apache.org/xmlns/features/v1.0.0") > -1;
+        
+        String text = new String(baos.toByteArray());
+        
+        assertTrue(text.contains("repository"));
+        
+        assertTrue(text.contains(FeaturesNamespaces.URI_CURRENT));
+        
+    }
+    
+    @Test
+    public void testReadXml1() throws Exception {
+
+        InputStream in = getClass().getClassLoader().getResourceAsStream("input-features-1.1.0.xml");
+        
+        Features featuresRoot = JaxbUtil.unmarshal(in, false);
+        
+        List<Feature> featuresList = featuresRoot.getFeature();
+        
+        assertEquals(featuresList.size(), 1);
+        
+        Feature feature = featuresList.get(0);
+
+        assertEquals(feature.getInstall(), "auto");
+
+
     }
-}
+    
+}
\ No newline at end of file
diff --git a/tooling/karaf-maven-plugin/src/test/resources/input-features-1.0.0.xml b/tooling/karaf-maven-plugin/src/test/resources/input-features-1.0.0.xml
new file mode 100644
index 0000000..a015b59
--- /dev/null
+++ b/tooling/karaf-maven-plugin/src/test/resources/input-features-1.0.0.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+    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.
+-->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0" name="geronimo-transaction">
+    <repository>http://foo.org</repository>
+</features>
diff --git a/tooling/karaf-maven-plugin/src/test/resources/input-features-1.1.0.xml b/tooling/karaf-maven-plugin/src/test/resources/input-features-1.1.0.xml
new file mode 100644
index 0000000..c70fa02
--- /dev/null
+++ b/tooling/karaf-maven-plugin/src/test/resources/input-features-1.1.0.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+    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.
+-->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.1.0" name="testing">
+
+    <repository>http://testing-feature.org</repository>
+    
+    <feature install="auto" name="testing-feature" version="1.0.0" description="some testing feature">
+        <bundle start-level="30">mvn:org.apache.karaf.features/org.apache.karaf.features.core/2.2.8</bundle>
+        <bundle start-level="30">mvn:org.apache.karaf.features/org.apache.karaf.features.command/2.2.8</bundle>
+    </feature>
+
+</features>
diff --git a/tooling/karaf-maven-plugin/src/test/resources/input-features.xml b/tooling/karaf-maven-plugin/src/test/resources/input-features.xml
deleted file mode 100644
index a015b59..0000000
--- a/tooling/karaf-maven-plugin/src/test/resources/input-features.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
-    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.
--->
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0" name="geronimo-transaction">
-    <repository>http://foo.org</repository>
-</features>
-- 
1.7.9.5

