Skip to content

Commit 6519416

Browse files
authored
Documentation updates for 2.1 (hamcrest#237)
* Update distributables discription for Hamcrest 2.1 * Update changes for Hamcrest 2.1 * Add background and border to code samples.
1 parent 7ffc219 commit 6519416

File tree

3 files changed

+128
-84
lines changed

3 files changed

+128
-84
lines changed

CHANGES.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
11
# Hamcrest Changes
22

3-
## Version 2.1-rc2 (27th November 2018)
3+
## Version 2.1 (Unreleased)
44

5-
* Publish pom-only artifacts for hamcrest-core and hamcrest-library.
6-
7-
## Version 2.1-rc1 (25th November 2018)
8-
9-
### Overview for 2.1-rc1
5+
### Overview for 2.1
106

117
After a long hiatus without releases, this version simplifies the packaging of
128
Hamcrest into a single jar: `hamcrest-<version>.jar`. Other big changes include
13-
Java 9 module compatibility, along with numerous other improvements and bug
14-
fixes.
9+
Java 9 module compatibility, migrating the code repository from Google Code to
10+
GitHub, along with numerous other new features, improvements and bug fixes.
1511

16-
### Breaking Changes for 2.1-rc1
12+
### Breaking Changes for 2.1
1713

18-
Although the class API has not changed since Hamcrest 1.3, the way that the
19-
project is packaged has changed. Refer to the [Hamcrest Distributables](http://hamcrest.org/JavaHamcrest/distributables.html)
20-
documentation for more information.
14+
* The way that the project is packaged has changed. This may cause problems with
15+
correctly upgrading transitive dependencies. Refer to the
16+
[Hamcrest Distributables](http://hamcrest.org/JavaHamcrest/distributables.html)
17+
documentation for more information, and in particular,
18+
[Upgrading from Hamcrest 1.x](http://hamcrest.org/JavaHamcrest/distributables.html#upgrading-from-hamcrest-1.x)
19+
* `org.hamcrest.Factory` has been removed. This was only used in old implementations
20+
of the hamcrest build toolchain, and can safely be deleted from client code without
21+
any effect.
2122

22-
### Changes for 2.1-rc1
23+
### Changes for 2.1
2324

24-
* Publish a single jar `hamcrest-2.1.jar`
2525
* Documentation updates
26+
* Several JavaDoc improvements and corrections
27+
* Fix JavaDoc examples
28+
* Upgraded to Java 7
29+
* Build with Gradle
30+
* Publish a single jar `hamcrest-2.1.jar`
31+
* Publish pom-only artifacts for `hamcrest-core` and `hamcrest-library`.
2632
* Add implementation for CharSequence length matcher
2733
* Fix for TypeSafeDiagnosingMatcher can't detect generic types for subclass
28-
* Renamed IsCollectionContaining to IsIterableContaining
2934
* Make Hamcrest an OSGI bundle
3035
* Add StringRegularExpression matcher
3136
* Fix StringContainsInOrder to detect if a repeated pattern is missing
3237
* Add ArrayAsIterableMatcher
3338
* Fix description for IsEqualIgnoringCase
34-
* Fix JavaDoc examples
35-
36-
## Version 2.0.0.0 (18th January 2015)
37-
38-
This version was the first release after migrating from the old Google Code hosting to GitHub.
39-
40-
* Upgraded to Java 7
41-
* Build with Gradle
42-
* Publish a single jar java-hamcrest-2.0.0.0.jar
4339
* Removed deprecated methods from previous release
4440
* Improve mismatch description of hasItem/hasItems
4541
* General improvements to mismatch descriptions
46-
* Several JavaDoc improvements and corrections
4742
* Deprecated several matcher factory methods of the for "isXyz"
4843
* Fix [GH issue #75](https://github.com/hamcrest/JavaHamcrest/issues/75) - address doclint errors reported in JDK 1.8
4944
* Fix [GH issue #69](https://github.com/hamcrest/JavaHamcrest/issues/69) - Iterable contains in order is null-safe

docs/css/hamcrest.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ h1, h2 {
3737
padding-left: 0px;
3838
padding-right: 40px;
3939
}
40+
pre.highlight {
41+
border: 1px solid #ccc;
42+
background-color: #eee;
43+
padding: 0.5em;
44+
}

docs/distributables.md

Lines changed: 103 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,98 +10,142 @@ layout: default
1010
## Introduction
1111
{:.no_toc}
1212

13-
Hamcrest consists of different jars matching the different needs of
14-
applications. This document describes these distributables and the
15-
functionality contained in each of them.
13+
This document describes the current and previous versions of the various Hamcrest
14+
distributables, and the functionality contained in each of them.
15+
16+
The latest version of Hamcrest consists of a single jar file which contains base
17+
classes and a library of useful matcher implementations. This is different from
18+
older versions.
19+
20+
Older versions of Hamcrest consisted of a number of different jars matching the
21+
different needs of applications. The change in the jar packaging requires care
22+
when upgrading.
1623

1724
## Table of Contents
1825
{:.no_toc}
1926

2027
* TOC
2128
{:toc}
2229

23-
## The Java Hamcrest Jars
24-
25-
### `hamcrest-core.jar`
26-
27-
This is the core API to be used by third-party framework providers.
28-
This includes a foundation set of matcher implementations for common
29-
operations. This API is stable and will rarely change. You will
30-
need this library as a minimum.
31-
32-
### `hamcrest-library.jar`
33-
34-
The library of Matcher implementations which are based on the core
35-
functionality in hamcrest-core.jar.
36-
37-
### `hamcrest-integration.jar`
38-
39-
Provides integration between Hamcrest and other testing tools, such as jMock
40-
and EasyMock. Uses hamcrest-core.jar and hamcrest-library.jar.
41-
42-
### `hamcrest-generator.jar`
43-
44-
A tool to allow many Matcher implementations to be combined into
45-
a single class with static methods returning the different matchers
46-
so users don't have to remember many classes/packages to import.
47-
Generates code. This library is only used internally at compile time.
48-
It is not necessary for the use of any of the other hamcrest libraries
49-
at runtime.
50-
51-
### `hamcrest-all.jar`
52-
53-
One jar containing all classes of all the other jars.
54-
55-
56-
## Adding Hamcrest to your Project
30+
## The Hamcrest Jar
5731

58-
The dependencies of the jars (`hamcrest-integration` uses `hamcrest-library`
59-
which uses `hamcrest-core`) is represented by the Maven dependency mechanism.
60-
There is no `hamcrest-all` library in the Maven repo prior to version 1.3. Just
61-
use hamcrest-integration which references all the other hamcrest libraries.
62-
32+
All the base classes and standard matcher implementations are contained in a
33+
single jar file called `hamcrest-2.1.jar`.
6334

64-
### Gradle
35+
### Using Hamcrest in a Gradle Project
6536

66-
Add `"org.hamcrest:hamcrest-library:1.3"` to the dependencies section of your
37+
Add `"org.hamcrest:hamcrest:2.1"` to the dependencies section of your
6738
`build.gradle`, for example:
6839

6940
```gradle
7041
apply plugin: 'java'
7142
7243
dependencies {
73-
testImplementation 'org.hamcrest:hamcrest-library:1.3'
44+
testImplementation 'org.hamcrest:hamcrest:2.1'
7445
}
7546
```
7647

7748
Note: older versions of Gradle use the `testCompile` configuration
7849
instead of the `testImplementation` configuration.
7950

80-
### Maven
51+
### Using Hamcrest in a Maven Project
8152

82-
Add the following dependency declaration to your `pom.xml`:
53+
Add the following to the `<dependencies>` section in your `pom.xml`:
8354

8455
```xml
8556
<dependency>
8657
<groupId>org.hamcrest</groupId>
87-
<artifactId>hamcrest-library</artifactId>
88-
<version>1.3</version>
58+
<artifactId>hamcrest</artifactId>
59+
<version>2.1</version>
8960
<scope>test</scope>
9061
</dependency>
9162
```
9263

93-
### Download
64+
### Download the Hamcrest Jar
9465

95-
You can download the jars directly from Maven Central. At a minimum, you will
96-
need `hamcrest-core.jar`, though most people will also use
97-
`hamcrest-library.jar` too. If you want to integrate Hamcrest Matchers with
98-
other test tools, such as jMock or EasyMock, download `hamcrest-integration.jar`, too.
99-
100-
You can find the jars by searching Maven Central for groupId `org.hamcrest`
66+
You can download the jars directly from Maven Central. You can find the jars by searching Maven Central for groupId `org.hamcrest`
10167
using the following link:
10268

10369
> [https://search.maven.org/search?q=g:org.hamcrest](https://search.maven.org/search?q=g:org.hamcrest)
10470
105-
Maven central has some extra artifacts called `java-hamcrest` and `hamcrest-java`,
106-
with a version of `2.0.0.0`. Please do not use these, as they are an aborted effort
107-
at repackaging the different jars.
71+
## Previous Versions of Hamcrest
72+
73+
Prior to version 2.x, Hamcrest was distributed through multiple jars, described
74+
below.
75+
76+
* **`hamcrest-core.jar`**: This was the core API to be used by third-party framework
77+
providers. This includes a foundation set of matcher implementations for common
78+
operations. This library was used as a dependency for many third-party libraries,
79+
including JUnit 4.x. From Hamcrest version 2.x, all the classes in
80+
`hamcrest-core.jar` were moved into `hamcrest.jar`.
81+
* **`hamcrest-library.jar`**: The library of Matcher implementations which are based
82+
on the core functionality in hamcrest-core.jar. From Hamcrest version 2.x, all the
83+
classes in `hamcrest-core.jar` were moved into `hamcrest.jar`.
84+
* **`hamcrest-integration.jar`**: Provides integration between Hamcrest and other
85+
testing tools, such as jMock and EasyMock. It depends upon `hamcrest-core.jar` and
86+
`hamcrest-library.jar`. There are no new releases of this library since version 1.3.
87+
* **`hamcrest-generator.jar`**: A tool to allow many Matcher implementations to be
88+
combined into a single class with static methods returning the different matchers
89+
so users don't have to remember many classes/packages to import. Generates code.
90+
This library is only used internally at compile time. It is not necessary for the
91+
use of any of the other hamcrest libraries at runtime. There are no new releases of
92+
this library since version 1.3.
93+
* **`hamcrest-all.jar`**: One jar containing all classes of all the other jars.
94+
There are no new releases of this library since version 1.3. Please use the single
95+
`hamcrest.jar` instead.
96+
97+
### Upgrading from Hamcrest 1.x
98+
99+
Care must be taken when upgrading from Hamcrest 1.3 or earlier. Due to the change in
100+
packaging, the version conflict resolution that happens in dependency management
101+
tools won't happen automatically. A common example is projects that depend upon
102+
JUnit 4. JUnit 4 declares a transitive dependency upon `hamcrest-core-1.3.jar`.
103+
Because `hamcrest-core` is not the same artifact as `hamcrest`, it will not be
104+
upgraded.
105+
106+
To address this issue, Hamcrest 2.1 and later also publish artifacts for
107+
`hamcrest-core` and `hamcrest-library`. Although these jars contain no classes,
108+
they trigger the version conflict upgrade in the dependency manager, and correctly
109+
declare transitive dependencies upon the new `hamcrest` packaging. Users can
110+
directly declare a dependency upon these shim jars to force the upgrade.
111+
112+
#### Gradle Upgrade Example
113+
114+
```gradle
115+
apply plugin: 'java'
116+
117+
dependencies {
118+
testImplementation 'org.hamcrest:hamcrest:2.1'
119+
testImplementation 'org.hamcrest:hamcrest-library:2.1'
120+
testImplementation 'junit:junit:4.12'
121+
}
122+
```
123+
124+
#### Maven Upgrade Example
125+
126+
**Warning**:
127+
Maven users should declare a dependency upon `hamcrest-library` **before** other
128+
dependencies, otherwise the older version will take precedence.
129+
130+
```xml
131+
<dependencies>
132+
<dependency>
133+
<groupId>org.hamcrest</groupId>
134+
<artifactId>hamcrest</artifactId>
135+
<version>2.1</version>
136+
<scope>test</scope>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.hamcrest</groupId>
140+
<artifactId>hamcrest-library</artifactId>
141+
<version>2.1</version>
142+
<scope>test</scope>
143+
</dependency>
144+
<dependency>
145+
<groupId>junit</groupId>
146+
<artifactId>junit</artifactId>
147+
<version>4.12</version>
148+
<scope>test</scope>
149+
</dependency>
150+
</dependencies>
151+
```

0 commit comments

Comments
 (0)