Skip to content

Commit 46abe8c

Browse files
authored
Update codebase to current Java level (#13)
Also, cleanup some bits, fix javadoc and add deprecated annotations.
1 parent 89c9c0a commit 46abe8c

11 files changed

+64
-71
lines changed

src/main/java/org/codehaus/plexus/resource/DefaultResourceManager.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ private DefaultResourceManager( Map<String, ResourceLoader> resourceLoaders )
6767
// ResourceManager Implementation
6868
// ----------------------------------------------------------------------
6969

70+
@Override
7071
public InputStream getResourceAsInputStream( String name )
7172
throws ResourceNotFoundException
7273
{
@@ -81,12 +82,14 @@ public InputStream getResourceAsInputStream( String name )
8182
}
8283
}
8384

85+
@Override
8486
public File getResourceAsFile( String name )
8587
throws ResourceNotFoundException, FileResourceCreationException
8688
{
8789
return getResourceAsFile( getResource( name ) );
8890
}
8991

92+
@Override
9093
public File getResourceAsFile( String name, String outputPath )
9194
throws ResourceNotFoundException, FileResourceCreationException
9295
{
@@ -108,8 +111,8 @@ public File getResourceAsFile( String name, String outputPath )
108111
return outputFile;
109112
}
110113

114+
@Override
111115
public File resolveLocation( String name, String outputPath )
112-
throws IOException
113116
{
114117
// Honour what the original locator does and return null ...
115118
try
@@ -122,8 +125,8 @@ public File resolveLocation( String name, String outputPath )
122125
}
123126
}
124127

128+
@Override
125129
public File resolveLocation( String name )
126-
throws IOException
127130
{
128131
// Honour what the original locator does and return null ...
129132
try
@@ -136,14 +139,16 @@ public File resolveLocation( String name )
136139
}
137140
}
138141

142+
@Override
139143
public void setOutputDirectory( File outputDirectory )
140144
{
141145
this.outputDirectory = outputDirectory;
142146
}
143147

148+
@Override
144149
public void addSearchPath( String id, String path )
145150
{
146-
ResourceLoader loader = (ResourceLoader) resourceLoaders.get( id );
151+
ResourceLoader loader = resourceLoaders.get( id );
147152

148153
if ( loader == null )
149154
{
@@ -153,6 +158,7 @@ public void addSearchPath( String id, String path )
153158
loader.addSearchPath( path );
154159
}
155160

161+
@Override
156162
public PlexusResource getResource( String name )
157163
throws ResourceNotFoundException
158164
{
@@ -176,6 +182,7 @@ public PlexusResource getResource( String name )
176182
throw new ResourceNotFoundException( name );
177183
}
178184

185+
@Override
179186
public File getResourceAsFile( PlexusResource resource )
180187
throws FileResourceCreationException
181188
{
@@ -198,6 +205,7 @@ public File getResourceAsFile( PlexusResource resource )
198205
return outputFile;
199206
}
200207

208+
@Override
201209
public void createResourceAsFile( PlexusResource resource, File outputFile )
202210
throws FileResourceCreationException
203211
{

src/main/java/org/codehaus/plexus/resource/PlexusResource.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public interface PlexusResource
5252
*
5353
* @return An {@link InputStream} with the resources contents, never null.
5454
*/
55-
public InputStream getInputStream()
56-
throws IOException;
55+
InputStream getInputStream() throws IOException;
5756

5857
/**
5958
* <p>
@@ -63,8 +62,7 @@ public InputStream getInputStream()
6362
*
6463
* @return A {@link File} containing the resources contents, if available, or null.
6564
*/
66-
public File getFile()
67-
throws IOException;
65+
File getFile() throws IOException;
6866

6967
/**
7068
* <p>
@@ -73,8 +71,7 @@ public File getFile()
7371
*
7472
* @return The resources URL, if available, or null.
7573
*/
76-
public URL getURL()
77-
throws IOException;
74+
URL getURL() throws IOException;
7875

7976
/**
8077
* <p>
@@ -83,13 +80,12 @@ public URL getURL()
8380
*
8481
* @return The resources URI, if available, or null.
8582
*/
86-
public URI getURI()
87-
throws IOException;
83+
URI getURI() throws IOException;
8884

8985
/**
9086
* Returns the resources name, if possible. A resources name is a relatively unspecified thing. For example, if the
9187
* resource has an {@link URL}, the name might be created by invoking {@link URL#toExternalForm()}. In the case of a
9288
* {@link File}, it might be {@link File#getPath()}.
9389
*/
94-
public String getName();
90+
String getName();
9591
}

src/main/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
*/
3838
public abstract class AbstractResourceLoader implements ResourceLoader
3939
{
40-
protected List<String> paths = new ArrayList<>();
40+
protected final List<String> paths = new ArrayList<>();
4141

42+
@Override
4243
public void addSearchPath( String path )
4344
{
4445
if ( !paths.contains( path ) )
@@ -47,6 +48,8 @@ public void addSearchPath( String path )
4748
}
4849
}
4950

51+
@Override
52+
@Deprecated
5053
public InputStream getResourceAsInputStream( String name )
5154
throws ResourceNotFoundException
5255
{

src/main/java/org/codehaus/plexus/resource/loader/FilePlexusResource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,32 @@ public FilePlexusResource( File file )
4646
this.file = file;
4747
}
4848

49+
@Override
4950
public File getFile()
50-
throws IOException
5151
{
5252
return file;
5353
}
5454

55+
@Override
5556
public InputStream getInputStream()
5657
throws IOException
5758
{
5859
return new FileInputStream( file );
5960
}
6061

62+
@Override
6163
public String getName()
6264
{
6365
return file.getPath();
6466
}
6567

68+
@Override
6669
public URI getURI()
67-
throws IOException
6870
{
6971
return file.toURI();
7072
}
7173

74+
@Override
7275
public URL getURL()
7376
throws IOException
7477
{

src/main/java/org/codehaus/plexus/resource/loader/FileResourceLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class FileResourceLoader
4646
// ResourceLoader Implementation
4747
// ----------------------------------------------------------------------
4848

49+
@Override
4950
public PlexusResource getResource( String name )
5051
throws ResourceNotFoundException
5152
{
@@ -69,6 +70,7 @@ public PlexusResource getResource( String name )
6970
/**
7071
* @deprecated Use {@link org.codehaus.plexus.resource.ResourceManager#getResourceAsFile(PlexusResource)}.
7172
*/
73+
@Deprecated
7274
public static File getResourceAsFile( String name, String outputPath, File outputDirectory )
7375
throws FileResourceCreationException
7476

src/main/java/org/codehaus/plexus/resource/loader/JarHolder.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747
public class JarHolder
4848
{
49-
private String urlpath = null;
49+
private final String urlpath;
5050

5151
private JarFile theJar = null;
5252

@@ -56,11 +56,6 @@ public JarHolder( String urlpath )
5656
{
5757
this.urlpath = urlpath;
5858

59-
init();
60-
}
61-
62-
public void init()
63-
{
6459
try
6560
{
6661
URL url = new URL( urlpath );
@@ -119,17 +114,17 @@ public InputStream getResource( String theentry )
119114
return data;
120115
}
121116

122-
public Hashtable getEntries()
117+
public Hashtable<String, String> getEntries()
123118
{
124-
Hashtable<String, String> allEntries = new Hashtable<String, String>( 559 );
119+
Hashtable<String, String> allEntries = new Hashtable<>( 559 );
125120

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

130125
while ( all.hasMoreElements() )
131126
{
132-
JarEntry je = (JarEntry) all.nextElement();
127+
JarEntry je = all.nextElement();
133128

134129
// We don't map plain directory entries
135130
if ( !je.isDirectory() )
@@ -155,29 +150,32 @@ public PlexusResource getPlexusResource( final String name )
155150
}
156151
return new PlexusResource()
157152
{
153+
@Override
158154
public File getFile()
159-
throws IOException
160155
{
161156
return null;
162157
}
163158

159+
@Override
164160
public InputStream getInputStream()
165161
throws IOException
166162
{
167163
return theJar.getInputStream( entry );
168164
}
169165

166+
@Override
170167
public String getName()
171168
{
172169
return conn.getURL() + name;
173170
}
174171

172+
@Override
175173
public URI getURI()
176-
throws IOException
177174
{
178175
return null;
179176
}
180177

178+
@Override
181179
public URL getURL()
182180
throws IOException
183181
{

src/main/java/org/codehaus/plexus/resource/loader/JarResourceLoader.java

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.util.LinkedHashMap;
3333
import java.util.Map;
34+
3435
import javax.inject.Named;
3536

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

5253
/**
5354
* Maps JAR URLs to the actual JAR (key = the JAR URL, value = the JAR).
5455
*/
55-
private Map<String, JarHolder> jarfiles = new LinkedHashMap<String, JarHolder>( 89 );
56-
57-
private boolean initializeCalled;
58-
59-
public void initialize()
60-
{
61-
initializeCalled = true;
62-
63-
if ( paths != null )
64-
{
65-
for ( int i = 0; i < paths.size(); i++ )
66-
{
67-
loadJar( paths.get( i ) );
68-
}
69-
}
70-
}
56+
private final Map<String, JarHolder> jarFiles = new LinkedHashMap<>( 89 );
7157

7258
private void loadJar( String path )
7359
{
@@ -100,17 +86,17 @@ private void loadJar( String path )
10086
addEntries( temp.getEntries() );
10187

10288
// Add it to the Jar table
103-
jarfiles.put( temp.getUrlPath(), temp );
89+
jarFiles.put( temp.getUrlPath(), temp );
10490
}
10591

10692
/**
10793
* Closes a Jar file and set its URLConnection to null.
10894
*/
10995
private void closeJar( String path )
11096
{
111-
if ( jarfiles.containsKey( path ) )
97+
if ( jarFiles.containsKey( path ) )
11298
{
113-
JarHolder theJar = (JarHolder) jarfiles.get( path );
99+
JarHolder theJar = jarFiles.get( path );
114100

115101
theJar.close();
116102
}
@@ -119,26 +105,22 @@ private void closeJar( String path )
119105
/**
120106
* Copy all the entries into the entryDirectory. It will overwrite any duplicate keys.
121107
*/
122-
private void addEntries( Map entries )
108+
private void addEntries( Map<String, String> entries )
123109
{
124110
entryDirectory.putAll( entries );
125111
}
126112

127113
/**
128-
* Get an InputStream so that the Runtime can build a template with it.
114+
* Get an {@link PlexusResource} by name.
129115
*
130-
* @param source name of template to get
131-
* @return InputStream containing the template
132-
* @throws ResourceNotFoundException if template not found in the file template path.
116+
* @param source name of resource to get
117+
* @return PlexusResource containing the resource
118+
* @throws ResourceNotFoundException if resource not found.
133119
*/
120+
@Override
134121
public PlexusResource getResource( String source )
135122
throws ResourceNotFoundException
136123
{
137-
if ( !initializeCalled )
138-
{
139-
initialize();
140-
}
141-
142124
if ( source == null || source.length() == 0 )
143125
{
144126
throw new ResourceNotFoundException( "Need to have a resource!" );
@@ -154,9 +136,9 @@ public PlexusResource getResource( String source )
154136

155137
if ( entryDirectory.containsKey( source ) )
156138
{
157-
String jarurl = (String) entryDirectory.get( source );
139+
String jarurl = entryDirectory.get( source );
158140

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

151+
@Override
169152
public void addSearchPath( String path )
170153
{
171154
if ( !paths.contains( path ) )
172155
{
173-
if ( initializeCalled )
174-
{
175-
loadJar( path );
176-
}
156+
loadJar( path );
177157
paths.add( path );
178158
}
179159
}

0 commit comments

Comments
 (0)