From 04bf49625242b9eabf0f1342050cabff019ae225 Mon Sep 17 00:00:00 2001 From: Volker Schumacher Date: Wed, 6 Jan 2010 23:25:29 +0800 Subject: resolve dependencies from unpack dir instead of local repository. --- .../apache/maven/plugin/nar/NarAssemblyMojo.java | 10 ++-- .../org/apache/maven/plugin/nar/NarLayout.java | 6 +++ .../org/apache/maven/plugin/nar/NarLayout21.java | 10 +++- .../org/apache/maven/plugin/nar/NarManager.java | 56 ++++++++++++---------- 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/apache/maven/plugin/nar/NarAssemblyMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarAssemblyMojo.java index e5dd1dc..0efe342 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarAssemblyMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarAssemblyMojo.java @@ -74,9 +74,13 @@ public class NarAssemblyMojo // of getBaseVersion, called in pathOf. dependency.isSnapshot(); - File srcDir = new File( getLocalRepository().pathOf( dependency ) ); - srcDir = new File( getLocalRepository().getBasedir(), srcDir.getParent() ); - srcDir = new File( srcDir, "nar/" ); + File srcDir = getLayout().getNarUnpackDirectory( + getUnpackDirectory(), + getNarManager().getNarFile( dependency )); +// File srcDir = new File( getLocalRepository().pathOf( dependency ) ); +// srcDir = new File( getLocalRepository().getBasedir(), srcDir.getParent() ); +// srcDir = new File( srcDir, "nar/" ); + File dstDir = getTargetDirectory(); try { 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 6e12eaa..d986ec2 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarLayout.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarLayout.java @@ -82,4 +82,10 @@ public interface NarLayout */ void unpackNar( File baseDir, ArchiverManager archiverManager, File file, String os, String linkerName, AOL defaultAOL ) throws MojoExecutionException, MojoFailureException; + + /** + * Returns the unpack directory of a specific nar file. + */ + File getNarUnpackDirectory(File baseUnpackDirectory, File narFile); + } 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 8e70641..6d8433b 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarLayout21.java @@ -178,7 +178,7 @@ public class NarLayout21 AOL defaultAOL ) throws MojoExecutionException, MojoFailureException { - File dir = new File( unpackDirectory, FileUtils.basename( file.getPath(), "." + NarConstants.NAR_EXTENSION ) ); + File dir = getNarUnpackDirectory(unpackDirectory, file); boolean process = false; @@ -210,4 +210,12 @@ public class NarLayout21 unpackNarAndProcess( archiverManager, file, dir, os, linkerName, defaultAOL ); } } + + public File getNarUnpackDirectory(File baseUnpackDirectory, File narFile) + { + File dir = new File( + baseUnpackDirectory, + FileUtils.basename( narFile.getPath(), "." + NarConstants.NAR_EXTENSION )); + return dir; + } } \ No newline at end of file diff --git a/src/main/java/org/apache/maven/plugin/nar/NarManager.java b/src/main/java/org/apache/maven/plugin/nar/NarManager.java index 32f5e65..7181a35 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarManager.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarManager.java @@ -174,12 +174,15 @@ public class NarManager for ( Iterator i = narArtifacts.iterator(); i.hasNext(); ) { Artifact dependency = (Artifact) i.next(); - + NarInfo narInfo = getNarInfo( dependency ); if ( noarch ) { artifactList.addAll( getAttachedNarDependencies( dependency, null, NarConstants.NAR_NO_ARCH ) ); } + // use preferred binding, unless non existing. + String binding = narInfo.getBinding( aol, type != null ? type : Library.STATIC ); + // FIXME kludge, but does not work anymore since AOL is now a class if ( aol.equals( NarConstants.NAR_NO_ARCH ) ) { @@ -188,17 +191,7 @@ public class NarManager } else { - if ( type != null ) - { - artifactList.addAll( getAttachedNarDependencies( dependency, aol, type ) ); - } - else - { - for ( int j = 0; j < narTypes.length; j++ ) - { - artifactList.addAll( getAttachedNarDependencies( dependency, aol, narTypes[j] )); - } - } + artifactList.addAll( getAttachedNarDependencies( dependency, aol, binding ) ); } } return artifactList; @@ -239,9 +232,8 @@ public class NarManager classifier = NarUtil.replace( "${aol}", aol.toString(), classifier ); } String version = nar.length >= 5 ? nar[4].trim() : dependency.getVersion(); - File file = dependency.getFile(); artifactList.add( new AttachedNarArtifact( groupId, artifactId, version, dependency.getScope(), - ext, classifier, dependency.isOptional(), file ) ); + ext, classifier, dependency.isOptional() ) ); } catch ( InvalidVersionSpecificationException e ) { @@ -266,18 +258,23 @@ public class NarManager // of getBaseVersion, called in pathOf. dependency.isSnapshot(); - File file = dependency.getFile(); - JarFile nar = null; + File file = new File( repository.getBasedir(), repository.pathOf( dependency ) ); + if ( !file.exists() ) + { + return null; + } + + JarFile jar = null; try { - nar = new JarFile( file ); + jar = new JarFile( file ); NarInfo info = new NarInfo( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), log ); - if ( !info.exists( nar ) ) + if ( !info.exists( jar ) ) { return null; } - info.read( nar ); + info.read( jar ); return info; } catch ( IOException e ) @@ -286,11 +283,11 @@ public class NarManager } finally { - if ( nar != null ) + if ( jar != null ) { try { - nar.close(); + jar.close(); } catch ( IOException e ) { @@ -300,6 +297,16 @@ public class NarManager } } + public final File getNarFile( Artifact dependency ) + throws MojoFailureException + { + // FIXME reported to maven developer list, isSnapshot changes behaviour + // of getBaseVersion, called in pathOf. + dependency.isSnapshot(); + return new File( repository.getBasedir(), NarUtil.replace( "${aol}", defaultAOL.toString(), + repository.pathOf( dependency ) ) ); + } + private List getDependencies( String scope ) { if ( scope.equals( Artifact.SCOPE_TEST ) ) @@ -331,10 +338,6 @@ public class NarManager for ( Iterator i = dependencies.iterator(); i.hasNext(); ) { Artifact dependency = (Artifact) i.next(); - File file = dependency.getFile(); - if ( file != null && file.exists() ) - continue; - try { log.debug( "Resolving " + dependency ); @@ -369,8 +372,9 @@ public class NarManager { Artifact dependency = (Artifact) i.next(); log.debug( "Unpack " + dependency ); + File file = getNarFile( dependency ); - layout.unpackNar( unpackDir, archiverManager, dependency.getFile(), os, linkerName, defaultAOL ); + layout.unpackNar(unpackDir, archiverManager, file, os, linkerName, defaultAOL); } } } -- cgit v1.2.3