[jboss-cvs] JBossAS SVN: r61100 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 5 15:39:51 EST 2007
Author: scott.stark at jboss.org
Date: 2007-03-05 15:39:51 -0500 (Mon, 05 Mar 2007)
New Revision: 61100
Added:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/SecurityActions.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractURLHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
Log:
JBMICROCONT-153, add a VirtualFile/VirtualFileHandle exists() method.
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -170,6 +170,16 @@
}
/**
+ * Tests whether the underlying implementation file still exists.
+ * @return true if the file exists, false otherwise.
+ * @throws IOException - thrown on failure to detect existence.
+ */
+ public boolean exists() throws IOException
+ {
+ return getHandler().exists();
+ }
+
+ /**
* Whether it is a simple leaf of the VFS,
* i.e. whether it can contain other files
*
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractURLHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractURLHandler.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractURLHandler.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -106,6 +106,19 @@
return c.getContentLength();
}
+ /**
+ * Basis existence on URLConnection.getLastModified() != 0. This may
+ * not be true for all url connections.
+ *
+ * @see URLConnection#getLastModified()
+ * @see org.jboss.test.virtual.test.URLExistsUnitTestCase
+ */
+ public boolean exists() throws IOException
+ {
+ URLConnection c = url.openConnection();
+ return c.getLastModified() != 0;
+ }
+
public boolean isHidden() throws IOException
{
checkClosed();
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -89,6 +89,11 @@
return delegate.isLeaf();
}
+ public boolean exists() throws IOException
+ {
+ return delegate.exists();
+ }
+
public boolean isHidden() throws IOException
{
return delegate.isHidden();
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/SecurityActions.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/SecurityActions.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/SecurityActions.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.virtual.plugins.context.file;
+
+import java.io.File;
+
+/**
+ * Package priviledged actions.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+class SecurityActions
+{
+ /**
+ * Actions for File access
+ interface FileActions
+ {
+ FileActions PRIVILEGED = new FileActions()
+ {
+ private final PrivilegedExceptionAction exAction = new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return (Subject) PolicyContext.getContext(SUBJECT_CONTEXT_KEY);
+ }
+ };
+ public Subject getContextSubject()
+ throws PolicyContextException
+ {
+ try
+ {
+ return (Subject) AccessController.doPrivileged(exAction);
+ }
+ catch(PrivilegedActionException e)
+ {
+ Exception ex = e.getException();
+ if( ex instanceof PolicyContextException )
+ throw (PolicyContextException) ex;
+ else
+ throw new UndeclaredThrowableException(ex);
+ }
+ }
+ };
+
+ FileActions NON_PRIVILEGED = new FileActions()
+ {
+ };
+
+ public boolean isFile(File f);
+ public boolean isHidden(File f);
+ }
+ */
+
+}
Property changes on: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -96,6 +96,15 @@
return children;
}
+ /**
+ * TODO: removing the entry/jar that resulted in this needs
+ * to be detected.
+ */
+ public boolean exists() throws IOException
+ {
+ return true;
+ }
+
public boolean isLeaf() throws IOException
{
return false;
@@ -283,6 +292,15 @@
contents = baos.toByteArray();
}
+ /**
+ * TODO: removing the entry/jar that resulted in this needs
+ * to be detected.
+ */
+ public boolean exists() throws IOException
+ {
+ return true;
+ }
+
public boolean isHidden() throws IOException
{
return false;
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -115,6 +115,15 @@
return 0;
}
+ /**
+ * TODO: removing the entry/jar that resulted in this needs
+ * to be detected.
+ */
+ public boolean exists() throws IOException
+ {
+ return true;
+ }
+
public boolean isLeaf()
{
return false;
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -110,6 +110,13 @@
long getSize() throws IOException;
/**
+ * Tests whether the underlying implementation file still exists.
+ * @return true if the file exists, false otherwise.
+ * @throws IOException - thrown on failure to detect existence.
+ */
+ boolean exists() throws IOException;
+
+ /**
* Whether it is a simple leaf of the VFS,
* i.e. whether it can contain other files
*
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -60,6 +60,9 @@
/** Size */
private long size;
+ /** Does the file exist */
+ private boolean exists = true;
+
/** Is a leaf */
private boolean leaf = true;
@@ -188,6 +191,16 @@
this.size = size;
}
+ public boolean exists()
+ {
+ return exists;
+ }
+
+ public void setExists(boolean exists)
+ {
+ this.exists = exists;
+ }
+
public boolean isLeaf() throws IOException
{
checkClosed();
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2007-03-05 20:34:19 UTC (rev 61099)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2007-03-05 20:39:51 UTC (rev 61100)
@@ -1248,4 +1248,111 @@
InputStream is = ucl.getResourceAsStream("/nosuch-quartz.props");
assertNull("getResourceAsStream(/nosuch-quartz.props)", is);
}
+
+ /**
+ * Test VirtualFile.exists for vfsfile based urls.
+ *
+ * @throws Exception
+ */
+ public void testFileExists()
+ throws Exception
+ {
+ File tmpRoot = File.createTempFile("vfs", ".root");
+ tmpRoot.delete();
+ tmpRoot.mkdir();
+ File tmp = File.createTempFile("testFileExists", null, tmpRoot);
+ log.info("+++ testFileExists, tmp="+tmp.getCanonicalPath());
+
+ URL rootURL = tmpRoot.toURL();
+ VFS vfs = VFS.getVFS(rootURL);
+ VirtualFile tmpVF = vfs.findChild(tmp.getName());
+ assertTrue(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertTrue("tmp.delete()", tmp.delete());
+ assertFalse(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertTrue(tmpRoot+".delete()", tmpRoot.delete());
+ }
+
+ /**
+ * Test VirtualFile.exists for vfsfile based urls for a directory.
+ *
+ * @throws Exception
+ */
+ public void testDirFileExists()
+ throws Exception
+ {
+ File tmpRoot = File.createTempFile("vfs", ".root");
+ tmpRoot.delete();
+ tmpRoot.mkdir();
+ File tmp = File.createTempFile("testFileExists", null, tmpRoot);
+ assertTrue(tmp+".delete()", tmp.delete());
+ assertTrue(tmp+".mkdir()", tmp.mkdir());
+ log.info("+++ testDirFileExists, tmp="+tmp.getCanonicalPath());
+
+ URL rootURL = tmpRoot.toURL();
+ VFS vfs = VFS.getVFS(rootURL);
+ VirtualFile tmpVF = vfs.findChild(tmp.getName());
+ assertTrue(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertFalse(tmpVF.getPathName()+".isLeaf()", tmpVF.isLeaf());
+ assertTrue(tmp+".delete()", tmp.delete());
+ assertFalse(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertTrue(tmpRoot+".delete()", tmpRoot.delete());
+ }
+
+ /**
+ * Test VirtualFile.exists for vfsjar based urls.
+ *
+ * @throws Exception
+ */
+ public void testJarExists()
+ throws Exception
+ {
+ File tmpRoot = File.createTempFile("vfs", ".root");
+ tmpRoot.delete();
+ tmpRoot.mkdir();
+ File tmpJar = File.createTempFile("testJarExists", ".jar", tmpRoot);
+ log.info("+++ testJarExists, tmpJar="+tmpJar.getCanonicalPath());
+ Manifest mf = new Manifest();
+ mf.getMainAttributes().putValue("Created-By", "FileVFSUnitTestCase.testJarExists");
+ FileOutputStream fos = new FileOutputStream(tmpJar);
+ JarOutputStream jos = new JarOutputStream(fos, mf);
+ jos.setComment("testJarExists");
+ jos.setLevel(0);
+ jos.close();
+
+ URL rootURL = tmpRoot.toURL();
+ VFS vfs = VFS.getVFS(rootURL);
+ VirtualFile tmpVF = vfs.findChild(tmpJar.getName());
+ assertTrue(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertTrue(tmpVF.getPathName()+".size() > 0", tmpVF.getSize() > 0);
+ assertTrue("tmp.delete()", tmpJar.delete());
+ assertFalse(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertTrue(tmpRoot+".delete()", tmpRoot.delete());
+ }
+
+ /**
+ * Test VirtualFile.exists for vfsjar based urls for a directory.
+ *
+ * @throws Exception
+ */
+ public void testDirJarExists()
+ throws Exception
+ {
+ File tmpRoot = File.createTempFile("vfs", ".root");
+ tmpRoot.delete();
+ tmpRoot.mkdir();
+ File tmp = File.createTempFile("testDirJarExists", ".jar", tmpRoot);
+ assertTrue(tmp+".delete()", tmp.delete());
+ assertTrue(tmp+".mkdir()", tmp.mkdir());
+ log.info("+++ testDirJarExists, tmp="+tmp.getCanonicalPath());
+
+ URL rootURL = tmpRoot.toURL();
+ VFS vfs = VFS.getVFS(rootURL);
+ VirtualFile tmpVF = vfs.findChild(tmp.getName());
+ log.info(tmpVF.getHandler());
+ assertTrue(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertFalse(tmpVF.getPathName()+".isLeaf()", tmpVF.isLeaf());
+ assertTrue(tmp+".delete()", tmp.delete());
+ assertFalse(tmpVF.getPathName()+".exists()", tmpVF.exists());
+ assertTrue(tmpRoot+".delete()", tmpRoot.delete());
+ }
}
More information about the jboss-cvs-commits
mailing list