JDK11 upgrade
[ccsdk/cds.git] / components / model-catalog / blueprint-model / test-blueprint-kotlin-parent / pom.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3   ~ Copyright © 2020 Bell Canada
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
18 <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">
19     <modelVersion>4.0.0</modelVersion>
20
21     <parent>
22         <groupId>org.onap.ccsdk.cds.cba</groupId>
23         <artifactId>blueprint-model</artifactId>
24         <version>1.0.0-SNAPSHOT</version>
25     </parent>
26
27     <artifactId>test-blueprint-kotlin-parent</artifactId>
28     <version>1.0.0-SNAPSHOT</version>
29     <packaging>pom</packaging>
30
31     <name>CBA - Test Kotlin scripts</name>
32     <description>CBA - Test Kotlin scripts</description>
33
34     <dependencies>
35         <dependency>
36             <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
37             <artifactId>execution-service</artifactId>
38         </dependency>
39         <dependency>
40             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
41             <artifactId>resource-resolution</artifactId>
42         </dependency>
43         <dependency>
44             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
45             <artifactId>netconf-executor</artifactId>
46         </dependency>
47         <dependency>
48             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
49             <artifactId>cli-executor</artifactId>
50         </dependency>
51         <dependency>
52             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
53             <artifactId>message-prioritizaion</artifactId>
54         </dependency>
55         <dependency>
56             <groupId>org.jetbrains.kotlin</groupId>
57             <artifactId>kotlin-test-junit</artifactId>
58             <scope>test</scope>
59         </dependency>
60         <dependency>
61             <groupId>org.jetbrains.kotlinx</groupId>
62             <artifactId>kotlinx-coroutines-test</artifactId>
63             <scope>test</scope>
64         </dependency>
65
66         <dependency>
67             <groupId>junit</groupId>
68             <artifactId>junit</artifactId>
69             <version>4.12</version>
70             <scope>test</scope>
71         </dependency>
72         <dependency>
73             <groupId>io.mockk</groupId>
74             <artifactId>mockk</artifactId>
75             <version>1.10.0</version>
76             <scope>test</scope>
77         </dependency>
78         <dependency>
79             <groupId>com.squareup.okhttp3</groupId>
80             <artifactId>okhttp</artifactId>
81             <version>3.14.0</version>
82         </dependency>
83     </dependencies>
84
85     <build>
86         <sourceDirectory>${project.basedir}/Scripts/kotlin</sourceDirectory>
87         <testSourceDirectory>${project.basedir}/Tests/kotlin</testSourceDirectory>
88         <resources>
89             <resource>
90                 <directory>${project.basedir}/Environments</directory>
91             </resource>
92         </resources>
93         <plugins>
94             <plugin>
95                 <artifactId>maven-antrun-plugin</artifactId>
96                 <executions>
97                     <execution>
98                         <id>validate-kotlin</id>
99                         <phase>validate</phase>
100                         <configuration>
101                             <target name="ktlint">
102                                 <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
103                                     <arg value="Scripts/kotlin/**/*.kt"/>
104                                 </java>
105                             </target>
106                             <skip>${format.skipValidate}</skip>
107                         </configuration>
108                         <goals>
109                             <goal>run</goal>
110                         </goals>
111                     </execution>
112                     <execution>
113                         <!-- Built-in formatter So that you wouldn't have to fix all style violations by hand.-->
114                         <id>format-kotlin</id>
115                         <phase>process-sources</phase>
116                         <configuration>
117                             <target name="ktlint">
118                                 <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
119                                     <arg value="-F"/>
120                                     <arg value="Scripts/kotlin/**/*.kt"/>
121                                 </java>
122                             </target>
123                             <skip>${format.skipExecute}</skip>
124                         </configuration>
125                         <goals>
126                             <goal>run</goal>
127                         </goals>
128                     </execution>
129                 </executions>
130             </plugin>
131             <plugin>
132                 <groupId>org.jacoco</groupId>
133                 <artifactId>jacoco-maven-plugin</artifactId>
134                 <executions>
135                     <execution>
136                         <id>pre-unit-test</id>
137                         <phase>none</phase>
138                     </execution>
139                     <execution>
140                         <id>default-prepare-agent</id>
141                         <phase>none</phase>
142                     </execution>
143                     <execution>
144                         <id>post-unit-test</id>
145                         <phase>none</phase>
146                     </execution>
147                     <execution>
148                         <id>default-report</id>
149                         <phase>none</phase>
150                     </execution>
151                     <execution>
152                         <id>pre-integration-test</id>
153                         <phase>none</phase>
154                     </execution>
155                     <execution>
156                         <id>post-integration-test</id>
157                         <phase>none</phase>
158                     </execution>
159                     <execution>
160                         <id>default-check</id>
161                         <phase>none</phase>
162                     </execution>
163                 </executions>
164             </plugin>
165             <plugin>
166                 <groupId>org.jetbrains.kotlin</groupId>
167                 <artifactId>kotlin-maven-plugin</artifactId>
168                 <executions>
169                     <execution>
170                         <id>compile</id>
171                         <phase>compile</phase>
172                         <goals>
173                             <goal>compile</goal>
174                         </goals>
175                         <configuration>
176                             <sourceDirs>
177                                 <sourceDir>${project.basedir}/Scripts/kotlin</sourceDir>
178                             </sourceDirs>
179                         </configuration>
180                     </execution>
181                     <execution>
182                         <id>test-compile</id>
183                         <phase>test-compile</phase>
184                         <goals>
185                             <goal>test-compile</goal>
186                         </goals>
187                         <configuration>
188                             <sourceDirs>
189                                 <sourceDir>${project.basedir}/Tests/kotlin</sourceDir>
190                             </sourceDirs>
191                         </configuration>
192                     </execution>
193                 </executions>
194             </plugin>
195             <plugin>
196                 <groupId>org.apache.maven.plugins</groupId>
197                 <artifactId>maven-site-plugin</artifactId>
198                 <executions>
199                     <execution>
200                         <id>attach-descriptor</id>
201                         <phase>none</phase>
202                     </execution>
203                 </executions>
204             </plugin>
205             <plugin>
206                 <artifactId>maven-checkstyle-plugin</artifactId>
207                 <executions>
208                     <execution>
209                         <id>check-license</id>
210                         <phase>none</phase>
211                     </execution>
212                     <execution>
213                         <id>check-style</id>
214                         <phase>none</phase>
215                     </execution>
216                 </executions>
217             </plugin>
218             <plugin>
219                 <artifactId>maven-assembly-plugin</artifactId>
220                 <dependencies>
221                     <dependency>
222                         <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
223                         <artifactId>cba-assembly-descriptor</artifactId>
224                         <version>1.0.0-SNAPSHOT</version>
225                         <exclusions>
226                             <exclusion>
227                                 <groupId>*</groupId>
228                                 <artifactId>*</artifactId>
229                             </exclusion>
230                         </exclusions>
231                     </dependency>
232                 </dependencies>
233                 <executions>
234                     <execution>
235                         <id>make-assembly</id>
236                         <phase>package</phase>
237                         <goals>
238                             <goal>single</goal>
239                         </goals>
240                         <configuration>
241                             <descriptorRefs>
242                                 <descriptorRef>cba_zip</descriptorRef>
243                             </descriptorRefs>
244                         </configuration>
245                     </execution>
246                 </executions>
247             </plugin>
248         </plugins>
249     </build>
250
251     <profiles>
252         <profile>
253             <id>deploy-cba</id>
254             <build>
255                 <plugins>
256                     <plugin>
257                         <groupId>org.codehaus.gmaven</groupId>
258                         <artifactId>groovy-maven-plugin</artifactId>
259                         <dependencies>
260                             <dependency>
261                                 <groupId>com.squareup.okhttp3</groupId>
262                                 <artifactId>okhttp</artifactId>
263                                 <version>3.14.0</version>
264                             </dependency>
265                             <dependency>
266                                 <groupId>commons-io</groupId>
267                                 <artifactId>commons-io</artifactId>
268                                 <version>${commons-io-version}</version>
269                             </dependency>
270                         </dependencies>
271                         <executions>
272                             <execution>
273                                 <id>deploy-cba</id>
274                                 <phase>install</phase>
275                                 <goals>
276                                     <goal>execute</goal>
277                                 </goals>
278                                 <configuration>
279                                     <source>
280                                         import okhttp3.Credentials
281                                         import okhttp3.MediaType
282                                         import okhttp3.MultipartBody
283                                         import okhttp3.OkHttpClient
284                                         import okhttp3.Request
285                                         import okhttp3.RequestBody
286                                         import org.apache.commons.io.IOUtils
287
288                                         import java.io.File
289
290                                         target = "${basedir.absolutePath}/target"
291                                         userName = throwIfPropMissing('cds.username')
292                                         password = throwIfPropMissing('cds.password')
293                                         protocol = properties['cds.protocol'] ?: 'http'
294                                         host = properties['cds.host'] ?: 'localhost'
295                                         port = properties['cds.port'] ?: '8081'
296
297                                         def cba = "${project.artifact.artifactId}-${project.artifact.version}-cba.zip"
298                                         def enrichedCba = "${project.artifact.artifactId}-${project.artifact.version}-enriched-cba.zip"
299                                         def enrichEndpoint = properties['cds.enrich.endpoint'] ?: 'api/v1/blueprint-model/enrich'
300                                         def publishEndpoint = properties['cds.publish.endpoint'] ?: 'api/v1/blueprint-model/publish'
301
302                                         def throwIfPropMissing(prop) {
303                                             value = properties[prop]
304                                             if (!value || "".equals(value)) {
305                                                 throw new RuntimeException("Property missing: $prop")
306                                             }
307                                             return value
308                                         }
309
310                                         def buildRequest(endpoint, fileName) {
311                                             body = new MultipartBody.Builder()
312                                               .setType(MultipartBody.FORM)
313                                               .addFormDataPart("file",
314                                                 fileName,
315                                                 RequestBody.create(MediaType.parse('application/zip'), new File(target, fileName)))
316                                               .build()
317
318                                             return new Request.Builder()
319                                               .url("$protocol://$host:$port/$endpoint")
320                                               .addHeader('Authorization', Credentials.basic(userName, password))
321                                               .post(body)
322                                               .build()
323                                         }
324
325                                         def logAndThrow(msg) {
326                                             if(response) {
327                                                 log.error(response.body().string())
328                                             }
329                                             throw new RuntimeException(msg)
330                                         }
331
332                                         response = null
333                                         try {
334                                             def client = new OkHttpClient()
335
336                                             response = client.newCall(buildRequest(enrichEndpoint, cba)).execute()
337                                             if (!response || !response.isSuccessful()) {
338                                                 logAndThrow("Failed to enrich CBA")
339                                             }
340
341                                             IOUtils.copy(
342                                               response.body().byteStream(),
343                                               new FileOutputStream(new File(target, enrichedCba))
344                                             )
345                                             log.info("Created enriched cba: $enrichedCba")
346
347                                             response = client.newCall(buildRequest(publishEndpoint, enrichedCba)).execute()
348                                             if (!response || !response.isSuccessful()) {
349                                                 logAndThrow("Failed to publish CBA")
350                                             }
351
352                                             log.info("CBA Deployed")
353                                             log.info(response.body().string())
354                                         } finally {
355                                             if (response) {
356                                                 response.close()
357                                             }
358                                         }
359                                     </source>
360                                 </configuration>
361                             </execution>
362                         </executions>
363                     </plugin>
364                 </plugins>
365             </build>
366         </profile>
367     </profiles>
368 </project>