Commit 5be66ae4 authored by Brian Long's avatar Brian Long
Browse files

removing AMP if no external libs

parent 5c2adf88
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -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 {
@@ -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() {
@@ -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");
@@ -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() {
@@ -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 {