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

tjwatson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-atomos.git


The following commit(s) were added to refs/heads/master by this push:
     new 2651616  Add ability to generate atomos index outside of native-image
     new 58643e0  Merge pull request #17 from tjwatson/index-example
2651616 is described below

commit 26516161b1a4c999e2145c7e5e0cb1f02fe08baf
Author: Thomas Watson <[email protected]>
AuthorDate: Mon Mar 16 15:44:04 2020 -0500

    Add ability to generate atomos index outside of native-image
    
    Added an example atomos.examples.index that uses the new mojo goal
    atomos-index along with the maven-assembly-plugin to create an
    executable JAR with all the bundle content included and indexed
    for Atomos
---
 atomos.examples/atomos.examples.index/pom.xml      |  95 ++++++++++++++++++
 .../atomos.examples.springloader/pom.xml           | 110 +--------------------
 .../atomos.examples.substrate.equinox/pom.xml      |  58 +----------
 .../atomos.examples.substrate.felix/pom.xml        |  58 +----------
 .../pom.xml                                        |  58 +----------
 .../atomos.examples.webconsole.bom/pom.xml         |  71 +++++++++++++
 atomos.examples/pom.xml                            |   4 +
 .../apache/felix/atomos/maven/AtomosIndexMojo.java |  76 ++++++++++++++
 .../apache/felix/atomos/maven/NativeImageMojo.java |  13 ++-
 .../apache/felix/atomos/maven/SubstrateUtil.java   |  99 +++++++++----------
 .../org/apache/felix/atomos/maven/MojoTest.java    |   2 +-
 .../apache/felix/atomos/maven/SubstrateTest.java   |  33 ++++++-
 12 files changed, 353 insertions(+), 324 deletions(-)

diff --git a/atomos.examples/atomos.examples.index/pom.xml 
b/atomos.examples/atomos.examples.index/pom.xml
new file mode 100644
index 0000000..679d5ef
--- /dev/null
+++ b/atomos.examples/atomos.examples.index/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.felix.atomos.examples</groupId>
+        <artifactId>org.apache.felix.atomos.examples</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+    <artifactId>org.apache.felix.atomos.examples.index</artifactId>
+    <name>atomos.examples.index</name>
+    <description>Example using the Atomos index to create an executable 
JAR</description>
+
+    <repositories>
+        <repository>
+            <id>atomos-temp-m2repo</id>
+            
<url>https://github.com/tjwatson/atomos-temp-m2repo/raw/master/repository</url>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>always</updatePolicy>
+            </snapshots>
+        </repository>
+    </repositories>
+    <profiles>
+        <profile>
+            <id>felix</id>
+            <properties>
+                <buildWithFelix>true</buildWithFelix>
+            </properties>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>org.apache.felix.log</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.atomos.runtime</artifactId>
+            <version>${atomos.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix.atomos.examples</groupId>
+            
<artifactId>org.apache.felix.atomos.examples.webconsole.bom</artifactId>
+            <version>${atomos.version}</version>
+            <type>pom</type>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>org.apache.felix.atomos.maven</artifactId>
+                <version>${atomos.version}</version>
+                <configuration>
+                    <debug>true</debug>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>atomos-index</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                        <configuration>
+                            <archive>
+                                <manifest>
+                                    
<mainClass>org.apache.felix.atomos.launch.AtomosLauncher</mainClass>
+                                </manifest>
+                            </archive>
+                            <descriptorRefs>
+                                
<descriptorRef>jar-with-dependencies</descriptorRef>
+                            </descriptorRefs>
+                            
<finalName>${project.artifactId}-${project.version}</finalName>
+                            <appendAssemblyId>false</appendAssemblyId>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/atomos.examples/atomos.examples.springloader/pom.xml 
b/atomos.examples/atomos.examples.springloader/pom.xml
index fa60a91..244fb13 100644
--- a/atomos.examples/atomos.examples.springloader/pom.xml
+++ b/atomos.examples/atomos.examples.springloader/pom.xml
@@ -41,114 +41,10 @@
             <version>${atomos.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix.atomos.tests</groupId>
-            
<artifactId>org.apache.felix.atomos.tests.testbundles.service.contract</artifactId>
+            <groupId>org.apache.felix.atomos.examples</groupId>
+            
<artifactId>org.apache.felix.atomos.examples.webconsole.bom</artifactId>
             <version>${atomos.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>*</groupId>
-                    <artifactId>*</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix.atomos.tests</groupId>
-            
<artifactId>org.apache.felix.atomos.tests.testbundles.service.impl</artifactId>
-            <version>${atomos.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>*</groupId>
-                    <artifactId>*</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix.atomos.tests</groupId>
-            
<artifactId>org.apache.felix.atomos.tests.testbundles.service.impl.activator</artifactId>
-            <version>${atomos.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>*</groupId>
-                    <artifactId>*</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix.atomos.tests</groupId>
-            
<artifactId>org.apache.felix.atomos.tests.testbundles.service.user</artifactId>
-            <version>${atomos.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>*</groupId>
-                    <artifactId>*</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.atomos.substrate.config</artifactId>
-            <version>${atomos.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>*</groupId>
-                    <artifactId>*</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.promise</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.command</artifactId>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.runtime</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.shell</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.jetty</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.whiteboard</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.webconsole</artifactId>
-            <classifier>all</classifier>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.servlet-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.cm</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.event</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>javax.annotation</groupId>
-            <artifactId>javax.annotation-api</artifactId>
-            <version>1.3.2</version>
+            <type>pom</type>
         </dependency>
     </dependencies>
  
diff --git a/atomos.examples/atomos.examples.substrate.equinox/pom.xml 
b/atomos.examples/atomos.examples.substrate.equinox/pom.xml
index 49c91e7..7b8bc45 100644
--- a/atomos.examples/atomos.examples.substrate.equinox/pom.xml
+++ b/atomos.examples/atomos.examples.substrate.equinox/pom.xml
@@ -98,59 +98,10 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.promise</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.command</artifactId>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.runtime</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.shell</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.jetty</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.whiteboard</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.webconsole</artifactId>
-            <classifier>all</classifier>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.servlet-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.cm</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.event</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>javax.annotation</groupId>
-            <artifactId>javax.annotation-api</artifactId>
-            <version>1.3.2</version>
+            <groupId>org.apache.felix.atomos.examples</groupId>
+            
<artifactId>org.apache.felix.atomos.examples.webconsole.bom</artifactId>
+            <version>${atomos.version}</version>
+            <type>pom</type>
         </dependency>
     </dependencies>
     <build>
@@ -180,7 +131,6 @@
                             <overWriteReleases>false</overWriteReleases>
                             <overWriteSnapshots>false</overWriteSnapshots>
                             <overWriteIfNewer>true</overWriteIfNewer>
-                            <excludeTransitive>true</excludeTransitive>
                         </configuration>
                     </execution>
                 </executions>
diff --git a/atomos.examples/atomos.examples.substrate.felix/pom.xml 
b/atomos.examples/atomos.examples.substrate.felix/pom.xml
index 1dfaa16..bad7377 100644
--- a/atomos.examples/atomos.examples.substrate.felix/pom.xml
+++ b/atomos.examples/atomos.examples.substrate.felix/pom.xml
@@ -107,63 +107,14 @@
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.promise</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.log</artifactId>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.command</artifactId>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.runtime</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.shell</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.jetty</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.whiteboard</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.webconsole</artifactId>
-            <classifier>all</classifier>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.servlet-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.cm</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.event</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>javax.annotation</groupId>
-            <artifactId>javax.annotation-api</artifactId>
-            <version>1.3.2</version>
+            <groupId>org.apache.felix.atomos.examples</groupId>
+            
<artifactId>org.apache.felix.atomos.examples.webconsole.bom</artifactId>
+            <version>${atomos.version}</version>
+            <type>pom</type>
         </dependency>
     </dependencies>
     <build>
@@ -193,7 +144,6 @@
                             <overWriteReleases>false</overWriteReleases>
                             <overWriteSnapshots>false</overWriteSnapshots>
                             <overWriteIfNewer>true</overWriteIfNewer>
-                            <excludeTransitive>true</excludeTransitive>
                         </configuration>
                     </execution>
                 </executions>
diff --git a/atomos.examples/atomos.examples.substrate.maven.equinox/pom.xml 
b/atomos.examples/atomos.examples.substrate.maven.equinox/pom.xml
index e4e3e66..ec266fa 100644
--- a/atomos.examples/atomos.examples.substrate.maven.equinox/pom.xml
+++ b/atomos.examples/atomos.examples.substrate.maven.equinox/pom.xml
@@ -47,59 +47,10 @@
             <type>pom</type>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.promise</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.command</artifactId>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.runtime</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.gogo.shell</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.jetty</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.whiteboard</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.webconsole</artifactId>
-            <classifier>all</classifier>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.servlet-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.cm</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.event</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>javax.annotation</groupId>
-            <artifactId>javax.annotation-api</artifactId>
-            <version>1.3.2</version>
+            <groupId>org.apache.felix.atomos.examples</groupId>
+            
<artifactId>org.apache.felix.atomos.examples.webconsole.bom</artifactId>
+            <version>${atomos.version}</version>
+            <type>pom</type>
         </dependency>
     </dependencies>
     <build>
@@ -119,7 +70,6 @@
                             <overWriteReleases>false</overWriteReleases>
                             <overWriteSnapshots>false</overWriteSnapshots>
                             <overWriteIfNewer>true</overWriteIfNewer>
-                            <excludeTransitive>false</excludeTransitive>
                         </configuration>
                     </execution>
                 </executions>
diff --git a/atomos.examples/atomos.examples.webconsole.bom/pom.xml 
b/atomos.examples/atomos.examples.webconsole.bom/pom.xml
new file mode 100644
index 0000000..ec8de38
--- /dev/null
+++ b/atomos.examples/atomos.examples.webconsole.bom/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd"; 
xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.felix.atomos.examples</groupId>
+        <artifactId>org.apache.felix.atomos.examples</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>org.apache.felix.atomos.examples.webconsole.bom</artifactId>
+    <packaging>pom</packaging>
+    <name>atomos.examples.webconsole.bom</name>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.promise</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.gogo.command</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.gogo.runtime</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.gogo.shell</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.http.jetty</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.http.api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.http.whiteboard</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.webconsole</artifactId>
+            <classifier>all</classifier>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.http.servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.cm</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.event</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.annotation</groupId>
+            <artifactId>javax.annotation-api</artifactId>
+            <version>1.3.2</version>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/atomos.examples/pom.xml b/atomos.examples/pom.xml
index f0ff17a..0da2440 100644
--- a/atomos.examples/pom.xml
+++ b/atomos.examples/pom.xml
@@ -11,6 +11,8 @@
     <artifactId>org.apache.felix.atomos.examples</artifactId>
     <name>atomos.examples</name>
     <modules>
+        <module>atomos.examples.webconsole.bom</module>
+        <module>atomos.examples.index</module>
         <module>atomos.examples.jlink</module>
         <module>atomos.examples.springloader</module>
     </modules>
@@ -18,6 +20,8 @@
         <profile>
             <id>substrate</id>
             <modules>
+                <module>atomos.examples.webconsole.bom</module>
+                <module>atomos.examples.index</module>
                 <module>atomos.examples.jlink</module>
                 <module>atomos.examples.springloader</module>
                 <module>atomos.examples.substrate.equinox</module>
diff --git 
a/atomos.maven/src/main/java/org/apache/felix/atomos/maven/AtomosIndexMojo.java 
b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/AtomosIndexMojo.java
new file mode 100644
index 0000000..75f70d2
--- /dev/null
+++ 
b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/AtomosIndexMojo.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed 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.felix.atomos.maven;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.jar.JarFile;
+import java.util.stream.Collectors;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+
+@Mojo(name = "atomos-index", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, 
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME, 
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
+public class AtomosIndexMojo extends AbstractMojo
+{
+    public static boolean isJarFile(Artifact a)
+    {
+        try (JarFile j = new JarFile(a.getFile());)
+        {
+
+            return true;
+        }
+        catch (IOException e)
+        {
+
+        }
+
+        return false;
+    }
+
+    @Parameter(defaultValue = "${project}", required = true, readonly = false)
+    private MavenProject project;
+
+    @Override
+    public void execute() throws MojoExecutionException
+    {
+        try
+        {
+            File outputDirectory = new 
File(project.getBuild().getOutputDirectory());
+            Files.createDirectories(outputDirectory.toPath());
+
+            List<Path> paths = project.getArtifacts().stream().filter(
+                AtomosIndexMojo::isJarFile).map(a -> 
a.getFile().toPath()).collect(
+                    Collectors.toList());
+
+            SubstrateUtil.indexContent(paths, outputDirectory.toPath());
+        }
+        catch (
+
+            Exception e)
+        {
+            throw new MojoExecutionException("Error", e);
+        }
+
+    }
+}
diff --git 
a/atomos.maven/src/main/java/org/apache/felix/atomos/maven/NativeImageMojo.java 
b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/NativeImageMojo.java
index ae47886..8ec736b 100644
--- 
a/atomos.maven/src/main/java/org/apache/felix/atomos/maven/NativeImageMojo.java
+++ 
b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/NativeImageMojo.java
@@ -15,11 +15,15 @@ package org.apache.felix.atomos.maven;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.jar.JarFile;
 import java.util.stream.Collectors;
 
@@ -136,7 +140,14 @@ public class NativeImageMojo extends AbstractMojo
             List<Path> paths = Files.list(classpath_lib.toPath()).filter(
                 NativeImageMojo::isJarFile).collect(Collectors.toList());
 
-            Path p = SubstrateUtil.substrate(paths, outputDirectory.toPath());
+            Path p = new File(outputDirectory, 
"atomos.substrate.jar").toPath();
+            URI uri = URI.create("jar:" + p.toUri());
+
+            try (FileSystem zipfs = FileSystems.newFileSystem(uri,
+                Map.of("create", "true")))
+            {
+                SubstrateUtil.indexContent(paths, zipfs.getPath("/"));
+            }
 
             List<ReflectConfig> reflectConfigs = 
ReflectConfigUtil.reflectConfig(paths);
 
diff --git 
a/atomos.maven/src/main/java/org/apache/felix/atomos/maven/SubstrateUtil.java 
b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/SubstrateUtil.java
index a946f71..e642747 100644
--- 
a/atomos.maven/src/main/java/org/apache/felix/atomos/maven/SubstrateUtil.java
+++ 
b/atomos.maven/src/main/java/org/apache/felix/atomos/maven/SubstrateUtil.java
@@ -15,8 +15,8 @@ package org.apache.felix.atomos.maven;
 
 import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.UncheckedIOException;
 import java.nio.file.Files;
@@ -30,7 +30,6 @@ import java.util.concurrent.atomic.AtomicLong;
 import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -93,53 +92,54 @@ public class SubstrateUtil
         return true;
     }
 
-    public static Path substrate(List<Path> files, Path outputDir)
+    public static void indexContent(List<Path> files,
+        Path outputRoot)
         throws IOException, NoSuchAlgorithmException
     {
-        if (!outputDir.toFile().isDirectory())
+        if (!Files.exists(outputRoot))
         {
-            throw new IllegalArgumentException(
-                "Output file must be a directory." + outputDir);
+            Files.createDirectories(outputRoot);
         }
-        if (!outputDir.toFile().exists())
+        if (!Files.isDirectory(outputRoot))
         {
-            Files.createDirectories(outputDir);
+            throw new IllegalArgumentException(
+                "Output file must be a directory." + outputRoot);
         }
 
-        final Path p = outputDir.resolve(ATOMOS_SUBSTRATE_JAR);
-
         final Manifest manifest = new Manifest();
         manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, 
"1.0");
-        try (final JarOutputStream z = new JarOutputStream(
-            new FileOutputStream(p.toFile()), manifest);)
+        Files.createDirectory(outputRoot.resolve("META-INF/"));
+        try (OutputStream mf = Files.newOutputStream(
+            outputRoot.resolve("META-INF/MANIFEST.MF")))
         {
+            manifest.write(mf);
+        }
 
-            final List<String> bundleIndexLines = new ArrayList<>();
-            final List<String> resources = new ArrayList<>();
-            final AtomicLong counter = new AtomicLong(0);
-            final Stream<SubstrateInfo> bis = files.stream()//
-                .map(path -> create(z, counter.getAndIncrement(), path));
+        final List<String> bundleIndexLines = new ArrayList<>();
+        final List<String> resources = new ArrayList<>();
+        final AtomicLong counter = new AtomicLong(0);
+        final Stream<SubstrateInfo> bis = files.stream()//
+            .map(path -> create(outputRoot, counter.getAndIncrement(), path));
 
-            bis.forEach(s -> {
-                if (s.bsn != null)
-                {
-                    bundleIndexLines.add(ATOMOS_BUNDLE_SEPARATOR);
-                    bundleIndexLines.add(s.id);
-                    bundleIndexLines.add(s.bsn);
-                    bundleIndexLines.add(s.version);
-                    s.files.forEach(f -> {
-                        bundleIndexLines.add(f);
-                        resources.add(ATOMOS_BUNDLES_BASE_PATH + s.id + "/" + 
f);
-                    });
-                }
-            });
-            writeBundleIndexFile(z, bundleIndexLines);
-            writeGraalResourceConfig(z, resources);
-        }
-        return p;
+        bis.forEach(s -> {
+            if (s.bsn != null)
+            {
+                bundleIndexLines.add(ATOMOS_BUNDLE_SEPARATOR);
+                bundleIndexLines.add(s.id);
+                bundleIndexLines.add(s.bsn);
+                bundleIndexLines.add(s.version);
+                s.files.forEach(f -> {
+                    bundleIndexLines.add(f);
+                    resources.add(ATOMOS_BUNDLES_BASE_PATH + s.id + "/" + f);
+                });
+            }
+        });
+        writeBundleIndexFile(outputRoot, bundleIndexLines);
+        writeGraalResourceConfig(outputRoot, resources);
     }
 
-    private static void writeGraalResourceConfig(JarOutputStream jos,
+    private static void writeGraalResourceConfig(
+        Path root,
         List<String> resources) throws IOException
     {
         //        resources.add(ATOMOS_BUNDLES_INDEX);
@@ -150,19 +150,19 @@ public class SubstrateUtil
 
         final String graalResConfJson = 
ResourceConfigUtil.createResourceJson(result);
 
-        final JarEntry graalResConfEntry = new JarEntry(
+        final Path graalResConfEntry = root.resolve(
             "META-INF/native-image/resource-config.json");
-        jos.putNextEntry(graalResConfEntry);
-        jos.write(graalResConfJson.getBytes());
-
+        Files.createDirectories(graalResConfEntry.getParent());
+        Files.writeString(graalResConfEntry, graalResConfJson);
     }
 
-    private static void writeBundleIndexFile(JarOutputStream jos,
+    private static void writeBundleIndexFile(
+        Path root,
         final List<String> resources) throws IOException
     {
 
-        final JarEntry atomosIndexEntry = new JarEntry(ATOMOS_BUNDLES_INDEX);
-        jos.putNextEntry(atomosIndexEntry);
+        final Path atomosIndexEntry = root.resolve(ATOMOS_BUNDLES_INDEX);
+        Files.createDirectories(atomosIndexEntry.getParent());
 
         final ByteArrayOutputStream out = new ByteArrayOutputStream();
         try (BufferedWriter writer = new BufferedWriter(new 
OutputStreamWriter(out)))
@@ -178,11 +178,10 @@ public class SubstrateUtil
                 }
             });
         }
-        jos.write(out.toByteArray());
-
+        Files.write(atomosIndexEntry, out.toByteArray());
     }
 
-    static SubstrateInfo create(JarOutputStream jos, long id, Path path)
+    static SubstrateInfo create(Path root, long id, Path path)
     {
         final SubstrateInfo info = new SubstrateInfo();
         info.path = path;
@@ -204,18 +203,18 @@ public class SubstrateUtil
             info.files = jar.stream().filter(j -> filter(j)).peek(j -> {
                 try
                 {
-                    final JarEntry entry = new JarEntry(
+                    final Path entry = root.resolve(
                         ATOMOS_BUNDLES_BASE_PATH + id + "/" + j.getName());
                     if (j.getCreationTime() != null)
                     {
-                        entry.setCreationTime(j.getCreationTime());
+                        Files.setLastModifiedTime(entry, j.getCreationTime());
                     }
                     if (j.getComment() != null)
                     {
-                        entry.setComment(j.getComment());
+                        // TODO figure out if there is a comment attribute
                     }
-                    jos.putNextEntry(entry);
-                    jos.write(jar.getInputStream(j).readAllBytes());
+                    Files.createDirectories(entry.getParent());
+                    Files.copy(jar.getInputStream(j), entry);
                 }
                 catch (final IOException e)
                 {
diff --git 
a/atomos.maven/src/test/java/org/apache/felix/atomos/maven/MojoTest.java 
b/atomos.maven/src/test/java/org/apache/felix/atomos/maven/MojoTest.java
index 7c8f0b1..432c3b0 100644
--- a/atomos.maven/src/test/java/org/apache/felix/atomos/maven/MojoTest.java
+++ b/atomos.maven/src/test/java/org/apache/felix/atomos/maven/MojoTest.java
@@ -32,7 +32,7 @@ public class MojoTest extends TestBase
 
         List<Path> paths = getAllDependencys();
 
-        SubstrateUtil.substrate(paths, tempDir);
+        SubstrateUtil.indexContent(paths, tempDir);
         List<ReflectConfig> reflectConfigs = 
ReflectConfigUtil.reflectConfig(paths);
         ResourceConfigResult resourceConfigResult = 
ResourceConfigUtil.resourceConfig(
             paths);
diff --git 
a/atomos.maven/src/test/java/org/apache/felix/atomos/maven/SubstrateTest.java 
b/atomos.maven/src/test/java/org/apache/felix/atomos/maven/SubstrateTest.java
index dcb80fa..ae96177 100644
--- 
a/atomos.maven/src/test/java/org/apache/felix/atomos/maven/SubstrateTest.java
+++ 
b/atomos.maven/src/test/java/org/apache/felix/atomos/maven/SubstrateTest.java
@@ -17,8 +17,13 @@ import static 
org.apache.felix.atomos.maven.TestConstants.DEP_ATOMOS_TESTS_TESTB
 import static org.apache.felix.atomos.maven.TestConstants.getDependency;
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.io.File;
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
 import java.nio.file.Path;
 import java.util.Arrays;
+import java.util.Map;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.stream.Collectors;
@@ -33,18 +38,40 @@ public class SubstrateTest extends TestBase
     void testSubstrate(@TempDir Path tempDir) throws Exception
     {
         Path path = getDependency(DEP_ATOMOS_TESTS_TESTBUNDLES_RESOURCE_A);
-        Path atomosSubstrateJar = SubstrateUtil.substrate(Arrays.asList(path), 
tempDir);
+        Path atomosSubstrateJar = new File(tempDir.toFile(), 
"test.index.jar").toPath();
+        URI uri = URI.create("jar:" + atomosSubstrateJar.toUri());
+
+        try (FileSystem zipfs = FileSystems.newFileSystem(uri, 
Map.of("create", "true")))
+        {
+            SubstrateUtil.indexContent(Arrays.asList(path),
+                zipfs.getPath("/"));
+        }
         assertThat(atomosSubstrateJar).exists().isRegularFile();
 
         try (JarFile jarFile = new JarFile(atomosSubstrateJar.toFile());)
         {
             assertThat(jarFile.stream().map(JarEntry::getName).collect(
-                Collectors.toList())).containsOnly("META-INF/MANIFEST.MF", //
+                Collectors.toList())).containsOnly( //
+                    "META-INF/", //
+                    "META-INF/MANIFEST.MF",
+                    "atomos/", //
+                    "atomos/0/", //
+                    "atomos/0/META-INF/", //
                     "atomos/0/META-INF/MANIFEST.MF", //
+                    "atomos/0/file.txt", //
+                    "atomos/0/META-TEXT/", //
                     "atomos/0/META-TEXT/file.txt", //
+                    "atomos/0/org/", //
+                    "atomos/0/org/apache/", //
+                    "atomos/0/org/apache/felix/", //
+                    "atomos/0/org/apache/felix/atomos/", //
+                    "atomos/0/org/apache/felix/atomos/tests/", //
+                    "atomos/0/org/apache/felix/atomos/tests/testbundles/", //
+                    
"atomos/0/org/apache/felix/atomos/tests/testbundles/resource/", //
+                    
"atomos/0/org/apache/felix/atomos/tests/testbundles/resource/a/", //
                     
"atomos/0/org/apache/felix/atomos/tests/testbundles/resource/a/file.txt", //
-                    "atomos/0/file.txt", //
                     "atomos/bundles.index", //
+                    "META-INF/native-image/", //
                     "META-INF/native-image/resource-config.json");
         }
 

Reply via email to