Skip to content

Commit

Permalink
better error handling in maven plugin, see #10
Browse files Browse the repository at this point in the history
  • Loading branch information
fredszaq committed Oct 25, 2013
1 parent 37ec324 commit 08d7bb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ By default, Rezenerator will process files in the `drawable` folder and output t

For a more complete example, take a look at the `rezenerator-maven-sample` project. The configuration in the sample is more convenient: it will take over completely the management of the `res` folder (we use the `res` folder and not one in the `target` folder because otherwise the project cannot be imported in Eclipse). Files processed by Rezenerator are then located in the `src/main/android/drawable` directory. Every other files that should normally be placed in the `res` folder are in `src/main/android/res`. It is then easier to use a SCM (you just have to exclude the `res` folder) and you can use the `src/main/android/res` folder as an overlay (any file you put in there will still be available to Android and will take precedence over the ones Rezenerator generates). Note that `src/main/android/res` is processed by the `maven-resource-plugin` and you can use filtering on it !

The maven plugin works in Eclipse with m2e, you may have to run `mvn clean compile` in the command line before the first import of an image ;)
The maven plugin works in Eclipse with m2e, you will have to refresh the project (F5) after adding a new image of after the first import.

## Note

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

import java.io.File;
import java.util.List;
import java.util.Map.Entry;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import com.tlorrain.android.rezenerator.core.Configuration;
import com.tlorrain.android.rezenerator.core.RezeneratorRunner;
import com.tlorrain.android.rezenerator.core.RunResult;
import com.tlorrain.android.rezenerator.core.log.Logger;

/**
Expand Down Expand Up @@ -51,12 +54,13 @@ public class GenerateMojo extends AbstractMojo {
@Parameter
private List<File> definitionDirs;

public void execute() throws MojoExecutionException {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("input dir : " + inputDirectory);
getLog().info("output dir : " + outputDirectory);
getLog().info("cache dir : " + cacheDirectory);

Configuration configuration = new Configuration();
final Configuration configuration = new Configuration();

configuration.setInDir(inputDirectory)//
.setBaseOutDir(outputDirectory)//
Expand All @@ -65,14 +69,14 @@ public void execute() throws MojoExecutionException {
.setLogger(new MavenLogger());

if (scannedPackages != null) {
for (String pkg : scannedPackages) {
for (final String pkg : scannedPackages) {
getLog().info("add scanned package: " + pkg);
configuration.addScannedPackage(pkg);
}
}

if (definitionDirs != null) {
for (File dir : definitionDirs) {
for (final File dir : definitionDirs) {
configuration.addDefinitionDir(dir);
}
} else {
Expand All @@ -83,30 +87,42 @@ public void execute() throws MojoExecutionException {
configuration.setForceUpdate(true);
}

new RezeneratorRunner().run(configuration).isSuccessful();
final RunResult runResult = new RezeneratorRunner().run(configuration);
if (!runResult.isSuccessful()) {
if (runResult.getErrors().size() > 0) {
final Entry<File, Exception> firstError = runResult.getErrors().entrySet().iterator().next();
throw new MojoFailureException("Rezenerator reported " + runResult.getErrors().size()
+ " errors, first one was on " + firstError.getKey() + " : "
+ firstError.getValue().getMessage(), firstError.getValue());
} else {
// TODO make sure we never go, there :D
throw new MojoFailureException("Rezenerator execution failed, no further details were provided");
}

}

}

private class MavenLogger implements Logger {

@Override
public void info(String info) {
GenerateMojo.this.getLog().info(info);
public void info(final String info) {
getLog().info(info);
}

@Override
public void verbose(String debug) {
GenerateMojo.this.getLog().debug(debug);
public void verbose(final String debug) {
getLog().debug(debug);
}

@Override
public void verbose(Exception exception) {
GenerateMojo.this.getLog().debug(exception);
public void verbose(final Exception exception) {
getLog().debug(exception);
}

@Override
public void error(String error) {
GenerateMojo.this.getLog().error(error);
public void error(final String error) {
getLog().error(error);
}

}
Expand Down

0 comments on commit 08d7bb0

Please sign in to comment.