📄 sunpreverifier.java
字号:
package org.momeunit.ant.preverifier;import java.io.File;import java.io.IOException;import java.util.Enumeration;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Location;import org.apache.tools.ant.Project;import org.momeunit.ant.core.Utility;/** * Preverifier that runs Sun WTK <code>preverify</code> tool. * * @author Sergio Morozov * @version 1.1.2 */public class SunPreverifier extends Preverifier{ /** * Array of preverify executables to be tested. */ private static final String[] EXECUTABLES = { "bin/preverify", "bin/preverify.exe" }; /** * Instantiates Sun preverifier with given WTK home directory. * * @param wtkHome * WTK home directory. * @since 1.1 */ public SunPreverifier(File wtkHome) { super(wtkHome); } /** * Instantiates Sun preverifier. * * @since 1.1 */ public SunPreverifier() { this(null); } /** * Starts Sun WTK <code>preverify</code> tool. * * @since 1.1 */ public Process execute(File src, File toDir, File atDir) { if (getWtkHome() == null) throw new NullPointerException("wtkHome"); Process res = null; Utility.assertExists(src); Utility.assertDirectory(toDir); if (atDir != null) Utility.assertDirectory(atDir); StringBuffer sb = new StringBuffer(); sb.append(getExecutable()); if (getClasspath() != null && getClasspath().size() > 0) sb.append( " -classpath ").append(getClasspath().toString()); sb.append(" -d ").append(toDir.getAbsolutePath()); if (getConfig() != null) sb.append(" -target CLDC").append(getConfig()); for (Enumeration e = enumeratePropertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); if (name.equals("cldc")) sb.append(" -cldc"); else if (name.equals("cldc10")) sb.append(" -cldc1.0"); else if (name.equals("nonative")) sb.append(" -nonative"); else if (name.equals("nofinalize")) sb.append(" -nofinalize"); else if (name.equals("nofp")) sb.append(" -nofp"); else throw new BuildException("unknown preverify property " + name, getTask() != null ? getTask().getLocation() : Location.UNKNOWN_LOCATION); } sb.append(' ').append(src.getAbsolutePath()); try { res = Runtime.getRuntime().exec(sb.toString(), null, atDir); Utility.log(getTask(), "Prevrifier command-line " + sb.toString(), Project.MSG_DEBUG); } catch (IOException e) { throw new BuildException("Error executing preverifier.", e, getTask() != null ? getTask().getLocation() : Location.UNKNOWN_LOCATION); } return res; } /** * Returns existent executable of Sun WTK <code>preverify</code> tool. * * @return the existent executable of Sun WTK <code>preverify</code> tool. * @throws BuildException * when no executable found. * @since 1.1 */ public String getExecutable() { String res = null; for (int i = 0; i < EXECUTABLES.length; i++) { File executable = new File(getWtkHome().getAbsolutePath() + '/' + EXECUTABLES[i]); if (executable.exists() && executable.isFile()) res = executable .getAbsolutePath(); } if (res == null) throw new BuildException("No Sun Preverifier found."); return res; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -