Skip to content

Commit e129f80

Browse files
committed
Migration to Sisu
1 parent 3a32e38 commit e129f80

14 files changed

+212
-143
lines changed

pom.xml

+51-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
<properties>
3535
<project.build.outputTimestamp>2020-01-20T18:52:37Z</project.build.outputTimestamp>
36+
<mockito.version>3.10.0</mockito.version>
3637
</properties>
3738

3839
<dependencies>
@@ -41,13 +42,9 @@
4142
<artifactId>plexus-utils</artifactId>
4243
</dependency>
4344
<dependency>
44-
<groupId>org.codehaus.plexus</groupId>
45-
<artifactId>plexus-container-default</artifactId>
46-
</dependency>
47-
<dependency>
48-
<groupId>org.codehaus.plexus</groupId>
49-
<artifactId>plexus-component-annotations</artifactId>
50-
<optional>true</optional>
45+
<groupId>javax.inject</groupId>
46+
<artifactId>javax.inject</artifactId>
47+
<version>1</version>
5148
</dependency>
5249
<dependency>
5350
<groupId>org.slf4j</groupId>
@@ -56,10 +53,22 @@
5653
</dependency>
5754

5855
<!-- TEST -->
56+
<dependency>
57+
<groupId>org.junit.jupiter</groupId>
58+
<artifactId>junit-jupiter</artifactId>
59+
<version>5.8.0-M1</version>
60+
<scope>test</scope>
61+
</dependency>
5962
<dependency>
6063
<groupId>org.mockito</groupId>
6164
<artifactId>mockito-core</artifactId>
62-
<version>3.9.0</version>
65+
<version>${mockito.version}</version>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.mockito</groupId>
70+
<artifactId>mockito-junit-jupiter</artifactId>
71+
<version>${mockito.version}</version>
6372
<scope>test</scope>
6473
</dependency>
6574
<dependency>
@@ -68,6 +77,27 @@
6877
<version>2.1.0</version>
6978
<scope>test</scope>
7079
</dependency>
80+
<dependency>
81+
<groupId>org.codehaus.plexus</groupId>
82+
<artifactId>plexus-testing</artifactId>
83+
<version>1.0.0</version>
84+
<scope>test</scope>
85+
<exclusions>
86+
<exclusion>
87+
<!-- guice with aop not working on java >= 16 -->
88+
<!-- should be fixed in plexus-testing -->
89+
<groupId>com.google.inject</groupId>
90+
<artifactId>guice</artifactId>
91+
</exclusion>
92+
</exclusions>
93+
</dependency>
94+
<dependency>
95+
<groupId>com.google.inject</groupId>
96+
<artifactId>guice</artifactId>
97+
<version>4.2.3</version>
98+
<classifier>no_aop</classifier>
99+
<scope>test</scope>
100+
</dependency>
71101
</dependencies>
72102

73103
<build>
@@ -88,6 +118,19 @@
88118
</execution>
89119
</executions>
90120
</plugin>
121+
<plugin>
122+
<groupId>org.eclipse.sisu</groupId>
123+
<artifactId>sisu-maven-plugin</artifactId>
124+
<version>0.3.4</version>
125+
<executions>
126+
<execution>
127+
<goals>
128+
<goal>main-index</goal>
129+
<goal>test-index</goal>
130+
</goals>
131+
</execution>
132+
</executions>
133+
</plugin>
91134
</plugins>
92135
</build>
93136

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

+19-14
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import org.codehaus.plexus.component.annotations.Component;
28-
import org.codehaus.plexus.component.annotations.Requirement;
2927

3028
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
3129
import org.codehaus.plexus.resource.loader.ResourceIOException;
@@ -42,28 +40,35 @@
4240
import java.io.InputStream;
4341
import java.io.OutputStream;
4442
import java.util.Map;
43+
import javax.inject.Inject;
44+
import javax.inject.Named;
4545

4646
/**
4747
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
4848
* @author Jason van Zyl
4949
* @version $Id$
5050
*/
51-
@Component( role = ResourceManager.class, instantiationStrategy = "per-lookup" )
51+
@Named
5252
public class DefaultResourceManager implements ResourceManager
5353
{
5454
private static final Logger LOGGER = LoggerFactory.getLogger( DefaultResourceManager.class );
5555

56-
@Requirement( role = ResourceLoader.class )
57-
private Map<String, ResourceLoader> resourceLoaders;
56+
private final Map<String, ResourceLoader> resourceLoaders;
5857

5958
private File outputDirectory;
6059

60+
@Inject
61+
private DefaultResourceManager( Map<String, ResourceLoader> resourceLoaders )
62+
{
63+
this.resourceLoaders = resourceLoaders;
64+
}
65+
6166
// ----------------------------------------------------------------------
6267
// ResourceManager Implementation
6368
// ----------------------------------------------------------------------
6469

6570
public InputStream getResourceAsInputStream( String name )
66-
throws ResourceNotFoundException
71+
throws ResourceNotFoundException
6772
{
6873
PlexusResource resource = getResource( name );
6974
try
@@ -77,13 +82,13 @@ public InputStream getResourceAsInputStream( String name )
7782
}
7883

7984
public File getResourceAsFile( String name )
80-
throws ResourceNotFoundException, FileResourceCreationException
85+
throws ResourceNotFoundException, FileResourceCreationException
8186
{
8287
return getResourceAsFile( getResource( name ) );
8388
}
8489

8590
public File getResourceAsFile( String name, String outputPath )
86-
throws ResourceNotFoundException, FileResourceCreationException
91+
throws ResourceNotFoundException, FileResourceCreationException
8792
{
8893
if ( outputPath == null )
8994
{
@@ -104,7 +109,7 @@ public File getResourceAsFile( String name, String outputPath )
104109
}
105110

106111
public File resolveLocation( String name, String outputPath )
107-
throws IOException
112+
throws IOException
108113
{
109114
// Honour what the original locator does and return null ...
110115
try
@@ -118,7 +123,7 @@ public File resolveLocation( String name, String outputPath )
118123
}
119124

120125
public File resolveLocation( String name )
121-
throws IOException
126+
throws IOException
122127
{
123128
// Honour what the original locator does and return null ...
124129
try
@@ -149,7 +154,7 @@ public void addSearchPath( String id, String path )
149154
}
150155

151156
public PlexusResource getResource( String name )
152-
throws ResourceNotFoundException
157+
throws ResourceNotFoundException
153158
{
154159
for ( ResourceLoader resourceLoader : resourceLoaders.values() )
155160
{
@@ -164,15 +169,15 @@ public PlexusResource getResource( String name )
164169
catch ( ResourceNotFoundException e )
165170
{
166171
LOGGER.debug( "The resource '{}' was not found with resourceLoader '{}'",
167-
name, resourceLoader.getClass().getName() );
172+
name, resourceLoader.getClass().getName() );
168173
}
169174
}
170175

171176
throw new ResourceNotFoundException( name );
172177
}
173178

174179
public File getResourceAsFile( PlexusResource resource )
175-
throws FileResourceCreationException
180+
throws FileResourceCreationException
176181
{
177182
try
178183
{
@@ -194,7 +199,7 @@ public File getResourceAsFile( PlexusResource resource )
194199
}
195200

196201
public void createResourceAsFile( PlexusResource resource, File outputFile )
197-
throws FileResourceCreationException
202+
throws FileResourceCreationException
198203
{
199204
InputStream is = null;
200205
OutputStream os = null;

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

-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
*/
3939
public interface ResourceManager
4040
{
41-
String ROLE = ResourceManager.class.getName();
42-
4341
InputStream getResourceAsInputStream( String name )
4442
throws ResourceNotFoundException;
4543

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,21 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import java.io.File;
28-
import java.io.IOException;
29-
30-
import org.codehaus.plexus.component.annotations.Component;
3127
import org.codehaus.plexus.resource.PlexusResource;
32-
import org.codehaus.plexus.resource.loader.AbstractResourceLoader;
33-
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
3428
import org.codehaus.plexus.util.FileUtils;
3529

30+
import java.io.File;
31+
import java.io.IOException;
32+
import javax.inject.Named;
33+
3634
/**
3735
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
3836
* @author Jason van Zyl
3937
* @version $Id$
4038
*/
41-
@Component( role = ResourceLoader.class, hint = "file", instantiationStrategy = "per-lookup" )
39+
@Named( FileResourceLoader.ID )
4240
public class FileResourceLoader
43-
extends AbstractResourceLoader
41+
extends AbstractResourceLoader
4442
{
4543
public static final String ID = "file";
4644

@@ -49,7 +47,7 @@ public class FileResourceLoader
4947
// ----------------------------------------------------------------------
5048

5149
public PlexusResource getResource( String name )
52-
throws ResourceNotFoundException
50+
throws ResourceNotFoundException
5351
{
5452
for ( String path : paths )
5553
{
@@ -69,10 +67,10 @@ public PlexusResource getResource( String name )
6967
}
7068

7169
/**
72-
* @deprecated Use {@link org.codehaus.plexus.resource.ResourceManager#getResourceAsFile(PlexusResource )}.
70+
* @deprecated Use {@link org.codehaus.plexus.resource.ResourceManager#getResourceAsFile(PlexusResource)}.
7371
*/
7472
public static File getResourceAsFile( String name, String outputPath, File outputDirectory )
75-
throws FileResourceCreationException
73+
throws FileResourceCreationException
7674

7775
{
7876
File f = new File( name );

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

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.codehaus.plexus.resource.loader;
22

3-
import org.codehaus.plexus.component.annotations.Component;
43

54
/*
65
* The MIT License
@@ -26,22 +25,22 @@
2625
* SOFTWARE.
2726
*/
2827

29-
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
3028
import org.codehaus.plexus.resource.PlexusResource;
3129
import org.slf4j.Logger;
3230
import org.slf4j.LoggerFactory;
3331

3432
import java.util.LinkedHashMap;
3533
import java.util.Map;
34+
import javax.inject.Named;
3635

3736
/**
3837
* @author Jason van Zyl
3938
*/
40-
@Component( role = ResourceLoader.class, hint = "jar", instantiationStrategy = "per-lookup" )
39+
@Named( JarResourceLoader.ID )
4140
public class JarResourceLoader
42-
extends AbstractResourceLoader
41+
extends AbstractResourceLoader
4342
{
44-
private static final Logger LOGGER = LoggerFactory.getLogger( ResourceLoader.class );
43+
private static final Logger LOGGER = LoggerFactory.getLogger( JarResourceLoader.class );
4544

4645
public static final String ID = "jar";
4746

@@ -58,15 +57,14 @@ public class JarResourceLoader
5857
private boolean initializeCalled;
5958

6059
public void initialize()
61-
throws InitializationException
6260
{
6361
initializeCalled = true;
6462

6563
if ( paths != null )
6664
{
6765
for ( int i = 0; i < paths.size(); i++ )
6866
{
69-
loadJar( (String) paths.get( i ) );
67+
loadJar( paths.get( i ) );
7068
}
7169
}
7270
}
@@ -84,7 +82,7 @@ private void loadJar( String path )
8482
if ( !path.startsWith( "jar:" ) )
8583
{
8684
LOGGER.error( "JarResourceLoader : JAR path must start with jar: -> "
87-
+ "see java.net.JarURLConnection for information" );
85+
+ "see java.net.JarURLConnection for information" );
8886
return;
8987
}
9088
if ( !path.endsWith( "!/" ) )
@@ -134,18 +132,11 @@ private void addEntries( Map entries )
134132
* @throws ResourceNotFoundException if template not found in the file template path.
135133
*/
136134
public PlexusResource getResource( String source )
137-
throws ResourceNotFoundException
135+
throws ResourceNotFoundException
138136
{
139137
if ( !initializeCalled )
140138
{
141-
try
142-
{
143-
initialize();
144-
}
145-
catch ( InitializationException e )
146-
{
147-
throw new ResourceNotFoundException( e.getMessage(), e );
148-
}
139+
initialize();
149140
}
150141

151142
if ( source == null || source.length() == 0 )

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

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
*/
3535
public interface ResourceLoader
3636
{
37-
String ROLE = ResourceLoader.class.getName();
38-
3937
/**
4038
* @deprecated Use {@link #getResource(String)}.
4139
*/

0 commit comments

Comments
 (0)