Created
September 29, 2014 03:27
-
-
Save bpodgursky/e43ff66575ea92c5a9f9 to your computer and use it in GitHub Desktop.
Mojo to print snapshot revisions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.liveramp.liveramp_build_maven_plugin; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.TreeMap; | |
import java.util.jar.Attributes; | |
import java.util.jar.JarFile; | |
import java.util.jar.Manifest; | |
import java.util.zip.ZipEntry; | |
import com.google.common.collect.Maps; | |
import org.apache.maven.artifact.Artifact; | |
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; | |
import org.apache.maven.plugin.AbstractMojo; | |
import org.apache.maven.plugin.MojoExecutionException; | |
import org.apache.maven.plugins.annotations.LifecyclePhase; | |
import org.apache.maven.plugins.annotations.Mojo; | |
import org.apache.maven.plugins.annotations.Parameter; | |
import org.apache.maven.plugins.annotations.ResolutionScope; | |
import org.apache.maven.project.MavenProject; | |
@Mojo(name = "print-snapshot-impl", | |
defaultPhase = LifecyclePhase.COMPILE, | |
requiresDependencyResolution = ResolutionScope.COMPILE) | |
public class PrintSnapshotImplMojo extends AbstractMojo { | |
@Parameter(defaultValue = "${project}", required = true, readonly = true) | |
private MavenProject project; | |
public void execute() throws MojoExecutionException { | |
try { | |
Set<Artifact> artifacts = project.getArtifacts(); | |
getLog().info(""); | |
getLog().info("Implementation-Build of snapshot dependencies:"); | |
getLog().info(""); | |
TreeMap<String, String> orderedArtifacts = Maps.newTreeMap(); | |
for (Artifact artifact : artifacts) { | |
DefaultArtifactVersion version = new DefaultArtifactVersion(artifact.getBaseVersion()); | |
if (version.getQualifier() != null && | |
artifact.getFile() != null && | |
version.getQualifier().equals("SNAPSHOT")) { | |
JarFile jar = new JarFile(artifact.getFile()); | |
ZipEntry entry = jar.getEntry("META-INF/MANIFEST.MF"); | |
Manifest manifest = new Manifest(jar.getInputStream(entry)); | |
Attributes attributes = manifest.getMainAttributes(); | |
String title = attributes.getValue("Implementation-Title"); | |
String build = attributes.getValue("Implementation-Build"); | |
if (title != null && build != null) { | |
orderedArtifacts.put( | |
artifact.getGroupId() + "." + artifact.getArtifactId() + ":" + version.toString(), | |
build | |
); | |
} | |
} | |
} | |
for (Map.Entry<String, String> entry : orderedArtifacts.entrySet()) { | |
getLog().info(entry.getKey() + ":\t" + entry.getValue()); | |
} | |
getLog().info(""); | |
} catch (Exception ex) { | |
throw new RuntimeException(ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment