Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DefaultPluginsServices.java 3.1KB

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