removing AMP if no external libs
This commit is contained in:
@@ -99,7 +99,8 @@ public class AmpMojo extends AbstractMojo {
|
|||||||
this.normalize();
|
this.normalize();
|
||||||
|
|
||||||
File ampFile = this.getOutputFile();
|
File ampFile = this.getOutputFile();
|
||||||
this.getLog().debug("Writing AMP file: " + ampFile.getAbsolutePath());
|
if (this.getLog().isDebugEnabled())
|
||||||
|
this.getLog().debug("Writing AMP file: " + ampFile.getAbsolutePath());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileOutputStream fostream = new FileOutputStream(ampFile, false);
|
FileOutputStream fostream = new FileOutputStream(ampFile, false);
|
||||||
@@ -107,18 +108,23 @@ public class AmpMojo extends AbstractMojo {
|
|||||||
ZipOutputStream zstream = new ZipOutputStream(bostream, Charset.forName(this.charsetName));
|
ZipOutputStream zstream = new ZipOutputStream(bostream, Charset.forName(this.charsetName));
|
||||||
try {
|
try {
|
||||||
this.zip(zstream);
|
this.zip(zstream);
|
||||||
|
|
||||||
zstream.finish();
|
|
||||||
} finally {
|
} finally {
|
||||||
|
zstream.finish();
|
||||||
zstream.close();
|
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) {
|
} catch (DependencyResolutionException dre) {
|
||||||
throw new MojoExecutionException("The dependencies could not be properly resolved", dre);
|
throw new MojoExecutionException("The dependencies could not be properly resolved", dre);
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
throw new MojoExecutionException("An I/O issue occurred", ie);
|
throw new MojoExecutionException("An I/O issue occurred", ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getLog().debug("Wrote AMP file: " + ampFile.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void normalize() {
|
private void normalize() {
|
||||||
@@ -187,6 +193,8 @@ public class AmpMojo extends AbstractMojo {
|
|||||||
|
|
||||||
File propFile = this.getModulePropertyFile();
|
File propFile = this.getModulePropertyFile();
|
||||||
this.zipFile(zstream, propFile, "");
|
this.zipFile(zstream, propFile, "");
|
||||||
|
|
||||||
|
int libcount = 0;
|
||||||
|
|
||||||
Collection<Dependency> deps = this.getDependencies();
|
Collection<Dependency> deps = this.getDependencies();
|
||||||
if (deps.isEmpty()) {
|
if (deps.isEmpty()) {
|
||||||
@@ -195,17 +203,23 @@ public class AmpMojo extends AbstractMojo {
|
|||||||
for (Dependency dependency : deps) {
|
for (Dependency dependency : deps) {
|
||||||
File file = dependency.getArtifact().getFile();
|
File file = dependency.getArtifact().getFile();
|
||||||
if (this.isAlfrescoModule(file)) {
|
if (this.isAlfrescoModule(file)) {
|
||||||
this.getLog().info("Not packaging JAR; detected as Alfresco JAR Module: " + dependency.getArtifact().getArtifactId());
|
if (this.getLog().isInfoEnabled())
|
||||||
|
this.getLog().info("Not packaging JAR; detected as Alfresco JAR Module: " + dependency.getArtifact().getArtifactId());
|
||||||
} else {
|
} else {
|
||||||
this.zipFile(zstream, file, "lib");
|
this.zipFile(zstream, file, "lib");
|
||||||
|
libcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getLog().isInfoEnabled())
|
if (this.getLog().isInfoEnabled())
|
||||||
this.getLog().info("Zipped " + deps.size() + " dependencies");
|
this.getLog().info("Zipped " + deps.size() + " dependencies");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FileSet fileset : this.libDirectories)
|
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() {
|
private List<String> getExclusions() {
|
||||||
@@ -237,14 +251,14 @@ public class AmpMojo extends AbstractMojo {
|
|||||||
this.zipFileset(zstream, resource, baseZipPath);
|
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);
|
targetPath = StringUtils.trimToEmpty(targetPath);
|
||||||
if (targetPath.length() > 0 && !targetPath.endsWith("/"))
|
if (targetPath.length() > 0 && !targetPath.endsWith("/"))
|
||||||
targetPath += "/";
|
targetPath += "/";
|
||||||
|
|
||||||
File directory = new File(this.project.getBasedir(), fileset.getDirectory());
|
File directory = new File(this.project.getBasedir(), fileset.getDirectory());
|
||||||
if (!directory.exists())
|
if (!directory.exists())
|
||||||
return;
|
return 0;
|
||||||
if (!directory.isDirectory())
|
if (!directory.isDirectory())
|
||||||
throw new MojoExecutionException("The fileset 'directory' must be a directory: " + fileset.getDirectory());
|
throw new MojoExecutionException("The fileset 'directory' must be a directory: " + fileset.getDirectory());
|
||||||
|
|
||||||
@@ -273,6 +287,8 @@ public class AmpMojo extends AbstractMojo {
|
|||||||
|
|
||||||
if (this.getLog().isInfoEnabled())
|
if (this.getLog().isInfoEnabled())
|
||||||
this.getLog().info("Zipped " + filenames.size() + " files: " + fileset.getDirectory());
|
this.getLog().info("Zipped " + filenames.size() + " files: " + fileset.getDirectory());
|
||||||
|
|
||||||
|
return filenames.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void zipFile(ZipOutputStream zstream, File file, String targetPath) throws IOException {
|
private void zipFile(ZipOutputStream zstream, File file, String targetPath) throws IOException {
|
||||||
|
Reference in New Issue
Block a user