|
|
|
@@ -1,7 +1,7 @@ |
|
|
|
/* |
|
|
|
* The Apache Software License, Version 1.1 |
|
|
|
* |
|
|
|
* Copyright (c) 1999 The Apache Software Foundation. All rights |
|
|
|
* Copyright (c) 1999 The Apache Software Foundation. All rights |
|
|
|
* reserved. |
|
|
|
* |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
@@ -9,7 +9,7 @@ |
|
|
|
* are met: |
|
|
|
* |
|
|
|
* 1. Redistributions of source code must retain the above copyright |
|
|
|
* notice, this list of conditions and the following disclaimer. |
|
|
|
* 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 |
|
|
|
@@ -17,15 +17,15 @@ |
|
|
|
* distribution. |
|
|
|
* |
|
|
|
* 3. The end-user documentation included with the redistribution, if |
|
|
|
* any, must include the following acknowlegement: |
|
|
|
* "This product includes software developed by the |
|
|
|
* any, must include the following acknowlegement: |
|
|
|
* "This product includes software developed by the |
|
|
|
* Apache Software Foundation (http://www.apache.org/)." |
|
|
|
* Alternately, this acknowlegement may appear in the software itself, |
|
|
|
* if and wherever such third-party acknowlegements normally appear. |
|
|
|
* |
|
|
|
* 4. The names "The Jakarta Project", "Ant", and "Apache Software |
|
|
|
* Foundation" must not be used to endorse or promote products derived |
|
|
|
* from this software without prior written permission. For written |
|
|
|
* from this software without prior written permission. For written |
|
|
|
* permission, please contact apache@apache.org. |
|
|
|
* |
|
|
|
* 5. Products derived from this software may not be called "Apache" |
|
|
|
@@ -54,24 +54,24 @@ |
|
|
|
|
|
|
|
package org.apache.tools.ant.taskdefs.optional; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.Vector; |
|
|
|
|
|
|
|
import org.apache.tools.ant.BuildException; |
|
|
|
import org.apache.tools.ant.DirectoryScanner; |
|
|
|
import org.apache.tools.ant.Project; |
|
|
|
import org.apache.tools.ant.taskdefs.MatchingTask; |
|
|
|
import org.apache.tools.ant.taskdefs.ExecTask; |
|
|
|
import org.apache.tools.ant.taskdefs.MatchingTask; |
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os; |
|
|
|
import org.apache.tools.ant.types.FileSet; |
|
|
|
import org.apache.tools.ant.types.Commandline; |
|
|
|
import org.apache.tools.ant.types.FileSet; |
|
|
|
import org.apache.tools.ant.util.FileUtils; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.Vector; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Create a CAB archive. |
|
|
|
@@ -87,21 +87,21 @@ public class Cab extends MatchingTask { |
|
|
|
private boolean doCompress = true; |
|
|
|
private boolean doVerbose = false; |
|
|
|
private String cmdOptions; |
|
|
|
|
|
|
|
|
|
|
|
protected String archiveType = "cab"; |
|
|
|
|
|
|
|
private FileUtils fileUtils = FileUtils.newFileUtils(); |
|
|
|
|
|
|
|
/** |
|
|
|
* This is the name/location of where to |
|
|
|
* This is the name/location of where to |
|
|
|
* create the .cab file. |
|
|
|
*/ |
|
|
|
public void setCabfile(File cabFile) { |
|
|
|
this.cabFile = cabFile; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* This is the base directory to look in for |
|
|
|
* This is the base directory to look in for |
|
|
|
* things to cab. |
|
|
|
*/ |
|
|
|
public void setBasedir(File baseDir) { |
|
|
|
@@ -157,9 +157,8 @@ public class Cab extends MatchingTask { |
|
|
|
* Create a new exec delegate. The delegate task is populated so that |
|
|
|
* it appears in the logs to be the same task as this one. |
|
|
|
*/ |
|
|
|
protected ExecTask createExec() throws BuildException |
|
|
|
{ |
|
|
|
ExecTask exec = (ExecTask)project.createTask("exec"); |
|
|
|
protected ExecTask createExec() throws BuildException { |
|
|
|
ExecTask exec = (ExecTask) project.createTask("exec"); |
|
|
|
exec.setOwningTarget(this.getOwningTarget()); |
|
|
|
exec.setTaskName(this.getTaskName()); |
|
|
|
exec.setDescription(this.getDescription()); |
|
|
|
@@ -171,14 +170,12 @@ public class Cab extends MatchingTask { |
|
|
|
* Check to see if the target is up to date with respect to input files. |
|
|
|
* @return true if the cab file is newer than its dependents. |
|
|
|
*/ |
|
|
|
protected boolean isUpToDate(Vector files) |
|
|
|
{ |
|
|
|
protected boolean isUpToDate(Vector files) { |
|
|
|
boolean upToDate = true; |
|
|
|
for (int i=0; i<files.size() && upToDate; i++) |
|
|
|
{ |
|
|
|
for (int i = 0; i < files.size() && upToDate; i++) { |
|
|
|
String file = files.elementAt(i).toString(); |
|
|
|
if (new File(baseDir,file).lastModified() > |
|
|
|
cabFile.lastModified()) { |
|
|
|
if (new File(baseDir, file).lastModified() > |
|
|
|
cabFile.lastModified()) { |
|
|
|
upToDate = false; |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -188,24 +185,21 @@ public class Cab extends MatchingTask { |
|
|
|
/** |
|
|
|
* Create the cabarc command line to use. |
|
|
|
*/ |
|
|
|
protected Commandline createCommand(File listFile) |
|
|
|
{ |
|
|
|
protected Commandline createCommand(File listFile) { |
|
|
|
Commandline command = new Commandline(); |
|
|
|
command.setExecutable("cabarc"); |
|
|
|
command.createArgument().setValue("-r"); |
|
|
|
command.createArgument().setValue("-p"); |
|
|
|
|
|
|
|
if (!doCompress) |
|
|
|
{ |
|
|
|
if (!doCompress) { |
|
|
|
command.createArgument().setValue("-m"); |
|
|
|
command.createArgument().setValue("none"); |
|
|
|
} |
|
|
|
|
|
|
|
if (cmdOptions != null) |
|
|
|
{ |
|
|
|
if (cmdOptions != null) { |
|
|
|
command.createArgument().setLine(cmdOptions); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
command.createArgument().setValue("n"); |
|
|
|
command.createArgument().setFile(cabFile); |
|
|
|
command.createArgument().setValue("@" + listFile.getAbsolutePath()); |
|
|
|
@@ -218,14 +212,12 @@ public class Cab extends MatchingTask { |
|
|
|
* to be included in the cab, one file per line. |
|
|
|
*/ |
|
|
|
protected File createListFile(Vector files) |
|
|
|
throws IOException |
|
|
|
{ |
|
|
|
throws IOException { |
|
|
|
File listFile = fileUtils.createTempFile("ant", "", null); |
|
|
|
|
|
|
|
|
|
|
|
PrintWriter writer = new PrintWriter(new FileOutputStream(listFile)); |
|
|
|
|
|
|
|
for (int i = 0; i < files.size(); i++) |
|
|
|
{ |
|
|
|
for (int i = 0; i < files.size(); i++) { |
|
|
|
writer.println(files.elementAt(i).toString()); |
|
|
|
} |
|
|
|
writer.close(); |
|
|
|
@@ -236,12 +228,10 @@ public class Cab extends MatchingTask { |
|
|
|
/** |
|
|
|
* Append all files found by a directory scanner to a vector. |
|
|
|
*/ |
|
|
|
protected void appendFiles(Vector files, DirectoryScanner ds) |
|
|
|
{ |
|
|
|
protected void appendFiles(Vector files, DirectoryScanner ds) { |
|
|
|
String[] dsfiles = ds.getIncludedFiles(); |
|
|
|
|
|
|
|
for (int i = 0; i < dsfiles.length; i++) |
|
|
|
{ |
|
|
|
for (int i = 0; i < dsfiles.length; i++) { |
|
|
|
files.addElement(dsfiles[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -251,23 +241,17 @@ public class Cab extends MatchingTask { |
|
|
|
* are gathered from filesets if any have been added, otherwise from the |
|
|
|
* traditional include parameters. |
|
|
|
*/ |
|
|
|
protected Vector getFileList() throws BuildException |
|
|
|
{ |
|
|
|
protected Vector getFileList() throws BuildException { |
|
|
|
Vector files = new Vector(); |
|
|
|
|
|
|
|
if (filesets.size() == 0) |
|
|
|
{ |
|
|
|
if (filesets.size() == 0) { |
|
|
|
// get files from old methods - includes and nested include |
|
|
|
appendFiles(files, super.getDirectoryScanner(baseDir)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
} else { |
|
|
|
// get files from filesets |
|
|
|
for (int i = 0; i < filesets.size(); i++) |
|
|
|
{ |
|
|
|
for (int i = 0; i < filesets.size(); i++) { |
|
|
|
FileSet fs = (FileSet) filesets.elementAt(i); |
|
|
|
if (fs != null) |
|
|
|
{ |
|
|
|
if (fs != null) { |
|
|
|
appendFiles(files, fs.getDirectoryScanner(project)); |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -281,26 +265,26 @@ public class Cab extends MatchingTask { |
|
|
|
checkConfiguration(); |
|
|
|
|
|
|
|
Vector files = getFileList(); |
|
|
|
|
|
|
|
|
|
|
|
// quick exit if the target is up to date |
|
|
|
if (isUpToDate(files)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
log("Building "+ archiveType +": "+ cabFile.getAbsolutePath()); |
|
|
|
log("Building " + archiveType + ": " + cabFile.getAbsolutePath()); |
|
|
|
|
|
|
|
if (!Os.isFamily("windows")) { |
|
|
|
log("Using listcab/libcabinet", Project.MSG_VERBOSE); |
|
|
|
|
|
|
|
|
|
|
|
StringBuffer sb = new StringBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
Enumeration fileEnum = files.elements(); |
|
|
|
|
|
|
|
|
|
|
|
while (fileEnum.hasMoreElements()) { |
|
|
|
sb.append(fileEnum.nextElement()).append("\n"); |
|
|
|
} |
|
|
|
sb.append("\n").append(cabFile.getAbsolutePath()).append("\n"); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
Process p = Runtime.getRuntime().exec("listcab"); |
|
|
|
OutputStream out = p.getOutputStream(); |
|
|
|
@@ -316,23 +300,23 @@ public class Cab extends MatchingTask { |
|
|
|
File listFile = createListFile(files); |
|
|
|
ExecTask exec = createExec(); |
|
|
|
File outFile = null; |
|
|
|
|
|
|
|
|
|
|
|
// die if cabarc fails |
|
|
|
exec.setFailonerror(true); |
|
|
|
exec.setDir(baseDir); |
|
|
|
|
|
|
|
|
|
|
|
if (!doVerbose) { |
|
|
|
outFile = fileUtils.createTempFile("ant", "", null); |
|
|
|
exec.setOutput(outFile); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
exec.setCommand(createCommand(listFile)); |
|
|
|
exec.execute(); |
|
|
|
|
|
|
|
|
|
|
|
if (outFile != null) { |
|
|
|
outFile.delete(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
listFile.delete(); |
|
|
|
} catch (IOException ioe) { |
|
|
|
String msg = "Problem creating " + cabFile + " " + ioe.getMessage(); |
|
|
|
|