Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge core and library, revive hamcrest-integration #229

Merged
merged 5 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 8 additions & 73 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'osgi'
apply plugin: 'maven-publish'

group = "org.hamcrest"
version = "1.4-SNAPSHOT"
version = "2.1-SNAPSHOT"

subprojects {
apply plugin: 'java-library'
Expand All @@ -12,8 +12,6 @@ subprojects {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

version = rootProject.version

repositories {
mavenCentral()
}
Expand Down Expand Up @@ -47,46 +45,6 @@ subprojects {
}
}

task allClassesJar(type: Jar, dependsOn: subprojects.tasks['build']) {
baseName = 'hamcrest-all'
subprojects.each { subproject ->
from zipTree(subproject.jar.archivePath)
}
manifest {
attributes 'Implementation-Title': 'hamcrest-all',
'Implementation-Vendor': 'hamcrest.org',
'Implementation-Version': version
}
}


task allSourcesJar(type: Jar) {
baseName = 'hamcrest-all'
classifier = 'sources'
subprojects.each { subproject ->
from subproject.sourceSets.main.allSource
}
}

task allJavadoc(type: Javadoc) {
group = 'Documentation'
description = 'Generate combined Javadoc for all projects'
title = "Hamcrest All $version API"
subprojects.each { proj ->
proj.tasks.withType(Javadoc).each { javadocTask ->
source += javadocTask.source
classpath += javadocTask.classpath
excludes += javadocTask.excludes
includes += javadocTask.includes
}
}
}

task allJavadocJar(type: Jar) {
classifier = 'javadoc'
from allJavadoc
}

def pomConfigurationFor(String pomName, String pomDescription) {
return {
name = pomName
Expand Down Expand Up @@ -124,36 +82,15 @@ def pomConfigurationFor(String pomName, String pomDescription) {

publishing {
publications {
def coreProject = project(':hamcrest-core')
def hamcrestProject = project(':hamcrest')
hamcrestCore(MavenPublication) {
from coreProject.components.java
artifactId coreProject.name
artifact coreProject.sourcesJar
artifact coreProject.javadocJar
pom pomConfigurationFor(
'Hamcrest Core',
'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.')
}

def libraryProject = project(':hamcrest-library')
hamcrestLibrary(MavenPublication) {
from libraryProject.components.java
artifactId = libraryProject.name
artifact libraryProject.sourcesJar
artifact libraryProject.javadocJar
pom pomConfigurationFor(
'Hamcrest Library',
'Hamcrest library of matcher implementations.')
}

hamcrestAll(MavenPublication) {
artifactId = 'hamcrest-all'
artifact allClassesJar
artifact allSourcesJar
artifact allJavadocJar
from hamcrestProject.components.java
artifactId hamcrestProject.name
artifact hamcrestProject.sourcesJar
artifact hamcrestProject.javadocJar
pom pomConfigurationFor(
'Hamcrest All',
'A self-contained hamcrest jar containing all of the sub-modules in a single artifact.')
'Hamcrest',
'Core API and libraries of hamcrest matcher framework.')
}
}
repositories {
Expand All @@ -174,6 +111,4 @@ publishing {
signing {
required { hasProperty('ossrhUsername') && hasProperty('ossrhPassword') }
sign publishing.publications.hamcrestCore
sign publishing.publications.hamcrestLibrary
sign publishing.publications.hamcrestAll
}
7 changes: 0 additions & 7 deletions hamcrest-core/hamcrest-core.gradle

This file was deleted.

15 changes: 0 additions & 15 deletions hamcrest-core/hamcrest-core.iml

This file was deleted.

15 changes: 15 additions & 0 deletions hamcrest-integration/hamcrest-integration.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version = '1.3.1-SNAPSHOT'

dependencies {
api 'org.hamcrest:hamcrest-library:1.3'
api 'org.easymock:easymock:2.2'
api('jmock:jmock:1.1.0') {
transitive = false
}

testImplementation(group: 'junit', name: 'junit', version: '4.12') {
transitive = false
}
}

javadoc.title = "Hamcrest Integration $version API"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.hamcrest;

import org.hamcrest.integration.EasyMock2Adapter;
import org.hamcrest.core.IsEqual;

/**
*
* @author Joe Walnes
*/
public class EasyMock2Matchers {

public static String equalTo(String string) {
EasyMock2Adapter.adapt(IsEqual.equalTo(string));
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hamcrest;

import org.hamcrest.integration.JMock1Adapter;
import org.hamcrest.core.IsEqual;
import org.jmock.core.Constraint;

public class JMock1Matchers {

public static Constraint equalTo(String string) {
return JMock1Adapter.adapt(IsEqual.equalTo(string));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.hamcrest;

/**
* Integration method for use with Java's <code>assert</code> keyword.
* Example:
* <pre>
* assert that("Foo", startsWith("f"));
* </pre>
*
* @author Neil Dunn
*/
public class JavaLangMatcherAssert {
private JavaLangMatcherAssert() {};

public static <T> boolean that(T argument, Matcher<? super T> matcher) {
return matcher.matches(argument);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.hamcrest.integration;

import org.easymock.IArgumentMatcher;
import org.easymock.EasyMock;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;

/**
* An adapter allowing a Hamcrest {@link org.hamcrest.Matcher}
* to act as an EasyMock {@link org.easymock.IArgumentMatcher}.
*
* @author Joe Walnes
*/
public class EasyMock2Adapter implements IArgumentMatcher {

/**
* Convenience factory method that will adapt a
* Hamcrest {@link org.hamcrest.Matcher} to act as an
* EasyMock {@link org.easymock.IArgumentMatcher} and
* report it to EasyMock so it can be kept track of.
*/
public static IArgumentMatcher adapt(Matcher<?> matcher) {
EasyMock2Adapter easyMock2Matcher = new EasyMock2Adapter(matcher);
EasyMock.reportMatcher(easyMock2Matcher);
return easyMock2Matcher;
}

private final Matcher<?> hamcrestMatcher;

public EasyMock2Adapter(Matcher<?> matcher) {
this.hamcrestMatcher = matcher;
}

@Override
public boolean matches(Object argument) {
return hamcrestMatcher.matches(argument);
}

@Override
public void appendTo(StringBuffer buffer) {
hamcrestMatcher.describeTo(new StringDescription(buffer));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.hamcrest.integration;

import org.jmock.core.Constraint;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;

/**
* An adapter allowing a Hamcrest {@link org.hamcrest.Matcher}
* to act as an jMock1 {@link org.jmock.core.Constraint}.
* Note, this is not necessary for jMock2 as it supports Hamcrest
* out of the box.
*
* @author Joe Walnes
*/
public class JMock1Adapter implements Constraint {

/**
* Convenience factory method that will adapt a
* Hamcrest {@link org.hamcrest.Matcher} to act as an
* jMock {@link org.jmock.core.Constraint}.
*/
public static Constraint adapt(Matcher<?> matcher) {
return new JMock1Adapter(matcher);
}

private final Matcher<?> hamcrestMatcher;

public JMock1Adapter(Matcher<?> matcher) {
this.hamcrestMatcher = matcher;
}

@Override
public boolean eval(Object o) {
return hamcrestMatcher.matches(o);
}

@Override
public StringBuffer describeTo(StringBuffer buffer) {
hamcrestMatcher.describeTo(new StringDescription(buffer));
return buffer;
}
}
10 changes: 0 additions & 10 deletions hamcrest-library/hamcrest-library.gradle

This file was deleted.

16 changes: 0 additions & 16 deletions hamcrest-library/hamcrest-library.iml

This file was deleted.

24 changes: 24 additions & 0 deletions hamcrest/hamcrest.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version = rootProject.version

sourceSets {
main {
java {
srcDirs rootProject.file('hamcrest-core/src/main/java'),
rootProject.file('hamcrest-library/src/main/java')
}
}
test {
java {
srcDirs rootProject.file('hamcrest-core/src/test/java'),
rootProject.file('hamcrest-library/src/test/java')
}
}
}

dependencies {
testImplementation(group: 'junit', name: 'junit', version: '4.12') {
transitive = false
}
}

javadoc.title = "Hamcrest $version API"
6 changes: 3 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
enableFeaturePreview('STABLE_PUBLISHING')

include 'hamcrest-core',
'hamcrest-library'
include 'hamcrest',
'hamcrest-integration'

rootProject.name = 'hamcrest'
rootProject.name = 'JavaHamcrest'

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