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 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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 IllegalArgumentException 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 IllegalArgumentException 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. * Return the version reference that matches exactly the version string of the artifact
  270. *
  271. * @param artifactReference The artifact reference
  272. * @return the version reference
  273. */
  274. VersionedReference toVersion( ArtifactReference artifactReference);
  275. /**
  276. * Delete from the managed repository all files / directories associated with the
  277. * provided version reference.
  278. *
  279. * @param reference the version reference to delete.
  280. * @throws ContentNotFoundException
  281. */
  282. void deleteVersion( VersionedReference reference )
  283. throws ContentNotFoundException, ContentAccessException;
  284. /**
  285. * delete a specified artifact from the repository
  286. *
  287. * @param artifactReference
  288. * @throws ContentNotFoundException
  289. */
  290. void deleteArtifact( ArtifactReference artifactReference )
  291. throws ContentNotFoundException, ContentAccessException;
  292. /**
  293. * @param groupId
  294. * @throws ContentNotFoundException
  295. * @since 1.4-M3
  296. */
  297. void deleteGroupId( String groupId )
  298. throws ContentNotFoundException, ContentAccessException;
  299. /**
  300. *
  301. * @param namespace groupId for maven
  302. * @param projectId artifactId for maven
  303. * @throws ContentNotFoundException
  304. */
  305. void deleteProject( String namespace, String projectId )
  306. throws ContentNotFoundException, ContentAccessException;
  307. /**
  308. * Deletes a project
  309. * @param reference
  310. */
  311. void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
  312. /**
  313. * <p>
  314. * Convenience method to get the repository id.
  315. * </p>
  316. * <p>
  317. * Equivalent to calling <code>.getRepository().getId()</code>
  318. * </p>
  319. *
  320. * @return the repository id.
  321. */
  322. String getId();
  323. /**
  324. * <p>
  325. * Gather up the list of related artifacts to the ArtifactReference provided.
  326. * This typically includes the pom files, and those things with
  327. * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
  328. * is set in the artifact reference, it may return artifacts with different classifiers.
  329. * </p>
  330. * <p>
  331. * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
  332. * </p>
  333. *
  334. * @param reference the reference to work off of.
  335. * @return the list of ArtifactReferences for related artifacts, if
  336. * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
  337. */
  338. List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
  339. throws ContentNotFoundException, LayoutException, ContentAccessException;
  340. /**
  341. * Returns all artifacts that belong to a given version
  342. * @param reference the version reference
  343. * @return the list of artifacts or a empty list
  344. */
  345. List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
  346. /**
  347. * <p>
  348. * Convenience method to get the repository (on disk) root directory.
  349. * </p>
  350. * <p>
  351. * Equivalent to calling <code>.getRepository().getLocation()</code>
  352. * </p>
  353. *
  354. * @return the repository (on disk) root directory.
  355. */
  356. String getRepoRoot();
  357. /**
  358. * Get the repository configuration associated with this
  359. * repository content.
  360. *
  361. * @return the repository that is associated with this repository content.
  362. */
  363. ManagedRepository getRepository();
  364. /**
  365. * Determines if the artifact referenced exists in the repository.
  366. *
  367. * @param reference the artifact reference to check for.
  368. * @return true if the artifact referenced exists.
  369. */
  370. boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
  371. /**
  372. * Determines if the version reference exists in the repository.
  373. *
  374. * @param reference the version reference to check for.
  375. * @return true if the version referenced exists.
  376. */
  377. boolean hasContent( VersionedReference reference ) throws ContentAccessException;
  378. /**
  379. * Set the repository configuration to associate with this
  380. * repository content.
  381. *
  382. * @param repo the repository to associate with this repository content.
  383. */
  384. void setRepository( ManagedRepository repo );
  385. /**
  386. * Given an {@link ArtifactReference}, return the file reference to the artifact.
  387. *
  388. * @param reference the artifact reference to use.
  389. * @return the relative path to the artifact.
  390. */
  391. StorageAsset toFile( VersionedReference reference );
  392. /**
  393. * Given an {@link ArtifactReference}, return the file reference to the artifact.
  394. *
  395. * @param reference the artifact reference to use.
  396. * @return the relative path to the artifact.
  397. */
  398. StorageAsset toFile( ArtifactReference reference );
  399. /**
  400. * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
  401. *
  402. * @param reference the archiva artifact to use.
  403. * @return the relative path to the artifact.
  404. */
  405. StorageAsset toFile( ArchivaArtifact reference );
  406. /**
  407. * Given a {@link ProjectReference}, return the path to the metadata for
  408. * the project.
  409. *
  410. * @param reference the reference to use.
  411. * @return the path to the metadata file, or null if no metadata is appropriate.
  412. */
  413. String toMetadataPath( ProjectReference reference );
  414. /**
  415. * Given a {@link VersionedReference}, return the path to the metadata for
  416. * the specific version of the project.
  417. *
  418. * @param reference the reference to use.
  419. * @return the path to the metadata file, or null if no metadata is appropriate.
  420. */
  421. String toMetadataPath( VersionedReference reference );
  422. /**
  423. * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
  424. *
  425. * @param reference the archiva artifact to use.
  426. * @return the relative path to the artifact.
  427. */
  428. String toPath( ArchivaArtifact reference );
  429. }