summaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/maven/plugin/nar/NarManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/apache/maven/plugin/nar/NarManager.java')
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarManager.java322
1 files changed, 161 insertions, 161 deletions
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 5cbcd10..fd77645 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarManager.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarManager.java
@@ -47,15 +47,15 @@ import org.codehaus.plexus.archiver.manager.ArchiverManager;
public class NarManager
{
- private Log log;
+ private Log log;
- private MavenProject project;
+ private MavenProject project;
- private ArtifactRepository repository;
+ private ArtifactRepository repository;
- private AOL defaultAOL;
+ private AOL defaultAOL;
- private String linkerName;
+ private String linkerName;
private String[] narTypes =
{ NarConstants.NAR_NO_ARCH, Library.STATIC, Library.SHARED, Library.JNI, Library.PLUGIN };
@@ -64,99 +64,99 @@ public class NarManager
Linker linker )
throws MojoFailureException, MojoExecutionException
{
- this.log = log;
- this.repository = repository;
- this.project = project;
- this.defaultAOL = NarUtil.getAOL( architecture, os, linker, null );
- this.linkerName = NarUtil.getLinkerName( architecture, os, linker );
- }
-
- /**
+ this.log = log;
+ this.repository = repository;
+ this.project = project;
+ this.defaultAOL = NarUtil.getAOL(architecture, os, linker, null);
+ this.linkerName = NarUtil.getLinkerName(architecture, os, linker);
+ }
+
+ /**
* Returns dependencies which are dependent on NAR files (i.e. contain NarInfo)
- */
- public final List/* <NarArtifact> */getNarDependencies( String scope )
+ */
+ public final List/* <NarArtifact> */getNarDependencies(String scope)
throws MojoExecutionException
{
- List narDependencies = new LinkedList();
+ List narDependencies = new LinkedList();
for ( Iterator i = getDependencies( scope ).iterator(); i.hasNext(); )
{
- Artifact dependency = (Artifact) i.next();
- log.debug( "Examining artifact for NarInfo: " + dependency );
+ Artifact dependency = (Artifact) i.next();
+ log.debug("Examining artifact for NarInfo: " + dependency);
- NarInfo narInfo = getNarInfo( dependency );
+ NarInfo narInfo = getNarInfo(dependency);
if ( narInfo != null )
{
- log.debug( " - added as NarDependency" );
- narDependencies.add( new NarArtifact( dependency, narInfo ) );
- }
- }
- return narDependencies;
- }
-
- /**
+ log.debug(" - added as NarDependency");
+ narDependencies.add(new NarArtifact(dependency, narInfo));
+ }
+ }
+ return narDependencies;
+ }
+
+ /**
* Returns all NAR dependencies by type: noarch, static, dynamic, jni, plugin.
- *
- * @throws MojoFailureException
- */
+ *
+ * @throws MojoFailureException
+ */
public final Map/* <String, List<AttachedNarArtifact>> */getAttachedNarDependencyMap( String scope )
throws MojoExecutionException, MojoFailureException
{
- Map attachedNarDependencies = new HashMap();
+ Map attachedNarDependencies = new HashMap();
for ( Iterator i = getNarDependencies( scope ).iterator(); i.hasNext(); )
{
- Artifact dependency = (Artifact) i.next();
+ Artifact dependency = (Artifact) i.next();
for ( int j = 0; j < narTypes.length; j++ )
{
List artifactList = getAttachedNarDependencies( dependency, defaultAOL, narTypes[j] );
if ( artifactList != null )
{
- attachedNarDependencies.put( narTypes[j], artifactList );
- }
- }
- }
- return attachedNarDependencies;
- }
+ attachedNarDependencies.put(narTypes[j], artifactList);
+ }
+ }
+ }
+ return attachedNarDependencies;
+ }
public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( List/* <NarArtifacts> */narArtifacts )
throws MojoExecutionException, MojoFailureException
{
- return getAttachedNarDependencies( narArtifacts, ( String )null );
- }
+ return getAttachedNarDependencies(narArtifacts, (String) null);
+ }
public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( List/* <NarArtifacts> */narArtifacts,
String classifier )
throws MojoExecutionException, MojoFailureException
{
- AOL aol = null;
- String type = null;
+ AOL aol = null;
+ String type = null;
if ( classifier != null )
{
- int dash = classifier.lastIndexOf( '-' );
+ int dash = classifier.lastIndexOf('-');
if ( dash < 0 )
{
- aol = new AOL( classifier );
- type = null;
+ aol = new AOL(classifier);
+ type = null;
}
else
{
- aol = new AOL( classifier.substring( 0, dash ) );
- type = classifier.substring( dash + 1 );
- }
- }
- return getAttachedNarDependencies( narArtifacts, aol, type );
- }
-
- public final List/* <AttachedNarArtifact> */getAttachedNarDependencies(
- List/* <NarArtifacts> */narArtifacts, List classifiers)
+ aol = new AOL(classifier.substring(0, dash));
+ type = classifier.substring(dash + 1);
+ }
+ }
+ return getAttachedNarDependencies(narArtifacts, aol, type);
+ }
+
+ public final List/* <AttachedNarArtifact> */getAttachedNarDependencies(
+ List/* <NarArtifacts> */narArtifacts, List classifiers)
throws MojoExecutionException, MojoFailureException
{
- String[] types;
-
- List artifactList = new ArrayList();
+ String[] types;
+
+ List artifactList = new ArrayList();
if( classifiers != null && !classifiers.isEmpty() )
{
- types = (String[]) classifiers.toArray();
+ types = (String[]) classifiers.toArray();
for ( int j = 0; j < types.length; j++ )
{
@@ -169,92 +169,92 @@ public class NarManager
else
{
artifactList.addAll( getAttachedNarDependencies( narArtifacts, ( String )null ));
- }
+ }
- return artifactList;
- }
+ return artifactList;
+ }
- /**
+ /**
* Returns a list of all attached nar dependencies for a specific binding and "noarch", but not where "local" is
* specified
- *
+ *
* @param scope compile, test, runtime, ....
* @param aol either a valid aol, noarch or null. In case of null both the default getAOL() and noarch dependencies
* are returned.
* @param type noarch, static, shared, jni, or null. In case of null the default binding found in narInfo is used.
- * @return
- * @throws MojoExecutionException
- * @throws MojoFailureException
- */
+ * @return
+ * @throws MojoExecutionException
+ * @throws MojoFailureException
+ */
public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( List/* <NarArtifacts> */narArtifacts,
AOL archOsLinker, String type )
throws MojoExecutionException, MojoFailureException
{
- boolean noarch = false;
- AOL aol = archOsLinker;
+ boolean noarch = false;
+ AOL aol = archOsLinker;
if ( aol == null )
{
- noarch = true;
- aol = defaultAOL;
- }
+ noarch = true;
+ aol = defaultAOL;
+ }
- List artifactList = new ArrayList();
+ List artifactList = new ArrayList();
for ( Iterator i = narArtifacts.iterator(); i.hasNext(); )
{
- Artifact dependency = (Artifact) i.next();
- NarInfo narInfo = getNarInfo( dependency );
+ 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.
+ // 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
+ // FIXME kludge, but does not work anymore since AOL is now a class
if ( aol.equals( NarConstants.NAR_NO_ARCH ) )
{
- // FIXME no handling of local
+ // FIXME no handling of local
artifactList.addAll( getAttachedNarDependencies( dependency, null, NarConstants.NAR_NO_ARCH ) );
}
else
{
artifactList.addAll( getAttachedNarDependencies( dependency, aol, binding ) );
- }
- }
- return artifactList;
- }
+ }
+ }
+ return artifactList;
+ }
private List/* <AttachedNarArtifact> */getAttachedNarDependencies( Artifact dependency, AOL archOsLinker,
String type )
throws MojoExecutionException, MojoFailureException
{
- AOL aol = archOsLinker;
+ AOL aol = archOsLinker;
log.debug( "GetNarDependencies for " + dependency + ", aol: " + aol + ", type: " + type );
- List artifactList = new ArrayList();
- NarInfo narInfo = getNarInfo( dependency );
- String[] nars = narInfo.getAttachedNars( aol, type );
- // FIXME Move this to NarInfo....
+ List artifactList = new ArrayList();
+ NarInfo narInfo = getNarInfo(dependency);
+ String[] nars = narInfo.getAttachedNars(aol, type);
+ // FIXME Move this to NarInfo....
if ( nars != null )
{
for ( int j = 0; j < nars.length; j++ )
{
- log.debug( " Checking: " + nars[j] );
+ log.debug(" Checking: " + nars[j]);
if ( nars[j].equals( "" ) )
{
- continue;
- }
- String[] nar = nars[j].split( ":", 5 );
+ continue;
+ }
+ String[] nar = nars[j].split(":", 5);
if ( nar.length >= 4 )
{
try
{
- String groupId = nar[0].trim();
- String artifactId = nar[1].trim();
- String ext = nar[2].trim();
- String classifier = nar[3].trim();
- // translate for instance g++ to gcc...
- aol = narInfo.getAOL( aol );
+ String groupId = nar[0].trim();
+ String artifactId = nar[1].trim();
+ String ext = nar[2].trim();
+ String classifier = nar[3].trim();
+ // translate for instance g++ to gcc...
+ aol = narInfo.getAOL(aol);
if ( aol != null )
{
classifier = NarUtil.replace( "${aol}", aol.toString(), classifier );
@@ -272,42 +272,42 @@ public class NarManager
else
{
log.warn( "nars property in " + dependency.getArtifactId() + " contains invalid field: '" + nars[j]
- + "' for type: " + type );
- }
- }
- }
- return artifactList;
- }
-
- public final NarInfo getNarInfo( Artifact dependency )
+ + "' for type: " + type);
+ }
+ }
+ }
+ return artifactList;
+ }
+
+ public final NarInfo getNarInfo(Artifact dependency)
throws MojoExecutionException
{
- // FIXME reported to maven developer list, isSnapshot changes behaviour
- // of getBaseVersion, called in pathOf.
- dependency.isSnapshot();
+ // FIXME reported to maven developer list, isSnapshot changes behaviour
+ // of getBaseVersion, called in pathOf.
+ dependency.isSnapshot();
File file = new File( repository.getBasedir(), repository.pathOf( dependency ) );
if ( !file.exists() )
{
- return null;
- }
+ return null;
+ }
- JarFile jar = null;
+ JarFile jar = null;
try
{
- jar = new JarFile( file );
+ jar = new JarFile(file);
NarInfo info =
new NarInfo( dependency.getGroupId(), dependency.getArtifactId(), dependency.getBaseVersion(), log );
if ( !info.exists( jar ) )
{
- return null;
- }
- info.read( jar );
- return info;
+ return null;
+ }
+ info.read(jar);
+ return info;
}
catch ( IOException e )
{
- throw new MojoExecutionException( "Error while reading " + file, e );
+ throw new MojoExecutionException("Error while reading " + file, e);
}
finally
{
@@ -315,74 +315,74 @@ public class NarManager
{
try
{
- jar.close();
+ jar.close();
}
catch ( IOException e )
{
- // ignore
- }
- }
- }
- }
+ // ignore
+ }
+ }
+ }
+ }
- public final File getNarFile( Artifact dependency )
+ public final File getNarFile(Artifact dependency)
throws MojoFailureException
{
- // FIXME reported to maven developer list, isSnapshot changes behaviour
- // of getBaseVersion, called in pathOf.
- dependency.isSnapshot();
+ // 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 ) )
{
- return project.getTestArtifacts();
+ return project.getTestArtifacts();
}
else if ( scope.equals( Artifact.SCOPE_RUNTIME ) )
{
- return project.getRuntimeArtifacts();
- }
- return project.getCompileArtifacts();
- }
+ return project.getRuntimeArtifacts();
+ }
+ return project.getCompileArtifacts();
+ }
public final void downloadAttachedNars( List/* <NarArtifacts> */narArtifacts, List remoteRepositories,
- ArtifactResolver resolver, String classifier )
+ ArtifactResolver resolver, String classifier)
throws MojoExecutionException, MojoFailureException
{
- // FIXME this may not be the right way to do this.... -U ignored and
- // also SNAPSHOT not used
- List dependencies = getAttachedNarDependencies( narArtifacts, classifier );
+ // FIXME this may not be the right way to do this.... -U ignored and
+ // also SNAPSHOT not used
+ List dependencies = getAttachedNarDependencies(narArtifacts, classifier);
log.debug( "Download called with classifier: " + classifier + " for NarDependencies {" );
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
- log.debug( " - " + ( i.next() ) );
- }
- log.debug( "}" );
+ log.debug(" - " + (i.next()));
+ }
+ log.debug("}");
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
- Artifact dependency = (Artifact) i.next();
+ Artifact dependency = (Artifact) i.next();
try
{
- log.debug( "Resolving " + dependency );
- resolver.resolve( dependency, remoteRepositories, repository );
+ log.debug("Resolving " + dependency);
+ resolver.resolve(dependency, remoteRepositories, repository);
}
catch ( ArtifactNotFoundException e )
{
- String message = "nar not found " + dependency.getId();
- throw new MojoExecutionException( message, e );
+ String message = "nar not found " + dependency.getId();
+ throw new MojoExecutionException(message, e);
}
catch ( ArtifactResolutionException e )
{
- String message = "nar cannot resolve " + dependency.getId();
- throw new MojoExecutionException( message, e );
- }
- }
- }
+ String message = "nar cannot resolve " + dependency.getId();
+ throw new MojoExecutionException(message, e);
+ }
+ }
+ }
public final void unpackAttachedNars( List/* <NarArtifacts> */narArtifacts, ArchiverManager archiverManager,
String classifier, String os, NarLayout layout, File unpackDir )
@@ -391,18 +391,18 @@ public class NarManager
log.debug( "Unpack called for OS: " + os + ", classifier: " + classifier + " for NarArtifacts {" );
for ( Iterator i = narArtifacts.iterator(); i.hasNext(); )
{
- log.debug( " - " + ( i.next() ) );
- }
- log.debug( "}" );
- // FIXME, kludge to get to download the -noarch, based on classifier
- List dependencies = getAttachedNarDependencies( narArtifacts, classifier );
+ log.debug(" - " + (i.next()));
+ }
+ log.debug("}");
+ // FIXME, kludge to get to download the -noarch, based on classifier
+ List dependencies = getAttachedNarDependencies(narArtifacts, classifier);
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
- Artifact dependency = (Artifact) i.next();
- log.debug( "Unpack " + dependency );
- File file = getNarFile( dependency );
+ Artifact dependency = (Artifact) i.next();
+ log.debug("Unpack " + dependency + " to " + unpackDir);
+ File file = getNarFile(dependency);
layout.unpackNar(unpackDir, archiverManager, file, os, linkerName, defaultAOL);
- }
- }
+ }
+ }
}