Merge "Extract common RPM test builder steps to macro"
[releng/builder.git] / jjb / update-p2composite-metadata.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2016 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # If we detect a snapshot build then there is no need to run this script.
13 # YangIDE has indicated that the only want the latest snapshot released to
14 # the snapshot directory.
15 if echo "$P2ZIP_URL" | grep opendaylight.snapshot; then
16     exit 0
17 fi
18 if [[ "$P2ZIP_URL" == "" ]]; then
19     exit 0
20 fi
21
22 EPOCH_DATE=$(date +%s%3N)
23 MVN_METADATA=$(echo "$P2ZIP_URL" | sed 's,/*[^/]\+/*$,,' | sed 's,/*[^/]\+/*$,,')/maven-metadata.xml
24 P2_COMPOSITE_ARTIFACTS=compositeArtifacts.xml
25 P2_COMPOSITE_CONTENT=compositeContent.xml
26
27 wget "$MVN_METADATA" -O maven-metadata.xml
28
29 VERSIONS=$(xmlstarlet sel -t -m "/metadata/versioning/versions" -v "version" maven-metadata.xml)
30 NUM_VERSIONS=$(echo "$VERSIONS" | wc -w)
31
32
33 ##
34 ## Create compositeArtifacts.xml and compositeContent.xml files
35 ##
36
37 cat > $P2_COMPOSITE_ARTIFACTS <<EOF
38 <?xml version='1.0' encoding='UTF-8'?>
39 <?compositeArtifactRepository version='1.0.0'?>
40 <repository name='OpenDaylight $PROJECT'
41     type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository' version='1.0.0'>
42   <properties size='1'>
43     <property name='p2.timestamp' value='$EPOCH_DATE'/>
44   </properties>
45   <children size='$NUM_VERSIONS'>
46 EOF
47
48 cat > $P2_COMPOSITE_CONTENT <<EOF
49 <?xml version='1.0' encoding='UTF-8'?>
50 <?compositeMetadataRepository version='1.0.0'?>
51 <repository name='OpenDaylight $PROJECT'
52     type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'>
53   <properties size='1'>
54     <property name='p2.timestamp' value='$EPOCH_DATE'/>
55   </properties>
56   <children size='$NUM_VERSIONS'>
57 EOF
58
59 ##
60 ## Loop versions
61 ##
62
63 for ver in $VERSIONS
64 do
65     echo "    <child location='$ver'/>" >> $P2_COMPOSITE_ARTIFACTS
66     echo "    <child location='$ver'/>" >> $P2_COMPOSITE_CONTENT
67 done
68
69 ##
70 ## Close files
71 ##
72
73 cat >> $P2_COMPOSITE_ARTIFACTS <<EOF
74   </children>
75 </repository>
76 EOF
77
78 cat >> $P2_COMPOSITE_CONTENT <<EOF
79   </children>
80 </repository>
81 EOF
82
83 ##
84 ## Create poms for uploading
85 ##
86
87 zip composite-repo.zip $P2_COMPOSITE_ARTIFACTS $P2_COMPOSITE_CONTENT
88
89 cat > deploy-composite-repo.xml <<EOF
90 <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">
91   <modelVersion>4.0.0</modelVersion>
92   <groupId>org.opendaylight.$PROJECT</groupId>
93   <artifactId>p2repo</artifactId>
94   <version>1.0.0-SNAPSHOT</version>
95   <packaging>pom</packaging>
96
97   <build>
98     <plugins>
99       <plugin>
100         <groupId>org.apache.maven.plugins</groupId>
101         <artifactId>maven-deploy-plugin</artifactId>
102         <version>2.8.2</version>
103         <configuration>
104           <skip>true</skip>
105         </configuration>
106       </plugin>
107       <plugin>
108         <groupId>org.sonatype.plugins</groupId>
109         <artifactId>maven-upload-plugin</artifactId>
110         <version>0.0.1</version>
111         <executions>
112           <execution>
113             <id>publish-site</id>
114             <phase>deploy</phase>
115             <goals>
116               <goal>upload-file</goal>
117             </goals>
118             <configuration>
119               <serverId>opendaylight-p2</serverId>
120               <repositoryUrl>https://nexus.opendaylight.org/service/local/repositories/p2repos/content-compressed</repositoryUrl>
121               <file>composite-repo.zip</file>
122               <repositoryPath>org.opendaylight.$PROJECT/release</repositoryPath>
123             </configuration>
124           </execution>
125         </executions>
126       </plugin>
127     </plugins>
128   </build>
129 </project>
130 EOF