Skip to content

Commit ce8e541

Browse files
Fix unclosed opened stream
Method ArtifactStore#get was used for checking only if artifact exist but return was not consumed and opened stream was never closed
1 parent 8297bfd commit ce8e541

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArtifactStoreFileSystem.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ public ArtifactStoreFileSystem( ArtifactStore store )
126126
this.store = store;
127127
}
128128

129-
/**
130-
* {@inheritDoc}
131-
*/
129+
@Override
132130
public Entry[] listEntries( DirectoryEntry directory )
133131
{
134132
if ( getRoot().equals( directory ) )
@@ -164,7 +162,6 @@ public Entry[] listEntries( DirectoryEntry directory )
164162
String groupId = path.replace( '/', '.' );
165163

166164
// get all the groupId's that start with this groupId
167-
String groupIdPrefix = groupId + ".";
168165
Set<String> groupIds = new TreeSet<>( store.getGroupIds( groupId ) );
169166
for ( String name : groupIds )
170167
{
@@ -223,9 +220,7 @@ public Entry[] listEntries( DirectoryEntry directory )
223220
return result.toArray(new Entry[0]);
224221
}
225222

226-
/**
227-
* {@inheritDoc}
228-
*/
223+
@Override
229224
protected Entry get( DirectoryEntry parent, String name )
230225
{
231226
String path = "/";
@@ -299,7 +294,8 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
299294
matcher.group( 10 ) );
300295
try
301296
{
302-
store.get( artifact );
297+
// check if artifact exist
298+
store.getSize( artifact );
303299
return new ArtifactFileEntry( this, parent, artifact, store );
304300
}
305301
catch ( IOException | ArtifactNotFoundException e )
@@ -325,7 +321,8 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
325321
matcher.group( 10 ), timestamp, buildNumber );
326322
try
327323
{
328-
store.get( artifact );
324+
// check if artifact exist
325+
store.getSize( artifact );
329326
return new ArtifactFileEntry( this, parent, artifact, store );
330327
}
331328
catch ( IOException | ArtifactNotFoundException e )
@@ -360,7 +357,8 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
360357
Artifact artifact = new Artifact( groupId, artifactId, version, classifier, type );
361358
try
362359
{
363-
store.get( artifact );
360+
// check if artifact exist
361+
store.getSize( artifact );
364362
return new ArtifactFileEntry( this, parent, artifact, store );
365363
}
366364
catch ( ArtifactNotFoundException | IOException e )
@@ -376,9 +374,7 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
376374
}
377375
}
378376

379-
/**
380-
* {@inheritDoc}
381-
*/
377+
@Override
382378
public long getLastModified( DirectoryEntry entry )
383379
throws IOException
384380
{

mrm-servlet/src/test/java/org/codehaus/mojo/mrm/impl/maven/ArtifactStoreFileSystemTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class ArtifactStoreFileSystemTest
4040

4141
@Test
4242
public void testGroupMetadataRegex()
43-
throws Exception
4443
{
4544
Matcher matcher = ArtifactStoreFileSystem.METADATA.matcher( "/commons/maven-metadata.xml" );
4645
assertTrue( matcher.matches() );
@@ -56,7 +55,6 @@ public void testGroupMetadataRegex()
5655

5756
@Test
5857
public void testArtifactRegex()
59-
throws Exception
6058
{
6159
Matcher matcher = ArtifactStoreFileSystem.ARTIFACT.matcher( "/commons/maven-metadata.xml" );
6260
assertFalse( matcher.matches() );
@@ -109,7 +107,6 @@ public void testArtifactRegex()
109107

110108
@Test
111109
public void testSnapshotArtifactRegex()
112-
throws Exception
113110
{
114111
Matcher matcher = ArtifactStoreFileSystem.SNAPSHOT_ARTIFACT.matcher( "/commons/maven-metadata.xml" );
115112
assertFalse( matcher.matches() );
@@ -159,7 +156,7 @@ public void testSnapshotArtifactRegex()
159156
public void testSiteXmlReleaseVersion() throws Exception
160157
{
161158
ArtifactStore store = mock( ArtifactStore.class );
162-
when( store.get( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
159+
when( store.getSize( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
163160
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem( store );
164161
FileEntry entry = (FileEntry) system.get( "/localhost/mmockrm-5/1/mmockrm-5-1-site_en.xml" );
165162
assertNull( entry );
@@ -169,7 +166,7 @@ public void testSiteXmlReleaseVersion() throws Exception
169166
public void testSiteXmlSnapshotVersion() throws Exception
170167
{
171168
ArtifactStore store = mock( ArtifactStore.class );
172-
when( store.get( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
169+
when( store.getSize( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
173170
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem( store );
174171
FileEntry entry = (FileEntry) system.get( "/localhost/mmockrm-5/1.0-SNAPSHOT/mmockrm-5-1.0-SNAPSHOT-site_en.xml" );
175172
assertNull( entry );

0 commit comments

Comments
 (0)