You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultPluginsServices.java 3.5KB

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