5ce4ac8a00f7e37e24b59f2a63ae5e0fc2d560c5
[odlparent.git] / features-parent / pom.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- vi: set et smarttab sw=4 tabstop=4: -->
3 <!--
4  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
5
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
9 -->
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
12     <!--
13          Base parent pom for building, packaging and testing Karaf features.
14          Users should do the following:
15
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
20     -->
21
22     <modelVersion>4.0.0</modelVersion>
23     <parent>
24         <groupId>org.opendaylight.odlparent</groupId>
25         <artifactId>odlparent</artifactId>
26         <version>1.8.2-SNAPSHOT</version>
27         <relativePath>../odlparent</relativePath>
28     </parent>
29
30     <artifactId>features-parent</artifactId>
31     <packaging>pom</packaging>
32     <name>ODL :: odlparent :: ${project.artifactId}</name>
33
34     <properties>
35         <features.file>features.xml</features.file>
36         <skip.karaf.featureTest>false</skip.karaf.featureTest>
37     </properties>
38
39     <build>
40         <resources>
41             <resource>
42                 <directory>src/main/resources</directory>
43                 <filtering>true</filtering>
44             </resource>
45         </resources>
46
47         <pluginManagement>
48             <plugins>
49                 <!-- generate dependencies versions -->
50                 <plugin>
51                     <artifactId>maven-dependency-plugin</artifactId>
52                     <version>2.10</version>
53                       <executions>
54                           <execution>
55                               <phase>generate-resources</phase>
56                               <goals><goal>resolve</goal></goals>
57                               <configuration>
58                                   <outputFile>${project.build.directory}/dependencies.txt</outputFile>
59                               </configuration>
60                           </execution>
61                       </executions>
62                 </plugin>
63                 <plugin>
64                     <groupId>com.alexecollins.maven.plugin</groupId>
65                     <artifactId>script-maven-plugin</artifactId>
66                     <version>1.0.0</version>
67                     <executions>
68                         <execution>
69                         <id>add-version-to-features</id>
70                         <phase>generate-resources</phase>
71                             <goals>
72                                  <goal>execute</goal>
73                             </goals>
74                             <configuration>
75                                 <language>groovy</language>
76                                 <script>
77                                     /**
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}}
84                                      */
85                                     def versionPlaceholder = "{{VERSION}}"
86                                     /**
87                                      * Path to features.xml which uses versionPlaceholder.
88                                      * This will be processed by this script.
89                                      *
90                                      */
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
96                                      * and populates map
97                                      */
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:
102                                         //  - groupId
103                                         //  - artifactId
104                                         //  - Type
105                                         //  - Qualifier (optional)
106                                         //  - Version
107                                         //  - Scope
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]
114                                             }
115                                         }
116                                     }
117
118                                     /*
119                                      * Takes splitted mvn: URL, looks for placeholder
120                                      * and returns new mvn: URL with version learned
121                                      * from dependency plugin.
122                                      *
123                                      * If referenced bundle is not dependency (direct or transitive)
124                                      * throws an exception and fails build.
125                                      *
126                                      */
127                                     def updatedURLFromProject = { args ->
128                                         // 0 - groupID, 1 - artifactID
129                                         // 2 - version, 3 - type, 4 - Classifier
130
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("/")
139                                         }
140                                         throw new IllegalArgumentException("Feature dependency $groupId:$artifactId is not a dependency in the project pom.xml.")
141                                     }
142
143                                     def updateMavenDependency = { dep ->
144                                         def mvnUrl = dep.text()
145                                         def prefix = ""
146                                         if (mvnUrl.startsWith("wrap:")) {
147                                             prefix = "wrap:"
148                                             mvnUrl = mvnUrl.substring(5)
149                                         }
150                                         if (mvnUrl.startsWith("mvn:") &amp;&amp; mvnUrl.indexOf(versionPlaceholder) >= 0) {
151                                             // Process property place-holders
152                                             def dollarIndex;
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);
159                                                 } else {
160                                                     println "[WARN] Malformed Maven URL: ${mvnUrl}";
161                                                     break;
162                                                 }
163                                             }
164                                             def components =  mvnUrl.substring(4).split("/")
165                                             if (components[2].startsWith(versionPlaceholder)) {
166                                                 def suffix = "";
167                                                 if (components[2].length() > versionPlaceholder.length()) {
168                                                     suffix = components[2].substring(versionPlaceholder.length())
169                                                     components[2] = versionPlaceholder
170                                                 }
171                                                 dep.value = prefix + updatedURLFromProject(components) + suffix
172                                             }
173                                         }
174                                     }
175
176                                     def featureFile = new File(project.basedir,featureFilePath)
177                                     def root = new XmlParser().parse(featureFile)
178
179                                     println "[INFO] Updating repository declarations"
180                                     root.repository.each updateMavenDependency
181
182                                     root.feature.each { feature ->
183                                         println "[INFO] Processing feature: ${feature.@name}"
184                                         feature.bundle.each updateMavenDependency
185                                         feature.configfile.each updateMavenDependency
186                                     }
187
188                                     def outDir = new File(project.build.directory,"generated-resources/script")
189                                     outDir.mkdirs();
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)
195                                     outWriter.close();
196                                 </script>
197                             </configuration>
198                         </execution>
199                     </executions>
200                     <dependencies>
201                         <dependency>
202                             <groupId>org.codehaus.groovy</groupId>
203                             <artifactId>groovy</artifactId>
204                             <version>1.8.6</version>
205                         </dependency>
206                     </dependencies>
207                 </plugin>
208                 <plugin>
209                     <groupId>org.apache.karaf.tooling</groupId>
210                     <artifactId>karaf-maven-plugin</artifactId>
211                     <version>${karaf.version}</version>
212                     <extensions>true</extensions>
213                     <executions>
214                         <execution>
215                             <id>features-create-kar</id>
216                             <goals>
217                                 <goal>features-create-kar</goal>
218                             </goals>
219                             <configuration>
220                                 <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
221                             </configuration>
222                         </execution>
223                     </executions>
224                     <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
225                 </plugin>
226                 <plugin>
227                     <groupId>org.codehaus.mojo</groupId>
228                     <artifactId>build-helper-maven-plugin</artifactId>
229                     <version>1.12</version>
230                     <executions>
231                         <execution>
232                         <phase>generate-resources</phase>
233                         <goals><goal>add-resource</goal></goals>
234                         <configuration>
235                             <resources>
236                               <resource>
237                                 <directory>${project.build.directory}/generated-resources/script</directory>
238                                 <filtering>true</filtering>
239                               </resource>
240                             </resources>
241                         </configuration>
242                         </execution>
243                         <execution>
244                             <id>attach-artifacts</id>
245                             <phase>package</phase>
246                             <goals>
247                                 <goal>attach-artifact</goal>
248                             </goals>
249                             <configuration>
250                                 <artifacts>
251                                     <artifact>
252                                         <file>${project.build.directory}/classes/${features.file}</file>
253                                         <type>xml</type>
254                                         <classifier>features</classifier>
255                                     </artifact>
256                                 </artifacts>
257                             </configuration>
258                         </execution>
259                     </executions>
260                 </plugin>
261                 <plugin>
262                     <artifactId>maven-resources-plugin</artifactId>
263                     <version>3.0.1</version>
264                     <executions>
265                         <execution>
266                             <id>filter</id>
267                             <phase>generate-resources</phase>
268                             <goals>
269                                 <goal>resources</goal>
270                             </goals>
271                         </execution>
272                     </executions>
273                 </plugin>
274                 <plugin>
275                     <artifactId>maven-surefire-plugin</artifactId>
276                     <version>${maven.surefire.version}</version>
277                     <configuration>
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.2-SNAPSHOT</karaf.distro.version>
284                         </systemPropertyVariables>
285                         <dependenciesToScan>
286                             <dependency>org.opendaylight.odlparent:features-test</dependency>
287                         </dependenciesToScan>
288                     </configuration>
289                 </plugin>
290                 <!-- Ignore/Execute plugin execution -->
291                 <plugin>
292                   <groupId>org.eclipse.m2e</groupId>
293                   <artifactId>lifecycle-mapping</artifactId>
294                   <version>1.0.0</version>
295                   <configuration>
296                     <lifecycleMappingMetadata>
297                       <pluginExecutions>
298                         <pluginExecution>
299                           <pluginExecutionFilter>
300                             <groupId>com.alexecollins.maven.plugin</groupId>
301                             <artifactId>script-maven-plugin</artifactId>
302                             <versionRange>[0.0,)</versionRange>
303                             <goals>
304                               <goal>execute</goal>
305                             </goals>
306                           </pluginExecutionFilter>
307                           <action>
308                             <ignore/>
309                           </action>
310                         </pluginExecution>
311                         <pluginExecution>
312                           <pluginExecutionFilter>
313                             <groupId>org.apache.maven.plugins</groupId>
314                             <artifactId>maven-dependency-plugin</artifactId>
315                             <versionRange>[0.0,)</versionRange>
316                             <goals>
317                               <goal>resolve</goal>
318                             </goals>
319                           </pluginExecutionFilter>
320                           <action>
321                             <ignore/>
322                           </action>
323                         </pluginExecution>
324                      </pluginExecutions>
325                    </lifecycleMappingMetadata>
326                   </configuration>
327                 </plugin>
328             </plugins>
329         </pluginManagement>
330
331         <plugins>
332             <plugin>
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>
337             </plugin>
338             <plugin>
339                 <artifactId>maven-dependency-plugin</artifactId>
340             </plugin>
341             <plugin>
342                 <groupId>com.alexecollins.maven.plugin</groupId>
343                 <artifactId>script-maven-plugin</artifactId>
344             </plugin>
345             <plugin>
346                 <groupId>org.apache.karaf.tooling</groupId>
347                 <artifactId>karaf-maven-plugin</artifactId>
348             </plugin>
349             <plugin>
350                 <groupId>org.codehaus.mojo</groupId>
351                 <artifactId>build-helper-maven-plugin</artifactId>
352             </plugin>
353             <plugin>
354                 <artifactId>maven-resources-plugin</artifactId>
355             </plugin>
356             <plugin>
357                 <artifactId>maven-surefire-plugin</artifactId>
358             </plugin>
359         </plugins>
360     </build>
361
362     <dependencies>
363         <!-- test the features.xml -->
364         <dependency>
365             <groupId>org.opendaylight.odlparent</groupId>
366             <artifactId>features-test</artifactId>
367             <version>1.8.2-SNAPSHOT</version>
368             <scope>test</scope>
369         </dependency>
370         <!-- Remove this dependency when a better fix for Bug 6523 appears. -->
371         <dependency>
372             <groupId>org.opendaylight.odlparent</groupId>
373             <artifactId>opendaylight-karaf-empty</artifactId>
374             <version>1.8.2-SNAPSHOT</version>
375             <type>zip</type>
376             <scope>test</scope>
377         </dependency>
378     </dependencies>
379
380   <!--
381     Maven Site Configuration
382
383     The following configuration is necessary for maven-site-plugin to
384     correctly identify the correct deployment path for OpenDaylight Maven
385     sites.
386   -->
387   <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
388
389   <distributionManagement>
390     <site>
391       <id>opendaylight-site</id>
392       <url>${nexus.site.url}/${project.artifactId}/</url>
393     </site>
394   </distributionManagement>
395 </project>