/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
*
*/
import org.gradle.api.Project
class Mvn {
final Project project
final File mvnHomeDir
Mvn(final Project project, File mvnHomeDir) {
this.project = project
this.mvnHomeDir = mvnHomeDir
}
void exec(File mvnProjectDir, String... params) {
project.javaexec {
classpath "${mvnHomeDir}/boot/plexus-classworlds-2.4.jar"
jvmArgs "-Dclassworlds.conf=${mvnHomeDir}/bin/m2.conf", "-Xmx256m", '-XX:PermSize=128m',
"-Dmaven.home=${mvnHomeDir}"
main = "org.codehaus.plexus.classworlds.launcher.Launcher"
workingDir = mvnProjectDir
args params
}
}
static Pom parsePom(File dir) {
File pomFile = new File(dir, 'pom.xml')
def pomModel = new XmlSlurper().parse(pomFile)
def el = pomModel['parent']
PomArtifact pomParent = el ? new PomArtifact(
el.groupId.text(),
el.artifactId.text(),
el.version.text()) : null
PomArtifact artifact = new PomArtifact(
pomModel.groupId.text(),
pomModel.artifactId.text(),
pomModel.version.text())
String name = pomModel.name
List modules = new ArrayList<>();
pomModel.modules.module.each { module ->
File modulePomFile = new File(new File(dir, module.text()), 'pom.xml')
def modulePomModel = new XmlSlurper().parse(modulePomFile)
PomArtifact moduleArtifact = new PomArtifact(
artifact.groupId ? artifact.groupId : pomParent.groupId,
modulePomModel.artifactId.text(),
artifact.version)
PomModule pomModule = new PomModule(module.text(), moduleArtifact)
modules.add(pomModule)
}
new Pom(name, pomParent, artifact, modules)
}
}