Skip to content

Instantly share code, notes, and snippets.

@stoerr
Created February 21, 2019 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoerr/9077c48bba51c5c0ae2fe2330bd390dc to your computer and use it in GitHub Desktop.
Save stoerr/9077c48bba51c5c0ae2fe2330bd390dc to your computer and use it in GitHub Desktop.
Creates a pom.xml in the directory a Sling launchpad runs for all JARs deployed in the Felix OSGI container there, enabling to import these easily into the IDE and download the sources/javadocs as well
import java.util.zip.ZipFile
println("Run in launchpad")
File topfile = new File("sling").canonicalFile
def pom = new FileWriter("pom.xml")
pom.append("""<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hps.launchpaddeps</groupId>
<artifactId>launchpad</artifactId>
<version>0.0.0-SNAPSHOT</version>
<!-- Generated by GenerateFelixPom.groovy. -->
<dependencies>
<properties>
<source.encoding>UTF-8</source.encoding>
<java.source>1.8</java.source>
<java.target>1.8</java.target>
</properties>
""")
topfile.traverse(nameFilter: ~/.*\.jar/) { File it ->
def jar = new ZipFile(it)
String pomentry = ""
jar.entries().find { it.name.endsWith("/pom.properties") && it.name.contains("META-INF/maven") }.each {
Properties props = new Properties()
props.load(jar.getInputStream(it))
def version = props.getProperty("version")
def group = props.getProperty("groupId")
def artifact = props.getProperty("artifactId")
pomentry = pomentry + """
<dependency>
<groupId>$group</groupId>
<artifactId>$artifact</artifactId>
<version>$version</version>
<scope>provided</scope>
</dependency>
"""
}
if (pomentry == "") {
def artifact = it.name.replaceAll(~/[^a-zA-Z0-9]/, "_")
String relativepath = it.canonicalPath.substring(topfile.parentFile.path.length())
pomentry = """
<dependency>
<groupId>hps.launchpaddeps</groupId>
<artifactId>$artifact</artifactId>
<version>0.0.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>\${project.basedir}$relativepath</systemPath>
</dependency>
"""
}
// println(pomentry)
pom.append(pomentry)
pomentry = ""
jar.close()
}
pom.append("""
</dependencies>
</project>
""")
pom.close()
println("Wrote pom.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment