Skip to content
Permalink
Browse files
Add a tallow task, submitted by zhihengz AT hotmail DOT com. PR 47078
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/dotnet/trunk@771741 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bodewig committed May 5, 2009
1 parent ced10d8 commit ecac2af1f25476ba8b1f26574740aba3947e5ae6
Showing 4 changed files with 340 additions and 0 deletions.
@@ -38,6 +38,10 @@
</properties>

<release version="SVN trunk" date="unpublished">
<action type="add" issue="47078">
A new tallow task has been added to ease creation of WiX built
installers.
</action>
<action type="update" issue="46968">
The wix task has new nested elements that allow users to send
addtional command line arguments to candle and light.
@@ -160,6 +160,9 @@ <h2>Tasks</h2>
<li><a href="wix.html">wix</a> - execute candle and/or light of
the WiX toolset.</li>

<li><a href="tallow.html">tallow</a> - execute tallow of the WiX
toolset.</li>

<li><a href="nunit.html">nunit</a> - execute the
nunit-console.exe <a href="http://www.nunit.org/">NUnit</a>
test runner.</li>
@@ -0,0 +1,113 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta http-equiv="Content-Language" content="en-us"></meta>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Tallow Task</title>
</head>

<body>
<h2>tallow</h2>

<h3>Description</h3>

<p>Runs tallow from the <a
href="http://sourceforge.net/projects/wix">Wix</a> toolset
</p>

<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">source</td>
<td valign="top">The single source directory to process.</td>
<td align="center">Either this or at least one nested
&lt;sources&gt; set.</td>
</tr>
<tr>
<td valign="top">target</td>
<td valign="top">The expected target file.</td>
<td align="center">Yes</td>
</tr>
<tr>
<td valign="top">vm</td>
<td valign="top">Same as <a
href="dotnetexec.html">dotnetexec</a>'s vm attribute.
Specify the framework to use.</td>
<td align="center">No.</td>
</tr>
<tr>
<td valign="top">wixHome</td>
<td valign="top">Installation directory of WiX.</td>
<td align="center">No - Ant will assume WiX is on your PATH
otherwise.</td>
</tr>
</table>

<h3>Parameters specified as nested elements</h3>

<h4>sources</h4>

<p>Specify source directories that shall be passed on the command line.
This is a <a
href="http://ant.apache.org/manual/CoreTypes/dirset.html">dirset</a>.</p>

<h4>arg</h4>

<p>Specifies additional arguments for talow</p>

<p><code>arg</code> is
a <a href="http://ant.apache.org/manual/using.html#arg">command
line argument</a>.</p>

<h3>Examples</h3>

<p>Create <code>product.wxs</code> from <code>product</code> directory:</p>

<pre>
&lt;tallow source="product" target="product.wxs"/&gt;
</pre>

<p>Create <code>product.wxs</code> from <code>bin</code>,<code>docs</code>,
and <code>conf</code> under <code>product</code> directory:</p>

<pre>
&lt;tallow target="bin.wxs"/&gt;
&lt;sources dir="product", includes="bin,docs,conf"/&gt;
&lt;/tallow&gt;
</pre>

<p>Create <code>product.wxs</code> from <code>bin</code>,<code>docs</code>,
and <code>conf</code> under <code>product</code> directory:, and
set all files <code>vital</code>
</p>

<pre>
&lt;tallow target="bin.wxs"/&gt;
&lt;sources dir="product", includes="bin,docs,conf"/&gt;
&lt;arg value="-dav"/&gt;
&lt;/tallow&gt;
</pre>
</body>
</html>
@@ -0,0 +1,220 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.ant.dotnet.wix;

import org.apache.ant.dotnet.DotNetExecTask;
import org.apache.ant.dotnet.build.AbstractBuildTask;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.DirSet;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
* Task to run the tallow on packaging content to create a wxs file
*
* @see http://sf.net/projects/wix
*/
public class TallowTask extends Task {

/**
* The vm attribute - if given.
*/
private String vm;

/**
* The source dirs.
*/
private ArrayList sources = new ArrayList();

/**
* A single source file.
*/
private File source;

/**
* The target file.
*/
private File target;

/**
* Where is WiX installed?
*/
private File wixHome = null;
/**
* addtional command line arguments for tallow.
*/
private Commandline cmdl = new Commandline();

public TallowTask() {
super();
}

/**
* Set the name of the executable for the virtual machine.
*
* @param value the name of the executable for the virtual machine
*/
public void setVm(String value) {
this.vm = value;
}

/**
* The main source file.
*
* <p><code>tallow</code> may include more directories than this one,
* the main source is the one passed on the command line.</p>
*
* @param File object of the main source file.
*/
public void setSource(File f) {
source = f;
}

/**
* The main target file.
*
* @param File object of the main target file.
*/
public void setTarget(File f) {
target = f;
}

/**
* A set of source files.
*/
public void addSources(DirSet ds) {
sources.add(ds);
}
/**
* Sets the installation directory of WiX.
*
* <p>If omitted, Ant will assume that WiX's executables can be
* found on the PATH.</p>
*/
public void setWixHome(File f) {
wixHome = f;
}
/**
* Adds a command-line argument for tallow.exe.
*
* @return new command line argument created.
*/
public Commandline.Argument createArg() {
return cmdl.createArgument();
}
public void execute() {

Collection grabbedDirs = grabSources();

if (target == null) {
throw new BuildException("You must specify the target if you want"
+ " to run tallow.");
}
runTallow(grabbedDirs);
}

private Collection grabSources() {

Set r = new HashSet();

if (source != null) {

if (!source.exists()) {
throw new BuildException("Source " + source
+ " doesn't exist.");
} else if (!source.isDirectory()) {

throw new BuildException("Source " + source
+ " is not directory.");
}

r.add(source);

} else if (sources.size() == 0) {
throw new BuildException("You must specify at least one source"
+ " file.");
} else {
Iterator iter = sources.iterator();
while (iter.hasNext()) {
DirSet ds = (DirSet) iter.next();
DirectoryScanner scanner = ds.getDirectoryScanner(getProject());
String[] f = scanner.getIncludedDirectories();
File base = ds.getDir(getProject());
for (int i = 0; i < f.length; i++) {
r.add(new File(base, f[i]));
}
}
if (r.isEmpty()) {
throw new BuildException("No sources found");
}
}

return r;
}
/**
* Run tallow passing all files of the collection on the command line.
*/
private void runTallow(Collection s) {
run(wixExecutable("tallow.exe"), s, target, cmdl);
}
/**
* returns an absolute path for the given executable if wixHome
* has been specified, the given name otherwise.
*/
private String wixExecutable(String name) {
return wixHome == null ? name
: new File(wixHome, name).getAbsolutePath();
}

/**
* Runs the specified command passing all files of the collection
* on the command line - potentially adding an /out parameter.
*/
private void run(String executable, Collection s, File target,
Commandline cmdl) {
DotNetExecTask exec =
DotNetExecTask.getTask(this, vm, executable, null);
exec.setFailonerror(true);
exec.setTaskType("wix");

exec.createArg().setValue("/nologo");

Iterator iter = s.iterator();
while (iter.hasNext()) {
File f = (File) iter.next();
exec.createArg().setValue("-d");
exec.createArg().setValue(f.getAbsolutePath());
}
String[] extraArgs = cmdl.getArguments();
for (int i = 0; i < extraArgs.length; i++) {
exec.createArg().setValue(extraArgs[i]);
}
exec.setOutput (target);

exec.execute();
}
}

0 comments on commit ecac2af

Please sign in to comment.