This project has retired. For details please refer to its
Attic page.
DefaultPluginsServices xref
1 package org.apache.archiva.rest.services;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
26 import org.springframework.stereotype.Service;
27
28 import javax.inject.Inject;
29
30 import org.apache.archiva.rest.api.services.PluginsService;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.context.ApplicationContext;
34 import org.springframework.core.io.Resource;
35
36
37
38
39
40 @Service("pluginsService#rest")
41 public class DefaultPluginsServices
42 implements PluginsService
43 {
44
45 private List<String> repositoryType = new ArrayList<>();
46
47 private List<String> adminFeatures = new ArrayList<>();
48
49 private ApplicationContext appCont;
50
51 private Logger log = LoggerFactory.getLogger( getClass() );
52
53 private String adminPlugins;
54
55 @Inject
56 public DefaultPluginsServices( ApplicationContext applicationContext )
57 throws IOException
58 {
59 this.appCont = applicationContext;
60
61
62 feed( repositoryType, "repository" );
63 feed( adminFeatures, "features" );
64 StringBuilder sb = new StringBuilder();
65 for ( String repoType : repositoryType )
66 {
67 sb.append( repoType ).append( "|" );
68 }
69 for ( String repoType : adminFeatures )
70 {
71 sb.append( repoType ).append( "|" );
72 }
73 log.debug( "getAdminPlugins: {}", sb.toString() );
74 if ( sb.length() > 1 )
75 {
76 adminPlugins = sb.substring( 0, sb.length() - 1 );
77 }
78 else
79 {
80 adminPlugins = sb.toString();
81 }
82 }
83
84 private void feed( List<String> repository, String key )
85 throws IOException
86 {
87 log.info( "Feeding: {}", key );
88 repository.clear();
89 Resource[] xmlResources;
90
91 xmlResources = appCont.getResources( "/**/" + key + "/**/main.js" );
92 for ( Resource rc : xmlResources )
93 {
94 String tmp = rc.getURL().toString();
95 tmp = tmp.substring( tmp.lastIndexOf( key ) + key.length() + 1, tmp.length() - 8 );
96 repository.add( "archiva/admin/" + key + "/" + tmp + "/main" );
97 }
98
99 }
100
101 @Override
102 public String getAdminPlugins()
103 throws ArchivaRestServiceException
104 {
105 return adminPlugins;
106 }
107 }