Loading src/main/java/com/inteligr8/alfresco/amp/AmpDependencyFilter.java +27 −2 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ 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; Loading @@ -12,8 +13,12 @@ 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 { Loading @@ -21,22 +26,42 @@ public class AmpDependencyFilter implements DependencyFilter { private final int streamBufferSize = 16 * 1024; private final Log log; private final Charset charset; private final ArtifactResolutionCallback callback; public AmpDependencyFilter(Log log, String charsetName) { 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) { File file = node.getArtifact().getFile(); 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"); Loading src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java +15 −3 Original line number Diff line number Diff line Loading @@ -36,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; Loading @@ -43,7 +47,7 @@ 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 int streamBufferSize = 16384; Loading @@ -56,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; Loading Loading @@ -223,7 +230,7 @@ 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); AmpDependencyFilter ampFilter = new AmpDependencyFilter(this.getLog(), this.charsetName, this); DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(this.project, this.session.getRepositorySession()); request.setResolutionFilter(DependencyFilterUtils.andFilter(scopeFilter, exclusionFilter, ampFilter)); Loading Loading @@ -301,4 +308,9 @@ public class AmpMojo extends AbstractMojo { zstream.closeEntry(); } @Override public ArtifactResult resolveArtifact(ArtifactRequest artifactRequest) throws ArtifactResolutionException { return this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), artifactRequest); } } src/main/java/com/inteligr8/alfresco/amp/ArtifactResolutionCallback.java 0 → 100644 +11 −0 Original line number Diff line number Diff line 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; } Loading
src/main/java/com/inteligr8/alfresco/amp/AmpDependencyFilter.java +27 −2 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ 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; Loading @@ -12,8 +13,12 @@ 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 { Loading @@ -21,22 +26,42 @@ public class AmpDependencyFilter implements DependencyFilter { private final int streamBufferSize = 16 * 1024; private final Log log; private final Charset charset; private final ArtifactResolutionCallback callback; public AmpDependencyFilter(Log log, String charsetName) { 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) { File file = node.getArtifact().getFile(); 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"); Loading
src/main/java/com/inteligr8/alfresco/amp/AmpMojo.java +15 −3 Original line number Diff line number Diff line Loading @@ -36,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; Loading @@ -43,7 +47,7 @@ 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 int streamBufferSize = 16384; Loading @@ -56,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; Loading Loading @@ -223,7 +230,7 @@ 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); AmpDependencyFilter ampFilter = new AmpDependencyFilter(this.getLog(), this.charsetName, this); DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(this.project, this.session.getRepositorySession()); request.setResolutionFilter(DependencyFilterUtils.andFilter(scopeFilter, exclusionFilter, ampFilter)); Loading Loading @@ -301,4 +308,9 @@ public class AmpMojo extends AbstractMojo { zstream.closeEntry(); } @Override public ArtifactResult resolveArtifact(ArtifactRequest artifactRequest) throws ArtifactResolutionException { return this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), artifactRequest); } }
src/main/java/com/inteligr8/alfresco/amp/ArtifactResolutionCallback.java 0 → 100644 +11 −0 Original line number Diff line number Diff line 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; }