diff options
author | Mark Donszelmann <Mark.Donszelmann@gmail.com> | 2009-10-06 14:44:29 +0200 |
---|---|---|
committer | Mark Donszelmann <Mark.Donszelmann@gmail.com> | 2009-10-06 14:44:29 +0200 |
commit | 3dca89f0015613ab3f287945965e9f92a6079cd8 (patch) | |
tree | a00619a63c55b74c16ac8116d04b21f322e1747b /src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java | |
parent | 75b9fcffc6709f9c65990f6d04d593d3bfb4743d (diff) | |
download | maven-nar-plugin-3dca89f0015613ab3f287945965e9f92a6079cd8.tar.gz maven-nar-plugin-3dca89f0015613ab3f287945965e9f92a6079cd8.tar.bz2 maven-nar-plugin-3dca89f0015613ab3f287945965e9f92a6079cd8.tar.xz maven-nar-plugin-3dca89f0015613ab3f287945965e9f92a6079cd8.zip |
Reformat all source files and add licenses to tests
Diffstat (limited to 'src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java')
-rw-r--r-- | src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java | 240 |
1 files changed, 130 insertions, 110 deletions
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 6376769..a42eca1 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarPackageMojo.java @@ -38,115 +38,135 @@ import org.codehaus.plexus.archiver.zip.ZipArchiver; * @requiresProject * @author Mark Donszelmann */ -public class NarPackageMojo extends AbstractCompileMojo { - - /** - * Used for attaching the artifact in the project - * - * @component - */ - private MavenProjectHelper projectHelper; - - private File narDirectory; - - public void execute() throws MojoExecutionException, MojoFailureException { - if (shouldSkip()) - return; - - // FIX for NARPLUGIN-??? where -DupdateReleaseInfo copies to a .nar file - getMavenProject().getArtifact().setArtifactHandler( - new NarArtifactHandler()); - - narDirectory = new File(getOutputDirectory(), "nar"); - - // noarch - String include = "include"; - if (new File(narDirectory, include).exists()) { - attachNar("include", null, NAR_NO_ARCH); - } - - // create nar with binaries - String bin = "bin"; - String[] binAOLs = new File(narDirectory, bin).list(); - for (int i = 0; i < (binAOLs != null ? binAOLs.length : 0); i++) { - attachNar(bin + "/" + binAOLs[i], binAOLs[i], bin); - } - - // 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 - String lib = "lib"; - String[] libAOLs = new File(narDirectory, lib).list(); - for (int j = 0; j < (libAOLs != null ? libAOLs.length : 0); j++) { - attachNar(lib + "/" + libAOLs[j] + "/" + type, libAOLs[j], type); - } - } - - // override binding if not set - if (getNarInfo().getBinding(null, null) == null) { - getNarInfo().setBinding(null, bindingType != null ? bindingType - : Library.NONE); - } - - try { - File propertiesDir = new File(getOutputDirectory(), "classes/META-INF/nar/" - + getMavenProject().getGroupId() + "/" + getMavenProject().getArtifactId()); - if (!propertiesDir.exists()) { - propertiesDir.mkdirs(); - } - File propertiesFile = new File(propertiesDir, NarInfo.NAR_PROPERTIES); - getNarInfo().writeToFile(propertiesFile); - } catch (IOException ioe) { - throw new MojoExecutionException( - "Cannot write nar properties file", ioe); - } - } - - private void attachNar(String dir, String aol, String type) - throws MojoExecutionException { - File libFile = new File(getOutputDirectory(), getFinalName() + "-" - + (aol != null ? aol + "-" : "") + type + "." + NAR_EXTENSION); - nar(libFile, narDirectory, 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, 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); - } - } +public class NarPackageMojo + extends AbstractCompileMojo +{ + + /** + * Used for attaching the artifact in the project + * + * @component + */ + private MavenProjectHelper projectHelper; + + private File narDirectory; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( shouldSkip() ) + return; + + // FIX for NARPLUGIN-??? where -DupdateReleaseInfo copies to a .nar file + getMavenProject().getArtifact().setArtifactHandler( new NarArtifactHandler() ); + + narDirectory = new File( getOutputDirectory(), "nar" ); + + // noarch + String include = "include"; + if ( new File( narDirectory, include ).exists() ) + { + attachNar( "include", null, NAR_NO_ARCH ); + } + + // create nar with binaries + String bin = "bin"; + String[] binAOLs = new File( narDirectory, bin ).list(); + for ( int i = 0; i < ( binAOLs != null ? binAOLs.length : 0 ); i++ ) + { + attachNar( bin + "/" + binAOLs[i], binAOLs[i], bin ); + } + + // 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 + String lib = "lib"; + String[] libAOLs = new File( narDirectory, lib ).list(); + for ( int j = 0; j < ( libAOLs != null ? libAOLs.length : 0 ); j++ ) + { + attachNar( lib + "/" + libAOLs[j] + "/" + type, libAOLs[j], type ); + } + } + + // override binding if not set + if ( getNarInfo().getBinding( null, null ) == null ) + { + getNarInfo().setBinding( null, bindingType != null ? bindingType : Library.NONE ); + } + + try + { + File propertiesDir = + new File( getOutputDirectory(), "classes/META-INF/nar/" + getMavenProject().getGroupId() + "/" + + getMavenProject().getArtifactId() ); + if ( !propertiesDir.exists() ) + { + propertiesDir.mkdirs(); + } + File propertiesFile = new File( propertiesDir, NarInfo.NAR_PROPERTIES ); + getNarInfo().writeToFile( propertiesFile ); + } + catch ( IOException ioe ) + { + throw new MojoExecutionException( "Cannot write nar properties file", ioe ); + } + } + + private void attachNar( String dir, String aol, String type ) + throws MojoExecutionException + { + File libFile = + new File( getOutputDirectory(), getFinalName() + "-" + ( aol != null ? aol + "-" : "" ) + type + "." + + NAR_EXTENSION ); + nar( libFile, narDirectory, 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, 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 ); + } + } } |