1 | |
package org.apache.maven.archiva.repository.project; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.List; |
23 | |
|
24 | |
import org.apache.commons.lang.StringUtils; |
25 | |
import org.apache.maven.archiva.configuration.ArchivaConfiguration; |
26 | |
import org.apache.maven.archiva.configuration.ConfigurationNames; |
27 | |
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; |
28 | |
import org.apache.maven.archiva.repository.ManagedRepositoryContent; |
29 | |
import org.apache.maven.archiva.repository.RepositoryContentFactory; |
30 | |
import org.apache.maven.archiva.repository.RepositoryException; |
31 | |
import org.apache.maven.archiva.repository.project.readers.ProjectModel300Reader; |
32 | |
import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader; |
33 | |
import org.apache.maven.archiva.repository.project.resolvers.ManagedRepositoryProjectResolver; |
34 | |
import org.apache.maven.archiva.repository.project.resolvers.NopProjectResolver; |
35 | |
import org.apache.maven.archiva.repository.project.resolvers.ProjectModelResolverStack; |
36 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; |
37 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; |
38 | |
import org.codehaus.plexus.registry.Registry; |
39 | |
import org.codehaus.plexus.registry.RegistryListener; |
40 | |
import org.slf4j.Logger; |
41 | |
import org.slf4j.LoggerFactory; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class ProjectModelResolverFactory |
50 | |
implements RegistryListener, Initializable |
51 | |
{ |
52 | 0 | private Logger log = LoggerFactory.getLogger( ProjectModelResolverFactory.class ); |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
private ArchivaConfiguration archivaConfiguration; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
private RepositoryContentFactory repositoryFactory; |
63 | |
|
64 | 0 | private ProjectModelResolverStack currentResolverStack = new ProjectModelResolverStack(); |
65 | |
|
66 | |
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) |
67 | |
{ |
68 | 0 | if ( ConfigurationNames.isManagedRepositories( propertyName ) ) |
69 | |
{ |
70 | 0 | update(); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | |
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) |
75 | |
{ |
76 | |
|
77 | 0 | } |
78 | |
|
79 | |
public ProjectModelResolverStack getCurrentResolverStack() |
80 | |
{ |
81 | 0 | return currentResolverStack; |
82 | |
} |
83 | |
|
84 | |
public void initialize() |
85 | |
throws InitializationException |
86 | |
{ |
87 | 0 | update(); |
88 | 0 | archivaConfiguration.addChangeListener( this ); |
89 | 0 | } |
90 | |
|
91 | |
private ManagedRepositoryProjectResolver toResolver( ManagedRepositoryConfiguration repo ) |
92 | |
throws RepositoryException |
93 | |
{ |
94 | 0 | ManagedRepositoryContent repoContent = repositoryFactory.getManagedRepositoryContent( repo.getId() ); |
95 | |
|
96 | |
ProjectModelReader reader; |
97 | 0 | if ( StringUtils.equals( "legacy", repo.getLayout() ) ) |
98 | |
{ |
99 | 0 | reader = new ProjectModel300Reader(); |
100 | |
} |
101 | |
else |
102 | |
{ |
103 | 0 | reader = new ProjectModel400Reader(); |
104 | |
} |
105 | |
|
106 | 0 | return new ManagedRepositoryProjectResolver( repoContent, reader ); |
107 | |
} |
108 | |
|
109 | |
private void update() |
110 | |
{ |
111 | 0 | synchronized ( currentResolverStack ) |
112 | |
{ |
113 | 0 | this.currentResolverStack.clearResolvers(); |
114 | |
|
115 | 0 | List<ManagedRepositoryConfiguration> list = |
116 | |
archivaConfiguration.getConfiguration().getManagedRepositories(); |
117 | 0 | for ( ManagedRepositoryConfiguration repo : list ) |
118 | |
{ |
119 | |
try |
120 | |
{ |
121 | 0 | ManagedRepositoryProjectResolver resolver = toResolver( repo ); |
122 | |
|
123 | |
|
124 | 0 | this.currentResolverStack.addProjectModelResolver( resolver ); |
125 | |
} |
126 | 0 | catch ( RepositoryException e ) |
127 | |
{ |
128 | 0 | log.warn( e.getMessage(), e ); |
129 | 0 | } |
130 | |
} |
131 | |
|
132 | |
|
133 | 0 | this.currentResolverStack.addProjectModelResolver( NopProjectResolver.getInstance() ); |
134 | 0 | } |
135 | 0 | } |
136 | |
} |