001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.ant;
022:
023: import net.charabia.jsmoothgen.application.*;
024: import net.charabia.jsmoothgen.skeleton.*;
025: import net.charabia.jsmoothgen.pe.*;
026: import java.io.*;
027:
028: public class JSmoothGen extends org.apache.tools.ant.Task {
029: /** JSmooth project file. */
030: private java.io.File m_prjfile;
031:
032: /** JSmooth skeletons root directory. */
033: private java.io.File m_skeletonRoot;
034:
035: /** Log level. */
036: private boolean m_verbose;
037:
038: /** Destination directory for the generated executable. */
039: private File m_destdir;
040:
041: /**
042: * Sets the destination directory for the generated executable.
043: *
044: * @param destdir the destination directory for the generated executable.
045: */
046: public void setDestdir(java.io.File destdir) {
047: m_destdir = destdir;
048: }
049:
050: /**
051: * Sets the JSmooth project file.
052: *
053: * @param prjfile the JSmooth project file.
054: */
055: public void setProject(java.io.File prjfile) {
056: m_prjfile = prjfile;
057: }
058:
059: /**
060: * Sets the JSmooth skeletons root directory.
061: *
062: * @param skeletonRoot the JSmooth skeletons root directory.
063: */
064: public void setSkeletonRoot(java.io.File skeletonRoot) {
065: m_skeletonRoot = skeletonRoot;
066: }
067:
068: /**
069: * Sets the log level to verbose or not.
070: *
071: * @param verbose the log level to verbose or not.
072: */
073: public void setVerbose(boolean val) {
074: m_verbose = val;
075: }
076:
077: public void execute() throws org.apache.tools.ant.BuildException {
078: if (m_prjfile == null)
079: throw new org.apache.tools.ant.BuildException(
080: "Project file not set");
081: if (m_skeletonRoot == null)
082: throw new org.apache.tools.ant.BuildException(
083: "Skeleton Root dir file not set");
084:
085: File prj = m_prjfile;
086: if (prj.exists() == false) {
087: prj = new File(prj.toString() + ".jsmooth");
088: }
089:
090: if (prj.exists() == false) {
091: throw new org.apache.tools.ant.BuildException(
092: "Project file " + prj + " not found");
093: }
094:
095: try {
096: JSmoothModelBean model = JSmoothModelPersistency.load(prj);
097:
098: File basedir = prj.getParentFile();
099:
100: File out;
101: if (m_destdir == null) {
102: out = new File(basedir, model.getExecutableName());
103: } else {
104: out = new File(m_destdir, model.getExecutableName());
105: }
106: log("Executable file is " + out);
107:
108: SkeletonList skelList = new SkeletonList(m_skeletonRoot);
109:
110: SkeletonBean skel = skelList.getSkeleton(model
111: .getSkeletonName());
112: File skelroot = skelList.getDirectory(skel);
113:
114: final ExeCompiler compiler = new ExeCompiler();
115: if (m_verbose) {
116: compiler.addListener(new ExeCompiler.StepListener() {
117: public void complete() {
118: }
119:
120: public void failed() {
121: }
122:
123: public void setNewState(int percentComplete,
124: String state) {
125: log("jsmooth: " + state + " ( "
126: + percentComplete + "%)");
127: }
128: });
129: }
130:
131: if (compiler.compile(skelroot, skel, basedir, model, out))
132: log("Java application wrapped in "
133: + model.getExecutableName());
134: else
135: log("jsmoothgen failed: " + compiler.getErrors());
136:
137: } catch (Exception exc) {
138: throw new org.apache.tools.ant.BuildException(
139: "Error building the jsmooth wrapper", exc);
140: }
141: }
142:
143: }
|