package com.tlorrain.android.rezenerator;

import static org.apache.maven.plugins.annotations.LifecyclePhase.INITIALIZE;

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

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

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

/**
 * Goal generating png resources from source (svg...) files
 * 
 */
@Mojo(name = "generate", defaultPhase = INITIALIZE)
public class GenerateMojo extends AbstractMojo {

	/**
	 * Directory containing the source files.
	 * 
	 */
	@Parameter(required = true, defaultValue = "${project.basedir}/drawable")
	private File inputDirectory;

	/**
	 * Directory where the images will be generated.
	 * 
	 */
	@Parameter(required = true, defaultValue = "${project.basedir}/res")
	private File outputDirectory;

	/**
	 * Directory where the images will be cached to speed up the build.
	 * 
	 */
	@Parameter(defaultValue = "${project.basedir}/.rezenerator-cache~")
	private File cacheDirectory;

	/**
	 * Packages to scan for definitions and processors.
	 */
	@Parameter
	private List<String> scannedPackages;

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

		Configuration configuration = new Configuration();

		configuration.setInDir(inputDirectory)//
				.setBaseOutDir(outputDirectory)//
				.addScannedPackage("com.tlorrain.android")// TODO add this by
															// default in conf
				.setLogger(new MavenLogger());

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

		if (System.getProperties().getProperty("rezenerator.force.update") != null) {
			configuration.setForceUpdate(true);
		}

		new RezeneratorRunner().run(configuration);

	}

	private class MavenLogger implements Logger {

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

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

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

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

	}
}

@@ -368,54 +368,8 @@
 ter;
-%0Aimport org.apache.maven.project.MavenProject;
 %0A%0Aim
@@ -1831,16 +1831,50 @@
 er());%0A%0A
+%09%09if (scannedPackages != null) %7B%0A%09
 %09%09for (S
@@ -1904,16 +1904,17 @@
 ages) %7B%0A
+%09
 %09%09%09getLo
@@ -1954,16 +1954,17 @@
 + pkg);%0A
+%09
 %09%09%09confi
@@ -1992,24 +1992,29 @@
 ckage(pkg);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%0A%09%09if (S

fix a NPE when no scanned packages configured in maven plugin