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.7.0-SNAPSHOT</version>
27 <relativePath>../odlparent</relativePath>
30 <artifactId>features-parent</artifactId>
31 <packaging>pom</packaging>
34 <features.file>features.xml</features.file>
35 <skip.karaf.featureTest>false</skip.karaf.featureTest>
41 <directory>src/main/resources</directory>
42 <filtering>true</filtering>
48 <!-- generate dependencies versions -->
50 <artifactId>maven-dependency-plugin</artifactId>
51 <version>2.10</version>
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 a dependency of the project.")
142 def updateMavenDependency = { dep ->
143 def mvnUrl = dep.text()
145 if (mvnUrl.startsWith("wrap:")) {
147 mvnUrl = mvnUrl.substring(5)
149 if (mvnUrl.startsWith("mvn:")) {
150 def components = mvnUrl.substring(4).split("/")
151 if (components[2].startsWith(versionPlaceholder)) {
153 if (components[2].length() > versionPlaceholder.length()) {
154 suffix = components[2].substring(versionPlaceholder.length())
155 components[2] = versionPlaceholder
157 dep.value = prefix + updatedURLFromProject(components) + suffix
162 def featureFile = new File(project.basedir,featureFilePath)
163 def root = new XmlParser().parse(featureFile)
165 println "[INFO] Updating repository declarations"
166 root.repository.each updateMavenDependency
168 root.feature.each { feature ->
169 println "[INFO] Processing feature: ${feature.@name}"
170 feature.bundle.each updateMavenDependency
171 feature.configfile.each updateMavenDependency
174 def outDir = new File(project.build.directory,"generated-resources/script")
176 def outFile = new File(outDir,"features.xml")
177 def outWriter = outFile.newPrintWriter("ASCII");
178 xmlPrinter = new XmlNodePrinter(outWriter);
179 xmlPrinter.preserveWhitespace = true
180 xmlPrinter.print(root)
188 <groupId>org.codehaus.groovy</groupId>
189 <artifactId>groovy</artifactId>
190 <version>1.8.6</version>
195 <groupId>org.apache.karaf.tooling</groupId>
196 <artifactId>karaf-maven-plugin</artifactId>
197 <version>${karaf.version}</version>
198 <extensions>true</extensions>
201 <id>features-create-kar</id>
203 <goal>features-create-kar</goal>
206 <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
210 <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
213 <groupId>org.codehaus.mojo</groupId>
214 <artifactId>build-helper-maven-plugin</artifactId>
215 <version>1.9.1</version>
218 <phase>generate-resources</phase>
219 <goals><goal>add-resource</goal></goals>
223 <directory>${project.build.directory}/generated-resources/script</directory>
224 <filtering>true</filtering>
230 <id>attach-artifacts</id>
231 <phase>package</phase>
233 <goal>attach-artifact</goal>
238 <file>${project.build.directory}/classes/${features.file}</file>
240 <classifier>features</classifier>
248 <artifactId>maven-resources-plugin</artifactId>
249 <version>2.7</version>
253 <phase>generate-resources</phase>
255 <goal>resources</goal>
261 <artifactId>maven-surefire-plugin</artifactId>
262 <version>${maven.surefire.version}</version>
264 <skip>${skip.karaf.featureTest}</skip>
266 <dependency>org.opendaylight.odlparent:features-test</dependency>
267 </dependenciesToScan>
270 <!-- Ignore/Execute plugin execution -->
272 <groupId>org.eclipse.m2e</groupId>
273 <artifactId>lifecycle-mapping</artifactId>
274 <version>1.0.0</version>
276 <lifecycleMappingMetadata>
279 <pluginExecutionFilter>
280 <groupId>com.alexecollins.maven.plugin</groupId>
281 <artifactId>script-maven-plugin</artifactId>
282 <versionRange>[0.0,)</versionRange>
286 </pluginExecutionFilter>
292 <pluginExecutionFilter>
293 <artifactId>maven-dependency-plugin</artifactId>
294 <versionRange>[0.0,)</versionRange>
298 </pluginExecutionFilter>
304 </lifecycleMappingMetadata>
312 <artifactId>maven-dependency-plugin</artifactId>
315 <groupId>com.alexecollins.maven.plugin</groupId>
316 <artifactId>script-maven-plugin</artifactId>
319 <groupId>org.apache.karaf.tooling</groupId>
320 <artifactId>karaf-maven-plugin</artifactId>
323 <groupId>org.codehaus.mojo</groupId>
324 <artifactId>build-helper-maven-plugin</artifactId>
327 <artifactId>maven-resources-plugin</artifactId>
330 <artifactId>maven-surefire-plugin</artifactId>
336 <!-- test the features.xml -->
338 <groupId>org.opendaylight.odlparent</groupId>
339 <artifactId>features-test</artifactId>
340 <version>1.7.0-SNAPSHOT</version>
346 Maven Site Configuration
348 The following configuration is necessary for maven-site-plugin to
349 correctly identify the correct deployment path for OpenDaylight Maven
352 <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
354 <distributionManagement>
356 <id>opendaylight-site</id>
357 <url>${nexus.site.url}/${project.artifactId}/</url>
359 </distributionManagement>