Loading src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java +25 −9 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class AmpMojo extends AbstractMojo { this.normalize(); File ampFile = this.getOutputFile(); if (this.getLog().isDebugEnabled()) this.getLog().debug("Writing AMP file: " + ampFile.getAbsolutePath()); try { Loading @@ -107,18 +108,23 @@ public class AmpMojo extends AbstractMojo { ZipOutputStream zstream = new ZipOutputStream(bostream, Charset.forName(this.charsetName)); try { this.zip(zstream); zstream.finish(); } finally { zstream.finish(); zstream.close(); } if (this.getLog().isDebugEnabled()) this.getLog().debug("Wrote AMP file: " + ampFile.length()); } catch (IllegalStateException ise) { this.getLog().warn(ise.getMessage()); ampFile.delete(); if (this.getLog().isDebugEnabled()) this.getLog().debug("Deleted AMP: " + ampFile.getAbsolutePath()); } catch (DependencyResolutionException dre) { throw new MojoExecutionException("The dependencies could not be properly resolved", dre); } catch (IOException ie) { throw new MojoExecutionException("An I/O issue occurred", ie); } this.getLog().debug("Wrote AMP file: " + ampFile.length()); } private void normalize() { Loading Loading @@ -188,6 +194,8 @@ public class AmpMojo extends AbstractMojo { File propFile = this.getModulePropertyFile(); this.zipFile(zstream, propFile, ""); int libcount = 0; Collection<Dependency> deps = this.getDependencies(); if (deps.isEmpty()) { this.getLog().info("Zipped 0 dependencies"); Loading @@ -195,17 +203,23 @@ public class AmpMojo extends AbstractMojo { for (Dependency dependency : deps) { File file = dependency.getArtifact().getFile(); if (this.isAlfrescoModule(file)) { if (this.getLog().isInfoEnabled()) this.getLog().info("Not packaging JAR; detected as Alfresco JAR Module: " + dependency.getArtifact().getArtifactId()); } else { this.zipFile(zstream, file, "lib"); libcount++; } } if (this.getLog().isInfoEnabled()) this.getLog().info("Zipped " + deps.size() + " dependencies"); } for (FileSet fileset : this.libDirectories) this.zipFileset(zstream, fileset, "lib"); libcount += this.zipFileset(zstream, fileset, "lib"); if (libcount == 0) throw new IllegalStateException("There are no external libraries to include, making an AMP pointless"); } private List<String> getExclusions() { Loading Loading @@ -237,14 +251,14 @@ public class AmpMojo extends AbstractMojo { this.zipFileset(zstream, resource, baseZipPath); } private void zipFileset(ZipOutputStream zstream, FileSet fileset, String targetPath) throws MojoExecutionException, IOException { private int zipFileset(ZipOutputStream zstream, FileSet fileset, String targetPath) throws MojoExecutionException, IOException { targetPath = StringUtils.trimToEmpty(targetPath); if (targetPath.length() > 0 && !targetPath.endsWith("/")) targetPath += "/"; File directory = new File(this.project.getBasedir(), fileset.getDirectory()); if (!directory.exists()) return; return 0; if (!directory.isDirectory()) throw new MojoExecutionException("The fileset 'directory' must be a directory: " + fileset.getDirectory()); Loading Loading @@ -273,6 +287,8 @@ public class AmpMojo extends AbstractMojo { if (this.getLog().isInfoEnabled()) this.getLog().info("Zipped " + filenames.size() + " files: " + fileset.getDirectory()); return filenames.size(); } private void zipFile(ZipOutputStream zstream, File file, String targetPath) throws IOException { Loading Loading
src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java +25 −9 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class AmpMojo extends AbstractMojo { this.normalize(); File ampFile = this.getOutputFile(); if (this.getLog().isDebugEnabled()) this.getLog().debug("Writing AMP file: " + ampFile.getAbsolutePath()); try { Loading @@ -107,18 +108,23 @@ public class AmpMojo extends AbstractMojo { ZipOutputStream zstream = new ZipOutputStream(bostream, Charset.forName(this.charsetName)); try { this.zip(zstream); zstream.finish(); } finally { zstream.finish(); zstream.close(); } if (this.getLog().isDebugEnabled()) this.getLog().debug("Wrote AMP file: " + ampFile.length()); } catch (IllegalStateException ise) { this.getLog().warn(ise.getMessage()); ampFile.delete(); if (this.getLog().isDebugEnabled()) this.getLog().debug("Deleted AMP: " + ampFile.getAbsolutePath()); } catch (DependencyResolutionException dre) { throw new MojoExecutionException("The dependencies could not be properly resolved", dre); } catch (IOException ie) { throw new MojoExecutionException("An I/O issue occurred", ie); } this.getLog().debug("Wrote AMP file: " + ampFile.length()); } private void normalize() { Loading Loading @@ -188,6 +194,8 @@ public class AmpMojo extends AbstractMojo { File propFile = this.getModulePropertyFile(); this.zipFile(zstream, propFile, ""); int libcount = 0; Collection<Dependency> deps = this.getDependencies(); if (deps.isEmpty()) { this.getLog().info("Zipped 0 dependencies"); Loading @@ -195,17 +203,23 @@ public class AmpMojo extends AbstractMojo { for (Dependency dependency : deps) { File file = dependency.getArtifact().getFile(); if (this.isAlfrescoModule(file)) { if (this.getLog().isInfoEnabled()) this.getLog().info("Not packaging JAR; detected as Alfresco JAR Module: " + dependency.getArtifact().getArtifactId()); } else { this.zipFile(zstream, file, "lib"); libcount++; } } if (this.getLog().isInfoEnabled()) this.getLog().info("Zipped " + deps.size() + " dependencies"); } for (FileSet fileset : this.libDirectories) this.zipFileset(zstream, fileset, "lib"); libcount += this.zipFileset(zstream, fileset, "lib"); if (libcount == 0) throw new IllegalStateException("There are no external libraries to include, making an AMP pointless"); } private List<String> getExclusions() { Loading Loading @@ -237,14 +251,14 @@ public class AmpMojo extends AbstractMojo { this.zipFileset(zstream, resource, baseZipPath); } private void zipFileset(ZipOutputStream zstream, FileSet fileset, String targetPath) throws MojoExecutionException, IOException { private int zipFileset(ZipOutputStream zstream, FileSet fileset, String targetPath) throws MojoExecutionException, IOException { targetPath = StringUtils.trimToEmpty(targetPath); if (targetPath.length() > 0 && !targetPath.endsWith("/")) targetPath += "/"; File directory = new File(this.project.getBasedir(), fileset.getDirectory()); if (!directory.exists()) return; return 0; if (!directory.isDirectory()) throw new MojoExecutionException("The fileset 'directory' must be a directory: " + fileset.getDirectory()); Loading Loading @@ -273,6 +287,8 @@ public class AmpMojo extends AbstractMojo { if (this.getLog().isInfoEnabled()) this.getLog().info("Zipped " + filenames.size() + " files: " + fileset.getDirectory()); return filenames.size(); } private void zipFile(ZipOutputStream zstream, File file, String targetPath) throws IOException { Loading