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.

ManagedRepositoryContent.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. package org.apache.archiva.repository;
  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.model.ArchivaArtifact;
  21. import org.apache.archiva.model.ArtifactReference;
  22. import org.apache.archiva.model.ProjectReference;
  23. import org.apache.archiva.model.VersionedReference;
  24. import org.apache.archiva.repository.content.Artifact;
  25. import org.apache.archiva.repository.content.ContentItem;
  26. import org.apache.archiva.repository.content.ItemNotFoundException;
  27. import org.apache.archiva.repository.content.ItemSelector;
  28. import org.apache.archiva.repository.content.Namespace;
  29. import org.apache.archiva.repository.content.Project;
  30. import org.apache.archiva.repository.content.Version;
  31. import org.apache.archiva.repository.storage.StorageAsset;
  32. import java.nio.file.Path;
  33. import java.util.List;
  34. import java.util.Set;
  35. import java.util.stream.Stream;
  36. /**
  37. * ManagedRepositoryContent interface for interacting with a managed repository in an abstract way,
  38. * without the need for processing based on filesystem paths, or working with the database.
  39. *
  40. * This interface
  41. */
  42. public interface ManagedRepositoryContent extends RepositoryContent
  43. {
  44. /// ***************** New generation interface **********************
  45. /**
  46. * Removes the specified content item and if the item is a container or directory,
  47. * all content stored under the given item.
  48. *
  49. * @param item the item.
  50. * @throws ItemNotFoundException if the item cannot be found
  51. * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
  52. * to the artifacts failed
  53. */
  54. void deleteItem( ContentItem item) throws ItemNotFoundException, ContentAccessException;
  55. /**
  56. * Returns a item for the given selector. The type of the returned item depends on the
  57. * selector.
  58. *
  59. * @param selector the item selector
  60. * @return the content item that matches the given selector
  61. * @throws ContentAccessException if an error occured while accessing the backend
  62. * @throws IllegalArgumentException if the selector does not select a valid content item
  63. */
  64. ContentItem getItem(ItemSelector selector) throws ContentAccessException, IllegalArgumentException;
  65. /**
  66. * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other
  67. * coordinates are ignored.
  68. * The following coordinates must be set at the given selector:
  69. * <ul>
  70. * <li>namespace</li>
  71. * </ul>
  72. * If not, a {@link IllegalArgumentException} will be thrown.
  73. *
  74. * @param namespaceSelector the selectory with the namespace coordinates
  75. * @return the namespace
  76. * @throws ItemNotFoundException if the item does not exist
  77. * @throws ContentAccessException if the item cannot be accessed
  78. * @throws IllegalArgumentException if the selector has no namespace specified
  79. */
  80. Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException;
  81. /**
  82. * Returns the project for the given coordinates.
  83. * The following coordinates must be set at the given selector:
  84. * <ul>
  85. * <li>namespace</li>
  86. * <li>projectId</li>
  87. * </ul>
  88. * If not, a {@link IllegalArgumentException} will be thrown.
  89. * Additional coordinates will be ignored.
  90. *
  91. * @param projectSelector
  92. * @return the project instance
  93. * @throws ItemNotFoundException if the project does not exist
  94. * @throws ContentAccessException if the item cannot be accessed
  95. * @throws IllegalArgumentException if the selector does not specify the required coordinates
  96. */
  97. Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException;
  98. /**
  99. * Returns the version for the given coordinates.
  100. * The following coordinates must be set at the given selector:
  101. * <ul>
  102. * <li>namespace</li>
  103. * <li>projectId</li>
  104. * <li>version</li>
  105. * </ul>
  106. * If not, a {@link IllegalArgumentException} will be thrown.
  107. *
  108. * Additional coordinates will be ignored.
  109. *
  110. * @param versionCoordinates
  111. * @return the version object
  112. * @throws ItemNotFoundException
  113. * @throws ContentAccessException
  114. * @throws IllegalArgumentException
  115. */
  116. Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException;
  117. /**
  118. * Returns the artifact object for the given coordinates.
  119. *
  120. * Normally the following coordinates should be set at the given selector:
  121. * <ul>
  122. * <li>namespace</li>
  123. * <li>artifactVersion and or version</li>
  124. * <li>artifactId or projectId</li>
  125. * </ul>
  126. * If the coordinates do not provide enough information for selecting a artifact, a {@link IllegalArgumentException} will be thrown
  127. * It depends on the repository type, what exactly is deleted for a given set of coordinates. Some repository type
  128. * may have different required and optional coordinates. For further information please check the documentation for the
  129. * type specific implementations.
  130. *
  131. * The following coordinates are optional and may further specify the artifact to delete.
  132. * <ul>
  133. * <li>classifier</li>
  134. * <li>type</li>
  135. * <li>extension</li>
  136. * </ul>
  137. *
  138. * The method always returns a artifact object, if the coordinates are valid. It does not guarantee that the artifact
  139. * exists. To check if there is really a physical representation of the artifact, use the <code>{@link Artifact#exists()}</code>
  140. * method of the artifact.
  141. * For upload and data retrieval use the methods of the {@link StorageAsset} reference returned in the artifact.
  142. *
  143. *
  144. * @param selector the selector with the artifact coordinates
  145. * @return a artifact object
  146. * @throws ItemNotFoundException if the selector coordinates do not specify a artifact
  147. * @throws ContentAccessException if the access to the underlying storage failed
  148. */
  149. Artifact getArtifact(ItemSelector selector) throws ContentAccessException;
  150. /**
  151. * Returns the artifacts that match the given selector. It is up to the repository implementation
  152. * what artifacts are returned for a given set of coordinates.
  153. *
  154. * @param selector the selector for the artifacts
  155. * @return a list of artifacts.
  156. * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
  157. * @throws ContentAccessException if the access to the underlying storage failed
  158. */
  159. List<? extends Artifact> getArtifacts( ItemSelector selector) throws ContentAccessException;
  160. /**
  161. * Returns the artifacts that match the given selector. It is up to the repository implementation
  162. * what artifacts are returned for a given set of coordinates.
  163. *
  164. * The returned stream is autoclosable and should always closed after using it.
  165. *
  166. * There is no guarantee about the order of the returned artifacts
  167. *
  168. * @param selector the selector for the artifacts
  169. * @return a stream with artifact elements.
  170. * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
  171. * @throws ContentAccessException if the access to the underlying storage failed
  172. */
  173. Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException;
  174. /**
  175. * Return the projects that are part of the given namespace.
  176. *
  177. * @param namespace the namespace
  178. * @return the list of projects or a empty list, if there are no projects for the given namespace.
  179. */
  180. List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException;
  181. /**
  182. * Returns the list of projects that match the given selector. The selector must at least specify a
  183. * a namespace.
  184. *
  185. * @param selector the selector
  186. * @return the list of projects that match the selector. A empty list of not project matches.
  187. * @throws ContentAccessException if the access to the storage backend failed
  188. * @throws IllegalArgumentException if the selector does not contain sufficient data for selecting projects
  189. */
  190. List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
  191. /**
  192. * Return the existing versions of the given project.
  193. *
  194. * @param project the project
  195. * @return a list of versions or a empty list, if not versions are available for the specified project
  196. * @throws ContentAccessException if the access to the underlying storage failed
  197. */
  198. List<? extends Version> getVersions( Project project) throws ContentAccessException;
  199. /**
  200. * Return the versions that match the given selector. The selector must at least specify a namespace and a projectId.
  201. *
  202. * @param selector the item selector. At least namespace and projectId must be set.
  203. * @return the list of version or a empty list, if no version matches the selector
  204. * @throws ContentAccessException if the access to the backend failed
  205. * @throws IllegalArgumentException if the selector does not contain enough information for selecting versions
  206. */
  207. List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
  208. /**
  209. * Return all the artifacts of a given content item (namespace, project, version)
  210. *
  211. * @param item the item
  212. * @return a list of artifacts or a empty list, if no artifacts are available for the specified item
  213. */
  214. List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException;
  215. /**
  216. * Return a stream of artifacts that are part of the given content item. The returned stream is
  217. * auto closable. There is no guarantee about the order of returned artifacts.
  218. *
  219. * As the stream may access IO resources, you should always use call this method inside try-with-resources or
  220. * make sure, that the stream is closed after using it.
  221. *
  222. * @param item the item from where the artifacts should be returned
  223. * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
  224. * is closed after use.
  225. * @throws ContentAccessException if the access to the underlying storage failed
  226. */
  227. Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException;
  228. /**
  229. * Returns true, if the selector coordinates point to a existing item in the repository.
  230. *
  231. * @param selector the item selector
  232. * @return <code>true</code>, if there exists such a item, otherwise <code>false</code>
  233. */
  234. boolean hasContent( ItemSelector selector );
  235. /**
  236. * Copies the artifact to the given destination coordinates
  237. *
  238. * @param sourceFile the path to the source file
  239. * @param destination the coordinates of the destination
  240. * @throws IllegalArgumentException if the destination is not valid
  241. */
  242. void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException;
  243. /**
  244. * Returns the item that matches the given path. The item at the path must not exist.
  245. *
  246. * @param path the path string that points to the item
  247. * @return the content item if the path is a valid item path
  248. * @throws LayoutException if the path is not valid for the repository layout
  249. */
  250. ContentItem toItem(String path) throws LayoutException;
  251. /**
  252. * Returns the item that matches the given asset path. The asset must not exist.
  253. *
  254. * @param assetPath the path to the artifact or directory
  255. * @return the item, if it is a valid path for the repository layout
  256. * @throws LayoutException if the path is not valid for the repository
  257. */
  258. ContentItem toItem(StorageAsset assetPath) throws LayoutException;
  259. /// ***************** End of new generation interface **********************
  260. /**
  261. * Returns the version reference for the given coordinates.
  262. * @param groupId the group id
  263. * @param artifactId the artifact id
  264. * @param version the version number
  265. * @return a version reference
  266. */
  267. VersionedReference toVersion( String groupId, String artifactId, String version );
  268. /**
  269. * Returns the version reference that represents the generic version, which means that
  270. * snapshot versions are converted to <VERSION>-SNAPSHOT
  271. * @param artifactReference the artifact reference
  272. * @return the generic version
  273. */
  274. VersionedReference toGenericVersion( ArtifactReference artifactReference );
  275. /**
  276. * Return the version reference that matches exactly the version string of the artifact
  277. *
  278. * @param artifactReference The artifact reference
  279. * @return the version reference
  280. */
  281. VersionedReference toVersion( ArtifactReference artifactReference);
  282. /**
  283. * Returns a artifact reference for the given coordinates.
  284. * @param groupId the group id
  285. * @param artifactId the artifact id
  286. * @param version the version
  287. * @param type the type
  288. * @param classifier the classifier
  289. * @return a artifact reference object
  290. */
  291. ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier);
  292. /**
  293. * Delete from the managed repository all files / directories associated with the
  294. * provided version reference.
  295. *
  296. * @param reference the version reference to delete.
  297. * @throws ContentNotFoundException
  298. */
  299. void deleteVersion( VersionedReference reference )
  300. throws ContentNotFoundException, ContentAccessException;
  301. /**
  302. * delete a specified artifact from the repository
  303. *
  304. * @param artifactReference
  305. * @throws ContentNotFoundException
  306. */
  307. void deleteArtifact( ArtifactReference artifactReference )
  308. throws ContentNotFoundException, ContentAccessException;
  309. /**
  310. * @param groupId
  311. * @throws ContentNotFoundException
  312. * @since 1.4-M3
  313. */
  314. void deleteGroupId( String groupId )
  315. throws ContentNotFoundException, ContentAccessException;
  316. /**
  317. *
  318. * @param namespace groupId for maven
  319. * @param projectId artifactId for maven
  320. * @throws ContentNotFoundException
  321. */
  322. void deleteProject( String namespace, String projectId )
  323. throws ContentNotFoundException, ContentAccessException;
  324. /**
  325. * Deletes a project
  326. * @param reference
  327. */
  328. void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
  329. /**
  330. * <p>
  331. * Convenience method to get the repository id.
  332. * </p>
  333. * <p>
  334. * Equivalent to calling <code>.getRepository().getId()</code>
  335. * </p>
  336. *
  337. * @return the repository id.
  338. */
  339. String getId();
  340. /**
  341. * <p>
  342. * Gather up the list of related artifacts to the ArtifactReference provided.
  343. * If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly
  344. * related to the given artifact, like checksums.
  345. * If type and classifier is <code>null</code> it will return the same artifacts as
  346. * {@link #getRelatedArtifacts(VersionedReference)}
  347. * </p>
  348. * <p>
  349. * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
  350. * </p>
  351. *
  352. * @param reference the reference to work off of.
  353. * @return the list of ArtifactReferences for related artifacts, if
  354. * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
  355. * @see #getRelatedArtifacts(VersionedReference)
  356. */
  357. List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
  358. throws ContentNotFoundException, LayoutException, ContentAccessException;
  359. /**
  360. * <p>
  361. * Gather up the list of related artifacts to the ArtifactReference provided.
  362. * This typically includes the pom files, and those things with
  363. * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
  364. * is set in the artifact reference, it may return artifacts with different classifiers.
  365. * </p>
  366. * <p>
  367. * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
  368. * </p>
  369. *
  370. * @param reference the reference to work off of.
  371. * @return the list of ArtifactReferences for related artifacts, if
  372. * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
  373. */
  374. List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
  375. throws ContentNotFoundException, LayoutException, ContentAccessException;
  376. /**
  377. * Returns all the assets that belong to a given artifact type. The list returned contain
  378. * all the files that correspond to the given artifact reference.
  379. * This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return
  380. * e.g. hash files.
  381. *
  382. * @param reference
  383. * @return
  384. */
  385. List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
  386. /**
  387. * Returns all artifacts that belong to a given version
  388. * @param reference the version reference
  389. * @return the list of artifacts or a empty list
  390. */
  391. List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
  392. /**
  393. * <p>
  394. * Convenience method to get the repository (on disk) root directory.
  395. * </p>
  396. * <p>
  397. * Equivalent to calling <code>.getRepository().getLocation()</code>
  398. * </p>
  399. *
  400. * @return the repository (on disk) root directory.
  401. */
  402. String getRepoRoot();
  403. /**
  404. * Get the repository configuration associated with this
  405. * repository content.
  406. *
  407. * @return the repository that is associated with this repository content.
  408. */
  409. ManagedRepository getRepository();
  410. /**
  411. * <p>
  412. * Given a specific {@link VersionedReference}, return the list of available versions for that
  413. * versioned reference.
  414. * </p>
  415. * <p>
  416. * <strong>NOTE:</strong> This is really only useful when working with SNAPSHOTs.
  417. * </p>
  418. *
  419. * @param reference the versioned reference to work off of.
  420. * @return the set of versions found.
  421. * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
  422. */
  423. Set<String> getVersions( VersionedReference reference )
  424. throws ContentNotFoundException, ContentAccessException, LayoutException;
  425. /**
  426. * Determines if the artifact referenced exists in the repository.
  427. *
  428. * @param reference the artifact reference to check for.
  429. * @return true if the artifact referenced exists.
  430. */
  431. boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
  432. /**
  433. * Determines if the version reference exists in the repository.
  434. *
  435. * @param reference the version reference to check for.
  436. * @return true if the version referenced exists.
  437. */
  438. boolean hasContent( VersionedReference reference ) throws ContentAccessException;
  439. /**
  440. * Set the repository configuration to associate with this
  441. * repository content.
  442. *
  443. * @param repo the repository to associate with this repository content.
  444. */
  445. void setRepository( ManagedRepository repo );
  446. /**
  447. * Given an {@link ArtifactReference}, return the file reference to the artifact.
  448. *
  449. * @param reference the artifact reference to use.
  450. * @return the relative path to the artifact.
  451. */
  452. StorageAsset toFile( VersionedReference reference );
  453. /**
  454. * Given an {@link ArtifactReference}, return the file reference to the artifact.
  455. *
  456. * @param reference the artifact reference to use.
  457. * @return the relative path to the artifact.
  458. */
  459. StorageAsset toFile( ArtifactReference reference );
  460. /**
  461. * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
  462. *
  463. * @param reference the archiva artifact to use.
  464. * @return the relative path to the artifact.
  465. */
  466. StorageAsset toFile( ArchivaArtifact reference );
  467. /**
  468. * Given a {@link ProjectReference}, return the path to the metadata for
  469. * the project.
  470. *
  471. * @param reference the reference to use.
  472. * @return the path to the metadata file, or null if no metadata is appropriate.
  473. */
  474. String toMetadataPath( ProjectReference reference );
  475. /**
  476. * Given a {@link VersionedReference}, return the path to the metadata for
  477. * the specific version of the project.
  478. *
  479. * @param reference the reference to use.
  480. * @return the path to the metadata file, or null if no metadata is appropriate.
  481. */
  482. String toMetadataPath( VersionedReference reference );
  483. /**
  484. * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
  485. *
  486. * @param reference the archiva artifact to use.
  487. * @return the relative path to the artifact.
  488. */
  489. String toPath( ArchivaArtifact reference );
  490. }