1 package org.apache.archiva.repository.features;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import org.apache.archiva.repository.Repository;
24 import org.apache.archiva.repository.event.RepositoryIndexEvent;
25 import org.apache.archiva.event.EventHandler;
26 import org.apache.archiva.repository.storage.StorageAsset;
27 import org.apache.commons.lang3.StringUtils;
28
29 import java.net.URI;
30 import java.net.URISyntaxException;
31
32 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
33 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class IndexCreationFeature extends AbstractFeature implements RepositoryFeature<IndexCreationFeature>{
51
52
53 private boolean skipPackedIndexCreation = false;
54
55 private URI indexPath;
56
57 private URI packedIndexPath;
58
59 private StorageAsset localIndexPath;
60
61 private StorageAsset localPackedIndexPath;
62
63 private Repository repo;
64
65 public IndexCreationFeature(Repository repository, EventHandler listener) {
66 super(listener);
67 this.repo = repository;
68 try {
69 this.indexPath = new URI(DEFAULT_INDEX_PATH);
70 this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
71 } catch (URISyntaxException e) {
72
73 e.printStackTrace();
74 }
75 }
76
77 public IndexCreationFeature(boolean skipPackedIndexCreation) {
78 this.skipPackedIndexCreation = skipPackedIndexCreation;
79 try {
80 this.indexPath = new URI(DEFAULT_INDEX_PATH);
81 this.packedIndexPath = new URI(DEFAULT_PACKED_INDEX_PATH);
82 } catch (URISyntaxException e) {
83
84 e.printStackTrace();
85 }
86 }
87
88 @Override
89 public IndexCreationFeature get() {
90 return this;
91 }
92
93
94
95
96
97 public boolean isSkipPackedIndexCreation() {
98 return skipPackedIndexCreation;
99 }
100
101
102
103
104
105
106 public void setSkipPackedIndexCreation(boolean skipPackedIndexCreation) {
107 this.skipPackedIndexCreation = skipPackedIndexCreation;
108 }
109
110
111
112
113
114
115
116 public URI getIndexPath( )
117 {
118 return indexPath;
119 }
120
121
122
123
124
125
126
127 public void setIndexPath( URI indexPath )
128 {
129 if ((this.indexPath==null && indexPath!=null) || !this.indexPath.equals(indexPath)) {
130 URI oldVal = this.indexPath;
131 this.indexPath = indexPath;
132 pushEvent(RepositoryIndexEvent.indexUriChange(this, repo, oldVal, this.indexPath));
133 }
134
135 }
136
137
138
139
140
141
142 public boolean hasIndex() {
143 return this.indexPath!=null && !StringUtils.isEmpty( this.indexPath.getPath() );
144 }
145
146
147
148
149
150
151 public StorageAsset getLocalIndexPath() {
152 return localIndexPath;
153 }
154
155
156
157
158
159
160 public void setLocalIndexPath(StorageAsset localIndexPath) {
161 this.localIndexPath = localIndexPath;
162 }
163
164
165
166
167
168
169 public URI getPackedIndexPath() {
170 return packedIndexPath;
171 }
172
173
174
175
176
177
178
179
180 public void setPackedIndexPath(URI packedIndexPath) {
181 URI oldVal = this.packedIndexPath;
182 this.packedIndexPath = packedIndexPath;
183 pushEvent(RepositoryIndexEvent.packedIndexUriChange(this, repo, oldVal, this.packedIndexPath));
184 }
185
186
187
188
189
190 public StorageAsset getLocalPackedIndexPath() {
191 return localPackedIndexPath;
192 }
193
194
195
196
197
198
199
200 public void setLocalPackedIndexPath(StorageAsset localPackedIndexPath) {
201 this.localPackedIndexPath = localPackedIndexPath;
202 }
203
204 @Override
205 public String toString() {
206 StringBuilder sb = new StringBuilder();
207 sb.append("IndexCreationFeature:{").append("skipPackedIndexCreation=").append(skipPackedIndexCreation)
208 .append(",indexPath=").append(indexPath).append(",packedIndexPath=").append(packedIndexPath).append("}");
209 return sb.toString();
210 }
211 }