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.5KB

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.model.ArtifactReference;
  24. import org.apache.archiva.repository.LayoutException;
  25. import org.apache.archiva.repository.ManagedRepository;
  26. import org.apache.archiva.repository.ManagedRepositoryContent;
  27. import org.apache.archiva.repository.RepositoryContentFactory;
  28. import org.springframework.stereotype.Service;
  29. import javax.inject.Inject;
  30. import java.util.Collection;
  31. import java.util.Collections;
  32. import java.util.Date;
  33. import java.util.HashSet;
  34. import java.util.List;
  35. import java.util.Set;
  36. @Service( "knownRepositoryContentConsumer#test-consumer" )
  37. public class TestConsumer
  38. extends AbstractMonitoredConsumer
  39. implements KnownRepositoryContentConsumer
  40. {
  41. private Set<ArtifactReference> consumed = new HashSet<ArtifactReference>();
  42. @Inject
  43. private RepositoryContentFactory factory;
  44. private ManagedRepositoryContent repository;
  45. @Override
  46. public String getId()
  47. {
  48. return "test-consumer";
  49. }
  50. @Override
  51. public String getDescription()
  52. {
  53. return null;
  54. }
  55. @Override
  56. public List<String> getIncludes()
  57. {
  58. return Collections.singletonList( "**/**" );
  59. }
  60. @Override
  61. public List<String> getExcludes()
  62. {
  63. return null;
  64. }
  65. @Override
  66. public void beginScan( ManagedRepository repository, Date whenGathered )
  67. throws ConsumerException
  68. {
  69. consumed.clear();
  70. this.repository = repository.getContent();
  71. }
  72. @Override
  73. public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
  74. throws ConsumerException
  75. {
  76. beginScan( repository, whenGathered );
  77. }
  78. @Override
  79. public void processFile( String path )
  80. throws ConsumerException
  81. {
  82. if ( !path.endsWith( ".sha1" ) && !path.endsWith( ".md5" ) )
  83. {
  84. try
  85. {
  86. consumed.add( repository.toArtifactReference( path ) );
  87. }
  88. catch ( LayoutException e )
  89. {
  90. throw new ConsumerException( e.getMessage(), e );
  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<ArtifactReference> getConsumed()
  110. {
  111. return consumed;
  112. }
  113. }