You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MavenRepositoryProvider.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. package org.apache.archiva.repository.maven2;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  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
  18. * under the License.
  19. */
  20. import org.apache.archiva.common.filelock.FileLockManager;
  21. import org.apache.archiva.configuration.*;
  22. import org.apache.archiva.repository.*;
  23. import org.apache.archiva.repository.storage.FilesystemStorage;
  24. import org.apache.archiva.repository.features.ArtifactCleanupFeature;
  25. import org.apache.archiva.repository.features.IndexCreationFeature;
  26. import org.apache.archiva.repository.features.RemoteIndexFeature;
  27. import org.apache.archiva.repository.features.StagingRepositoryFeature;
  28. import org.apache.commons.lang.StringUtils;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;
  31. import org.springframework.stereotype.Service;
  32. import javax.inject.Inject;
  33. import java.io.IOException;
  34. import java.net.URI;
  35. import java.net.URISyntaxException;
  36. import java.nio.file.Files;
  37. import java.nio.file.Path;
  38. import java.nio.file.Paths;
  39. import java.time.Duration;
  40. import java.time.Period;
  41. import java.time.temporal.ChronoUnit;
  42. import java.util.HashSet;
  43. import java.util.Set;
  44. import java.util.stream.Collectors;
  45. import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
  46. import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
  47. /**
  48. * Provider for the maven2 repository implementations
  49. */
  50. @Service("mavenRepositoryProvider")
  51. public class MavenRepositoryProvider implements RepositoryProvider {
  52. @Inject
  53. private ArchivaConfiguration archivaConfiguration;
  54. @Inject
  55. private FileLockManager fileLockManager;
  56. private static final Logger log = LoggerFactory.getLogger(MavenRepositoryProvider.class);
  57. static final Set<RepositoryType> TYPES = new HashSet<>();
  58. static {
  59. TYPES.add(RepositoryType.MAVEN);
  60. }
  61. @Override
  62. public Set<RepositoryType> provides() {
  63. return TYPES;
  64. }
  65. @Override
  66. public MavenManagedRepository createManagedInstance(String id, String name) {
  67. return createManagedInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir());
  68. }
  69. public MavenManagedRepository createManagedInstance(String id, String name, Path baseDir) {
  70. FilesystemStorage storage = null;
  71. try {
  72. storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
  73. } catch (IOException e) {
  74. log.error("Could not initialize fileystem for repository {}", id);
  75. throw new RuntimeException(e);
  76. }
  77. return new MavenManagedRepository(id, name, storage);
  78. }
  79. @Override
  80. public MavenRemoteRepository createRemoteInstance(String id, String name) {
  81. return createRemoteInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir());
  82. }
  83. public MavenRemoteRepository createRemoteInstance(String id, String name, Path baseDir) {
  84. FilesystemStorage storage = null;
  85. try {
  86. storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
  87. } catch (IOException e) {
  88. log.error("Could not initialize fileystem for repository {}", id);
  89. throw new RuntimeException(e);
  90. }
  91. return new MavenRemoteRepository(id, name, storage);
  92. }
  93. @Override
  94. public EditableRepositoryGroup createRepositoryGroup(String id, String name) {
  95. return createRepositoryGroup(id, name, archivaConfiguration.getRepositoryBaseDir());
  96. }
  97. public MavenRepositoryGroup createRepositoryGroup(String id, String name, Path baseDir) {
  98. FilesystemStorage storage = null;
  99. try {
  100. storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager);
  101. } catch (IOException e) {
  102. log.error("Could not initialize fileystem for repository {}", id);
  103. throw new RuntimeException(e);
  104. }
  105. return new MavenRepositoryGroup(id, name, storage);
  106. }
  107. private URI getURIFromString(String uriStr) throws RepositoryException {
  108. URI uri;
  109. try {
  110. if (StringUtils.isEmpty(uriStr)) {
  111. return new URI("");
  112. }
  113. if (uriStr.startsWith("/")) {
  114. // only absolute paths are prepended with file scheme
  115. uri = new URI("file://" + uriStr);
  116. } else {
  117. uri = new URI(uriStr);
  118. }
  119. if (uri.getScheme() != null && !"file".equals(uri.getScheme())) {
  120. log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri);
  121. throw new RepositoryException("The uri " + uriStr + " is not valid. Only file:// URI is allowed for maven.");
  122. }
  123. } catch (URISyntaxException e) {
  124. String newCfg = "file://" + uriStr;
  125. try {
  126. uri = new URI(newCfg);
  127. } catch (URISyntaxException e1) {
  128. log.error("Could not create URI from {} -> ", uriStr, newCfg);
  129. throw new RepositoryException("The config entry " + uriStr + " cannot be converted to URI.");
  130. }
  131. }
  132. log.debug("Setting location uri: {}", uri);
  133. return uri;
  134. }
  135. @Override
  136. public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException {
  137. MavenManagedRepository repo = createManagedInstance(cfg.getId(), cfg.getName(), Paths.get(cfg.getLocation()).getParent());
  138. updateManagedInstance(repo, cfg);
  139. return repo;
  140. }
  141. @Override
  142. public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
  143. try {
  144. repo.setLocation(getURIFromString(cfg.getLocation()));
  145. } catch (UnsupportedURIException e) {
  146. throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
  147. }
  148. setBaseConfig(repo, cfg);
  149. Path repoDir = repo.getAsset("").getFilePath();
  150. if (!Files.exists(repoDir)) {
  151. log.debug("Creating repo directory {}", repoDir);
  152. try {
  153. Files.createDirectories(repoDir);
  154. } catch (IOException e) {
  155. log.error("Could not create directory {} for repository {}", repoDir, repo.getId(), e);
  156. throw new RepositoryException("Could not create directory for repository " + repoDir);
  157. }
  158. }
  159. repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
  160. repo.setBlocksRedeployment(cfg.isBlockRedeployments());
  161. repo.setScanned(cfg.isScanned());
  162. if (cfg.isReleases()) {
  163. repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
  164. }
  165. if (cfg.isSnapshots()) {
  166. repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
  167. }
  168. StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
  169. stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
  170. IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
  171. indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
  172. String indexDir = StringUtils.isEmpty( cfg.getIndexDir() ) ? DEFAULT_INDEX_PATH : cfg.getIndexDir();
  173. String packedIndexDir = StringUtils.isEmpty( cfg.getPackedIndexDir() ) ? DEFAULT_PACKED_INDEX_PATH : cfg.getPackedIndexDir();
  174. indexCreationFeature.setIndexPath(getURIFromString(indexDir));
  175. indexCreationFeature.setPackedIndexPath(getURIFromString(packedIndexDir));
  176. ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
  177. artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
  178. artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
  179. artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
  180. }
  181. @Override
  182. public ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException {
  183. log.debug("Creating staging instance for {}", baseConfiguration.getId());
  184. return createManagedInstance(getStageRepoConfig(baseConfiguration));
  185. }
  186. @Override
  187. public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException {
  188. MavenRemoteRepository repo = createRemoteInstance(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir());
  189. updateRemoteInstance(repo, cfg);
  190. return repo;
  191. }
  192. private String convertUriToPath(URI uri) {
  193. if (uri.getScheme() == null) {
  194. return uri.getPath();
  195. } else if ("file".equals(uri.getScheme())) {
  196. return Paths.get(uri).toString();
  197. } else {
  198. return uri.toString();
  199. }
  200. }
  201. @Override
  202. public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
  203. setBaseConfig(repo, cfg);
  204. repo.setCheckPath(cfg.getCheckPath());
  205. repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
  206. try {
  207. repo.setLocation(new URI(cfg.getUrl()));
  208. } catch (UnsupportedURIException | URISyntaxException e) {
  209. log.error("Could not set remote url " + cfg.getUrl());
  210. throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
  211. }
  212. repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
  213. RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
  214. remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
  215. remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
  216. remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
  217. remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
  218. if (cfg.isDownloadRemoteIndex()) {
  219. try {
  220. remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
  221. } catch (URISyntaxException e) {
  222. log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
  223. remoteIndexFeature.setDownloadRemoteIndex(false);
  224. remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
  225. }
  226. }
  227. for ( Object key : cfg.getExtraHeaders().keySet() ) {
  228. repo.addExtraHeader( key.toString(), cfg.getExtraHeaders().get(key).toString() );
  229. }
  230. for ( Object key : cfg.getExtraParameters().keySet() ) {
  231. repo.addExtraParameter( key.toString(), cfg.getExtraParameters().get(key).toString() );
  232. }
  233. PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
  234. if (cfg.getPassword() != null && cfg.getUsername() != null) {
  235. credentials.setPassword(cfg.getPassword().toCharArray());
  236. credentials.setUsername(cfg.getUsername());
  237. repo.setCredentials(credentials);
  238. } else {
  239. credentials.setPassword(new char[0]);
  240. }
  241. IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
  242. if (cfg.getIndexDir() != null) {
  243. indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
  244. }
  245. if (cfg.getPackedIndexDir() != null) {
  246. indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
  247. }
  248. log.debug("Updated remote instance {}", repo);
  249. }
  250. @Override
  251. public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException {
  252. Path repositoryGroupBase = getArchivaConfiguration().getRepositoryGroupBaseDir();
  253. MavenRepositoryGroup newGrp = createRepositoryGroup(configuration.getId(), configuration.getName(),
  254. repositoryGroupBase);
  255. updateRepositoryGroupInstance(newGrp, configuration);
  256. return newGrp;
  257. }
  258. @Override
  259. public void updateRepositoryGroupInstance(EditableRepositoryGroup repositoryGroup, RepositoryGroupConfiguration configuration) throws RepositoryException {
  260. repositoryGroup.setName(repositoryGroup.getPrimaryLocale(), configuration.getName());
  261. repositoryGroup.setMergedIndexTTL(configuration.getMergedIndexTtl());
  262. repositoryGroup.setSchedulingDefinition(configuration.getCronExpression());
  263. if (repositoryGroup.supportsFeature( IndexCreationFeature.class )) {
  264. IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get();
  265. indexCreationFeature.setIndexPath( getURIFromString(configuration.getMergedIndexPath()) );
  266. Path localPath = Paths.get(configuration.getMergedIndexPath());
  267. Path repoGroupPath = repositoryGroup.getAsset("").getFilePath().toAbsolutePath();
  268. if (localPath.isAbsolute() && !localPath.startsWith(repoGroupPath)) {
  269. try {
  270. FilesystemStorage storage = new FilesystemStorage(localPath.getParent(), fileLockManager);
  271. indexCreationFeature.setLocalIndexPath(storage.getAsset(localPath.getFileName().toString()));
  272. } catch (IOException e) {
  273. throw new RepositoryException("Could not initialize storage for index path "+localPath);
  274. }
  275. } else if (localPath.isAbsolute()) {
  276. indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(repoGroupPath.relativize(localPath).toString()));
  277. } else
  278. {
  279. indexCreationFeature.setLocalIndexPath(repositoryGroup.getAsset(localPath.toString()));
  280. }
  281. }
  282. // References to other repositories are set filled by the registry
  283. }
  284. @Override
  285. public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
  286. if (!(remoteRepository instanceof MavenRemoteRepository)) {
  287. log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
  288. throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
  289. }
  290. RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
  291. cfg.setType(remoteRepository.getType().toString());
  292. cfg.setId(remoteRepository.getId());
  293. cfg.setName(remoteRepository.getName());
  294. cfg.setDescription(remoteRepository.getDescription());
  295. cfg.setUrl(remoteRepository.getLocation().toString());
  296. cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
  297. cfg.setCheckPath(remoteRepository.getCheckPath());
  298. RepositoryCredentials creds = remoteRepository.getLoginCredentials();
  299. if (creds != null) {
  300. if (creds instanceof PasswordCredentials) {
  301. PasswordCredentials pCreds = (PasswordCredentials) creds;
  302. cfg.setPassword(new String(pCreds.getPassword()));
  303. cfg.setUsername(pCreds.getUsername());
  304. }
  305. }
  306. cfg.setLayout(remoteRepository.getLayout());
  307. cfg.setExtraParameters(remoteRepository.getExtraParameters());
  308. cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
  309. cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
  310. IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
  311. cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
  312. cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
  313. RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
  314. cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
  315. cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
  316. cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
  317. cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
  318. cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
  319. return cfg;
  320. }
  321. @Override
  322. public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
  323. if (!(managedRepository instanceof MavenManagedRepository || managedRepository instanceof BasicManagedRepository)) {
  324. log.error("Wrong remote repository type " + managedRepository.getClass().getName());
  325. throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName());
  326. }
  327. ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
  328. cfg.setType(managedRepository.getType().toString());
  329. cfg.setId(managedRepository.getId());
  330. cfg.setName(managedRepository.getName());
  331. cfg.setDescription(managedRepository.getDescription());
  332. cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
  333. cfg.setLayout(managedRepository.getLayout());
  334. cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
  335. cfg.setScanned(managedRepository.isScanned());
  336. cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
  337. StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get();
  338. cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
  339. IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
  340. cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
  341. cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
  342. cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
  343. ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
  344. cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
  345. cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
  346. cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
  347. if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
  348. cfg.setReleases(true);
  349. } else {
  350. cfg.setReleases(false);
  351. }
  352. if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
  353. cfg.setSnapshots(true);
  354. } else {
  355. cfg.setSnapshots(false);
  356. }
  357. return cfg;
  358. }
  359. @Override
  360. public RepositoryGroupConfiguration getRepositoryGroupConfiguration(RepositoryGroup repositoryGroup) throws RepositoryException {
  361. if (repositoryGroup.getType() != RepositoryType.MAVEN) {
  362. throw new RepositoryException("The given repository group is not of MAVEN type");
  363. }
  364. RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration();
  365. cfg.setId(repositoryGroup.getId());
  366. cfg.setName(repositoryGroup.getName());
  367. if (repositoryGroup.supportsFeature( IndexCreationFeature.class ))
  368. {
  369. IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get();
  370. cfg.setMergedIndexPath( indexCreationFeature.getIndexPath().toString() );
  371. }
  372. cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL());
  373. cfg.setRepositories(repositoryGroup.getRepositories().stream().map(r -> r.getId()).collect(Collectors.toList()));
  374. cfg.setCronExpression(repositoryGroup.getSchedulingDefinition());
  375. return cfg;
  376. }
  377. private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) {
  378. ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
  379. stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
  380. stagingRepository.setLayout(repository.getLayout());
  381. stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
  382. stagingRepository.setBlockRedeployments(repository.isBlockRedeployments());
  383. stagingRepository.setRetentionPeriod(repository.getRetentionPeriod());
  384. stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots());
  385. stagingRepository.setStageRepoNeeded(false);
  386. String path = repository.getLocation();
  387. int lastIndex = path.replace('\\', '/').lastIndexOf('/');
  388. stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId());
  389. if (StringUtils.isNotBlank(repository.getIndexDir())) {
  390. Path indexDir = null;
  391. try {
  392. indexDir = Paths.get(new URI(repository.getIndexDir().startsWith("file://") ? repository.getIndexDir() : "file://" + repository.getIndexDir()));
  393. if (indexDir.isAbsolute()) {
  394. Path newDir = indexDir.getParent().resolve(indexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
  395. log.debug("Changing index directory {} -> {}", indexDir, newDir);
  396. stagingRepository.setIndexDir(newDir.toString());
  397. } else {
  398. log.debug("Keeping index directory {}", repository.getIndexDir());
  399. stagingRepository.setIndexDir(repository.getIndexDir());
  400. }
  401. } catch (URISyntaxException e) {
  402. log.error("Could not parse index path as uri {}", repository.getIndexDir());
  403. stagingRepository.setIndexDir("");
  404. }
  405. // in case of absolute dir do not use the same
  406. }
  407. if (StringUtils.isNotBlank(repository.getPackedIndexDir())) {
  408. Path packedIndexDir = null;
  409. packedIndexDir = Paths.get(repository.getPackedIndexDir());
  410. if (packedIndexDir.isAbsolute()) {
  411. Path newDir = packedIndexDir.getParent().resolve(packedIndexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
  412. log.debug("Changing index directory {} -> {}", packedIndexDir, newDir);
  413. stagingRepository.setPackedIndexDir(newDir.toString());
  414. } else {
  415. log.debug("Keeping index directory {}", repository.getPackedIndexDir());
  416. stagingRepository.setPackedIndexDir(repository.getPackedIndexDir());
  417. }
  418. // in case of absolute dir do not use the same
  419. }
  420. stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression());
  421. stagingRepository.setReleases(repository.isReleases());
  422. stagingRepository.setRetentionCount(repository.getRetentionCount());
  423. stagingRepository.setScanned(repository.isScanned());
  424. stagingRepository.setSnapshots(repository.isSnapshots());
  425. stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation());
  426. // do not duplicate description
  427. //stagingRepository.getDescription("")
  428. return stagingRepository;
  429. }
  430. private void setBaseConfig(EditableRepository repo, AbstractRepositoryConfiguration cfg) throws RepositoryException {
  431. URI baseUri = archivaConfiguration.getRepositoryBaseDir().toUri();
  432. repo.setBaseUri(baseUri);
  433. repo.setName(repo.getPrimaryLocale(), cfg.getName());
  434. repo.setDescription(repo.getPrimaryLocale(), cfg.getDescription());
  435. repo.setLayout(cfg.getLayout());
  436. }
  437. public ArchivaConfiguration getArchivaConfiguration() {
  438. return archivaConfiguration;
  439. }
  440. public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration) {
  441. this.archivaConfiguration = archivaConfiguration;
  442. }
  443. @Override
  444. public <T> void raise(RepositoryEvent<T> event) {
  445. //
  446. }
  447. }