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.

TestConsumer.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package org.apache.archiva.scheduler.repository;
  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.consumers.AbstractMonitoredConsumer;
  21. import org.apache.archiva.consumers.ConsumerException;
  22. import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
  23. import org.apache.archiva.repository.content.LayoutException;
  24. import org.apache.archiva.repository.ManagedRepository;
  25. import org.apache.archiva.repository.ManagedRepositoryContent;
  26. import org.apache.archiva.repository.RepositoryContentFactory;
  27. import org.springframework.stereotype.Service;
  28. import javax.inject.Inject;
  29. import java.util.Collection;
  30. import java.util.Collections;
  31. import java.util.Date;
  32. import java.util.HashSet;
  33. import java.util.List;
  34. import java.util.Set;
  35. @Service( "knownRepositoryContentConsumer#test-consumer" )
  36. public class TestConsumer
  37. extends AbstractMonitoredConsumer
  38. implements KnownRepositoryContentConsumer
  39. {
  40. private Set<String> consumed = new HashSet<>();
  41. @Inject
  42. private RepositoryContentFactory factory;
  43. private ManagedRepositoryContent repository;
  44. @Override
  45. public String getId()
  46. {
  47. return "test-consumer";
  48. }
  49. @Override
  50. public String getDescription()
  51. {
  52. return null;
  53. }
  54. @Override
  55. public List<String> getIncludes()
  56. {
  57. return Collections.singletonList( "**/**" );
  58. }
  59. @Override
  60. public List<String> getExcludes()
  61. {
  62. return null;
  63. }
  64. @Override
  65. public void beginScan( ManagedRepository repository, Date whenGathered )
  66. throws ConsumerException
  67. {
  68. consumed.clear();
  69. this.repository = repository.getContent();
  70. }
  71. @Override
  72. public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
  73. throws ConsumerException
  74. {
  75. beginScan( repository, whenGathered );
  76. }
  77. @Override
  78. public void processFile( String path )
  79. throws ConsumerException
  80. {
  81. if ( !path.endsWith( ".sha1" ) && !path.endsWith( ".md5" ) )
  82. {
  83. try
  84. {
  85. repository.toItemSelector( path );
  86. consumed.add( path );
  87. }
  88. catch ( LayoutException e )
  89. {
  90. // Layout exception for specific paths
  91. }
  92. }
  93. }
  94. @Override
  95. public void processFile( String path, boolean executeOnEntireRepo )
  96. throws Exception
  97. {
  98. processFile( path );
  99. }
  100. @Override
  101. public void completeScan()
  102. {
  103. }
  104. @Override
  105. public void completeScan( boolean executeOnEntireRepo )
  106. {
  107. completeScan();
  108. }
  109. public Collection<String> getConsumed()
  110. {
  111. return consumed;
  112. }
  113. }