1 | |
package org.apache.maven.archiva.repository.scanner; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.LinkedHashSet; |
25 | |
import java.util.List; |
26 | |
import java.util.Set; |
27 | |
|
28 | |
import org.apache.commons.collections.CollectionUtils; |
29 | |
import org.apache.maven.archiva.configuration.FileTypes; |
30 | |
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; |
31 | |
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; |
32 | |
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; |
33 | |
import org.apache.maven.archiva.consumers.RepositoryContentConsumer; |
34 | |
import org.apache.maven.archiva.repository.RepositoryException; |
35 | |
import org.codehaus.plexus.util.DirectoryWalker; |
36 | |
|
37 | |
import javax.swing.*; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class DefaultRepositoryScanner |
46 | |
implements RepositoryScanner |
47 | |
{ |
48 | |
|
49 | |
|
50 | |
|
51 | |
private FileTypes filetypes; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
private RepositoryContentConsumers consumerUtil; |
57 | |
|
58 | 0 | private Set<RepositoryScannerInstance> inProgressScans = new LinkedHashSet<RepositoryScannerInstance>(); |
59 | |
|
60 | |
public RepositoryScanStatistics scan( ManagedRepositoryConfiguration repository, long changesSince ) |
61 | |
throws RepositoryException |
62 | |
{ |
63 | 0 | List<KnownRepositoryContentConsumer> knownContentConsumers = consumerUtil.getSelectedKnownConsumers(); |
64 | 0 | List<InvalidRepositoryContentConsumer> invalidContentConsumers = consumerUtil.getSelectedInvalidConsumers(); |
65 | 0 | List<String> ignoredPatterns = filetypes.getFileTypePatterns( FileTypes.IGNORED ); |
66 | |
|
67 | 0 | return scan( repository, knownContentConsumers, invalidContentConsumers, ignoredPatterns, changesSince ); |
68 | |
} |
69 | |
|
70 | |
public RepositoryScanStatistics scan( ManagedRepositoryConfiguration repository, |
71 | |
List<KnownRepositoryContentConsumer> knownContentConsumers, |
72 | |
List<InvalidRepositoryContentConsumer> invalidContentConsumers, |
73 | |
List<String> ignoredContentPatterns, long changesSince ) |
74 | |
throws RepositoryException |
75 | |
{ |
76 | 0 | if ( repository == null ) |
77 | |
{ |
78 | 0 | throw new IllegalArgumentException( "Unable to operate on a null repository." ); |
79 | |
} |
80 | |
|
81 | 0 | File repositoryBase = new File( repository.getLocation() ); |
82 | |
|
83 | 0 | if ( !repositoryBase.exists() ) |
84 | |
{ |
85 | 0 | throw new UnsupportedOperationException( "Unable to scan a repository, directory " |
86 | |
+ repositoryBase.getPath() + " does not exist." ); |
87 | |
} |
88 | |
|
89 | 0 | if ( !repositoryBase.isDirectory() ) |
90 | |
{ |
91 | 0 | throw new UnsupportedOperationException( "Unable to scan a repository, path " |
92 | |
+ repositoryBase.getPath() + " is not a directory." ); |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | 0 | List<String> allExcludes = new ArrayList<String>(); |
98 | 0 | List<String> allIncludes = new ArrayList<String>(); |
99 | |
|
100 | 0 | if ( CollectionUtils.isNotEmpty( ignoredContentPatterns ) ) |
101 | |
{ |
102 | 0 | allExcludes.addAll( ignoredContentPatterns ); |
103 | |
} |
104 | |
|
105 | |
|
106 | 0 | allIncludes.add( "**/*" ); |
107 | |
|
108 | |
|
109 | 0 | DirectoryWalker dirWalker = new DirectoryWalker(); |
110 | |
|
111 | 0 | dirWalker.setBaseDir( repositoryBase ); |
112 | |
|
113 | 0 | dirWalker.setIncludes( allIncludes ); |
114 | 0 | dirWalker.setExcludes( allExcludes ); |
115 | |
|
116 | |
|
117 | 0 | RepositoryScannerInstance scannerInstance = new RepositoryScannerInstance( repository, knownContentConsumers, |
118 | |
invalidContentConsumers, changesSince ); |
119 | |
|
120 | 0 | inProgressScans.add( scannerInstance ); |
121 | |
|
122 | 0 | dirWalker.addDirectoryWalkListener( scannerInstance ); |
123 | |
|
124 | |
|
125 | 0 | dirWalker.scan(); |
126 | |
|
127 | 0 | RepositoryScanStatistics stats = scannerInstance.getStatistics(); |
128 | |
|
129 | 0 | stats.setKnownConsumers( gatherIds( knownContentConsumers ) ); |
130 | 0 | stats.setInvalidConsumers( gatherIds( invalidContentConsumers ) ); |
131 | |
|
132 | 0 | inProgressScans.remove( scannerInstance ); |
133 | |
|
134 | 0 | return stats; |
135 | |
} |
136 | |
|
137 | |
private List<String> gatherIds( List<? extends RepositoryContentConsumer> consumers ) |
138 | |
{ |
139 | 0 | List<String> ids = new ArrayList<String>(); |
140 | 0 | for ( RepositoryContentConsumer consumer : consumers ) |
141 | |
{ |
142 | 0 | ids.add( consumer.getId() ); |
143 | |
} |
144 | 0 | return ids; |
145 | |
} |
146 | |
|
147 | |
public Set<RepositoryScannerInstance> getInProgressScans() |
148 | |
{ |
149 | 0 | return inProgressScans; |
150 | |
} |
151 | |
} |