mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 16:07:12 -07:00
maven pom importing
This commit is contained in:
parent
ac7215ac12
commit
5f739035e0
6 changed files with 216 additions and 3 deletions
|
@ -55,6 +55,7 @@ private class Main @Inject constructor(
|
|||
println(Banner.get() + Kobalt.version + "\n")
|
||||
// runTest()
|
||||
runWithArgs(jc, args)
|
||||
log(1, "************ shutting down executors")
|
||||
executors.shutdown()
|
||||
debug("All done")
|
||||
})
|
||||
|
|
|
@ -75,14 +75,46 @@ public class ProjectGenerator : KobaltLogger {
|
|||
put("version", pom.version ?: "0.1")
|
||||
put("name", pom.name ?: pom.artifactId)
|
||||
}
|
||||
|
||||
val properties = pom.properties
|
||||
val mapped = properties.entrySet().toMap({it.key}, {translate(it.key)})
|
||||
|
||||
map.put("properties", properties
|
||||
.entrySet()
|
||||
.map({ Pair(mapped.get(it.key), it.value) }))
|
||||
val partition = pom.dependencies.groupBy { it.scope }
|
||||
.flatMap { it.value }
|
||||
.map { updateVersion(it, mapped) }
|
||||
.sortedBy { it.groupId + ":" + it.artifactId }
|
||||
.partition { it.scope != "test" }
|
||||
|
||||
mainDeps.addAll(partition.first)
|
||||
testDeps.addAll(partition.second)
|
||||
}
|
||||
|
||||
private fun updateVersion(dep: Dependency, mapped: Map<String, String>): Dependency {
|
||||
if ( dep.version.startsWith("\${")) {
|
||||
val property = dep.version.substring(2, dep.version.length() - 1)
|
||||
println("property = ${property}")
|
||||
return Dependency(dep.groupId, dep.artifactId, "\${${mapped.get(property)}}", dep.optional, dep.scope)
|
||||
} else {
|
||||
return dep
|
||||
}
|
||||
}
|
||||
|
||||
private fun translate(key: String) : String {
|
||||
val split = key.split('.')
|
||||
return split.mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }).join("")
|
||||
}
|
||||
|
||||
private fun String.upperFirst(): String {
|
||||
if (this.isBlank()) {
|
||||
return this
|
||||
} else {
|
||||
return this.substring(0, 1).toUpperCase() + this.substring(1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect all the languages contained in this project.
|
||||
*/
|
||||
|
|
|
@ -5,12 +5,10 @@ import com.beust.kobalt.misc.ToString
|
|||
import com.google.inject.assistedinject.Assisted
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.NodeList
|
||||
import org.w3c.dom.Text
|
||||
import org.xml.sax.InputSource
|
||||
import java.io.FileReader
|
||||
import javax.xml.xpath.XPathConstants
|
||||
import kotlin.dom.get
|
||||
import kotlin.dom.toXmlString
|
||||
import kotlin.dom.childElements
|
||||
|
||||
public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
|
||||
@Assisted documentFile: java.io.File) : KobaltLogger {
|
||||
|
@ -65,6 +63,12 @@ public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
|
|||
version = XPATH.compile("/project/version").evaluate(document)
|
||||
name = XPATH.compile("/project/name").evaluate(document)
|
||||
|
||||
var list = XPATH.compile("/project/properties").evaluate(document, XPathConstants.NODESET) as NodeList
|
||||
var elem = list.item(0) as Element?
|
||||
elem.childElements().forEach {
|
||||
properties.put(it.nodeName, it.textContent)
|
||||
}
|
||||
|
||||
val deps = DEPENDENCIES.evaluate(document, XPathConstants.NODESET) as NodeList
|
||||
for (i in 0..deps.getLength() - 1) {
|
||||
val d = deps.item(i) as NodeList
|
||||
|
|
|
@ -2,7 +2,12 @@ import com.beust.kobalt.*
|
|||
import com.beust.kobalt.plugin.packaging.assemble
|
||||
{{imports}}
|
||||
|
||||
{{#properties}}
|
||||
val {{first}} = {{second}}
|
||||
{{/properties}}
|
||||
|
||||
val p = {{directive}} {
|
||||
|
||||
name = "{{name}}"
|
||||
group = "{{group}}"
|
||||
artifactId = name
|
||||
|
|
19
src/test/kotlin/com/beust/kobalt/maven/PomTest.kt
Normal file
19
src/test/kotlin/com/beust/kobalt/maven/PomTest.kt
Normal file
|
@ -0,0 +1,19 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
|
||||
class PomTest {
|
||||
@Test
|
||||
fun importPom() {
|
||||
val pom = Pom("testing", File("src/test/resources/pom.xml"));
|
||||
|
||||
Assert.assertEquals(pom.groupId, "com.foo.bob")
|
||||
Assert.assertEquals(pom.artifactId, "rawr")
|
||||
Assert.assertEquals(pom.name, "rawr")
|
||||
Assert.assertEquals(pom.version, "1.2.3")
|
||||
Assert.assertEquals(pom.properties.get("commons.version"), "2.1.1")
|
||||
Assert.assertEquals(pom.properties.get("guice.version"), "4.0")
|
||||
}
|
||||
}
|
152
src/test/resources/pom.xml
Normal file
152
src/test/resources/pom.xml
Normal file
|
@ -0,0 +1,152 @@
|
|||
<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>com.foo.bob</groupId>
|
||||
<artifactId>rawr</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.3</version>
|
||||
|
||||
<name>rawr</name>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>something.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<inherited>true</inherited>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</plugin>
|
||||
<!-- Run me with 'mvn exec:java'. -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
|
||||
<configuration>
|
||||
<mainClass>com.foo.bob.Rawr</mainClass>
|
||||
<classpathScope>test</classpathScope>
|
||||
<arguments>
|
||||
<argument>-Xmx512m</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>com.foo.bob.Rawr</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-email</artifactId>
|
||||
<version>${commons.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<classifier>no_aop</classifier>
|
||||
<version>${guice.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-report-plugin</artifactId>
|
||||
<version>2.16</version>
|
||||
<configuration>
|
||||
<linkXRef>false</linkXRef>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
<properties>
|
||||
<commons.version>2.1.1</commons.version>
|
||||
<guice.version>4.0</guice.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
Loading…
Add table
Add a link
Reference in a new issue