Skip to content

Commit 829e259

Browse files
committed
Refactoring to meet requirements for 2.x
It's about time for major refactoring of Eid library. Introducing 2.x relase with: * Better structure * More obvious exceptions constructors * Better configuration * Optional validation
1 parent e4015c4 commit 829e259

60 files changed

Lines changed: 3818 additions & 1302 deletions

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 4 deletions
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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
language: java
2-
script: mvn clean install --fail-at-end
2+
script: mvn clean verify --fail-at-end
33
notifications:
44
email:
55
on_failure: true
66
matrix:
77
include:
8-
- jdk: openjdk6
9-
env: JACOCO=true
108
- jdk: openjdk7
11-
env: JACOCO=true COVERALLS=true
12-
- jdk: oraclejdk7
139
env: JACOCO=true
10+
- jdk: openjdk8
11+
env: JACOCO=true COVERALLS=true
1412
- jdk: oraclejdk8
1513
env: JACOCO=true
16-
- jdk: openjdk7
17-
env: JACOCO=true GDMSESSION=sonar
18-
- jdk: openjdk7
14+
- jdk: openjdk8
1915
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
16+
script: mvn clean verify sonar:sonar --fail-at-end

LICENSE

Lines changed: 1 addition & 1 deletion
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

Lines changed: 75 additions & 12 deletions
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) [![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

1317
* [EidGenerator for Netbeans IDE](http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator)
1418
* [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)
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

@@ -107,14 +120,15 @@ 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(transation.isValid(), "20151119:120238", "Invalid transaction: {0}", transaction);
118132
```
119133

120134
Will produce output similar to;
@@ -132,7 +146,7 @@ There are two versions. One with `UnsafeSupplier` and one with `UnsafeProcedure`
132146
Example:
133147

134148
```java
135-
InputStream is = EidPreconditions.tryToExecute(new UnsafeSupplier<InputStream>() {
149+
InputStream is = EidExecutions.tryToExecute(new UnsafeSupplier<InputStream>() {
136150
@Override @Nonnull
137151
public InputStream get() throws IOException {
138152
return this.getClass().getClassLoader()
@@ -144,18 +158,22 @@ InputStream is = EidPreconditions.tryToExecute(new UnsafeSupplier<InputStream>()
144158
or with Java 8:
145159

146160
```java
147-
import static pl.wavesoftware.eid.utils.EidPreconditions.tryToExecute;
161+
import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute;
148162
// [..]
149-
InputStream is = tryToExecute(() -> { resource("project.properties"); }, "20150718:121521");
163+
InputStream is = tryToExecute(
164+
() -> openResource("project.properties"),
165+
"20150718:121521"
166+
);
150167
```
151168

152169
#### Logging
153170

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.
171+
Eid object can also be useful in logging. That is `message` method provided to do that. Message formatting is done using
172+
`MessageFormat.format(String, Object[])` method.
155173
For example:
156174

157175
```java
158-
log.debug(new Eid("20151119:121814").makeLogMessage("REST request received: %s", request));
176+
log.debug(new Eid("20151119:121814").message("REST request received: {0}", request).toString());
159177
```
160178

161179
will unfold to something similar to:
@@ -164,6 +182,45 @@ will unfold to something similar to:
164182
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>
165183
```
166184

185+
#### Configuration
186+
187+
From release `2.0.0` configuration interfaces have been added. There are 2 ways to configure Eid library.
188+
189+
##### Configuration using Java's ServiceLoader mechanism
190+
191+
Java `ServiceLoader` mechanism is standard for extending libraries. To do that, create on your classpath, a file:
192+
193+
`META-INF/services/pl.wavesoftware.eid.Configurator`
194+
195+
In that file, place a fully qualified class name of your class that implements `EidConfigurator` interface. It should be called first time you reference an Eid, or and of the eid exceptions, or utility preconditions class.
196+
197+
##### Programmatic configuration
198+
199+
You can also configure Eid library programmatically. To do just that, use `Eid.getBinding().getConfigurationSystem().configure()` method.
200+
201+
```java
202+
// configure
203+
EidConfigurator original = Eid.getBinding().getConfigurationSystem().configure(new EidConfigurator() {
204+
@Override
205+
public void configure(EidConfiguration configuration) {
206+
configuration.uniqueIdGenerator(new UniqueIdGenerator() {
207+
@Override
208+
public String generateUniqId() {
209+
return constUniq;
210+
}
211+
});
212+
}
213+
});
214+
// restore original configuration with:
215+
Eid.getBinding().getConfigurationSystem().configure(original);
216+
```
217+
218+
Note, that method returns a configurator that can be used to restore configuration to the state before you invoke this configuration method.
219+
220+
#### Validation
221+
222+
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.
223+
167224
### Contributing
168225

169226
Contributions are welcome!
@@ -184,6 +241,12 @@ Even if you can't contribute code, if you have an idea for an improvement please
184241

185242
### Releases
186243

244+
- 2.0.0
245+
- Complete overhaul of library structure
246+
- More obvious exceptions constructors
247+
- Better configuration
248+
- Optional validation
249+
187250
- 1.2.0
188251
- Major performance tweaks and tests for `EidPreconditions` methods #4
189252
- Major performance tweaks and tests for `Eid` class #2

pom.xml

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<!--
3+
~ Copyright (c) 2015 Wave Software
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
21+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
322
<modelVersion>4.0.0</modelVersion>
423
<groupId>pl.wavesoftware</groupId>
524
<artifactId>eid-exceptions</artifactId>
6-
<version>1.2.1-SNAPSHOT</version>
25+
<version>2.0.0-SNAPSHOT</version>
726
<packaging>jar</packaging>
827

928
<name>EID Runtime Exceptions and Utilities</name>
1029
<description>
11-
This small library holds a set of Exceptions that implements idea of fast, reusable, error codes
12-
that can be simple thrown fast in case of unpredictable and unrecoverable application failure.
30+
This small library holds a set of Exceptions that implements idea of
31+
fast, reusable, error codes that can be simple thrown fast in case of
32+
unpredictable and unrecoverable application failure.
1333
</description>
1434
<url>http://wavesoftware.github.io/java-eid-exceptions/</url>
1535
<inceptionYear>2015</inceptionYear>
@@ -36,10 +56,6 @@
3656
</developer>
3757
</developers>
3858

39-
<prerequisites>
40-
<maven>${maven.required.version}</maven>
41-
</prerequisites>
42-
4359
<scm>
4460
<connection>scm:git:https://github.com/wavesoftware/java-eid-exceptions.git</connection>
4561
<developerConnection>scm:git:git@github.com:wavesoftware/java-eid-exceptions.git</developerConnection>
@@ -68,8 +84,6 @@
6884
</distributionManagement>
6985

7086
<properties>
71-
<netbeans.hint.license>apache20</netbeans.hint.license>
72-
<maven.required.version>3.0.4</maven.required.version>
7387
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
7488
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
7589
<sonar.working.directory>${project.build.directory}/sonar</sonar.working.directory>
@@ -93,7 +107,6 @@
93107
<groupId>com.google.code.findbugs</groupId>
94108
<artifactId>jsr305</artifactId>
95109
<version>3.0.1</version>
96-
<type>jar</type>
97110
</dependency>
98111

99112
<!-- Tests -->
@@ -110,12 +123,6 @@
110123
<version>1.7.1</version>
111124
<scope>test</scope>
112125
</dependency>
113-
<dependency>
114-
<groupId>org.hamcrest</groupId>
115-
<artifactId>hamcrest-all</artifactId>
116-
<version>1.3</version>
117-
<scope>test</scope>
118-
</dependency>
119126
<dependency>
120127
<groupId>org.openjdk.jmh</groupId>
121128
<artifactId>jmh-core</artifactId>
@@ -149,13 +156,12 @@
149156
</dependencies>
150157

151158
<build>
152-
153159
<pluginManagement>
154160
<plugins>
155161
<plugin>
156-
<groupId>org.codehaus.mojo</groupId>
162+
<groupId>org.sonarsource.scanner.maven</groupId>
157163
<artifactId>sonar-maven-plugin</artifactId>
158-
<version>3.0.1</version>
164+
<version>3.5.0.1254</version>
159165
</plugin>
160166
<plugin>
161167
<groupId>external.atlassian.jgitflow</groupId>
@@ -296,6 +302,11 @@
296302
<artifactId>maven-site-plugin</artifactId>
297303
<version>3.5</version>
298304
</plugin>
305+
<plugin>
306+
<groupId>org.codehaus.gmaven</groupId>
307+
<artifactId>groovy-maven-plugin</artifactId>
308+
<version>2.1</version>
309+
</plugin>
299310
</plugins>
300311
</pluginManagement>
301312

@@ -360,7 +371,7 @@
360371
</plugin>
361372

362373
<plugin>
363-
<groupId>org.codehaus.mojo</groupId>
374+
<groupId>org.sonarsource.scanner.maven</groupId>
364375
<artifactId>sonar-maven-plugin</artifactId>
365376
<executions>
366377
<execution>
@@ -376,12 +387,11 @@
376387
<plugin>
377388
<groupId>org.codehaus.gmaven</groupId>
378389
<artifactId>groovy-maven-plugin</artifactId>
379-
<version>2.0</version>
380390
<dependencies>
381391
<dependency>
382392
<groupId>org.codehaus.groovy</groupId>
383393
<artifactId>groovy-all</artifactId>
384-
<version>2.4.6</version>
394+
<version>2.4.15</version>
385395
</dependency>
386396
</dependencies>
387397
<configuration>

0 commit comments

Comments
 (0)