Skip to content

Commit 5410358

Browse files
committed
Merge branch 'release/2.0.0'
2 parents 6b4367d + f310b68 commit 5410358

File tree

102 files changed

+6523
-1533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+6523
-1533
lines changed

.circleci/config.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Java Maven CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-java/ for more details
4+
#
5+
version: 2
6+
7+
references:
8+
build: &build
9+
working_directory: ~/repo
10+
11+
environment:
12+
# Customize the JVM maximum heap limit
13+
MAVEN_OPTS: -Xmx2048m
14+
JACOCO: false
15+
16+
steps:
17+
- checkout
18+
19+
# Download and cache dependencies
20+
- restore_cache:
21+
keys:
22+
- v2-dependencies-{{ checksum "pom.xml" }}
23+
# fallback to using the latest cache if no exact match is found
24+
- v2-dependencies-
25+
26+
- run:
27+
name: Go Offline with Maven
28+
command: mvn verify -DskipTests
29+
30+
- save_cache:
31+
paths:
32+
- ~/.m2
33+
key: v2-dependencies-{{ checksum "pom.xml" }}
34+
35+
# run tests!
36+
- run:
37+
name: Run integration tests
38+
command: mvn verify
39+
40+
workflows:
41+
version: 2
42+
integration-tests:
43+
jobs:
44+
- zulu-6
45+
- zulu-7
46+
- zulu-8
47+
- zulu-9
48+
- zulu-11
49+
50+
jobs:
51+
zulu-6:
52+
docker:
53+
- image: wavesoftware/circleci-zulujdk:6
54+
<<: *build
55+
zulu-7:
56+
docker:
57+
- image: wavesoftware/circleci-zulujdk:7
58+
<<: *build
59+
zulu-8:
60+
docker:
61+
- image: wavesoftware/circleci-zulujdk:8
62+
<<: *build
63+
zulu-9:
64+
docker:
65+
- image: wavesoftware/circleci-zulujdk:9
66+
<<: *build
67+
zulu-11:
68+
docker:
69+
- image: wavesoftware/circleci-zulujdk:11
70+
<<: *build
71+
72+
73+

.editorconfig

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ end_of_line = lf
99
insert_final_newline = true
1010
charset = utf-8
1111
indent_style = space
12-
indent_size = 4
12+
indent_size = 4
13+
14+
[*.yml]
15+
indent_size = 2

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
# Eclipse IDE
1212
/.classpath
1313
/.project
14-
/.settings/org.eclipse.core.resources.prefs
15-
/.settings/org.eclipse.jdt.core.prefs
16-
/.settings/org.eclipse.m2e.core.prefs
17-
/.settings/org.eclipse.jdt.ui.prefs
14+
/.settings
1815

1916
# Netbeans IDE
2017
/nbactions.xml

.travis.yml

+21-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
language: java
2-
script: mvn clean install --fail-at-end
2+
dist: trusty
3+
before_script: mvn dependency:go-offline
4+
script: mvn clean verify --fail-at-end
35
notifications:
46
email:
5-
on_failure: true
7+
on_failure: change
68
matrix:
79
include:
8-
- jdk: openjdk6
9-
env: JACOCO=true
10-
- jdk: openjdk7
11-
env: JACOCO=true COVERALLS=true
12-
- jdk: oraclejdk7
13-
env: JACOCO=true
14-
- jdk: oraclejdk8
15-
env: JACOCO=true
16-
- jdk: openjdk7
17-
env: JACOCO=true GDMSESSION=sonar
18-
- jdk: openjdk7
19-
env: JACOCO=true SONAR=publish
20-
script: mvn clean install sonar:sonar --fail-at-end
21-
- jdk: openjdk6
22-
env: JACOCO=false
23-
- jdk: openjdk7
24-
env: JACOCO=false
25-
- jdk: oraclejdk7
26-
env: JACOCO=false
27-
- jdk: oraclejdk8
28-
env: JACOCO=false
10+
# Quality testing
11+
- jdk: oraclejdk8
12+
env: JACOCO=true RELEASE_CHECKS=true
13+
- jdk: oraclejdk8
14+
env: JACOCO=true COVERALLS=true
15+
- jdk: oraclejdk8
16+
env: JACOCO=true SONAR=publish
17+
script: mvn clean verify sonar:sonar --fail-at-end
18+
# Performance testing
19+
- jdk: openjdk7
20+
env: JACOCO=false
21+
- jdk: openjdk8
22+
env: JACOCO=false
23+
- jdk: oraclejdk9
24+
env: JACOCO=false
25+
- jdk: oraclejdk11
26+
env: JACOCO=false

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2015 Wave Software
189+
Copyright 2015-2018 Wave Software
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

+99-24
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
# EID Runtime Exceptions and Utilities
22

3-
[![Build Status](https://travis-ci.org/wavesoftware/java-eid-exceptions.svg?branch=master)](https://travis-ci.org/wavesoftware/java-eid-exceptions) [![Coverage Status](https://coveralls.io/repos/wavesoftware/java-eid-exceptions/badge.svg?branch=master&service=github)](https://coveralls.io/github/wavesoftware/java-eid-exceptions?branch=master) [![SonarQube Tech Debt](https://img.shields.io/sonar/http/sonar-ro.wavesoftware.pl/pl.wavesoftware:eid-exceptions/tech_debt.svg)](http://sonar-ro.wavesoftware.pl/dashboard/index/2600) [![Dependency Status](https://www.versioneye.com/user/projects/55aafc74306535001b000440/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55aafc74306535001b000440) [![Maven Central](https://img.shields.io/maven-central/v/pl.wavesoftware/eid-exceptions.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22pl.wavesoftware%22%20AND%20a%3A%22eid-exceptions%22)
3+
[![Build Status](https://travis-ci.org/wavesoftware/java-eid-exceptions.svg?branch=master)](https://travis-ci.org/wavesoftware/java-eid-exceptions) [![Coverage Status](https://coveralls.io/repos/wavesoftware/java-eid-exceptions/badge.svg?branch=master&service=github)](https://coveralls.io/github/wavesoftware/java-eid-exceptions?branch=master) [![SonarQube Tech Debt](https://img.shields.io/sonar/https/sonar.wavesoftware.pl/pl.wavesoftware%3Aeid-exceptions/tech_debt.svg)](https://sonar.wavesoftware.pl/dashboard?id=pl.wavesoftware%3Aeid-exceptions) [![Maven Central](https://img.shields.io/maven-central/v/pl.wavesoftware/eid-exceptions.svg)](https://search.maven.org/artifact/pl.wavesoftware/eid-exceptions/1.2.0/jar)
44

55
This small library holds a set of exceptions and utilities that implements idea of fast, reusable, error codes that can be simply thrown fast in case of unpredictable and unrecoverable application failure. It is meant to be used for application bugs.
66

7-
## Idea
7+
## The Idea
88

9-
The idea is to use a set of simple runtime exceptions. They should always take the Exception ID (Eid) object in the making. This eid object will then be reported when displaying or logging that exception. It can also be viewed on the professional fatal error window of the application as a bug reference. EidRuntimeExceptions contains also additional unique ID to distinguish each single exception from others with same Eid. This approach simplifies the management of exceptions in the application and allows developers to focus on functionalities rather than coming up with the correct statement for the exception.
9+
The main idea of this library is to use a set of simple runtime exceptions to speedup development and make it more professional in the same time. Those exceptions should always take the Exception ID (Eid for short) object on construction. The Eid object should be generated by developer while writing code and committed in the constructor of an exception. This eid object will then be reported when that exception is being displayed or logged.
1010

11-
This approach is best to use with tools and plugins like:
11+
This approach simplifies the management of exceptions in the application and allows developers to focus on functionality and code quality, rather than coming up with the correct statement for the exception.
12+
13+
This error number is perfect to be displayed on the error "500" page for your application as a bug reference. It's good idea, because it is static, so wil l not change in subsequent invocations, but it also do not disclose the actual reason why bug occurred.
14+
15+
This approach is best to use with tools and IDE plugins like:
1216

13-
* [EidGenerator for Netbeans IDE](http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator)
1417
* [Generating Exception Id number in Intellij IDEA with Live Templates](https://github.com/wavesoftware/java-eid-exceptions/wiki/Generating%20Exception%20Id%20number%20in%20Intellij%20IDEA%20with%20Live%20Templates)
18+
* [EidGenerator for Netbeans IDE](http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator)
19+
20+
Error page can say something like:
21+
22+
> We are deeply sorry. A fatal error occurred.
23+
> The reference number is: 20150721:100554
24+
>
25+
> Wait a couple of minutes, and try again. If the same error number persists, call IT support.
26+
27+
That error page is easy to implement, because all those exceptions implement `EidContainer` interface.
1528

1629
Example:
1730

@@ -43,7 +56,7 @@ This classes shouldn't be used in any public API or library. It is designed to b
4356
<dependency>
4457
<groupId>pl.wavesoftware</groupId>
4558
<artifactId>eid-exceptions</artifactId>
46-
<version>1.1.0</version>
59+
<version>1.2.0</version>
4760
</dependency>
4861
```
4962

@@ -107,20 +120,26 @@ checkElementIndex(index, list.size(), "20150721:115749");
107120

108121
#### Formatted message support
109122

110-
From release `1.1.0` there have been added methods to support additional formatted messages for `checkArgument`, `checkState`, `checkNotNull` and `checkElementIndex` method. Those method versions can sometimes be used to pass additional information to exceptions that will be displayed in log files.
123+
From release `1.2.0` methods have been added to support additional formatted messages for `checkArgument`,
124+
`checkState`, `checkNotNull` and `checkElementIndex` method. Those method versions can sometimes be used to pass additional information to exceptions that will be displayed in log files.
111125

112-
Message formatting is done using `String.format(String, Object[])` method.
126+
From release `2.0.0` message formatting is done using `MessageFormat#format(String, Object[])` method.
113127

114128
For example:
115129

116130
```java
117-
checkState(transation.isValid(), "20151119:120238", "Invalid transaction: %s, transaction);
131+
checkState(
132+
transation.isValid(), "20151119:120238",
133+
"Invalid transaction: {0}", transaction
134+
);
118135
```
119136

120137
Will produce output similar to;
121138

122139
```
123-
pl.wavesoftware.eid.exceptions.EidIllegalStateException: [20151119:120238]<xf4j1l> => Invalid transaction: <Transaction id=null, buyer=null, products=[]>
140+
pl.wavesoftware.eid.exceptions.EidIllegalStateException:
141+
↵ [20151119:120238]<xf4j1l> => Invalid transaction:
142+
↵ <Transaction id=null, buyer=null, products=[]>
124143
```
125144

126145
#### Functional try to execute blocks
@@ -132,39 +151,84 @@ There are two versions. One with `UnsafeSupplier` and one with `UnsafeProcedure`
132151
Example:
133152

134153
```java
135-
InputStream is = EidPreconditions.tryToExecute(new UnsafeSupplier<InputStream>() {
136-
@Override
154+
import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute;
155+
// [..]
156+
InputStream is = tryToExecute(
157+
() -> openResource("project.properties"),
158+
"20150718:121521"
159+
);
160+
```
161+
162+
or with JDK < 8
163+
164+
```java
165+
InputStream is = EidExecutions.tryToExecute(new UnsafeSupplier<InputStream>() {
166+
@Override @Nonnull
137167
public InputStream get() throws IOException {
138168
return this.getClass().getClassLoader()
139169
.getResourceAsStream("project.properties");
140170
}
141171
}, "20150718:121521");
142172
```
143173

144-
or with Java 8:
145-
146-
```java
147-
import static pl.wavesoftware.eid.utils.EidPreconditions.tryToExecute;
148-
// [..]
149-
InputStream is = tryToExecute(() -> { resource("project.properties"); }, "20150718:121521");
150-
```
151-
152174
#### Logging
153175

154-
Eid object can also be useful in logging. That are `makeLogMessage` method provided to do that. Message formatting is done using `String.format(String, Object[])` method.
176+
Eid object can also be useful in logging. That is `message` method provided to do that. Message formatting is done using
177+
`MessageFormat.format(String, Object[])` method.
155178
For example:
156179

157180
```java
158-
log.debug(new Eid("20151119:121814").makeLogMessage("REST request received: %s", request));
181+
log.debug(DefaultEid
182+
.eid("20151119:121814")
183+
.message("REST request received: {0}", request).toString()
184+
);
159185
```
160186

161187
will unfold to something similar to:
162188

163189
```
164-
2017-01-08T16:45:34,334 DEBUG [a.b.c.RestBroker] [20151119:121814]<d1afca> REST request received: <RestRequest user=<User id=345> flow=ShowLastTransactions step=Confirm>
190+
2017-01-08T16:45:34,334 DEBUG [a.b.c.RestBroker]
191+
↵ [20151119:121814]<d1afca> REST request received:
192+
↵ <RestRequest user=<User id=345> flow=ShowLastTransactions step=Confirm>
165193
```
166194

167-
###Contributing
195+
#### Configuration
196+
197+
From release `2.0.0` configuration interfaces have been added. There are 2 ways to configure Eid library.
198+
199+
##### Configuration using Java's ServiceLoader mechanism
200+
201+
Java `ServiceLoader` mechanism is standard for extending libraries. To do that, create on your classpath, a file:
202+
203+
`META-INF/services/pl.wavesoftware.eid.api.Configurator`
204+
205+
In that file, place a fully qualified class name of your class that implements `Configurator` interface. It should be called first time you reference an Eid, or and of the eid exceptions, or utility preconditions class.
206+
207+
##### Programmatic configuration
208+
209+
You can also configure Eid library programmatically. To do just that, use `EidModule.getBinding().getConfigurationSystem().configure()` method.
210+
211+
```java
212+
// configure
213+
Configurator original = EidModul.getBinding()
214+
.getConfigurationSystem()
215+
.configure(configuration ->
216+
configuration.uniqueIdGenerator(() -> constUniq)
217+
);
218+
219+
// restore original configuration with:
220+
EidModule.getBinding()
221+
.getConfigurationSystem()
222+
.configure(original);
223+
```
224+
225+
Note, that method returns a configurator that can be used to restore configuration to the state before you invoke this configuration method.
226+
227+
#### Validation
228+
229+
On `2.0.0` release optional validation have been added. If you configure a `Validator` using either of configuration methods, each new Eid will be validated for correctness. Note that this will happen lazily for `EidPreconditions` and `EidExecutions` utility methods.
230+
231+
### Contributing
168232

169233
Contributions are welcome!
170234

@@ -184,6 +248,17 @@ Even if you can't contribute code, if you have an idea for an improvement please
184248

185249
### Releases
186250

251+
- 2.0.0
252+
- Complete overhaul of library structure
253+
- More obvious exceptions constructors
254+
- Better configuration
255+
- Optional validation
256+
257+
- 1.2.0
258+
- Major performance tweaks and tests for `EidPreconditions` methods #4
259+
- Major performance tweaks and tests for `Eid` class #2
260+
- Switched to new OSSRH maven template
261+
- Switched to Git Flow via jgitflow plugin
187262
- 1.1.0
188263
- Adding support for formatted messages in exceptions and also in utility methods of `EidPreconditions`
189264
- 1.0.1

0 commit comments

Comments
 (0)