├── .gitignore
├── src
├── test
│ ├── jars
│ │ ├── afterburner.fx-1.6.2.jar
│ │ └── testpom.xml
│ └── java
│ │ ├── xplr
│ │ └── ExplorerTest.java
│ │ └── com
│ │ └── airhacks
│ │ └── xplr
│ │ ├── POMTest.java
│ │ ├── JarFileInfoTest.java
│ │ ├── JarAnalyzerTest.java
│ │ └── FileWalkerTest.java
└── main
│ └── java
│ ├── xplr
│ └── Explorer.java
│ └── com
│ └── airhacks
│ └── xplr
│ ├── FileWalker.java
│ ├── JarAnalyzer.java
│ ├── POM.java
│ └── JarFileInfo.java
├── README.md
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | nbproject
3 | install.sh
4 |
--------------------------------------------------------------------------------
/src/test/jars/afterburner.fx-1.6.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamBien/xplr/HEAD/src/test/jars/afterburner.fx-1.6.2.jar
--------------------------------------------------------------------------------
/src/test/java/xplr/ExplorerTest.java:
--------------------------------------------------------------------------------
1 | package xplr;
2 |
3 | import org.junit.Test;
4 |
5 | /**
6 | *
7 | * @author airhacks.com
8 | */
9 | public class ExplorerTest {
10 |
11 |
12 | @Test(expected = IllegalStateException.class)
13 | public void exploreNotExistingJar() {
14 | String[] arguments = new String[]{"doesnotexists.txt"};
15 | Explorer.main(arguments);
16 | }
17 |
18 | @Test
19 | public void exploreExistingJar() {
20 | String[] arguments = new String[]{"src/test/jars/afterburner.fx-1.6.2.jar"};
21 | Explorer.main(arguments);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/com/airhacks/xplr/POMTest.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Paths;
6 | import static org.hamcrest.CoreMatchers.is;
7 | import static org.junit.Assert.assertThat;
8 | import org.junit.Test;
9 |
10 | /**
11 | *
12 | * @author airhacks.com
13 | */
14 | public class POMTest {
15 |
16 | @Test
17 | public void parsePOM() throws IOException {
18 | String content = new String(Files.readAllBytes(Paths.get("src/test/jars/testpom.xml")));
19 | POM pom = new POM(content);
20 | assertThat(pom.getArtifactId(), is("afterburner.fx"));
21 | assertThat(pom.getGroupId(), is("com.airhacks"));
22 | assertThat(pom.getPackaging(), is("jar"));
23 | assertThat(pom.getVersion(), is("9"));
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/java/com/airhacks/xplr/JarFileInfoTest.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import static org.hamcrest.CoreMatchers.is;
4 | import static org.junit.Assert.assertThat;
5 | import org.junit.Test;
6 |
7 | /**
8 | *
9 | * @author airhacks.com
10 | */
11 | public class JarFileInfoTest {
12 |
13 | @Test
14 | public void limitShortString() {
15 | String expected = "expected";
16 | String actual = JarFileInfo.limit(expected);
17 | assertThat(actual, is(expected));
18 | }
19 |
20 | @Test
21 | public void limitTooLong() {
22 | String tooLong = "";
23 | for (int i = 0; i < 256; i++) {
24 | tooLong += i;
25 | }
26 | String actual = JarFileInfo.limit(tooLong);
27 | assertThat(actual.length(), is(JarFileInfo.MAX_LENGTH + 3 /* the three dots*/));
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # xplr
2 |
3 | JAR Meta-Info Explorer
4 |
5 | xplr is a self-contained Java 8 CLI utility, which traverses recursively folders, searches for JARs, extracts the versioning information from ```manifest.mf``` and ```pom.xml``` and generates ```mvn install:install-file``` statements.
6 |
7 | xplr is helpful for extracting dependency information for Maven dependencies from "legacy" JARs.
8 |
9 | Sample output:
10 |
11 | ```
12 | #####################################
13 | Directory: .
14 | #####################################
15 |
16 | # Jar: ./original-xplr.jar
17 | ## Manifest:
18 | ## Package: com.airhacks.xplr
19 | Archiver-Version:Plexus Archiver
20 | Built-By:abien
21 | Created-By:Apache Maven 3.3.3
22 | Build-Jdk:1.8.0_77
23 | Manifest-Version:1.0
24 |
25 | ## POM:
26 |
27 | com.airhacks
28 | xplr
29 | 0.0.1
30 | jar
31 |
32 | ## MVN install command:
33 | mvn install:install-file -Dfile=./original-xplr.jar -DgroupId=com.airhacks -DartifactId=xplr -Dversion=0.0.1 -Dpackaging=jar
34 | ```
35 |
36 |
37 | ## Requirements
38 |
39 | Java 8
40 |
41 | ## Usage
42 |
43 | ```java -jar xplr.jar [FOLDER] [CLASS NAME]``` or
44 | ```java -jar xplr.jar [JAR_FILE] [CLASS NAME]```
45 |
46 | FOLDER (optional): specifies the folder. Defaults to the current working directory
47 |
48 | JAR_FILE: a jar in the current directory or a fully qualified path to the jar file.
49 |
50 | CLASS NAME (optional): searches for jars containing the specified class name. The search is case insensitive.
51 |
52 |
--------------------------------------------------------------------------------
/src/test/java/com/airhacks/xplr/JarAnalyzerTest.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Path;
5 | import java.nio.file.Paths;
6 | import java.util.jar.Manifest;
7 | import java.util.stream.Stream;
8 | import static org.hamcrest.CoreMatchers.is;
9 | import static org.junit.Assert.assertNotNull;
10 | import static org.junit.Assert.assertNull;
11 | import static org.junit.Assert.assertThat;
12 | import org.junit.Before;
13 | import org.junit.Test;
14 |
15 | /**
16 | *
17 | * @author airhacks.com
18 | */
19 | public class JarAnalyzerTest {
20 |
21 | JarAnalyzer cut;
22 | private Path pathToJar;
23 |
24 | @Before
25 | public void init() {
26 | this.pathToJar = Paths.get("src/test/jars/afterburner.fx-1.6.2.jar");
27 | }
28 |
29 | @Test
30 | public void analyze() throws IOException {
31 | Manifest manifest = JarAnalyzer.getManifest(pathToJar);
32 | assertNotNull(manifest);
33 | POM mavenPOM = JarAnalyzer.getMavenPOM(pathToJar);
34 | assertNotNull(mavenPOM);
35 | System.out.println("mavenPOM = " + mavenPOM);
36 | }
37 |
38 | @Test
39 | public void getPackage() {
40 | String expected = "com.airhacks.afterburner.configuration";
41 | String actual = JarAnalyzer.getPackage(this.pathToJar);
42 | assertThat(actual, is(expected));
43 | }
44 |
45 | @Test
46 | public void getPackageForClassWithoutPackage() {
47 | Stream packageStream = Stream.of("Duke.class");
48 | String actual = JarAnalyzer.getPackage(packageStream);
49 | assertNull(actual);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/xplr/Explorer.java:
--------------------------------------------------------------------------------
1 | package xplr;
2 |
3 | import com.airhacks.xplr.FileWalker;
4 | import com.airhacks.xplr.JarAnalyzer;
5 | import com.airhacks.xplr.JarFileInfo;
6 | import java.nio.file.Path;
7 | import java.nio.file.Paths;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.stream.Collectors;
11 | import java.util.stream.Stream;
12 |
13 | /**
14 | *
15 | * @author airhacks.com
16 | */
17 | public class Explorer {
18 |
19 | public static void main(String[] args) {
20 | String rootFolderOrFile = args.length >= 1 ? args[0] : ".";
21 | String className = args.length >= 2 ? args[1] : null;
22 | Path root = Paths.get(rootFolderOrFile);
23 | List jars = FileWalker.findJars(root);
24 | Stream stream = filter(className, jars.stream());
25 | Map> byPath = stream.map(JarAnalyzer::analyze).
26 | collect(Collectors.groupingBy(JarFileInfo::getFolderName));
27 | String report = byPath.entrySet().
28 | stream().
29 | map(e -> toString(e.getKey(), e.getValue())).
30 | collect(Collectors.joining("\n"));
31 | System.out.println(report);
32 | }
33 |
34 | static Stream filter(String className, Stream stream) {
35 | if (className != null) {
36 | return stream.filter(j -> JarAnalyzer.containsFileName(j, className));
37 | }
38 | return stream;
39 | }
40 |
41 | static String toString(Path path, List jars) {
42 | String retVal = "#####################################\n";
43 | retVal += "Directory: " + path.toString() + "\n";
44 | retVal += "#####################################\n";
45 | retVal += jars.stream().map(j -> j.toString()).
46 | collect(Collectors.joining("\n---\n", "\n", "\n---\n"));
47 | return retVal;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/airhacks/xplr/FileWalker.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.nio.file.FileVisitResult;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 | import java.nio.file.Paths;
9 | import java.nio.file.SimpleFileVisitor;
10 | import java.nio.file.attribute.BasicFileAttributes;
11 | import java.util.ArrayList;
12 | import java.util.Arrays;
13 | import java.util.List;
14 |
15 | /**
16 | *
17 | * @author airhacks.com
18 | */
19 | public interface FileWalker {
20 |
21 | public static List findJars(Path root) {
22 | if (isJar(root)) {
23 | Path fileWithAbsolutePath = asAbsolutePath(root);
24 | return Arrays.asList(fileWithAbsolutePath);
25 | }
26 | return scanFolder(root);
27 | }
28 |
29 | static Path asAbsolutePath(Path file) {
30 | String asString = file.toString();
31 | if (!asString.startsWith(".") && !asString.startsWith(File.pathSeparator)) {
32 | return Paths.get(".").resolve(file);
33 | }
34 | return file;
35 | }
36 |
37 | static boolean isJar(Path file) {
38 | return file.getFileName().toString().endsWith(".jar");
39 | }
40 |
41 | public static List scanFolder(Path root) throws IllegalStateException {
42 | List jars = new ArrayList<>();
43 | SimpleFileVisitor visitor = new SimpleFileVisitor() {
44 | @Override
45 | public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
46 | if (!attributes.isDirectory()) {
47 | if (file.toString().endsWith(".jar")) {
48 | jars.add(file);
49 | }
50 | }
51 | return FileVisitResult.CONTINUE;
52 | }
53 | };
54 | try {
55 | Files.walkFileTree(root, visitor);
56 | } catch (IOException ex) {
57 | throw new IllegalStateException(ex);
58 | }
59 | return jars;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/com/airhacks/xplr/FileWalkerTest.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import java.nio.file.Path;
4 | import java.nio.file.Paths;
5 | import java.util.List;
6 | import static org.hamcrest.CoreMatchers.is;
7 | import static org.junit.Assert.assertFalse;
8 | import static org.junit.Assert.assertThat;
9 | import static org.junit.Assert.assertTrue;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 |
13 | /**
14 | *
15 | * @author airhacks.com
16 | */
17 | public class FileWalkerTest {
18 |
19 | private Path pathToJar;
20 | private FileWalker cut;
21 |
22 | @Before
23 | public void init() {
24 | this.pathToJar = Paths.get("src/test/");
25 | }
26 |
27 | @Test
28 | public void isJar() {
29 | assertTrue(FileWalker.isJar(Paths.get("hugo.jar")));
30 | assertFalse(FileWalker.isJar(Paths.get("hugo/")));
31 | }
32 |
33 | @Test
34 | public void isAbsolutePathWithPlainDottedFile() {
35 | Path file = Paths.get("org.eclipse.persistence.jpa.jar");
36 | Path expected = Paths.get("./org.eclipse.persistence.jpa.jar");
37 | Path actual = FileWalker.asAbsolutePath(file);
38 | assertThat(actual.toString(), is(expected.toString()));
39 | }
40 |
41 | @Test
42 | public void isAbsolutePathWithPlainFile() {
43 | Path file = Paths.get("hugo.jar");
44 | Path expected = Paths.get("./hugo.jar");
45 | Path actual = FileWalker.asAbsolutePath(file);
46 | assertThat(actual.toString(), is(expected.toString()));
47 | }
48 |
49 | @Test
50 | public void isAbsolutePathWithFileWithPath() {
51 | Path file = Paths.get("/temp/hugo.jar");
52 | Path expected = Paths.get("/temp/hugo.jar");
53 | Path actual = FileWalker.asAbsolutePath(file);
54 | assertThat(actual.toString(), is(expected.toString()));
55 | }
56 |
57 |
58 | @Test
59 | public void findJars() {
60 | Path expected = Paths.get("src/test/jars/afterburner.fx-1.6.2.jar");
61 | List jars = FileWalker.findJars(this.pathToJar);
62 | assertThat(jars.size(), is(1));
63 | assertThat(jars.get(0), is(expected));
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.airhacks
5 | xplr
6 | 0.0.2
7 | jar
8 |
9 |
10 | junit
11 | junit
12 | 4.12
13 | test
14 |
15 |
16 |
17 |
18 |
19 | org.apache.maven.plugins
20 | maven-shade-plugin
21 | 3.2.1
22 |
23 |
24 | package
25 |
26 | shade
27 |
28 |
29 |
30 |
31 | xplr.Explorer
32 |
33 |
34 |
35 |
36 | junit:junit
37 | org.mockito
38 |
39 |
40 | xplr
41 |
42 |
43 |
44 |
45 |
46 | xplr
47 |
48 |
49 | UTF-8
50 | 1.8
51 | 1.8
52 |
53 |
--------------------------------------------------------------------------------
/src/main/java/com/airhacks/xplr/JarAnalyzer.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.FileInputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.InputStreamReader;
8 | import java.nio.file.Path;
9 | import java.util.jar.JarEntry;
10 | import java.util.jar.JarFile;
11 | import java.util.jar.JarInputStream;
12 | import java.util.jar.Manifest;
13 | import java.util.stream.Collectors;
14 | import java.util.stream.Stream;
15 |
16 | /**
17 | *
18 | * @author airhacks.com
19 | */
20 | public interface JarAnalyzer {
21 |
22 | public static Manifest getManifest(Path jar) {
23 | try (FileInputStream fileInputStream = new FileInputStream(jar.toFile())) {
24 | try (JarInputStream inputStream = new JarInputStream(fileInputStream)) {
25 | return inputStream.getManifest();
26 | }
27 | } catch (IOException ex) {
28 | throw new IllegalStateException(ex);
29 | }
30 | }
31 |
32 | public static boolean containsFileName(Path jar, String className) {
33 | try (FileInputStream fileInputStream = new FileInputStream(jar.toFile())) {
34 | try (JarInputStream inputStream = new JarInputStream(fileInputStream)) {
35 | JarEntry entry;
36 | while ((entry = inputStream.getNextJarEntry()) != null) {
37 | if (entry.getName().contains(className)) {
38 | return true;
39 | }
40 | }
41 | }
42 | } catch (IOException ex) {
43 | throw new IllegalStateException(ex);
44 | }
45 | return false;
46 | }
47 |
48 | public static POM getMavenPOM(Path jar) {
49 | try (JarFile file = new JarFile(jar.toFile())) {
50 | POM pom = file.stream().
51 | filter(e -> e.getName().endsWith("pom.xml")).
52 | map((JarEntry e) -> {
53 | try {
54 | return file.getInputStream(e);
55 | } catch (IOException ex) {
56 | throw new IllegalStateException(ex);
57 | }
58 | }).
59 | map(JarAnalyzer::read).
60 | findFirst().
61 | map(POM::new).
62 | orElse(null);
63 | if (pom != null) {
64 | return pom;
65 | }
66 | } catch (IOException ex) {
67 | throw new IllegalStateException(ex);
68 | }
69 | return null;
70 | }
71 |
72 | public static String getPackage(Path jar) {
73 | try (JarFile file = new JarFile(jar.toFile())) {
74 | return getPackage(file.stream().
75 | map(e -> e.getName()));
76 | } catch (IOException ex) {
77 | throw new IllegalStateException(ex);
78 | }
79 | }
80 |
81 | static String getPackage(Stream packages) {
82 | return packages.filter(n -> n.endsWith(".class")).
83 | filter(n -> n.lastIndexOf("/") != -1).
84 | map(n -> n.substring(0, n.lastIndexOf(".class"))).
85 | map(n -> n.substring(0, n.lastIndexOf("/"))).
86 | map(n -> n.replace("/", ".")).
87 | sorted((second, first) -> new Integer(first.length()).
88 | compareTo(second.length())).
89 | findFirst().
90 | orElse(null);
91 | }
92 |
93 | public static JarFileInfo analyze(Path jar) {
94 | return new JarFileInfo(jar, getManifest(jar), getMavenPOM(jar), getPackage(jar));
95 |
96 | }
97 |
98 | static void log(JarEntry entry) {
99 | System.out.println(entry);
100 | }
101 |
102 | static String read(InputStream stream) {
103 | try (BufferedReader buffer = new BufferedReader(new InputStreamReader(stream))) {
104 | return buffer.lines().collect(Collectors.joining("\n"));
105 | } catch (IOException ex) {
106 | throw new IllegalStateException(ex);
107 | }
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/com/airhacks/xplr/POM.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import java.io.IOException;
4 | import java.io.StringReader;
5 | import javax.xml.parsers.DocumentBuilder;
6 | import javax.xml.parsers.DocumentBuilderFactory;
7 | import javax.xml.parsers.ParserConfigurationException;
8 | import org.w3c.dom.Document;
9 | import org.w3c.dom.Node;
10 | import org.w3c.dom.NodeList;
11 | import org.xml.sax.InputSource;
12 | import org.xml.sax.SAXException;
13 |
14 | /**
15 | *
16 | * @author airhacks.com
17 | */
18 | public final class POM {
19 |
20 | private String content;
21 |
22 | private String groupId;
23 | private String artifactId;
24 | private String packaging;
25 | private String version;
26 |
27 | public POM(String content) {
28 | this.content = content;
29 | parse();
30 | }
31 |
32 | public POM(String groupId, String artifactId, String version) {
33 | this.groupId = groupId;
34 | this.artifactId = artifactId;
35 | this.version = version;
36 | }
37 |
38 | void parse() {
39 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
40 | DocumentBuilder builder = null;
41 | try {
42 | builder = factory.newDocumentBuilder();
43 | } catch (ParserConfigurationException ex) {
44 | throw new IllegalStateException(ex);
45 | }
46 | try (StringReader reader = new StringReader(content)) {
47 | try {
48 | Document document = builder.parse(new InputSource(reader));
49 | Node project = document.getElementsByTagName("project").item(0);
50 | NodeList childNodes = project.getChildNodes();
51 | for (int i = 0; i < childNodes.getLength(); i++) {
52 | Node item = childNodes.item(i);
53 | if ("parent".equalsIgnoreCase(item.getNodeName())) {
54 | this.groupId = findSubNode("groupId", item);
55 | this.artifactId = findSubNode("artifactId", item);
56 | this.packaging = findSubNode("packaging", item);
57 | this.version = findSubNode("version", item);
58 | }
59 | if ("groupId".equals(item.getNodeName())) {
60 | this.groupId = item.getTextContent();
61 | }
62 | if ("artifactId".equals(item.getNodeName())) {
63 | this.artifactId = item.getTextContent();
64 | }
65 | if ("packaging".equals(item.getNodeName())) {
66 | this.packaging = item.getTextContent();
67 | }
68 | if ("version".equals(item.getNodeName())) {
69 | this.version = item.getTextContent();
70 | }
71 | }
72 | } catch (SAXException | IOException ex) {
73 | throw new IllegalStateException(ex);
74 | }
75 | }
76 | }
77 |
78 | String findSubNode(String nodeName, Node parent) {
79 | NodeList childNodes = parent.getChildNodes();
80 | for (int i = 0; i < childNodes.getLength(); i++) {
81 | Node item = childNodes.item(i);
82 | if (nodeName.equals(item.getNodeName())) {
83 | return item.getTextContent();
84 | }
85 | }
86 | return null;
87 | }
88 |
89 | public String getGroupId() {
90 | return groupId;
91 | }
92 |
93 | public String getArtifactId() {
94 | return artifactId;
95 | }
96 |
97 | public String getPackaging() {
98 | return packaging;
99 | }
100 |
101 | public String getVersion() {
102 | return version;
103 | }
104 |
105 | @Override
106 | public String toString() {
107 | String retVal = "" + "\n";
108 | retVal += " " + this.groupId + "" + "\n";
109 | retVal += " " + this.artifactId + "" + "\n";
110 | retVal += " " + this.version + "" + "\n";
111 | if (packaging != null) {
112 | retVal += " " + this.packaging + "" + "\n";
113 | }
114 | retVal += "";
115 |
116 | return retVal;
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/java/com/airhacks/xplr/JarFileInfo.java:
--------------------------------------------------------------------------------
1 | package com.airhacks.xplr;
2 |
3 | import java.nio.file.Path;
4 | import java.util.jar.Attributes;
5 | import java.util.jar.Manifest;
6 | import java.util.stream.Collectors;
7 |
8 | /**
9 | *
10 | * @author airhacks.com
11 | */
12 | public class JarFileInfo {
13 |
14 | private final Manifest manifest;
15 | private final Path fileName;
16 | private final POM pom;
17 | private final String longestPackagePath;
18 | final static int MAX_LENGTH = 128;
19 |
20 | public JarFileInfo(Path fileName, Manifest manifest, POM pom, String longestPackagePath) {
21 | this.fileName = fileName;
22 | this.manifest = manifest;
23 | this.pom = pom;
24 | this.longestPackagePath = longestPackagePath;
25 | }
26 |
27 | public String getManifest() {
28 | Attributes mainAttributes = this.manifest.getMainAttributes();
29 | String main = mainAttributes.entrySet().stream().
30 | map(e -> e.getKey() + ":" + limit(e.getValue())).
31 | collect(Collectors.joining("\n"));
32 | return main;
33 | }
34 |
35 | public Path getFolderName() {
36 | return this.fileName.getParent();
37 | }
38 |
39 | public Path getFileName() {
40 | return fileName;
41 | }
42 |
43 | public POM getPom() {
44 | return pom;
45 | }
46 |
47 | public String getLongestPackagePath() {
48 | return longestPackagePath;
49 | }
50 |
51 | public String getMavenInstallCommand() {
52 | return "mvn install:install-file -Dfile=" + this.fileName
53 | + " -DgroupId=" + getGroupId()
54 | + " -DartifactId=" + getArtifactId()
55 | + " -Dversion=" + getVersion()
56 | + " -Dpackaging=" + getPackaging();
57 | }
58 |
59 | String getGroupId() {
60 | String groupId = this.pom == null ? null : this.pom.getGroupId();
61 | if (groupId == null) {
62 | groupId = getLongestPackagePath();
63 | }
64 | return groupId;
65 | }
66 |
67 | String getArtifactId() {
68 | String artifactId = this.pom == null ? null : this.pom.getArtifactId();
69 | if (artifactId == null) {
70 | artifactId = getFileNameWithoutExtension();
71 | }
72 | return artifactId;
73 | }
74 |
75 | String extractFileNameWithoutExtension(Path path) {
76 | Path file = path.getFileName();
77 | String nameAsString = file.toString();
78 | int indexOfDot = nameAsString.lastIndexOf(".");
79 | return nameAsString.substring(0, indexOfDot);
80 | }
81 |
82 | String getFileNameWithoutExtension() {
83 | return this.extractFileNameWithoutExtension(this.getFileName());
84 | }
85 |
86 | String getVersion() {
87 | String version = this.pom == null ? null : this.pom.getVersion();
88 | if (version == null) {
89 | return "1.0";
90 | } else {
91 | return version;
92 | }
93 | }
94 |
95 | String getPackaging() {
96 | String packaging = this.pom == null ? null : this.pom.getPackaging();
97 | if (packaging == null) {
98 | return "jar";
99 | } else {
100 | return packaging;
101 | }
102 | }
103 |
104 | @Override
105 | public String toString() {
106 | String msg = "# ";
107 | msg += "Jar: " + getFileName() + "\n";
108 | msg += "## Manifest: " + "\n";
109 | msg += "## Package: " + getLongestPackagePath() + "\n";
110 | msg += getManifest() + "\n";
111 | if (pom != null) {
112 | msg += "\n## POM: " + "\n";
113 | msg += getPom() + "\n";
114 | } else {
115 | POM suggestion = new POM(this.getGroupId(), this.getArtifactId(), this.getVersion());
116 | msg += "\n## Suggestion: " + "\n";
117 | msg += suggestion + "\n";
118 | }
119 | msg += "## MVN install command: " + "\n";
120 | msg += getMavenInstallCommand();
121 | return msg;
122 | }
123 |
124 | static String limit(Object value) {
125 | String stringified = value.toString();
126 | int length = stringified.length();
127 | if (length > MAX_LENGTH) {
128 | return stringified.substring(0, MAX_LENGTH) + "...";
129 | }
130 | return stringified;
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/src/test/jars/testpom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | org.sonatype.oss
5 | oss-parent
6 | 9
7 |
8 | com.airhacks
9 | afterburner.fx
10 | jar
11 |
12 | afterburner.fx
13 | afterburner.fx is a minimalistic JavaFX MVP framework based on Convention over Configuration and Dependency Injection
14 | http://afterburner.adam-bien.com
15 |
16 | Adam Bien
17 | http://adam-bien.com
18 |
19 | 2013
20 |
21 |
22 |
23 | The Apache Software License, Version 2.0
24 | http://www.apache.org/licenses/LICENSE-2.0.txt
25 | repo
26 |
27 |
28 |
29 |
30 | Adam Bien
31 | adam-bien.com
32 | http://adam-bien.com
33 |
34 |
35 |
36 |
37 | junit
38 | junit
39 | 4.11
40 | test
41 |
42 |
43 | org.mockito
44 | mockito-all
45 | 1.9.5
46 | test
47 |
48 |
49 | javax.inject
50 | javax.inject
51 | 1
52 | compile
53 |
54 |
55 |
56 |
57 |
58 | org.codehaus.mojo
59 | license-maven-plugin
60 | 1.6
61 |
62 | true
63 |
64 |
65 |
66 | add-apache-headers
67 |
68 | update-file-header
69 |
70 | process-sources
71 |
72 | apache_v2
73 |
74 |
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-shade-plugin
80 | 2.1
81 |
82 |
83 | package
84 |
85 | shade
86 |
87 |
88 |
89 |
90 | junit:junit
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | org.apache.maven.plugins
99 | maven-gpg-plugin
100 | 1.5
101 |
102 |
103 | sign-artifacts
104 | verify
105 |
106 | sign
107 |
108 |
109 |
110 |
111 |
112 | org.apache.maven.plugins
113 | maven-source-plugin
114 | 2.2.1
115 |
116 |
117 | attach-sources
118 | verify
119 |
120 | jar-no-fork
121 |
122 |
123 |
124 |
125 |
126 | org.apache.maven.plugins
127 | maven-release-plugin
128 | 2.5
129 |
130 | v@{project.version}
131 |
132 |
133 |
134 | org.jacoco
135 | jacoco-maven-plugin
136 | 0.7.0.201403182114
137 |
138 |
139 |
140 | prepare-agent
141 |
142 |
143 |
144 | report
145 | prepare-package
146 |
147 | report
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 | src/main/java
156 |
157 | **/*.fxml
158 | **/*.css
159 | **/*.properties
160 |
161 |
162 |
163 | src/test/java
164 |
165 | **/*.fxml
166 | **/*.css
167 | **/*.properties
168 |
169 |
170 |
171 | src/main/resources
172 |
173 | **/*.xml
174 |
175 |
176 |
177 | afterburner
178 |
179 |
180 | scm:git:git@github.com:AdamBien/afterburner.fx.git
181 | scm:git:git@github.com:AdamBien/afterburner.fx.git
182 | scm:git:git@github.com:AdamBien/afterburner.fx.git
183 | v1.6.2
184 |
185 |
186 | UTF-8
187 | 1.8
188 | 1.8
189 |
190 |
191 |
--------------------------------------------------------------------------------