Fill out the rest of the ant task to basically mirror the command line

This commit is contained in:
2012-07-27 17:52:24 +00:00
parent 83b022243f
commit 5dac28935a
3 changed files with 315 additions and 43 deletions

98
build/build-testacant.xml Normal file
View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="ac-ant-test" default="all">
<property name="projdir" value=".."/>
<target name="version" description="Get version from source.">
<property name="main.path" value="${projdir}/src/com/webcodepro/applecommander/ui"/>
<loadfile srcfile="${main.path}/AppleCommander.java" property="acVersion">
<filterchain>
<linecontainsregexp>
<regexp pattern='^.*String VERSION = ".*";.*$'/>
</linecontainsregexp>
<tokenfilter>
<replaceregex pattern='^.*String VERSION = "(.*)";.*$' replace='\1'/>
</tokenfilter>
<striplinebreaks/>
</filterchain>
</loadfile>
<echo>Testing ant support from version ${acVersion}...</echo>
<!-- Set a number of properties based on that version number -->
<taskdef name="appleCommander" classname="com.webcodepro.applecommander.ui.AntTask" classpath="${projdir}/work/dist/AppleCommander-${acVersion}-ac.jar"/>
<property name="dos140image" value="${projdir}/work/dist/test-${acVersion}-dos140.do"/>
<property name="pro140image" value="${projdir}/work/dist/test-${acVersion}-pro140.po"/>
<property name="pro800image" value="${projdir}/work/dist/test-${acVersion}-pro800.po"/>
<property name="pas140image" value="${projdir}/work/dist/test-${acVersion}-pas140.po"/>
<property name="pas800image" value="${projdir}/work/dist/test-${acVersion}-pas800.po"/>
</target>
<target name="all" depends="version, clean, test" description="Tests some of the functions of the AppleCommander Ant task. Run 'clean' afterwards to clean up.">
<!-- This target is here to orchestrate the staging of other tasks via the 'depends' clause. -->
</target>
<target name="test" description="Run the bulk of the testing.">
<!-- First, build images to play with -->
<appleCommander command="dos140" imagename="${dos140image}" />
<appleCommander command="pro800" imagename="${pro800image}" />
<appleCommander command="pro140" imagename="${pro140image}" />
<appleCommander command="pas800" imagename="${pas800image}" />
<appleCommander command="pas140" imagename="${pas140image}" />
<!-- Now, copy a file to the images -->
<appleCommander command="p" input="manifest.mf" imagename="${dos140image}" filename="MANIFEST" type="T" />
<appleCommander command="p" input="manifest.mf" imagename="${pas140image}" filename="MANIFEST" type="text" />
<appleCommander command="p" input="manifest.mf" imagename="${pas800image}" filename="MANIFEST" type="text" />
<appleCommander command="p" input="manifest.mf" imagename="${pro140image}" filename="MANIFEST" type="txt" />
<appleCommander command="p" input="${pas140image}" imagename="${pro800image}" filename="BIG140IMG" type="bin" />
<!-- Now, copy a file that should not fit on the images -->
<echo message="Here we expect messages from [appleCommander] complaining about file space requirements not being met..."/>
<appleCommander failonerror="false" command="p" input="${pro800image}" imagename="${dos140image}" filename="BLOWUP" type="T" />
<appleCommander failonerror="false" command="p" input="${pro800image}" imagename="${pas140image}" filename="BLOWUP" type="text" />
<appleCommander failonerror="false" command="p" input="${pro800image}" imagename="${pas800image}" filename="BLOWUP" type="text" />
<appleCommander failonerror="false" command="p" input="${pro800image}" imagename="${pro140image}" filename="BLOWUP" type="txt" />
<appleCommander failonerror="false" command="p" input="${pro800image}" imagename="${pro800image}" filename="BLOWUP" type="txt" />
<!-- Now, ask for some directories -->
<echo message="Here we are asking for a normal DOS directory."/>
<appleCommander command="ls" imagename="${dos140image}" />
<echo message="Here we are asking for a native Pascal directory."/>
<appleCommander command="l" imagename="${pas800image}" />
<echo message="Here we are asking for a detailed ProDOS directory."/>
<appleCommander command="ll" imagename="${pro800image}" />
<!-- Now, ask for some information on images -->
<echo message="Here we are asking for general image information."/>
<appleCommander command="i" imagename="${dos140image}" />
<!-- Now, delete that file we created -->
<appleCommander command="d" imagename="${dos140image}" filename="MANIFEST" />
<appleCommander command="d" imagename="${pas140image}" filename="MANIFEST" />
<echo message="Note: the 'No match' message is coming from the Pascal 140k image, which gets corrupted when it is blown up with the large file."/>
<appleCommander command="d" imagename="${pas800image}" filename="MANIFEST" />
<appleCommander command="d" imagename="${pro140image}" filename="MANIFEST" />
<appleCommander command="d" imagename="${pro800image}" filename="BIG140IMG" />
<!-- Now, the files should be gone -->
<echo message="Now, the files that appeared before should be gone."/>
<appleCommander command="ls" imagename="${dos140image}" />
<appleCommander command="l" imagename="${pas800image}" />
<appleCommander command="ll" imagename="${pro800image}" />
<!-- Now, test some file exporting -->
<echo message="Here are the contents of a file:"/>
<appleCommander command="p" input="manifest.mf" imagename="${pro140image}" filename="TEST" type="txt" />
<appleCommander command="e" imagename="${pro140image}" filename="TEST" />
<echo message="Here are the contents of a file, native:"/>
<appleCommander command="g" imagename="${pro140image}" filename="TEST" />
<appleCommander command="x" imagename="${pro140image}" outputpath="${projdir}/work/dist" />
<echo message="Files should be exported to the current working directory now." />
<!-- Now, try out unshrinking -->
<!--
<appleCommander command="unshrink" filename="DiskCommander.GS.sdk" imagename="${projdir}/work/dist/test.po" />
-->
</target>
<target name="clean" description="Get rid of testing artifacts.">
<delete file="${dos140image}" />
<delete file="${pas140image}" />
<delete file="${pas800image}" />
<delete file="${pro140image}" />
<delete file="${pro800image}" />
<delete file="TEST.txt" />
</target>
</project>

View File

@ -19,24 +19,64 @@ package com.webcodepro.applecommander.ui;
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.File;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.FormattedDisk;
public class AntTask extends Task
{
public void execute() throws BuildException
{
/*
* Commands: p, cc65, n, k
* p: <imagename> <filename> <type> [<address>]
* Commands:
* cc65: <imagename> <filename> <type>
* d: <imagename> <filename>
* e: <imagename> <filename>
* i: <imagename>
* k/u: <imagename> <filename>
* ls/l/ll: <imagename>
* n: <imagename> <volname>
* k: <imagename> <filename>
*
* p: <imagename> <filename> <type> [<address>]
* x: <imagename> <outputpath>
* dos140: <imagename> <volname>
* pro140/pro800: <imagename> <volname>
* pas140/pas800: <imagename> <volname>
* unshrink: <filename> <imagename>
*/
if (_command.equals("p") || (_command.equals("cc65")))
if (_command.equals("i"))
{
try
{
String[] onlyOneImage = { "nonsense", _imageName };
com.webcodepro.applecommander.ui.ac.getDiskInfo(onlyOneImage);
}
catch (Exception ex)
{
if (_failonerror)
throw new BuildException(ex);
else
System.out.println(ex.getMessage());
}
}
else if (_command.equals("e") || _command.equals("g"))
{
try
{
com.webcodepro.applecommander.ui.ac.getFile(_imageName, _fileName, _command.equals("e"));
}
catch (Exception ex)
{
if (_failonerror)
throw new BuildException(ex);
else
System.out.println(ex.getMessage());
}
}
else if (_command.equals("p") || (_command.equals("cc65")))
{
try
{
@ -47,12 +87,27 @@ public class AntTask extends Task
}
catch (Exception ex)
{
if (_failonerror)
throw new BuildException(ex);
}
}
else
System.out.println(ex.getMessage());
}
}
else if (_command.equals("d"))
{
if (_command.equals("n"))
try
{
com.webcodepro.applecommander.ui.ac.deleteFile(_imageName, _fileName);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else if (_command.equals("n"))
{
try
{
@ -60,30 +115,130 @@ public class AntTask extends Task
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
}
}
else
{
if (_command.equals("k"))
System.out.println(io.getMessage());
}
}
else if (_command.equals("k") || _command.equals("u"))
{
try
{
if (_command.equals("k"))
com.webcodepro.applecommander.ui.ac.setFileLocked(_imageName, _fileName, true);
else // Assume unlock
com.webcodepro.applecommander.ui.ac.setFileLocked(_imageName, _fileName, false);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else if (_command.equals("ls") || _command.equals("l") || _command.equals("ll"))
{
try
{
String[] onlyOneImage = { "nonsense", _imageName };
if (_command.equals("ls"))
com.webcodepro.applecommander.ui.ac.showDirectory(onlyOneImage, FormattedDisk.FILE_DISPLAY_STANDARD);
else if (_command.equals("l"))
com.webcodepro.applecommander.ui.ac.showDirectory(onlyOneImage, FormattedDisk.FILE_DISPLAY_NATIVE);
else // Assume "ll"
com.webcodepro.applecommander.ui.ac.showDirectory(onlyOneImage, FormattedDisk.FILE_DISPLAY_DETAIL);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else if (_command.equals("dos140"))
{
try
{
com.webcodepro.applecommander.ui.ac.createDosDisk(_imageName, Disk.APPLE_140KB_DISK);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else if ((_command.equals("pro800") || _command.equals("pro140")))
{
try
{
if (_command.equals("pro800"))
com.webcodepro.applecommander.ui.ac.createProDisk(_imageName, _volName, Disk.APPLE_800KB_DISK);
else
com.webcodepro.applecommander.ui.ac.createProDisk(_imageName, _volName, Disk.APPLE_140KB_DISK);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else if ((_command.equals("pas800") || _command.equals("pas140")))
{
try
{
if (_command.equals("pas800"))
com.webcodepro.applecommander.ui.ac.createPasDisk(_imageName, _volName, Disk.APPLE_800KB_DISK);
else
com.webcodepro.applecommander.ui.ac.createPasDisk(_imageName, _volName, Disk.APPLE_140KB_DISK);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else if (_command.equals("x"))
{
try
{
com.webcodepro.applecommander.ui.ac.getFiles(_imageName, _outputPath);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else if (_command.equals("unshrink"))
{
try
{
com.webcodepro.applecommander.ui.ac.unshrink(_fileName, _imageName);
}
catch (IOException io)
{
if (_failonerror)
throw new BuildException(io);
else
System.out.println(io.getMessage());
}
}
else
{
throw new BuildException("Command \""+_command+"\" not implemented.");
throw new BuildException("Command \"" + _command + "\" not implemented.");
}
}
}
}
public void setCommand(String command)
{
@ -105,6 +260,11 @@ public class AntTask extends Task
_fileName = fileName;
}
public void setOutputPath(String outputPath)
{
_outputPath = outputPath;
}
public void setVolumeName(String volumeName)
{
_volName = volumeName;
@ -120,6 +280,16 @@ public class AntTask extends Task
_address = address;
}
public void setFailOnError(String failonerror)
{
if (failonerror.equalsIgnoreCase("true"))
_failonerror = true;
if (failonerror.equalsIgnoreCase("false"))
_failonerror = false;
}
boolean _failonerror = true;
String _input = null;
String _command = null;
@ -128,7 +298,9 @@ public class AntTask extends Task
String _fileName = null;
String _volName = null;
String _volName = "ACDISK";
String _outputPath = null;
String _type = null;

View File

@ -99,16 +99,16 @@ public class ac {
} else if ("-ll".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
showDirectory(args, FormattedDisk.FILE_DISPLAY_DETAIL);
} else if ("-e".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
getFile(args[1], new Name(args[2]), true);
getFile(args[1], args[2], true);
} else if ("-x".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
getFiles(args[1], (args.length > 2 ? args[2] : ""));
} else if ("-g".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
getFile(args[1], new Name(args[2]), false);
getFile(args[1], args[2], false);
} else if ("-p".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
putFile(args[1], new Name(args[2]), args[3],
(args.length > 4 ? args[4] : "0x2000"));
} else if ("-d".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
deleteFile(args[1], new Name(args[2]));
deleteFile(args[1], args[2]);
} else if ("-k".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
setFileLocked(args[1], args[2], true);
} else if ("-u".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
@ -247,9 +247,10 @@ public class ac {
/**
* Delete the file named fileName from the disk named imageName.
*/
static void deleteFile(String imageName, Name name)
static void deleteFile(String imageName, String fileName)
throws IOException {
Disk disk = new Disk(imageName);
Name name = new Name(fileName);
if (!disk.isSDK()) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
@ -272,9 +273,10 @@ public class ac {
* Get the file named filename from the disk named imageName; the file is
* filtered according to its type and sent to &lt;stdout>.
*/
static void getFile(String imageName, Name name, boolean filter)
static void getFile(String imageName, String fileName, boolean filter)
throws IOException {
Disk disk = new Disk(imageName);
Name name = new Name(fileName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i];
@ -302,7 +304,7 @@ public class ac {
*/
static void getFiles(String imageName, String directory) throws IOException {
Disk disk = new Disk(imageName);
if (directory.length() > 0) {
if ((directory != null) && (directory.length() > 0)) {
// Add a final directory separator if the user didn't supply one
if (!directory.endsWith(File.separator))
directory = directory + File.separator;