plexus-resources-1.0~alpha7/0000755000175000017500000000000012137721314015500 5ustar eugeneeugeneplexus-resources-1.0~alpha7/pom.xml0000644000175000017500000000251711337603154017024 0ustar eugeneeugene 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/0000755000175000017500000000000012137721314016267 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/site/0000755000175000017500000000000012137721314017233 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/site/site.xml0000644000175000017500000000041711253532642020725 0ustar eugeneeugene plexus-resources-1.0~alpha7/src/main/0000755000175000017500000000000012137721314017213 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/main/java/0000755000175000017500000000000012137721314020134 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/main/java/org/0000755000175000017500000000000012137721314020723 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/main/java/org/codehaus/0000755000175000017500000000000012137721314022516 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/0000755000175000017500000000000012137721314024036 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/0000755000175000017500000000000012137721314025665 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/0000755000175000017500000000000012137721314027133 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/JarHolder.java0000644000175000017500000001072411247053263031656 0ustar eugeneeugenepackage 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 ); } }; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceCreationException.javaplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceCreationEx0000644000175000017500000000322511125700135033423 0ustar eugeneeugenepackage 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 ); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader.javaplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader0000644000175000017500000000441311247053263033464 0ustar eugeneeugenepackage 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 ); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceLoader.javaplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FileResourceLoader.jav0000644000175000017500000000772511247053263033370 0ustar eugeneeugenepackage 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; } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceNotFoundException.javaplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceNotFoundExcept0000644000175000017500000000334010616205343033472 0ustar eugeneeugenepackage 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.java0000644000175000017500000001275311247053263033363 0ustar eugeneeugenepackage 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 ); } } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceIOException.javaplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ResourceIOException.ja0000644000175000017500000000335211125657060033352 0ustar eugeneeugenepackage 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 ); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoader.javaplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/ThreadContextClasspath0000644000175000017500000000502411254762275033510 0ustar eugeneeugenepackage 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 ); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FilePlexusResource.javaplexus-resources-1.0~alpha7/src/main/java/org/codehaus/plexus/resource/loader/FilePlexusResource.jav0000644000175000017500000000407511125657060033435 0ustar eugeneeugenepackage 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.java0000644000175000017500000000376711125657060033370 0ustar eugeneeugenepackage 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.java0000644000175000017500000001306711336111666033311 0ustar eugeneeugenepackage 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.java0000644000175000017500000000401011125657060032711 0ustar eugeneeugenepackage 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.java0000644000175000017500000001624411336110147033122 0ustar eugeneeugenepackage 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.java0000644000175000017500000000674211125700135031523 0ustar eugeneeugenepackage 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.java0000644000175000017500000000647711125657060031632 0ustar eugeneeugenepackage 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/0000755000175000017500000000000012137721314021225 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/0000755000175000017500000000000012137721314017246 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/java/0000755000175000017500000000000012137721314020167 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/java/org/0000755000175000017500000000000012137721314020756 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/java/org/codehaus/0000755000175000017500000000000012137721314022551 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/0000755000175000017500000000000012137721314024071 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/0000755000175000017500000000000012137721314025720 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/0000755000175000017500000000000012137721314027166 5ustar eugeneeugene././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/FileResourceLoaderTest.javaplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/FileResourceLoaderTest0000644000175000017500000000506611125657060033500 0ustar eugeneeugenepackage 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() ); } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoaderTest.javaplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/ThreadContextClasspath0000644000175000017500000000565011125700135033530 0ustar eugeneeugenepackage 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/0000755000175000017500000000000012137721314030600 5ustar eugeneeugene././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/manager/ResourceManagerTest.javaplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/manager/ResourceManage0000644000175000017500000000312110534344761033426 0ustar eugeneeugenepackage 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 ); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/AbstractResourceLoaderTest.javaplexus-resources-1.0~alpha7/src/test/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader0000644000175000017500000000530711125657060033522 0ustar eugeneeugenepackage 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.java0000644000175000017500000001136011125520763032507 0ustar eugeneeugenepackage 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/0000755000175000017500000000000012137721314021260 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/resources/org/0000755000175000017500000000000012137721314022047 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/0000755000175000017500000000000012137721314023642 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/0000755000175000017500000000000012137721314025162 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/0000755000175000017500000000000012137721314027011 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/0000755000175000017500000000000012137721314030257 5ustar eugeneeugene././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/FileResourceLoaderTest.xmlplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/FileResourceLoade0000644000175000017500000000070310534353173033541 0ustar eugeneeugene org.codehaus.plexus.resource.loader.ResourceLoader file org.codehaus.plexus.resource.loader.FileResourceLoader ${basedir}/src/test/file-resources ././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoaderTest.xmlplexus-resources-1.0~alpha7/src/test/resources/org/codehaus/plexus/resource/loader/ThreadContextClas0000644000175000017500000000046210534353173033566 0ustar eugeneeugene 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.xml0000644000175000017500000000130410534335077033461 0ustar eugeneeugene 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/0000755000175000017500000000000012137721314022036 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/resources/dir/classpath.txt0000644000175000017500000000001510202121334024540 0ustar eugeneeugeneclasspath.txtplexus-resources-1.0~alpha7/src/test/file-resources/0000755000175000017500000000000012137721314022175 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/file-resources/dir/0000755000175000017500000000000012137721314022753 5ustar eugeneeugeneplexus-resources-1.0~alpha7/src/test/file-resources/dir/file.txt0000644000175000017500000000001010202121334024405 0ustar eugeneeugenefile.txt