Change to use maven 3

Also, download and build common directly instead of hacking the
build to use the jars from tarballs.openstack.org

Update the README.md to explain the new StackForge build

Change-Id: I08cc1b304eaad38fc0619a09efc91c11e8633199
This commit is contained in:
Craig Bryant 2015-03-12 17:14:21 -06:00
parent 68ef496cc9
commit 011824ef26
7 changed files with 93 additions and 159 deletions

View File

@ -15,9 +15,7 @@ mvn clean package
# StackForge Java Build
There is a pom.xml in the base directory that should only be used for the StackForge build. The StackForge build is a rather strange build because of the limitations of the current StackForge java jobs and infrastructure. This build depends on jars that are built in the monasca-common build. That StrackForge build uploads the completed jars to http://tarballs.openstack.org/ci/monasca-common, but they are just regular jars, and not in a maven repository. Hence, the first thing the maven build from the base project does is execute the build in the download directory. That pom.xml executes the script download.sh which downloads the required jars from http://tarballs.openstack.org/ci/monasca-common and then uses maven to install them in the local directory. The maven install needs the pom.xml so that is pulled from the jar file and then changed to have the right version before the install.
The monasca-common jars also need the base monasca-common pom.xml. So, that is pulled from gihtub.com and also installed in the local repository.
There is a pom.xml in the base directory that should only be used for the StackForge build. The StackForge build is a rather strange build because of the limitations of the current StackForge java jobs and infrastructure. We have found that the API runs faster if built with maven 3 but the StackForge nodes only have maven 2. This build checks the version of maven and if not maven 3, it downloads a version of maven 3 and uses it. This build depends on jars that are from monasca-common. That StrackForge build uploads the completed jars to http://tarballs.openstack.org/ci/monasca-common, but they are just regular jars, and not in a maven repository and sometimes zuul takes a long time to do the upload. Hence, the first thing the maven build from the base project does is invoke build_common.sh in the common directory. This script clones monasca-common and then invokes maven 3 to build monasca-common in the common directory and install the jars in the local maven repository.
Since this is all rather complex, that part of the build only works on StackForge so follow the simple instruction above if you are building your own monasca-api.

29
common/build_common.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
set -x
ME=`whoami`
echo "Running as user: $ME"
MVN=$1
VERSION=$2
check_user() {
ME=$1
if [ "${ME}" != "jenkins" ]; then
echo "\nERROR: Download monasca-common and do a mvn install to install the monasca-commom jars\n" 1>&2
exit 1
fi
}
BUILD_COMMON=false
POM_FILE=~/.m2/repository/monasca-common/monasca-common/${VERSION}/monasca-common-${VERSION}.pom
if [ ! -r "${POM_FILE}" ]; then
check_user ${ME}
BUILD_COMMON=true
fi
# This should only be done on the stack forge system
if [ "${BUILD_COMMON}" = "true" ]; then
git clone https://github.com/stackforge/monasca-common
cd monasca-common
${MVN} clean
${MVN} install
fi

View File

@ -1,72 +0,0 @@
#!/bin/sh
set -x
ME=`whoami`
echo "Running as user: $ME"
VERSION=$1
check_user() {
ME=$1
if [ "${ME}" != "jenkins" ]; then
echo "\nERROR: Download monasca-common and do a mvn install to install the monasca-commom jars\n" 1>&2
exit 1
fi
}
# TODO: Grep these out of the pom itself rather than have them explicitly listed
JARS="
monasca-common-influxdb
monasca-common-model
monasca-common-persistence
monasca-common-util
monasca-common-kafka
monasca-common-middleware
monasca-common-testing
"
for JAR in $JARS; do
JARFILE=~/.m2//repository/monasca-common/${JAR}/${VERSION}/${JAR}-${VERSION}.jar
if [ ! -r "$JARFILE" ]; then
check_user ${ME}
# Download it from stackforge
FILE=`basename $JARFILE`
curl http://tarballs.openstack.org/ci/monasca-common/${FILE} > ${FILE}
# Upload into the local repository
POM=META-INF/maven/monasca-common/${JAR}/pom.xml
jar -xvf ${FILE} ${POM}
TMPFILE=pom.$$
sed -e "s/\${computedVersion}/${VERSION}/" ${POM} > ${TMPFILE}
mv ${TMPFILE} ${POM}
mvn install:install-file -Dfile=${FILE} -DgroupId=monasca-common \
-DartifactId=${JAR} -Dversion=${VERSION} -Dpackaging=jar -DpomFile=${POM}
fi
done
POM_FILE=~/.m2/repository/monasca-common/monasca-common/${VERSION}/monasca-common-${VERSION}.pom
if [ ! -r "${POM_FILE}" ]; then
check_user ${ME}
TMPDIR=pom_tmp.$$
mkdir -p ${TMPDIR}
curl https://raw.githubusercontent.com/stackforge/monasca-common/master/java/pom.xml > ${TMPDIR}/pom.xml
mvn install:install-file -DgroupId=monasca-common -DartifactId=monasca-common -Dversion=${VERSION} -Dpackaging=pom -Dfile=${TMPDIR}/pom.xml
rm -fr ${TMPDIR}
fi
TEST_JARS="
monasca-common-dropwizard
"
for TEST_JAR in $TEST_JARS; do
JARFILE=~/.m2//repository/monasca-common/${TEST_JAR}/${VERSION}/${TEST_JAR}-${VERSION}-tests.jar
if [ ! -r "$JARFILE" ]; then
check_user ${ME}
# Download it from stackforge
FILE=`basename $JARFILE`
curl http://tarballs.openstack.org/ci/monasca-common/${FILE} > ${FILE}
# Upload into the local repository
POM=META-INF/maven/monasca-common/${TEST_JAR}/pom.xml
jar -xvf ${FILE} ${POM}
TMPFILE=pom.$$
sed -e "s/\${computedVersion}/${VERSION}/" ${POM} > ${TMPFILE}
mv ${TMPFILE} ${POM}
mvn install:install-file -Dfile=${FILE} -DgroupId=monasca-common \
-DartifactId=${TEST_JAR} -Dversion=${VERSION} -Dpackaging=test-jar -DpomFile=${POM}
fi
done

View File

@ -1,40 +0,0 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>monasca-persister</groupId>
<artifactId>monasca-persister-download</artifactId>
<version>1.0.0-SNAPSHOT</version>
<url>http://github.com/stackforge/monasca-persister</url>
<packaging>pom</packaging>
<properties>
<!-- Versioning -->
<exec.args>${project.version}</exec.args>
<skipITs>true</skipITs>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>package-execution</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>./download.sh</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -9,6 +9,10 @@
<url>http://github.com/stackforge/monasca-api</url>
<packaging>jar</packaging>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<properties>
<computedVersion>${project.version}-${timestamp}-${buildNumber}</computedVersion>
<computedName>${project.artifactId}-${computedVersion}</computedName>

55
pom.xml
View File

@ -4,21 +4,13 @@
<groupId>monasca</groupId>
<artifactId>monasca-api-base</artifactId>
<version>${computedVersion}</version>
<version>1.0.0-SNAPSHOT</version>
<url>http://github.com/stackforge/monasca-api</url>
<packaging>pom</packaging>
<!--
<prerequisites>
<maven>3.0</maven>
</prerequisites>
-->
<properties>
<!-- Versioning -->
<versionNumber>1.0.0</versionNumber>
<computedVersion>${versionNumber}-SNAPSHOT</computedVersion>
<exec.args>${version} ${sun.java.command}</exec.args>
<skipITs>true</skipITs>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -29,55 +21,30 @@
<developerConnection>scm:git:git@github.com:stackforge/monasca-api</developerConnection>
</scm>
<modules>
<module>download</module>
<module>java</module>
</modules>
<profiles>
<profile>
<id>release-deploy-url-override</id>
<activation>
<property>
<name>BUILD_NUM</name>
</property>
</activation>
<properties>
<computedVersion>${project.version}</computedVersion>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9</version>
<configuration>
<tag>${project.version}</tag>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>some-execution</id>
<id>package-execution</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>clean-execution</id>
<phase>clean</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>ln</executable>
<arguments>
<argument>-sf</argument>
<argument>java/target</argument>
<argument>target</argument>
</arguments>
<executable>run_maven.sh</executable>
</configuration>
</plugin>
</plugins>

48
run_maven.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# Download maven 3 if the system maven isn't maven 3
VERSION=`mvn -v | grep "Apache Maven 3"`
if [ -z "${VERSION}" ]; then
curl http://archive.apache.org/dist/maven/binaries/apache-maven-3.2.1-bin.tar.gz > apache-maven-3.2.1-bin.tar.gz
tar -xvzf apache-maven-3.2.1-bin.tar.gz
MVN=${PWD}/apache-maven-3.2.1/bin/mvn
else
MVN=mvn
fi
# Get the expected common version
COMMON_VERSION=$1
# Get rid of the version argument
shift
# Get rid of the java property name containing the args
shift
RUN_BUILD=false
for ARG in $*; do
if [ "$ARG" = "package" ]; then
RUN_BUILD=true
fi
if [ "$ARG" = "install" ]; then
RUN_BUILD=true
fi
done
if [ $RUN_BUILD = "true" ]; then
( cd common; ./build_common.sh ${MVN} ${COMMON_VERSION} )
RC=$?
if [ $RC != 0 ]; then
exit $RC
fi
fi
# Invoke the maven 3 on the real pom.xml
( cd java; ${MVN} $* )
RC=$?
# Copy the jars where the publisher will find them
if [ $RUN_BUILD = "true" ]; then
ln -sf java/target target
fi
rm -fr apache-maven-3.2.1*
exit $RC