Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b080710a1 | ||
|
|
0a69deb73a | ||
|
|
80e03c558b | ||
|
|
e7f2c1da67 | ||
|
|
00abdc4340 | ||
|
|
0a3bf69eff | ||
|
|
8e66eaefdf | ||
|
|
aadc05a270 |
@@ -8,17 +8,25 @@
|
||||
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>amp-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.2</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>A Maven plugin to generate AMP files</name>
|
||||
<description>Generate Alfresco Module Packages (AMP) files in a way simialr to WAR files</description>
|
||||
|
||||
<scm>
|
||||
<url>https://bitbucket.org/inteligr8/maven-amp-plugin</url>
|
||||
</scm>
|
||||
<organization>
|
||||
<name>Inteligr8</name>
|
||||
<url>https://www.inteligr8.com</url>
|
||||
</organization>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>brian.long</id>
|
||||
<name>Brian Long</name>
|
||||
<email>brian@inteligr8.com</email>
|
||||
<url>https://twitter.com/brianmlong</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
@@ -109,7 +117,7 @@
|
||||
<repository>
|
||||
<id>inteligr8-releases</id>
|
||||
<name>Inteligr8 Releases</name>
|
||||
<url>http://repos.yateslong.us/nexus/repository/inteligr8-public</url>
|
||||
<url>http://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
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.Arrays;
|
||||
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.artifact.Artifact;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
import org.eclipse.aether.resolution.ArtifactRequest;
|
||||
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
||||
import org.eclipse.aether.resolution.ArtifactResult;
|
||||
|
||||
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;
|
||||
private final ArtifactResolutionCallback callback;
|
||||
|
||||
public AmpDependencyFilter(Log log, String charsetName, ArtifactResolutionCallback callback) {
|
||||
this.log = log;
|
||||
this.charset = Charset.forName(charsetName);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
|
||||
Artifact artifact = node.getArtifact();
|
||||
if (this.log.isDebugEnabled())
|
||||
this.log.debug("Checking dependency: " + artifact.getArtifactId());
|
||||
File file = artifact.getFile();
|
||||
try {
|
||||
if (file == null) {
|
||||
if (this.log.isDebugEnabled())
|
||||
this.log.debug("Resolving dependency: " + artifact.getArtifactId());
|
||||
ArtifactResult result = this.callback.resolveArtifact(new ArtifactRequest(node));
|
||||
if (result.isMissing() || !result.isResolved())
|
||||
throw new ArtifactResolutionException(Arrays.asList(result));
|
||||
artifact = result.getArtifact();
|
||||
file = artifact.getFile();
|
||||
}
|
||||
if (this.log.isDebugEnabled())
|
||||
this.log.debug("Checking dependency file: " + file);
|
||||
|
||||
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 (ArtifactResolutionException are) {
|
||||
this.log.warn("An artifact could not be resolved; assuming it is not an Alfresco module and continuing");
|
||||
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;
|
||||
@@ -41,6 +36,10 @@ import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.impl.ArtifactResolver;
|
||||
import org.eclipse.aether.resolution.ArtifactRequest;
|
||||
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
||||
import org.eclipse.aether.resolution.ArtifactResult;
|
||||
import org.eclipse.aether.util.filter.DependencyFilterUtils;
|
||||
import org.eclipse.aether.util.filter.ExclusionsDependencyFilter;
|
||||
import org.eclipse.aether.util.filter.ScopeDependencyFilter;
|
||||
@@ -48,9 +47,8 @@ import org.eclipse.aether.util.filter.ScopeDependencyFilter;
|
||||
@Mojo( name = "amp", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true,
|
||||
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class AmpMojo extends AbstractMojo {
|
||||
public class AmpMojo extends AbstractMojo implements ArtifactResolutionCallback {
|
||||
|
||||
private final Pattern modulePropertiesPattern = Pattern.compile("^alfresco/module/[^/]+/module\\.properties$");
|
||||
private final int streamBufferSize = 16384;
|
||||
|
||||
@Parameter( defaultValue = "${project}", readonly = true )
|
||||
@@ -62,6 +60,9 @@ public class AmpMojo extends AbstractMojo {
|
||||
@Requirement
|
||||
private ProjectDependenciesResolver resolver;
|
||||
|
||||
@Requirement
|
||||
private ArtifactResolver artifactResolver;
|
||||
|
||||
@Parameter( property = "outputFile", required = true, defaultValue = "${project.build.directory}/${project.artifactId}-${project.version}.amp" )
|
||||
protected String outputAmpFile;
|
||||
|
||||
@@ -202,13 +203,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 +230,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, this);
|
||||
|
||||
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 +308,9 @@ 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;
|
||||
@Override
|
||||
public ArtifactResult resolveArtifact(ArtifactRequest artifactRequest) throws ArtifactResolutionException {
|
||||
return this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), artifactRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.inteligr8.alfresco.amp;
|
||||
|
||||
import org.eclipse.aether.resolution.ArtifactRequest;
|
||||
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
||||
import org.eclipse.aether.resolution.ArtifactResult;
|
||||
|
||||
public interface ArtifactResolutionCallback {
|
||||
|
||||
ArtifactResult resolveArtifact(ArtifactRequest artifactRequest) throws ArtifactResolutionException;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user