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.8.0-SNAPSHOT</version>
27 <relativePath>../odlparent</relativePath>
30 <artifactId>features-parent</artifactId>
31 <packaging>pom</packaging>
32 <name>ODL :: odlparent :: ${project.artifactId}</name>
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>
52 <version>2.10</version>
55 <phase>generate-resources</phase>
56 <goals><goal>resolve</goal></goals>
58 <outputFile>${project.build.directory}/dependencies.txt</outputFile>
64 <groupId>com.alexecollins.maven.plugin</groupId>
65 <artifactId>script-maven-plugin</artifactId>
66 <version>1.0.0</version>
69 <id>add-version-to-features</id>
70 <phase>generate-resources</phase>
75 <language>groovy</language>
78 * Placeholder, which is used in src/features/features.xml
79 * to mark version which should be inserted from dependencies.
80 * Currently works only for bundle and configfile tags
81 * with mvn: url schema, and needs to be used
82 * as third component of schema.
83 * eg. mvn:group/artefact/{{VERSION}}
85 def versionPlaceholder = "{{VERSION}}"
87 * Path to features.xml which uses versionPlaceholder.
88 * This will be processed by this script.
91 def featureFilePath = "src/main/features/features.xml"
92 // Contains mapping of groupID:artefactID to versoin
93 def versionMap = new HashMap();
94 /* Loads transitive dependency list generated from
95 * maven-dependency-plugin resolve goal
98 def dependencies = new File(project.build.directory,"dependencies.txt")
99 dependencies.eachLine {
100 def cmps = it.trim().split(":")
101 // Depends on number of components:
105 // - Qualifier (optional)
108 if(cmps.length > 4) {
109 def id = cmps[0] + ":" + cmps[1]
110 if(cmps.length == 6) {
111 versionMap[id] = cmps[4]
112 } else if(cmps.length == 5) {
113 versionMap[id] = cmps[3]
119 * Takes splitted mvn: URL, looks for placeholder
120 * and returns new mvn: URL with version learned
121 * from dependency plugin.
123 * If referenced bundle is not dependency (direct or transitive)
124 * throws an exception and fails build.
127 def updatedURLFromProject = { args ->
128 // 0 - groupID, 1 - artifactID
129 // 2 - version, 3 - type, 4 - Classifier
131 def groupId = args[0];
132 def artifactId = args[1];
133 def id = groupId + ":" + artifactId
134 def dependencyVersion = versionMap[id]
135 if(dependencyVersion != null) {
136 // Overriding version
137 args[2] = dependencyVersion
138 return "mvn:" + args.join("/")
140 throw new IllegalArgumentException("Feature dependency $groupId:$artifactId is not a dependency in the project pom.xml.")
143 def updateMavenDependency = { dep ->
144 def mvnUrl = dep.text()
146 if (mvnUrl.startsWith("wrap:")) {
148 mvnUrl = mvnUrl.substring(5)
150 if (mvnUrl.startsWith("mvn:") && mvnUrl.indexOf(versionPlaceholder) >= 0) {
151 // Process property place-holders
153 while ((dollarIndex = mvnUrl.indexOf("\${")) >= 0) {
154 def closingBrace = mvnUrl.indexOf("}", dollarIndex);
155 if (closingBrace > dollarIndex) {
156 def propKey = mvnUrl.substring(dollarIndex + 2, closingBrace);
157 def propVal = project.properties[propKey];
158 mvnUrl = mvnUrl.replace("\${${propKey}}", propVal);
160 println "[WARN] Malformed Maven URL: ${mvnUrl}";
164 def components = mvnUrl.substring(4).split("/")
165 if (components[2].startsWith(versionPlaceholder)) {
167 if (components[2].length() > versionPlaceholder.length()) {
168 suffix = components[2].substring(versionPlaceholder.length())
169 components[2] = versionPlaceholder
171 dep.value = prefix + updatedURLFromProject(components) + suffix
176 def featureFile = new File(project.basedir,featureFilePath)
177 def root = new XmlParser().parse(featureFile)
179 println "[INFO] Updating repository declarations"
180 root.repository.each updateMavenDependency
182 root.feature.each { feature ->
183 println "[INFO] Processing feature: ${feature.@name}"
184 feature.bundle.each updateMavenDependency
185 feature.configfile.each updateMavenDependency
188 def outDir = new File(project.build.directory,"generated-resources/script")
190 def outFile = new File(outDir,"features.xml")
191 def outWriter = outFile.newPrintWriter("ASCII");
192 xmlPrinter = new XmlNodePrinter(outWriter);
193 xmlPrinter.preserveWhitespace = true
194 xmlPrinter.print(root)
202 <groupId>org.codehaus.groovy</groupId>
203 <artifactId>groovy</artifactId>
204 <version>1.8.6</version>
209 <groupId>org.apache.karaf.tooling</groupId>
210 <artifactId>karaf-maven-plugin</artifactId>
211 <version>${karaf.version}</version>
212 <extensions>true</extensions>
215 <id>features-create-kar</id>
217 <goal>features-create-kar</goal>
220 <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
224 <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
227 <groupId>org.codehaus.mojo</groupId>
228 <artifactId>build-helper-maven-plugin</artifactId>
229 <version>1.12</version>
232 <phase>generate-resources</phase>
233 <goals><goal>add-resource</goal></goals>
237 <directory>${project.build.directory}/generated-resources/script</directory>
238 <filtering>true</filtering>
244 <id>attach-artifacts</id>
245 <phase>package</phase>
247 <goal>attach-artifact</goal>
252 <file>${project.build.directory}/classes/${features.file}</file>
254 <classifier>features</classifier>
262 <artifactId>maven-resources-plugin</artifactId>
263 <version>3.0.1</version>
267 <phase>generate-resources</phase>
269 <goal>resources</goal>
275 <artifactId>maven-surefire-plugin</artifactId>
276 <version>${maven.surefire.version}</version>
278 <skip>${skip.karaf.featureTest}</skip>
279 <systemPropertyVariables>
280 <!-- Remove these properties when a better fix to Bug 6523 appears. -->
281 <karaf.distro.groupId>org.opendaylight.odlparent</karaf.distro.groupId>
282 <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>
283 <karaf.distro.version>1.8.0-SNAPSHOT</karaf.distro.version>
284 </systemPropertyVariables>
286 <dependency>org.opendaylight.odlparent:features-test</dependency>
287 </dependenciesToScan>
290 <!-- Ignore/Execute plugin execution -->
292 <groupId>org.eclipse.m2e</groupId>
293 <artifactId>lifecycle-mapping</artifactId>
294 <version>1.0.0</version>
296 <lifecycleMappingMetadata>
299 <pluginExecutionFilter>
300 <groupId>com.alexecollins.maven.plugin</groupId>
301 <artifactId>script-maven-plugin</artifactId>
302 <versionRange>[0.0,)</versionRange>
306 </pluginExecutionFilter>
312 <pluginExecutionFilter>
313 <groupId>org.apache.maven.plugins</groupId>
314 <artifactId>maven-dependency-plugin</artifactId>
315 <versionRange>[0.0,)</versionRange>
319 </pluginExecutionFilter>
325 </lifecycleMappingMetadata>
333 <!-- This generates the META-INF/maven/dependencies.properties file
334 which is required by the versionAsInProject() used in SingleFeatureTest -->
335 <groupId>org.apache.servicemix.tooling</groupId>
336 <artifactId>depends-maven-plugin</artifactId>
339 <artifactId>maven-dependency-plugin</artifactId>
342 <groupId>com.alexecollins.maven.plugin</groupId>
343 <artifactId>script-maven-plugin</artifactId>
346 <groupId>org.apache.karaf.tooling</groupId>
347 <artifactId>karaf-maven-plugin</artifactId>
350 <groupId>org.codehaus.mojo</groupId>
351 <artifactId>build-helper-maven-plugin</artifactId>
354 <artifactId>maven-resources-plugin</artifactId>
357 <artifactId>maven-surefire-plugin</artifactId>
363 <!-- test the features.xml -->
365 <groupId>org.opendaylight.odlparent</groupId>
366 <artifactId>features-test</artifactId>
367 <version>1.8.0-SNAPSHOT</version>
370 <!-- Remove this dependency when a better fix for Bug 6523 appears. -->
372 <groupId>org.opendaylight.odlparent</groupId>
373 <artifactId>opendaylight-karaf-empty</artifactId>
374 <version>1.8.0-SNAPSHOT</version>
381 Maven Site Configuration
383 The following configuration is necessary for maven-site-plugin to
384 correctly identify the correct deployment path for OpenDaylight Maven
387 <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
389 <distributionManagement>
391 <id>opendaylight-site</id>
392 <url>${nexus.site.url}/${project.artifactId}/</url>
394 </distributionManagement>