Skip to content

Commit

Permalink
Fixes junit-teamgh-309: build.xml uploads junitX.jar as junit-depX.jar
Browse files Browse the repository at this point in the history
  • Loading branch information
dsaff committed Sep 13, 2011
1 parent 61f0654 commit 9de54af
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 68 deletions.
79 changes: 58 additions & 21 deletions build.xml
@@ -1,13 +1,14 @@
<project name="junit" default="dist" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<tstamp />
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

<property file="${user.home}/.junit.properties" />
<property name="src" value="src/main/java" />
<property name="target" location="target" />
<property name="bin" location="${target}/main" />
<property name="version-base" value="4.9" />
<property name="version-status" value="" />
<property name="version-base" value="4.9.1" />
<property name="version-status" value="-SNAPSHOT" />
<property name="version" value="${version-base}${version-status}" />
<property name="dist" value="junit${version}" />
<property name="versionfile" value="${src}/junit/runner/Version.java" />
Expand Down Expand Up @@ -217,19 +218,18 @@

<!-- to do automatic build upload, you need the maven ant tasks jar. -->
<!-- therefore, you must run ant as ant -lib build/lib stage.maven -->
<macrodef name="stage.maven.jar">
<macrodef name="push.maven.jar">
<attribute name="jar" />
<attribute name="pom" />
<attribute name="url" />
<attribute name="repo.id" />
<element name="artifact.args" implicit="true" optional="true" />
<sequential>
<property name="maven-repository-url"
value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
<property name="maven-repository-id" value="sonatype-nexus-staging" />
<echo message="Staging to maven: @{jar}" />
<echo message="Pushing to maven: @{jar} -> @{url}" />
<artifact:mvn failonerror="true">
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.1:sign-and-deploy-file" />
<arg value="-Durl=${maven-repository-url}" />
<arg value="-DrepositoryId=${maven-repository-id}" />
<arg value="-Durl=@{url}" />
<arg value="-DrepositoryId=@{repo.id}" />
<arg value="-DpomFile=@{pom}" />
<arg value="-Dfile=@{jar}" />
<artifact.args />
Expand All @@ -238,40 +238,77 @@
</sequential>
</macrodef>

<macrodef name="stage.maven.artifactId">
<macrodef name="push.maven.artifact">
<attribute name="artifactId" />
<attribute name="url" />
<attribute name="repo.id" />
<attribute name="is.snapshot" default="false" />
<sequential>
<local name="m.prefix" />
<property name="m.prefix" value="${dist}/@{artifactId}-${version}" />
<local name="m.jar" />
<property name="m.jar" value="${m.prefix}.jar" />
<local name="m.sources.jar" />
<property name="m.sources.jar" value="${m.prefix}-src.jar" />
<local name="m.javadoc.jar" />
<property name="m.javadoc.jar" value="${m.prefix}-javadoc.jar" />
<local name="m.pom" />
<property name="m.pom" value="${dist}/pom-@{artifactId}.xml" />

<filter token="version" value="${version}" />
<filter token="artifactId" value="@{artifactId}" />

<copy
file="pom-template.xml"
file="build/maven/pom-template.xml"
tofile="${m.pom}"
filtering="on"
overwrite="true"
/>

<stage.maven.jar jar="${m.jar}" pom="${m.pom}" />

<stage.maven.jar jar="${m.sources.jar}" pom="${m.pom}" >
<arg value="-Dclassifier=sources" />
</stage.maven.jar>
<push.maven.jar jar="${m.jar}" pom="${m.pom}"
url="@{url}" repo.id="@{repo.id}" />

<if>
<equals arg1="${is.snapshot}" arg2="false" />
<then>
<push.maven.jar jar="${m.sources.jar}" pom="${m.pom}"
url="@{url}" repo.id="@{repo.id}">
<arg value="-Dclassifier=sources" />
</push.maven.jar>

<stage.maven.jar jar="${m.javadoc.jar}" pom="${m.pom}" >
<arg value="-Dclassifier=javadoc" />
</stage.maven.jar>
<push.maven.jar jar="${m.javadoc.jar}" pom="${m.pom}"
url="@{url}" repo.id="@{repo.id}">
<arg value="-Dclassifier=javadoc" />
</push.maven.jar>
</then>
</if>
</sequential>
</macrodef>

<target name="stage.maven" depends="all.maven.jars">
<stage.maven.artifactId artifactId="junit" />
<stage.maven.artifactId artifactId="junit-dep" />
<property name="stage.url"
value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
<property name="stage.repo.id" value="sonatype-nexus-staging" />

<push.maven.artifact artifactId="junit"
url="${stage.url}"
repo.id="${stage.repo.id}" />
<push.maven.artifact artifactId="junit-dep"
url="${stage.url}"
repo.id="${stage.repo.id}" />
</target>

<target name="snapshot.maven" depends="all.maven.jars">
<property name="snapshot.url"
value="https://oss.sonatype.org/content/repositories/snapshots/" />
<property name="snapshot.repo.id" value="sonatype-nexus-snapshots" />

<push.maven.artifact artifactId="junit"
url="${snapshot.url}"
repo.id="${snapshot.repo.id}" />
<push.maven.artifact artifactId="junit-dep"
url="${snapshot.url}"
repo.id="${snapshot.repo.id}" />
</target>

<target name="print.version">
Expand Down
Binary file added build/lib/ant-contrib-1.0b3.jar
Binary file not shown.
File renamed without changes.
49 changes: 49 additions & 0 deletions build/maven/post_maven_tests.sh
@@ -0,0 +1,49 @@
set -e
set -o pipefail

function TEST_junit_dep_49_plays_not_nicely_with_later_hamcrest {
# Make sure our system notices the bug (this broke because of a bad push)
! runs_with_newer_hamcrest junit-dep 4.9
}

function TEST_junit_dep_snapshot_plays_nicely_with_later_hamcrest {
runs_with_newer_hamcrest junit-dep LATEST
}

function TEST_junit_snapshot_plays_not_nicely_with_later_hamcrest {
! runs_with_newer_hamcrest junit LATEST
}

function runs_with_newer_hamcrest {
local artifact_id=$1
local version=$2
rm -rf ~/.m2/repository/junit
rm -rf uses_junit
cp -r sample_project_template uses_junit
sed -i '' -e "s/___ARTIFACT_ID___/$artifact_id/" uses_junit/pom.xml
sed -i '' -e "s/___VERSION___/$version/" uses_junit/pom.xml
in_dir uses_junit mvn test
finally rm -rf uses_junit
}

### <copied src="https://gist.github.com/1206506">
function in_dir {
local dir=$1
shift
if [ ! -e $dir ]; then
echo "$dir does not exist"
return 1
fi
pushd $dir >/dev/null
"$@"
finally popd >/dev/null
}

function finally {
local return_this=$?
"$@"
return $return_this
}
### </copied>

source ../run_tests.sh
61 changes: 61 additions & 0 deletions build/maven/sample_project_template/pom.xml
@@ -0,0 +1,61 @@
<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>com.example</groupId>
<artifactId>junit-dependency-test</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.hamcrest>1.2.1</version.hamcrest>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>___ARTIFACT_ID___</artifactId>
<version>___VERSION___</version>
</dependency>

<!--
This dependency must be included *before* junit, because said JAR
contains an old hamcrest-core version. This is problematic at
runtime; see JunitDependencyTest.
If junit-dep has the right contents, the order should not matter.
-->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${version.hamcrest}</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${version.hamcrest}</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>Sonatype</id>
<url>https://oss.sonatype.org/content/groups/public</url>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,33 @@
import org.hamcrest.Matchers;
import org.junit.Test;

public final class JunitDependencyTest {
/**
* JUnit dependency test.
*
* This class has three dependencies. These can be on the classpath in
* different orders. Of the two orderings below, the first one will cause a
* NoSuchMethodError, while the second one allows the test to pass
* successfully. See the explanation below for more information.
*
* Ordering 1: junit-4.9, hamcrest-core-1.2.1, hamcrest-library-1.2.1.
* Ordering 2: hamcrest-core-1.2.1, junit-4.9, hamcrest-library-1.2.1.
*/
@Test
public void test() {
/*
* Note that we call Matchers#anyOf(Matcher<T>, Matcher<? super T>).
* This method is provided by hamcrest-library-1.2.1. Said module is
* compiled against hamcrest-core-1.2.1. Matchers#anyOf calls
* AnyOf#anyOf(Matcher<T>, Matcher<? super T>). The latter method is
* provided by hamcrest-core-1.2.1, but *not* by hamcrest-core-1.1.
*
* However, hamcrest-core-1.1 *does* contain a class called AnyOf. Now,
* since junit-4.9 incorporates hamcrest-core-1.1 we must make sure that
* hamcrest-core-1.2.1 is placed *before* junit-4.9 on the classpath.
* Failure to do so will cause the wrong AnyOf class to be used. The
* result is a NoSuchMethodError.
*/
Matchers.anyOf(Matchers.nullValue(), Matchers.notNullValue());
}
}
36 changes: 36 additions & 0 deletions build/run_tests.sh
@@ -0,0 +1,36 @@
# See maven/post_maven_tests.sh for an example use

SCRIPT_NAME=$0
TEST_NAME=${1:-ALL}

function get_tests() {
if [ $TEST_NAME == "ALL" ]; then
part1=function
part2=TEST_
grep "$part1 $part2" $SCRIPT_NAME | sed 's/.*\(TEST_[A-Za-z0-9_]*\).*/\1/'
else
echo "TEST_${TEST_NAME}"
fi
}

function run_tests() {
local exit_code=0

for t in $(get_tests); do
echo "RUNNING: $t"
if "$t"; then
echo "PASSED: $t"
else
echo "FAILED: $t"
return 1
fi
done
}

if run_tests; then
echo "ALL TESTS PASSED"
exit 0
else
echo "A TEST FAILED"
exit 1
fi
35 changes: 1 addition & 34 deletions build_tests.sh
@@ -1,9 +1,6 @@
set -e
set -o pipefail

SCRIPT_NAME=$0
TEST_NAME=${1:-ALL}

function TEST_BUILDING_in_zip {
version=$(get_junit_version)
ant zip
Expand Down Expand Up @@ -76,34 +73,4 @@ function get_junit_version {
ant print.version | grep echo | sed 's/.*echo..\([1-9].*\)/\1/'
}

function get_tests() {
if [ $TEST_NAME == "ALL" ]; then
part1=function
part2=TEST_
grep "$part1 $part2" $SCRIPT_NAME | sed 's/.*\(TEST_[A-Za-z0-9_]*\).*/\1/'
else
echo "TEST_${TEST_NAME}"
fi
}

function run_tests() {
local exit_code=0

for t in $(get_tests); do
echo "RUNNING: $t"
if "$t"; then
echo "PASSED: $t"
else
echo "FAILED: $t"
return 1
fi
done
}

if run_tests; then
echo "ALL TESTS PASSED"
exit 0
else
echo "A TEST FAILED"
exit 1
fi
source build/run_tests.sh
4 changes: 4 additions & 0 deletions doc/ReleaseNotes4.9.1.html
@@ -0,0 +1,4 @@

Can't open /Users/saff/git-repos/stems_and_seeds/junit/doc/ReleaseNotes4.9.1.txt: No such file or directory at build/Markdown.pl line 218.
Use of uninitialized value $text in substitution (s///) at build/Markdown.pl line 245.
Use of uninitialized value $text in substitution (s///) at build/Markdown.pl line 246.
12 changes: 0 additions & 12 deletions pom-template.xml.asc

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/junit/runner/Version.java
Expand Up @@ -9,7 +9,7 @@ private Version() {
}

public static String id() {
return "4.9";
return "4.9.1-SNAPSHOT";
}

public static void main(String[] args) {
Expand Down

0 comments on commit 9de54af

Please sign in to comment.