Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update codebase to current Java level #13

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private DefaultResourceManager( Map<String, ResourceLoader> resourceLoaders )
// ResourceManager Implementation
// ----------------------------------------------------------------------

@Override
public InputStream getResourceAsInputStream( String name )
throws ResourceNotFoundException
{
Expand All @@ -81,12 +82,14 @@ public InputStream getResourceAsInputStream( String name )
}
}

@Override
public File getResourceAsFile( String name )
throws ResourceNotFoundException, FileResourceCreationException
{
return getResourceAsFile( getResource( name ) );
}

@Override
public File getResourceAsFile( String name, String outputPath )
throws ResourceNotFoundException, FileResourceCreationException
{
Expand All @@ -108,8 +111,8 @@ public File getResourceAsFile( String name, String outputPath )
return outputFile;
}

@Override
public File resolveLocation( String name, String outputPath )
throws IOException
{
// Honour what the original locator does and return null ...
try
Expand All @@ -122,8 +125,8 @@ public File resolveLocation( String name, String outputPath )
}
}

@Override
public File resolveLocation( String name )
throws IOException
{
// Honour what the original locator does and return null ...
try
Expand All @@ -136,14 +139,16 @@ public File resolveLocation( String name )
}
}

@Override
public void setOutputDirectory( File outputDirectory )
{
this.outputDirectory = outputDirectory;
}

@Override
public void addSearchPath( String id, String path )
{
ResourceLoader loader = (ResourceLoader) resourceLoaders.get( id );
ResourceLoader loader = resourceLoaders.get( id );

if ( loader == null )
{
Expand All @@ -153,6 +158,7 @@ public void addSearchPath( String id, String path )
loader.addSearchPath( path );
}

@Override
public PlexusResource getResource( String name )
throws ResourceNotFoundException
{
Expand All @@ -176,6 +182,7 @@ public PlexusResource getResource( String name )
throw new ResourceNotFoundException( name );
}

@Override
public File getResourceAsFile( PlexusResource resource )
throws FileResourceCreationException
{
Expand All @@ -198,6 +205,7 @@ public File getResourceAsFile( PlexusResource resource )
return outputFile;
}

@Override
public void createResourceAsFile( PlexusResource resource, File outputFile )
throws FileResourceCreationException
{
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/org/codehaus/plexus/resource/PlexusResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public interface PlexusResource
*
* @return An {@link InputStream} with the resources contents, never null.
*/
public InputStream getInputStream()
throws IOException;
InputStream getInputStream() throws IOException;

/**
* <p>
Expand All @@ -63,8 +62,7 @@ public InputStream getInputStream()
*
* @return A {@link File} containing the resources contents, if available, or null.
*/
public File getFile()
throws IOException;
File getFile() throws IOException;

/**
* <p>
Expand All @@ -73,8 +71,7 @@ public File getFile()
*
* @return The resources URL, if available, or null.
*/
public URL getURL()
throws IOException;
URL getURL() throws IOException;

/**
* <p>
Expand All @@ -83,13 +80,12 @@ public URL getURL()
*
* @return The resources URI, if available, or null.
*/
public URI getURI()
throws IOException;
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();
String getName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
*/
public abstract class AbstractResourceLoader implements ResourceLoader
{
protected List<String> paths = new ArrayList<>();
protected final List<String> paths = new ArrayList<>();

@Override
public void addSearchPath( String path )
{
if ( !paths.contains( path ) )
Expand All @@ -47,6 +48,8 @@ public void addSearchPath( String path )
}
}

@Override
@Deprecated
public InputStream getResourceAsInputStream( String name )
throws ResourceNotFoundException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,32 @@ public FilePlexusResource( File file )
this.file = file;
}

@Override
public File getFile()
throws IOException
{
return file;
}

@Override
public InputStream getInputStream()
throws IOException
{
return new FileInputStream( file );
}

@Override
public String getName()
{
return file.getPath();
}

@Override
public URI getURI()
throws IOException
{
return file.toURI();
}

@Override
public URL getURL()
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class FileResourceLoader
// ResourceLoader Implementation
// ----------------------------------------------------------------------

@Override
public PlexusResource getResource( String name )
throws ResourceNotFoundException
{
Expand All @@ -69,6 +70,7 @@ public PlexusResource getResource( String name )
/**
* @deprecated Use {@link org.codehaus.plexus.resource.ResourceManager#getResourceAsFile(PlexusResource)}.
*/
@Deprecated
public static File getResourceAsFile( String name, String outputPath, File outputDirectory )
throws FileResourceCreationException

Expand Down
20 changes: 9 additions & 11 deletions src/main/java/org/codehaus/plexus/resource/loader/JarHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*/
public class JarHolder
{
private String urlpath = null;
private final String urlpath;

private JarFile theJar = null;

Expand All @@ -56,11 +56,6 @@ public JarHolder( String urlpath )
{
this.urlpath = urlpath;

init();
}

public void init()
{
try
{
URL url = new URL( urlpath );
Expand Down Expand Up @@ -119,17 +114,17 @@ public InputStream getResource( String theentry )
return data;
}

public Hashtable getEntries()
public Hashtable<String, String> getEntries()
{
Hashtable<String, String> allEntries = new Hashtable<String, String>( 559 );
Hashtable<String, String> allEntries = new Hashtable<>( 559 );

if ( theJar != null )
{
Enumeration<JarEntry> all = theJar.entries();

while ( all.hasMoreElements() )
{
JarEntry je = (JarEntry) all.nextElement();
JarEntry je = all.nextElement();

// We don't map plain directory entries
if ( !je.isDirectory() )
Expand All @@ -155,29 +150,32 @@ public PlexusResource getPlexusResource( final String name )
}
return new PlexusResource()
{
@Override
public File getFile()
throws IOException
{
return null;
}

@Override
public InputStream getInputStream()
throws IOException
{
return theJar.getInputStream( entry );
}

@Override
public String getName()
{
return conn.getURL() + name;
}

@Override
public URI getURI()
throws IOException
{
return null;
}

@Override
public URL getURL()
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.util.LinkedHashMap;
import java.util.Map;

import javax.inject.Named;

/**
Expand All @@ -47,27 +48,12 @@ public class JarResourceLoader
/**
* Maps entries to the parent JAR File (key = the entry *excluding* plain directories, value = the JAR URL).
*/
private Map entryDirectory = new LinkedHashMap( 559 );
private final Map<String, String> entryDirectory = new LinkedHashMap<>( 559 );

/**
* Maps JAR URLs to the actual JAR (key = the JAR URL, value = the JAR).
*/
private Map<String, JarHolder> jarfiles = new LinkedHashMap<String, JarHolder>( 89 );

private boolean initializeCalled;

public void initialize()
{
initializeCalled = true;

if ( paths != null )
{
for ( int i = 0; i < paths.size(); i++ )
{
loadJar( paths.get( i ) );
}
}
}
private final Map<String, JarHolder> jarFiles = new LinkedHashMap<>( 89 );

private void loadJar( String path )
{
Expand Down Expand Up @@ -100,17 +86,17 @@ private void loadJar( String path )
addEntries( temp.getEntries() );

// Add it to the Jar table
jarfiles.put( temp.getUrlPath(), temp );
jarFiles.put( temp.getUrlPath(), temp );
}

/**
* Closes a Jar file and set its URLConnection to null.
*/
private void closeJar( String path )
{
if ( jarfiles.containsKey( path ) )
if ( jarFiles.containsKey( path ) )
{
JarHolder theJar = (JarHolder) jarfiles.get( path );
JarHolder theJar = jarFiles.get( path );

theJar.close();
}
Expand All @@ -119,26 +105,22 @@ private void closeJar( String path )
/**
* Copy all the entries into the entryDirectory. It will overwrite any duplicate keys.
*/
private void addEntries( Map entries )
private void addEntries( Map<String, String> entries )
{
entryDirectory.putAll( entries );
}

/**
* Get an InputStream so that the Runtime can build a template with it.
* Get an {@link PlexusResource} by name.
*
* @param source name of template to get
* @return InputStream containing the template
* @throws ResourceNotFoundException if template not found in the file template path.
* @param source name of resource to get
* @return PlexusResource containing the resource
* @throws ResourceNotFoundException if resource not found.
*/
@Override
public PlexusResource getResource( String source )
throws ResourceNotFoundException
{
if ( !initializeCalled )
{
initialize();
}

if ( source == null || source.length() == 0 )
{
throw new ResourceNotFoundException( "Need to have a resource!" );
Expand All @@ -154,9 +136,9 @@ public PlexusResource getResource( String source )

if ( entryDirectory.containsKey( source ) )
{
String jarurl = (String) entryDirectory.get( source );
String jarurl = entryDirectory.get( source );

final JarHolder holder = (JarHolder) jarfiles.get( jarurl );
final JarHolder holder = jarFiles.get( jarurl );
if ( holder != null )
{
return holder.getPlexusResource( source );
Expand All @@ -166,14 +148,12 @@ public PlexusResource getResource( String source )
throw new ResourceNotFoundException( "JarResourceLoader Error: cannot find resource " + source );
}

@Override
public void addSearchPath( String path )
{
if ( !paths.contains( path ) )
{
if ( initializeCalled )
{
loadJar( path );
}
loadJar( path );
paths.add( path );
}
}
Expand Down
Loading