You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/10/05 20:54:56 UTC
svn commit: r821961 [14/30] - in /geronimo/sandbox/djencks/osgi/framework:
./ buildsupport/ buildsupport/car-maven-plugin/
buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/
buildsupport/geronimo-maven-plugin/src/main/jav...
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoFileResourceCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoFileResourceCollection.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoFileResourceCollection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResource.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResource.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResource.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResource.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,66 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.FileInfo;
+
+
+/**
+ * A resource is a file-like entity. It may be an actual file,
+ * an URL, a zip entry, or something like that.
+ */
+public interface PlexusIoResource extends FileInfo
+{
+ /**
+ * Unknown resource size.
+ */
+ public static final long UNKNOWN_RESOURCE_SIZE = -1;
+
+ /**
+ * Unknown modification date
+ */
+ public static final long UNKNOWN_MODIFICATION_DATE = 0;
+
+ /**
+ * Returns the date, when the resource was last modified, if known.
+ * Otherwise, returns {@link #UNKNOWN_MODIFICATION_DATE}.
+ * @see java.io.File#lastModified()
+ */
+ long getLastModified();
+
+ /**
+ * Returns, whether the resource exists.
+ */
+ boolean isExisting();
+
+ /**
+ * Returns the resources size, if known. Otherwise returns
+ * {@link #UNKNOWN_RESOURCE_SIZE}.
+ */
+ long getSize();
+
+ /**
+ * Returns an {@link URL}, which may be used to reference the
+ * resource, if possible.
+ * @return An URL referencing the resource, if possible, or null.
+ * In the latter case, you are forced to use {@link #getInputStream()}.
+ */
+ URL getURL() throws IOException;
+}
\ No newline at end of file
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResource.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceCollection.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceCollection.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceCollection.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceCollection.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,64 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.IOException;
+import java.util.Iterator;
+
+
+/**
+ * A resource collection is a set of {@link PlexusIoResource} instances.
+ */
+public interface PlexusIoResourceCollection
+{
+ /**
+ * Role of the ResourceCollection component.
+ */
+ public static final String ROLE = PlexusIoResourceCollection.class.getName();
+
+ /**
+ * Role hint of the default resource collection, which is a set
+ * of files in a base directory.
+ */
+ public static final String DEFAULT_ROLE_HINT = "default";
+
+ /**
+ * Returns an iterator over the resources in the collection.
+ */
+ Iterator getResources() throws IOException;
+
+ /**
+ * Returns the resources suggested name. This is used for
+ * integrating file mappers.
+ * @param resource A resource, which has been obtained by
+ * calling {@link #getResources()}.
+ */
+ String getName( PlexusIoResource resource ) throws IOException;
+
+ /**
+ * Returns the collections last modification time. For a
+ * collection of files, this might be the last modification
+ * time of the file, which has been modified at last. For an
+ * archive file, this might be the modification time of the
+ * archive file.
+ * @return {@link PlexusIoResource#UNKNOWN_MODIFICATION_DATE},
+ * if the collections last modification time is unknown,
+ * otherwise the last modification time in milliseconds.
+ */
+ long getLastModified() throws IOException;
+
+}
\ No newline at end of file
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceCollection.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceCollection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceWithAttributes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceWithAttributes.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceWithAttributes.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceWithAttributes.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,29 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.geronimo.system.plugin.plexus.io.attributes.PlexusIoResourceAttributes;
+
+public interface PlexusIoResourceWithAttributes
+ extends PlexusIoResource
+{
+
+ PlexusIoResourceAttributes getAttributes();
+
+ void setAttributes( PlexusIoResourceAttributes attributes );
+
+}
\ No newline at end of file
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceWithAttributes.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceWithAttributes.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoResourceWithAttributes.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoURLResource.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoURLResource.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoURLResource.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoURLResource.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,43 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class PlexusIoURLResource extends AbstractPlexusIoResource
+{
+ private URL url;
+
+
+ public InputStream getContents() throws IOException
+ {
+ return getURL().openStream();
+ }
+
+ public URL getURL() throws IOException
+ {
+ return url;
+ }
+
+ public void setURL( URL pUrl )
+ {
+ url = pUrl;
+ }
+
+}
\ No newline at end of file
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoURLResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoURLResource.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoURLResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoZipFileResourceCollection.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoZipFileResourceCollection.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoZipFileResourceCollection.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoZipFileResourceCollection.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,85 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+
+public class PlexusIoZipFileResourceCollection extends AbstractPlexusIoArchiveResourceCollection
+{
+ /**
+ * The zip file resource collections role hint.
+ */
+ public static final String ROLE_HINT = "zipFile";
+
+ /**
+ * The zip file resource collections role hint for jar files.
+ */
+ public static final String JAR_ROLE_HINT = "jarFile";
+
+ public PlexusIoZipFileResourceCollection()
+ {
+
+ }
+
+ protected Iterator getEntries() throws IOException
+ {
+ final File f = getFile();
+ if ( f == null )
+ {
+ throw new IOException( "The zip file has not been set." );
+ }
+ final URL url = new URL( "jar:" + f.toURI().toURL() + "!/");
+ final ZipFile zipFile = new ZipFile( f );
+ final Enumeration en = zipFile.entries();
+ return new Iterator(){
+ public boolean hasNext()
+ {
+ return en.hasMoreElements();
+ }
+ public Object next()
+ {
+ final ZipEntry entry = (ZipEntry) en.nextElement();
+ final PlexusIoURLResource res = new PlexusIoURLResource(){
+ public URL getURL() throws IOException
+ {
+ return new URL( url, entry.getName() );
+ }
+ };
+ final boolean dir = entry.isDirectory();
+ res.setName( entry.getName() );
+ res.setDirectory( dir );
+ res.setExisting( true );
+ res.setFile( !dir );
+ long l = entry.getTime();
+ res.setLastModified( l == -1 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l );
+ res.setSize( dir ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize() );
+ return res;
+ }
+ public void remove()
+ {
+ throw new UnsupportedOperationException( "Removing isn't implemented." );
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoZipFileResourceCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoZipFileResourceCollection.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/PlexusIoZipFileResourceCollection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/package.html
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/package.html?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/package.html (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/package.html Mon Oct 5 18:54:50 2009
@@ -0,0 +1,10 @@
+<html><head><title>Resources and Resource Collections</title></head>
+<body><h1>Resources and Resource Collections</h1>
+<p>This package implements ideas, which have been shamelessly
+ copied from Ants resource collection framework. Basically,
+ a resource is an abstraction of file-like entities: An actual
+ file, an URL, a zip entry, and so on. On the other hand,
+ a resource collections is a collection of resources.</p>
+<p>Resource collections can be copied, moved, archived, unarchived,
+ and so on.</p>
+</body></html>
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/package.html
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/package.html
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResource.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResource.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResource.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResource.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,75 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources.proxy;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.geronimo.system.plugin.plexus.io.resources.AbstractPlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class PlexusIoProxyResource
+ extends AbstractPlexusIoResource
+{
+
+ private final PlexusIoResource src;
+
+ public PlexusIoProxyResource( PlexusIoResource plexusIoResource )
+ {
+ this.src = plexusIoResource;
+ setName( src.getName() );
+ }
+
+ public long getLastModified()
+ {
+ return src.getLastModified();
+ }
+
+ public long getSize()
+ {
+ return src.getSize();
+ }
+
+ public boolean isDirectory()
+ {
+ return src.isDirectory();
+ }
+
+ public boolean isExisting()
+ {
+ return src.isExisting();
+ }
+
+ public boolean isFile()
+ {
+ return src.isFile();
+ }
+
+ public URL getURL()
+ throws IOException
+ {
+ return src.getURL();
+ }
+
+ public InputStream getContents()
+ throws IOException
+ {
+ return src.getContents();
+ }
+
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResource.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceCollection.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceCollection.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceCollection.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceCollection.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,183 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources.proxy;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.geronimo.system.plugin.plexus.io.attributes.PlexusIoResourceAttributeUtils;
+import org.apache.geronimo.system.plugin.plexus.io.attributes.PlexusIoResourceAttributes;
+import org.apache.geronimo.system.plugin.plexus.io.attributes.SimpleResourceAttributes;
+import org.apache.geronimo.system.plugin.plexus.io.filemappers.FileMapper;
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.FileSelector;
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.IncludeExcludeFileSelector;
+import org.apache.geronimo.system.plugin.plexus.io.resources.AbstractPlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.AbstractPlexusIoResourceCollection;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIOResourceCollectionWithAttributes;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResourceCollection;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResourceWithAttributes;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * Implementation of {@link PlexusIoResourceCollection} for an archives
+ * contents.
+ */
+public class PlexusIoProxyResourceCollection
+ extends AbstractPlexusIoResourceCollection
+ implements PlexusIOResourceCollectionWithAttributes
+{
+ private PlexusIoResourceCollection src;
+
+ private SimpleResourceAttributes defaultFileAttributes;
+
+ private SimpleResourceAttributes defaultDirAttributes;
+
+ private PlexusIoResourceAttributes overrideFileAttributes;
+
+ private PlexusIoResourceAttributes overrideDirAttributes;
+
+ /**
+ * Sets the archive to read.
+ */
+ public void setSrc( PlexusIoResourceCollection src )
+ {
+ this.src = src;
+ }
+
+ /**
+ * Returns the archive to read.
+ */
+ public PlexusIoResourceCollection getSrc()
+ {
+ return src;
+ }
+
+ protected FileSelector getDefaultFileSelector()
+ {
+ IncludeExcludeFileSelector fileSelector = new IncludeExcludeFileSelector();
+ fileSelector.setIncludes( getIncludes() );
+ fileSelector.setExcludes( getExcludes() );
+ fileSelector.setCaseSensitive( isCaseSensitive() );
+ fileSelector.setUseDefaultExcludes( isUsingDefaultExcludes() );
+ return fileSelector;
+ }
+
+ public Iterator getResources() throws IOException
+ {
+ final List result = new ArrayList();
+ final FileSelector fileSelector = getDefaultFileSelector();
+ String prefix = getPrefix();
+ if ( prefix != null && prefix.length() == 0 )
+ {
+ prefix = null;
+ }
+ for ( Iterator iter = getSrc().getResources(); iter.hasNext(); )
+ {
+ PlexusIoResource plexusIoResource = (PlexusIoResource) iter.next();
+
+ PlexusIoResourceAttributes attrs = null;
+ if ( plexusIoResource instanceof PlexusIoResourceWithAttributes )
+ {
+ attrs = ((PlexusIoResourceWithAttributes)plexusIoResource).getAttributes();
+ }
+
+ if ( plexusIoResource.isDirectory() )
+ {
+ attrs = PlexusIoResourceAttributeUtils.mergeAttributes( overrideDirAttributes, attrs, defaultDirAttributes );
+ }
+ else
+ {
+ attrs = PlexusIoResourceAttributeUtils.mergeAttributes( overrideFileAttributes, attrs, defaultFileAttributes );
+ }
+
+ if ( !fileSelector.isSelected( plexusIoResource ) )
+ {
+ continue;
+ }
+ if ( !isSelected( plexusIoResource ) )
+ {
+ continue;
+ }
+ if ( plexusIoResource.isDirectory() && !isIncludingEmptyDirectories() )
+ {
+ continue;
+ }
+ if ( prefix != null )
+ {
+ String name = plexusIoResource.getName();
+
+ if ( plexusIoResource instanceof PlexusIoResourceWithAttributes )
+ {
+ plexusIoResource = new PlexusIoProxyResourceWithAttributes( (PlexusIoResourceWithAttributes) plexusIoResource );
+ }
+ else
+ {
+ plexusIoResource = new PlexusIoProxyResource( plexusIoResource );
+ }
+
+ ( (AbstractPlexusIoResource) plexusIoResource ).setName( prefix + name );
+ }
+
+ result.add( plexusIoResource );
+ }
+ return result.iterator();
+ }
+
+ public String getName( PlexusIoResource resource )
+ throws IOException
+ {
+ String name = resource.getName();
+ final FileMapper[] mappers = getFileMappers();
+ if ( mappers != null )
+ {
+ for ( int i = 0; i < mappers.length; i++ )
+ {
+ name = mappers[i].getMappedFileName( name );
+ }
+ }
+ /*
+ * The prefix is applied when creating the resource.
+ * return PrefixFileMapper.getMappedFileName( getPrefix(), name );
+ */
+ return name;
+ }
+
+ public long getLastModified()
+ throws IOException
+ {
+ return src.getLastModified();
+ }
+
+ public void setDefaultAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode )
+ {
+ defaultFileAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, fileMode );
+ defaultFileAttributes.setOctalMode( fileMode );
+
+ defaultDirAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, dirMode );
+ defaultDirAttributes.setOctalMode( dirMode );
+ }
+
+ public void setOverrideAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode )
+ {
+ overrideFileAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, fileMode );
+
+ overrideDirAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, dirMode );
+ }
+}
\ No newline at end of file
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceCollection.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceCollection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceWithAttributes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceWithAttributes.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceWithAttributes.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceWithAttributes.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,76 @@
+package org.apache.geronimo.system.plugin.plexus.io.resources.proxy;
+
+/*
+ * Copyright 2007 The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.geronimo.system.plugin.plexus.io.resources.AbstractPlexusIoResourceWithAttributes;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResourceWithAttributes;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class PlexusIoProxyResourceWithAttributes
+ extends AbstractPlexusIoResourceWithAttributes
+{
+
+ private final PlexusIoResourceWithAttributes src;
+
+ public PlexusIoProxyResourceWithAttributes( PlexusIoResourceWithAttributes plexusIoResource )
+ {
+ this.src = plexusIoResource;
+ setName( src.getName() );
+ setAttributes( src.getAttributes() );
+ }
+
+ public long getLastModified()
+ {
+ return src.getLastModified();
+ }
+
+ public long getSize()
+ {
+ return src.getSize();
+ }
+
+ public boolean isDirectory()
+ {
+ return src.isDirectory();
+ }
+
+ public boolean isExisting()
+ {
+ return src.isExisting();
+ }
+
+ public boolean isFile()
+ {
+ return src.isFile();
+ }
+
+ public URL getURL()
+ throws IOException
+ {
+ return src.getURL();
+ }
+
+ public InputStream getContents()
+ throws IOException
+ {
+ return src.getContents();
+ }
+
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceWithAttributes.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceWithAttributes.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/resources/proxy/PlexusIoProxyResourceWithAttributes.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/AbstractScanner.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/AbstractScanner.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/AbstractScanner.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/AbstractScanner.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,434 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+
+import java.io.File;
+
+public abstract class AbstractScanner
+ implements Scanner
+{
+ /**
+ * Patterns which should be excluded by default, like SCM files
+ * <ul>
+ * <li>Misc: **/*~, **/#*#, **/.#*, **/%*%, **/._* </li>
+ * <li>CVS: **/CVS, **/CVS/**, **/.cvsignore</li>
+ * <li>RCS: **/RCS, **/RCS/**</li>
+ * <li>SCCS: **/SCCS, **/SCCS/**</li>
+ * <li>VSSercer: **/vssver.scc</li>
+ * <li>SVN: **/.svn, **/.svn/**</li>
+ * <li>GNU: **/.arch-ids, **/.arch-ids/**</li>
+ * <li>Bazaar: **/.bzr, **/.bzr/**</li>
+ * <li>SurroundSCM: **/.MySCMServerInfo</li>
+ * <li>Mac: **/.DS_Store</li>
+ * <li>Serena Dimension: **/.metadata, **/.metadata/**</li>
+ * <li>Mercurial: **/.hg, **/.hg/**</li>
+ * <li>GIT: **/.git, **/.git/**</li>
+ * <li>Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, **/ChangeSet/**</li>
+ * <li>Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, **/.darcsrepo/****/-darcs-backup*, **/.darcs-temp-mail
+ * </ul>
+ *
+ * @see #addDefaultExcludes()
+ */
+ public static final String[] DEFAULTEXCLUDES = {
+ // Miscellaneous typical temporary files
+ "**/*~",
+ "**/#*#",
+ "**/.#*",
+ "**/%*%",
+ "**/._*",
+
+ // CVS
+ "**/CVS",
+ "**/CVS/**",
+ "**/.cvsignore",
+
+ // RCS
+ "**/RCS",
+ "**/RCS/**",
+
+ // SCCS
+ "**/SCCS",
+ "**/SCCS/**",
+
+ // Visual SourceSafe
+ "**/vssver.scc",
+
+ // Subversion
+ "**/.svn",
+ "**/.svn/**",
+
+ // Arch
+ "**/.arch-ids",
+ "**/.arch-ids/**",
+
+ //Bazaar
+ "**/.bzr",
+ "**/.bzr/**",
+
+ //SurroundSCM
+ "**/.MySCMServerInfo",
+
+ // Mac
+ "**/.DS_Store",
+
+ // Serena Dimensions Version 10
+ "**/.metadata",
+ "**/.metadata/**",
+
+ // Mercurial
+ "**/.hg",
+ "**/.hg/**",
+
+ // git
+ "**/.git",
+ "**/.git/**",
+
+ // BitKeeper
+ "**/BitKeeper",
+ "**/BitKeeper/**",
+ "**/ChangeSet",
+ "**/ChangeSet/**",
+
+ // darcs
+ "**/_darcs",
+ "**/_darcs/**",
+ "**/.darcsrepo",
+ "**/.darcsrepo/**",
+ "**/-darcs-backup*",
+ "**/.darcs-temp-mail"
+ };
+
+ /** The patterns for the files to be included. */
+ protected String[] includes;
+
+ /** The patterns for the files to be excluded. */
+ protected String[] excludes;
+
+ /**
+ * Whether or not the file system should be treated as a case sensitive
+ * one.
+ */
+ protected boolean isCaseSensitive = true;
+
+ /**
+ * Sets whether or not the file system should be regarded as case sensitive.
+ *
+ * @param isCaseSensitive whether or not the file system should be
+ * regarded as a case sensitive one
+ */
+ public void setCaseSensitive( boolean isCaseSensitive )
+ {
+ this.isCaseSensitive = isCaseSensitive;
+ }
+
+ /**
+ * Tests whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ * <p>
+ * This is not a general purpose test and should only be used if you
+ * can live with false positives. For example, <code>pattern=**\a</code>
+ * and <code>str=b</code> will yield <code>true</code>.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ *
+ * @return whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ */
+ protected static boolean matchPatternStart( String pattern, String str )
+ {
+ return SelectorUtils.matchPatternStart( pattern, str );
+ }
+
+ /**
+ * Tests whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ * <p>
+ * This is not a general purpose test and should only be used if you
+ * can live with false positives. For example, <code>pattern=**\a</code>
+ * and <code>str=b</code> will yield <code>true</code>.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ * @param isCaseSensitive Whether or not matching should be performed
+ * case sensitively.
+ *
+ * @return whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ */
+ protected static boolean matchPatternStart( String pattern, String str,
+ boolean isCaseSensitive )
+ {
+ return SelectorUtils.matchPatternStart( pattern, str, isCaseSensitive );
+ }
+
+ /**
+ * Tests whether or not a given path matches a given pattern.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ *
+ * @return <code>true</code> if the pattern matches against the string,
+ * or <code>false</code> otherwise.
+ */
+ protected static boolean matchPath( String pattern, String str )
+ {
+ return SelectorUtils.matchPath( pattern, str );
+ }
+
+ /**
+ * Tests whether or not a given path matches a given pattern.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ * @param isCaseSensitive Whether or not matching should be performed
+ * case sensitively.
+ *
+ * @return <code>true</code> if the pattern matches against the string,
+ * or <code>false</code> otherwise.
+ */
+ protected static boolean matchPath( String pattern, String str,
+ boolean isCaseSensitive )
+ {
+ return SelectorUtils.matchPath( pattern, str, isCaseSensitive );
+ }
+
+ /**
+ * Tests whether or not a string matches against a pattern.
+ * The pattern may contain two special characters:<br>
+ * '*' means zero or more characters<br>
+ * '?' means one and only one character
+ *
+ * @param pattern The pattern to match against.
+ * Must not be <code>null</code>.
+ * @param str The string which must be matched against the pattern.
+ * Must not be <code>null</code>.
+ *
+ * @return <code>true</code> if the string matches against the pattern,
+ * or <code>false</code> otherwise.
+ */
+ public static boolean match( String pattern, String str )
+ {
+ return SelectorUtils.match( pattern, str );
+ }
+
+ /**
+ * Tests whether or not a string matches against a pattern.
+ * The pattern may contain two special characters:<br>
+ * '*' means zero or more characters<br>
+ * '?' means one and only one character
+ *
+ * @param pattern The pattern to match against.
+ * Must not be <code>null</code>.
+ * @param str The string which must be matched against the pattern.
+ * Must not be <code>null</code>.
+ * @param isCaseSensitive Whether or not matching should be performed
+ * case sensitively.
+ *
+ *
+ * @return <code>true</code> if the string matches against the pattern,
+ * or <code>false</code> otherwise.
+ */
+ protected static boolean match( String pattern, String str,
+ boolean isCaseSensitive )
+ {
+ return SelectorUtils.match( pattern, str, isCaseSensitive );
+ }
+
+
+ /**
+ * Sets the list of include patterns to use. All '/' and '\' characters
+ * are replaced by <code>File.separatorChar</code>, so the separator used
+ * need not match <code>File.separatorChar</code>.
+ * <p>
+ * When a pattern ends with a '/' or '\', "**" is appended.
+ *
+ * @param includes A list of include patterns.
+ * May be <code>null</code>, indicating that all files
+ * should be included. If a non-<code>null</code>
+ * list is given, all elements must be
+ * non-<code>null</code>.
+ */
+ public void setIncludes( String[] includes )
+ {
+ if ( includes == null )
+ {
+ this.includes = null;
+ }
+ else
+ {
+ this.includes = new String[includes.length];
+ for ( int i = 0; i < includes.length; i++ )
+ {
+ String pattern = includes[i].trim();
+ if ( !pattern.startsWith( SelectorUtils.REGEX_HANDLER_PREFIX ) )
+ {
+ pattern = pattern.replace( File.separatorChar == '/' ? '\\' : '/', File.separatorChar );
+ }
+
+ if ( pattern.endsWith( File.separator ) )
+ {
+ pattern += "**";
+ }
+
+ this.includes[i] = pattern;
+ }
+ }
+ }
+
+ /**
+ * Sets the list of exclude patterns to use. All '/' and '\' characters
+ * are replaced by <code>File.separatorChar</code>, so the separator used
+ * need not match <code>File.separatorChar</code>.
+ * <p>
+ * When a pattern ends with a '/' or '\', "**" is appended.
+ *
+ * @param excludes A list of exclude patterns.
+ * May be <code>null</code>, indicating that no files
+ * should be excluded. If a non-<code>null</code> list is
+ * given, all elements must be non-<code>null</code>.
+ */
+ public void setExcludes( String[] excludes )
+ {
+ if ( excludes == null )
+ {
+ this.excludes = null;
+ }
+ else
+ {
+ this.excludes = new String[excludes.length];
+ for ( int i = 0; i < excludes.length; i++ )
+ {
+ String pattern = excludes[i].trim();
+ if ( !pattern.startsWith( SelectorUtils.REGEX_HANDLER_PREFIX ) )
+ {
+ pattern = pattern.replace( File.separatorChar == '/' ? '\\' : '/', File.separatorChar );
+ }
+
+ if ( pattern.endsWith( File.separator ) )
+ {
+ pattern += "**";
+ }
+
+ this.excludes[i] = pattern;
+ }
+ }
+ }
+
+
+ /**
+ * Tests whether or not a name matches against at least one include
+ * pattern.
+ *
+ * @param name The name to match. Must not be <code>null</code>.
+ * @return <code>true</code> when the name matches against at least one
+ * include pattern, or <code>false</code> otherwise.
+ */
+ protected boolean isIncluded( String name )
+ {
+ for ( int i = 0; i < includes.length; i++ )
+ {
+ if ( matchPath( includes[i], name, isCaseSensitive ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Tests whether or not a name matches the start of at least one include
+ * pattern.
+ *
+ * @param name The name to match. Must not be <code>null</code>.
+ * @return <code>true</code> when the name matches against the start of at
+ * least one include pattern, or <code>false</code> otherwise.
+ */
+ protected boolean couldHoldIncluded( String name )
+ {
+ for ( int i = 0; i < includes.length; i++ )
+ {
+ if ( matchPatternStart( includes[i], name, isCaseSensitive ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Tests whether or not a name matches against at least one exclude
+ * pattern.
+ *
+ * @param name The name to match. Must not be <code>null</code>.
+ * @return <code>true</code> when the name matches against at least one
+ * exclude pattern, or <code>false</code> otherwise.
+ */
+ protected boolean isExcluded( String name )
+ {
+ for ( int i = 0; i < excludes.length; i++ )
+ {
+ if ( matchPath( excludes[i], name, isCaseSensitive ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Adds default exclusions to the current exclusions set.
+ */
+ public void addDefaultExcludes()
+ {
+ int excludesLength = excludes == null ? 0 : excludes.length;
+ String[] newExcludes;
+ newExcludes = new String[excludesLength + DEFAULTEXCLUDES.length];
+ if ( excludesLength > 0 )
+ {
+ System.arraycopy( excludes, 0, newExcludes, 0, excludesLength );
+ }
+ for ( int i = 0; i < DEFAULTEXCLUDES.length; i++ )
+ {
+ newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i];
+ }
+ excludes = newExcludes;
+ }
+
+ protected void setupDefaultFilters()
+ {
+ if ( includes == null )
+ {
+ // No includes supplied, so set it to 'matches all'
+ includes = new String[1];
+ includes[0] = "**";
+ }
+ if ( excludes == null )
+ {
+ excludes = new String[0];
+ }
+ }
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/AbstractScanner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/AbstractScanner.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/AbstractScanner.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Base64.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Base64.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Base64.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Base64.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,509 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * Provides Base64 encoding and decoding as defined by RFC 2045.
+ *
+ * <p>This class implements section <cite>6.8. Base64 Content-Transfer-Encoding</cite>
+ * from RFC 2045 <cite>Multipurpose Internet Mail Extensions (MIME) Part One:
+ * Format of Internet Message Bodies</cite> by Freed and Borenstein.</p>
+ *
+ * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
+ * @author Apache Software Foundation
+ * @since 1.0-dev
+ * @version $Id: Base64.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class Base64 {
+
+ //
+ // Source Id: Base64.java 161350 2005-04-14 20:39:46Z ggregory
+ //
+
+ /**
+ * Chunk size per RFC 2045 section 6.8.
+ *
+ * <p>The {@value} character limit does not count the trailing CRLF, but counts
+ * all other characters, including any equal signs.</p>
+ *
+ * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 6.8</a>
+ */
+ static final int CHUNK_SIZE = 76;
+
+ /**
+ * Chunk separator per RFC 2045 section 2.1.
+ *
+ * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
+ */
+ static final byte[] CHUNK_SEPARATOR = "\r\n".getBytes();
+
+ /**
+ * The base length.
+ */
+ static final int BASELENGTH = 255;
+
+ /**
+ * Lookup length.
+ */
+ static final int LOOKUPLENGTH = 64;
+
+ /**
+ * Used to calculate the number of bits in a byte.
+ */
+ static final int EIGHTBIT = 8;
+
+ /**
+ * Used when encoding something which has fewer than 24 bits.
+ */
+ static final int SIXTEENBIT = 16;
+
+ /**
+ * Used to determine how many bits data contains.
+ */
+ static final int TWENTYFOURBITGROUP = 24;
+
+ /**
+ * Used to get the number of Quadruples.
+ */
+ static final int FOURBYTE = 4;
+
+ /**
+ * Used to test the sign of a byte.
+ */
+ static final int SIGN = -128;
+
+ /**
+ * Byte used to pad output.
+ */
+ static final byte PAD = (byte) '=';
+
+ /**
+ * Contains the Base64 values <code>0</code> through <code>63</code> accessed by using character encodings as
+ * indices.
+ * <p>
+ * For example, <code>base64Alphabet['+']</code> returns <code>62</code>.
+ * </p>
+ * <p>
+ * The value of undefined encodings is <code>-1</code>.
+ * </p>
+ */
+ private static byte[] base64Alphabet = new byte[BASELENGTH];
+
+ /**
+ * <p>
+ * Contains the Base64 encodings <code>A</code> through <code>Z</code>, followed by <code>a</code> through
+ * <code>z</code>, followed by <code>0</code> through <code>9</code>, followed by <code>+</code>, and
+ * <code>/</code>.
+ * </p>
+ * <p>
+ * This array is accessed by using character values as indices.
+ * </p>
+ * <p>
+ * For example, <code>lookUpBase64Alphabet[62] </code> returns <code>'+'</code>.
+ * </p>
+ */
+ private static byte[] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];
+
+ // Populating the lookup and character arrays
+ static {
+ for (int i = 0; i < BASELENGTH; i++) {
+ base64Alphabet[i] = (byte) -1;
+ }
+ for (int i = 'Z'; i >= 'A'; i--) {
+ base64Alphabet[i] = (byte) (i - 'A');
+ }
+ for (int i = 'z'; i >= 'a'; i--) {
+ base64Alphabet[i] = (byte) (i - 'a' + 26);
+ }
+ for (int i = '9'; i >= '0'; i--) {
+ base64Alphabet[i] = (byte) (i - '0' + 52);
+ }
+
+ base64Alphabet['+'] = 62;
+ base64Alphabet['/'] = 63;
+
+ for (int i = 0; i <= 25; i++) {
+ lookUpBase64Alphabet[i] = (byte) ('A' + i);
+ }
+
+ for (int i = 26, j = 0; i <= 51; i++, j++) {
+ lookUpBase64Alphabet[i] = (byte) ('a' + j);
+ }
+
+ for (int i = 52, j = 0; i <= 61; i++, j++) {
+ lookUpBase64Alphabet[i] = (byte) ('0' + j);
+ }
+
+ lookUpBase64Alphabet[62] = (byte) '+';
+ lookUpBase64Alphabet[63] = (byte) '/';
+ }
+
+ /**
+ * Returns whether or not the <code>octect</code> is in the base 64 alphabet.
+ *
+ * @param octect The value to test
+ * @return <code>true</code> if the value is defined in the the base 64 alphabet, <code>false</code> otherwise.
+ */
+ private static boolean isBase64(byte octect) {
+ if (octect == PAD) {
+ return true;
+ } else if (octect < 0 || base64Alphabet[octect] == -1) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Tests a given byte array to see if it contains
+ * only valid characters within the Base64 alphabet.
+ *
+ * @param arrayOctect byte array to test
+ * @return <code>true</code> if all bytes are valid characters in the Base64
+ * alphabet or if the byte array is empty; false, otherwise
+ */
+ public static boolean isArrayByteBase64(byte[] arrayOctect) {
+
+ arrayOctect = discardWhitespace(arrayOctect);
+
+ int length = arrayOctect.length;
+ if (length == 0) {
+ // shouldn't a 0 length array be valid base64 data?
+ // return false;
+ return true;
+ }
+ for (int i = 0; i < length; i++) {
+ if (!isBase64(arrayOctect[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Encodes binary data using the base64 algorithm but
+ * does not chunk the output.
+ *
+ * @param binaryData binary data to encode
+ * @return Base64 characters
+ */
+ public static byte[] encodeBase64(byte[] binaryData) {
+ return encodeBase64(binaryData, false);
+ }
+
+ /**
+ * Encodes binary data using the base64 algorithm and chunks
+ * the encoded output into 76 character blocks
+ *
+ * @param binaryData binary data to encode
+ * @return Base64 characters chunked in 76 character blocks
+ */
+ public static byte[] encodeBase64Chunked(byte[] binaryData) {
+ return encodeBase64(binaryData, true);
+ }
+
+
+ /**
+ * Decodes a byte[] containing containing
+ * characters in the Base64 alphabet.
+ *
+ * @param pArray A byte array containing Base64 character data
+ * @return a byte array containing binary data
+ */
+ public byte[] decode(byte[] pArray) {
+ return decodeBase64(pArray);
+ }
+
+ /**
+ * Encodes binary data using the base64 algorithm, optionally
+ * chunking the output into 76 character blocks.
+ *
+ * @param binaryData Array containing binary data to encode.
+ * @param isChunked if <code>true</code> this encoder will chunk
+ * the base64 output into 76 character blocks
+ * @return Base64-encoded data.
+ */
+ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
+ int lengthDataBits = binaryData.length * EIGHTBIT;
+ int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP;
+ int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP;
+ byte encodedData[] = null;
+ int encodedDataLength = 0;
+ int nbrChunks = 0;
+
+ if (fewerThan24bits != 0) {
+ //data not divisible by 24 bit
+ encodedDataLength = (numberTriplets + 1) * 4;
+ } else {
+ // 16 or 8 bit
+ encodedDataLength = numberTriplets * 4;
+ }
+
+ // If the output is to be "chunked" into 76 character sections,
+ // for compliance with RFC 2045 MIME, then it is important to
+ // allow for extra length to account for the separator(s)
+ if (isChunked) {
+
+ nbrChunks =
+ (CHUNK_SEPARATOR.length == 0 ? 0 : (int) Math.ceil((float) encodedDataLength / CHUNK_SIZE));
+ encodedDataLength += nbrChunks * CHUNK_SEPARATOR.length;
+ }
+
+ encodedData = new byte[encodedDataLength];
+
+ byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0;
+
+ int encodedIndex = 0;
+ int dataIndex = 0;
+ int i = 0;
+ int nextSeparatorIndex = CHUNK_SIZE;
+ int chunksSoFar = 0;
+
+ //log.debug("number of triplets = " + numberTriplets);
+ for (i = 0; i < numberTriplets; i++) {
+ dataIndex = i * 3;
+ b1 = binaryData[dataIndex];
+ b2 = binaryData[dataIndex + 1];
+ b3 = binaryData[dataIndex + 2];
+
+ //log.debug("b1= " + b1 +", b2= " + b2 + ", b3= " + b3);
+
+ l = (byte) (b2 & 0x0f);
+ k = (byte) (b1 & 0x03);
+
+ byte val1 =
+ ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
+ byte val2 =
+ ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
+ byte val3 =
+ ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
+
+ encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
+ //log.debug( "val2 = " + val2 );
+ //log.debug( "k4 = " + (k<<4) );
+ //log.debug( "vak = " + (val2 | (k<<4)) );
+ encodedData[encodedIndex + 1] =
+ lookUpBase64Alphabet[val2 | (k << 4)];
+ encodedData[encodedIndex + 2] =
+ lookUpBase64Alphabet[(l << 2) | val3];
+ encodedData[encodedIndex + 3] = lookUpBase64Alphabet[b3 & 0x3f];
+
+ encodedIndex += 4;
+
+ // If we are chunking, let's put a chunk separator down.
+ if (isChunked) {
+ // this assumes that CHUNK_SIZE % 4 == 0
+ if (encodedIndex == nextSeparatorIndex) {
+ System.arraycopy(
+ CHUNK_SEPARATOR,
+ 0,
+ encodedData,
+ encodedIndex,
+ CHUNK_SEPARATOR.length);
+ chunksSoFar++;
+ nextSeparatorIndex =
+ (CHUNK_SIZE * (chunksSoFar + 1)) +
+ (chunksSoFar * CHUNK_SEPARATOR.length);
+ encodedIndex += CHUNK_SEPARATOR.length;
+ }
+ }
+ }
+
+ // form integral number of 6-bit groups
+ dataIndex = i * 3;
+
+ if (fewerThan24bits == EIGHTBIT) {
+ b1 = binaryData[dataIndex];
+ k = (byte) (b1 & 0x03);
+ //log.debug("b1=" + b1);
+ //log.debug("b1<<2 = " + (b1>>2) );
+ byte val1 =
+ ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
+ encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
+ encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4];
+ encodedData[encodedIndex + 2] = PAD;
+ encodedData[encodedIndex + 3] = PAD;
+ } else if (fewerThan24bits == SIXTEENBIT) {
+
+ b1 = binaryData[dataIndex];
+ b2 = binaryData[dataIndex + 1];
+ l = (byte) (b2 & 0x0f);
+ k = (byte) (b1 & 0x03);
+
+ byte val1 =
+ ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
+ byte val2 =
+ ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
+
+ encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
+ encodedData[encodedIndex + 1] =
+ lookUpBase64Alphabet[val2 | (k << 4)];
+ encodedData[encodedIndex + 2] = lookUpBase64Alphabet[l << 2];
+ encodedData[encodedIndex + 3] = PAD;
+ }
+
+ if (isChunked) {
+ // we also add a separator to the end of the final chunk.
+ if (chunksSoFar < nbrChunks) {
+ System.arraycopy(
+ CHUNK_SEPARATOR,
+ 0,
+ encodedData,
+ encodedDataLength - CHUNK_SEPARATOR.length,
+ CHUNK_SEPARATOR.length);
+ }
+ }
+
+ return encodedData;
+ }
+
+ /**
+ * Decodes Base64 data into octects
+ *
+ * @param base64Data Byte array containing Base64 data
+ * @return Array containing decoded data.
+ */
+ public static byte[] decodeBase64(byte[] base64Data) {
+ // RFC 2045 requires that we discard ALL non-Base64 characters
+ base64Data = discardNonBase64(base64Data);
+
+ // handle the edge case, so we don't have to worry about it later
+ if (base64Data.length == 0) {
+ return new byte[0];
+ }
+
+ int numberQuadruple = base64Data.length / FOURBYTE;
+ byte decodedData[] = null;
+ byte b1 = 0, b2 = 0, b3 = 0, b4 = 0, marker0 = 0, marker1 = 0;
+
+ // Throw away anything not in base64Data
+
+ int encodedIndex = 0;
+ int dataIndex = 0;
+ {
+ // this sizes the output array properly - rlw
+ int lastData = base64Data.length;
+ // ignore the '=' padding
+ while (base64Data[lastData - 1] == PAD) {
+ if (--lastData == 0) {
+ return new byte[0];
+ }
+ }
+ decodedData = new byte[lastData - numberQuadruple];
+ }
+
+ for (int i = 0; i < numberQuadruple; i++) {
+ dataIndex = i * 4;
+ marker0 = base64Data[dataIndex + 2];
+ marker1 = base64Data[dataIndex + 3];
+
+ b1 = base64Alphabet[base64Data[dataIndex]];
+ b2 = base64Alphabet[base64Data[dataIndex + 1]];
+
+ if (marker0 != PAD && marker1 != PAD) {
+ //No PAD e.g 3cQl
+ b3 = base64Alphabet[marker0];
+ b4 = base64Alphabet[marker1];
+
+ decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
+ decodedData[encodedIndex + 1] =
+ (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
+ decodedData[encodedIndex + 2] = (byte) (b3 << 6 | b4);
+ } else if (marker0 == PAD) {
+ //Two PAD e.g. 3c[Pad][Pad]
+ decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
+ } else if (marker1 == PAD) {
+ //One PAD e.g. 3cQ[Pad]
+ b3 = base64Alphabet[marker0];
+
+ decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
+ decodedData[encodedIndex + 1] =
+ (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
+ }
+ encodedIndex += 3;
+ }
+ return decodedData;
+ }
+
+ /**
+ * Discards any whitespace from a base-64 encoded block.
+ *
+ * @param data The base-64 encoded data to discard the whitespace
+ * from.
+ * @return The data, less whitespace (see RFC 2045).
+ */
+ static byte[] discardWhitespace(byte[] data) {
+ byte groomedData[] = new byte[data.length];
+ int bytesCopied = 0;
+
+ for (int i = 0; i < data.length; i++) {
+ switch (data[i]) {
+ case (byte) ' ' :
+ case (byte) '\n' :
+ case (byte) '\r' :
+ case (byte) '\t' :
+ break;
+ default:
+ groomedData[bytesCopied++] = data[i];
+ }
+ }
+
+ byte packedData[] = new byte[bytesCopied];
+
+ System.arraycopy(groomedData, 0, packedData, 0, bytesCopied);
+
+ return packedData;
+ }
+
+ /**
+ * Discards any characters outside of the base64 alphabet, per
+ * the requirements on page 25 of RFC 2045 - "Any characters
+ * outside of the base64 alphabet are to be ignored in base64
+ * encoded data."
+ *
+ * @param data The base-64 encoded data to groom
+ * @return The data, less non-base64 characters (see RFC 2045).
+ */
+ static byte[] discardNonBase64(byte[] data) {
+ byte groomedData[] = new byte[data.length];
+ int bytesCopied = 0;
+
+ for (int i = 0; i < data.length; i++) {
+ if (isBase64(data[i])) {
+ groomedData[bytesCopied++] = data[i];
+ }
+ }
+
+ byte packedData[] = new byte[bytesCopied];
+
+ System.arraycopy(groomedData, 0, packedData, 0, bytesCopied);
+
+ return packedData;
+ }
+
+ /**
+ * Encodes a byte[] containing binary data, into a byte[] containing
+ * characters in the Base64 alphabet.
+ *
+ * @param pArray a byte array containing binary data
+ * @return A byte array containing only Base64 character data
+ */
+ public byte[] encode(byte[] pArray) {
+ return encodeBase64(pArray, false);
+ }
+
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Base64.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Base64.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Base64.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CachedMap.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CachedMap.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CachedMap.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CachedMap.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,407 @@
+/*
+ * J.A.D.E. Java(TM) Addition to Default Environment.
+ * Latest release available at http://jade.dautelle.com/
+ * This class is public domain (not copyrighted).
+ */
+package org.apache.geronimo.system.plugin.plexus.util;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * <p> This class provides cache access to <code>Map</code> collections.</p>
+ *
+ * <p> Instance of this class can be used as "proxy" for any collection
+ * implementing the <code>java.util.Map</code> interface.</p>
+ *
+ * <p> Typically, {@link CachedMap} are used to accelerate access to
+ * large collections when the access to the collection is not evenly
+ * distributed (associative cache). The performance gain is about
+ * 50% for the fastest hash map collections (e.g. {@link FastMap}).
+ * For slower collections such as <code>java.util.TreeMap</code>,
+ * non-resizable {@link FastMap} (real-time) or database access,
+ * performance can be of several orders of magnitude.</p>
+ *
+ * <p> <b>Note:</b> The keys used to access elements of a {@link CachedMap} do
+ * not need to be immutable as they are not stored in the cache
+ * (only keys specified by the {@link #put} method are).
+ * In other words, access can be performed using mutable keys as long
+ * as these keys can be compared for equality with the real map's keys
+ * (e.g. same <code>hashCode</code> values).</p>
+ *
+ * <p> This implementation is not synchronized. Multiple threads accessing
+ * or modifying the collection must be synchronized externally.</p>
+ *
+ * <p><i> This class is <b>public domain</b> (not copyrighted).</i></p>
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 5.3, October 30, 2003
+ */
+public final class CachedMap implements Map {
+
+ /**
+ * Holds the FastMap backing this collection
+ * (<code>null</code> if generic backing map).
+ */
+ private final FastMap _backingFastMap;
+
+ /**
+ * Holds the generic map backing this collection.
+ */
+ private final Map _backingMap;
+
+ /**
+ * Holds the keys of the backing map (key-to-key mapping).
+ * (<code>null</code> if FastMap backing map).
+ */
+ private final FastMap _keysMap;
+
+ /**
+ * Holds the cache's mask (capacity - 1).
+ */
+ private final int _mask;
+
+ /**
+ * Holds the keys being cached.
+ */
+ private final Object[] _keys;
+
+ /**
+ * Holds the values being cached.
+ */
+ private final Object[] _values;
+
+ /**
+ * Creates a cached map backed by a {@link FastMap}.
+ * The default cache size and map capacity is set to <code>256</code>
+ * entries.
+ */
+ public CachedMap() {
+ this(256, new FastMap());
+ }
+
+ /**
+ * Creates a cached map backed by a {@link FastMap} and having the
+ * specified cache size.
+ *
+ * @param cacheSize the cache size, the actual cache size is the
+ * first power of 2 greater or equal to <code>cacheSize</code>.
+ * This is also the initial capacity of the backing map.
+ */
+ public CachedMap(int cacheSize) {
+ this(cacheSize, new FastMap(cacheSize));
+ }
+
+ /**
+ * Creates a cached map backed by the specified map and having the specified
+ * cache size. In order to maitain cache veracity, it is critical
+ * that <b>all</b> update to the backing map is accomplished through the
+ * {@link CachedMap} instance; otherwise {@link #flush} has to be called.
+ *
+ * @param cacheSize the cache size, the actual cache size is the
+ * first power of 2 greater or equal to <code>cacheSize</code>.
+ * @param backingMap the backing map to be "wrapped" in a cached map.
+ */
+ public CachedMap(int cacheSize, Map backingMap) {
+
+ // Find a power of 2 >= minimalCache
+ int actualCacheSize = 1;
+ while (actualCacheSize < cacheSize) {
+ actualCacheSize <<= 1;
+ }
+
+ // Sets up cache.
+ _keys = new Object[actualCacheSize];
+ _values = new Object[actualCacheSize];
+ _mask = actualCacheSize - 1;
+
+ // Sets backing map references.
+ if (backingMap instanceof FastMap) {
+ _backingFastMap = (FastMap)backingMap;
+ _backingMap = _backingFastMap;
+ _keysMap = null;
+ } else {
+ _backingFastMap = null;
+ _backingMap = backingMap;
+ _keysMap = new FastMap(backingMap.size());
+ for (Iterator i= backingMap.keySet().iterator(); i.hasNext();) {
+ Object key = i.next();
+ _keysMap.put(key, key);
+ }
+ }
+ }
+
+ /**
+ * Returns the actual cache size.
+ *
+ * @return the cache size (power of 2).
+ */
+ public int getCacheSize() {
+ return _keys.length;
+ }
+
+ /**
+ * Returns the backing map. If the backing map is modified directly,
+ * this {@link CachedMap} has to be flushed.
+ *
+ * @return the backing map.
+ * @see #flush
+ */
+ public Map getBackingMap() {
+ return (_backingFastMap != null) ? _backingFastMap : _backingMap;
+ }
+
+ /**
+ * Flushes the key/value pairs being cached. This method should be called
+ * if the backing map is externally modified.
+ */
+ public void flush() {
+ for (int i=0; i < _keys.length; i++) {
+ _keys[i] = null;
+ _values[i] = null;
+ }
+
+ if (_keysMap != null) {
+ // Re-populates keys from backing map.
+ for (Iterator i= _backingMap.keySet().iterator(); i.hasNext();) {
+ Object key = i.next();
+ _keysMap.put(key, key);
+ }
+ }
+ }
+
+ /**
+ * Returns the value to which this map maps the specified key.
+ * First, the cache is being checked, then if the cache does not contains
+ * the specified key, the backing map is accessed and the key/value
+ * pair is stored in the cache.
+ *
+ * @param key the key whose associated value is to be returned.
+ * @return the value to which this map maps the specified key, or
+ * <code>null</code> if the map contains no mapping for this key.
+ * @throws ClassCastException if the key is of an inappropriate type for
+ * the backing map (optional).
+ * @throws NullPointerException if the key is <code>null</code>.
+ */
+ public Object get(Object key) {
+ int index = key.hashCode() & _mask;
+ return key.equals(_keys[index]) ?
+ _values[index] : getCacheMissed(key, index);
+ }
+ private Object getCacheMissed(Object key, int index) {
+ if (_backingFastMap != null) {
+ Map.Entry entry = _backingFastMap.getEntry(key);
+ if (entry != null) {
+ _keys[index] = entry.getKey();
+ Object value = entry.getValue();
+ _values[index] = value;
+ return value;
+ } else {
+ return null;
+ }
+ } else { // Generic backing map.
+ Object mapKey = _keysMap.get(key);
+ if (mapKey != null) {
+ _keys[index] = mapKey;
+ Object value = _backingMap.get(key);
+ _values[index] = value;
+ return value;
+ } else {
+ return null;
+ }
+ }
+ }
+
+ /**
+ * Associates the specified value with the specified key in this map.
+ *
+ * @param key the key with which the specified value is to be associated.
+ * @param value the value to be associated with the specified key.
+ * @return the previous value associated with specified key, or
+ * <code>null</code> if there was no mapping for the key.
+ * @throws UnsupportedOperationException if the <code>put</code> operation
+ * is not supported by the backing map.
+ * @throws ClassCastException if the class of the specified key or value
+ * prevents it from being stored in this map.
+ * @throws IllegalArgumentException if some aspect of this key or value
+ * prevents it from being stored in this map.
+ * @throws NullPointerException if the key is <code>null</code>.
+ */
+ public Object put(Object key, Object value) {
+ // Updates the cache.
+ int index = key.hashCode() & _mask;
+ if (key.equals(_keys[index]) ) {
+ _values[index] = value;
+ } else if (_keysMap != null) { // Possibly a new key.
+ _keysMap.put(key, key);
+ }
+
+ // Updates the backing map.
+ return _backingMap.put(key, value);
+ }
+
+ /**
+ * Removes the mapping for this key from this map if it is present.
+ *
+ * @param key key whose mapping is to be removed from the map.
+ * @return previous value associated with specified key,
+ * or <code>null</code> if there was no mapping for key.
+ * @throws ClassCastException if the key is of an inappropriate type for
+ * the backing map (optional).
+ * @throws NullPointerException if the key is <code>null</code>.
+ * @throws UnsupportedOperationException if the <code>remove</code> method
+ * is not supported by the backing map.
+ */
+ public Object remove(Object key) {
+ // Removes from cache.
+ int index = key.hashCode() & _mask;
+ if (key.equals(_keys[index]) ) {
+ _keys[index] = null;
+ }
+ // Removes from key map.
+ if (_keysMap != null) {
+ _keysMap.remove(key);
+ }
+ // Removes from backing map.
+ return _backingMap.remove(key);
+ }
+
+ /**
+ * Indicates if this map contains a mapping for the specified key.
+ *
+ * @param key the key whose presence in this map is to be tested.
+ * @return <code>true</code> if this map contains a mapping for the
+ * specified key; <code>false</code> otherwise.
+ */
+ public boolean containsKey(Object key) {
+ // Checks the cache.
+ int index = key.hashCode() & _mask;
+ if (key.equals(_keys[index]) ) {
+ return true;
+ } else { // Checks the backing map.
+ return _backingMap.containsKey(key);
+ }
+ }
+
+ /**
+ * Returns the number of key-value mappings in this map. If the
+ * map contains more than <code>Integer.MAX_VALUE</code> elements,
+ * returns <code>Integer.MAX_VALUE</code>.
+ *
+ * @return the number of key-value mappings in this map.
+ */
+ public int size() {
+ return _backingMap.size();
+ }
+
+ /**
+ * Returns <code>true</code> if this map contains no key-value mappings.
+ *
+ * @return <code>true</code> if this map contains no key-value mappings.
+ */
+ public boolean isEmpty() {
+ return _backingMap.isEmpty();
+ }
+
+ /**
+ * Returns <code>true</code> if this map maps one or more keys to the
+ * specified value.
+ *
+ * @param value value whose presence in this map is to be tested.
+ * @return <code>true</code> if this map maps one or more keys to the
+ * specified value.
+ * @throws ClassCastException if the value is of an inappropriate type for
+ * the backing map (optional).
+ * @throws NullPointerException if the value is <code>null</code> and the
+ * backing map does not not permit <code>null</code> values.
+ */
+ public boolean containsValue(Object value) {
+ return _backingMap.containsValue(value);
+ }
+
+ /**
+ * Copies all of the mappings from the specified map to this map
+ * (optional operation). This method automatically flushes the cache.
+ *
+ * @param map the mappings to be stored in this map.
+ * @throws UnsupportedOperationException if the <code>putAll</code> method
+ * is not supported by the backing map.
+ * @throws ClassCastException if the class of a key or value in the
+ * specified map prevents it from being stored in this map.
+ * @throws IllegalArgumentException some aspect of a key or value in the
+ * specified map prevents it from being stored in this map.
+ * @throws NullPointerException the specified map is <code>null</code>, or
+ * if the backing map does not permit <code>null</code> keys or
+ * values, and the specified map contains <code>null</code> keys or
+ * values.
+ */
+ public void putAll(Map map) {
+ _backingMap.putAll(map);
+ flush();
+ }
+
+ /**
+ * Removes all mappings from this map (optional operation). This method
+ * automatically flushes the cache.
+ *
+ * @throws UnsupportedOperationException if clear is not supported by the
+ * backing map.
+ */
+ public void clear() {
+ _backingMap.clear();
+ flush();
+ }
+
+ /**
+ * Returns an <b>unmodifiable</b> view of the keys contained in this
+ * map.
+ *
+ * @return an unmodifiable view of the keys contained in this map.
+ */
+ public Set keySet() {
+ return Collections.unmodifiableSet(_backingMap.keySet());
+ }
+
+ /**
+ * Returns an <b>unmodifiable</b> view of the values contained in this map.
+ *
+ * @return an unmodifiable view of the values contained in this map.
+ */
+ public Collection values() {
+ return Collections.unmodifiableCollection(_backingMap.values());
+ }
+
+ /**
+ * Returns an <b>unmodifiable</b> view of the mappings contained in this
+ * map. Each element in the returned set is a <code>Map.Entry</code>.
+ *
+ * @return an unmodifiable view of the mappings contained in this map.
+ */
+ public Set entrySet() {
+ return Collections.unmodifiableSet(_backingMap.entrySet());
+ }
+
+
+ /**
+ * Compares the specified object with this map for equality. Returns
+ * <tt>true</tt> if the given object is also a map and the two Maps
+ * represent the same mappings.
+ *
+ * @param o object to be compared for equality with this map.
+ * @return <code>true</code> if the specified object is equal to this map.
+ */
+ public boolean equals(Object o) {
+ return _backingMap.equals(o);
+ }
+
+ /**
+ * Returns the hash code value for this map.
+ *
+ * @return the hash code value for this map.
+ */
+ public int hashCode() {
+ return _backingMap.hashCode();
+ }
+}
\ No newline at end of file
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CachedMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CachedMap.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CachedMap.java
------------------------------------------------------------------------------
svn:mime-type = text/plain