Author: gawor
Date: Wed Apr 23 19:42:51 2014
New Revision: 1589501
URL: http://svn.apache.org/r1589501
Log:
ARIES-1175: Support for adding custom headers
Added:
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java
(with props)
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml
(with props)
Modified:
aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java
Modified:
aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java
URL:
http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java?rev=1589501&r1=1589500&r2=1589501&view=diff
==============================================================================
---
aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java
(original)
+++
aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java
Wed Apr 23 19:42:51 2014
@@ -36,6 +36,7 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -68,7 +69,18 @@ public class EsaMojo
private static final String SUBSYSTEM_CONTENT = "Subsystem-Content";
private static final String SUBSYSTEM_USEBUNDLE = "Use-Bundle";
private static final String SUBSYSTEM_TYPE = "Subsystem-Type";
-
+
+ private static final Set<String> SKIP_INSTRUCTIONS = new HashSet<String>();
+
+ static {
+ SKIP_INSTRUCTIONS.add(SUBSYSTEM_MANIFESTVERSION);
+ SKIP_INSTRUCTIONS.add(SUBSYSTEM_SYMBOLICNAME);
+ SKIP_INSTRUCTIONS.add(SUBSYSTEM_VERSION);
+ SKIP_INSTRUCTIONS.add(SUBSYSTEM_NAME);
+ SKIP_INSTRUCTIONS.add(SUBSYSTEM_DESCRIPTION);
+ SKIP_INSTRUCTIONS.add(SUBSYSTEM_CONTENT);
+ }
+
/**
* Coverter for maven pom values to OSGi manifest values (pulled in from
the maven-bundle-plugin)
*/
@@ -158,7 +170,7 @@ public class EsaMojo
*
* @parameter
*/
- private Map instructions = new LinkedHashMap();;
+ private Map instructions = new LinkedHashMap();
/**
* Adding pom.xml and pom.properties to the archive.
@@ -451,16 +463,15 @@ public class EsaMojo
FileUtils.fileAppend(fileName, "\n");
- // Add any use bundle entry
- if (instructions.containsKey(SUBSYSTEM_USEBUNDLE)) {
- FileUtils.fileAppend(fileName, SUBSYSTEM_USEBUNDLE + ": "
- + instructions.get(SUBSYSTEM_USEBUNDLE) + "\n");
- }
-
- // Add any subsystem type
- if (instructions.containsKey(SUBSYSTEM_TYPE)) {
- FileUtils.fileAppend(fileName, SUBSYSTEM_TYPE + ": "
- + instructions.get(SUBSYSTEM_TYPE) + "\n");
+ Iterator<Map.Entry<?, ?>> instructionIter =
instructions.entrySet().iterator();
+ while(instructionIter.hasNext()) {
+ Map.Entry<?, ?> entry = instructionIter.next();
+ String header = entry.getKey().toString();
+ if (SKIP_INSTRUCTIONS.contains(header)) {
+ continue;
+ }
+ getLog().debug("Adding header: " + header);
+ FileUtils.fileAppend(fileName, header + ": " +
entry.getValue() + "\n");
}
} catch (Exception e) {
@@ -469,7 +480,7 @@ public class EsaMojo
}
}
-
+
// The maven2OsgiConverter assumes the artifact is a jar so we need our own
// This uses the same fallback scheme as the converter
private String getSubsystemSymbolicName(Artifact artifact) {
Modified:
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java?rev=1589501&r1=1589500&r2=1589501&view=diff
==============================================================================
---
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java
(original)
+++
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java
Wed Apr 23 19:42:51 2014
@@ -452,6 +452,54 @@ public class EsaMojoTest
}
+ public void testCustomInstructions()
+ throws Exception
+ {
+ File testPom = new File( getBasedir(),
+
"target/test-classes/unit/basic-esa-custom-instructions/plugin-config.xml" );
+
+ EsaMojo mojo = ( EsaMojo ) lookupMojo( "esa", testPom );
+
+ assertNotNull( mojo );
+
+ String finalName = ( String ) getVariableValueFromObject( mojo,
"finalName" );
+
+ String workDir = ( String ) getVariableValueFromObject( mojo,
"workDirectory" );
+
+ String outputDir = ( String ) getVariableValueFromObject( mojo,
"outputDirectory" );
+
+ mojo.execute();
+
+
+ //check the generated esa file
+ File esaFile = new File( outputDir, finalName + ".esa" );
+
+ assertTrue( esaFile.exists() );
+
+ //expected files/directories inside the esa file
+ List expectedFiles = new ArrayList();
+
+ expectedFiles.add( "OSGI-INF/SUBSYSTEM.MF" );
+ expectedFiles.add( "OSGI-INF/" );
+ expectedFiles.add( "maven-artifact01-1.0-SNAPSHOT.jar" );
+ expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" );
+
+ ZipFile esa = new ZipFile( esaFile );
+
+ Enumeration entries = esa.getEntries();
+
+ assertTrue( entries.hasMoreElements() );
+
+ int missing = getSizeOfExpectedFiles(entries, expectedFiles);
+ assertEquals("Missing files: " + expectedFiles, 0, missing);
+
+ // Test for the Foo header
+ testForHeader(esa, "Foo", "Foo: bar");
+
+ // Test for the MyHeader header
+ testForHeader(esa, "MyHeader", "MyHeader: myValue");
+ }
+
private int getSizeOfExpectedFiles( Enumeration entries, List
expectedFiles )
{
while( entries.hasMoreElements() )
Added:
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java
URL:
http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java?rev=1589501&view=auto
==============================================================================
---
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java
(added)
+++
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java
Wed Apr 23 19:42:51 2014
@@ -0,0 +1,31 @@
+package org.apache.aries.plugin.esa.stubs;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+public class EsaMavenProjectStub8
+ extends EsaMavenProjectStub
+{
+ public File getFile()
+ {
+ return new File( getBasedir(),
"src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml" );
+ }
+}
Propchange:
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub8.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml
URL:
http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml?rev=1589501&view=auto
==============================================================================
---
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml
(added)
+++
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml
Wed Apr 23 19:42:51 2014
@@ -0,0 +1,44 @@
+<!--
+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>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>esa-maven-plugin</artifactId>
+ <configuration>
+
<esaSourceDirectory>${basedir}/src/test/resources/unit/basic-esa-custom-instructions/src/main/esa</esaSourceDirectory>
+ <generateManifest>true</generateManifest>
+ <instructions>
+ <Subsystem-Type>feature</Subsystem-Type>
+ <MyHeader>myValue</MyHeader>
+ <Foo>bar</Foo>
+ </instructions>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ <includeEmptyDirs>true</includeEmptyDirs>
+
<workDirectory>${basedir}/target/unit/basic-esa-custom-instructions/target/esa-test-custom-instructions</workDirectory>
+
<sharedResources>${basedir}/target/unit/basic-esa-custom-instructions/target/maven-shared-archive-resources</sharedResources>
+
<outputDirectory>${basedir}/target/unit/basic-esa-custom-instructions/target</outputDirectory>
+ <finalName>test-esa-custom-instructions</finalName>
+ <project
implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub8" />
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange:
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-custom-instructions/plugin-config.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml