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

com.pyx4me.maven.j2me.WtkPreverifyMojo 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: WtkPreverifyMojo.java 1514 2007-10-18 19:21:45Z vlads $
 */
package com.pyx4me.maven.j2me;

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

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 de.pleumann.antenna.misc.Utility;

/**
 * The preverify MoJo runs the WTK preverify command from the given J2ME SDK.
 * 

* Preverification takes place in the phase process-classes, that means after * Successful compilation. The MoJo takes the classes to preverify from * ${project.build.outputDirectory} and places the preverified classes into the * same directory. Therefore no change to the packaging phase is necessary. *

* * @goal preverify * @phase process-classes * @description Preverifies j2me class files * */ public class WtkPreverifyMojo extends AbstractWtkMojo { /** * Specifies the input jar name of the application to be processed. * * @parameter expression="${project.build.finalName}.jar" * @required */ protected File injar; public void execute() throws MojoExecutionException, MojoFailureException { executeWtkPreverifyTask(injar, this); } static void executeWtkPreverifyTask(File jarFile, AbstractWtkMojo mojo) throws MojoExecutionException, MojoFailureException { Project antProject = mojo.getAntProject(); Task dummyTaks = new Task() { }; dummyTaks.setTaskName("preverify"); dummyTaks.setProject(antProject); Utility utility = Utility.getInstance(antProject, dummyTaks); StringBuffer path = new StringBuffer(); if (!mojo.useWtkLibs) { List dependancy = mojo.mavenProject.getCompileArtifacts(); for (Iterator i = dependancy.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); if (!mojo.isUseDependency(artifact)) { continue; } File file = getClasspathElement(artifact, mojo.mavenProject); mojo.getLog().info("WtkPreverify.classpathEntry " + file); if (path.length() > 0) { path.append(File.pathSeparatorChar); } path.append(file.getAbsolutePath()); } if (mojo.libs != null) { for (Iterator i = mojo.libs.iterator(); i.hasNext();) { Object lib = i.next(); if (path.length() > 0) { path.append(File.pathSeparatorChar); } path.append(lib.toString()); } } mojo.getLog().info("Preverify classpath " + path); } else { String mdipClassPath = utility.getMidpApi(); mojo.getLog().debug("Preverify use mdipClassPath " + mdipClassPath); path.append(mdipClassPath); } boolean cldc = true; int flags = 0; utility.preverify(jarFile, mojo.outputDirectory, path.toString(), cldc, flags); } // static WtkPreverify createWtkPreverifyTask(AbstractWtkMojo mojo) throws // MojoExecutionException, // MojoFailureException { // // WtkPreverify task = new WtkPreverify(); // mojo.initTask(task); // // Project antProject = mojo.getAntProject(); // if (!mojo.useWtkLibs) { // List dependancy = mojo.mavenProject.getCompileArtifacts(); // for (Iterator i = dependancy.iterator(); i.hasNext();) { // Artifact artifact = (Artifact) i.next(); // if (!mojo.isUseDependency(artifact)) { // continue; // } // File file = getClasspathElement(artifact, mojo.mavenProject); // mojo.getLog().info("WtkPreverify.classpathEntry " + file); // task.setClasspath(new Path(antProject, file.getAbsolutePath())); // } // if (mojo.libs != null) { // for (Iterator i = mojo.libs.iterator(); i.hasNext();) { // Object lib = i.next(); // task.setBootclasspath(new Path(antProject, lib.toString())); // } // } // } else { // Utility utility = Utility.getInstance(antProject, task); // String mdipClassPath = utility.getMidpApi(); // mojo.getLog().debug("WtkPreverify use mdipClassPath " + mdipClassPath); // task.setBootclasspath(new Path(antProject, mdipClassPath)); // } // // // Hacks to keep tmp directory // // File tmpDir = new FileTmpDirRemovalHack(mojo.outputDirectory, // // "wtk-preverify"); // // if (!tmpDir.exists()) { // // tmpDir.mkdir(); // // } // // Utility utility = Utility.getInstance(antProject, task); // // privateSet(utility, "tmpDir", tmpDir); // // mojo.getLog().debug("WtkPreverify.bootclasspath " + // task.getBootclasspath()); // mojo.getLog().info("WtkPreverify.fullClasspath " + // task.getFullClasspath()); // // return task; // } // private static class FileTmpDirRemovalHack extends File { // // private static final long serialVersionUID = 1L; // // public FileTmpDirRemovalHack(File file) { // super(file.getAbsolutePath()); // } // // public FileTmpDirRemovalHack(File parent, String child) { // super(parent, child); // } // // public File[] listFiles() { // StackTraceElement[] ste = new Throwable().getStackTrace(); // if (ste[1].getMethodName().equals("delete")) { // return new File[0]; // } // return super.listFiles(); // } // // public boolean delete() { // return true; // } // } // // private static void privateSet(Object obj, String name, Object value) // throws MojoExecutionException, // MojoFailureException { // Class klass = obj.getClass(); // try { // Field f = null; // Field fields[] = klass.getDeclaredFields(); // for (int i = 0; i < fields.length; i++) { // if (name.equals(fields[i].getName())) { // fields[i].setAccessible(true); // f = fields[i]; // break; // } // } // f.set(obj, value); // } catch (Throwable e) { // e.printStackTrace(); // throw new MojoExecutionException("Can't accss filed " + name + " " + // e.toString(), e); // } // } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy