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