|
From: <chr...@us...> - 2009-04-29 21:55:54
|
Revision: 5361
http://jnode.svn.sourceforge.net/jnode/?rev=5361&view=rev
Author: chrisboertien
Date: 2009-04-29 21:55:50 +0000 (Wed, 29 Apr 2009)
Log Message:
-----------
Refactored commands from fs project to cli project
This is the first in a series of commits that aims to pull commands
out of the various subprojects and into a common projects.
This update brings most of the commands from the fs project into
org.jnode.command.file and the fs/archive commands into org.jnode.command.archive
Signed-off-by: chrisboertien <chr...@gm...>
Modified Paths:
--------------
trunk/all/build.xml
trunk/all/conf/default-plugin-list.xml
trunk/all/conf/shell-plugin-list.xml
trunk/all/lib/jnode.xml
trunk/fs/descriptors/org.jnode.fs.command.xml
trunk/fs/descriptors/org.jnode.fs.ext2.command.xml
Added Paths:
-----------
trunk/cli/
trunk/cli/build.xml
trunk/cli/descriptors/
trunk/cli/descriptors/org.apache.tools.archive.xml
trunk/cli/descriptors/org.jnode.command.archive.xml
trunk/cli/descriptors/org.jnode.command.file.xml
trunk/cli/descriptors/org.jnode.command.util.xml
trunk/cli/src/
trunk/cli/src/commands/
trunk/cli/src/commands/org/
trunk/cli/src/commands/org/jnode/
trunk/cli/src/commands/org/jnode/command/
trunk/cli/src/commands/org/jnode/command/archive/
trunk/cli/src/commands/org/jnode/command/archive/ArchiveCommand.java
trunk/cli/src/commands/org/jnode/command/archive/BUnzipCommand.java
trunk/cli/src/commands/org/jnode/command/archive/BZCatCommand.java
trunk/cli/src/commands/org/jnode/command/archive/BZip.java
trunk/cli/src/commands/org/jnode/command/archive/BZipCommand.java
trunk/cli/src/commands/org/jnode/command/archive/GUnzipCommand.java
trunk/cli/src/commands/org/jnode/command/archive/GZip.java
trunk/cli/src/commands/org/jnode/command/archive/GZipCommand.java
trunk/cli/src/commands/org/jnode/command/archive/TarCommand.java
trunk/cli/src/commands/org/jnode/command/archive/UnzipCommand.java
trunk/cli/src/commands/org/jnode/command/archive/ZCatCommand.java
trunk/cli/src/commands/org/jnode/command/archive/Zip.java
trunk/cli/src/commands/org/jnode/command/archive/ZipCommand.java
trunk/cli/src/commands/org/jnode/command/file/
trunk/cli/src/commands/org/jnode/command/file/CdCommand.java
trunk/cli/src/commands/org/jnode/command/file/CpCommand.java
trunk/cli/src/commands/org/jnode/command/file/DFCommand.java
trunk/cli/src/commands/org/jnode/command/file/DeleteCommand.java
trunk/cli/src/commands/org/jnode/command/file/DirCommand.java
trunk/cli/src/commands/org/jnode/command/file/FindCommand.java
trunk/cli/src/commands/org/jnode/command/file/HexdumpCommand.java
trunk/cli/src/commands/org/jnode/command/file/Md5SumCommand.java
trunk/cli/src/commands/org/jnode/command/file/MkdirCommand.java
trunk/cli/src/commands/org/jnode/command/file/PwdCommand.java
trunk/cli/src/commands/org/jnode/command/file/TouchCommand.java
trunk/cli/src/commands/org/jnode/command/util/
trunk/cli/src/commands/org/jnode/command/util/AbstractDirectoryWalker.java
Removed Paths:
-------------
trunk/fs/descriptors/org.apache.tools.archive.xml
trunk/fs/descriptors/org.jnode.fs.command.archive.xml
trunk/fs/src/fs/org/jnode/fs/command/AbstractDirectoryWalker.java
trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java
trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java
trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java
trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java
trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java
trunk/fs/src/fs/org/jnode/fs/command/FindCommand.java
trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java
trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java
trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java
trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java
trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/ArchiveCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/BUnzipCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/BZCatCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/BZip.java
trunk/fs/src/fs/org/jnode/fs/command/archive/BZipCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/GUnzipCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/GZip.java
trunk/fs/src/fs/org/jnode/fs/command/archive/GZipCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/TarCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/UnzipCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/ZCatCommand.java
trunk/fs/src/fs/org/jnode/fs/command/archive/Zip.java
trunk/fs/src/fs/org/jnode/fs/command/archive/ZipCommand.java
Modified: trunk/all/build.xml
===================================================================
--- trunk/all/build.xml 2009-04-29 19:58:08 UTC (rev 5360)
+++ trunk/all/build.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -38,6 +38,7 @@
<property name="jnode-textui.jar" value="${root.dir}/textui/build/classes"/>
<property name="jnode-net.jar" value="${root.dir}/net/build/classes"/>
<property name="jnode-shell.jar" value="${root.dir}/shell/build/classes"/>
+ <property name="jnode-coreutils.jar" value="${root.dir}/coreutils/build/classes"/>
<property name="jnode-fonts.jar" value="${build.dir}/descriptors/jnode-fonts.jar"/>
<property name="jnode-images.jar" value="${build.dir}/descriptors/jnode-images.jar"/>
@@ -143,6 +144,7 @@
<pathelement location="${jnode-shell.jar}"/>
<pathelement location="${jnode-net.jar}"/>
<pathelement location="${jnode-gui.jar}"/>
+ <pathelement location="${jnode-coreutils.jar}"/>
<pathelement location="${thinlet.jar}"/>
<pathelement location="${jnode-textui.jar}"/>
<pathelement location="${bcel-5.1.jar}"/>
@@ -344,6 +346,7 @@
<libalias name="jnode-textui.jar" alias="${jnode-textui.jar}"/>
<libalias name="jnode-net.jar" alias="${jnode-net.jar}"/>
<libalias name="jnode-shell.jar" alias="${jnode-shell.jar}"/>
+ <libalias name="jnode-coreutils.jar" alias="${jnode-coreutils.jar}"/>
<libalias name="jnode-mmtk-genrc.jar" alias="${jnode-mmtk-genrc.jar}"/>
<libalias name="jnode-mmtk-ms.jar" alias="${jnode-mmtk-ms.jar}"/>
Modified: trunk/all/conf/default-plugin-list.xml
===================================================================
--- trunk/all/conf/default-plugin-list.xml 2009-04-29 19:58:08 UTC (rev 5360)
+++ trunk/all/conf/default-plugin-list.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -31,7 +31,6 @@
<plugin id="org.classpath.ext.security"/>
<plugin id="org.classpath.tools"/>
- <plugin id="org.apache.tools.archive" />
<plugin id="org.apache.jakarta.commons.net"/>
<plugin id="org.xbill.dns"/>
@@ -49,6 +48,12 @@
<plugin id="org.jnode.awt.font"/>
<plugin id="org.jnode.awt.font.truetype"/>
<plugin id="org.jnode.awt.swingpeers"/>
+
+ <plugin id="org.apache.tools.archive" />
+ <plugin id="org.jnode.command.archive"/>
+ <plugin id="org.jnode.command.file"/>
+ <plugin id="org.jnode.command.util"/>
+
<plugin id="org.jnode.debug"/>
<plugin id="org.jnode.debugger"/>
@@ -116,7 +121,6 @@
<plugin id="org.jnode.driver.video.vesa"/>
<plugin id="org.jnode.fs.command"/>
- <plugin id="org.jnode.fs.command.archive" />
<plugin id="org.jnode.fs.ext2"/>
<plugin id="org.jnode.fs.ext2.command"/>
<plugin id="org.jnode.fs.hfsplus"/>
Modified: trunk/all/conf/shell-plugin-list.xml
===================================================================
--- trunk/all/conf/shell-plugin-list.xml 2009-04-29 19:58:08 UTC (rev 5360)
+++ trunk/all/conf/shell-plugin-list.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin-list name="shell">
<manifest>
- <attribute key="Main-Class" value="org.jnode.shell.CommandShell"/>
+ <attribute key="Main-Class" value="org.jnode.shell.CommandShell"/>
+ <attribute key="Main-Class-Arg" value="boot"/>
</manifest>
<plugin id="org.jnode.driver"/>
Modified: trunk/all/lib/jnode.xml
===================================================================
--- trunk/all/lib/jnode.xml 2009-04-29 19:58:08 UTC (rev 5360)
+++ trunk/all/lib/jnode.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -70,6 +70,7 @@
<ant target="@{target}" dir="${root.dir}/gui" inheritall="on" inheritrefs="on" />
<ant target="@{target}" dir="${root.dir}/textui" inheritall="on" inheritrefs="on" />
<ant target="@{target}" dir="${root.dir}/distr" inheritall="on" inheritrefs="on" />
+ <ant target="@{target}" dir="${root.dir}/coreutils" inheritall="on" inheritrefs="on" />
</sequential>
</macrodef>
Added: trunk/cli/build.xml
===================================================================
--- trunk/cli/build.xml (rev 0)
+++ trunk/cli/build.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,42 @@
+<project name="JNode-CoreUtils" default="all" basedir=".">
+
+ <typedef file="${basedir}/../all/lib/jnode.xml"/>
+
+ <property name="my-build.dir" value="${basedir}/build"/>
+ <property name="my-classes.dir" value="${my-build.dir}/classes"/>
+ <property name="my-src.dir" value="${basedir}/src"/>
+ <property name="my.jar" value="${jnode-coreutils.jar}"/>
+ <property name="my-report.dir" value="${my-build.dir}/report"/>
+
+<!-- Subproject specific classpath -->
+ <path id="my-cp">
+ <pathelement location="${jnode-core.jar}"/>
+ <pathelement location="${jnode-fs.jar}"/>
+ <pathelement location="${jnode-shell.jar}"/>
+ <pathelement location="${jnode-net.jar}"/>
+ <pathelement location="${jnode-gui.jar}"/>
+ <path refid="cp"/>
+ </path>
+
+<!-- Initialize subproject directories -->
+ <target name="prepare">
+ <mkdir dir="${my-classes.dir}"/>
+ <jnode.copy-descriptors/>
+ </target>
+
+<!-- Compile subproject -->
+ <target name="compile" depends="prepare">
+ <jnode.compile>
+ <src path="${my-src.dir}/commands"/>
+ <classpath refid="my-cp"/>
+ </jnode.compile>
+ </target>
+
+ <target name="assemble" depends="compile"/>
+
+ <target name="all" depends="assemble"/>
+
+ <target name="clean">
+ <jnode.clean/>
+ </target>
+</project>
Copied: trunk/cli/descriptors/org.apache.tools.archive.xml (from rev 5360, trunk/fs/descriptors/org.apache.tools.archive.xml)
===================================================================
--- trunk/cli/descriptors/org.apache.tools.archive.xml (rev 0)
+++ trunk/cli/descriptors/org.apache.tools.archive.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plugin SYSTEM "jnode.dtd">
+
+<plugin id="org.apache.tools.archive"
+ name="Ant archive tools"
+ version="1.7.1"
+ provider-name="Apache Ant"
+ provider-url="http://ant.apache.org"
+ license-name="apache2.0">
+
+ <runtime>
+ <library name="ant.jar">
+ <export name="org.apache.tools.tar.*" />
+ <export name="org.apache.tools.zip.*" />
+ <export name="org.apache.tools.bzip2.*" />
+ </library>
+ </runtime>
+
+ <extension point="org.jnode.security.permissions">
+ <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write"/>
+ <permission class="java.lang.RuntimePermission" name="readFileDescriptor"/>
+ <permission class="java.lang.RuntimePermission" name="writeFileDescriptor"/>
+ <permission class="java.util.PropertyPermission" name="*" actions="read,write"/>
+ </extension>
+</plugin>
Copied: trunk/cli/descriptors/org.jnode.command.archive.xml (from rev 5360, trunk/fs/descriptors/org.jnode.fs.command.archive.xml)
===================================================================
--- trunk/cli/descriptors/org.jnode.command.archive.xml (rev 0)
+++ trunk/cli/descriptors/org.jnode.command.archive.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,285 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plugin SYSTEM "jnode.dtd">
+
+<plugin id="org.jnode.command.archive"
+ name="JNode archive commands"
+ version="@VERSION@"
+ provider-name="@PROVIDER@"
+ license-name="lgpl">
+
+ <requires>
+ <import plugin="org.apache.tools.archive" />
+ <import plugin="org.jnode.shell.syntax" />
+ <import plugin="org.jnode.command.util" />
+ </requires>
+
+ <runtime>
+ <library name="jnode-coreutils.jar">
+ <export name="org.jnode.command.archive.*" />
+ </library>
+ </runtime>
+
+ <extension point="org.jnode.shell.aliases">
+ <alias name="bzip2" class="org.jnode.command.archive.BZipCommand" />
+ <alias name="bunzip2" class="org.jnode.command.archive.BUnzipCommand" />
+ <alias name="bzcat" class="org.jnode.command.archive.BZCatCommand" />
+ <alias name="gzip" class="org.jnode.command.archive.GZipCommand" />
+ <alias name="gunzip" class="org.jnode.command.archive.GUnzipCommand" />
+ <alias name="tar" class="org.jnode.command.archive.TarCommand" />
+ <alias name="unzip" class="org.jnode.command.archive.UnzipCommand" />
+ <alias name="zcat" class="org.jnode.command.archive.ZCatCommand" />
+ <alias name="zip" class="org.jnode.command.archive.ZipCommand" />
+ </extension>
+
+ <extension point="org.jnode.shell.syntaxes">
+ <syntax alias="bunzip2">
+ <empty description="decompress stdin to stdout" />
+ <sequence description="decompress files">
+ <optionSet>
+ <!-- BZip -->
+ <option argLabel="compress" shortName="z" longName="compress"/>
+ <option argLabel="decompress" shortName="d" longName="decompress"/>
+ <option argLabel="test" shortName="t" longName="test" />
+ <option argLabel="keep" shortName="k" longName="keep" />
+ <option argLabel="small" shortName="s" longName="small" />
+ <!-- ArchiveCommand -->
+ <option argLabel="stdout" shortName="c" longName="stdout" />
+ <option argLabel="force" shortName="f" longName="force" />
+ <option argLabel="verbose" shortName="v" longName="verbose" />
+ <option argLabel="quiet" shortName="q" longName="quiet" />
+ <option argLabel="debug" longName="debug" />
+ </optionSet>
+ <repeat>
+ <argument argLabel="files" />
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="bzcat">
+ <empty description="decompress stdin to stdout" />
+ <sequence description="decompress files to stdout">
+ <optionSet>
+ <option argLabel="small" shortName="s" longName="small" />
+ </optionSet>
+ <repeat>
+ <argument argLabel="files" />
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="bzip2">
+ <empty description="compress stdin to stdout" />
+ <sequence description="compress files">
+ <optionSet>
+ <!-- BZipCommand -->
+ <option argLabel="c1" shortName="1" longName="fast" />
+ <option argLabel="c2" shortName="2" />
+ <option argLabel="c3" shortName="3" />
+ <option argLabel="c4" shortName="4" />
+ <option argLabel="c5" shortName="5" />
+ <option argLabel="c6" shortName="6" />
+ <option argLabel="c7" shortName="7" />
+ <option argLabel="c8" shortName="8" />
+ <option argLabel="c9" shortName="9" longName="best" />
+ <!-- BZip -->
+ <option argLabel="decompress" shortName="d" longName="decompress" />
+ <option argLabel="compress" shortName="z" longName="compress" />
+ <option argLabel="test" shortName="t" longName="test" />
+ <option argLabel="keep" shortName="k" longName="keep" />
+ <option argLabel="small" shortName="s" longName="small" />
+ <!-- ArchiveCommand -->
+ <option argLabel="stdout" shortName="c" longName="stdout" />
+ <option argLabel="force" shortName="f" longName="force" />
+ <option argLabel="verbose" shortName="v" longName="verbose" />
+ <option argLabel="quiet" shortName="q" longName="quiet" />
+ <option argLabel="debug" longName="debug" />
+ </optionSet>
+ <repeat>
+ <argument argLabel="files" />
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="gunzip">
+ <empty description="decompress standard input to standard output" />
+ <sequence description="decompress files">
+ <optionSet>
+ <!-- GZip -->
+ <option argLabel="test" shortName="t" longName="test" />
+ <option argLabel="list" shortName="l" longName="list" />
+ <option argLabel="recurse" shortName="r" longName="recursive" />
+ <option argLabel="noname" shortName="n" longName="no-name" />
+ <option argLabel="name" shortName="N" longName="name" />
+ <!-- ArchiveCommand -->
+ <option argLabel="stdout" shortName="c" longName="stdout" />
+ <option argLabel="force" shortName="f" longName="force" />
+ <option argLabel="quiet" shortName="q" longName="quiet" />
+ <option argLabel="verbose" shortName="v" longName="verbose" />
+ <option argLabel="debug" longName="debug" />
+ </optionSet>
+ <optional eager="true">
+ <option argLabel="suffix" shortName="S" longName="suffix" />
+ </optional>
+ <repeat minCount="1">
+ <argument argLabel="files" />
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="gzip">
+ <empty description="compress standard input to standard output" />
+ <sequence description="compress files">
+ <optionSet>
+ <!-- GZipCommand -->
+ <option argLabel="c1" shortName="1" longName="fast" />
+ <option argLabel="c9" shortName="9" longName="best" />
+ <option argLabel="decompress" shortName="d" longName="decompress" />
+ <!-- GZip -->
+ <option argLabel="test" shortName="t" longName="test" />
+ <option argLabel="list" shortName="l" longName="list" />
+ <option argLabel="recurse" shortName="r" longName="recursive" />
+ <option argLabel="noname" shortName="n" longName="no-name" />
+ <option argLabel="name" shortName="N" longName="name" />
+ <!-- ArchiveCommand -->
+ <option argLabel="stdout" shortName="c" longName="stdout" />
+ <option argLabel="force" shortName="f" longName="force" />
+ <option argLabel="quiet" shortName="q" longName="quiet" />
+ <option argLabel="verbose" shortName="v" longName="verbose" />
+ <option argLabel="debug" longName="debug" />
+ </optionSet>
+ <optional eager="true">
+ <option argLabel="suffix" shortName="S" longName="suffix" />
+ </optional>
+ <repeat minCount="1">
+ <argument argLabel="files" />
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="tar">
+ <sequence>
+ <optionSet description="tar options">
+ <!-- Tar Operations -->
+ <option argLabel="doAppend" shortName="r" longName="append" />
+ <option argLabel="doCreate" shortName="c" longName="create" />
+ <option argLabel="doConcat" shortName="A" longName="concatenate" />
+ <option argLabel="doDiff" shortName="d" longName="diff" />
+ <option argLabel="doExtract" shortName="x" longName="extract" />
+ <option argLabel="doList" shortName="t" longName="list" />
+ <option argLabel="doUpdate" shortName="u" longName="update" />
+ <option argLabel="doDelete" longName="delete" />
+ <!-- Tar Global Options -->
+ <option argLabel="archive" shortName="f" longName="file" />
+ <option argLabel="bzip" shortName="j" longName="bzip2" />
+ <option argLabel="fileList" shortName="T" longName="files-from"/>
+ <option argLabel="gzip" shortName="z" longName="gzip" />
+ <option argLabel="interact" shortName="w" longName="interactive" />
+ <option argLabel="keep_old" shortName="k" longName="keep-old-files" />
+ <option argLabel="verify" shortName="W" longName="verify" />
+ <option argLabel="xfile" shortName="X" longName="exclude-from"/>
+ <option argLabel="backup" longName="backup" />
+ <option argLabel="keep_new" longName="keep-newer-files" />
+ <option argLabel="removeFiles" longName="remove-files" />
+ <option argLabel="showTotals" longName="totals" />
+ <option argLabel="suffix" longName="suffix" />
+ <option argLabel="unlink" longName="unlink" />
+ <!-- Tar Path Parser Options -->
+ <option argLabel="dir" shortName="C" longName="directory" />
+ <option argLabel="exclude" longName="exclude" label="pattern" />
+ <option argLabel="noRecurse" longName="no-recursion" />
+ <option argLabel="recurse" longName="recursion" />
+ <!-- ArchiveCommand -->
+ <option argLabel="verbose" shortName="v" longName="verbose" />
+ <option argLabel="stdout" shortName="O" longName="to-stdout" />
+ <option argLabel="debug" longName="debug" />
+ <!--
+ <option argLabel="minDate" shortName="N" longName="newer" />
+ <option argLabel="minMTime" longName="newer-mtime" />
+ -->
+ </optionSet>
+ <repeat>
+ <argument argLabel="paths"/>
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="unzip">
+ <sequence>
+ <optionSet>
+ <!-- UnzipCommand -->
+ <option argLabel="backup" shortName="B"/>
+ <option argLabel="ignore-case" shortName="C"/>
+ <option argLabel="keep" shortName="n"/>
+ <option argLabel="overwrite" shortName="o"/>
+ <!-- Zip -->
+ <option argLabel="no-path" shortName="j"/>
+ <!-- Zip Operations -->
+ <option argLabel="freshen" shortName="f"/>
+ <option argLabel="list" shortName="l"/>
+ <option argLabel="test" shortName="t"/>
+ <option argLabel="update" shortName="u"/>
+ <!-- ArchiveCommand -->
+ <option argLabel="stdout" shortName="p"/>
+ <option argLabel="verbose" shortName="v"/>
+ <option argLabel="quiet" shortName="q"/>
+ <option argLabel="debug" longName="debug"/>
+ </optionSet>
+ <argument argLabel="archive"/>
+ <repeat>
+ <argument argLabel="patterns"/>
+ </repeat>
+ <!-- TODO
+ <repeat>
+ <option argLabel="exclude" shortName="x"/>
+ </repeat>
+ <optional>
+ <option argLabel="extract-dir" shortName="d"/>
+ </optional>
+ -->
+ </sequence>
+ </syntax>
+ <syntax alias="zcat">
+ <empty description="decompress standard input to standard output" />
+ <repeat minCount="1">
+ <argument argLabel="files" />
+ </repeat>
+ </syntax>
+ <syntax alias="zip">
+ <sequence>
+ <optionSet>
+ <!-- ZipCommand -->
+ <option argLabel="files-stdin" shortName="@"/>
+ <option argLabel="tmp-dir" shortName="b"/>
+ <option argLabel="no-dirs" shortName="D"/>
+ <option argLabel="no-compress" shortName="n"/>
+ <option argLabel="recurse" shortName="r"/>
+ <!--<option argLabel="recurse-cd" shortName="R"/>-->
+ <option argLabel="newer" shortName="t"/>
+ <option argLabel="older" longName="tt"/>
+ <!-- Zip -->
+ <option argLabel="no-path" shortName="j"/>
+ <!-- Zip Operations -->
+ <option argLabel="delete" shortName="d"/>
+ <option argLabel="freshen" shortName="f"/>
+ <option argLabel="move" shortName="m"/>
+ <option argLabel="update" shortName="u"/>
+ <!-- ArchiveCommand -->
+ <option argLabel="quiet" shortName="q"/>
+ <option argLabel="verbose" shortName="v"/>
+ <option argLabel="debug" longName="debug"/>
+ </optionSet>
+ <argument argLabel="archive"/>
+ <repeat>
+ <alternatives>
+ <option argLabel="exclude" shortName="x"/>
+ <option argLabel="include" shortName="i"/>
+ <argument argLabel="patterns"/>
+ </alternatives>
+ </repeat>
+ </sequence>
+ </syntax>
+ </extension>
+
+ <extension point="org.jnode.security.permissions">
+ <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write,delete"/>
+ <permission class="java.util.PropertyPermission" name="user.dir" actions="read,write"/>
+ <permission class="java.util.PropertyPermission" name="*" actions="read,write"/>
+ <permission class="java.lang.RuntimePermission" name="modifyThreadGroup"/>
+ <permission class="java.lang.RuntimePermission" name="exitVM"/>
+ <permission class="org.jnode.security.JNodePermission" name="getVmClass"/>
+ </extension>
+</plugin>
Added: trunk/cli/descriptors/org.jnode.command.file.xml
===================================================================
--- trunk/cli/descriptors/org.jnode.command.file.xml (rev 0)
+++ trunk/cli/descriptors/org.jnode.command.file.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plugin SYSTEM "jnode.dtd">
+
+<plugin id="org.jnode.command.file"
+ name="JNode file commands"
+ version="@VERSION@"
+ provider-name="@PROVIDER@"
+ license-name="lgpl">
+
+ <requires>
+ <import plugin="org.jnode.shell.syntax"/>
+ <import plugin="org.jnode.command.util"/>
+ </requires>
+
+ <runtime>
+ <library name="jnode-coreutils.jar">
+ <export name="org.jnode.command.file.*"/>
+ </library>
+ </runtime>
+
+ <extension point="org.jnode.shell.aliases">
+ <alias name="cd" class="org.jnode.command.file.CdCommand" internal="yes"/>
+ <alias name="cp" class="org.jnode.command.file.CpCommand"/>
+ <alias name="del" class="org.jnode.command.file.DeleteCommand"/>
+ <alias name="df" class="org.jnode.command.file.DFCommand"/>
+ <alias name="dir" class="org.jnode.command.file.DirCommand"/>
+ <alias name="find" class="org.jnode.command.file.FindCommand"/>
+ <alias name="hexdump" class="org.jnode.command.file.HexdumpCommand"/>
+ <alias name="ls" class="org.jnode.command.file.DirCommand"/>
+ <alias name="md5sum" class="org.jnode.command.file.Md5SumCommand"/>
+ <alias name="mkdir" class="org.jnode.command.file.MkdirCommand"/>
+ <alias name="pwd" class="org.jnode.command.file.PwdCommand"/>
+ <alias name="rm" class="org.jnode.command.file.DeleteCommand"/>
+ <alias name="touch" class="org.jnode.command.file.TouchCommand"/>
+ </extension>
+
+ <extension point="org.jnode.shell.syntaxes">
+ <syntax alias="cd">
+ <empty description="change the current directory to the 'user.home' directory"/>
+ <argument argLabel="directory" description="change the current directory to 'directory'"/>
+ </syntax>
+ <syntax alias="cp">
+ <sequence description="copy files or directories">
+ <optionSet>
+ <option argLabel="force" shortName="f" longName="force"/>
+ <option argLabel="update" shortName="u" longName="update"/>
+ <option argLabel="interactive" shortName="i" longName="interactive"/>
+ <option argLabel="recursive" shortName="r" longName="recursive"/>
+ <option argLabel="verbose" shortName="v" longName="verbose"/>
+ </optionSet>
+ <repeat minCount="1">
+ <argument argLabel="source"/>
+ </repeat>
+ <argument argLabel="target"/>
+ </sequence>
+ </syntax>
+ <syntax alias="del">
+ <sequence description="delete files and directories">
+ <optionSet>
+ <option argLabel="recursive" shortName="r" longName="recursive"/>
+ <option argLabel="force" shortName="f" longName="force" />
+ <option argLabel="interactive" shortName="i" longName="interactive" />
+ <option argLabel="verbose" shortName="v" longName="verbose" />
+ </optionSet>
+ <repeat minCount="1">
+ <argument argLabel="paths"/>
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="df">
+ <empty description="display disk usage for all filesystems"/>
+ <argument argLabel="device" description="display disk usage for the filesystem on a device"/>
+ </syntax>
+ <syntax alias="dir">
+ <empty description="list the current directory"/>
+ <argument argLabel="path" description="list a file or directory"/>
+ </syntax>
+ <syntax alias="find">
+ <sequence description="find files or directories">
+ <repeat minCount="0">
+ <argument argLabel="directory" description="directory to start searching from"/>
+ </repeat>
+ <optionSet>
+ <option argLabel="type" shortName="t" longName="type"/>
+ <option argLabel="maxdepth" shortName="D" longName="maxdepth"/>
+ <option argLabel="mindepth" shortName="d" longName="mindepth"/>
+ <option argLabel="name" shortName="n" longName="name"/>
+ <option argLabel="iname" shortName="N" longName="iname"/>
+ </optionSet>
+ </sequence>
+ </syntax>
+ <syntax alias="hexdump">
+ <empty description="print a hex dump of standard input"/>
+ <argument argLabel="file" description="print a hex dump of a file"/>
+ <option argLabel="url" shortName="u" longName="url" description="print a hex dump of a URL"/>
+ </syntax>
+ <syntax alias="ls">
+ <empty description="list the current directory"/>
+ <repeat>
+ <argument argLabel="path" description="list files or directories"/>
+ </repeat>
+ </syntax>
+ <syntax alias="md5sum">
+ <empty description="Calculates the MD5 digest for standard input"/>
+ <option argLabel="checkfile" shortName="c" longName="check"/>
+ <sequence description="Calculates the MD5 digests for files">
+ <optional eager="true">
+ <option argLabel="recursive" shortName="r" longName="recursive"/>
+ </optional>
+ <repeat minCount="1"><argument argLabel="paths"/></repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="mkdir">
+ <argument argLabel="directory" description="create a new directory"/>
+ </syntax>
+ <syntax alias="pwd">
+ <empty description="show the pathname for the current directory"/>
+ </syntax>
+ <syntax alias="rm">
+ <sequence description="delete files and directories">
+ <optionSet>
+ <option argLabel="recursive" shortName="r" longName="recursive"/>
+ <option argLabel="force" shortName="f" longName="force" />
+ <option argLabel="interactive" shortName="i" longName="interactive" />
+ <option argLabel="verbose" shortName="v" longName="verbose" />
+ </optionSet>
+ <repeat minCount="1">
+ <argument argLabel="paths"/>
+ </repeat>
+ </sequence>
+ </syntax>
+ <syntax alias="touch">
+ <argument argLabel="file" description="touch the given file"/>
+ </syntax>
+ </extension>
+
+ <extension point="org.jnode.security.permissions">
+ <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write,delete"/>
+ <permission class="java.io.RuntimePermission" name="readFileDescriptor"/>
+ <permission class="java.io.RuntimePermission" name="writeFileDescriptor"/>
+ <permission class="java.util.PropertyPermission" name="user.dir" actions="read,write"/>
+ </extension>
+</plugin>
Added: trunk/cli/descriptors/org.jnode.command.util.xml
===================================================================
--- trunk/cli/descriptors/org.jnode.command.util.xml (rev 0)
+++ trunk/cli/descriptors/org.jnode.command.util.xml 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plugin SYSTEM "jnode.dtd">
+
+<plugin id="org.jnode.command.util"
+ name="JNode command utilities"
+ version="@VERSION@"
+ provider-name="@PROVIDER@"
+ license-name="lgpl">
+
+ <runtime>
+ <library name="jnode-coreutils.jar">
+ <export name="org.jnode.command.util.*" />
+ </library>
+ </runtime>
+</plugin>
Copied: trunk/cli/src/commands/org/jnode/command/archive/ArchiveCommand.java (from rev 5360, trunk/fs/src/fs/org/jnode/fs/command/archive/ArchiveCommand.java)
===================================================================
--- trunk/cli/src/commands/org/jnode/command/archive/ArchiveCommand.java (rev 0)
+++ trunk/cli/src/commands/org/jnode/command/archive/ArchiveCommand.java 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,301 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.command.archive;
+
+import org.jnode.shell.AbstractCommand;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.FlagArgument;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.IOException;
+
+import java.util.ArrayList;
+
+import org.apache.tools.zip.ZipFile;
+
+/**
+ * This is a base class that holds some convenience methods for implementing archive commands.
+ *
+ * @author chris boertien
+ */
+public class ArchiveCommand extends AbstractCommand {
+
+ private static final String help_verbose = "show the compression ratio for each file compressed";
+ private static final String help_debug = "internal debug output";
+ private static final String help_quiet = "supress non-essential warning messages";
+ private static final String help_stdout = "pipe data to stdout";
+ private static final String help_force = "force overwrite of output files";
+ protected static final String help_decompress = "force decompression";
+
+ protected static final String prompt_overwrite = " already exists. Do you wish to overwrite? [Y/n]: ";
+
+ protected static final String err_exception_uncaught = "Unhandled Exception thrown";
+ protected static final String err_file_create = "Could not create file: ";
+ protected static final String err_file_not_exist = "Could not find file: ";
+ protected static final String err_stream_create = "Could not create stream: ";
+
+ protected static final String fmt_size_diff = "%s:\t%f.2%% -- replaced with %s";
+
+ protected final FlagArgument Quiet = new FlagArgument("quiet", Argument.OPTIONAL, help_quiet);
+ protected final FlagArgument Verbose = new FlagArgument("verbose", Argument.OPTIONAL, help_verbose);
+ protected final FlagArgument Debug = new FlagArgument("debug", Argument.OPTIONAL, help_debug);
+ protected final FlagArgument Stdout = new FlagArgument("stdout", Argument.OPTIONAL, help_stdout);
+ protected final FlagArgument Force = new FlagArgument("force", Argument.OPTIONAL, help_force);
+
+ protected static final int OUT_FATAL = 0x01;
+ protected static final int OUT_ERROR = 0x02;
+ protected static final int OUT_WARN = 0x04;
+ protected static final int OUT_NOTICE = 0x08;
+ protected static final int OUT_DEBUG = 0x80;
+
+ protected static final int BUFFER_SIZE = 4096;
+
+ protected int outMode = OUT_ERROR | OUT_WARN;
+
+ protected PrintWriter stdoutWriter;
+ protected PrintWriter stderrWriter;
+ protected Reader stdinReader;
+ protected InputStream stdin;
+ protected OutputStream stdout;
+
+ protected String commandName;
+ protected int rc = 1;
+ protected boolean use_stdout;
+ protected boolean force;
+ protected boolean compress;
+
+ private byte[] buffer;
+
+ private ArchiveCommand() {}
+
+ protected ArchiveCommand(String s) {
+ super(s);
+ }
+
+ public void execute(String command) {
+ stdoutWriter = getOutput().getPrintWriter();
+ stderrWriter = getError().getPrintWriter();
+ stdinReader = getInput().getReader();
+ stdin = getInput().getInputStream();
+ stdout = getOutput().getOutputStream();
+
+ // FIXME get rid of this {
+ if (command.equals("zcat") || command.equals("bzcat")) return;
+
+ if (!command.equals("tar")) {
+ if (Quiet.isSet()) outMode = 0;
+ force = Force.isSet();
+ }
+
+ if (!use_stdout) use_stdout = Stdout.isSet();
+
+ if (outMode != 0) {
+ if (Verbose.isSet()) outMode |= OUT_NOTICE;
+ if (Debug.isSet()) outMode |= OUT_DEBUG;
+ }
+ // }
+ }
+
+ protected void createStreamBuffer(int size) {
+ buffer = new byte[size];
+ }
+
+ /**
+ * Pipes the contents of the InputStream into the OutputStream.
+ *
+ * This is most usefull for applying a stream filter that reads data from a source
+ * and pipes the contents to an output stream.
+ *
+ * @param InputStream stream to read from
+ * @param OutputStream stream to write to
+ * @param int size of buffer to use.
+ */
+ protected void processStream(InputStream in , OutputStream out) throws IOException {
+ int len;
+ if (buffer == null) buffer = new byte[4096];
+ while ((len = in.read(buffer)) > 0) {
+ out.write(buffer, 0, len);
+ }
+ }
+
+ /**
+ * Opens a FileOutputStream for a file.
+ *
+ * If there is a problem opening the stream, the exception is caught and an error message
+ * is displayed.
+ *
+ * @param File the file to open the stream on
+ * @param boolean if the file exists, delete it first
+ * @param boolean if delete is true, this forces the deletion without prompting the user
+ * @return an OutputStream on the file, or null if there was a problem. null could also be
+ * returned if the delete option was chosen and the user said no to overwriting.
+ */
+ protected OutputStream openFileWrite(File file , boolean delete , boolean forced) {
+ try {
+ boolean createNew = true;
+ if (file == null) {
+ error(err_file_create + "null");
+ return null;
+ }
+
+ if (file.exists()) {
+ if (delete) {
+ if (forced) {
+ file.delete();
+ } else {
+ if (prompt_yn(file + prompt_overwrite, true)) {
+ file.delete();
+ } else {
+ notice("Skipping " + file);
+ return null;
+ }
+ }
+ } else {
+ return new FileOutputStream(file);
+ }
+ }
+ if (createNew && !file.createNewFile()) {
+ error(err_file_create + file);
+ return null;
+ }
+ return new FileOutputStream(file);
+ } catch (IOException ioe) {
+ error(err_stream_create + file);
+ return null;
+ }
+ }
+
+ /**
+ * Opens a FileInputStream on a file.
+ *
+ * If there is a problem opening the stream, the IOException is caught, and an
+ * error message displayed to the console.
+ *
+ * @param the file to open the stream on
+ * @return the InputStream or null if there was a problem.
+ */
+ protected InputStream openFileRead(File file) {
+ try {
+ if (file == null || !file.exists()) {
+ error(err_file_not_exist + file);
+ return null;
+ }
+ return new FileInputStream(file);
+ } catch (IOException ioe) {
+ error(err_stream_create + file);
+ return null;
+ }
+ }
+
+ /**
+ * Convenience method for closing streams and writers.
+ */
+ protected void close(Closeable obj) {
+ if (obj != null) {
+ try {
+ obj.close();
+ } catch (IOException _) {
+ //ignore
+ }
+ }
+ }
+
+ /**
+ * Convenience method for closing org.apache.tools.zip.ZipFile
+ */
+ protected void close(ZipFile zfile) {
+ if (zfile != null) {
+ try {
+ zfile.close();
+ } catch (IOException _) {
+ // ignore
+ }
+ }
+ }
+
+ /**
+ * Prompt the user with a question asking for a yes or no answer.
+ *
+ * FIXME This is unsafe as it will trigger an endless loop if stdin
+ * is not the terminal.
+ *
+ * @param String the question to ask the user
+ * @return true if the user said yes, false if the user said no
+ */
+ protected boolean prompt_yn(String s, boolean defaultY) {
+ int choice;
+ // put a cap on the looping to prevent non-terminal stdin
+ // from an infinte loop
+ for (int i = 0; i < 10; i++) {
+ stdoutWriter.print(s);
+ try {
+ choice = stdinReader.read();
+ } catch (IOException _) {
+ throw new RuntimeException("Problem with stdin");
+ }
+ stdoutWriter.println();
+ if (choice == 'y') return true;
+ if (choice == 'n') return false;
+ if (choice == '\n') return defaultY;
+ }
+
+ return false;
+ }
+
+ protected void out(String s) {
+ stdoutWriter.println(s);
+ }
+
+ protected void err(String s) {
+ stderrWriter.println(s);
+ }
+
+ protected void debug(String s) {
+ if ((outMode & OUT_DEBUG) == OUT_DEBUG) {
+ stderrWriter.print("debug: ");
+ stderrWriter.println(s);
+ }
+ }
+
+ protected void notice(String s) {
+ if ((outMode & OUT_NOTICE) == OUT_NOTICE) stdoutWriter.println(s);
+ }
+
+ protected void warn(String s) {
+ if ((outMode & OUT_WARN) == OUT_WARN) stdoutWriter.println(s);
+ }
+
+ protected void error(String s) {
+ if ((outMode & OUT_ERROR) == OUT_ERROR) stderrWriter.println(s);
+ }
+
+ protected void fatal(String s, int exit_code) {
+ stderrWriter.println("Fatal error: " + s);
+ exit(exit_code);
+ }
+}
Copied: trunk/cli/src/commands/org/jnode/command/archive/BUnzipCommand.java (from rev 5360, trunk/fs/src/fs/org/jnode/fs/command/archive/BUnzipCommand.java)
===================================================================
--- trunk/cli/src/commands/org/jnode/command/archive/BUnzipCommand.java (rev 0)
+++ trunk/cli/src/commands/org/jnode/command/archive/BUnzipCommand.java 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,40 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.command.archive;
+
+/**
+ * @author chris boertien
+ */
+public class BUnzipCommand extends BZip {
+
+ public BUnzipCommand() {
+ super("decompresses data in bzip2 format");
+ // from ArchiveCommand
+ registerArguments(Quiet, Verbose, Stdout, Force, Debug);
+ // from BZip
+ registerArguments(Compress, Decompress, Files, Keep, Small, Test);
+ }
+
+ public void execute() {
+ compress = false;
+ super.execute("bunzip2");
+ }
+}
Copied: trunk/cli/src/commands/org/jnode/command/archive/BZCatCommand.java (from rev 5360, trunk/fs/src/fs/org/jnode/fs/command/archive/BZCatCommand.java)
===================================================================
--- trunk/cli/src/commands/org/jnode/command/archive/BZCatCommand.java (rev 0)
+++ trunk/cli/src/commands/org/jnode/command/archive/BZCatCommand.java 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,36 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.jnode.command.archive;
+
+/**
+ * @author chris boertien
+ */
+public class BZCatCommand extends BZip {
+
+ public BZCatCommand() {
+ super("extract files to stdout");
+ // from BZip
+ registerArguments(Files, Small);
+ }
+
+ public void execute() {
+ super.execute("bzcat");
+ }
+}
Copied: trunk/cli/src/commands/org/jnode/command/archive/BZip.java (from rev 5360, trunk/fs/src/fs/org/jnode/fs/command/archive/BZip.java)
===================================================================
--- trunk/cli/src/commands/org/jnode/command/archive/BZip.java (rev 0)
+++ trunk/cli/src/commands/org/jnode/command/archive/BZip.java 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,272 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.command.archive;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.tools.bzip2.CBZip2InputStream;
+import org.apache.tools.bzip2.CBZip2OutputStream;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.FileArgument;
+import org.jnode.shell.syntax.FlagArgument;
+
+
+/**
+ * BZip is the backing class for handling compression and decompression
+ * of bzip files.
+ *
+ * @author chris boertien
+ */
+public class BZip extends ArchiveCommand {
+
+ private static final boolean DEBUG = false;
+
+ private static final String help_compress = "forces compression; regardless of invocation name";
+ private static final String help_files = "space seperated list of files to compress";
+ private static final String help_keep = "Keep input files";
+ private static final String help_small = "(ignored)";
+ private static final String help_test = "test the file integrity";
+
+ private static final String fmt_suffix_bad = "Can't guess original name for %s -- using %s.out";
+
+ protected final FlagArgument Compress;
+ protected final FlagArgument Decompress;
+ protected final FileArgument Files;
+ protected final FlagArgument Keep;
+ protected final FlagArgument Small;
+ protected final FlagArgument Test;
+
+ private List<File> files;
+ private int rc = 1;
+ protected int clevel;
+ protected boolean keep;
+ protected boolean small;
+
+ public BZip(String s) {
+ super(s);
+ Compress = new FlagArgument("compress", Argument.OPTIONAL, help_compress);
+ Decompress = new FlagArgument("decompress", Argument.OPTIONAL, help_decompress);
+ int flags = Argument.OPTIONAL | Argument.MULTIPLE | Argument.EXISTING | FileArgument.HYPHEN_IS_SPECIAL;
+ Files = new FileArgument("files", flags, help_files);
+ Keep = new FlagArgument("keep", Argument.OPTIONAL, help_keep);
+ Small = new FlagArgument("small", Argument.OPTIONAL, help_small);
+ Test = new FlagArgument("test", Argument.OPTIONAL, help_test);
+ createStreamBuffer(4096);
+ }
+
+ public void execute(String command) {
+ super.execute(command);
+ parseOptions(command);
+
+ try {
+ if (compress) {
+ compress();
+ } else {
+ decompress();
+ }
+ rc = 0;
+ } catch (IOException e) {
+ error(err_exception_uncaught);
+ rc = 1;
+ } finally {
+ exit(rc);
+ }
+ }
+
+ private void compress() throws IOException {
+ InputStream in = null;
+ OutputStream out = null;
+ CBZip2OutputStream bzout = null;
+
+ if (use_stdout) {
+ bzout = new CBZip2OutputStream(stdout, clevel);
+ }
+
+ for (File file : files) {
+ if (file.getName().equals("-")) {
+ processStream(stdin, bzout);
+ continue;
+ }
+
+ try {
+ if (use_stdout) {
+ if ((in = openFileRead(file)) == null) {
+ rc = 1;
+ continue;
+ }
+ processStream(in, bzout);
+ continue;
+ }
+ try {
+ File bzfile = new File(file.getAbsolutePath() + ".bz2");
+ if ((out = openFileWrite(bzfile, true, force)) == null) {
+ rc = 1;
+ continue;
+ }
+ bzout = new CBZip2OutputStream(out, clevel);
+ if ((in = openFileRead(file)) == null) {
+ rc = 1;
+ continue;
+ }
+ processStream(in, bzout);
+ float sizeDiff = ((float) bzfile.length() / (float) file.length()) * 100;
+ notice(String.format(fmt_size_diff, file, sizeDiff, bzfile));
+ if (!keep) file.delete();
+ } finally {
+ close(bzout);
+ }
+ } finally {
+ close(in);
+ }
+ }
+ // TEST need to see if this is even necessary, and if it is
+ // should it be within a finally block
+ if (use_stdout) {
+ bzout.close();
+ }
+ }
+
+ private void decompress() throws IOException {
+ InputStream in = null;
+ OutputStream out = stdout;
+
+ for (File bzfile : files) {
+ if (bzfile.getName().equals("-")) {
+ processStream(new CBZip2InputStream(stdin), out);
+ continue;
+ }
+ try {
+ if (use_stdout) {
+ if ((in = new CBZip2InputStream(openFileRead(bzfile))) == null) {
+ rc = 1;
+ continue;
+ }
+ processStream(in, out);
+ continue;
+ }
+ try {
+ File file = stripSuffix(bzfile);
+ if ((out = openFileWrite(file, true, force)) == null) {
+ rc = 1;
+ continue;
+ }
+ if ((in = new CBZip2InputStream(openFileRead(bzfile))) == null) {
+ rc = 1;
+ continue;
+ }
+ processStream(in, out);
+ float sizeDiff = ((float) bzfile.length() / (float) file.length()) * 100;
+ notice(String.format(fmt_size_diff, bzfile, sizeDiff, file));
+ if (!keep) bzfile.delete();
+ } finally {
+ close(out);
+ }
+ } finally {
+ close(in);
+ }
+ }
+ }
+
+ private void test(File[] files) {
+ // TODO
+ // requires patch to apache ant to have CBZip2InputStream fail with an
+ // exception, instead it just prints to stderr and doesn't tell us if
+ // it failed.
+ //
+ // Otherwise we would have to read and compute the crc ourself.
+ }
+
+ /**
+ * Strips .bz and .bz2 suffixes from the file. Will also replace
+ * .tbz and .tbz2 files with .tar suffix. If the suffix doesn't match
+ * any of these, the suffix .out will be appended to the file name
+ */
+ private File stripSuffix(File bzfile) {
+ String name = bzfile.getName();
+ int len = 0;
+ String newSuffix = null;
+
+ if (name.endsWith(".bz")) {
+ len = 3;
+ } else if (name.endsWith(".bz2")) {
+ len = 4;
+ } else if (name.endsWith(".tbz")) {
+ len = 4;
+ newSuffix = ".tar";
+ } else if (name.endsWith(".tbz2")) {
+ len = 5;
+ newSuffix = ".tar";
+ } else {
+ notice(String.format(fmt_suffix_bad, bzfile.getPath(), bzfile.getPath()));
+ return new File(bzfile.getPath() + ".out");
+ }
+
+ if (len > 0) {
+ name = name.substring(0, name.length() - len);
+ }
+
+ if (newSuffix != null) {
+ name = name + newSuffix;
+ }
+
+ return new File(name);
+ }
+
+ private void parseOptions(String command) {
+ small = Small.isSet();
+ if (!command.equals("bzcat")) {
+ if (compress && Decompress.isSet()) {
+ compress = false;
+ }
+ if (!compress && Compress.isSet()) {
+ compress = true;
+ }
+
+ keep = use_stdout || Keep.isSet();
+ }
+
+ files = new ArrayList<File>();
+
+ for (File file : Files.getValues()) {
+ if (file.isDirectory()) {
+ for (File f : file.listFiles()) {
+ if (!f.isDirectory()) {
+ files.add(f);
+ }
+ }
+ } else {
+ if (file.getName().equals("-")) {
+ use_stdout = true;
+ }
+ files.add(file);
+ }
+ }
+
+ if (files.size() == 0) {
+ files.add(new File("-"));
+ use_stdout = true;
+ }
+ }
+}
Copied: trunk/cli/src/commands/org/jnode/command/archive/BZipCommand.java (from rev 5360, trunk/fs/src/fs/org/jnode/fs/command/archive/BZipCommand.java)
===================================================================
--- trunk/cli/src/commands/org/jnode/command/archive/BZipCommand.java (rev 0)
+++ trunk/cli/src/commands/org/jnode/command/archive/BZipCommand.java 2009-04-29 21:55:50 UTC (rev 5361)
@@ -0,0 +1,68 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.command.archive;
+
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.FlagArgument;
+
+/**
+ * @author chris boertien
+ */
+public class BZipCommand extends BZip {
+
+ private static final String help_fast = "compress faster";
+ private static final String help_best = "compress better";
+
+ private final FlagArgument C1 = new FlagArgument("c1", Argument.OPTIONAL, help_fast);
+ private final FlagArgument C2 = new FlagArgument("c2", Argument.OPTIONAL, " ");
+ private final FlagArgument C3 = new FlagArgument("c3", Argument.OPTIONAL, " ");
+ private final FlagArgument C4 = new FlagArgument("c4", Argument.OPTIONAL, " ");
+ private final FlagArgument C5 = new FlagArgument("c5", Argument.OPTIONAL, " ");
+ private final FlagArgument C6 = new FlagArgument("c6", Argument.OPTIONAL, " ");
+ private final FlagArgument C7 = new FlagArgument("c7", Argument.OPTIONAL, " ");
+ private final FlagArgument C8 = new FlagArgument("c8", Argument.OPTIONAL, " ");
+ private final FlagArgument C9 = new FlagArgument("c9", Argument.OPTIONAL, help_best);
+
+ public BZipCommand() {
+ super("compresses data with bzip2");
+ // from ArchiveCommand
+ registerArguments(Quiet, Verbose, Stdout, Force, Debug);
+ // from BZip
+ registerArguments(Compress, Decompress, Files, Keep, Small, Test);
+ registerArguments(C1, C2, C3, C4, C5, C6, C7, C8, C9);
+ }
+
+ public void execute() {
+ compress = true;
+ if (C1.isSet()) clevel = 1;
+ if (C2.isSet()) clevel = 2;
+ if (C3.isSet()) clevel = 3;
+ if (C4.isSet()) clevel = 4;
+ if (C5.isSet()) clevel = 5;
+ if (C6.isSet()) clevel = 6;
+ if (C7.isSet()) clevel = 7;
+ if (C8.isSet()) clevel = 8;
+ if (C9.isSet()) clevel = 9;
+ else clevel = 6;
+
+ super.execute("bzip2");
+ }
+}
Copied: trunk/cli/src/commands/org/jnode/command/archive/GUnzipCommand.java (from rev 5360, trunk/fs/src/fs/org/jnode/fs/command/archive/GUnzipCommand.java)
=========...
[truncated message content] |