1 package org.apache.maven.plugin.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 @Component( role = ResourceManager.class, hint = "license" )
34 public class LicenseResourceManager
35 extends DefaultResourceManager
36 {
37
38 @Requirement( role = ResourceLoader.class )
39 private Map<String, ResourceLoader> resourceLoaders;
40
41 @Override
42 public void addSearchPath( String id, String path )
43 {
44 ResourceLoader loader = (ResourceLoader) resourceLoaders.get( id );
45
46 if ( loader == null )
47 {
48 throw new IllegalArgumentException( "unknown resource loader: " + id );
49 }
50
51 loader.addSearchPath( path );
52 }
53
54 @Override
55 public PlexusResource getResource( String name )
56 throws ResourceNotFoundException
57 {
58 for ( ResourceLoader resourceLoader : resourceLoaders.values() )
59 {
60 if ( resourceLoader instanceof ThreadContextClasspathResourceLoader
61 && !"config/maven-header.txt".equals( name ) )
62 {
63
64
65 continue;
66 }
67
68 try
69 {
70 PlexusResource resource = resourceLoader.getResource( name );
71
72 getLogger().debug( "The resource " + "'" + name + "'" + " was found as " + resource.getName() + "." );
73
74 return resource;
75 }
76 catch ( ResourceNotFoundException e )
77 {
78 getLogger().debug( "The resource " + "'" + name + "'" + " was not found with resourceLoader "
79 + resourceLoader.getClass().getName() + "." );
80 }
81 }
82
83 throw new ResourceNotFoundException( name );
84 }
85 }