1 | |
package org.apache.maven.archiva.scheduled.tasks; |
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.io.IOException; |
24 | |
|
25 | |
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; |
26 | |
import org.sonatype.nexus.index.NexusIndexer; |
27 | |
import org.sonatype.nexus.index.context.DefaultIndexingContext; |
28 | |
import org.sonatype.nexus.index.context.IndexingContext; |
29 | |
import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class TaskCreator |
36 | |
{ |
37 | |
public static RepositoryTask createRepositoryTask( String repositoryId ) |
38 | |
{ |
39 | 0 | RepositoryTask task = new RepositoryTask(); |
40 | 0 | task.setRepositoryId( repositoryId ); |
41 | 0 | return task; |
42 | |
} |
43 | |
|
44 | |
public static RepositoryTask createRepositoryTask( String repositoryId, boolean scanAll ) |
45 | |
{ |
46 | 0 | RepositoryTask task = createRepositoryTask( repositoryId ); |
47 | 0 | task.setScanAll( scanAll ); |
48 | |
|
49 | 0 | return task; |
50 | |
} |
51 | |
|
52 | |
public static RepositoryTask createRepositoryTask( String repositoryId, File resourceFile, |
53 | |
boolean updateRelatedArtifacts ) |
54 | |
{ |
55 | 0 | RepositoryTask task = createRepositoryTask( repositoryId ); |
56 | 0 | task.setResourceFile( resourceFile ); |
57 | 0 | task.setUpdateRelatedArtifacts( updateRelatedArtifacts ); |
58 | |
|
59 | 0 | return task; |
60 | |
} |
61 | |
|
62 | |
public static RepositoryTask createRepositoryTask( String repositoryId, File resourceFile, |
63 | |
boolean updateRelatedArtifacts, boolean scanAll ) |
64 | |
{ |
65 | 0 | RepositoryTask task = createRepositoryTask( repositoryId, resourceFile, updateRelatedArtifacts ); |
66 | 0 | task.setScanAll( scanAll ); |
67 | |
|
68 | 0 | return task; |
69 | |
} |
70 | |
|
71 | |
public static ArtifactIndexingTask createIndexingTask( ManagedRepositoryConfiguration repository, File resource, |
72 | |
ArtifactIndexingTask.Action action, IndexingContext context ) |
73 | |
{ |
74 | 0 | return new ArtifactIndexingTask( repository, resource, action, context ); |
75 | |
} |
76 | |
|
77 | |
public static IndexingContext createContext( ManagedRepositoryConfiguration repository ) |
78 | |
throws IOException, UnsupportedExistingLuceneIndexException |
79 | |
{ |
80 | 0 | String indexDir = repository.getIndexDir(); |
81 | 0 | File managedRepository = new File( repository.getLocation() ); |
82 | |
|
83 | 0 | File indexDirectory = null; |
84 | 0 | if ( indexDir != null && !"".equals( indexDir ) ) |
85 | |
{ |
86 | 0 | indexDirectory = new File( repository.getIndexDir() ); |
87 | |
} |
88 | |
else |
89 | |
{ |
90 | 0 | indexDirectory = new File( managedRepository, ".indexer" ); |
91 | |
} |
92 | |
|
93 | 0 | IndexingContext context = |
94 | |
new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, |
95 | |
null, null, NexusIndexer.FULL_INDEX, false ); |
96 | 0 | context.setSearchable( repository.isScanned() ); |
97 | 0 | return context; |
98 | |
} |
99 | |
|
100 | |
} |