1 package org.apache.archiva.maven.repository;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.filelock.FileLockManager;
22 import org.apache.archiva.configuration.AbstractRepositoryConfiguration;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
26 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
27 import org.apache.archiva.event.Event;
28 import org.apache.archiva.event.EventHandler;
29 import org.apache.archiva.repository.EditableManagedRepository;
30 import org.apache.archiva.repository.EditableRemoteRepository;
31 import org.apache.archiva.repository.EditableRepository;
32 import org.apache.archiva.repository.EditableRepositoryGroup;
33 import org.apache.archiva.repository.ManagedRepository;
34 import org.apache.archiva.repository.ReleaseScheme;
35 import org.apache.archiva.repository.RemoteRepository;
36 import org.apache.archiva.repository.Repository;
37 import org.apache.archiva.repository.RepositoryCredentials;
38 import org.apache.archiva.repository.RepositoryException;
39 import org.apache.archiva.repository.RepositoryGroup;
40 import org.apache.archiva.repository.RepositoryProvider;
41 import org.apache.archiva.repository.RepositoryType;
42 import org.apache.archiva.repository.UnsupportedURIException;
43 import org.apache.archiva.repository.base.managed.BasicManagedRepository;
44 import org.apache.archiva.repository.base.PasswordCredentials;
45 import org.apache.archiva.repository.event.RepositoryEvent;
46 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
47 import org.apache.archiva.repository.features.IndexCreationFeature;
48 import org.apache.archiva.repository.features.RemoteIndexFeature;
49 import org.apache.archiva.repository.features.StagingRepositoryFeature;
50 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
51 import org.apache.commons.lang3.StringUtils;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.springframework.stereotype.Service;
56 import javax.inject.Inject;
57 import java.io.IOException;
59 import java.net.URISyntaxException;
60 import java.nio.file.Files;
61 import java.nio.file.Path;
62 import java.nio.file.Paths;
63 import java.time.Duration;
64 import java.time.Period;
65 import java.time.temporal.ChronoUnit;
66 import java.util.ArrayList;
67 import java.util.HashSet;
68 import java.util.List;
70 import java.util.stream.Collectors;
72 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
73 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
76 * Provider for the maven2 repository implementation
78 @Service("mavenRepositoryProvider")
79 public class MavenRepositoryProvider implements RepositoryProvider {
83 private ArchivaConfiguration archivaConfiguration;
86 private FileLockManager fileLockManager;
88 private final List<EventHandler<? super RepositoryEvent>> repositoryEventHandlers = new ArrayList<>( );
90 private static final Logger log = LoggerFactory.getLogger(MavenRepositoryProvider.class);
92 static final Set<RepositoryType> TYPES = new HashSet<>();
95 TYPES.add(RepositoryType.MAVEN);
99 public Set<RepositoryType> provides() {
104 public MavenManagedRepository createManagedInstance(String id, String name) {
105 return createManagedInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir());
108 public MavenManagedRepository createManagedInstance(String id, String name, Path baseDir) {
109 FilesystemStorage storage;
111 storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
112 } catch (IOException e) {
113 log.error("Could not initialize fileystem for repository {}", id);
114 throw new RuntimeException(e);
116 MavenManagedRepository repo = new MavenManagedRepository( id, name, storage );
117 registerEventHandler( repo );
122 public MavenRemoteRepository createRemoteInstance(String id, String name) {
123 return createRemoteInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir());
126 public MavenRemoteRepository createRemoteInstance(String id, String name, Path baseDir) {
127 FilesystemStorage storage;
129 storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
130 } catch (IOException e) {
131 log.error("Could not initialize filesystem for repository {}: '{}'", id, e.getMessage());
132 throw new RuntimeException(e);
134 MavenRemoteRepository repo = new MavenRemoteRepository( id, name, storage );
135 registerEventHandler( repo );
140 public EditableRepositoryGroup createRepositoryGroup(String id, String name) {
141 return createRepositoryGroup(id, name, archivaConfiguration.getRepositoryGroupBaseDir().resolve( id ));
144 public MavenRepositoryGroup createRepositoryGroup(String id, String name, Path repositoryPath) {
145 FilesystemStorage storage;
147 storage = new FilesystemStorage(repositoryPath, fileLockManager);
148 } catch (IOException e) {
149 log.error("Could not initialize filesystem for repository {}: '{}'", id, e.getMessage());
150 throw new RuntimeException(e);
152 MavenRepositoryGroup group = new MavenRepositoryGroup( id, name, storage );
153 registerEventHandler( group );
157 private void registerEventHandler( Repository repo ) {
158 for (EventHandler<? super RepositoryEvent> eventHandler : repositoryEventHandlers) {
159 repo.registerEventHandler( RepositoryEvent.ANY, eventHandler );
163 private URI getURIFromString(String uriStr) throws RepositoryException {
166 if (StringUtils.isEmpty(uriStr)) {
169 if (uriStr.startsWith("/")) {
170 // only absolute paths are prepended with file scheme
171 uri = new URI("file://" + uriStr);
172 } else if (uriStr.contains(":\\")) {
173 //windows absolute path drive
174 uri = new URI("file:///" + uriStr.replaceAll("\\\\", "/"));
176 uri = new URI(uriStr);
178 if (uri.getScheme() != null && !"file".equals(uri.getScheme())) {
179 log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri);
180 throw new RepositoryException("The uri " + uriStr + " is not valid. Only file:// URI is allowed for maven.");
182 } catch (URISyntaxException e) {
183 String newCfg = "file://" + uriStr;
185 uri = new URI(newCfg);
186 } catch (URISyntaxException e1) {
187 log.error("Could not create URI from {} -> {}", uriStr, newCfg);
188 throw new RepositoryException("The config entry " + uriStr + " cannot be converted to URI.");
191 log.debug("Setting location uri: {}", uri);
196 public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException {
197 MavenManagedRepository repo = createManagedInstance(cfg.getId(), cfg.getName(), Paths.get(cfg.getLocation()).getParent());
198 updateManagedInstance(repo, cfg);
203 public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
205 repo.setLocation(getURIFromString(cfg.getLocation()));
206 } catch (UnsupportedURIException e) {
207 throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
209 setBaseConfig(repo, cfg);
210 Path repoDir = repo.getRoot().getFilePath();
211 if (!Files.exists(repoDir)) {
212 log.debug("Creating repo directory {}", repoDir);
214 Files.createDirectories(repoDir);
215 } catch (IOException e) {
216 log.error("Could not create directory {} for repository {}", repoDir, repo.getId(), e);
217 throw new RepositoryException("Could not create directory for repository " + repoDir);
220 repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
221 repo.setBlocksRedeployment(cfg.isBlockRedeployments());
222 repo.setScanned(cfg.isScanned());
223 if (cfg.isReleases()) {
224 repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
226 repo.removeActiveReleaseScheme(ReleaseScheme.RELEASE);
228 if (cfg.isSnapshots()) {
229 repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
231 repo.removeActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
234 StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
235 stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
237 IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
238 indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
239 String indexDir = StringUtils.isEmpty( cfg.getIndexDir() ) ? DEFAULT_INDEX_PATH : cfg.getIndexDir();
240 String packedIndexDir = StringUtils.isEmpty( cfg.getPackedIndexDir() ) ? DEFAULT_PACKED_INDEX_PATH : cfg.getPackedIndexDir();
241 indexCreationFeature.setIndexPath(getURIFromString(indexDir));
242 indexCreationFeature.setPackedIndexPath(getURIFromString(packedIndexDir));
244 ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
246 artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
247 artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
248 artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
253 public ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException {
254 log.debug("Creating staging instance for {}", baseConfiguration.getId());
255 return createManagedInstance(getStageRepoConfig(baseConfiguration));
260 public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException {
261 MavenRemoteRepository repo = createRemoteInstance(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir());
262 updateRemoteInstance(repo, cfg);
266 private String convertUriToPath(URI uri) {
267 if (uri.getScheme() == null) {
268 return uri.getPath();
269 } else if ("file".equals(uri.getScheme())) {
270 return Paths.get(uri).toString();
272 return uri.toString();
277 public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
278 setBaseConfig(repo, cfg);
279 repo.setCheckPath(cfg.getCheckPath());
280 repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
282 repo.setLocation(new URI(cfg.getUrl()));
283 } catch (UnsupportedURIException | URISyntaxException e) {
284 log.error("Could not set remote url " + cfg.getUrl());
285 throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
287 repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
288 RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
289 remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
290 remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
291 remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
292 remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
293 if (cfg.isDownloadRemoteIndex()) {
295 remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
296 } catch (URISyntaxException e) {
297 log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
298 remoteIndexFeature.setDownloadRemoteIndex(false);
299 remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
302 for ( Object key : cfg.getExtraHeaders().keySet() ) {
303 repo.addExtraHeader( key.toString(), cfg.getExtraHeaders().get(key).toString() );
305 for ( Object key : cfg.getExtraParameters().keySet() ) {
306 repo.addExtraParameter( key.toString(), cfg.getExtraParameters().get(key).toString() );
308 PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
309 if (cfg.getPassword() != null && cfg.getUsername() != null) {
310 credentials.setPassword(cfg.getPassword().toCharArray());
311 credentials.setUsername(cfg.getUsername());
312 repo.setCredentials(credentials);
314 credentials.setPassword(new char[0]);
316 IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
317 if ( !StringUtils.isEmpty( cfg.getIndexDir( ) ) )
319 indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir( ) ) );
321 if (!StringUtils.isEmpty( cfg.getPackedIndexDir() )) {
322 indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
324 log.debug("Updated remote instance {}", repo);
328 public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException {
329 Path repositoryPath = getRepositoryGroupPath( configuration );
330 MavenRepositoryGroup newGrp = createRepositoryGroup(configuration.getId(), configuration.getName(),
332 updateRepositoryGroupInstance(newGrp, configuration);
336 private Path getRepositoryGroupPath(RepositoryGroupConfiguration configuration) {
337 if (StringUtils.isNotEmpty( configuration.getLocation() )) {
338 return Paths.get( configuration.getLocation( ) );
340 return getArchivaConfiguration( ).getRepositoryGroupBaseDir( ).resolve( configuration.getId( ) );
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)) {
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);
361 } else if (localPath.isAbsolute()) {
362 indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(repoGroupPath.relativize(localPath).toString()));
365 indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(localPath.toString()));
368 // References to other repositories are set filled by the registry
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());
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();
387 if (creds instanceof PasswordCredentials) {
388 PasswordCredentials pCreds = (PasswordCredentials) creds;
389 cfg.setPassword(new String(pCreds.getPassword()));
390 cfg.setUsername(pCreds.getUsername());
393 cfg.setLayout(remoteRepository.getLayout());
394 cfg.setExtraParameters(remoteRepository.getExtraParameters());
395 cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
396 cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
398 IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
399 cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
400 cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
402 RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
403 if ( remoteIndexFeature.getIndexUri( ) == null )
405 cfg.setRemoteIndexUrl( "" );
409 cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
411 cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
412 cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
413 cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
414 cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
415 if ( StringUtils.isEmpty( remoteIndexFeature.getProxyId( ) ) )
417 cfg.setRemoteDownloadNetworkProxyId("");
421 cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
430 public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
431 if (!(managedRepository instanceof MavenManagedRepository || managedRepository instanceof BasicManagedRepository )) {
432 log.error("Wrong remote repository type " + managedRepository.getClass().getName());
433 throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName());
435 ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
436 cfg.setType(managedRepository.getType().toString());
437 cfg.setId(managedRepository.getId());
438 cfg.setName(managedRepository.getName());
439 cfg.setDescription(managedRepository.getDescription());
440 cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
441 cfg.setLayout(managedRepository.getLayout());
442 cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
443 cfg.setScanned(managedRepository.isScanned());
444 cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
445 StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get();
446 cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
447 IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
448 cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
449 cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
450 cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
452 ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
453 cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
454 cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
455 cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
457 cfg.setReleases( managedRepository.getActiveReleaseSchemes( ).contains( ReleaseScheme.RELEASE ) );
458 cfg.setSnapshots( managedRepository.getActiveReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) );
464 public RepositoryGroupConfiguration getRepositoryGroupConfiguration(RepositoryGroup repositoryGroup) throws RepositoryException {
465 if (repositoryGroup.getType() != RepositoryType.MAVEN) {
466 throw new RepositoryException("The given repository group is not of MAVEN type");
468 RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration();
469 cfg.setId(repositoryGroup.getId());
470 cfg.setName(repositoryGroup.getName());
471 if (repositoryGroup.supportsFeature( IndexCreationFeature.class ))
473 IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get();
475 cfg.setMergedIndexPath( indexCreationFeature.getIndexPath().toString() );
477 cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL());
478 cfg.setRepositories(repositoryGroup.getRepositories().stream().map( Repository::getId ).collect(Collectors.toList()));
479 cfg.setCronExpression(repositoryGroup.getSchedulingDefinition());
484 public void addRepositoryEventHandler( EventHandler<? super RepositoryEvent> eventHandler )
486 this.repositoryEventHandlers.add( eventHandler );
489 private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) {
490 ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
491 stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
492 stagingRepository.setLayout(repository.getLayout());
493 stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
494 stagingRepository.setBlockRedeployments(repository.isBlockRedeployments());
495 stagingRepository.setRetentionPeriod(repository.getRetentionPeriod());
496 stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots());
497 stagingRepository.setStageRepoNeeded(false);
499 String path = repository.getLocation();
500 int lastIndex = path.replace('\\', '/').lastIndexOf('/');
501 stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId());
503 if (StringUtils.isNotBlank(repository.getIndexDir())) {
506 if (repository.getIndexDir().startsWith( "file:" )) {
507 indexDir = Paths.get( new URI( repository.getIndexDir( ) ) );
510 indexDir = Paths.get( repository.getIndexDir( ) );
512 if (indexDir.isAbsolute()) {
513 Path newDir = indexDir.getParent().resolve(indexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
514 log.debug("Changing index directory {} -> {}", indexDir, newDir);
515 stagingRepository.setIndexDir(newDir.toString());
517 log.debug("Keeping index directory {}", repository.getIndexDir());
518 stagingRepository.setIndexDir(repository.getIndexDir());
520 } catch (URISyntaxException e) {
521 log.error("Could not parse index path as uri {}", repository.getIndexDir());
522 stagingRepository.setIndexDir("");
524 // in case of absolute dir do not use the same
526 if (StringUtils.isNotBlank(repository.getPackedIndexDir())) {
528 packedIndexDir = Paths.get(repository.getPackedIndexDir());
529 if (packedIndexDir.isAbsolute()) {
530 Path newDir = packedIndexDir.getParent().resolve(packedIndexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
531 log.debug("Changing index directory {} -> {}", packedIndexDir, newDir);
532 stagingRepository.setPackedIndexDir(newDir.toString());
534 log.debug("Keeping index directory {}", repository.getPackedIndexDir());
535 stagingRepository.setPackedIndexDir(repository.getPackedIndexDir());
537 // in case of absolute dir do not use the same
539 stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression());
540 stagingRepository.setReleases(repository.isReleases());
541 stagingRepository.setRetentionCount(repository.getRetentionCount());
542 stagingRepository.setScanned(repository.isScanned());
543 stagingRepository.setSnapshots(repository.isSnapshots());
544 stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation());
545 // do not duplicate description
546 //stagingRepository.getDescription("")
547 return stagingRepository;
550 private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg)
553 URI baseUri = archivaConfiguration.getRepositoryBaseDir().toUri();
554 repo.setBaseUri(baseUri);
556 repo.setName(repo.getPrimaryLocale(), cfg.getName());
557 repo.setDescription(repo.getPrimaryLocale(), cfg.getDescription());
558 repo.setLayout(cfg.getLayout());
561 public ArchivaConfiguration getArchivaConfiguration() {
562 return archivaConfiguration;
565 public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration) {
566 this.archivaConfiguration = archivaConfiguration;
570 public void handle(Event event) {