1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- vi: set et smarttab sw=4 tabstop=4: -->
4 Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
6 This program and the accompanying materials are made available under the
7 terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 and is available at http://www.eclipse.org/legal/epl-v10.html
10 <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/xsd/maven-4.0.0.xsd">
11 <modelVersion>4.0.0</modelVersion>
13 <groupId>org.opendaylight.yangtools</groupId>
14 <artifactId>yangtools-parent</artifactId>
15 <version>0.7.0-SNAPSHOT</version>
16 <relativePath>../parent/pom.xml</relativePath>
19 <groupId>org.opendaylight.yangtools</groupId>
20 <artifactId>features-builder</artifactId>
21 <packaging>pom</packaging>
22 <version>0.7.0-SNAPSHOT</version>
25 <features.file>features.xml</features.file>
31 <directory>src/main/resources</directory>
32 <filtering>true</filtering>
38 <!-- generate dependencies versions -->
40 <artifactId>maven-dependency-plugin</artifactId>
43 <phase>generate-resources</phase>
44 <goals><goal>resolve</goal></goals>
46 <outputFile>${project.build.directory}/dependencies.txt</outputFile>
52 <groupId>com.alexecollins.maven.plugin</groupId>
53 <artifactId>script-maven-plugin</artifactId>
54 <version>1.0.0</version>
57 <id>add-version-to-features</id>
58 <phase>generate-resources</phase>
63 <language>groovy</language>
66 * Placeholder, which is used in src/feature/features.xml
67 * to mark version which should be inserted from dependencies.
68 * Currently works only for bundle and configfile tags
69 * with mvn: url schema, and needs to be used
70 * as third component of schema.
71 * eg. mvn:group/artefact/{{VERSION}}
73 def versionPlaceholder = "{{VERSION}}"
75 * Path to features.xml which uses versionPlaceholder.
76 * This will be processed by this script.
79 def featureFilePath = "src/main/feature/features.xml"
80 // Contains mapping of groupID:artefactID to versoin
81 def versionMap = new HashMap();
82 /* Loads transitive dependency list generated from
83 * maven-dependency-plugin resolve goal
86 def dependencies = new File(project.build.directory,"dependencies.txt")
87 dependencies.eachLine {
88 def cmps = it.trim().split(":")
93 if(cmps.length >= 4) {
94 def id = cmps[0] + ":" + cmps[1]
95 versionMap[id] = cmps[3]
100 * Takes splitted mvn: URL, looks for placeholder
101 * and returns new mvn: URL with version learned
102 * from dependency plugin.
104 * If referenced bundle is not dependency (direct or transitive)
105 * throws an exception and fails build.
108 def updatedURLFromProject = { args ->
109 // 0 - groupID, 1 - artifactID
110 // 2 - version, 3 - type, 4 - Classifier
112 def groupId = args[0];
113 def artifactId = args[1];
114 def id = groupId + ":" + artifactId
115 def dependencyVersion = versionMap[id]
116 if(dependencyVersion != null) {
117 // Overriding version
118 args[2] = dependencyVersion
119 return "mvn:" + args.join("/")
121 throw new IllegalArgumentException("Feature dependency $groupId:$artifactId is not dependecy of project.")
125 def updateMavenDependency = { dep ->
126 def mvnUrl = dep.text()
127 if(mvnUrl.startsWith("mvn:")) {
128 def components = mvnUrl.substring(4).split("/")
129 if(components[2] == versionPlaceholder) {
130 dep.value = updatedURLFromProject(components)
135 def featureFile = new File(project.basedir,featureFilePath)
136 def root = new XmlParser().parse(featureFile)
138 root.feature.each { feature ->
139 println "[INFO] Processing feature: ${feature.@name}"
140 feature.bundle.each updateMavenDependency
141 feature.configfile.each updateMavenDependency
144 def outDir = new File(project.build.directory,"generated-resources/script")
146 def outFile = new File(outDir,"features.xml")
147 def outWriter = outFile.newPrintWriter("ASCII");
148 xmlPrinter = new XmlNodePrinter(outWriter);
149 xmlPrinter.preserveWhitespace = true
150 xmlPrinter.print(root)
158 <groupId>org.codehaus.groovy</groupId>
159 <artifactId>groovy</artifactId>
160 <version>1.8.6</version>
165 <groupId>org.apache.karaf.tooling</groupId>
166 <artifactId>karaf-maven-plugin</artifactId>
167 <version>${karaf.version}</version>
168 <extensions>true</extensions>
171 <id>features-create-kar</id>
173 <goal>features-create-kar</goal>
176 <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
180 <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
183 <groupId>org.codehaus.mojo</groupId>
184 <artifactId>build-helper-maven-plugin</artifactId>
187 <phase>generate-resources</phase>
188 <goals><goal>add-resource</goal></goals>
192 <directory>${project.build.directory}/generated-resources/script</directory>
193 <filtering>true</filtering>
199 <id>attach-artifacts</id>
200 <phase>package</phase>
202 <goal>attach-artifact</goal>
207 <file>${project.build.directory}/classes/${features.file}</file>
209 <classifier>features</classifier>
217 <groupId>org.apache.maven.plugins</groupId>
218 <artifactId>maven-resources-plugin</artifactId>
222 <phase>generate-resources</phase>
224 <goal>resources</goal>
230 <groupId>org.apache.maven.plugins</groupId>
231 <artifactId>maven-surefire-plugin</artifactId>
234 <dependency>org.opendaylight.yangtools:features-test</dependency>
235 </dependenciesToScan>
243 <!-- test the features.xml -->
245 <groupId>org.opendaylight.yangtools</groupId>
246 <artifactId>features-test</artifactId>
247 <version>0.7.0-SNAPSHOT</version>