Skip to content

Commit f18c06a

Browse files
authored
Merge core and library, revive hamcrest-integration (hamcrest#229)
This is a big change to the project structure, but there are no changes to any Java code. As this is a breaking change due to the repackaging, the version has changed from 1.4-SNAPSHOT to 2.1-SNAPSHOT. I realise that the Java API hasn't actually changed, but since there is already a version 2.0.0.0 published on Maven Central, the next version published must be incrementally higher than that, at a minimum. This revives hamcrest-integration as separate subproject. This was done by unzipping hamcrest-integration-1.3.jar downloaded from Maven Central. Unfortunately, the corresponding code available from the archived hamcrest-java on Google Code appeared out of date. I could not see test code for java-integration (I had a poke around the Google Code archive, but no luck there). Salient points: * New project hamcrest is the result of merging hamcrest-core and hamcrest-library. * hamcrest-integration remains an independent project. * hamcrest-integration remains only as a 1.3 line bugfix backstop. It is not published, and its version is pinned at 1.3.1-SNAPSHOT. * All aggregated jars removed (no hamcrest-all or java-hamcrest), which means only a single artefact is published: org.hamcrest:hamcrest:<version> (jar, sources and javadoc)
1 parent c9522e3 commit f18c06a

File tree

13 files changed

+182
-124
lines changed

13 files changed

+182
-124
lines changed

build.gradle

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'osgi'
33
apply plugin: 'maven-publish'
44

55
group = "org.hamcrest"
6-
version = "1.4-SNAPSHOT"
6+
version = "2.1-SNAPSHOT"
77

88
subprojects {
99
apply plugin: 'java-library'
@@ -12,8 +12,6 @@ subprojects {
1212
sourceCompatibility = JavaVersion.VERSION_1_7
1313
targetCompatibility = JavaVersion.VERSION_1_7
1414

15-
version = rootProject.version
16-
1715
repositories {
1816
mavenCentral()
1917
}
@@ -47,46 +45,6 @@ subprojects {
4745
}
4846
}
4947

50-
task allClassesJar(type: Jar, dependsOn: subprojects.tasks['build']) {
51-
baseName = 'hamcrest-all'
52-
subprojects.each { subproject ->
53-
from zipTree(subproject.jar.archivePath)
54-
}
55-
manifest {
56-
attributes 'Implementation-Title': 'hamcrest-all',
57-
'Implementation-Vendor': 'hamcrest.org',
58-
'Implementation-Version': version
59-
}
60-
}
61-
62-
63-
task allSourcesJar(type: Jar) {
64-
baseName = 'hamcrest-all'
65-
classifier = 'sources'
66-
subprojects.each { subproject ->
67-
from subproject.sourceSets.main.allSource
68-
}
69-
}
70-
71-
task allJavadoc(type: Javadoc) {
72-
group = 'Documentation'
73-
description = 'Generate combined Javadoc for all projects'
74-
title = "Hamcrest All $version API"
75-
subprojects.each { proj ->
76-
proj.tasks.withType(Javadoc).each { javadocTask ->
77-
source += javadocTask.source
78-
classpath += javadocTask.classpath
79-
excludes += javadocTask.excludes
80-
includes += javadocTask.includes
81-
}
82-
}
83-
}
84-
85-
task allJavadocJar(type: Jar) {
86-
classifier = 'javadoc'
87-
from allJavadoc
88-
}
89-
9048
def pomConfigurationFor(String pomName, String pomDescription) {
9149
return {
9250
name = pomName
@@ -124,36 +82,15 @@ def pomConfigurationFor(String pomName, String pomDescription) {
12482

12583
publishing {
12684
publications {
127-
def coreProject = project(':hamcrest-core')
85+
def hamcrestProject = project(':hamcrest')
12886
hamcrestCore(MavenPublication) {
129-
from coreProject.components.java
130-
artifactId coreProject.name
131-
artifact coreProject.sourcesJar
132-
artifact coreProject.javadocJar
133-
pom pomConfigurationFor(
134-
'Hamcrest Core',
135-
'This is the core API of hamcrest matcher framework to be used by third-party framework providers. This includes the a foundation set of matcher implementations for common operations.')
136-
}
137-
138-
def libraryProject = project(':hamcrest-library')
139-
hamcrestLibrary(MavenPublication) {
140-
from libraryProject.components.java
141-
artifactId = libraryProject.name
142-
artifact libraryProject.sourcesJar
143-
artifact libraryProject.javadocJar
144-
pom pomConfigurationFor(
145-
'Hamcrest Library',
146-
'Hamcrest library of matcher implementations.')
147-
}
148-
149-
hamcrestAll(MavenPublication) {
150-
artifactId = 'hamcrest-all'
151-
artifact allClassesJar
152-
artifact allSourcesJar
153-
artifact allJavadocJar
87+
from hamcrestProject.components.java
88+
artifactId hamcrestProject.name
89+
artifact hamcrestProject.sourcesJar
90+
artifact hamcrestProject.javadocJar
15491
pom pomConfigurationFor(
155-
'Hamcrest All',
156-
'A self-contained hamcrest jar containing all of the sub-modules in a single artifact.')
92+
'Hamcrest',
93+
'Core API and libraries of hamcrest matcher framework.')
15794
}
15895
}
15996
repositories {
@@ -174,6 +111,4 @@ publishing {
174111
signing {
175112
required { hasProperty('ossrhUsername') && hasProperty('ossrhPassword') }
176113
sign publishing.publications.hamcrestCore
177-
sign publishing.publications.hamcrestLibrary
178-
sign publishing.publications.hamcrestAll
179114
}

hamcrest-core/hamcrest-core.gradle

Lines changed: 0 additions & 7 deletions
This file was deleted.

hamcrest-core/hamcrest-core.iml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version = '1.3.1-SNAPSHOT'
2+
3+
dependencies {
4+
api 'org.hamcrest:hamcrest-library:1.3'
5+
api 'org.easymock:easymock:2.2'
6+
api('jmock:jmock:1.1.0') {
7+
transitive = false
8+
}
9+
10+
testImplementation(group: 'junit', name: 'junit', version: '4.12') {
11+
transitive = false
12+
}
13+
}
14+
15+
javadoc.title = "Hamcrest Integration $version API"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.hamcrest;
2+
3+
import org.hamcrest.integration.EasyMock2Adapter;
4+
import org.hamcrest.core.IsEqual;
5+
6+
/**
7+
*
8+
* @author Joe Walnes
9+
*/
10+
public class EasyMock2Matchers {
11+
12+
public static String equalTo(String string) {
13+
EasyMock2Adapter.adapt(IsEqual.equalTo(string));
14+
return null;
15+
}
16+
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.hamcrest;
2+
3+
import org.hamcrest.integration.JMock1Adapter;
4+
import org.hamcrest.core.IsEqual;
5+
import org.jmock.core.Constraint;
6+
7+
public class JMock1Matchers {
8+
9+
public static Constraint equalTo(String string) {
10+
return JMock1Adapter.adapt(IsEqual.equalTo(string));
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.hamcrest;
2+
3+
/**
4+
* Integration method for use with Java's <code>assert</code> keyword.
5+
* Example:
6+
* <pre>
7+
* assert that("Foo", startsWith("f"));
8+
* </pre>
9+
*
10+
* @author Neil Dunn
11+
*/
12+
public class JavaLangMatcherAssert {
13+
private JavaLangMatcherAssert() {};
14+
15+
public static <T> boolean that(T argument, Matcher<? super T> matcher) {
16+
return matcher.matches(argument);
17+
}
18+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.hamcrest.integration;
2+
3+
import org.easymock.IArgumentMatcher;
4+
import org.easymock.EasyMock;
5+
import org.hamcrest.Matcher;
6+
import org.hamcrest.StringDescription;
7+
8+
/**
9+
* An adapter allowing a Hamcrest {@link org.hamcrest.Matcher}
10+
* to act as an EasyMock {@link org.easymock.IArgumentMatcher}.
11+
*
12+
* @author Joe Walnes
13+
*/
14+
public class EasyMock2Adapter implements IArgumentMatcher {
15+
16+
/**
17+
* Convenience factory method that will adapt a
18+
* Hamcrest {@link org.hamcrest.Matcher} to act as an
19+
* EasyMock {@link org.easymock.IArgumentMatcher} and
20+
* report it to EasyMock so it can be kept track of.
21+
*/
22+
public static IArgumentMatcher adapt(Matcher<?> matcher) {
23+
EasyMock2Adapter easyMock2Matcher = new EasyMock2Adapter(matcher);
24+
EasyMock.reportMatcher(easyMock2Matcher);
25+
return easyMock2Matcher;
26+
}
27+
28+
private final Matcher<?> hamcrestMatcher;
29+
30+
public EasyMock2Adapter(Matcher<?> matcher) {
31+
this.hamcrestMatcher = matcher;
32+
}
33+
34+
@Override
35+
public boolean matches(Object argument) {
36+
return hamcrestMatcher.matches(argument);
37+
}
38+
39+
@Override
40+
public void appendTo(StringBuffer buffer) {
41+
hamcrestMatcher.describeTo(new StringDescription(buffer));
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.hamcrest.integration;
2+
3+
import org.jmock.core.Constraint;
4+
import org.hamcrest.Matcher;
5+
import org.hamcrest.StringDescription;
6+
7+
/**
8+
* An adapter allowing a Hamcrest {@link org.hamcrest.Matcher}
9+
* to act as an jMock1 {@link org.jmock.core.Constraint}.
10+
* Note, this is not necessary for jMock2 as it supports Hamcrest
11+
* out of the box.
12+
*
13+
* @author Joe Walnes
14+
*/
15+
public class JMock1Adapter implements Constraint {
16+
17+
/**
18+
* Convenience factory method that will adapt a
19+
* Hamcrest {@link org.hamcrest.Matcher} to act as an
20+
* jMock {@link org.jmock.core.Constraint}.
21+
*/
22+
public static Constraint adapt(Matcher<?> matcher) {
23+
return new JMock1Adapter(matcher);
24+
}
25+
26+
private final Matcher<?> hamcrestMatcher;
27+
28+
public JMock1Adapter(Matcher<?> matcher) {
29+
this.hamcrestMatcher = matcher;
30+
}
31+
32+
@Override
33+
public boolean eval(Object o) {
34+
return hamcrestMatcher.matches(o);
35+
}
36+
37+
@Override
38+
public StringBuffer describeTo(StringBuffer buffer) {
39+
hamcrestMatcher.describeTo(new StringDescription(buffer));
40+
return buffer;
41+
}
42+
}

hamcrest-library/hamcrest-library.gradle

Lines changed: 0 additions & 10 deletions
This file was deleted.

hamcrest-library/hamcrest-library.iml

Lines changed: 0 additions & 16 deletions
This file was deleted.

hamcrest/hamcrest.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version = rootProject.version
2+
3+
sourceSets {
4+
main {
5+
java {
6+
srcDirs rootProject.file('hamcrest-core/src/main/java'),
7+
rootProject.file('hamcrest-library/src/main/java')
8+
}
9+
}
10+
test {
11+
java {
12+
srcDirs rootProject.file('hamcrest-core/src/test/java'),
13+
rootProject.file('hamcrest-library/src/test/java')
14+
}
15+
}
16+
}
17+
18+
dependencies {
19+
testImplementation(group: 'junit', name: 'junit', version: '4.12') {
20+
transitive = false
21+
}
22+
}
23+
24+
javadoc.title = "Hamcrest $version API"

settings.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
enableFeaturePreview('STABLE_PUBLISHING')
22

3-
include 'hamcrest-core',
4-
'hamcrest-library'
3+
include 'hamcrest',
4+
'hamcrest-integration'
55

6-
rootProject.name = 'hamcrest'
6+
rootProject.name = 'JavaHamcrest'
77

88
// Change the file name of the child project build file to match the directory name
99
// This avoids having multiple `build.gradle` files, making them easier to distinguish

0 commit comments

Comments
 (0)