This project has retired. For details please refer to its Attic page.
DefaultPluginsServices xref
View Javadoc
1   package org.apache.archiva.rest.services;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
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   * @author Eric Barboni
38   * @since 1.4.0
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          // rebuild
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 }