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 java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
26 import org.springframework.stereotype.Service;
28 import javax.inject.Inject;
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;
37 * @author Eric Barboni
40 @Service("pluginsService#rest")
41 public class DefaultPluginsServices
42 implements PluginsService
45 private List<String> repositoryType = new ArrayList<String>();
47 private List<String> adminFeatures = new ArrayList<String>();
49 private ApplicationContext appCont;
51 private Logger log = LoggerFactory.getLogger( getClass() );
54 public DefaultPluginsServices( ApplicationContext applicationContext )
56 this.appCont = applicationContext;
59 private void feed( List<String> repository, String key )
60 throws ArchivaRestServiceException
62 log.info( "Feeding: {}", key );
64 Resource[] xmlResources;
67 xmlResources = appCont.getResources( "/**/" + key + "/**/main.js" );
68 for ( Resource rc : xmlResources )
70 String tmp = rc.getURL().toString();
71 tmp = tmp.substring( tmp.lastIndexOf( key ) + key.length() + 1, tmp.length() - 8 );
72 repository.add( "archiva/admin/" + key + "/" + tmp + "/main" );
75 catch ( IOException e )
78 throw new ArchivaRestServiceException( e.getMessage(), e );
83 public String getAdminPlugins()
84 throws ArchivaRestServiceException
87 feed( repositoryType, "repository" );
88 feed( adminFeatures, "features" );
89 StringBuilder sb = new StringBuilder();
90 for ( String repoType : repositoryType )
92 sb.append( repoType ).append( "|" );
94 for ( String repoType : adminFeatures )
96 sb.append( repoType ).append( "|" );
98 log.debug( "getAdminPlugins: {}", sb.toString() );
99 if ( sb.length() > 1 )
101 return sb.substring( 0, sb.length() - 1 );
105 return sb.toString();