Skip to content

Commit

Permalink
Merge branch 'release/0.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeslopalo committed Oct 28, 2016
2 parents cf0465a + 368f9da commit fa410f0
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 42 deletions.
19 changes: 19 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
engines:

checkstyle:
enabled: true
channel: "beta"
checks:
com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck:
enabled: false

pmd:
enabled: true
channel: "beta"

fixme:
enabled: true

csslint:
enabled: true

markdownlint:
enabled: true
checks:
MD026:
enabled: false
MD014:
enabled: false
MD013:
enabled: false
exclude_fingerprints:
- ada55f17fa4a11ae8c12260832bb30ee

shellcheck:
enabled: true

ratings:
paths:
- "**.java"
- "**.css"
- "**.md"
exclude_paths: []
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ insert_final_newline = false
indent_size = 2

[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = true
indent_size = 2

[*.txt]
Expand Down
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
### v0.2.2 (2016-10-17) - Switch off doclint with java8
### v0.2.3 (2016-10-29) - Fix some codeclimate issues

* [ad29b01] Fix cobertura.sh issues
* [5a5722f] Fix README.md issues
* [f222792] Fix some codeclimante issues
* [44371c7] Fix javadoc for Flash
* [ae838fb] Exclude rules in codeclimate
* [9186c04] Fix 'pwd' command invocation from cobertura.sh
* [77316e7] Try to disable complete checks and not single issues
* [320e8e9] Add an extra white line before heading
* [740f7f8] Exclude more checks for codeclimate analysis
* [b6064ba] Fix codeclimate issues
* [750f5d1] Disable a codeclimate check
* [15dae76] Bump version to 0.2.3


### vv0.2.2 (2016-10-17) - Switch off doclint with java8

* [352dd2e] Switch off java8's doclint (temporal)
* [e566744] Bump version to 0.2.2
* [be5954c] Update CHANGELOG.md with 0.2.2 changes


### vv0.2.1 (2016-10-17) - Fix bintray's distribution repository id
Expand Down
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flash-messages

_An easy way to send & show *flash messages*_

|Build| State |
Expand All @@ -10,26 +11,27 @@ _An easy way to send & show *flash messages*_
|Coverity Scan |[![Coverity Scan Build Status](https://scan.coverity.com/projects/2142/badge.svg?branch=master)](https://scan.coverity.com/projects/2142?branch=master)|
|Code climate|[![Code Climate](https://codeclimate.com/github/jeslopalo/flash-messages/badges/gpa.svg)](https://codeclimate.com/github/jeslopalo/flash-messages)<br/>[![Test Coverage](https://codeclimate.com/github/jeslopalo/flash-messages/badges/coverage.svg)](https://codeclimate.com/github/jeslopalo/flash-messages/coverage)<br/>[![Issue Count](https://codeclimate.com/github/jeslopalo/flash-messages/badges/issue_count.svg)](https://codeclimate.com/github/jeslopalo/flash-messages)|

# Flash!
## Flash!

When applying the [Post/Redirect/Get](http://kcy.me/15fxw) pattern in web application development, I run always into the same problem: __how to communicate the result to the user after the redirection__.

While it is a known problem and it has been resolved in other platforms (like Ruby), Java does not seem to provide a simple and elegant solution.

*flash-messages* is an easy way to communicate flash messages after a redirection in Java web applications.

Today, you can use *flash-messages* in applications which use **spring-mvc** as web framework and **Jstl** to render views.
Today, you can use *flash-messages* in applications which use **spring-mvc** as web framework and **Jstl** to render views.

In future releases, it will be possible to use it in **JavaEE** applications and possibly with another view technologies like **Thymeleaf** or **Freemarker**.

Let's start!

## Features

- Seamless integration with ```@RequestMapping``` and ```@ExceptionHandler``` methods in the **spring-mvc** framework ```@Controller```'s
- Different levels of messages (ie. __SUCCESS__, __INFO__, __WARNING__, __ERROR__)
- Different levels of messages (ie. __SUCCESS__, __INFO__, __WARNING__, __ERROR__)
- Resolution of __i18n__ messages with arguments
- Resolution of __i18n__ arguments (ie Text, Link)
- Resolution of __i18n__ arguments (ie Text, Link)
- Easy integration with the **Twitter Bootstrap** alerts


## Getting started

Expand All @@ -38,7 +40,9 @@ Let's start!
#### Maven

##### Bill Of Materials (BOM)

*flash-messages* artifacts are in **Maven Central** and includes a BOM ([Bill Of Materials](http://kcy.me/15g1b)) to facilitate the use of its modules.

```xml
<dependencyManagement>
<dependencies>
Expand All @@ -54,7 +58,9 @@ Let's start!
```

##### Artifacts

After importing the *BOM* in your `pom.xml` you can easily declare the modules.

```xml
<dependencies>
...
Expand All @@ -75,14 +81,17 @@ After importing the *BOM* in your `pom.xml` you can easily declare the modules.
```

#### Download

You can download the latest version directly from GitHub:

- `flash-messages-core` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-core/0.2.2/flash-messages-core-0.2.2.jar)_)**
- `flash-messages-spring` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-spring/0.2.2/flash-messages-spring-0.2.2.jar)_)**
- `flash-messages-taglibs` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-taglibs/0.2.2/flash-messages-taglibs-0.2.2.jar)_)**
- `flash-messages-core` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-core/0.2.2/flash-messages-core-0.2.2.jar)_)**
- `flash-messages-spring` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-spring/0.2.2/flash-messages-spring-0.2.2.jar)_)**
- `flash-messages-taglibs` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-taglibs/0.2.2/flash-messages-taglibs-0.2.2.jar)_)**

#### Building from sources

You can build the latest version directly from source. Just run:

```sh
$ mkdir flash-messages-repository
$ cd flash-messages-repository
Expand All @@ -92,30 +101,35 @@ $ mvn clean package
```

### Configuration

*flash-messages* is configured using **spring** [JavaConfig](http://kcy.me/15fuu). It has been tested with versions greater or equal than **3.2.6.RELEASE**.

#### Default configuration

In order to obtain the default configuration, just add ```@EnableFlashMessages``` to a ```@Configuration``` class (the same with ```@EnableWebMvc``` should be enough).

```java
import es.sandbox.ui.messages.spring.config.annotation.EnableFlashMessages;

@Configuration
@EnableFlashMessages
@EnableWebMvc
public class WebMvcConfigurer {
...
@Bean
public MessageSource messageSource() {
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource= new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("WEB-INF/i18n/messages");
messageSource.setBasenames("WEB-INF/i18n/messages");
return messageSource;
}
...
}
```

#### Custom configuration

To modify the default behavior of *flash-messages* just extend ```FlashMessagesConfigurerAdapter``` and override those methods that you want to customize.

```java
import es.sandbox.ui.messages.Level;
import es.sandbox.ui.messages.CssClassesByLevel;
Expand All @@ -127,7 +141,7 @@ import es.sandbox.ui.messages.spring.config.annotation.FlashMessagesConfigurerAd
public class CustomFlashMessagesConfigurer extends FlashMessagesConfigurerAdapter {

/**
* Sets the styles of flash-messages to be compatible
* Sets the styles of flash-messages to be compatible
* with twitter bootstrap alerts
*/
@Override
Expand All @@ -140,21 +154,22 @@ public class CustomFlashMessagesConfigurer extends FlashMessagesConfigurerAdapte
The main elements that can be configured or customized are: _levels of messages_, the _css classes applied to the levels_, the _strategy to resolve i18n messages_ or _modify the scope where messages are stored_.

### Writing messages

In order to write messages, just declare an argument of type ```Flash``` in the handler method (or in a ```@ExceptionHandler``` method), then you can add messages to the different levels.

```java
@RequestMapping(value="/target", method= RequestMethod.POST)
String post(Flash flash, @ModelAttribute FormBackingBean form, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
if (bindingResult.hasErrors()) {
return "form";
}

Result result= this.service.doSomething(form.getValue());
if (result.isSuccessful()) {
flash.success("messages.success-after-post", result.getValue());
return "redirect:/successful-target-after-post";
}

flash.error("messages.error-in-service", form.getValue());
return "redirect:/error-target-after-post";
}
Expand All @@ -167,7 +182,9 @@ String handle(ServiceException exception, Flash flash) {
```

### Painting messages

Finally, you must to include the ```<flash:messages />``` taglib in your views (or better in your decorator template).

```jsp
<%@ taglib prefix="flash" uri="http://sandbox.es/tags/flash-messages" %>
Expand Down
2 changes: 1 addition & 1 deletion flash-messages-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion flash-messages-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class Context {
* @param strategy
* @throws NullPointerException
*/
Context(StoreAccessorFactory factory, MessageResolverStrategy strategy) throws NullPointerException {
Context(StoreAccessorFactory factory, MessageResolverStrategy strategy)
throws NullPointerException {

if (factory == null) {
throw new NullPointerException("StoreAccessorFactory can't not be null");
Expand Down Expand Up @@ -132,10 +133,11 @@ private StoreAccessor createAccessor(HttpServletRequest request)

@Override
public String toString() {
return String.format("Context [factory=%s, messageResolver=%s, levels=%s, cssClassesByLevel=%s]",
this.factory.getClass().getSimpleName(),
this.messageResolver,
this.levels,
this.cssClassesByLevel);
return
String.format("Context [factory=%s, messageResolver=%s, levels=%s, cssClassesByLevel=%s]",
this.factory.getClass().getSimpleName(),
this.messageResolver,
this.levels,
this.cssClassesByLevel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ private static EnumMap<Level, String> defaultLevelCssClasses() {
}

private static String cssClass(Level level) {
return String.format("%s %s-%s", DEFAULT_MAIN_CSS_CLASS, DEFAULT_PREFIX_CSS_CLASSES, level.name().toLowerCase());
return String.format("%s %s-%s",
DEFAULT_MAIN_CSS_CLASS,
DEFAULT_PREFIX_CSS_CLASSES,
level.name().toLowerCase());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@


/**
* <p>
* Allow controllers to add flash messages in the view.
* <p>
* Some examples:
* <p>
* <p>
* <pre>
* flash.success(&quot;i18n.message.code&quot;);
* flash.error(&quot;i18n.message.code&quot;, 1L, new Date());
* flash.warning(&quot;i18n.message.code&quot;, Arguments.text(&quot;i18n.argument.code&quot;));
* flash.info(&quot;i18n.message.code&quot;, Arguments.link(&quot;/path/to/somewhere&quot;).title(&quot;i18n.argument.code&quot;));
* flash.error(&quot;i18n.message.code&quot;,
* 1L, new Date());
* flash.warning(&quot;i18n.message.code&quot;,
* Arguments.text(&quot;i18n.argument.code&quot;));
* flash.info(&quot;i18n.message.code&quot;,
* Arguments.link(&quot;/path/to/somewhere&quot;).title(&quot;i18n.argument.code&quot;));
* </pre>
* <p>
* <br/>
*
* @author jeslopalo
* @since v0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public boolean equals(Object obj) {
*/
@Override
public String toString() {
return String.format("[(%1$tF %1$tT) %2$s: %3$s]", this.timestamp.toDate(), this.level, this.text);
return String.format("[(%1$tF %1$tT) %2$s: %3$s]",
this.timestamp.toDate(), this.level, this.text);
}
}
2 changes: 1 addition & 1 deletion flash-messages-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<packaging>pom</packaging>

<name>Flash Messages POM</name>
Expand Down
2 changes: 1 addition & 1 deletion flash-messages-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion flash-messages-taglibs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<relativePath>./flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions src/main/scripts/build/cobertura.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

echo "Working directory: [`pwd`]"
echo "Working directory: [$(pwd)]"

echo "Generating cobertura reports to be submited to coverall service"
mvn cobertura:cobertura coveralls:report -P coveralls $1
mvn cobertura:cobertura coveralls:report -P coveralls "$1"

0 comments on commit fa410f0

Please sign in to comment.