1 package org.apache.archiva.rest.services;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
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;
36 * @author Eric Barboni
39 @Service( "pluginsService#rest" )
40 public class DefaultPluginsServices
41 implements PluginsService
44 private List<String> repositoryType = new ArrayList<>();
46 private List<String> adminFeatures = new ArrayList<>();
48 private ApplicationContext applicationContext;
50 private Logger log = LoggerFactory.getLogger( getClass() );
52 private String adminPlugins;
55 public DefaultPluginsServices( ApplicationContext applicationContext )
58 log.debug( "init DefaultPluginsServices" );
59 this.applicationContext = applicationContext;
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 )
69 sb.append( repoType ).append( "|" );
71 for ( String repoType : adminFeatures )
73 sb.append( repoType ).append( "|" );
75 log.debug( "getAdminPlugins: {}", sb.toString() );
76 if ( sb.length() > 1 )
78 adminPlugins = sb.substring( 0, sb.length() - 1 );
82 adminPlugins = sb.toString();
86 private List<String> feed( String key )
89 log.info( "Feeding: {}", key );
90 Resource[] xmlResources = applicationContext.getResources( "/**/" + key + "/**/main.js" );
91 if (xmlResources == null)
93 return Collections.emptyList();
95 List<String> repository = new ArrayList<>( xmlResources.length );
96 for ( Resource rc : xmlResources )
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" );
106 public String getAdminPlugins()
107 throws ArchivaRestServiceException