removing AMP if no external libs

This commit is contained in:
2021-01-25 10:29:34 -05:00
parent 5c2adf88fd
commit 5be66ae49a

View File

@@ -99,7 +99,8 @@ public class AmpMojo extends AbstractMojo {
this.normalize();
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 {
FileOutputStream fostream = new FileOutputStream(ampFile, false);
@@ -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() {
@@ -187,6 +193,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()) {
@@ -195,17 +203,23 @@ public class AmpMojo extends AbstractMojo {
for (Dependency dependency : deps) {
File file = dependency.getArtifact().getFile();
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 {
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() {
@@ -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());
@@ -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 {