You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/30 07:58:47 UTC
svn commit: r700351 - in
/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main:
java/org/apache/geronimo/gshell/commands/vfs/ resources/META-INF/spring/
resources/org/apache/geronimo/gshell/commands/vfs/
Author: jdillon
Date: Mon Sep 29 22:58:46 2008
New Revision: 700351
URL: http://svn.apache.org/viewvc?rev=700351&view=rev
Log:
Added 'fileinfo' command
Added:
geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java (with props)
geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties (contents, props changed)
- copied, changed from r700230, geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties
Modified:
geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml
Added: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java?rev=700351&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java (added)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java Mon Sep 29 22:58:46 2008
@@ -0,0 +1,97 @@
+/*
+ * 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.geronimo.gshell.commands.vfs;
+
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileType;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+/**
+ * Display information about a file.
+ *
+ * @version $Rev$ $Date$
+ */
+public class FileInfoAction
+ extends VfsActionSupport
+{
+ @Argument(required=true)
+ private String path;
+
+ public Object execute(final CommandContext context) throws Exception {
+ assert context != null;
+ IO io = context.getIo();
+
+ FileObject file = resolveFile(context, path);
+
+ if (!file.exists()) {
+ io.error("File not found: {}", file.getName());
+ return Result.FAILURE;
+ }
+ else if (file.getType() == FileType.FOLDER) {
+ io.error("File is a directory: {}", file.getName());
+ return Result.FAILURE;
+ }
+
+ io.info("URL: {}", file.getURL());
+ io.info("Name: {}", file.getName());
+ io.info("BaseName: {}", file.getName().getBaseName());
+ io.info("Extension: {}", file.getName().getExtension());
+ io.info("Path: {}", file.getName().getPath());
+ io.info("Scheme: {}", file.getName().getScheme());
+ io.info("URI: {}", file.getName().getURI());
+ io.info("Root URI: {}", file.getName().getRootURI());
+ io.info("Parent: {}", file.getName().getParent());
+ io.info("Type: {}", file.getType());
+ io.info("Exists: {}", file.exists());
+ io.info("Readable: {}", file.isReadable());
+ io.info("Writeable: {}", file.isWriteable());
+ io.info("Root path: {}", file.getFileSystem().getRoot().getName().getPath());
+
+ if (file.exists()) {
+ if (file.getType().equals(FileType.FILE)) {
+ io.info("Size: {} bytes", file.getContent().getSize());
+ }
+ else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) {
+ FileObject[] children = file.getChildren();
+ io.info("Directory with {} files", children.length);
+
+ for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
+ io.info("#{}:{}", iterChildren, children[iterChildren].getName());
+ if (iterChildren > 5) {
+ break;
+ }
+ }
+ }
+ io.info("Last modified: {}", DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime())));
+ }
+ else {
+ io.info("The file does not exist");
+ }
+
+ file.close();
+
+ return Result.SUCCESS;
+ }
+}
Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml?rev=700351&r1=700350&r2=700351&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml Mon Sep 29 22:58:46 2008
@@ -95,6 +95,14 @@
<null/>
</gshell:completers>
</gshell:command>
+
+ <gshell:command name="fileinfo">
+ <gshell:action class="org.apache.geronimo.gshell.commands.vfs.FileInfoAction"/>
+ <gshell:completers>
+ <ref bean="fileObjectNameCompleter"/>
+ <null/>
+ </gshell:completers>
+ </gshell:command>
</gshell:command-bundle>
<!--
Copied: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties (from r700230, geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties?p2=geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties&p1=geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties&r1=700230&r2=700351&rev=700351&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties Mon Sep 29 22:58:46 2008
@@ -21,14 +21,12 @@
## $Rev$ $Date$
##
-command.name=cat
+command.name=fileinfo
-command.description=Displays the contents of a file.
+command.description=Displays information about a file.
command.argument.path=Path of file to display
command.argument.path.token=PATH
-command.option.displayLineNumbers=Number the output lines, starting at 1
-
command.manual=\
- TODO: cat manual
\ No newline at end of file
+ TODO: fileinfo manual
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain