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.odlparent</groupId>
14 <artifactId>odlparent</artifactId>
15 <version>1.5.0-SNAPSHOT</version>
18 <groupId>org.opendaylight.yangtools</groupId>
19 <artifactId>features-builder</artifactId>
20 <packaging>pom</packaging>
21 <version>0.7.0-SNAPSHOT</version>
24 <features.file>features.xml</features.file>
30 <directory>src/main/resources</directory>
31 <filtering>true</filtering>
37 <!-- generate dependencies versions -->
39 <artifactId>maven-dependency-plugin</artifactId>
42 <phase>generate-resources</phase>
43 <goals><goal>resolve</goal></goals>
45 <outputFile>${project.build.directory}/dependencies.txt</outputFile>
51 <groupId>com.alexecollins.maven.plugin</groupId>
52 <artifactId>script-maven-plugin</artifactId>
53 <version>1.0.0</version>
56 <id>add-version-to-features</id>
57 <phase>generate-resources</phase>
62 <language>groovy</language>
65 * Placeholder, which is used in src/feature/features.xml
66 * to mark version which should be inserted from dependencies.
67 * Currently works only for bundle and configfile tags
68 * with mvn: url schema, and needs to be used
69 * as third component of schema.
70 * eg. mvn:group/artefact/{{VERSION}}
72 def versionPlaceholder = "{{VERSION}}"
74 * Path to features.xml which uses versionPlaceholder.
75 * This will be processed by this script.
78 def featureFilePath = "src/main/feature/features.xml"
79 // Contains mapping of groupID:artefactID to versoin
80 def versionMap = new HashMap();
81 /* Loads transitive dependency list generated from
82 * maven-dependency-plugin resolve goal
85 def dependencies = new File(project.build.directory,"dependencies.txt")
86 dependencies.eachLine {
87 def cmps = it.trim().split(":")
92 if(cmps.length >= 4) {
93 def id = cmps[0] + ":" + cmps[1]
94 versionMap[id] = cmps[3]
99 * Takes splitted mvn: URL, looks for placeholder
100 * and returns new mvn: URL with version learned
101 * from dependency plugin.
103 * If referenced bundle is not dependency (direct or transitive)
104 * throws an exception and fails build.
107 def updatedURLFromProject = { args ->
108 // 0 - groupID, 1 - artifactID
109 // 2 - version, 3 - type, 4 - Classifier
111 def groupId = args[0];
112 def artifactId = args[1];
113 def id = groupId + ":" + artifactId
114 def dependencyVersion = versionMap[id]
115 if(dependencyVersion != null) {
116 // Overriding version
117 args[2] = dependencyVersion
118 return "mvn:" + args.join("/")
120 throw new IllegalArgumentException("Feature dependency $groupId:$artifactId is not dependecy of project.")
124 def updateMavenDependency = { dep ->
125 def mvnUrl = dep.text()
126 if(mvnUrl.startsWith("mvn:")) {
127 def components = mvnUrl.substring(4).split("/")
128 if(components[2] == versionPlaceholder) {
129 dep.value = updatedURLFromProject(components)
134 def featureFile = new File(project.basedir,featureFilePath)
135 def root = new XmlParser().parse(featureFile)
137 root.feature.each { feature ->
138 println "[INFO] Processing feature: ${feature.@name}"
139 feature.bundle.each updateMavenDependency
140 feature.configfile.each updateMavenDependency
143 def outDir = new File(project.build.directory,"generated-resources/script")
145 def outFile = new File(outDir,"features.xml")
146 def outWriter = outFile.newPrintWriter("ASCII");
147 xmlPrinter = new XmlNodePrinter(outWriter);
148 xmlPrinter.preserveWhitespace = true
149 xmlPrinter.print(root)
157 <groupId>org.codehaus.groovy</groupId>
158 <artifactId>groovy</artifactId>
159 <version>1.8.6</version>
164 <groupId>org.apache.karaf.tooling</groupId>
165 <artifactId>karaf-maven-plugin</artifactId>
166 <version>${karaf.version}</version>
167 <extensions>true</extensions>
170 <id>features-create-kar</id>
172 <goal>features-create-kar</goal>
175 <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
179 <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
182 <groupId>org.codehaus.mojo</groupId>
183 <artifactId>build-helper-maven-plugin</artifactId>
186 <phase>generate-resources</phase>
187 <goals><goal>add-resource</goal></goals>
191 <directory>${project.build.directory}/generated-resources/script</directory>
192 <filtering>true</filtering>
198 <id>attach-artifacts</id>
199 <phase>package</phase>
201 <goal>attach-artifact</goal>
206 <file>${project.build.directory}/classes/${features.file}</file>
208 <classifier>features</classifier>
216 <groupId>org.apache.maven.plugins</groupId>
217 <artifactId>maven-resources-plugin</artifactId>
221 <phase>generate-resources</phase>
223 <goal>resources</goal>
229 <groupId>org.apache.maven.plugins</groupId>
230 <artifactId>maven-surefire-plugin</artifactId>
233 <dependency>org.opendaylight.yangtools:features-test</dependency>
234 </dependenciesToScan>
242 <!-- test the features.xml -->
244 <groupId>org.opendaylight.yangtools</groupId>
245 <artifactId>features-test</artifactId>
246 <version>0.7.0-SNAPSHOT</version>