pom.xml revision 6c3f614e
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3  ~ Copyright (c) 2016 Cisco and/or its affiliates.
4  ~
5  ~ Licensed under the Apache License, Version 2.0 (the "License");
6  ~ you may not use this file except in compliance with the License.
7  ~ You may obtain a copy of the License at:
8  ~
9  ~     http://www.apache.org/licenses/LICENSE-2.0
10  ~
11  ~ Unless required by applicable law or agreed to in writing, software
12  ~ distributed under the License is distributed on an "AS IS" BASIS,
13  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ~ See the License for the specific language governing permissions and
15  ~ limitations under the License.
16  -->
17<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19
20    <parent>
21        <groupId>io.fd.honeycomb.common</groupId>
22        <artifactId>impl-parent</artifactId>
23        <version>1.16.12-SNAPSHOT</version>
24        <relativePath>../impl-parent</relativePath>
25    </parent>
26
27    <modelVersion>4.0.0</modelVersion>
28    <artifactId>minimal-distribution-parent</artifactId>
29    <name>${project.artifactId}</name>
30    <version>1.16.12-SNAPSHOT</version>
31    <packaging>pom</packaging>
32
33    <properties>
34        <start.script.template>
35#!/bin/sh -
36STATUS=100
37
38while [ $STATUS -eq 100 ]
39do
40  %s
41  STATUS=$?
42  echo "Honeycomb exited with status: $STATUS"
43  if [ $STATUS -eq 100 ]
44  then
45    echo "Restarting..."
46  fi
47done
48        </start.script.template>
49        <exec.parameters>-Xms32m -Xmx128m -XX:MetaspaceSize=32m -XX:MaxMetaspaceSize=128m</exec.parameters>
50        <exec.parameters.minimal>-client -Xms20m -Xmx32m -XX:MetaspaceSize=5m -XX:MaxMetaspaceSize=32m -XX:MaxMetaspaceExpansion=1m -Xss512k -XX:+UseSerialGC -Djava.compiler=NONE -Xverify:none -noverify</exec.parameters.minimal>
51        <debug.parameters>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</debug.parameters>
52
53        <!-- Jersey versions to run RESTCONF-->
54        <jersey.version>1.19.1</jersey.version>
55        <jetty.version>9.3.11.v20160721</jetty.version>
56        <servlet.version>3.1.0</servlet.version>
57        <!-- Used by mdsal as provided/runtime dependency-->
58        <osgi.core.version>5.0.0</osgi.core.version>
59        <!-- Use /dev/urandom instead of /dev/random during tests to speed up execution
60            http://stackoverflow.com/questions/137212/how-to-solve-performance-problem-with-java-securerandom
61        -->
62        <random.seed.file>/dev/./urandom</random.seed.file>
63        <no.modules.defined.message>// This distribution does not define any own modules.
64// In order to do so either distribution.modules property must be defined in distribution pom.xml,
65// containing list of desired modules to start, or this file can be directly edited with same effect.
66//
67// Note : Modules should be referenced by full class name, for ex.: io.fd.test.SampleModule, and separated with comma.
68        </no.modules.defined.message>
69    </properties>
70
71    <dependencyManagement>
72        <dependencies>
73            <!-- Jersey + Jetty for RESTCONF -->
74            <dependency>
75                <groupId>org.eclipse.jetty</groupId>
76                <artifactId>jetty-server</artifactId>
77                <version>${jetty.version}</version>
78            </dependency>
79            <dependency>
80                <groupId>javax.servlet</groupId>
81                <artifactId>javax.servlet-api</artifactId>
82                <version>${servlet.version}</version>
83            </dependency>
84            <dependency>
85                <groupId>org.eclipse.jetty</groupId>
86                <artifactId>jetty-webapp</artifactId>
87                <version>${jetty.version}</version>
88            </dependency>
89            <dependency>
90                <groupId>org.eclipse.jetty</groupId>
91                <artifactId>jetty-servlets</artifactId>
92                <version>${jetty.version}</version>
93            </dependency>
94            <dependency>
95                <groupId>com.sun.jersey</groupId>
96                <artifactId>jersey-server</artifactId>
97                <version>${jersey.version}</version>
98            </dependency>
99            <dependency>
100                <groupId>com.sun.jersey</groupId>
101                <artifactId>jersey-core</artifactId>
102                <version>${jersey.version}</version>
103            </dependency>
104            <dependency>
105                <groupId>com.sun.jersey</groupId>
106                <artifactId>jersey-servlet</artifactId>
107                <version>${jersey.version}</version>
108            </dependency>
109            <!-- OSGI Even tough not running in OSGI, dependency needs to be here since some deprecated MD-SAL APIs rely on osgi core -->
110            <dependency>
111                <groupId>org.osgi</groupId>
112                <artifactId>org.osgi.core</artifactId>
113                <version>${osgi.core.version}</version>
114            </dependency>
115        </dependencies>
116    </dependencyManagement>
117
118    <!-- Generate executable shell script -->
119    <build>
120        <pluginManagement>
121            <plugins>
122                <plugin>
123                    <groupId>org.apache.maven.plugins</groupId>
124                    <artifactId>maven-jar-plugin</artifactId>
125                    <version>2.6</version>
126                    <configuration>
127                        <archive>
128                            <manifest>
129                                <mainClass>${main.class}</mainClass>
130                                <addClasspath>true</addClasspath>
131                                <classpathPrefix>lib/</classpathPrefix>
132                                <useUniqueVersions>false</useUniqueVersions>
133                                <classpathMavenRepositoryLayout>true</classpathMavenRepositoryLayout>
134                            </manifest>
135                            <manifestEntries>
136                                <Class-Path>config/ cert/ modules/</Class-Path>
137                            </manifestEntries>
138                        </archive>
139                    </configuration>
140                </plugin>
141
142                <!-- Copy all dependencies -->
143                <plugin>
144                    <groupId>org.apache.maven.plugins</groupId>
145                    <artifactId>maven-dependency-plugin</artifactId>
146                    <version>2.10</version>
147                    <executions>
148                        <execution>
149                            <id>copy-dependencies</id>
150                            <phase>package</phase>
151                            <goals>
152                                <goal>copy-dependencies</goal>
153                            </goals>
154                            <configuration>
155                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
156                                <useBaseVersion>true</useBaseVersion>
157                                <useRepositoryLayout>true</useRepositoryLayout>
158                                <excludeArtifactIds>yang-jmx-generator</excludeArtifactIds>
159                            </configuration>
160                        </execution>
161                        <execution>
162                            <id>unpack-configuration</id>
163                            <phase>prepare-package</phase>
164                            <goals>
165                                <goal>unpack-dependencies</goal>
166                            </goals>
167                            <configuration>
168                                <includes>**/honeycomb-minimal-resources/</includes>
169                                <outputDirectory>${project.build.outputDirectory}/</outputDirectory>
170                            </configuration>
171                        </execution>
172                    </executions>
173                </plugin>
174
175                <!-- Generate shell script -->
176                <!-- Extract modules started by distribution -->
177                <plugin>
178                    <groupId>org.codehaus.gmaven</groupId>
179                    <artifactId>groovy-maven-plugin</artifactId>
180                    <executions>
181                        <execution>
182                            <id>start-scripts-generation</id>
183                            <phase>package</phase>
184                            <goals>
185                                <goal>execute</goal>
186                            </goals>
187                            <configuration>
188                                <!-- TODO HONEYCOMB-157 Make scripts more robust -->
189                                <source>
190                                    import java.nio.file.Paths
191
192                                    log.info "Generating shell exec script"
193                                    def scriptTemplate = properties.getOrDefault("start.script.template", "")
194                                    def args = properties.getOrDefault("exec.parameters", "")
195                                    log.debug "Additional shell exec script properties: ${args}"
196                                    def javaArgs = "${args} -jar \$(dirname \$0)/${project.artifactId}-${project.version}.jar"
197                                    def scriptParent = Paths.get(project.build.outputDirectory, "honeycomb-minimal-resources")
198                                    scriptParent.toFile().mkdirs()
199                                    def scriptContent = "java " + javaArgs
200                                    log.info "Generating shell exec script as ${scriptContent}"
201                                    def scriptPath = Paths.get(scriptParent.toString(), "honeycomb")
202                                    log.info "Writing shell exec script to ${scriptPath}"
203                                    scriptPath.toFile().text = String.format(scriptTemplate, scriptContent)
204                                    scriptPath.toFile().setExecutable(true)
205
206                                    scriptPath = Paths.get(scriptParent.toString(), "honeycomb-start")
207                                    log.info "Writing shell exec script to ${scriptPath}"
208                                    scriptPath.toFile().text = "\$(dirname \$0)/honeycomb &amp;"
209                                    scriptPath.toFile().setExecutable(true)
210
211                                    def debug_args = properties.getOrDefault("debug.parameters", "")
212                                    def debugScriptContent = "java" + " ${debug_args} " + javaArgs
213                                    log.info "Generating shell debug script as ${debugScriptContent}"
214                                    scriptPath = Paths.get(scriptParent.toString(), "honeycomb-debug")
215                                    log.info "Writing shell debug script to ${scriptPath}"
216                                    scriptPath.toFile().text = String.format(scriptTemplate, debugScriptContent)
217                                    scriptPath.toFile().setExecutable(true)
218                                </source>
219                            </configuration>
220                        </execution>
221                        <execution>
222                            <id>distribution-module-assembly</id>
223                            <!-- phase changed from package to earlier phase to generate module descriptor before distribution jar is created,
224                             to include descriptor in the jar,to be accessible to children distributions-->
225                            <phase>prepare-package</phase>
226                            <goals>
227                                <goal>execute</goal>
228                            </goals>
229                            <configuration>
230                                <source>import java.nio.file.Paths
231                                import java.nio.file.Files
232
233                                // module configuration file extraction
234                                // builds project name from group,artifact and version to prevent overwriting
235                                // while building multiple distribution project
236                                def artifact = project.getArtifact()
237                                def projectName = "${artifact.getGroupId()}_${artifact.getArtifactId()}_${artifact.getVersion()}".replace(".","-")
238                                log.info "Generating list of modules started by distribution ${projectName}"
239
240                                def activeModules = properties.getProperty("distribution.modules", "")
241                                        .tokenize(",")
242                                        .collect { module -> module.trim() }
243
244                                log.info "Project ${projectName} : Found modules ${activeModules}"
245                                //creates folder modules
246
247                                def outputPath = Paths.get(project.build.outputDirectory, "honeycomb-minimal-resources", "modules")
248                                //creates module folder
249                                outputPath.toFile().mkdirs()
250
251                                def outputFile = Paths.get(outputPath.toString(), "${projectName}_module-config.txt").toFile()
252                                outputFile.createNewFile();
253                                log.info("Writing module configuration for distribution ${projectName} to ${outputPath}")
254
255                                if (activeModules.isEmpty()) {
256                                    outputFile.text = properties.getProperty("no.modules.defined.message")
257                                } else {
258                                    outputFile.text = activeModules.join(System.lineSeparator)
259                                }
260                                </source>
261                            </configuration>
262                        </execution>
263                    </executions>
264                </plugin>
265
266                <!-- Build archives -->
267                <plugin>
268                    <artifactId>maven-assembly-plugin</artifactId>
269                    <version>2.5.3</version>
270                    <dependencies>
271                        <dependency>
272                            <groupId>io.fd.honeycomb.common</groupId>
273                            <artifactId>minimal-assembly-descriptor</artifactId>
274                            <version>1.16.12-SNAPSHOT</version>
275                        </dependency>
276                    </dependencies>
277                    <executions>
278                        <execution>
279                            <id>create-archive</id>
280                            <phase>package</phase>
281                            <goals>
282                                <goal>single</goal>
283                            </goals>
284                            <configuration>
285                                <descriptorRefs>
286                                    <descriptorRef>honeycomb-minimal</descriptorRef>
287                                </descriptorRefs>
288                            </configuration>
289                        </execution>
290                    </executions>
291                </plugin>
292
293                <plugin>
294                    <artifactId>maven-surefire-plugin</artifactId>
295                    <configuration>
296                        <!--http://stackoverflow.com/questions/18107375/getting-skipping-jacoco-execution-due-to-missing-execution-data-file-upon-exec-->
297                        <argLine>${argLine} -Djava.security.egd=file:${random.seed.file}</argLine>
298                    </configuration>
299                </plugin>
300            </plugins>
301        </pluginManagement>
302        <plugins>
303            <plugin>
304                <groupId>org.codehaus.gmaven</groupId>
305                <artifactId>groovy-maven-plugin</artifactId>
306            </plugin>
307            <plugin>
308                <groupId>org.apache.maven.plugins</groupId>
309                <artifactId>maven-jar-plugin</artifactId>
310            </plugin>
311            <plugin>
312                <groupId>org.apache.maven.plugins</groupId>
313                <artifactId>maven-dependency-plugin</artifactId>
314            </plugin>
315            <plugin>
316                <artifactId>maven-assembly-plugin</artifactId>
317            </plugin>
318        </plugins>
319    </build>
320</project>
321