View Javadoc
1   package org.apache.archiva.scheduler.repository;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.admin.model.beans.ManagedRepository;
23  import org.apache.archiva.consumers.AbstractMonitoredConsumer;
24  import org.apache.archiva.consumers.ConsumerException;
25  import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
26  import org.apache.archiva.model.ArtifactReference;
27  import org.apache.archiva.repository.ManagedRepositoryContent;
28  import org.apache.archiva.repository.RepositoryContentFactory;
29  import org.apache.archiva.repository.RepositoryException;
30  import org.apache.archiva.repository.layout.LayoutException;
31  import org.springframework.stereotype.Service;
32  
33  import javax.inject.Inject;
34  import java.util.Collection;
35  import java.util.Collections;
36  import java.util.Date;
37  import java.util.HashSet;
38  import java.util.List;
39  import java.util.Set;
40  
41  @Service( "knownRepositoryContentConsumer#test-consumer" )
42  public class TestConsumer
43      extends AbstractMonitoredConsumer
44      implements KnownRepositoryContentConsumer
45  {
46      private Set<ArtifactReference> consumed = new HashSet<ArtifactReference>();
47  
48      @Inject
49      private RepositoryContentFactory factory;
50  
51      private ManagedRepositoryContent repository;
52  
53      @Override
54      public String getId()
55      {
56          return "test-consumer";
57      }
58  
59      @Override
60      public String getDescription()
61      {
62          return null;
63      }
64  
65      @Override
66      public List<String> getIncludes()
67      {
68          return Collections.singletonList( "**/**" );
69      }
70  
71      @Override
72      public List<String> getExcludes()
73      {
74          return null;
75      }
76  
77      @Override
78      public void beginScan( ManagedRepository repository, Date whenGathered )
79          throws ConsumerException
80      {
81          consumed.clear();
82  
83          try
84          {
85              this.repository = factory.getManagedRepositoryContent( repository.getId() );
86          }
87          catch ( RepositoryException e )
88          {
89              throw new ConsumerException( e.getMessage(), e );
90          }
91      }
92  
93      @Override
94      public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
95          throws ConsumerException
96      {
97          beginScan( repository, whenGathered );
98      }
99  
100     @Override
101     public void processFile( String path )
102         throws ConsumerException
103     {
104         if ( !path.endsWith( ".sha1" ) && !path.endsWith( ".md5" ) )
105         {
106             try
107             {
108                 consumed.add( repository.toArtifactReference( path ) );
109             }
110             catch ( LayoutException e )
111             {
112                 throw new ConsumerException( e.getMessage(), e );
113             }
114         }
115     }
116 
117     @Override
118     public void processFile( String path, boolean executeOnEntireRepo )
119         throws Exception
120     {
121         processFile( path );
122     }
123 
124     @Override
125     public void completeScan()
126     {
127     }
128 
129     @Override
130     public void completeScan( boolean executeOnEntireRepo )
131     {
132         completeScan();
133     }
134 
135     public Collection<ArtifactReference> getConsumed()
136     {
137         return consumed;
138     }
139 }