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">
13 Base parent pom for building, packaging and testing Karaf features.
14 Users should do the following:
16 - specify this as their parent
17 - define their features template in src/main/features
18 - make sure the packaging is set to jar
19 - setup projects <dependencies/> as needed for their features
22 <modelVersion>4.0.0</modelVersion>
24 <groupId>org.opendaylight.odlparent</groupId>
25 <artifactId>odlparent</artifactId>
26 <version>1.6.0-SNAPSHOT</version>
27 <relativePath>../odlparent</relativePath>
30 <groupId>org.opendaylight.odlparent</groupId>
31 <artifactId>features-parent</artifactId>
32 <packaging>pom</packaging>
35 <features.file>features.xml</features.file>
36 <skip.karaf.featureTest>false</skip.karaf.featureTest>
42 <directory>src/main/resources</directory>
43 <filtering>true</filtering>
49 <!-- generate dependencies versions -->
51 <artifactId>maven-dependency-plugin</artifactId>
54 <phase>generate-resources</phase>
55 <goals><goal>resolve</goal></goals>
57 <outputFile>${project.build.directory}/dependencies.txt</outputFile>
63 <groupId>com.alexecollins.maven.plugin</groupId>
64 <artifactId>script-maven-plugin</artifactId>
65 <version>1.0.0</version>
68 <id>add-version-to-features</id>
69 <phase>generate-resources</phase>
74 <language>groovy</language>
77 * Placeholder, which is used in src/features/features.xml
78 * to mark version which should be inserted from dependencies.
79 * Currently works only for bundle and configfile tags
80 * with mvn: url schema, and needs to be used
81 * as third component of schema.
82 * eg. mvn:group/artefact/{{VERSION}}
84 def versionPlaceholder = "{{VERSION}}"
86 * Path to features.xml which uses versionPlaceholder.
87 * This will be processed by this script.
90 def featureFilePath = "src/main/features/features.xml"
91 // Contains mapping of groupID:artefactID to versoin
92 def versionMap = new HashMap();
93 /* Loads transitive dependency list generated from
94 * maven-dependency-plugin resolve goal
97 def dependencies = new File(project.build.directory,"dependencies.txt")
98 dependencies.eachLine {
99 def cmps = it.trim().split(":")
100 // Depends on number of components:
104 // - Qualifier (optional)
107 if(cmps.length > 4) {
108 def id = cmps[0] + ":" + cmps[1]
109 if(cmps.length == 6) {
110 versionMap[id] = cmps[4]
111 } else if(cmps.length == 5) {
112 versionMap[id] = cmps[3]
118 * Takes splitted mvn: URL, looks for placeholder
119 * and returns new mvn: URL with version learned
120 * from dependency plugin.
122 * If referenced bundle is not dependency (direct or transitive)
123 * throws an exception and fails build.
126 def updatedURLFromProject = { args ->
127 // 0 - groupID, 1 - artifactID
128 // 2 - version, 3 - type, 4 - Classifier
130 def groupId = args[0];
131 def artifactId = args[1];
132 def id = groupId + ":" + artifactId
133 def dependencyVersion = versionMap[id]
134 if(dependencyVersion != null) {
135 // Overriding version
136 args[2] = dependencyVersion
137 return "mvn:" + args.join("/")
139 throw new IllegalArgumentException("Feature dependency $groupId:$artifactId is not dependecy of project.")
142 def updateMavenDependency = { dep ->
143 def mvnUrl = dep.text()
144 if (mvnUrl.startsWith("mvn:")) {
145 def components = mvnUrl.substring(4).split("/")
146 if (components[2] == versionPlaceholder) {
147 dep.value = updatedURLFromProject(components)
149 } else if (mvnUrl.startsWith("wrap:mvn:")) {
150 def components = mvnUrl.substring(9).split("/")
151 if (components[2] == versionPlaceholder) {
152 dep.value = "wrap:" + updatedURLFromProject(components)
157 def featureFile = new File(project.basedir,featureFilePath)
158 def root = new XmlParser().parse(featureFile)
160 println "[INFO] Updating repository declarations"
161 root.repository.each updateMavenDependency
163 root.feature.each { feature ->
164 println "[INFO] Processing feature: ${feature.@name}"
165 feature.bundle.each updateMavenDependency
166 feature.configfile.each updateMavenDependency
169 def outDir = new File(project.build.directory,"generated-resources/script")
171 def outFile = new File(outDir,"features.xml")
172 def outWriter = outFile.newPrintWriter("ASCII");
173 xmlPrinter = new XmlNodePrinter(outWriter);
174 xmlPrinter.preserveWhitespace = true
175 xmlPrinter.print(root)
183 <groupId>org.codehaus.groovy</groupId>
184 <artifactId>groovy</artifactId>
185 <version>1.8.6</version>
190 <groupId>org.apache.karaf.tooling</groupId>
191 <artifactId>karaf-maven-plugin</artifactId>
192 <version>${karaf.version}</version>
193 <extensions>true</extensions>
196 <id>features-create-kar</id>
198 <goal>features-create-kar</goal>
201 <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
205 <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
208 <groupId>org.codehaus.mojo</groupId>
209 <artifactId>build-helper-maven-plugin</artifactId>
212 <phase>generate-resources</phase>
213 <goals><goal>add-resource</goal></goals>
217 <directory>${project.build.directory}/generated-resources/script</directory>
218 <filtering>true</filtering>
224 <id>attach-artifacts</id>
225 <phase>package</phase>
227 <goal>attach-artifact</goal>
232 <file>${project.build.directory}/classes/${features.file}</file>
234 <classifier>features</classifier>
242 <groupId>org.apache.maven.plugins</groupId>
243 <artifactId>maven-resources-plugin</artifactId>
247 <phase>generate-resources</phase>
249 <goal>resources</goal>
255 <groupId>org.apache.maven.plugins</groupId>
256 <artifactId>maven-surefire-plugin</artifactId>
258 <skip>${skip.karaf.featureTest}</skip>
260 <dependency>org.opendaylight.odlparent:features-test</dependency>
261 </dependenciesToScan>
264 <!-- Ignore/Execute plugin execution -->
266 <groupId>org.eclipse.m2e</groupId>
267 <artifactId>lifecycle-mapping</artifactId>
268 <version>1.0.0</version>
270 <lifecycleMappingMetadata>
273 <pluginExecutionFilter>
274 <groupId>com.alexecollins.maven.plugin</groupId>
275 <artifactId>script-maven-plugin</artifactId>
276 <versionRange>[0.0,)</versionRange>
280 </pluginExecutionFilter>
286 <pluginExecutionFilter>
287 <groupId>org.apache.maven.plugins</groupId>
288 <artifactId>maven-dependency-plugin</artifactId>
289 <versionRange>[0.0,)</versionRange>
293 </pluginExecutionFilter>
299 </lifecycleMappingMetadata>
307 <artifactId>maven-dependency-plugin</artifactId>
310 <groupId>com.alexecollins.maven.plugin</groupId>
311 <artifactId>script-maven-plugin</artifactId>
314 <groupId>org.apache.karaf.tooling</groupId>
315 <artifactId>karaf-maven-plugin</artifactId>
318 <groupId>org.codehaus.mojo</groupId>
319 <artifactId>build-helper-maven-plugin</artifactId>
322 <groupId>org.apache.maven.plugins</groupId>
323 <artifactId>maven-resources-plugin</artifactId>
326 <groupId>org.apache.maven.plugins</groupId>
327 <artifactId>maven-surefire-plugin</artifactId>
333 <!-- test the features.xml -->
335 <groupId>org.opendaylight.odlparent</groupId>
336 <artifactId>features-test</artifactId>
337 <version>1.6.0-SNAPSHOT</version>