Skip to content

Commit

Permalink
Merge pull request #6 from wavesoftware/feature/refactor-for-2.x
Browse files Browse the repository at this point in the history
Refactoring to meet requirements for 2.x
  • Loading branch information
cardil authored Dec 18, 2018
2 parents e4015c4 + 351b3ac commit 86952e7
Show file tree
Hide file tree
Showing 97 changed files with 6,249 additions and 1,495 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
# Eclipse IDE
/.classpath
/.project
/.settings/org.eclipse.core.resources.prefs
/.settings/org.eclipse.jdt.core.prefs
/.settings/org.eclipse.m2e.core.prefs
/.settings/org.eclipse.jdt.ui.prefs
/.settings

# Netbeans IDE
/nbactions.xml
Expand Down
28 changes: 11 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
language: java
script: mvn clean install --fail-at-end
script: mvn clean verify --fail-at-end
notifications:
email:
on_failure: true
matrix:
include:
- jdk: openjdk6
env: JACOCO=true
# Performance testing
- jdk: openjdk7
env: JACOCO=false
- jdk: openjdk8
env: JACOCO=false
# Quality testing
- jdk: openjdk7
env: JACOCO=true COVERALLS=true
- jdk: oraclejdk7
env: JACOCO=true
- jdk: openjdk8
env: JACOCO=true COVERALLS=true
- jdk: oraclejdk8
env: JACOCO=true
- jdk: openjdk7
env: JACOCO=true GDMSESSION=sonar
- jdk: openjdk7
- jdk: openjdk8
env: JACOCO=true SONAR=publish
script: mvn clean install sonar:sonar --fail-at-end
- jdk: openjdk6
env: JACOCO=false
- jdk: openjdk7
env: JACOCO=false
- jdk: oraclejdk7
env: JACOCO=false
- jdk: oraclejdk8
env: JACOCO=false
script: mvn clean verify sonar:sonar --fail-at-end
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2015 Wave Software
Copyright 2015-2018 Wave Software

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
89 changes: 77 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# EID Runtime Exceptions and Utilities

[![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)
[![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)



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.

## Idea
## The Idea

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.

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.
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.

This approach is best to use with tools and plugins like:
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.

This approach is best to use with tools and IDE plugins like:

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

Error page can say something like:

> We are deeply sorry. A fatal error occurred.
> The reference number is: 20150721:100554
>
> Wait a couple of minutes, and try again. If the same error number persists, call IT support.
That error page is easy to implement, because all those exceptions implement `EidContainer` interface.

Example:

Expand Down Expand Up @@ -107,14 +122,15 @@ checkElementIndex(index, list.size(), "20150721:115749");

#### Formatted message support

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.
From release `1.2.0` methods have been added 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.

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

For example:

```java
checkState(transation.isValid(), "20151119:120238", "Invalid transaction: %s, transaction);
checkState(transation.isValid(), "20151119:120238", "Invalid transaction: {0}", transaction);
```

Will produce output similar to;
Expand All @@ -132,7 +148,7 @@ There are two versions. One with `UnsafeSupplier` and one with `UnsafeProcedure`
Example:

```java
InputStream is = EidPreconditions.tryToExecute(new UnsafeSupplier<InputStream>() {
InputStream is = EidExecutions.tryToExecute(new UnsafeSupplier<InputStream>() {
@Override @Nonnull
public InputStream get() throws IOException {
return this.getClass().getClassLoader()
Expand All @@ -144,18 +160,22 @@ InputStream is = EidPreconditions.tryToExecute(new UnsafeSupplier<InputStream>()
or with Java 8:

```java
import static pl.wavesoftware.eid.utils.EidPreconditions.tryToExecute;
import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute;
// [..]
InputStream is = tryToExecute(() -> { resource("project.properties"); }, "20150718:121521");
InputStream is = tryToExecute(
() -> openResource("project.properties"),
"20150718:121521"
);
```

#### Logging

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

```java
log.debug(new Eid("20151119:121814").makeLogMessage("REST request received: %s", request));
log.debug(new Eid("20151119:121814").message("REST request received: {0}", request).toString());
```

will unfold to something similar to:
Expand All @@ -164,6 +184,45 @@ will unfold to something similar to:
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>
```

#### Configuration

From release `2.0.0` configuration interfaces have been added. There are 2 ways to configure Eid library.

##### Configuration using Java's ServiceLoader mechanism

Java `ServiceLoader` mechanism is standard for extending libraries. To do that, create on your classpath, a file:

`META-INF/services/pl.wavesoftware.eid.Configurator`

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.

##### Programmatic configuration

You can also configure Eid library programmatically. To do just that, use `Eid.getBinding().getConfigurationSystem().configure()` method.

```java
// configure
EidConfigurator original = Eid.getBinding().getConfigurationSystem().configure(new EidConfigurator() {
@Override
public void configure(EidConfiguration configuration) {
configuration.uniqueIdGenerator(new UniqueIdGenerator() {
@Override
public String generateUniqId() {
return constUniq;
}
});
}
});
// restore original configuration with:
Eid.getBinding().getConfigurationSystem().configure(original);
```

Note, that method returns a configurator that can be used to restore configuration to the state before you invoke this configuration method.

#### Validation

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.

### Contributing

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

### Releases

- 2.0.0
- Complete overhaul of library structure
- More obvious exceptions constructors
- Better configuration
- Optional validation

- 1.2.0
- Major performance tweaks and tests for `EidPreconditions` methods #4
- Major performance tweaks and tests for `Eid` class #2
Expand Down
56 changes: 33 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!--
~ Copyright (c) 2015 Wave Software
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.wavesoftware</groupId>
<artifactId>eid-exceptions</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>EID Runtime Exceptions and Utilities</name>
<description>
This small library holds a set of Exceptions that implements idea of fast, reusable, error codes
that can be simple thrown fast in case of unpredictable and unrecoverable application failure.
This small library holds a set of Exceptions that implements idea of
fast, reusable, error codes that can be simple thrown fast in case of
unpredictable and unrecoverable application failure.
</description>
<url>http://wavesoftware.github.io/java-eid-exceptions/</url>
<inceptionYear>2015</inceptionYear>
Expand All @@ -36,10 +56,6 @@
</developer>
</developers>

<prerequisites>
<maven>${maven.required.version}</maven>
</prerequisites>

<scm>
<connection>scm:git:https://github.com/wavesoftware/java-eid-exceptions.git</connection>
<developerConnection>scm:git:git@github.com:wavesoftware/java-eid-exceptions.git</developerConnection>
Expand Down Expand Up @@ -68,8 +84,6 @@
</distributionManagement>

<properties>
<netbeans.hint.license>apache20</netbeans.hint.license>
<maven.required.version>3.0.4</maven.required.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<sonar.working.directory>${project.build.directory}/sonar</sonar.working.directory>
Expand All @@ -93,7 +107,6 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.1</version>
<type>jar</type>
</dependency>

<!-- Tests -->
Expand All @@ -110,12 +123,6 @@
<version>1.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand Down Expand Up @@ -149,13 +156,12 @@
</dependencies>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.0.1</version>
<version>3.5.0.1254</version>
</plugin>
<plugin>
<groupId>external.atlassian.jgitflow</groupId>
Expand Down Expand Up @@ -296,6 +302,11 @@
<artifactId>maven-site-plugin</artifactId>
<version>3.5</version>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down Expand Up @@ -360,7 +371,7 @@
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<executions>
<execution>
Expand All @@ -376,12 +387,11 @@
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.6</version>
<version>2.4.15</version>
</dependency>
</dependencies>
<configuration>
Expand Down
Loading

0 comments on commit 86952e7

Please sign in to comment.