Last active
January 29, 2020 19:20
-
-
Save pierre-ernst/91bd32e16079a88c541dbc8e4f9aa523 to your computer and use it in GitHub Desktop.
Generates a maven pom.xml file from a Jars.lock file (see https://github.com/mkristian/jar-dependencies)
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.github.pierre_ernst; | |
import java.io.File; | |
import java.util.Scanner; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
/** | |
* Generates a maven pom.xml file from a Jars.lock file | |
* @see https://github.com/mkristian/jar-dependencies | |
*/ | |
public class JarsLock2mvn { | |
public static void main(String... args) { | |
try { | |
if (args.length != 1) { | |
System.err.println("Usage: java " + JarsLock2mvn.class.getName() + " <Jars.lock>"); | |
} else { | |
System.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + | |
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" + | |
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + | |
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n" + | |
"\t<modelVersion>4.0.0</modelVersion>\n" + | |
"\t<groupId>com.github.pierre_ernst</groupId>\n" + | |
"\t<version>1</version>\n" + | |
"\t<artifactId>jarsLock2mvn</artifactId>\n\t<dependencies>\n"); | |
Scanner input = new Scanner(new File(args[0])); | |
Pattern p = Pattern.compile("^([^:]+):([^:]+):([^:]+):compile:.*$"); | |
while (input.hasNext()) { | |
Matcher m = p.matcher(input.next()); | |
if (m.matches()) { | |
String g = m.group(1); | |
String a = m.group(2); | |
String v = m.group(3); | |
System.out.println("\t\t<dependency>\n\t\t\t<groupId>" + g + "</groupId>\n\t\t\t<artifactId>" + a + "</artifactId>\n\t\t\t<version>" + v + "</version>\n\t\t</dependency>\n"); | |
} | |
} | |
System.out.println("\t</dependencies>\n</project>"); | |
} | |
} catch (Exception ex) { | |
ex.printStackTrace(System.err); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment