Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Suszyński Krzysztof committed Mar 30, 2016
2 parents f2049dd + 339b63f commit 6b4367d
Show file tree
Hide file tree
Showing 19 changed files with 610 additions and 406 deletions.
31 changes: 24 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
language: java
sudo: false
script: mvn clean install -P '!sonar,ci' --fail-at-end
script: mvn clean install --fail-at-end
notifications:
email:
on_failure: true
jdk:
- openjdk6
- openjdk7
- oraclejdk7
- oraclejdk8
matrix:
include:
- jdk: openjdk6
env: JACOCO=true
- jdk: openjdk7
env: JACOCO=true COVERALLS=true
- jdk: oraclejdk7
env: JACOCO=true
- jdk: oraclejdk8
env: JACOCO=true
- jdk: openjdk7
env: JACOCO=true GDMSESSION=sonar
- jdk: openjdk7
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
30 changes: 19 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?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">
<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.1.1-SNAPSHOT</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>EID Runtime Exceptions and Utilities</name>
Expand Down Expand Up @@ -80,9 +79,12 @@
<sonar.java.source>${java.source.version}</sonar.java.source>
<maven.compiler.source>1.${java.source.version}</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<jacoco.version>0.7.6.201602180812</jacoco.version>

<skipTests/>
<skipTests />
<coveralls.skip>${skipTests}</coveralls.skip>
<sonar.skip>${skipTests}</sonar.skip>
<failsafe.rerunFailingTestsCount>2</failsafe.rerunFailingTestsCount>
</properties>

<dependencies>
Expand Down Expand Up @@ -129,7 +131,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.19</version>
<version>1.7.20</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -169,7 +171,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
Expand Down Expand Up @@ -319,8 +321,13 @@

<profiles>
<profile>
<id>ci</id>

<id>jacoco</id>
<activation>
<property>
<name>env.JACOCO</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -374,13 +381,14 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.5</version>
<version>2.4.6</version>
</dependency>
</dependencies>
<configuration>
<defaults>
<sonar.issues.file>${sonar.working.directory}/${sonar.report.export.path}
</sonar.issues.file>
<sonar.skip>${sonar.skip}</sonar.skip>
</defaults>
<source>${project.basedir}/src/test/groovy/verify-sonar-issues.groovy</source>
</configuration>
Expand All @@ -399,10 +407,10 @@
</profile>

<profile>
<id>travis</id>
<id>coveralls</id>
<activation>
<property>
<name>env.TRAVIS</name>
<name>env.COVERALLS</name>
<value>true</value>
</property>
</activation>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package pl.wavesoftware.eid;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
* @since 2016-03-26
*/
@Nonnull
@TypeQualifierDefault(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ReturnTypesAreNonnullByDefault {
}
44 changes: 15 additions & 29 deletions src/main/java/pl/wavesoftware/eid/exceptions/Eid.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package pl.wavesoftware.eid.exceptions;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -30,7 +29,7 @@
* <p>
* Exception identifier for all Eid Runtime Exceptions.
*
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class Eid implements Serializable {

Expand All @@ -50,6 +49,8 @@ public class Eid implements Serializable {

private static final int MESSAGE_FORMAT_NUM_SPEC = 2;

private static final String EMPTY_REF = "";

private static String messageFormat = DEFAULT_MESSAGE_FORMAT;

private static UniqIdGenerator uniqIdGenerator = DEFAULT_UNIQ_ID_GENERATOR;
Expand All @@ -62,7 +63,7 @@ public class Eid implements Serializable {

private final String ref;

private final Future<String> futureUniqueId;
private String uniqueId;

/**
* Constructor
Expand All @@ -71,9 +72,8 @@ public class Eid implements Serializable {
* @param ref an optional reference
*/
public Eid(String id, @Nullable String ref) {
futureUniqueId = new UniqFuture();
this.id = id;
this.ref = ref == null ? "" : ref;
this.ref = ref == null ? EMPTY_REF : ref;
}

/**
Expand All @@ -82,7 +82,8 @@ public Eid(String id, @Nullable String ref) {
* @param id the exception id, must be unique developer inserted string, from date
*/
public Eid(String id) {
this(id, null);
this.id = id;
this.ref = EMPTY_REF;
}

/**
Expand Down Expand Up @@ -161,26 +162,25 @@ public static String setRefFormat(String refFormat) {
/**
* Makes a log message from this EID object
* <p>
* <p>This method is for convenience of usage of EID in logging. You can use it like this:
* <p>
* This method is for convenience of usage of EID in logging. You can use it like this:
* <pre>
* log.debug(new Eid("20151025:202129").makeLogMessage("A request: %s", request));
* </pre>
* @param logMessageFormat a log message format as accepted by {@link String#format(String, Object...)}
* @param parameters a parameters for logMessageFormat to by passed to {@link String#format(String, Object...)}
* @return a formatted message
*/
public String makeLogMessage(@Nonnull String logMessageFormat, @Nonnull Object... parameters) {
public String makeLogMessage(String logMessageFormat, Object... parameters) {
String message = String.format(logMessageFormat, parameters);
return String.format(getMessageFormat(), this.toString(), message);
}

@Override
public String toString() {
if ("".equals(ref)) {
return String.format(format, id, futureUniqueId.get());
return String.format(format, id, getUniq());
}
return String.format(refFormat, id, ref, futureUniqueId.get());
return String.format(refFormat, id, ref, getUniq());
}

/**
Expand All @@ -207,7 +207,10 @@ public String getRef() {
* @return a unique string
*/
public String getUniq() {
return futureUniqueId.get();
if (uniqueId == null) {
uniqueId = uniqIdGenerator.generateUniqId();
}
return uniqueId;
}

private static void validateFormat(String format, int numSpecifiers) {
Expand Down Expand Up @@ -241,23 +244,6 @@ public interface UniqIdGenerator {
String generateUniqId();
}

private interface Future<T extends Serializable> extends Serializable {
T get();
}

private static final class UniqFuture implements Future<String> {
private static final long serialVersionUID = 20160325113314L;
private String future;
private UniqFuture() {}
@Override
public String get() {
if (future == null) {
future = uniqIdGenerator.generateUniqId();
}
return future;
}
}

private static final class StdUniqIdGenerator implements UniqIdGenerator {

private static final int BASE36 = 36;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Indicate that object contains a Eid object
*
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public interface EidContainer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see IllegalArgumentException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidIllegalArgumentException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidIllegalArgumentException(Eid id, String messageFormat, Object... param
}

/**
* @inheritdoc
* @return {@link IllegalArgumentException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see IllegalStateException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidIllegalStateException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidIllegalStateException(Eid id, String messageFormat, Object... paramete
}

/**
* @inheritdoc
* @return {@link IllegalStateException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see IndexOutOfBoundsException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidIndexOutOfBoundsException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidIndexOutOfBoundsException(Eid id, String messageFormat, Object... para
}

/**
* @inheritdoc
* @return {@link IndexOutOfBoundsException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see NullPointerException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidNullPointerException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidNullPointerException(Eid id, String messageFormat, Object... parameter
}

/**
* @inheritdoc
* @return {@link NullPointerException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* <p>
* For convenience use {@link pl.wavesoftware.eid.utils.EidPreconditions}
*
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidRuntimeException extends RuntimeException implements EidContainer {

Expand All @@ -54,13 +54,13 @@ public EidRuntimeException(String eid, String ref) {
}

/**
* Constructs a new runtime exception with the specified cause, a exception Id and detail message of <tt>eid.toString() + " =>
* " + (cause==null ? null : cause.toString())</tt>
* (which typically contains the class and detail message of
* <tt>cause</tt>). This constructor is useful for runtime exceptions that are little more than wrappers for other throwable.
* Constructs a new runtime exception with the specified cause, a exception Id and detail message of
* <code>eid.toString() + " =&gt; " + (cause==null ? null : cause.toString())</code> (which typically contains
* the class and detail message of <code>cause</code>). This constructor is useful for runtime exceptions
* that are little more than wrappers for other throwable.
*
* @param eid exception ID
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <tt>null</tt>
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <code>null</code>
* value is permitted, and indicates that the cause is nonexistent or unknown.)
*/
public EidRuntimeException(String eid, Throwable cause) {
Expand All @@ -72,7 +72,7 @@ public EidRuntimeException(String eid, Throwable cause) {
*
* @param eid exception ID
* @param ref the ref code for Eid
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <tt>null</tt> value is
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <code>null</code> value is
* permitted, and indicates that the cause is nonexistent or unknown.)
*/
public EidRuntimeException(String eid, String ref, Throwable cause) {
Expand All @@ -92,10 +92,10 @@ public EidRuntimeException(Eid id) {
/**
* Constructs a new runtime exception with the specified Eid object and cause
* <p>
* The detail message is computed as <tt>String.format(Eid.getMessageFormat(), id.toString(), message(cause))</tt>
* The detail message is computed as <code>String.format(Eid.getMessageFormat(), id.toString(), message(cause))</code>
*
* @param id exception ID
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <tt>null</tt> value is
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <code>null</code> value is
* permitted, and indicates that the cause is nonexistent or unknown.)
*/
public EidRuntimeException(Eid id, Throwable cause) {
Expand Down
Loading

0 comments on commit 6b4367d

Please sign in to comment.