Add missing license headers
[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.6.0-SNAPSHOT</version>
27         <relativePath>../odlparent</relativePath>
28     </parent>
29
30     <groupId>org.opendaylight.odlparent</groupId>
31     <artifactId>features-parent</artifactId>
32     <packaging>pom</packaging>
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                       <executions>
53                           <execution>
54                               <phase>generate-resources</phase>
55                               <goals><goal>resolve</goal></goals>
56                               <configuration>
57                                   <outputFile>${project.build.directory}/dependencies.txt</outputFile>
58                               </configuration>
59                           </execution>
60                       </executions>
61                 </plugin>
62                 <plugin>
63                     <groupId>com.alexecollins.maven.plugin</groupId>
64                     <artifactId>script-maven-plugin</artifactId>
65                     <version>1.0.0</version>
66                     <executions>
67                         <execution>
68                         <id>add-version-to-features</id>
69                         <phase>generate-resources</phase>
70                             <goals>
71                                  <goal>execute</goal>
72                             </goals>
73                             <configuration>
74                                 <language>groovy</language>
75                                 <script>
76                                     /**
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}}
83                                      */
84                                     def versionPlaceholder = "{{VERSION}}"
85                                     /**
86                                      * Path to features.xml which uses versionPlaceholder.
87                                      * This will be processed by this script.
88                                      *
89                                      */
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
95                                      * and populates map
96                                      */
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:
101                                         //  - groupId
102                                         //  - artifactId
103                                         //  - Type
104                                         //  - Qualifier (optional)
105                                         //  - Version
106                                         //  - Scope
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]
113                                             }
114                                         }
115                                     }
116
117                                     /*
118                                      * Takes splitted mvn: URL, looks for placeholder
119                                      * and returns new mvn: URL with version learned
120                                      * from dependency plugin.
121                                      *
122                                      * If referenced bundle is not dependency (direct or transitive)
123                                      * throws an exception and fails build.
124                                      *
125                                      */
126                                     def updatedURLFromProject = { args ->
127                                         // 0 - groupID, 1 - artifactID
128                                         // 2 - version, 3 - type, 4 - Classifier
129
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("/")
138                                         }
139                                         throw new IllegalArgumentException("Feature dependency $groupId:$artifactId is not dependecy of project.")
140                                     }
141
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)
148                                             }
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)
153                                             }
154                                         }
155                                     }
156
157                                     def featureFile = new File(project.basedir,featureFilePath)
158                                     def root = new XmlParser().parse(featureFile)
159
160                                     println "[INFO] Updating repository declarations"
161                                     root.repository.each updateMavenDependency
162
163                                     root.feature.each { feature ->
164                                         println "[INFO] Processing feature: ${feature.@name}"
165                                         feature.bundle.each updateMavenDependency
166                                         feature.configfile.each updateMavenDependency
167                                     }
168
169                                     def outDir = new File(project.build.directory,"generated-resources/script")
170                                     outDir.mkdirs();
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)
176                                     outWriter.close();
177                                 </script>
178                             </configuration>
179                         </execution>
180                     </executions>
181                     <dependencies>
182                         <dependency>
183                             <groupId>org.codehaus.groovy</groupId>
184                             <artifactId>groovy</artifactId>
185                             <version>1.8.6</version>
186                         </dependency>
187                     </dependencies>
188                 </plugin>
189                 <plugin>
190                     <groupId>org.apache.karaf.tooling</groupId>
191                     <artifactId>karaf-maven-plugin</artifactId>
192                     <version>${karaf.version}</version>
193                     <extensions>true</extensions>
194                     <executions>
195                         <execution>
196                             <id>features-create-kar</id>
197                             <goals>
198                                 <goal>features-create-kar</goal>
199                             </goals>
200                             <configuration>
201                                 <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
202                             </configuration>
203                         </execution>
204                     </executions>
205                     <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
206                 </plugin>
207                 <plugin>
208                     <groupId>org.codehaus.mojo</groupId>
209                     <artifactId>build-helper-maven-plugin</artifactId>
210                     <executions>
211                         <execution>
212                         <phase>generate-resources</phase>
213                         <goals><goal>add-resource</goal></goals>
214                         <configuration>
215                             <resources>
216                               <resource>
217                                 <directory>${project.build.directory}/generated-resources/script</directory>
218                                 <filtering>true</filtering>
219                               </resource>
220                             </resources>
221                         </configuration>
222                         </execution>
223                         <execution>
224                             <id>attach-artifacts</id>
225                             <phase>package</phase>
226                             <goals>
227                                 <goal>attach-artifact</goal>
228                             </goals>
229                             <configuration>
230                                 <artifacts>
231                                     <artifact>
232                                         <file>${project.build.directory}/classes/${features.file}</file>
233                                         <type>xml</type>
234                                         <classifier>features</classifier>
235                                     </artifact>
236                                 </artifacts>
237                             </configuration>
238                         </execution>
239                     </executions>
240                 </plugin>
241                 <plugin>
242                     <groupId>org.apache.maven.plugins</groupId>
243                     <artifactId>maven-resources-plugin</artifactId>
244                     <executions>
245                         <execution>
246                             <id>filter</id>
247                             <phase>generate-resources</phase>
248                             <goals>
249                                 <goal>resources</goal>
250                             </goals>
251                         </execution>
252                     </executions>
253                 </plugin>
254                 <plugin>
255                     <groupId>org.apache.maven.plugins</groupId>
256                     <artifactId>maven-surefire-plugin</artifactId>
257                     <configuration>
258                         <skip>${skip.karaf.featureTest}</skip>
259                         <dependenciesToScan>
260                             <dependency>org.opendaylight.odlparent:features-test</dependency>
261                         </dependenciesToScan>
262                     </configuration>
263                 </plugin>
264                 <!-- Ignore/Execute plugin execution -->
265                 <plugin>
266                   <groupId>org.eclipse.m2e</groupId>
267                   <artifactId>lifecycle-mapping</artifactId>
268                   <version>1.0.0</version>
269                   <configuration>
270                     <lifecycleMappingMetadata>
271                       <pluginExecutions>
272                         <pluginExecution>
273                           <pluginExecutionFilter>
274                             <groupId>com.alexecollins.maven.plugin</groupId>
275                             <artifactId>script-maven-plugin</artifactId>
276                             <versionRange>[0.0,)</versionRange>
277                             <goals>
278                               <goal>execute</goal>
279                             </goals>
280                           </pluginExecutionFilter>
281                           <action>
282                             <ignore/>
283                           </action>
284                         </pluginExecution>
285                         <pluginExecution>
286                           <pluginExecutionFilter>
287                             <groupId>org.apache.maven.plugins</groupId>
288                             <artifactId>maven-dependency-plugin</artifactId>
289                             <versionRange>[0.0,)</versionRange>
290                             <goals>
291                               <goal>resolve</goal>
292                             </goals>
293                           </pluginExecutionFilter>
294                           <action>
295                             <ignore/>
296                           </action>
297                         </pluginExecution>
298                      </pluginExecutions>
299                    </lifecycleMappingMetadata>
300                   </configuration>
301                 </plugin>
302             </plugins>
303         </pluginManagement>
304
305         <plugins>
306             <plugin>
307                 <artifactId>maven-dependency-plugin</artifactId>
308             </plugin>
309             <plugin>
310                 <groupId>com.alexecollins.maven.plugin</groupId>
311                 <artifactId>script-maven-plugin</artifactId>
312             </plugin>
313             <plugin>
314                 <groupId>org.apache.karaf.tooling</groupId>
315                 <artifactId>karaf-maven-plugin</artifactId>
316             </plugin>
317             <plugin>
318                 <groupId>org.codehaus.mojo</groupId>
319                 <artifactId>build-helper-maven-plugin</artifactId>
320             </plugin>
321             <plugin>
322                 <groupId>org.apache.maven.plugins</groupId>
323                 <artifactId>maven-resources-plugin</artifactId>
324             </plugin>
325             <plugin>
326                 <groupId>org.apache.maven.plugins</groupId>
327                 <artifactId>maven-surefire-plugin</artifactId>
328             </plugin>
329         </plugins>
330     </build>
331
332     <dependencies>
333         <!-- test the features.xml -->
334         <dependency>
335             <groupId>org.opendaylight.odlparent</groupId>
336             <artifactId>features-test</artifactId>
337             <version>1.6.0-SNAPSHOT</version>
338             <scope>test</scope>
339         </dependency>
340     </dependencies>
341 </project>