All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pyx4me.maven.j2me.PreprocessMojo Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
/**
 * Pyx4me framework
 * Copyright (C) 2006-2007 pyx4.com.
 * 
 * @author vlads
 * @version $Id: PreprocessMojo.java 1508 2007-10-17 08:59:03Z vlads $
 */
package com.pyx4me.maven.j2me;

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

import net.sf.jour.PreProcessor;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;

import com.pyx4j.log4j.MavenLogAppender;

import de.pleumann.antenna.misc.Utility;

/**
 * The j2me:preprocess helper to optimize generated classes.
 * 
 * @author vlads
 * 
 * @goal preprocess
 * 
 * @description Preprocess
 */
public abstract class PreprocessMojo extends AbstractJadWtkMojo {

	/**
	 * Reads configuration options from the given file. File or resource name.
	 * 
	 * @parameter default-value="${basedir}/jour.xml"
	 */
	private String jourConfig;

	/**
	 * Output directory name relative to outputDirectory parameter.
	 * 
	 * @parameter expression="iclasses"
	 * @required
	 */
	protected String output;

	public void execute() throws MojoExecutionException, MojoFailureException {
		PreprocessMojo.executeClassPreprocessor(jourConfig, getJarFile(classifier), output, this);
	}

	public static File executeClassPreprocessor(String jourConfig, File jarFileOrClassesDirectory, String output,
			AbstractJadWtkMojo mojo) throws MojoExecutionException, MojoFailureException {
		MavenLogAppender.startPluginLog(mojo);
		try {

			mojo.getLog().info(jourConfig);

			File out = new File(mojo.outputDirectory, output);

			List classpath = new Vector();

			if (mojo.useWtkLibs) {
				// Find MIDP ClassPath from WTK
				Project antProject = mojo.getAntProject();
				Task dummyTaks = new Task() {
				};
				dummyTaks.setTaskName("jour");
				dummyTaks.setProject(antProject);

				Utility utility = Utility.getInstance(antProject, dummyTaks);

				String mdipClassPath = utility.getMidpApi();
				classpath.add(mdipClassPath);
			} else {
				List dependancy = mojo.mavenProject.getCompileArtifacts();
				for (Iterator i = dependancy.iterator(); i.hasNext();) {
					Artifact artifact = (Artifact) i.next();
					File file = getClasspathElement(artifact, mojo.mavenProject);
					classpath.add(file.toString());
				}
				if (mojo.libs != null) {
					for (Iterator i = mojo.libs.iterator(); i.hasNext();) {
						Object lib = i.next();
						classpath.add(lib.toString());
					}
				}
			}

			PreProcessor pp = new PreProcessor(jourConfig, jarFileOrClassesDirectory, out, classpath);

			pp.setCopyClasses(true);
			pp.setCopyResources(true);

			try {
				pp.process();
			} catch (Exception e) {
				mojo.getLog().error("PreProcessing error", e);
				throw new MojoExecutionException("PreProcessing error", e);
			}

			return out;

		} finally {
			MavenLogAppender.endPluginLog(mojo);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy