plexus-resources-1.0~alpha7/ 0000755 0001750 0001750 00000000000 12137721314 015500 5 ustar eugene eugene plexus-resources-1.0~alpha7/pom.xml 0000644 0001750 0001750 00000002517 11337603154 017024 0 ustar eugene eugene
4.0.0
org.codehaus.plexus
plexus-components
1.1.17
plexus-resources
1.0-alpha-7
Plexus Resource Component
A component to transparently retrieve resources from the filesystem, classpath or internet.
scm:svn:http://svn.codehaus.org/plexus/plexus-components/tags/plexus-resources-1.0-alpha-7
scm:svn:https://svn.codehaus.org/plexus/plexus-components/tags/plexus-resources-1.0-alpha-7
http://fisheye.codehaus.org/browse/plexus/plexus-components/tags/plexus-resources-1.0-alpha-7
org.codehaus.plexus
plexus-utils
org.codehaus.plexus
plexus-container-default
plexus-resources-1.0~alpha7/src/ 0000755 0001750 0001750 00000000000 12137721314 016267 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/site/ 0000755 0001750 0001750 00000000000 12137721314 017233 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/site/site.xml 0000644 0001750 0001750 00000000417 11253532642 020725 0 ustar eugene eugene
plexus-resources-1.0~alpha7/src/main/ 0000755 0001750 0001750 00000000000 12137721314 017213 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/main/java/ 0000755 0001750 0001750 00000000000 12137721314 020134 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/main/java/org/ 0000755 0001750 0001750 00000000000 12137721314 020723 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/main/java/org/codehaus/ 0000755 0001750 0001750 00000000000 12137721314 022516 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/ 0000755 0001750 0001750 00000000000 12137721314 024036 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/ 0000755 0001750 0001750 00000000000 12137721314 025665 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ 0000755 0001750 0001750 00000000000 12137721314 027133 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/JarHolder.java 0000644 0001750 0001750 00000010724 11247053263 031656 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.codehaus.plexus.resource.PlexusResource;
/**
* A small wrapper around a Jar
*
* @author Dave Bryson
* @author Jason van Zyl
* @version $Id: JarHolder.java 8366 2009-08-31 23:03:15Z jdcasey $
*/
public class JarHolder
{
private String urlpath = null;
private JarFile theJar = null;
private JarURLConnection conn = null;
public JarHolder( String urlpath )
{
this.urlpath = urlpath;
init();
}
public void init()
{
try
{
URL url = new URL( urlpath );
conn = (JarURLConnection) url.openConnection();
conn.setAllowUserInteraction( false );
conn.setDoInput( true );
conn.setDoOutput( false );
conn.connect();
theJar = conn.getJarFile();
}
catch ( IOException ioe )
{
}
}
public void close()
{
try
{
theJar.close();
}
catch ( Exception e )
{
}
theJar = null;
conn = null;
}
public InputStream getResource( String theentry )
throws ResourceNotFoundException
{
InputStream data = null;
try
{
JarEntry entry = theJar.getJarEntry( theentry );
if ( entry != null )
{
data = theJar.getInputStream( entry );
}
}
catch ( Exception fnfe )
{
throw new ResourceNotFoundException( fnfe.getMessage() );
}
return data;
}
public Hashtable getEntries()
{
Hashtable allEntries = new Hashtable( 559 );
Enumeration all = theJar.entries();
while ( all.hasMoreElements() )
{
JarEntry je = (JarEntry) all.nextElement();
// We don't map plain directory entries
if ( !je.isDirectory() )
{
allEntries.put( je.getName(), this.urlpath );
}
}
return allEntries;
}
public String getUrlPath()
{
return urlpath;
}
public PlexusResource getPlexusResource( final String name )
{
final JarEntry entry = theJar.getJarEntry( name );
if ( entry == null )
{
return null;
}
return new PlexusResource()
{
public File getFile()
throws IOException
{
return null;
}
public InputStream getInputStream()
throws IOException
{
return theJar.getInputStream( entry );
}
public String getName()
{
return conn.getURL() + name;
}
public URI getURI()
throws IOException
{
return null;
}
public URL getURL()
throws IOException
{
return new URL( conn.getJarFileURL(), name );
}
};
}
}
././@LongLink 0000000 0000000 0000000 00000000161 00000000000 011563 L ustar root root plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceCreationException.java plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceCreationEx0000644 0001750 0001750 00000003225 11125700135 033423 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/** @author Jason van Zyl */
public class FileResourceCreationException
extends Exception
{
private static final long serialVersionUID = 3203687211821479687L;
public FileResourceCreationException( String string )
{
super( string );
}
public FileResourceCreationException( String string, Throwable throwable )
{
super( string, throwable );
}
public FileResourceCreationException( Throwable throwable )
{
super( throwable );
}
}
././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader.java plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader0000644 0001750 0001750 00000004413 11247053263 033464 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.resource.PlexusResource;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.ArrayList;
/**
* @author Trygve Laugstøl
* @version $Id: AbstractResourceLoader.java 8366 2009-08-31 23:03:15Z jdcasey $
*/
public abstract class AbstractResourceLoader
extends AbstractLogEnabled
implements ResourceLoader
{
/** @configuration */
protected List paths = new ArrayList();
public void addSearchPath( String path )
{
if ( !paths.contains( path ) )
{
paths.add( path );
}
}
public InputStream getResourceAsInputStream( String name )
throws ResourceNotFoundException
{
PlexusResource resource = getResource( name );
try
{
return resource.getInputStream();
}
catch ( IOException e )
{
throw new ResourceIOException( "Failed to open resource " + resource.getName() + ": " + e.getMessage(), e );
}
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceLoader.java plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceLoader.jav0000644 0001750 0001750 00000007725 11247053263 033370 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import org.codehaus.plexus.resource.PlexusResource;
import org.codehaus.plexus.resource.loader.AbstractResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.FileUtils;
/**
* @author Trygve Laugstøl
* @author Jason van Zyl
* @version $Id: FileResourceLoader.java 8366 2009-08-31 23:03:15Z jdcasey $
* @plexus.component role-hint="file" instantiation-strategy="per-lookup"
*/
public class FileResourceLoader
extends AbstractResourceLoader
{
public static final String ID = "file";
// ----------------------------------------------------------------------
// ResourceLoader Implementation
// ----------------------------------------------------------------------
public PlexusResource getResource( String name )
throws ResourceNotFoundException
{
for ( Iterator it = paths.iterator(); it.hasNext(); )
{
String path = (String) it.next();
final File file = new File( path, name );
if ( file.canRead() )
{
return new FilePlexusResource( file );
}
}
File file = new File( name );
if ( file.isAbsolute() && file.canRead() )
{
return new FilePlexusResource( file );
}
throw new ResourceNotFoundException( name );
}
/**
* @deprecated Use {@link org.codehaus.plexus.resource.ResourceManager#getResourceAsFile(PlexusResource )}.
*/
public static File getResourceAsFile( String name, String outputPath, File outputDirectory )
throws FileResourceCreationException
{
File f = new File( name );
if ( f.exists() )
{
if ( outputPath == null )
{
return f;
}
else
{
try
{
File outputFile;
if ( outputDirectory != null )
{
outputFile = new File( outputDirectory, outputPath );
}
else
{
outputFile = new File( outputPath );
}
if ( !outputFile.getParentFile().exists() )
{
outputFile.getParentFile().mkdirs();
}
FileUtils.copyFile( f, outputFile );
return outputFile;
}
catch ( IOException e )
{
throw new FileResourceCreationException( "Cannot create file-based resource.", e );
}
}
}
return null;
}
}
././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011566 L ustar root root plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceNotFoundException.java plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceNotFoundExcept0000644 0001750 0001750 00000003340 10616205343 033472 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* @author Trygve Laugstøl
* @version $Id: ResourceNotFoundException.java 6388 2007-05-02 22:04:19Z jochen $
*/
public class ResourceNotFoundException
extends Exception
{
private static final long serialVersionUID = -566548849252110330L;
public ResourceNotFoundException( String name )
{
super( "Could not find resource '" + name + "'." );
}
public ResourceNotFoundException( String name, Throwable cause )
{
super( "Could not find resource '" + name + "'.", cause );
}
}
plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/JarResourceLoader.java0000644 0001750 0001750 00000012753 11247053263 033363 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.resource.PlexusResource;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author Jason van Zyl
* @plexus.component role-hint="jar" instantiation-strategy="per-lookup"
*/
public class JarResourceLoader
extends AbstractResourceLoader
{
public static final String ID = "jar";
/**
* Maps entries to the parent JAR File (key = the entry *excluding* plain directories, value = the JAR URL).
*/
private Map entryDirectory = new LinkedHashMap( 559 );
/**
* Maps JAR URLs to the actual JAR (key = the JAR URL, value = the JAR).
*/
private Map jarfiles = new LinkedHashMap( 89 );
private boolean initializeCalled;
public void initialize()
throws InitializationException
{
initializeCalled = true;
if ( paths != null )
{
for ( int i = 0; i < paths.size(); i++ )
{
loadJar( (String) paths.get( i ) );
}
}
}
private void loadJar( String path )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "JarResourceLoader : trying to load \"" + path + "\"" );
}
// Check path information
if ( path == null )
{
getLogger().error( "JarResourceLoader : can not load JAR - JAR path is null" );
return;
}
if ( !path.startsWith( "jar:" ) )
{
getLogger().error(
"JarResourceLoader : JAR path must start with jar: -> "
+ "see java.net.JarURLConnection for information" );
return;
}
if ( !path.endsWith( "!/" ) )
{
path += "!/";
}
// Close the jar if it's already open this is useful for a reload
closeJar( path );
// Create a new JarHolder
JarHolder temp = new JarHolder( path );
// Add it's entries to the entryCollection
addEntries( temp.getEntries() );
// Add it to the Jar table
jarfiles.put( temp.getUrlPath(), temp );
}
/**
* Closes a Jar file and set its URLConnection to null.
*/
private void closeJar( String path )
{
if ( jarfiles.containsKey( path ) )
{
JarHolder theJar = (JarHolder) jarfiles.get( path );
theJar.close();
}
}
/**
* Copy all the entries into the entryDirectory. It will overwrite any duplicate keys.
*/
private void addEntries( Map entries )
{
entryDirectory.putAll( entries );
}
/**
* Get an InputStream so that the Runtime can build a template with it.
*
* @param source name of template to get
* @return InputStream containing the template
* @throws ResourceNotFoundException if template not found in the file template path.
*/
public PlexusResource getResource( String source )
throws ResourceNotFoundException
{
if ( !initializeCalled )
{
try
{
initialize();
}
catch ( InitializationException e )
{
throw new ResourceNotFoundException( e.getMessage(), e );
}
}
if ( source == null || source.length() == 0 )
{
throw new ResourceNotFoundException( "Need to have a resource!" );
}
/*
* if a / leads off, then just nip that :)
*/
if ( source.startsWith( "/" ) )
{
source = source.substring( 1 );
}
if ( entryDirectory.containsKey( source ) )
{
String jarurl = (String) entryDirectory.get( source );
final JarHolder holder = (JarHolder) jarfiles.get( jarurl );
if ( holder != null )
{
return holder.getPlexusResource( source );
}
}
throw new ResourceNotFoundException( "JarResourceLoader Error: cannot find resource " + source );
}
public void addSearchPath( String path )
{
if ( !paths.contains( path ) )
{
if ( initializeCalled )
{
loadJar( path );
}
paths.add( path );
}
}
}
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceIOException.java plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceIOException.ja0000644 0001750 0001750 00000003352 11125657060 033352 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* An instance of this class is thrown, if the {@link org.codehaus.plexus.resource.ResourceManager}, or
* {@link ResourceLoader} encounters an {@link java.io.IOException}, which indicates that the resource exists, but
* wasn't accessible.
*/
public class ResourceIOException
extends ResourceNotFoundException
{
private static final long serialVersionUID = 1342518075415496931L;
public ResourceIOException( String name, Throwable cause )
{
super( name, cause );
}
public ResourceIOException( String name )
{
super( name );
}
}
././@LongLink 0000000 0000000 0000000 00000000170 00000000000 011563 L ustar root root plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoader.java plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ThreadContextClasspath0000644 0001750 0001750 00000005024 11254762275 033510 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.net.URL;
import org.codehaus.plexus.resource.PlexusResource;
import org.codehaus.plexus.resource.loader.AbstractResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
/**
* @author Trygve Laugstøl
* @version $Id: ThreadContextClasspathResourceLoader.java 8418 2009-09-18 19:51:25Z bentmann $
* @plexus.component role-hint="classloader"
*/
public class ThreadContextClasspathResourceLoader
extends AbstractResourceLoader
{
public static final String ID = "classloader";
// ----------------------------------------------------------------------
// ResourceLoader Implementation
// ----------------------------------------------------------------------
public PlexusResource getResource( String name )
throws ResourceNotFoundException
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if ( classLoader == null )
{
throw new ResourceNotFoundException( name );
}
if ( name != null && name.startsWith( "/" ) )
{
name = name.substring( 1 );
}
final URL url = classLoader.getResource( name );
if ( url == null )
{
throw new ResourceNotFoundException( name );
}
return new URLPlexusResource( url );
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FilePlexusResource.java plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FilePlexusResource.jav0000644 0001750 0001750 00000004075 11125657060 033435 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import org.codehaus.plexus.resource.PlexusResource;
/**
* Implementation of {@link PlexusResource} for files.
*/
public class FilePlexusResource
implements PlexusResource
{
private final File file;
public FilePlexusResource( File file )
{
this.file = file;
}
public File getFile()
throws IOException
{
return file;
}
public InputStream getInputStream()
throws IOException
{
return new FileInputStream( file );
}
public String getName()
{
return file.getPath();
}
public URI getURI()
throws IOException
{
return file.toURI();
}
public URL getURL()
throws IOException
{
return file.toURI().toURL();
}
}
plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/URLPlexusResource.java0000644 0001750 0001750 00000003767 11125657060 033370 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import org.codehaus.plexus.resource.PlexusResource;
/**
* Implementation of {@link PlexusResource} for URL's.
*/
public class URLPlexusResource
implements PlexusResource
{
private final URL url;
public URLPlexusResource( URL url )
{
this.url = url;
}
public File getFile()
throws IOException
{
return null;
}
public InputStream getInputStream()
throws IOException
{
return url.openStream();
}
public String getName()
{
return url.toExternalForm();
}
public URI getURI()
throws IOException
{
return null;
}
public URL getURL()
throws IOException
{
return url;
}
}
plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/URLResourceLoader.java0000644 0001750 0001750 00000013067 11336111666 033311 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.codehaus.plexus.resource.PlexusResource;
/**
* @author Jason van Zyl
* @plexus.component role-hint="url" instantiation-strategy="per-lookup"
*/
public class URLResourceLoader
extends AbstractResourceLoader
{
public static final String ID = "url";
protected Map templateRoots = new HashMap();
/**
* Get an InputStream so that the Runtime can build a template with it.
*
* @param name name of template to fetch bytestream of
* @return InputStream containing the template
* @throws ResourceNotFoundException if template not found in the file template path.
*/
public PlexusResource getResource( String name )
throws ResourceNotFoundException
{
if ( name == null || name.length() == 0 )
{
throw new ResourceNotFoundException( "URLResourceLoader : No template name provided" );
}
Exception exception = null;
for ( Iterator i = paths.iterator(); i.hasNext(); )
{
String path = (String) i.next();
try
{
URL u = new URL( path + name );
final InputStream inputStream = u.openStream();
if ( inputStream != null )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "URLResourceLoader: Found '" + name + "' at '" + path + "'" );
}
// save this root for later re-use
templateRoots.put( name, path );
return new URLPlexusResource( u )
{
private boolean useSuper;
public synchronized InputStream getInputStream()
throws IOException
{
if ( !useSuper )
{
useSuper = true;
return inputStream;
}
return super.getInputStream();
}
};
}
}
catch ( IOException ioe )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"URLResourceLoader: Exception when looking for '" + name + "' at '" + path + "'",
ioe );
}
// only save the first one for later throwing
if ( exception == null )
{
exception = ioe;
}
}
}
// here we try to download without any path just the name which can be an url
try
{
URL u = new URL( name );
final InputStream inputStream = u.openStream();
if ( inputStream != null )
{
return new URLPlexusResource( u )
{
private boolean useSuper;
public synchronized InputStream getInputStream()
throws IOException
{
if ( !useSuper )
{
useSuper = true;
return inputStream;
}
return super.getInputStream();
}
};
}
}
catch ( IOException ioe )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "URLResourceLoader: Exception when looking for '" + name, ioe );
}
// only save the first one for later throwing
if ( exception == null )
{
exception = ioe;
}
}
// if we never found the template
String msg;
if ( exception == null )
{
msg = "URLResourceLoader : Resource '" + name + "' not found.";
}
else
{
msg = exception.getMessage();
}
// convert to a general Velocity ResourceNotFoundException
throw new ResourceNotFoundException( msg );
}
}
plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceLoader.java 0000644 0001750 0001750 00000004010 11125657060 032711 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.InputStream;
import org.codehaus.plexus.resource.PlexusResource;
/**
* @author Trygve Laugstøl
* @version $Id: ResourceLoader.java 7981 2008-12-28 11:08:32Z bentmann $
*/
public interface ResourceLoader
{
String ROLE = ResourceLoader.class.getName();
/**
* @deprecated Use {@link #getResource(String)}.
*/
InputStream getResourceAsInputStream( String name )
throws ResourceNotFoundException;
void addSearchPath( String path );
/**
* Returns the resource with the given name.
*
* @param name The resources name.
* @return The resource with the given name.
* @throws ResourceNotFoundException The resource wasn't found, or wasn't available.
*/
PlexusResource getResource( String name )
throws ResourceNotFoundException;
}
plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/DefaultResourceManager.java 0000644 0001750 0001750 00000016244 11336110147 033122 0 ustar eugene eugene package org.codehaus.plexus.resource;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.ResourceIOException;
import org.codehaus.plexus.resource.loader.ResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Map;
/**
* @author Trygve Laugstøl
* @author Jason van Zyl
* @version $Id: DefaultResourceManager.java 8647 2010-02-15 00:08:07Z olamy $
* @plexus.component instantiation-strategy="per-lookup"
*/
public class DefaultResourceManager
extends AbstractLogEnabled
implements ResourceManager
{
/** @plexus.requirement role="org.codehaus.plexus.resource.loader.ResourceLoader" */
private Map resourceLoaders;
/** @plexus.configuration */
private File outputDirectory;
// ----------------------------------------------------------------------
// ResourceManager Implementation
// ----------------------------------------------------------------------
public InputStream getResourceAsInputStream( String name )
throws ResourceNotFoundException
{
PlexusResource resource = getResource( name );
try
{
return resource.getInputStream();
}
catch ( IOException e )
{
throw new ResourceIOException( "Failed to open resource " + resource.getName() + ": " + e.getMessage(), e );
}
}
public File getResourceAsFile( String name )
throws ResourceNotFoundException, FileResourceCreationException
{
return getResourceAsFile( getResource( name ) );
}
public File getResourceAsFile( String name, String outputPath )
throws ResourceNotFoundException, FileResourceCreationException
{
if ( outputPath == null )
{
return getResourceAsFile( name );
}
PlexusResource resource = getResource( name );
File outputFile;
if ( outputDirectory != null )
{
outputFile = new File( outputDirectory, outputPath );
}
else
{
outputFile = new File( outputPath );
}
createResourceAsFile( resource, outputFile );
return outputFile;
}
public File resolveLocation( String name, String outputPath )
throws IOException
{
// Honour what the original locator does and return null ...
try
{
return getResourceAsFile( name, outputPath );
}
catch ( Exception e )
{
return null;
}
}
public File resolveLocation( String name )
throws IOException
{
// Honour what the original locator does and return null ...
try
{
return getResourceAsFile( name );
}
catch ( Exception e )
{
return null;
}
}
public void setOutputDirectory( File outputDirectory )
{
this.outputDirectory = outputDirectory;
}
public void addSearchPath( String id, String path )
{
ResourceLoader loader = (ResourceLoader) resourceLoaders.get( id );
if ( loader == null )
{
throw new IllegalArgumentException( "unknown resource loader: " + id );
}
loader.addSearchPath( path );
}
public PlexusResource getResource( String name )
throws ResourceNotFoundException
{
for ( Iterator i = resourceLoaders.values().iterator(); i.hasNext(); )
{
ResourceLoader resourceLoader = (ResourceLoader) i.next();
try
{
PlexusResource resource = resourceLoader.getResource( name );
getLogger().debug( "The resource " + "'" + name + "'" + " was found as " + resource.getName() + "." );
return resource;
}
catch ( ResourceNotFoundException e )
{
getLogger().debug(
"The resource " + "'" + name + "'" + " was not found with resourceLoader "
+ resourceLoader.getClass().getName() + "." );
}
}
throw new ResourceNotFoundException( name );
}
public File getResourceAsFile( PlexusResource resource )
throws FileResourceCreationException
{
try
{
File f = resource.getFile();
if ( f != null )
{
return f;
}
}
catch ( IOException e )
{
// Ignore this, try to make use of resource.getInputStream().
}
final File outputFile = FileUtils.createTempFile( "plexus-resources", "tmp", outputDirectory );
outputFile.deleteOnExit();
createResourceAsFile( resource, outputFile );
return outputFile;
}
public void createResourceAsFile( PlexusResource resource, File outputFile )
throws FileResourceCreationException
{
InputStream is = null;
OutputStream os = null;
try
{
is = resource.getInputStream();
File dir = outputFile.getParentFile();
if ( !dir.isDirectory() && !dir.mkdirs() )
{
throw new FileResourceCreationException( "Failed to create directory " + dir.getPath() );
}
os = new FileOutputStream( outputFile );
IOUtil.copy( is, os );
is.close();
is = null;
os.close();
os = null;
}
catch ( IOException e )
{
throw new FileResourceCreationException( "Cannot create file-based resource:" + e.getMessage(), e );
}
finally
{
IOUtil.close( is );
IOUtil.close( os );
}
}
}
plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/PlexusResource.java 0000644 0001750 0001750 00000006742 11125700135 031523 0 ustar eugene eugene package org.codehaus.plexus.resource;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
/**
* A resource is a byte stream, possibly (but not necessarily) with additional attributes like {@link File}, {@link URL}
* , or {@link URI}.
*
* @since 1.0-alpha-5
*/
public interface PlexusResource
{
/**
*
* Returns the resource as an {@link InputStream}. In general, you should not assume, that this method may me called
* more than once. In typical cases (for example, if the Resource is backed by a file or loaded through the
* classpath), one may create an {@link InputStream} as often as is necessary. However, you should think of cases
* like an URL pointing to a servlet, where the resource contents change with every call.
*
*
* If you need a reliable way of reloading the resource more than once, then you should use
* {@link ResourceManager#getResourceAsFile(PlexusResource)}.
*
*
* @return An {@link InputStream} with the resources contents, never null.
*/
public InputStream getInputStream()
throws IOException;
/**
*
* Returns the resource as a file, if possible. A resource doesn't need to be available as a file: If you require a
* file, use {@link ResourceManager#getResourceAsFile(PlexusResource)}.
*
*
* @return A {@link File} containing the resources contents, if available, or null.
*/
public File getFile()
throws IOException;
/**
*
* Returns the resources URL, if possible. A resource doesn't need to have an URL.
*
*
* @return The resources URL, if available, or null.
*/
public URL getURL()
throws IOException;
/**
*
* Returns the resources URI, if possible. A resource doesn't need to have an URI.
*
*
* @return The resources URI, if available, or null.
*/
public URI getURI()
throws IOException;
/**
* Returns the resources name, if possible. A resources name is a relatively unspecified thing. For example, if the
* resource has an {@link URL}, the name might be created by invoking {@link URL#toExternalForm()}. In the case of a
* {@link File}, it might be {@link File#getPath()}.
*/
public String getName();
}
plexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/ResourceManager.java 0000644 0001750 0001750 00000006477 11125657060 031632 0 ustar eugene eugene package org.codehaus.plexus.resource;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.InputStream;
import java.io.File;
import java.io.IOException;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
/**
* @author Trygve Laugstøl
* @author Jason van Zyl
* @version $Id: ResourceManager.java 7981 2008-12-28 11:08:32Z bentmann $
*/
public interface ResourceManager
{
String ROLE = ResourceManager.class.getName();
InputStream getResourceAsInputStream( String name )
throws ResourceNotFoundException;
File getResourceAsFile( String name )
throws ResourceNotFoundException, FileResourceCreationException;
File getResourceAsFile( String name, String outputFile )
throws ResourceNotFoundException, FileResourceCreationException;
void setOutputDirectory( File outputDirectory );
void addSearchPath( String resourceLoaderId, String searchPath );
/**
* Provides compatibility with the Locator utility used by several Maven Plugins.
*
* @deprecated
*/
File resolveLocation( String location, String localfile )
throws IOException;
/**
* Provides compatibility with the Locator utility used by several Maven Plugins.
*
* @deprecated
*/
File resolveLocation( String location )
throws IOException;
/**
* Searches for a resource with the given name.
*
* @since 1.0-alpha-5
*/
PlexusResource getResource( String name )
throws ResourceNotFoundException;
/**
* Returns a file with the given resources contents. If the resource is already available as a file, returns that
* file. Otherwise, a file in the resource managers output directory is created and the resource is downloaded to
* that file.
*
* @since 1.0-alpha-5
*/
File getResourceAsFile( PlexusResource resource )
throws FileResourceCreationException;
/**
* Downloads the resource to the given output file.
*
* @since 1.0-alpha-5
*/
void createResourceAsFile( PlexusResource resource, File outputFile )
throws FileResourceCreationException;
}
plexus-resources-1.0~alpha7/src/main/resources/ 0000755 0001750 0001750 00000000000 12137721314 021225 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/ 0000755 0001750 0001750 00000000000 12137721314 017246 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/java/ 0000755 0001750 0001750 00000000000 12137721314 020167 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/java/org/ 0000755 0001750 0001750 00000000000 12137721314 020756 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/java/org/codehaus/ 0000755 0001750 0001750 00000000000 12137721314 022551 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/ 0000755 0001750 0001750 00000000000 12137721314 024071 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/ 0000755 0001750 0001750 00000000000 12137721314 025720 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/ 0000755 0001750 0001750 00000000000 12137721314 027166 5 ustar eugene eugene ././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/FileResourceLoaderTest.java plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/FileResourceLoaderTest0000644 0001750 0001750 00000005066 11125657060 033500 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import org.codehaus.plexus.resource.PlexusResource;
import org.codehaus.plexus.resource.loader.AbstractResourceLoaderTest;
/**
* @author Trygve Laugstøl
* @version $Id: FileResourceLoaderTest.java 7981 2008-12-28 11:08:32Z bentmann $
*/
public class FileResourceLoaderTest
extends AbstractResourceLoaderTest
{
public void testLookupWithAAbsolutePathName()
throws Exception
{
assertResource( "/dir/file.txt", "file.txt" );
}
public void testLookupWithARelativePath()
throws Exception
{
assertResource( "dir/file.txt", "file.txt" );
}
public void testLookupWhenTheResourceIsMissing()
throws Exception
{
assertMissingResource( "/foo.txt" );
assertMissingResource( "foo.txt" );
}
public void testPlexusResource()
throws Exception
{
ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
PlexusResource resource = resourceLoader.getResource( "/dir/file.txt" );
final File f = new File( "src/test/file-resources", "/dir/file.txt" );
assertEquals( f.getAbsolutePath(), resource.getFile().getPath() );
assertEquals( f.toURI(), resource.getURI() );
assertEquals( f.toURI().toURL(), resource.getURL() );
assertEquals( f.getAbsolutePath(), resource.getName() );
}
}
././@LongLink 0000000 0000000 0000000 00000000174 00000000000 011567 L ustar root root plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoaderTest.java plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/ThreadContextClasspath0000644 0001750 0001750 00000005650 11125700135 033530 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.net.URL;
import org.codehaus.plexus.resource.PlexusResource;
/**
* @author Trygve Laugstøl
* @version $Id: ThreadContextClasspathResourceLoaderTest.java 7983 2008-12-28 13:34:21Z bentmann $
*/
public class ThreadContextClasspathResourceLoaderTest
extends AbstractResourceLoaderTest
{
public void testLookupWithAAbsolutePathName()
throws Exception
{
assertResource( "/dir/classpath.txt", "classpath.txt" );
}
public void testLookupWithARelativePath()
throws Exception
{
assertResource( "dir/classpath.txt", "classpath.txt" );
}
public void testLookupWhenTheResourceIsMissing()
throws Exception
{
assertMissingResource( "/foo.txt" );
assertMissingResource( "foo.txt" );
}
public void testLookupWithANullThreadContextClassLoader()
throws Exception
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( null );
assertMissingResource( "/dir/classpath.txt" );
assertMissingResource( "dir/classpath.txt" );
Thread.currentThread().setContextClassLoader( loader );
}
public void testPlexusResource()
throws Exception
{
ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
PlexusResource resource = resourceLoader.getResource( "/dir/classpath.txt" );
assertNull( resource.getFile() );
assertNull( resource.getURI() );
URL url = Thread.currentThread().getContextClassLoader().getResource( "/dir/classpath.txt" );
assertEquals( url, resource.getURL() );
assertEquals( url.toExternalForm(), resource.getName() );
}
}
plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/manager/ 0000755 0001750 0001750 00000000000 12137721314 030600 5 ustar eugene eugene ././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011570 L ustar root root plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/manager/ResourceManagerTest.java plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/manager/ResourceManage0000644 0001750 0001750 00000003121 10534344761 033426 0 ustar eugene eugene package org.codehaus.plexus.resource.loader.manager;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.resource.ResourceManager;
/**
* @author Trygve Laugstøl
* @version $Id: ResourceManagerTest.java 4937 2006-12-02 18:46:09Z jvanzyl $
*/
public class ResourceManagerTest
extends PlexusTestCase
{
public void testFoo()
throws Exception
{
lookup( ResourceManager.ROLE );
}
}
././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011567 L ustar root root plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/AbstractResourceLoaderTest.java plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader0000644 0001750 0001750 00000005307 11125657060 033522 0 ustar eugene eugene package org.codehaus.plexus.resource.loader;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.InputStream;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.resource.loader.ResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.IOUtil;
/**
* @author Trygve Laugstøl
* @version $Id: AbstractResourceLoaderTest.java 7981 2008-12-28 11:08:32Z bentmann $
*/
public abstract class AbstractResourceLoaderTest
extends PlexusTestCase
{
protected void assertResource( String name, String expectedContent )
throws Exception
{
ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
InputStream is = resourceLoader.getResource( name ).getInputStream();
assertNotNull( "The returned input stream is null, name: '" + name + "'.", is );
String actualContent = IOUtil.toString( is, "UTF-8" );
assertEquals( expectedContent, actualContent );
}
protected void assertMissingResource( String name )
throws Exception
{
ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
try
{
InputStream is = resourceLoader.getResource( name ).getInputStream();
String content = IOUtil.toString( is, "UTF-8" );
fail( "Expected ResourceNotFoundException while looking for a resource named '" + name + "'. Content:\n"
+ content );
}
catch ( ResourceNotFoundException e )
{
// expected
}
}
}
plexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/ResourceManagerTest.java 0000644 0001750 0001750 00000011360 11125520763 032507 0 ustar eugene eugene package org.codehaus.plexus.resource;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import java.io.InputStream;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.FileUtils;
/**
* @author Trygve Laugstøl
* @version $Id: ResourceManagerTest.java 7978 2008-12-27 21:45:23Z bentmann $
*/
public class ResourceManagerTest
extends PlexusTestCase
{
public void testResourceManagerRetrievingInputStreams()
throws Exception
{
ResourceManager resourceManager = (ResourceManager) lookup( ResourceManager.ROLE );
InputStream in;
File absoluteFile = new File( getBasedir(), "src/test/file-resources/dir/file.txt" ).getAbsoluteFile();
assertTrue( absoluteFile.isFile() );
assertTrue( absoluteFile.isAbsolute() );
in = resourceManager.getResourceAsInputStream( absoluteFile.getAbsolutePath() );
assertEquals( "file.txt", IOUtil.toString( in, "UTF-8" ) );
in = resourceManager.getResourceAsInputStream( "/dir/file.txt" );
assertEquals( "file.txt", IOUtil.toString( in, "UTF-8" ) );
in = resourceManager.getResourceAsInputStream( "dir/file.txt" );
assertEquals( "file.txt", IOUtil.toString( in, "UTF-8" ) );
in = resourceManager.getResourceAsInputStream( "/dir/classpath.txt" );
assertEquals( "classpath.txt", IOUtil.toString( in, "UTF-8" ) );
in = resourceManager.getResourceAsInputStream( "dir/classpath.txt" );
assertEquals( "classpath.txt", IOUtil.toString( in, "UTF-8" ) );
}
public void testResourceManagerRetrievingFiles()
throws Exception
{
ResourceManager resourceManager = (ResourceManager) lookup( ResourceManager.ROLE );
File f;
File absoluteFile = new File( getBasedir(), "src/test/file-resources/dir/file.txt" ).getAbsoluteFile();
assertTrue( absoluteFile.isFile() );
assertTrue( absoluteFile.isAbsolute() );
f = resourceManager.getResourceAsFile( absoluteFile.getAbsolutePath() );
assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
f = resourceManager.getResourceAsFile( "/dir/file.txt" );
assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
f = resourceManager.getResourceAsFile( "dir/file.txt" );
assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
f = resourceManager.getResourceAsFile( "/dir/classpath.txt" );
assertEquals( "classpath.txt", FileUtils.fileRead( f, "UTF-8" ) );
f = resourceManager.getResourceAsFile( "dir/classpath.txt" );
assertEquals( "classpath.txt", FileUtils.fileRead( f, "UTF-8" ) );
}
public void testResourceManagerRetrievingFilesToSpecificLocation()
throws Exception
{
File outDir = new File( getBasedir(), "target/test/unit/output-directory" );
ResourceManager resourceManager = (ResourceManager) lookup( ResourceManager.ROLE );
resourceManager.setOutputDirectory( outDir );
File ef = new File( outDir, "test/f.txt" );
FileUtils.forceDelete( ef );
assertFalse( ef.exists() );
File f = resourceManager.getResourceAsFile( "dir/file.txt", "test/f.txt" );
assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
assertEquals( ef, f );
File ec = new File( outDir, "test/c.txt" );
FileUtils.forceDelete( ec );
assertFalse( ec.exists() );
File c = resourceManager.getResourceAsFile( "dir/classpath.txt", "test/c.txt" );
assertEquals( "classpath.txt", FileUtils.fileRead( c, "UTF-8" ) );
assertEquals( ec, c );
}
}
plexus-resources-1.0~alpha7/src/test/resources/ 0000755 0001750 0001750 00000000000 12137721314 021260 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/resources/org/ 0000755 0001750 0001750 00000000000 12137721314 022047 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/ 0000755 0001750 0001750 00000000000 12137721314 023642 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/ 0000755 0001750 0001750 00000000000 12137721314 025162 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/ 0000755 0001750 0001750 00000000000 12137721314 027011 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/ 0000755 0001750 0001750 00000000000 12137721314 030257 5 ustar eugene eugene ././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011567 L ustar root root plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/FileResourceLoaderTest.xml plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/FileResourceLoade0000644 0001750 0001750 00000000703 10534353173 033541 0 ustar eugene eugene
org.codehaus.plexus.resource.loader.ResourceLoader
file
org.codehaus.plexus.resource.loader.FileResourceLoader
${basedir}/src/test/file-resources
././@LongLink 0000000 0000000 0000000 00000000200 00000000000 011555 L ustar root root plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoaderTest.xml plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/ThreadContextClas0000644 0001750 0001750 00000000462 10534353173 033566 0 ustar eugene eugene
org.codehaus.plexus.resource.loader.ResourceLoader
classloader
org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader
plexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/ResourceManagerTest.xml 0000644 0001750 0001750 00000001304 10534335077 033461 0 ustar eugene eugene
org.codehaus.plexus.resource.loader.ResourceLoader
classpath
org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader
org.codehaus.plexus.resource.loader.ResourceLoader
file
org.codehaus.plexus.resource.loader.FileResourceLoader
${basedir}/src/test/file-resources
plexus-resources-1.0~alpha7/src/test/resources/dir/ 0000755 0001750 0001750 00000000000 12137721314 022036 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/resources/dir/classpath.txt 0000644 0001750 0001750 00000000015 10202121334 024540 0 ustar eugene eugene classpath.txt plexus-resources-1.0~alpha7/src/test/file-resources/ 0000755 0001750 0001750 00000000000 12137721314 022175 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/file-resources/dir/ 0000755 0001750 0001750 00000000000 12137721314 022753 5 ustar eugene eugene plexus-resources-1.0~alpha7/src/test/file-resources/dir/file.txt 0000644 0001750 0001750 00000000010 10202121334 024405 0 ustar eugene eugene file.txt