/* ====================================================================
*
* The ObjectStyle Group Software License, Version 1.0
*
* Copyright (c) 2002, 2004 The ObjectStyle Group
* and individual authors of the software. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* ObjectStyle Group (http://objectstyle.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "ObjectStyle Group" and "Cayenne"
* must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact andrus@objectstyle.org.
*
* 5. Products derived from this software may not be called "ObjectStyle"
* nor may "ObjectStyle" appear in their names without prior written
* permission of the ObjectStyle Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the ObjectStyle Group. For more
* information on the ObjectStyle Group, please see
*
* As specified by Apple Documentation
* @return
*/
public String getJavaVersion() {
return task.getJavaVersion();
}
/**
* Returns a name of the jar WebObjects project being built with ".jar"
* appended.
*/
public String getJarName() {
return task.getJarName() + ".jar";
}
/**
* Creates all needed files based on WOProject templates. This is a main
* worker method. Returns true when a template is written.
*/
public boolean processTemplates() throws BuildException {
Iterator it = fileIterator();
boolean returnValue = false;
try {
ClassLoader cl = this.task.getClass().getClassLoader();
if (cl == null) {
// cl = ClassLoader.getSystemClassLoader();
throw new BuildException("Could not load classloader");
}
while (it.hasNext()) {
String targetName = (String) it.next();
String templName = templateForTarget(targetName);
FilterSetCollection filters = filtersForTarget(targetName);
InputStream template = cl.getResourceAsStream(templName);
File target = new File(targetName);
if (copyFile(template, target, filters))
returnValue = true;
}
} catch (IOException ioex) {
throw new BuildException("Error doing project formatting.", ioex);
} finally {
it = null;
}
return returnValue;
}
/**
* Returns an iterator over String objects that specify paths of the files
* to be created during the build process.
*/
public abstract Iterator fileIterator();
/**
* Returns a path to the template that should be used to build a target
* file.
*/
public abstract String templateForTarget(String targetName) throws BuildException;
/**
* Returns a FilterSetCollection that should be applied when generating a
* target file.
*/
public abstract FilterSetCollection filtersForTarget(String targetName) throws BuildException;
/**
* Convienence method to copy a file from a source to a destination
* specifying if token filtering must be used.
*
*
* This method is copied from Ant FileUtils with some changes and * simplifications. FileUtils can't be used directly, since its API doesn't * allow InputStreams for the source file. *
* * @throws IOException * Returns true when a .sh file is copied. */ public boolean copyFile(InputStream src, File destFile, FilterSetCollection filters) throws IOException { log("destFile.getName(): " + destFile.getName() + " this.getName(): " + this.getName(), Project.MSG_VERBOSE); if (destFile.exists() && destFile.isFile() && destFile.getName().equals(this.getName())) { // these files only need an update when a new Version of WO is // installed. // A clean in that case is better. // destFile.delete(); src.close(); return false; } if (destFile.exists() && destFile.isFile()) { destFile.delete(); } // ensure that parent dir of dest file exists! // not using getParentFile method to stay 1.1 compat File parent = new File(destFile.getParent()); if (!parent.exists()) { parent.mkdirs(); } if (filters != null && filters.hasFilters()) { BufferedReader in = new BufferedReader(new InputStreamReader(src)); BufferedWriter out = new BufferedWriter(new FileWriter(destFile)); log("filters: " + filters, Project.MSG_VERBOSE); String newline = null; String line = in.readLine(); while (line != null) { if (line.length() == 0) { out.newLine(); } else { log("line: " + line, Project.MSG_VERBOSE); newline = filters.replaceTokens(line); log("newline: " + newline, Project.MSG_VERBOSE); out.write(newline); out.newLine(); } line = in.readLine(); } out.close(); in.close(); } else { FileOutputStream out = new FileOutputStream(destFile); byte[] buffer = new byte[8 * 1024]; int count = 0; do { out.write(buffer, 0, count); count = src.read(buffer, 0, buffer.length); } while (count != -1); src.close(); out.close(); } return destFile.getName().equals(this.getName()); } /** * Returns a string that can be used in Info.plist file to indicate JARs * required by the project. */ private String libString(Iterator extLibs) { String endLine = System.getProperty("line.separator"); StringBuffer buf = new StringBuffer(); buf.append("