]> source.dussan.org Git - archiva.git/blob
de7d279ee5bf978a50dd1854bcdbab4496e47d1f
[archiva.git] /
1 package org.apache.archiva.repository.maven;
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.common.filelock.FileLockManager;
23 import org.apache.archiva.configuration.AbstractRepositoryConfiguration;
24 import org.apache.archiva.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
27 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
28 import org.apache.archiva.event.Event;
29 import org.apache.archiva.event.EventHandler;
30 import org.apache.archiva.repository.EditableManagedRepository;
31 import org.apache.archiva.repository.EditableRemoteRepository;
32 import org.apache.archiva.repository.EditableRepository;
33 import org.apache.archiva.repository.EditableRepositoryGroup;
34 import org.apache.archiva.repository.ManagedRepository;
35 import org.apache.archiva.repository.ReleaseScheme;
36 import org.apache.archiva.repository.RemoteRepository;
37 import org.apache.archiva.repository.Repository;
38 import org.apache.archiva.repository.RepositoryCredentials;
39 import org.apache.archiva.repository.RepositoryException;
40 import org.apache.archiva.repository.RepositoryGroup;
41 import org.apache.archiva.repository.RepositoryProvider;
42 import org.apache.archiva.repository.RepositoryType;
43 import org.apache.archiva.repository.UnsupportedURIException;
44 import org.apache.archiva.repository.base.managed.BasicManagedRepository;
45 import org.apache.archiva.repository.base.PasswordCredentials;
46 import org.apache.archiva.repository.event.RepositoryEvent;
47 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
48 import org.apache.archiva.repository.features.IndexCreationFeature;
49 import org.apache.archiva.repository.features.RemoteIndexFeature;
50 import org.apache.archiva.repository.features.StagingRepositoryFeature;
51 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
52 import org.apache.commons.lang3.StringUtils;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.springframework.stereotype.Service;
56
57 import javax.inject.Inject;
58 import java.io.IOException;
59 import java.net.URI;
60 import java.net.URISyntaxException;
61 import java.nio.file.Files;
62 import java.nio.file.Path;
63 import java.nio.file.Paths;
64 import java.time.Duration;
65 import java.time.Period;
66 import java.time.temporal.ChronoUnit;
67 import java.util.ArrayList;
68 import java.util.HashSet;
69 import java.util.List;
70 import java.util.Set;
71 import java.util.stream.Collectors;
72
73 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
74 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
75
76 /**
77  * Provider for the maven2 repository implementation
78  */
79 @Service("mavenRepositoryProvider")
80 public class MavenRepositoryProvider implements RepositoryProvider {
81
82
83     @Inject
84     private ArchivaConfiguration archivaConfiguration;
85
86     @Inject
87     private FileLockManager fileLockManager;
88
89     private final List<EventHandler<? super RepositoryEvent>> repositoryEventHandlers = new ArrayList<>( );
90
91     private static final Logger log = LoggerFactory.getLogger(MavenRepositoryProvider.class);
92
93     static final Set<RepositoryType> TYPES = new HashSet<>();
94
95     static {
96         TYPES.add(RepositoryType.MAVEN);
97     }
98
99     @Override
100     public Set<RepositoryType> provides() {
101         return TYPES;
102     }
103
104     @Override
105     public MavenManagedRepository createManagedInstance(String id, String name) {
106         return createManagedInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir());
107     }
108
109     public MavenManagedRepository createManagedInstance(String id, String name, Path baseDir) {
110         FilesystemStorage storage;
111         try {
112             storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
113         } catch (IOException e) {
114             log.error("Could not initialize fileystem for repository {}", id);
115             throw new RuntimeException(e);
116         }
117         MavenManagedRepository repo = new MavenManagedRepository( id, name, storage );
118         registerEventHandler( repo );
119         return repo;
120     }
121
122     @Override
123     public MavenRemoteRepository createRemoteInstance(String id, String name) {
124         return createRemoteInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir());
125     }
126
127     public MavenRemoteRepository createRemoteInstance(String id, String name, Path baseDir) {
128         FilesystemStorage storage;
129         try {
130             storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
131         } catch (IOException e) {
132             log.error("Could not initialize filesystem for repository {}: '{}'", id, e.getMessage());
133             throw new RuntimeException(e);
134         }
135         MavenRemoteRepository repo = new MavenRemoteRepository( id, name, storage );
136         registerEventHandler( repo );
137         return repo;
138     }
139
140     @Override
141     public EditableRepositoryGroup createRepositoryGroup(String id, String name) {
142         return createRepositoryGroup(id, name, archivaConfiguration.getRepositoryGroupBaseDir().resolve( id ));
143     }
144
145     public MavenRepositoryGroup createRepositoryGroup(String id, String name, Path repositoryPath) {
146         FilesystemStorage storage;
147         try {
148             storage = new FilesystemStorage(repositoryPath, fileLockManager);
149         } catch (IOException e) {
150             log.error("Could not initialize filesystem for repository {}: '{}'", id, e.getMessage());
151             throw new RuntimeException(e);
152         }
153         MavenRepositoryGroup group = new MavenRepositoryGroup( id, name, storage );
154         registerEventHandler( group );
155         return group;
156     }
157
158     private void registerEventHandler( Repository repo ) {
159         for (EventHandler<? super RepositoryEvent> eventHandler : repositoryEventHandlers) {
160             repo.registerEventHandler( RepositoryEvent.ANY, eventHandler );
161         }
162     }
163
164     private URI getURIFromString(String uriStr) throws RepositoryException {
165         URI uri;
166         try {
167             if (StringUtils.isEmpty(uriStr)) {
168                 return new URI("");
169             }
170             if (uriStr.startsWith("/")) {
171                 // only absolute paths are prepended with file scheme
172                 uri = new URI("file://" + uriStr);
173             } else if (uriStr.contains(":\\")) {
174                 //windows absolute path drive 
175                 uri = new URI("file:///" + uriStr.replaceAll("\\\\", "/"));
176             } else {
177                 uri = new URI(uriStr);
178             }
179             if (uri.getScheme() != null && !"file".equals(uri.getScheme())) {
180                 log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri);
181                 throw new RepositoryException("The uri " + uriStr + " is not valid. Only file:// URI is allowed for maven.");
182             }
183         } catch (URISyntaxException e) {
184             String newCfg = "file://" + uriStr;
185             try {
186                 uri = new URI(newCfg);
187             } catch (URISyntaxException e1) {
188                 log.error("Could not create URI from {} -> {}", uriStr, newCfg);
189                 throw new RepositoryException("The config entry " + uriStr + " cannot be converted to URI.");
190             }
191         }
192         log.debug("Setting location uri: {}", uri);
193         return uri;
194     }
195
196     @Override
197     public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException {
198         MavenManagedRepository repo = createManagedInstance(cfg.getId(), cfg.getName(), Paths.get(cfg.getLocation()).getParent());
199         updateManagedInstance(repo, cfg);
200         return repo;
201     }
202
203     @Override
204     public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
205         try {
206             repo.setLocation(getURIFromString(cfg.getLocation()));
207         } catch (UnsupportedURIException e) {
208             throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
209         }
210         setBaseConfig(repo, cfg);
211         Path repoDir = repo.getRoot().getFilePath();
212         if (!Files.exists(repoDir)) {
213             log.debug("Creating repo directory {}", repoDir);
214             try {
215                 Files.createDirectories(repoDir);
216             } catch (IOException e) {
217                 log.error("Could not create directory {} for repository {}", repoDir, repo.getId(), e);
218                 throw new RepositoryException("Could not create directory for repository " + repoDir);
219             }
220         }
221         repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
222         repo.setBlocksRedeployment(cfg.isBlockRedeployments());
223         repo.setScanned(cfg.isScanned());
224         if (cfg.isReleases()) {
225             repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
226         } else {
227             repo.removeActiveReleaseScheme(ReleaseScheme.RELEASE);
228         }
229         if (cfg.isSnapshots()) {
230             repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
231         } else {
232             repo.removeActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
233         }
234
235         StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
236         stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
237
238         IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
239         indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
240         String indexDir = StringUtils.isEmpty( cfg.getIndexDir() ) ? DEFAULT_INDEX_PATH : cfg.getIndexDir();
241         String packedIndexDir = StringUtils.isEmpty( cfg.getPackedIndexDir() ) ? DEFAULT_PACKED_INDEX_PATH : cfg.getPackedIndexDir();
242         indexCreationFeature.setIndexPath(getURIFromString(indexDir));
243         indexCreationFeature.setPackedIndexPath(getURIFromString(packedIndexDir));
244
245         ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
246
247         artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
248         artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
249         artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
250     }
251
252
253     @Override
254     public ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException {
255         log.debug("Creating staging instance for {}", baseConfiguration.getId());
256         return createManagedInstance(getStageRepoConfig(baseConfiguration));
257     }
258
259
260     @Override
261     public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException {
262         MavenRemoteRepository repo = createRemoteInstance(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir());
263         updateRemoteInstance(repo, cfg);
264         return repo;
265     }
266
267     private String convertUriToPath(URI uri) {
268         if (uri.getScheme() == null) {
269             return uri.getPath();
270         } else if ("file".equals(uri.getScheme())) {
271             return Paths.get(uri).toString();
272         } else {
273             return uri.toString();
274         }
275     }
276
277     @Override
278     public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
279         setBaseConfig(repo, cfg);
280         repo.setCheckPath(cfg.getCheckPath());
281         repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
282         try {
283             repo.setLocation(new URI(cfg.getUrl()));
284         } catch (UnsupportedURIException | URISyntaxException e) {
285             log.error("Could not set remote url " + cfg.getUrl());
286             throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
287         }
288         repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
289         RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
290         remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
291         remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
292         remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
293         remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
294         if (cfg.isDownloadRemoteIndex()) {
295             try {
296                 remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
297             } catch (URISyntaxException e) {
298                 log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
299                 remoteIndexFeature.setDownloadRemoteIndex(false);
300                 remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
301             }
302         }
303         for ( Object key : cfg.getExtraHeaders().keySet() ) {
304             repo.addExtraHeader( key.toString(), cfg.getExtraHeaders().get(key).toString() );
305         }
306         for ( Object key : cfg.getExtraParameters().keySet() ) {
307             repo.addExtraParameter( key.toString(), cfg.getExtraParameters().get(key).toString() );
308         }
309         PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
310         if (cfg.getPassword() != null && cfg.getUsername() != null) {
311             credentials.setPassword(cfg.getPassword().toCharArray());
312             credentials.setUsername(cfg.getUsername());
313             repo.setCredentials(credentials);
314         } else {
315             credentials.setPassword(new char[0]);
316         }
317         IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
318         if (cfg.getIndexDir() != null) {
319             indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
320         }
321         if (cfg.getPackedIndexDir() != null) {
322             indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
323         }
324         log.debug("Updated remote instance {}", repo);
325     }
326
327     @Override
328     public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException {
329         Path repositoryPath = getRepositoryGroupPath( configuration );
330         MavenRepositoryGroup newGrp = createRepositoryGroup(configuration.getId(), configuration.getName(),
331                 repositoryPath);
332         updateRepositoryGroupInstance(newGrp, configuration);
333         return newGrp;
334     }
335
336     private Path getRepositoryGroupPath(RepositoryGroupConfiguration configuration) {
337         if (StringUtils.isNotEmpty( configuration.getLocation() )) {
338             return Paths.get( configuration.getLocation( ) );
339         } else {
340             return getArchivaConfiguration( ).getRepositoryGroupBaseDir( ).resolve( configuration.getId( ) );
341         }
342     }
343
344     @Override
345     public void updateRepositoryGroupInstance(EditableRepositoryGroup repositoryGroup, RepositoryGroupConfiguration configuration) throws RepositoryException {
346         repositoryGroup.setName(repositoryGroup.getPrimaryLocale(), configuration.getName());
347         repositoryGroup.setMergedIndexTTL(configuration.getMergedIndexTtl());
348         repositoryGroup.setSchedulingDefinition(configuration.getCronExpression());
349         if (repositoryGroup.supportsFeature( IndexCreationFeature.class )) {
350             IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get();
351             indexCreationFeature.setIndexPath( getURIFromString(configuration.getMergedIndexPath()) );
352             Path localPath = Paths.get(configuration.getMergedIndexPath());
353             Path repoGroupPath = repositoryGroup.getRoot().getFilePath().toAbsolutePath();
354             if (localPath.isAbsolute() && !localPath.startsWith(repoGroupPath)) {
355                 try {
356                     FilesystemStorage storage = new FilesystemStorage(localPath.getParent(), fileLockManager);
357                     indexCreationFeature.setLocalIndexPath(storage.getAsset(localPath.getFileName().toString()));
358                 } catch (IOException e) {
359                     throw new RepositoryException("Could not initialize storage for index path "+localPath);
360                 }
361             } else if (localPath.isAbsolute()) {
362                 indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(repoGroupPath.relativize(localPath).toString()));
363             } else
364             {
365                 indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(localPath.toString()));
366             }
367         }
368         // References to other repositories are set filled by the registry
369     }
370
371     @Override
372     public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
373         if (!(remoteRepository instanceof MavenRemoteRepository)) {
374             log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
375             throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
376         }
377         RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
378         cfg.setType(remoteRepository.getType().toString());
379         cfg.setId(remoteRepository.getId());
380         cfg.setName(remoteRepository.getName());
381         cfg.setDescription(remoteRepository.getDescription());
382         cfg.setUrl(remoteRepository.getLocation().toString());
383         cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
384         cfg.setCheckPath(remoteRepository.getCheckPath());
385         RepositoryCredentials creds = remoteRepository.getLoginCredentials();
386         if (creds != null) {
387             if (creds instanceof PasswordCredentials) {
388                 PasswordCredentials pCreds = (PasswordCredentials) creds;
389                 cfg.setPassword(new String(pCreds.getPassword()));
390                 cfg.setUsername(pCreds.getUsername());
391             }
392         }
393         cfg.setLayout(remoteRepository.getLayout());
394         cfg.setExtraParameters(remoteRepository.getExtraParameters());
395         cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
396         cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
397
398         IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
399         cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
400         cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
401
402         RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
403         if (remoteIndexFeature.getIndexUri() != null) {
404             cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
405         }
406         cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
407         cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
408         cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
409         cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
410         if (!StringUtils.isEmpty(remoteIndexFeature.getProxyId())) {
411             cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
412         } else {
413             cfg.setRemoteDownloadNetworkProxyId("");
414         }
415
416
417
418
419         return cfg;
420
421     }
422
423     @Override
424     public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
425         if (!(managedRepository instanceof MavenManagedRepository || managedRepository instanceof BasicManagedRepository )) {
426             log.error("Wrong remote repository type " + managedRepository.getClass().getName());
427             throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName());
428         }
429         ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
430         cfg.setType(managedRepository.getType().toString());
431         cfg.setId(managedRepository.getId());
432         cfg.setName(managedRepository.getName());
433         cfg.setDescription(managedRepository.getDescription());
434         cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
435         cfg.setLayout(managedRepository.getLayout());
436         cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
437         cfg.setScanned(managedRepository.isScanned());
438         cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
439         StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get();
440         cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
441         IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
442         cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
443         cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
444         cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
445
446         ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
447         cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
448         cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
449         cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
450
451         cfg.setReleases( managedRepository.getActiveReleaseSchemes( ).contains( ReleaseScheme.RELEASE ) );
452         cfg.setSnapshots( managedRepository.getActiveReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) );
453         return cfg;
454
455     }
456
457     @Override
458     public RepositoryGroupConfiguration getRepositoryGroupConfiguration(RepositoryGroup repositoryGroup) throws RepositoryException {
459         if (repositoryGroup.getType() != RepositoryType.MAVEN) {
460             throw new RepositoryException("The given repository group is not of MAVEN type");
461         }
462         RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration();
463         cfg.setId(repositoryGroup.getId());
464         cfg.setName(repositoryGroup.getName());
465         if (repositoryGroup.supportsFeature( IndexCreationFeature.class ))
466         {
467             IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get();
468
469             cfg.setMergedIndexPath( indexCreationFeature.getIndexPath().toString() );
470         }
471         cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL());
472         cfg.setRepositories(repositoryGroup.getRepositories().stream().map( Repository::getId ).collect(Collectors.toList()));
473         cfg.setCronExpression(repositoryGroup.getSchedulingDefinition());
474         return cfg;
475     }
476
477     @Override
478     public void addRepositoryEventHandler( EventHandler<? super RepositoryEvent> eventHandler )
479     {
480         this.repositoryEventHandlers.add( eventHandler );
481     }
482
483     private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) {
484         ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
485         stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
486         stagingRepository.setLayout(repository.getLayout());
487         stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
488         stagingRepository.setBlockRedeployments(repository.isBlockRedeployments());
489         stagingRepository.setRetentionPeriod(repository.getRetentionPeriod());
490         stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots());
491         stagingRepository.setStageRepoNeeded(false);
492
493         String path = repository.getLocation();
494         int lastIndex = path.replace('\\', '/').lastIndexOf('/');
495         stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId());
496
497         if (StringUtils.isNotBlank(repository.getIndexDir())) {
498             Path indexDir;
499             try {
500                 indexDir = Paths.get(new URI(repository.getIndexDir().startsWith("file://") ? repository.getIndexDir() : "file://" + repository.getIndexDir()));
501                 if (indexDir.isAbsolute()) {
502                     Path newDir = indexDir.getParent().resolve(indexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
503                     log.debug("Changing index directory {} -> {}", indexDir, newDir);
504                     stagingRepository.setIndexDir(newDir.toString());
505                 } else {
506                     log.debug("Keeping index directory {}", repository.getIndexDir());
507                     stagingRepository.setIndexDir(repository.getIndexDir());
508                 }
509             } catch (URISyntaxException e) {
510                 log.error("Could not parse index path as uri {}", repository.getIndexDir());
511                 stagingRepository.setIndexDir("");
512             }
513             // in case of absolute dir do not use the same
514         }
515         if (StringUtils.isNotBlank(repository.getPackedIndexDir())) {
516             Path packedIndexDir;
517             packedIndexDir = Paths.get(repository.getPackedIndexDir());
518             if (packedIndexDir.isAbsolute()) {
519                 Path newDir = packedIndexDir.getParent().resolve(packedIndexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
520                 log.debug("Changing index directory {} -> {}", packedIndexDir, newDir);
521                 stagingRepository.setPackedIndexDir(newDir.toString());
522             } else {
523                 log.debug("Keeping index directory {}", repository.getPackedIndexDir());
524                 stagingRepository.setPackedIndexDir(repository.getPackedIndexDir());
525             }
526             // in case of absolute dir do not use the same
527         }
528         stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression());
529         stagingRepository.setReleases(repository.isReleases());
530         stagingRepository.setRetentionCount(repository.getRetentionCount());
531         stagingRepository.setScanned(repository.isScanned());
532         stagingRepository.setSnapshots(repository.isSnapshots());
533         stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation());
534         // do not duplicate description
535         //stagingRepository.getDescription("")
536         return stagingRepository;
537     }
538
539     private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg)
540     {
541
542         URI baseUri = archivaConfiguration.getRepositoryBaseDir().toUri();
543         repo.setBaseUri(baseUri);
544
545         repo.setName(repo.getPrimaryLocale(), cfg.getName());
546         repo.setDescription(repo.getPrimaryLocale(), cfg.getDescription());
547         repo.setLayout(cfg.getLayout());
548     }
549
550     public ArchivaConfiguration getArchivaConfiguration() {
551         return archivaConfiguration;
552     }
553
554     public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration) {
555         this.archivaConfiguration = archivaConfiguration;
556     }
557
558     @Override
559     public void handle(Event event) {
560         //
561     }
562
563 }