filtering modules properly per Maven API
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.inteligr8.alfresco.amp;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
|
||||
public class AmpDependencyFilter implements DependencyFilter {
|
||||
|
||||
private final Pattern modulePropertiesPattern = Pattern.compile("^alfresco/module/[^/]+/module\\.properties$");
|
||||
private final int streamBufferSize = 16 * 1024;
|
||||
private final Log log;
|
||||
private final Charset charset;
|
||||
|
||||
public AmpDependencyFilter(Log log, String charsetName) {
|
||||
this.log = log;
|
||||
this.charset = Charset.forName(charsetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
|
||||
File file = node.getArtifact().getFile();
|
||||
try {
|
||||
if (this.isAlfrescoModule(file)) {
|
||||
if (this.log.isInfoEnabled())
|
||||
this.log.info("Not packaging JAR; detected as Alfresco JAR Module: " + node.getArtifact().getArtifactId());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (IOException ie) {
|
||||
this.log.warn("An I/O issue occurred while inspecting a JAR to see if it is an Alfresco module; assuming it isn't and continuing");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAlfrescoModule(File file) throws IOException {
|
||||
FileInputStream fistream = new FileInputStream(file);
|
||||
BufferedInputStream bistream = new BufferedInputStream(fistream, this.streamBufferSize);
|
||||
ZipInputStream zstream = new ZipInputStream(bistream, this.charset);
|
||||
try {
|
||||
ZipEntry zentry = zstream.getNextEntry();
|
||||
while (zentry != null) {
|
||||
try {
|
||||
Matcher modPropsMatcher = this.modulePropertiesPattern.matcher(zentry.getName());
|
||||
if (modPropsMatcher.find())
|
||||
return true;
|
||||
} finally {
|
||||
zstream.closeEntry();
|
||||
}
|
||||
|
||||
zentry = zstream.getNextEntry();
|
||||
}
|
||||
} finally {
|
||||
zstream.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -1,9 +1,7 @@
|
||||
package com.inteligr8.alfresco.amp;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
@@ -13,10 +11,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -50,7 +45,6 @@ import org.eclipse.aether.util.filter.ScopeDependencyFilter;
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class AmpMojo extends AbstractMojo {
|
||||
|
||||
private final Pattern modulePropertiesPattern = Pattern.compile("^alfresco/module/[^/]+/module\\.properties$");
|
||||
private final int streamBufferSize = 16384;
|
||||
|
||||
@Parameter( defaultValue = "${project}", readonly = true )
|
||||
@@ -202,13 +196,8 @@ public class AmpMojo extends AbstractMojo {
|
||||
} else {
|
||||
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++;
|
||||
}
|
||||
this.zipFile(zstream, file, "lib");
|
||||
libcount++;
|
||||
}
|
||||
|
||||
if (this.getLog().isInfoEnabled())
|
||||
@@ -234,9 +223,10 @@ public class AmpMojo extends AbstractMojo {
|
||||
|
||||
ScopeDependencyFilter scopeFilter = new ScopeDependencyFilter(Arrays.asList(includeScopes), new ArrayList<String>(0));
|
||||
ExclusionsDependencyFilter exclusionFilter = new ExclusionsDependencyFilter(this.getExclusions());
|
||||
AmpDependencyFilter ampFilter = new AmpDependencyFilter(this.getLog(), this.charsetName);
|
||||
|
||||
DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(this.project, this.session.getRepositorySession());
|
||||
request.setResolutionFilter(DependencyFilterUtils.andFilter(scopeFilter, exclusionFilter));
|
||||
request.setResolutionFilter(DependencyFilterUtils.andFilter(scopeFilter, exclusionFilter, ampFilter));
|
||||
|
||||
DependencyResolutionResult result = this.resolver.resolve(request);
|
||||
return result.getResolvedDependencies();
|
||||
@@ -311,29 +301,4 @@ public class AmpMojo extends AbstractMojo {
|
||||
zstream.closeEntry();
|
||||
}
|
||||
|
||||
private boolean isAlfrescoModule(File file) throws IOException {
|
||||
FileInputStream fistream = new FileInputStream(file);
|
||||
BufferedInputStream bistream = new BufferedInputStream(fistream, this.streamBufferSize);
|
||||
ZipInputStream zstream = new ZipInputStream(bistream, Charset.forName(this.charsetName));
|
||||
try {
|
||||
ZipEntry zentry = zstream.getNextEntry();
|
||||
while (zentry != null) {
|
||||
this.getLog().debug("dep entry: " + zentry.getName());
|
||||
try {
|
||||
Matcher modPropsMatcher = this.modulePropertiesPattern.matcher(zentry.getName());
|
||||
if (modPropsMatcher.find())
|
||||
return true;
|
||||
} finally {
|
||||
zstream.closeEntry();
|
||||
}
|
||||
|
||||
zentry = zstream.getNextEntry();
|
||||
}
|
||||
} finally {
|
||||
zstream.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user