001package org.apache.archiva.rest.services; 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021import java.io.IOException; 022import java.util.ArrayList; 023import java.util.List; 024 025import org.apache.archiva.rest.api.services.ArchivaRestServiceException; 026import org.springframework.stereotype.Service; 027 028import javax.inject.Inject; 029 030import org.apache.archiva.rest.api.services.PluginsService; 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033import org.springframework.context.ApplicationContext; 034import org.springframework.core.io.Resource; 035 036/** 037 * @author Eric Barboni 038 * @since 1.4.0 039 */ 040@Service("pluginsService#rest") 041public class DefaultPluginsServices 042 implements PluginsService 043{ 044 045 private List<String> repositoryType = new ArrayList<>(); 046 047 private List<String> adminFeatures = new ArrayList<>(); 048 049 private ApplicationContext appCont; 050 051 private Logger log = LoggerFactory.getLogger( getClass() ); 052 053 private String adminPlugins; 054 055 @Inject 056 public DefaultPluginsServices( ApplicationContext applicationContext ) 057 throws IOException 058 { 059 this.appCont = applicationContext; 060 061 // rebuild 062 feed( repositoryType, "repository" ); 063 feed( adminFeatures, "features" ); 064 StringBuilder sb = new StringBuilder(); 065 for ( String repoType : repositoryType ) 066 { 067 sb.append( repoType ).append( "|" ); 068 } 069 for ( String repoType : adminFeatures ) 070 { 071 sb.append( repoType ).append( "|" ); 072 } 073 log.debug( "getAdminPlugins: {}", sb.toString() ); 074 if ( sb.length() > 1 ) 075 { 076 adminPlugins = sb.substring( 0, sb.length() - 1 ); 077 } 078 else 079 { 080 adminPlugins = sb.toString(); 081 } 082 } 083 084 private void feed( List<String> repository, String key ) 085 throws IOException 086 { 087 log.info( "Feeding: {}", key ); 088 repository.clear(); 089 Resource[] xmlResources; 090 091 xmlResources = appCont.getResources( "/**/" + key + "/**/main.js" ); 092 for ( Resource rc : xmlResources ) 093 { 094 String tmp = rc.getURL().toString(); 095 tmp = tmp.substring( tmp.lastIndexOf( key ) + key.length() + 1, tmp.length() - 8 ); 096 repository.add( "archiva/admin/" + key + "/" + tmp + "/main" ); 097 } 098 099 } 100 101 @Override 102 public String getAdminPlugins() 103 throws ArchivaRestServiceException 104 { 105 return adminPlugins; 106 } 107}