Bug 568768 - [Releng] Update broken build setup

- Add jenkins and publish scripts
- Fix missing cbi reference

Change-Id: I852111f8c21dc7a2cb4568956e17adbed629280e
Signed-off-by: Quentin Le Menez <quentin.lemenez@cea.fr>
diff --git a/pom.xml b/pom.xml
index 09c8fa9..4ddb2ab 100755
--- a/pom.xml
+++ b/pom.xml
@@ -33,9 +33,10 @@
 		<maven.compiler.version>3.7.0</maven.compiler.version>
 		<java.source.version>1.8</java.source.version>
 		<java.target.version>1.8</java.target.version>
-		
+
 		<!-- https://repo.eclipse.org/content/repositories/cbi-releases/ -->
-		<jarSignerVersion>1.1.7</jarSignerVersion>
+		<jarSignerVersion>1.1.5</jarSignerVersion>
+		<tycho.scmUrl>scm:git:git://git.eclipse.org/gitroot/papyrus/org.eclipse.papyrus-requirements.git</tycho.scmUrl>
 	</properties>
 
 	<!-- Children modules to build -->
@@ -46,13 +47,9 @@
 		<!-- <module>tests</module> -->
 	</modules>
 
-	<scm>
-		<url>https://git.eclipse.org/c/papyrus/org.eclipse.papyrus-requirements.git</url>
-		<connection>scm:git:git://git.eclipse.org/gitroot/papyrus/org.eclipse.papyrus-requirements.git</connection>
-	</scm>
-
 	<pluginRepositories>
-		<pluginRepository>
+		<!-- https://repo.maven.apache.org/maven2/ is being fetched by default -->
+		<!-- pluginRepository>
 			<id>central</id>
 			<name>Central Repository</name>
 			<url>https://repo.maven.apache.org/maven2</url>
@@ -62,6 +59,17 @@
 			<snapshots>
 				<enabled>false</enabled>
 			</snapshots>
+		</pluginRepository -->
+		<pluginRepository>
+			<id>org.eclipse.cbi.maven.plugins</id>
+			<name>Eclipse CBI</name>
+			<url>https://repo.eclipse.org/content/repositories/cbi-releases/</url>
+			<releases>
+				<enabled>true</enabled>
+			</releases>
+			<snapshots>
+				<enabled>false</enabled>
+			</snapshots>
 		</pluginRepository>
 		<pluginRepository>
 			<id>tycho-snapshots</id>
@@ -93,6 +101,11 @@
 				<artifactId>maven-clean-plugin</artifactId>
 				<version>${maven.clean.version}</version>
 			</plugin>
+			<plugin>
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-p2-repository-plugin</artifactId>
+				<version>${tycho.version}</version>
+			</plugin>
 
 			<!-- Integration between Tycho and Maven -->
 			<plugin>
@@ -115,6 +128,52 @@
 				</configuration>
 			</plugin>
 
+			<!-- Sources -->
+			<plugin>
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-source-plugin</artifactId>
+				<version>${tycho.version}</version>
+				<executions>
+					<execution>
+						<id>plugin-source</id>
+						<goals>
+							<goal>plugin-source</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.eclipse.tycho.extras</groupId>
+				<artifactId>tycho-source-feature-plugin</artifactId>
+				<version>${tychoExtrasVersion}</version>
+				<executions>
+					<execution>
+						<id>source-feature</id>
+						<phase>package</phase>
+						<goals>
+							<goal>source-feature</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-packaging-plugin</artifactId>
+				<version>${tycho.version}</version>
+				<configuration>
+					<sourceReferences>
+						<generate>true</generate>
+					</sourceReferences>
+				</configuration>
+				<dependencies>
+					<dependency>
+						<groupId>org.eclipse.tycho.extras</groupId>
+						<artifactId>tycho-sourceref-jgit</artifactId>
+						<version>${tychoExtrasVersion}</version>
+					</dependency>
+				</dependencies>
+			</plugin>
+
 			<plugin>
 				<groupId>org.eclipse.tycho</groupId>
 				<artifactId>target-platform-configuration</artifactId>
@@ -144,4 +203,150 @@
 		</plugins>
 	</build>
 
+
+	<profiles>
+		<profile>
+			<id>defaultProfile</id>
+			<activation>
+				<activeByDefault>true</activeByDefault>
+			</activation>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.eclipse.tycho</groupId>
+						<artifactId>tycho-p2-plugin</artifactId>
+						<version>${tycho.version}</version>
+						<executions>
+							<execution>
+								<id>attach-p2-metadata</id>
+								<phase>package</phase>
+								<goals>
+									<goal>p2-metadata</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+
+		<!-- Stable release profile. Eclipse servers only -->
+		<profile>
+			<id>packAndSign</id>
+			<activation>
+				<property>
+					<name>SIGN</name>
+					<value>true</value>
+				</property>
+			</activation>
+			<!-- Pack200 -->
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.eclipse.tycho.extras</groupId>
+						<artifactId>tycho-pack200a-plugin</artifactId>
+						<version>${tychoExtrasVersion}</version>
+						<executions>
+							<execution>
+								<id>pack200-normalize</id>
+								<goals>
+									<goal>normalize</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
+						<groupId>org.eclipse.cbi.maven.plugins</groupId>
+						<artifactId>eclipse-jarsigner-plugin</artifactId>
+						<version>${jarSignerVersion}</version>
+						<executions>
+							<execution>
+								<id>sign</id>
+								<goals>
+									<goal>sign</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
+						<groupId>org.eclipse.tycho.extras</groupId>
+						<artifactId>tycho-pack200b-plugin</artifactId>
+						<version>${tychoExtrasVersion}</version>
+						<executions>
+							<execution>
+								<id>pack200-pack</id>
+								<goals>
+									<goal>pack</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
+						<groupId>org.eclipse.tycho</groupId>
+						<artifactId>tycho-p2-plugin</artifactId>
+						<version>${tycho.version}</version>
+						<executions>
+							<execution>
+								<id>attach-p2-metadata</id>
+								<phase>package</phase>
+								<goals>
+									<goal>p2-metadata</goal>
+								</goals>
+							</execution>
+						</executions>
+						<configuration>
+							<defaultP2Metadata>false</defaultP2Metadata>
+						</configuration>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+
+		<!-- Nightly profile. Artifacts can be consumed, but are not signed -->
+		<profile>
+			<id>pack</id>
+			<activation>
+				<property>
+					<name>SIGN</name>
+					<value>false</value>
+				</property>
+			</activation>
+			<build>
+				<plugins>
+					<!-- Pack200 -->
+					<plugin>
+						<groupId>org.eclipse.tycho.extras</groupId>
+						<artifactId>tycho-pack200b-plugin</artifactId>
+						<version>${tychoExtrasVersion}</version>
+						<executions>
+							<execution>
+								<id>pack200-pack</id>
+								<goals>
+									<goal>pack</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
+						<groupId>org.eclipse.tycho</groupId>
+						<artifactId>tycho-p2-plugin</artifactId>
+						<version>${tycho.version}</version>
+						<executions>
+							<execution>
+								<id>attach-p2-metadata</id>
+								<phase>package</phase>
+								<goals>
+									<goal>p2-metadata</goal>
+								</goals>
+							</execution>
+						</executions>
+						<configuration>
+							<defaultP2Metadata>false</defaultP2Metadata>
+						</configuration>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+
 </project>	
diff --git a/releng/org.eclipse.papyrus.requirements.p2/pom.xml b/releng/org.eclipse.papyrus.requirements.p2/pom.xml
index e1e36a2..aa1a00c 100755
--- a/releng/org.eclipse.papyrus.requirements.p2/pom.xml
+++ b/releng/org.eclipse.papyrus.requirements.p2/pom.xml
@@ -15,5 +15,5 @@
 	<artifactId>org.eclipse.papyrus.requirements.releng.p2</artifactId>
 	<name>Requirements update site</name>
 	<packaging>eclipse-repository</packaging>
-
+	
 </project>
\ No newline at end of file
diff --git a/releng/pom.xml b/releng/pom.xml
index 151bda7..d1a0b5d 100755
--- a/releng/pom.xml
+++ b/releng/pom.xml
@@ -23,199 +23,4 @@
 		<module>targetplatforms</module>
 	</modules>
 
-	<build>
-		<plugins>
-			<!-- Sources -->
-			<plugin>
-				<groupId>org.eclipse.tycho</groupId>
-				<artifactId>tycho-source-plugin</artifactId>
-				<version>${tycho.version}</version>
-				<executions>
-					<execution>
-						<id>plugin-source</id>
-						<goals>
-							<goal>plugin-source</goal>
-						</goals>
-					</execution>
-				</executions>
-			</plugin>
-			<plugin>
-				<groupId>org.eclipse.tycho.extras</groupId>
-				<artifactId>tycho-source-feature-plugin</artifactId>
-				<version>${tychoExtrasVersion}</version>
-				<executions>
-					<execution>
-						<id>source-feature</id>
-						<phase>package</phase>
-						<goals>
-							<goal>source-feature</goal>
-						</goals>
-					</execution>
-				</executions>
-			</plugin>
-			<plugin>
-				<groupId>org.eclipse.tycho</groupId>
-				<artifactId>tycho-packaging-plugin</artifactId>
-				<version>${tycho.version}</version>
-				<configuration>
-					<sourceReferences>
-						<generate>true</generate>
-					</sourceReferences>
-				</configuration>
-				<dependencies>
-					<dependency>
-						<groupId>org.eclipse.tycho.extras</groupId>
-						<artifactId>tycho-sourceref-jgit</artifactId>
-						<version>${tychoExtrasVersion}</version>
-					</dependency>
-				</dependencies>
-			</plugin>
-		</plugins>
-	</build>
-
-	<profiles>
-		<profile>
-			<id>defaultProfile</id>
-			<activation>
-				<activeByDefault>true</activeByDefault>
-			</activation>
-			<build>
-				<plugins>
-					<plugin>
-						<groupId>org.eclipse.tycho</groupId>
-						<artifactId>tycho-p2-plugin</artifactId>
-						<version>${tycho.version}</version>
-						<executions>
-							<execution>
-								<id>attach-p2-metadata</id>
-								<phase>package</phase>
-								<goals>
-									<goal>p2-metadata</goal>
-								</goals>
-							</execution>
-						</executions>
-					</plugin>
-				</plugins>
-			</build>
-		</profile>
-
-		<!-- Stable release profile. Eclipse servers only -->
-		<profile>
-			<id>packAndSign</id>
-			<activation>
-				<property>
-					<name>SIGN</name>
-					<value>true</value>
-				</property>
-			</activation>
-			<!-- Pack200 -->
-			<build>
-				<plugins>
-					<plugin>
-						<groupId>org.eclipse.tycho.extras</groupId>
-						<artifactId>tycho-pack200a-plugin</artifactId>
-						<version>${tychoExtrasVersion}</version>
-						<executions>
-							<execution>
-								<id>pack200-normalize</id>
-								<goals>
-									<goal>normalize</goal>
-								</goals>
-							</execution>
-						</executions>
-					</plugin>
-					<plugin>
-						<groupId>org.eclipse.cbi.maven.plugins</groupId>
-						<artifactId>eclipse-jarsigner-plugin</artifactId>
-						<version>${jarSignerVersion}</version>
-						<executions>
-							<execution>
-								<id>sign</id>
-								<goals>
-									<goal>sign</goal>
-								</goals>
-							</execution>
-						</executions>
-					</plugin>
-					<plugin>
-						<groupId>org.eclipse.tycho.extras</groupId>
-						<artifactId>tycho-pack200b-plugin</artifactId>
-						<version>${tychoExtrasVersion}</version>
-						<executions>
-							<execution>
-								<id>pack200-pack</id>
-								<goals>
-									<goal>pack</goal>
-								</goals>
-							</execution>
-						</executions>
-					</plugin>
-					<plugin>
-						<groupId>org.eclipse.tycho</groupId>
-						<artifactId>tycho-p2-plugin</artifactId>
-						<version>${tycho.version}</version>
-						<executions>
-							<execution>
-								<id>attach-p2-metadata</id>
-								<phase>package</phase>
-								<goals>
-									<goal>p2-metadata</goal>
-								</goals>
-							</execution>
-						</executions>
-						<configuration>
-							<defaultP2Metadata>false</defaultP2Metadata>
-						</configuration>
-					</plugin>
-				</plugins>
-			</build>
-		</profile>
-
-		<!-- Nightly profile. Artifacts can be consumed, but are not signed -->
-		<profile>
-			<id>pack</id>
-			<activation>
-				<property>
-					<name>SIGN</name>
-					<value>false</value>
-				</property>
-			</activation>
-			<build>
-				<plugins>
-					<!-- Pack200 -->
-					<plugin>
-						<groupId>org.eclipse.tycho.extras</groupId>
-						<artifactId>tycho-pack200b-plugin</artifactId>
-						<version>${tychoExtrasVersion}</version>
-						<executions>
-							<execution>
-								<id>pack200-pack</id>
-								<goals>
-									<goal>pack</goal>
-								</goals>
-							</execution>
-						</executions>
-					</plugin>
-					<plugin>
-						<groupId>org.eclipse.tycho</groupId>
-						<artifactId>tycho-p2-plugin</artifactId>
-						<version>${tycho.version}</version>
-						<executions>
-							<execution>
-								<id>attach-p2-metadata</id>
-								<phase>package</phase>
-								<goals>
-									<goal>p2-metadata</goal>
-								</goals>
-							</execution>
-						</executions>
-						<configuration>
-							<defaultP2Metadata>false</defaultP2Metadata>
-						</configuration>
-					</plugin>
-				</plugins>
-			</build>
-		</profile>
-	</profiles>
-
 </project>
\ No newline at end of file
diff --git a/releng/scripts/buildafter.sh b/releng/scripts/buildafter.sh
new file mode 100755
index 0000000..12c2779
--- /dev/null
+++ b/releng/scripts/buildafter.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+p2UpdateSiteDir=${WORKSPACE}/source/releng/org.eclipse.papyrus.requirements.p2/target/repository
+updateSite=${WORKSPACE}/repository
+
+zipName="Papyrus-Requirements.zip"
+
+rm -rf tmp
+mkdir -p "tmp/$FULL_BUILD_ID"
+
+rm -rf $updateSite
+mv $p2UpdateSiteDir $updateSite
+
+# create the update site zip
+cd $updateSite && zip -r $zipName *
+mv $updateSite/$zipName ${WORKSPACE}
diff --git a/releng/scripts/publish.sh b/releng/scripts/publish.sh
new file mode 100755
index 0000000..8674d00
--- /dev/null
+++ b/releng/scripts/publish.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+alias ll="ls -la"
+
+########### Parameters Check ###########
+if (test $# -ne 5) then
+  echo "The script must have access to the following parameters:
+  - MILESTONE,
+  - SIGN,
+  - RELEASE_NUMBER,
+  - OVERRIDE,
+  - PUBLISH"
+fi
+
+########### Parameters Initialization ###########
+if ! $PUBLISH ; then
+  exit 0 # nothing to do here
+fi 
+
+if ! $SIGN ; then
+  echo "The sources may not have been signed. Please verify the build and artifacts parameters and try again."
+  exit 1
+fi
+
+#The specific localization
+remoteRoot="/home/data/httpd/download.eclipse.org"
+requirementsRoot="modeling/mdt/papyrus/components/requirements"
+
+if [[ "$MILESTONE" == "-R" ]] ; then
+  destination=$remoteRoot/$requirementsRoot/release-$RELEASE_NUMBER
+  destinationUpdateSite=$destination
+else
+  destination=$remoteRoot/$requirementsRoot/milestones-$RELEASE_NUMBER
+  destinationUpdateSite=$destination/$RELEASE_NUMBER$MILESTONE
+fi
+echo $destinationUpdateSite
+
+#jobArtifacts=$HOME/.jenkins/jobs/$PROMOTED_JOB_NAME/builds/$PROMOTED_NUMBER/archive
+jobArtifacts=$HOME/agent/workspace/$JOB_NAME/
+if [ ! -d $jobArtifacts ] ; then
+  echo "No artifact folder was found under the specified $jobArtifacts path"
+  exit 1
+fi
+
+echo "$jobArtifacts contains the following :"
+ls $jobArtifacts
+
+if [ -d $destination ] ; then
+  if [ -d $destinationUpdateSite ] ; then
+    if $OVERRIDE ; then
+      echo "Removing previous artifacts"
+      rm -rf $destinationUpdateSite
+    else
+      echo "The milestone already exists. You might want to change the suffix or delete the previous one."
+      exit 1
+    fi
+  fi
+fi
+
+
+########### Publish Artifacts ###########
+#Go to the artifact directory
+cd $jobArtifacts
+
+# Check the availability of the artifacts to promote before creating anything
+if [ ! -f Papyrus-Requirements.zip ] ; then
+  echo "There is no Papyrus-Requirements.zip here."
+  pwd
+  ls
+  exit 1
+fi
+if [ ! -d repository ] ; then
+  echo "There is no repository directory here."
+  pwd
+  ls
+  exit 1
+fi
+
+echo "Promoting the Job to $destinationUpdateSite"
+
+#No error if exists, makes parent directories as needed
+echo "creating $destinationUpdateSite"
+mkdir -p $destinationUpdateSite
+
+if [ ! -d $destinationUpdateSite ] ; then
+  echo "The destination folder could not be created. Please look why in the logs."
+  exit 1
+fi
+
+#Copy the contents onto the server folder
+echo "copying the zip into $destinationUpdateSite"
+cp Papyrus-Requirements.zip $destinationUpdateSite
+
+echo "copying the p2 repository folder into $destinationUpdateSite"
+cp -r repository/* $destinationUpdateSite
+
+
+########### Set Access Rights ###########
+# This function sets the acess rights to allow all memebers of the group to edit the files
+function setAccessRights() {
+  chmod -R 775 "$1"
+  chgrp -hR modeling.mdt.papyrus "$1"
+}
+echo "Set access right -R: $destinationUpdateSite"
+setAccessRights $destinationUpdateSite
+
+
+echo "publishing done."
\ No newline at end of file