1 package org.apache.maven.plugins.checkstyle.resource;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Map;
23
24 import org.codehaus.plexus.component.annotations.Component;
25 import org.codehaus.plexus.component.annotations.Requirement;
26 import org.codehaus.plexus.resource.DefaultResourceManager;
27 import org.codehaus.plexus.resource.PlexusResource;
28 import org.codehaus.plexus.resource.ResourceManager;
29 import org.codehaus.plexus.resource.loader.ResourceLoader;
30 import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
31 import org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader;
32
33
34
35
36
37
38 @Component( role = ResourceManager.class, hint = "license", instantiationStrategy = "per-lookup" )
39 public class LicenseResourceManager
40 extends DefaultResourceManager
41 {
42
43 @Requirement( role = ResourceLoader.class )
44 private Map<String, ResourceLoader> resourceLoaders;
45
46 @Override
47 public void addSearchPath( String id, String path )
48 {
49 ResourceLoader loader = resourceLoaders.get( id );
50
51 if ( loader == null )
52 {
53 throw new IllegalArgumentException( "unknown resource loader: " + id );
54 }
55
56 loader.addSearchPath( path );
57 }
58
59 @Override
60 public PlexusResource getResource( String name )
61 throws ResourceNotFoundException
62 {
63 for ( ResourceLoader resourceLoader : resourceLoaders.values() )
64 {
65 if ( resourceLoader instanceof ThreadContextClasspathResourceLoader
66 && !"config/maven-header.txt".equals( name ) )
67 {
68
69
70 continue;
71 }
72
73 try
74 {
75 PlexusResource resource = resourceLoader.getResource( name );
76
77 getLogger().debug( "The resource '" + name + "' was found as " + resource.getName() + "." );
78
79 return resource;
80 }
81 catch ( ResourceNotFoundException e )
82 {
83 getLogger().debug( "The resource '" + name + "' was not found with resourceLoader "
84 + resourceLoader.getClass().getName() + "." );
85 }
86 }
87
88 throw new ResourceNotFoundException( name );
89 }
90 }