diff options
Diffstat (limited to 'src/main/java/org/apache/maven/plugin/nar/NarLayout21.java')
-rw-r--r-- | src/main/java/org/apache/maven/plugin/nar/NarLayout21.java | 133 |
1 files changed, 76 insertions, 57 deletions
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 623e3fa..090e83e 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java @@ -3,9 +3,12 @@ package org.apache.maven.plugin.nar; import java.io.File; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.archiver.manager.ArchiverManager; +import org.codehaus.plexus.util.FileUtils; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -42,28 +45,31 @@ import org.codehaus.plexus.archiver.manager.ArchiverManager; public class NarLayout21 extends AbstractNarLayout { - public File getNoArchDirectory( File baseDir ) + private NarFileLayout fileLayout; + + public NarLayout21( Log log ) { - return new File( baseDir, NarConstants.NAR_NO_ARCH ); + super( log ); + this.fileLayout = new NarFileLayout10(); } - private File getAolDirectory( File baseDir ) + public File getNoArchDirectory( File baseDir, String artifactId, String version ) { - return new File( baseDir, NarConstants.NAR_AOL ); + return new File( baseDir, artifactId + "-" + version + "-" + NarConstants.NAR_NO_ARCH ); } - private File getAolDirectory( File baseDir, String aol, String type ) + private File getAolDirectory( File baseDir, String artifactId, String version, String aol, String type ) { - return new File( getAolDirectory( baseDir ), aol + "-" + type ); + return new File( baseDir, artifactId + "-" + version + "-" + aol + "-" + type ); } /* * (non-Javadoc) * @see org.apache.maven.plugin.nar.NarLayout#getIncludeDirectory(java.io.File) */ - public final File getIncludeDirectory( File baseDir ) + public final File getIncludeDirectory( File baseDir, String artifactId, String version ) { - return new File( getNoArchDirectory( baseDir ), "include" ); + return new File( getNoArchDirectory( baseDir, artifactId, version ), fileLayout.getIncludeDirectory() ); } /* @@ -71,7 +77,7 @@ public class NarLayout21 * @see org.apache.maven.plugin.nar.NarLayout#getLibDir(java.io.File, org.apache.maven.plugin.nar.AOL, * java.lang.String) */ - public final File getLibDirectory( File baseDir, String aol, String type ) + public final File getLibDirectory( File baseDir, String artifactId, String version, String aol, String type ) throws MojoExecutionException { if ( type.equals( Library.EXECUTABLE ) ) @@ -80,10 +86,8 @@ public class NarLayout21 "NAR: for type EXECUTABLE call getBinDirectory instead of getLibDirectory" ); } - File dir = getAolDirectory( baseDir, aol, type ); - dir = new File( dir, "lib" ); - dir = new File( dir, aol ); - dir = new File( dir, type ); + File dir = getAolDirectory( baseDir, artifactId, version, aol, type ); + dir = new File( dir, fileLayout.getLibDirectory( aol, type ) ); return dir; } @@ -92,11 +96,10 @@ public class NarLayout21 * @see org.apache.maven.plugin.nar.NarLayout#getLibDir(java.io.File, org.apache.maven.plugin.nar.AOL, * java.lang.String) */ - public final File getBinDirectory( File baseDir, String aol ) + public final File getBinDirectory( File baseDir, String artifactId, String version, String aol ) { - File dir = getAolDirectory( baseDir, aol, Library.EXECUTABLE ); - dir = new File( dir, "bin" ); - dir = new File( dir, aol ); + File dir = getAolDirectory( baseDir, artifactId, version, aol, Library.EXECUTABLE ); + dir = new File(dir, fileLayout.getBinDirectory( aol )); return dir; } @@ -105,33 +108,41 @@ public class NarLayout21 * @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 final void attachNars( File baseDir, ArchiverManager archiverManager, MavenProjectHelper projectHelper, MavenProject project, NarInfo narInfo ) + public final void attachNars( File baseDir, ArchiverManager archiverManager, MavenProjectHelper projectHelper, + MavenProject project, NarInfo narInfo ) throws MojoExecutionException { - if ( getNoArchDirectory( baseDir ).exists() ) + if ( getNoArchDirectory( baseDir, project.getArtifactId(), project.getVersion() ).exists() ) { - attachNar( archiverManager, projectHelper, project, NarConstants.NAR_NO_ARCH, getNoArchDirectory( baseDir ), "*/**" ); + attachNar( archiverManager, projectHelper, project, NarConstants.NAR_NO_ARCH, + getNoArchDirectory( baseDir, project.getArtifactId(), project.getVersion() ), "*/**" ); narInfo.setNar( null, NarConstants.NAR_NO_ARCH, project.getGroupId() + ":" + project.getArtifactId() + ":" + NarConstants.NAR_TYPE + ":" + NarConstants.NAR_NO_ARCH ); } - File classifierDir = getAolDirectory( baseDir ); - String[] classifier = classifierDir.list(); - for ( int i = 0; ( classifier != null ) && ( i < classifier.length ); i++ ) + // list all directories in basedir, scan them for classifiers + String[] subDirs = baseDir.list(); + for ( int i = 0; ( subDirs != null ) && ( i < subDirs.length ); i++ ) { - File dir = new File( classifierDir, classifier[i] ); - attachNar( archiverManager, projectHelper, project, classifier[i], dir, "*/**" ); - - String type = null; - AOL aol = null; - - File binDir = new File( dir, "bin" ); - String[] aolDir = binDir.list(); - if ( ( aolDir != null ) && aolDir.length > 0 ) + String artifactIdVersion = project.getArtifactId()+"-"+project.getVersion(); + + // skip entries not belonging to this project + if (!subDirs[i].startsWith( artifactIdVersion )) continue; + + String classifier = subDirs[i].substring( artifactIdVersion.length()+1 ); + System.err.println("*** "+classifier); + // skip noarch here + if (classifier.equals( NarConstants.NAR_NO_ARCH )) continue; + + File dir = new File( baseDir, subDirs[i] ); + attachNar( archiverManager, projectHelper, project, classifier, dir, "*/**" ); + + int lastDash = classifier.lastIndexOf( '-' ); + String type = classifier.substring( lastDash+1); + AOL aol = new AOL(classifier.substring( 0, lastDash-1 )); + + if (type.equals( Library.EXECUTABLE )) { - type = Library.EXECUTABLE; - aol = new AOL(aolDir[0]); - if ( narInfo.getBinding( aol, null ) == null ) { narInfo.setBinding( aol, Library.EXECUTABLE ); @@ -143,39 +154,47 @@ public class NarLayout21 } else { - // look for type in aol/<aol-type>/lib/<aol>/<type> - File libDir = new File( dir, "lib" ); - aolDir = libDir.list(); - if ( ( aolDir != null ) && aolDir.length > 0 ) - { - aol = new AOL(aolDir[0]); - String[] typeDir = new File( libDir, aol.toString() ).list(); - if ( ( typeDir != null ) && ( typeDir.length > 0 ) ) - { - type = typeDir[0]; - } - } - - assert(aol != null); - assert(type != null); - // and not set or override if SHARED - if (( narInfo.getBinding( aol, null ) == null ) || type.equals( Library.SHARED ) ) + if ( ( narInfo.getBinding( aol, null ) == null ) || type.equals( Library.SHARED ) ) { narInfo.setBinding( aol, type ); } // and not set or override if SHARED - if (( narInfo.getBinding( null, null ) == null ) || type.equals( Library.SHARED ) ) + if ( ( narInfo.getBinding( null, null ) == null ) || type.equals( Library.SHARED ) ) { narInfo.setBinding( null, type ); } } - - assert(type != null); + narInfo.setNar( null, type, project.getGroupId() + ":" + project.getArtifactId() + ":" - + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + type ); + + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + type ); + } + } + + public void unpackNar( ArchiverManager archiverManager, File file, String os, String linkerName, AOL defaultAOL ) + throws MojoExecutionException, MojoFailureException + { + File narLocation = new File( file.getParentFile(), "nar" ); + File dir = new File( narLocation, FileUtils.basename( file.getPath(), "." + NarConstants.NAR_EXTENSION ) ); + boolean process = false; + if ( !narLocation.exists() ) + { + narLocation.mkdirs(); + process = true; + } + else if ( !dir.exists() ) + { + process = true; + } + else if ( file.lastModified() > dir.lastModified() ) + { + process = true; } + if ( process ) + { + unpackNarAndProcess( archiverManager, file, dir, os, linkerName, defaultAOL ); + } } -} +}
\ No newline at end of file |