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.

ManagedRepositoryContentMock.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. package org.apache.archiva.repository.mock;
  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.repository.content.ContentAccessException;
  21. import org.apache.archiva.repository.ManagedRepositoryContent;
  22. import org.apache.archiva.repository.ItemDeleteStatus;
  23. import org.apache.archiva.repository.content.LayoutException;
  24. import org.apache.archiva.repository.ManagedRepository;
  25. import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
  26. import org.apache.archiva.repository.content.ManagedRepositoryContentLayout;
  27. import org.apache.archiva.repository.content.Artifact;
  28. import org.apache.archiva.repository.content.BaseDataItemTypes;
  29. import org.apache.archiva.repository.content.ContentItem;
  30. import org.apache.archiva.repository.content.DataItem;
  31. import org.apache.archiva.repository.content.ItemNotFoundException;
  32. import org.apache.archiva.repository.content.ItemSelector;
  33. import org.apache.archiva.repository.content.Namespace;
  34. import org.apache.archiva.repository.content.Project;
  35. import org.apache.archiva.repository.content.Version;
  36. import org.apache.archiva.repository.content.base.ArchivaContentItem;
  37. import org.apache.archiva.repository.content.base.ArchivaDataItem;
  38. import org.apache.archiva.repository.content.base.ArchivaNamespace;
  39. import org.apache.archiva.repository.content.base.ArchivaProject;
  40. import org.apache.archiva.repository.content.base.ArchivaVersion;
  41. import org.apache.archiva.repository.storage.StorageAsset;
  42. import org.springframework.stereotype.Service;
  43. import java.nio.file.Path;
  44. import java.util.List;
  45. import java.util.function.Consumer;
  46. import java.util.stream.Stream;
  47. /**
  48. * @author Martin Stockhammer <martin_s@apache.org>
  49. */
  50. @Service("managedRepositoryContent#mock")
  51. public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout, ManagedRepositoryContent
  52. {
  53. private ManagedRepository repository;
  54. @Override
  55. public void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ) throws ContentAccessException, IllegalArgumentException
  56. {
  57. }
  58. @Override
  59. public <T extends ContentItem> T adaptItem( Class<T> clazz, ContentItem item ) throws LayoutException
  60. {
  61. if (clazz.isAssignableFrom( Version.class ))
  62. {
  63. if ( !item.hasCharacteristic( Version.class ) )
  64. {
  65. item.setCharacteristic( Version.class, createVersionFromPath( item.getAsset() ) );
  66. }
  67. return (T) item.adapt( Version.class );
  68. } else if ( clazz.isAssignableFrom( Project.class )) {
  69. if ( !item.hasCharacteristic( Project.class ) )
  70. {
  71. item.setCharacteristic( Project.class, createProjectFromPath( item.getAsset() ) );
  72. }
  73. return (T) item.adapt( Project.class );
  74. } else if ( clazz.isAssignableFrom( Namespace.class )) {
  75. if ( !item.hasCharacteristic( Namespace.class ) )
  76. {
  77. item.setCharacteristic( Namespace.class, createNamespaceFromPath( item.getAsset() ) );
  78. }
  79. return (T) item.adapt( Namespace.class );
  80. }
  81. throw new LayoutException( "Could not convert item to class " + clazz);
  82. }
  83. private Version createVersionFromPath( StorageAsset asset )
  84. {
  85. Project proj = createProjectFromPath( asset.getParent( ) );
  86. return ArchivaVersion.withRepository( this ).withAsset( asset )
  87. .withProject( proj ).withVersion( asset.getName( ) ).build();
  88. }
  89. private Project createProjectFromPath( StorageAsset asset) {
  90. Namespace ns = createNamespaceFromPath( asset );
  91. return ArchivaProject.withRepository( this ).withAsset( asset )
  92. .withNamespace( ns ).withId( asset.getName( ) ).build( );
  93. }
  94. private Namespace createNamespaceFromPath( StorageAsset asset) {
  95. String namespace = asset.getPath( ).replace( "/", "." );
  96. return ArchivaNamespace.withRepository( this )
  97. .withAsset( asset ).withNamespace( namespace ).build();
  98. }
  99. @Override
  100. public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException
  101. {
  102. }
  103. @Override
  104. public void copyItem( ContentItem item, ManagedRepository destinationRepository ) throws ItemNotFoundException, ContentAccessException
  105. {
  106. }
  107. @Override
  108. public void copyItem( ContentItem item, ManagedRepository destinationRepository, boolean updateMetadata ) throws ItemNotFoundException, ContentAccessException
  109. {
  110. }
  111. @Override
  112. public ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
  113. {
  114. return null;
  115. }
  116. @Override
  117. public Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException
  118. {
  119. return null;
  120. }
  121. @Override
  122. public Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException
  123. {
  124. return null;
  125. }
  126. @Override
  127. public Version getVersion( ItemSelector versionCoordinates ) throws ContentAccessException, IllegalArgumentException
  128. {
  129. return null;
  130. }
  131. @Override
  132. public Artifact getArtifact( ItemSelector selector ) throws ContentAccessException
  133. {
  134. return null;
  135. }
  136. @Override
  137. public Artifact getArtifact( String path ) throws LayoutException, ContentAccessException
  138. {
  139. return null;
  140. }
  141. @Override
  142. public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException
  143. {
  144. return null;
  145. }
  146. @Override
  147. public Stream<? extends Artifact> newArtifactStream( ItemSelector selector ) throws ContentAccessException
  148. {
  149. return null;
  150. }
  151. @Override
  152. public Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ) throws ContentAccessException, IllegalArgumentException
  153. {
  154. return null;
  155. }
  156. @Override
  157. public List<? extends Project> getProjects( Namespace namespace ) throws ContentAccessException
  158. {
  159. return null;
  160. }
  161. @Override
  162. public List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
  163. {
  164. return null;
  165. }
  166. @Override
  167. public List<? extends Version> getVersions( Project project ) throws ContentAccessException
  168. {
  169. return null;
  170. }
  171. @Override
  172. public List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
  173. {
  174. return null;
  175. }
  176. @Override
  177. public List<String> getArtifactVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
  178. {
  179. return null;
  180. }
  181. @Override
  182. public List<? extends Artifact> getArtifacts( ContentItem item ) throws ContentAccessException
  183. {
  184. return null;
  185. }
  186. @Override
  187. public Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException
  188. {
  189. return null;
  190. }
  191. @Override
  192. public boolean hasContent( ItemSelector selector )
  193. {
  194. return false;
  195. }
  196. @Override
  197. public ContentItem getParent( ContentItem item )
  198. {
  199. try
  200. {
  201. return toItem( item.getAsset( ).getParent( ) );
  202. }
  203. catch ( LayoutException e )
  204. {
  205. throw new RuntimeException( "Bad layout error " + e.getMessage( ) );
  206. }
  207. }
  208. @Override
  209. public List<? extends ContentItem> getChildren( ContentItem item )
  210. {
  211. return null;
  212. }
  213. @Override
  214. public <T extends ContentItem> T applyCharacteristic( Class<T> clazz, ContentItem item ) throws LayoutException
  215. {
  216. return null;
  217. }
  218. @Override
  219. public <T extends ManagedRepositoryContentLayout> T getLayout( Class<T> clazz ) throws LayoutException
  220. {
  221. return null;
  222. }
  223. @Override
  224. public <T extends ManagedRepositoryContentLayout> boolean supportsLayout( Class<T> clazz )
  225. {
  226. return false;
  227. }
  228. @Override
  229. public List<Class<? extends ManagedRepositoryContentLayout>> getSupportedLayouts( )
  230. {
  231. return null;
  232. }
  233. @Override
  234. public void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException
  235. {
  236. }
  237. @Override
  238. public DataItem getMetadataItem( Version version )
  239. {
  240. return ArchivaDataItem.withAsset( version.getAsset( ).resolve( "maven-metadata.xml" ) ).withId( "maven-metadata.xml" )
  241. .withDataType( BaseDataItemTypes.METADATA ).build();
  242. }
  243. @Override
  244. public DataItem getMetadataItem( Project project )
  245. {
  246. return ArchivaDataItem.withAsset( project.getAsset( ).resolve( "maven-metadata.xml" ) ).withId( "maven-metadata.xml" )
  247. .withDataType( BaseDataItemTypes.METADATA ).build( );
  248. }
  249. @Override
  250. public ContentItem toItem( String path ) throws LayoutException
  251. {
  252. StorageAsset asset = repository.getRoot().resolve( path );
  253. return toItem( asset );
  254. }
  255. @Override
  256. public ContentItem toItem( StorageAsset asset ) throws LayoutException
  257. {
  258. if (asset.isLeaf()) {
  259. return ArchivaDataItem.withAsset( asset ).withId( asset.getName() ).build();
  260. } else
  261. {
  262. return ArchivaContentItem.withRepository( this )
  263. .withAsset( asset ).build( );
  264. }
  265. }
  266. @Override
  267. public String toPath( ContentItem item )
  268. {
  269. return null;
  270. }
  271. @Override
  272. public String getId( )
  273. {
  274. return null;
  275. }
  276. @Override
  277. public ManagedRepository getRepository( )
  278. {
  279. return repository;
  280. }
  281. @Override
  282. public void setRepository( ManagedRepository repo )
  283. {
  284. this.repository = repo;
  285. }
  286. @Override
  287. public String toPath( ItemSelector selector )
  288. {
  289. return null;
  290. }
  291. @Override
  292. public ItemSelector toItemSelector( String path ) throws LayoutException
  293. {
  294. return null;
  295. }
  296. @Override
  297. public ManagedRepositoryContent getGenericContent( )
  298. {
  299. return null;
  300. }
  301. }