summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Donszelmann <Mark.Donszelmann@gmail.com>2009-11-05 16:17:51 +0100
committerMark Donszelmann <Mark.Donszelmann@gmail.com>2009-11-05 16:17:51 +0100
commit5f3d4a7de54c13dff30f3e61761b693e26c406fa (patch)
tree083bfae72124c0e3a2b68854cae58c426d0bea3c
parent707da2d176a5c04878cfb84c4f71bdb799a128e0 (diff)
downloadmaven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.tar.gz
maven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.tar.bz2
maven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.tar.xz
maven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.zip
Added test for layout change, it0016
-rw-r--r--src/it/it0016-layout/it0016-executable-dep-lib-shared/pom.xml68
-rw-r--r--src/it/it0016-layout/it0016-executable-dep-lib-shared/src/main/c/HelloWorldExe.c9
-rw-r--r--src/it/it0016-layout/it0016-lib-shared/pom.xml68
-rw-r--r--src/it/it0016-layout/it0016-lib-shared/src/main/c/HelloWorldLib.c7
-rw-r--r--src/it/it0016-layout/it0016-lib-shared/src/main/include/HelloWorldLib.h9
-rw-r--r--src/it/it0016-layout/it0016-lib-shared/src/test/c/HelloWorldTest.c9
-rw-r--r--src/it/it0016-layout/pom.xml50
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/AbstractCompileMojo.java37
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java67
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java6
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/DefaultNarLayout.java30
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarLayout.java31
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarLayout20.java100
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarLayout21.java100
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java158
15 files changed, 512 insertions, 237 deletions
diff --git a/src/it/it0016-layout/it0016-executable-dep-lib-shared/pom.xml b/src/it/it0016-layout/it0016-executable-dep-lib-shared/pom.xml
new file mode 100644
index 0000000..95b34e0
--- /dev/null
+++ b/src/it/it0016-layout/it0016-executable-dep-lib-shared/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.nar</groupId>
+ <artifactId>it0016-pom</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>it0016-executable-dep-lib-shared</artifactId>
+ <packaging>nar</packaging>
+
+ <name>Maven NAR Executable and Shared Library</name>
+ <version>1.0-SNAPSHOT</version>
+ <description>
+ Executable depending on a shared library.
+ </description>
+
+ <properties>
+ <skipTests>true</skipTests>
+ </properties>
+
+ <build>
+ <defaultGoal>integration-test</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-nar-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <libraries>
+ <library>
+ <type>executable</type>
+ <run>true</run>
+ </library>
+ </libraries>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.nar</groupId>
+ <artifactId>it0016-lib-shared</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/it/it0016-layout/it0016-executable-dep-lib-shared/src/main/c/HelloWorldExe.c b/src/it/it0016-layout/it0016-executable-dep-lib-shared/src/main/c/HelloWorldExe.c
new file mode 100644
index 0000000..4aa35d8
--- /dev/null
+++ b/src/it/it0016-layout/it0016-executable-dep-lib-shared/src/main/c/HelloWorldExe.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "HelloWorldLib.h"
+
+int main(int argc, char *argv[]) {
+ printf("%s\n", HelloWorldLib_sayHello());
+ return 0;
+}
+
+
diff --git a/src/it/it0016-layout/it0016-lib-shared/pom.xml b/src/it/it0016-layout/it0016-lib-shared/pom.xml
new file mode 100644
index 0000000..831e48e
--- /dev/null
+++ b/src/it/it0016-layout/it0016-lib-shared/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.nar</groupId>
+ <artifactId>it0016-pom</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>it0016-lib-shared</artifactId>
+ <packaging>nar</packaging>
+
+ <name>Maven NAR Shared Library</name>
+ <version>1.0-SNAPSHOT</version>
+ <description>
+ Simple shared library and test file
+ </description>
+ <url>http://maven.apache.org/</url>
+
+ <properties>
+ <skipTests>true</skipTests>
+ </properties>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-nar-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <layout>NarLayout20</layout>
+ <libraries>
+ <library>
+ <type>shared</type>
+ </library>
+ </libraries>
+ <tests>
+ <test>
+ <name>HelloWorldTest</name>
+ <link>shared</link>
+ </test>
+ </tests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/it0016-layout/it0016-lib-shared/src/main/c/HelloWorldLib.c b/src/it/it0016-layout/it0016-lib-shared/src/main/c/HelloWorldLib.c
new file mode 100644
index 0000000..9f65143
--- /dev/null
+++ b/src/it/it0016-layout/it0016-lib-shared/src/main/c/HelloWorldLib.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include "HelloWorldLib.h"
+
+char* HelloWorldLib_sayHello() {
+ return "Hello NAR LIB World!";
+}
+
diff --git a/src/it/it0016-layout/it0016-lib-shared/src/main/include/HelloWorldLib.h b/src/it/it0016-layout/it0016-lib-shared/src/main/include/HelloWorldLib.h
new file mode 100644
index 0000000..e801bec
--- /dev/null
+++ b/src/it/it0016-layout/it0016-lib-shared/src/main/include/HelloWorldLib.h
@@ -0,0 +1,9 @@
+#ifndef HelloWorldLib_H
+#define HelloWorldLib_H
+
+#ifdef WIN32
+__declspec(dllexport)
+#endif
+extern char* HelloWorldLib_sayHello();
+
+#endif
diff --git a/src/it/it0016-layout/it0016-lib-shared/src/test/c/HelloWorldTest.c b/src/it/it0016-layout/it0016-lib-shared/src/test/c/HelloWorldTest.c
new file mode 100644
index 0000000..4aa35d8
--- /dev/null
+++ b/src/it/it0016-layout/it0016-lib-shared/src/test/c/HelloWorldTest.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "HelloWorldLib.h"
+
+int main(int argc, char *argv[]) {
+ printf("%s\n", HelloWorldLib_sayHello());
+ return 0;
+}
+
+
diff --git a/src/it/it0016-layout/pom.xml b/src/it/it0016-layout/pom.xml
new file mode 100644
index 0000000..0fc5b68
--- /dev/null
+++ b/src/it/it0016-layout/pom.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.nar</groupId>
+ <artifactId>it-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../it-parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>it0016-pom</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Maven NAR Layout</name>
+ <version>1.0-SNAPSHOT</version>
+ <description>
+ Project to check layout compatibility
+ </description>
+ <url>http://maven.apache.org/</url>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ </build>
+
+ <modules>
+ <module>it0016-executable-dep-lib-shared</module>
+ <module>it0016-lib-shared</module>
+ </modules>
+</project>
diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractCompileMojo.java b/src/main/java/org/apache/maven/plugin/nar/AbstractCompileMojo.java
index 08ad9f6..5a541ad 100644
--- a/src/main/java/org/apache/maven/plugin/nar/AbstractCompileMojo.java
+++ b/src/main/java/org/apache/maven/plugin/nar/AbstractCompileMojo.java
@@ -129,6 +129,15 @@ public abstract class AbstractCompileMojo
*/
private Java java;
+ /**
+ * Layout to be used for building and upacking artifacts
+ *
+ * @parameter expression="${nar.layout}" default-value="org.apache.maven.plugin.nar.NarLayout21"
+ * @required
+ */
+ private String layout;
+ private NarLayout narLayout;
+
private NarInfo narInfo;
private List/* <String> */dependencyLibOrder;
@@ -253,9 +262,31 @@ public abstract class AbstractCompileMojo
return narInfo;
}
- // FIXME, needs to be configurable and maybe move up
- protected NarLayout getLayout()
+ // FIXME, needs to maybe move up
+ protected NarLayout getLayout() throws MojoExecutionException
{
- return new DefaultNarLayout();
+ if (narLayout == null) {
+ String className = layout.indexOf( '.' ) < 0 ? NarLayout21.class.getPackage().getName()+"."+layout : layout;
+ getLog().debug( "Using "+className);
+ Class cls;
+ try
+ {
+ cls = Class.forName( className );
+ narLayout = (NarLayout)cls.newInstance();
+ }
+ catch ( ClassNotFoundException e )
+ {
+ throw new MojoExecutionException( "Cannot find class for layout "+className, e );
+ }
+ catch ( InstantiationException e )
+ {
+ throw new MojoExecutionException( "Cannot instantiate class for layout "+className, e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new MojoExecutionException( "Cannot access class for layout "+className, e );
+ }
+ }
+ return narLayout;
}
}
diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java b/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
new file mode 100644
index 0000000..7dc2f65
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
@@ -0,0 +1,67 @@
+/*
+ * 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.maven.plugin.nar;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.zip.ZipArchiver;
+
+/**
+ *
+ * @author Mark Donszelmann (Mark.Donszelmann@gmail.com)
+ * @version $Id$
+ */
+public abstract class AbstractNarLayout
+ implements NarLayout, NarConstants
+{
+
+ protected void attachNar( MavenProjectHelper projectHelper, MavenProject project, String classifier, File dir,
+ String include )
+ throws MojoExecutionException
+ {
+ File narFile =
+ new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + "-" + classifier + "."
+ + NarConstants.NAR_EXTENSION );
+ if ( narFile.exists() )
+ narFile.delete();
+ Archiver archiver = new ZipArchiver();
+ try
+ {
+ archiver.addDirectory( dir, new String[] { include }, null );
+ archiver.setDestFile( narFile );
+ archiver.createArchive();
+ }
+ catch ( ArchiverException e )
+ {
+ throw new MojoExecutionException( "NAR: cannot create NAR archive '" + narFile + "'", e );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "NAR: cannot create NAR archive '" + narFile + "'", e );
+ }
+ projectHelper.attachArtifact( project, NarConstants.NAR_TYPE, classifier, narFile );
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java b/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java
index 9e624db..9e23d42 100644
--- a/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java
@@ -73,7 +73,7 @@ public abstract class AbstractResourcesMojo
private ArchiverManager archiverManager;
protected int copyIncludes( File srcDir )
- throws IOException
+ throws IOException, MojoExecutionException
{
int copied = 0;
@@ -90,7 +90,7 @@ public abstract class AbstractResourcesMojo
}
protected int copyBinaries( File srcDir, String aol )
- throws IOException
+ throws IOException, MojoExecutionException
{
int copied = 0;
@@ -107,7 +107,7 @@ public abstract class AbstractResourcesMojo
}
protected int copyLibraries( File srcDir, String aol )
- throws MojoFailureException, IOException
+ throws MojoFailureException, IOException, MojoExecutionException
{
int copied = 0;
diff --git a/src/main/java/org/apache/maven/plugin/nar/DefaultNarLayout.java b/src/main/java/org/apache/maven/plugin/nar/DefaultNarLayout.java
deleted file mode 100644
index 604ee85..0000000
--- a/src/main/java/org/apache/maven/plugin/nar/DefaultNarLayout.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.maven.plugin.nar;
-
-import java.io.File;
-
-/*
- * 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.
- */
-
-/**
- * @author Mark Donszelmann (Mark.Donszelmann@gmail.com)
- */
-public class DefaultNarLayout
- extends NarLayout21
-{
-}
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarLayout.java b/src/main/java/org/apache/maven/plugin/nar/NarLayout.java
index fe1a5e4..a264ea2 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarLayout.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarLayout.java
@@ -2,6 +2,10 @@ package org.apache.maven.plugin.nar;
import java.io.File;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -23,37 +27,38 @@ import java.io.File;
*/
/**
- * Interface to define the layout of nar files (executables, libs, include dirs) in both the
- * repository (local, unpacked) as well as in target.
+ * Interface to define the layout of nar files (executables, libs, include dirs) in both the repository (local,
+ * unpacked) as well as in target.
*
* @author Mark Donszelmann (Mark.Donszelmann@gmail.com)
*/
public interface NarLayout
{
/**
- * Specified wgere the noarch specific includes are unpacked
+ * Specifies where libraries are stored
*
* @return
*/
- public File getNoarchDirectory( File baseDir );
+ public File getLibDirectory( File baseDir, String aol, String type );
/**
- * Specifies where the aol specific libs are unpacked
- *
+ * Specifies where includes are stored
+ *
* @return
*/
- public File getAolDirectory( File baseDir );
-
+ public File getIncludeDirectory( File targetDirectory );
+
/**
- * Specifies where libraries are stored
+ * Specifies where binaries are stored
*
* @return
*/
- public File getLibDirectory(File baseDir, String aol, String type);
+ public File getBinDirectory( File baseDir, String aol );
/**
- * Specifies where includes are stored
- * @return
+ * Called to attach nars to main jar file. This method needs to produce all the attached nar files and set NarInfo
+ * accordingly.
*/
- public File getIncludeDirectory( File targetDirectory );
+ public void attachNars( File baseDir, MavenProjectHelper projectHelper, MavenProject project, NarInfo narInfo )
+ throws MojoExecutionException;
}
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarLayout20.java b/src/main/java/org/apache/maven/plugin/nar/NarLayout20.java
index 9cd4f9d..c49ac2c 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarLayout20.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarLayout20.java
@@ -2,6 +2,10 @@ package org.apache.maven.plugin.nar;
import java.io.File;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -24,54 +28,106 @@ import java.io.File;
/**
* Initial layout which expands a nar file into:
*
- * <pre>
+ * <pre>
* nar/includue
* nar/bin
* nar/lib
* </pre>
*
- * this layout was abandoned bacuse there is no one-to-one relation between the
- * nar file and its directory structure. Therefore SNAPSHOTS could not be fully
- * deleted when replaced.
+ * this layout was abandoned because there is no one-to-one relation between the nar file and its directory structure.
+ * Therefore SNAPSHOTS could not be fully deleted when replaced.
*
* @author Mark Donszelmann (Mark.Donszelmann@gmail.com)
*/
public class NarLayout20
- implements NarLayout
+ extends AbstractNarLayout
{
- public File getAolDirectory( File baseDir )
- {
- return baseDir;
- }
-
- public File getNoarchDirectory( File baseDir )
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.nar.NarLayout#getIncludeDirectory(java.io.File)
+ */
+ public File getIncludeDirectory( File baseDir )
{
- return baseDir;
+ return new File( baseDir, "include" );
}
/*
* (non-Javadoc)
- * @see org.apache.maven.plugin.nar.NarLayout#getIncludeDirectory(java.io.File)
+ * @see org.apache.maven.plugin.nar.NarLayout#getLibDir(java.io.File, org.apache.maven.plugin.nar.AOL, String type)
*/
- public File getIncludeDirectory( File baseDir )
+ public File getLibDirectory( File baseDir, String aol, String type )
{
- File dir = getNoarchDirectory( baseDir );
- dir = new File( dir, "include" );
+ if ( type.equals( Library.EXECUTABLE ) )
+ {
+ System.err.println( "WARNING, Replace call to getLibDirectory with getBinDirectory" );
+ Thread.dumpStack();
+ }
+
+ File dir = new File( baseDir, "lib" );
+ dir = new File( dir, aol.toString() );
+ dir = new File( dir, type );
return dir;
}
/*
* (non-Javadoc)
- * @see org.apache.maven.plugin.nar.NarLayout#getLibDir(org.apache.maven.plugin.nar.AOL, java.lang.String)
+ * @see org.apache.maven.plugin.nar.NarLayout#getBinDirectory(java.io.File, java.lang.String)
*/
- public File getLibDirectory( File baseDir, String aol, String type )
+ public File getBinDirectory( File baseDir, String aol )
{
- File dir = getAolDirectory( baseDir );
- dir = new File( dir, type.equals( Library.EXECUTABLE ) ? "bin" : "lib" );
+ File dir = new File( baseDir, "bin" );
dir = new File( dir, aol.toString() );
- if ( !type.equals( Library.EXECUTABLE ) )
- dir = new File( dir, type );
return dir;
}
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.nar.NarLayout#attachNars(java.io.File, org.apache.maven.project.MavenProjectHelper,
+ * org.apache.maven.project.MavenProject, org.apache.maven.plugin.nar.NarInfo)
+ */
+ public void attachNars( File baseDir, MavenProjectHelper projectHelper, MavenProject project, NarInfo narInfo )
+ throws MojoExecutionException
+ {
+ if ( getIncludeDirectory( baseDir ).exists() )
+ {
+ attachNar( projectHelper, project, "noarch", baseDir, "include/**" );
+ narInfo.setNar( null, "noarch", project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + NarConstants.NAR_TYPE + ":" + "noarch" );
+ }
+
+ String[] binAOL = new File( baseDir, "bin" ).list();
+ for ( int i = 0; ( binAOL != null ) && ( i < binAOL.length ); i++ )
+ {
+ attachNar( projectHelper, project, binAOL[i] + "-" + Library.EXECUTABLE, baseDir, "bin/" + binAOL[i]
+ + "/**" );
+ narInfo.setNar( null, Library.EXECUTABLE, project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + Library.EXECUTABLE );
+ }
+
+ File libDir = new File( baseDir, "lib" );
+ String[] libAOL = libDir.list();
+ for ( int i = 0; ( libAOL != null ) && ( i < libAOL.length ); i++ )
+ {
+ String bindingType = null;
+ String[] libType = new File( libDir, libAOL[i] ).list();
+ for ( int j = 0; ( libType != null ) && ( j < libType.length ); j++ )
+ {
+ attachNar( projectHelper, project, libAOL[i] + "-" + libType[j], baseDir, "lib/" + libAOL[i] + "/"
+ + libType[j] + "/**" );
+ narInfo.setNar( null, libType[j], project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + libType[j] );
+
+ // set if not set or override if SHARED
+ if ( ( bindingType == null ) || libType[j].equals( Library.SHARED ) )
+ {
+ bindingType = libType[j];
+ }
+ }
+
+ if ( narInfo.getBinding( null, null ) == null )
+ {
+ narInfo.setBinding( null, bindingType != null ? bindingType : Library.NONE );
+ }
+ }
+ }
}
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java b/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java
index 074d594..61c3a19 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java
@@ -2,6 +2,10 @@ package org.apache.maven.plugin.nar;
import java.io.File;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -35,16 +39,16 @@ import java.io.File;
* @author Mark Donszelmann (Mark.Donszelmann@gmail.com)
*/
public class NarLayout21
- implements NarLayout
+ extends AbstractNarLayout
{
- public File getAolDirectory( File baseDir )
+ private File getNoarchDirectory( File baseDir )
{
- return new File( baseDir, "aol" );
+ return new File( baseDir, "noarch" );
}
- public File getNoarchDirectory( File baseDir )
+ private File getAolDirectory( File baseDir )
{
- return new File( baseDir, "noarch" );
+ return new File( baseDir, "aol" );
}
private File getAolDirectory( File baseDir, String aol, String type )
@@ -58,23 +62,95 @@ public class NarLayout21
*/
public File getIncludeDirectory( File baseDir )
{
- File dir = getNoarchDirectory( baseDir );
- dir = new File( dir, "include" );
- return dir;
+ return new File( getNoarchDirectory( baseDir ), "include" );
}
/*
* (non-Javadoc)
- * @see org.apache.maven.plugin.nar.NarLayout#getLibDir(org.apache.maven.plugin.nar.AOL, java.lang.String)
+ * @see org.apache.maven.plugin.nar.NarLayout#getLibDir(java.io.File, org.apache.maven.plugin.nar.AOL,
+ * java.lang.String)
*/
public File getLibDirectory( File baseDir, String aol, String type )
{
+ if ( type.equals( Library.EXECUTABLE ) )
+ {
+ System.err.println( "WARNING, Replace call to getLibDirectory with getBinDirectory" );
+ Thread.dumpStack();
+ }
+
File dir = getAolDirectory( baseDir, aol, type );
- dir = new File( dir, type.equals( Library.EXECUTABLE ) ? "bin" : "lib" );
+ dir = new File( dir, "lib" );
dir = new File( dir, aol.toString() );
- if ( !type.equals( Library.EXECUTABLE ) )
- dir = new File( dir, type );
+ dir = new File( dir, type );
return dir;
}
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.nar.NarLayout#getLibDir(java.io.File, org.apache.maven.plugin.nar.AOL,
+ * java.lang.String)
+ */
+ public File getBinDirectory( File baseDir, String aol )
+ {
+ File dir = getAolDirectory( baseDir, aol, Library.EXECUTABLE );
+ dir = new File( dir, "bin" );
+ dir = new File( dir, aol.toString() );
+ return dir;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.nar.NarLayout#attachNars(java.io.File, org.apache.maven.project.MavenProjectHelper,
+ * org.apache.maven.project.MavenProject, org.apache.maven.plugin.nar.NarInfo)
+ */
+ public void attachNars( File baseDir, MavenProjectHelper projectHelper, MavenProject project, NarInfo narInfo )
+ throws MojoExecutionException
+ {
+ if (getNoarchDirectory( baseDir ).exists()) {
+ attachNar( projectHelper, project, "noarch", getNoarchDirectory( baseDir ), "*/**" );
+ narInfo.setNar( null, "noarch", project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + NarConstants.NAR_TYPE + ":" + "noarch" );
+ }
+
+ String bindingType = null;
+ File classifierDir = getAolDirectory( baseDir );
+ String[] classifier = classifierDir.list();
+ for ( int i = 0; ( classifier != null ) && ( i < classifier.length ); i++ )
+ {
+ File dir = new File( classifierDir, classifier[i] );
+ attachNar( projectHelper, project, classifier[i], dir, "*/**" );
+
+ // look for type in aol/lib/<aol>/type
+ String type = Library.EXECUTABLE;
+ File libDir = new File( dir, "lib" );
+ String[] aolDir = libDir.list();
+ if ( ( aolDir != null ) && aolDir.length > 0 )
+ {
+ String[] typeDir = new File( libDir, aolDir[0] ).list();
+ if ( ( typeDir != null ) && ( typeDir.length > 0 ) )
+ {
+ type = typeDir[0];
+ }
+ }
+
+ narInfo.setNar( null, type, project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + type );
+
+ // set if not Executable
+ if ( !type.equals( Library.EXECUTABLE ) )
+ {
+ // and not set or override if SHARED
+ if ( ( bindingType == null ) || type.equals( Library.SHARED ) )
+ {
+ bindingType = type;
+ }
+ }
+
+ }
+
+ if ( narInfo.getBinding( null, null ) == null )
+ {
+ narInfo.setBinding( null, bindingType != null ? bindingType : Library.NONE );
+ }
+ }
}
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java
index 6645de1..49f129e 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java
@@ -21,14 +21,10 @@ package org.apache.maven.plugin.nar;
import java.io.File;
import java.io.IOException;
-import java.util.Iterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProjectHelper;
-import org.codehaus.plexus.archiver.Archiver;
-import org.codehaus.plexus.archiver.ArchiverException;
-import org.codehaus.plexus.archiver.zip.ZipArchiver;
/**
* Jars up the NAR files.
@@ -55,62 +51,12 @@ public class NarPackageMojo
if ( shouldSkip() )
return;
- // FIX for NARPLUGIN-??? where -DupdateReleaseInfo copies to a .nar file
+ // Avoid that -DupdateReleaseInfo copies to a .nar file
getMavenProject().getArtifact().setArtifactHandler( new NarArtifactHandler() );
- // noarch
- File noarchDir = getLayout().getNoarchDirectory( getTargetDirectory() );
- if ( noarchDir.exists() )
- {
- String type = noarchDir.getName();
- attachNar( noarchDir, type );
- getNarInfo().setNar(
- null,
- type,
- getMavenProject().getGroupId() + ":" + getMavenProject().getArtifactId() + ":"
- + NAR_TYPE + ":" + type );
- }
-
- // create nar with binaries
- /* OLD CODE
- String bin = "bin";
- String[] binAOLs = new File( getTargetDirectory(), bin ).list();
- for ( int i = 0; i < ( binAOLs != null ? binAOLs.length : 0 ); i++ )
- {
- attachNarOld( bin + "/" + binAOLs[i], binAOLs[i], Library.EXECUTABLE );
- }
- */
-
- // create nars for each type of library (static, shared).
- String bindingType = null;
- for ( Iterator i = getLibraries().iterator(); i.hasNext(); )
- {
- Library library = (Library) i.next();
- String type = library.getType();
- if ( bindingType == null )
- bindingType = type;
-
- // create nar with libraries
- // FIXME NAR-90, the resources nar may copy extra libs in.
- File aolDirectory = getLayout().getAolDirectory( getTargetDirectory() );
- String[] subDirs = aolDirectory.list();
- for ( int j = 0; j < ( subDirs != null ? subDirs.length : 0 ); j++ )
- {
- attachNar( new File( aolDirectory, subDirs[j] ), subDirs[j] );
- getNarInfo().setNar(
- null,
- type,
- getMavenProject().getGroupId() + ":" + getMavenProject().getArtifactId() + ":"
- + NAR_TYPE + ":" + "${aol}-" + type );
- }
- }
-
- // override binding if not set
- if ( getNarInfo().getBinding( null, null ) == null )
- {
- getNarInfo().setBinding( null, bindingType != null ? bindingType : Library.NONE );
- }
-
+ // let the layout decide which nars to attach
+ getLayout().attachNars( getTargetDirectory(), projectHelper, getMavenProject(), getNarInfo() );
+
try
{
File propertiesDir =
@@ -128,100 +74,4 @@ public class NarPackageMojo
throw new MojoExecutionException( "Cannot write nar properties file", ioe );
}
}
-
- /**
- * @param file
- * @param string
- * @param type
- * @throws MojoExecutionException
- */
- private void attachNar( File dir, String classifier )
- throws MojoExecutionException
- {
- File narFile = new File( getOutputDirectory(), getFinalName() + "-" + classifier + "." + NAR_EXTENSION );
- nar( narFile, dir );
- projectHelper.attachArtifact( getMavenProject(), NAR_TYPE, classifier, narFile );
- }
-
- private void attachNarOld( String dir, String aol, String type )
- throws MojoExecutionException
- {
- File libFile =
- new File( getOutputDirectory(), getFinalName() + "-" + ( aol != null ? aol + "-" : "" ) + type + "."
- + NAR_EXTENSION );
- narOld( libFile, getTargetDirectory(), new String[] { dir } );
- projectHelper.attachArtifact( getMavenProject(), NAR_TYPE, ( aol != null ? aol + "-" : "" ) + type, libFile );
- getNarInfo().setNar(
- null,
- type,
- getMavenProject().getGroupId() + ":" + getMavenProject().getArtifactId() + ":" + NAR_TYPE
- + ":" + ( aol != null ? "${aol}-" : "" ) + type );
-
- }
-
- private void nar( File nar, File dir )
- throws MojoExecutionException
- {
- try
- {
- if ( nar.exists() )
- {
- nar.delete();
- }
-
- Archiver archiver = new ZipArchiver();
- // seems to return same archiver all the time
- // archiverManager.getArchiver(NAR_ROLE_HINT);
- String[] includes = new String[] { "*/**" };
- archiver.addDirectory( dir, includes, null );
- archiver.setDestFile( nar );
- archiver.createArchive();
- }
- catch ( ArchiverException e )
- {
- throw new MojoExecutionException( "Error while creating NAR archive.", e );
- // } catch (NoSuchArchiverException e) {
- // throw new MojoExecutionException("Error while creating NAR
- // archive.", e );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error while creating NAR archive.", e );
- }
- }
-
- private void narOld( File nar, File dir, String[] dirs )
- throws MojoExecutionException
- {
- try
- {
- if ( nar.exists() )
- {
- nar.delete();
- }
-
- Archiver archiver = new ZipArchiver();
- // seems to return same archiver all the time
- // archiverManager.getArchiver(NAR_ROLE_HINT);
- for ( int i = 0; i < dirs.length; i++ )
- {
- String[] includes = new String[] { dirs[i] + "/**" };
- archiver.addDirectory( dir, includes, null );
- }
- archiver.setDestFile( nar );
- archiver.createArchive();
- }
- catch ( ArchiverException e )
- {
- throw new MojoExecutionException( "Error while creating NAR archive.", e );
- // } catch (NoSuchArchiverException e) {
- // throw new MojoExecutionException("Error while creating NAR
- // archive.", e );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error while creating NAR archive.", e );
- }
- }
-
}