@Test public void testAddArtifact() throws IOException, URISyntaxException, LayoutException { ManagedRepository repo = createManagedRepoWithContent( "delete-repository" ); ManagedRepositoryContent myRepoContent = repo.getContent( ); BaseRepositoryContentLayout layout = myRepoContent.getLayout( BaseRepositoryContentLayout.class ); Path repoRoot = repo.getRoot().getFilePath( ); Path tmpFile = Files.createTempFile( "archiva-mvn-repotest", "jar" ); try( OutputStream outputStream = Files.newOutputStream( tmpFile )) { for ( int i = 0; i < 255; i++ ) { outputStream.write( "test.test.test\n".getBytes( Charset.forName( "UTF-8" ) ) ); } } Path file = repoRoot.resolve( "org/apache/maven/samplejar/2.0/samplejar-2.0.jar" ); FileTime lmt = Files.getLastModifiedTime( file ); ArchivaItemSelector selector = ArchivaItemSelector.builder( ) .withNamespace( "org.apache.maven" ) .withProjectId( "samplejar" ) .withVersion( "2.0" ) .withArtifactId( "samplejar" ) .withArtifactVersion( "2.0" ) .withExtension( "jar" ) .build( ); Artifact artifact = layout.getArtifact( selector ); layout.addArtifact( tmpFile, artifact ); FileTime lmtAfter = Files.getLastModifiedTime( file ); assertNotEquals( lmtAfter, lmt ); Reader ln = Files.newBufferedReader( file, Charset.forName( "UTF-8" ) ); char[] content = new char[50]; ln.read( content ); assertTrue( new String( content ).startsWith( "test.test.test" ) ); tmpFile = Files.createTempFile( "archiva-mvn-repotest", "jar" ); try( OutputStream outputStream = Files.newOutputStream( tmpFile )) { for ( int i = 0; i < 255; i++ ) { outputStream.write( "test.test.test\n".getBytes( Charset.forName( "UTF-8" ) ) ); } } file = repoRoot.resolve( "org/apache/maven/samplejar/2.0/samplejar-2.0.test" ); assertFalse( Files.exists( file ) ); assertTrue( Files.exists( tmpFile ) ); selector = ArchivaItemSelector.builder( ) .withNamespace( "org.apache.maven" ) .withProjectId( "samplejar" ) .withVersion( "2.0" ) .withArtifactId( "samplejar" ) .withArtifactVersion( "2.0" ) .withExtension( "test" ) .build( ); artifact = layout.getArtifact( selector ); layout.addArtifact( tmpFile, artifact ); ln = Files.newBufferedReader( file, Charset.forName( "UTF-8" ) ); ln.read( content ); assertTrue( new String( content ).startsWith( "test.test.test" ) ); }
@Override public void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException { try { StorageAsset asset = destination.getAsset( ); if ( !asset.exists( ) ) { asset.create( ); } asset.replaceDataFromFile( sourceFile ); } catch ( IOException e ) { log.error( "Could not push data to asset source={} destination={}. {}", sourceFile, destination.getAsset( ).getFilePath( ), e.getMessage( ) ); throw new ContentAccessException( e.getMessage( ), e ); } }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException { try { StorageAsset asset = destination.getAsset( ); if ( !asset.exists( ) ) { asset.create( ); } asset.replaceDataFromFile( sourceFile ); } catch ( IOException e ) { log.error( "Could not push data to asset source={} destination={}. {}", sourceFile, destination.getAsset( ).getFilePath( ), e.getMessage( ) ); throw new ContentAccessException( e.getMessage( ), e ); } } }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException { try { StorageAsset asset = destination.getAsset( ); if ( !asset.exists( ) ) { asset.create( ); } asset.replaceDataFromFile( sourceFile ); } catch ( IOException e ) { log.error( "Could not push data to asset source={} destination={}. {}", sourceFile, destination.getAsset( ).getFilePath( ), e.getMessage( ) ); throw new ContentAccessException( e.getMessage( ), e ); } } ManagedDefaultRepositoryContent( );  ManagedDefaultRepositoryContent( ManagedRepository repository, FileTypes fileTypes, FileLockManager lockManager ); }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException { try { StorageAsset asset = destination.getAsset( ); if ( !asset.exists( ) ) { asset.create( ); } asset.replaceDataFromFile( sourceFile ); } catch ( IOException e ) { log.error( "Could not push data to asset source={} destination={}. {}", sourceFile, destination.getAsset( ).getFilePath( ), e.getMessage( ) ); throw new ContentAccessException( e.getMessage( ), e ); } } ManagedDefaultRepositoryContent( );  ManagedDefaultRepositoryContent( ManagedRepository repository, FileTypes fileTypes, FileLockManager lockManager ); void setFileTypes( FileTypes fileTypes ); @Override T adaptItem( Class<T> clazz, ContentItem item ); @Override void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ); @Override void deleteItem( ContentItem item ); @Override ContentItem getItem( ItemSelector selector ); @Override Namespace getNamespace( final ItemSelector namespaceSelector ); @Override Project getProject( final ItemSelector selector ); @Override Version getVersion( final ItemSelector selector ); Artifact createArtifact( final StorageAsset artifactPath, final ItemSelector selector,
                                    final String classifier ); Namespace getNamespaceFromArtifactPath( final StorageAsset artifactPath ); Namespace getNamespaceFromPath( final StorageAsset nsPath ); Namespace createNamespaceFromPath( final StorageAsset namespacePath); @Override ManagedRepositoryContent getGenericContent( ); @Override Artifact getArtifact( final ItemSelector selectorArg ); @Override Artifact getArtifact( String path ); @Override List<? extends Project> getProjects( Namespace namespace ); @Override List<? extends Project> getProjects( ItemSelector selector ); @Override List<? extends Version> getVersions( final Project project ); @Override List<? extends Version> getVersions( final ItemSelector selector ); List<String> getArtifactVersions( final ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ItemSelector selector ); @Override Stream<? extends Artifact> newArtifactStream( ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ContentItem item ); Stream<? extends Artifact> newArtifactStream( Namespace item ); Stream<? extends Artifact> newArtifactStream( Project item ); Stream<? extends Artifact> newArtifactStream( Version item ); Stream<? extends Artifact> newArtifactStream( Artifact item ); @Override Stream<? extends Artifact> newArtifactStream( ContentItem item ); @Override Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ); @Override boolean hasContent( ItemSelector selector ); @Override ContentItem getParent( ContentItem item ); @Override List<? extends ContentItem> getChildren( ContentItem item ); @Override T applyCharacteristic( Class<T> clazz, ContentItem item ); @Override T getLayout( Class<T> clazz ); @Override boolean supportsLayout( Class<T> clazz ); @Override List<Class<? extends ManagedRepositoryContentLayout>> getSupportedLayouts( ); @Override void addArtifact( Path sourceFile, Artifact destination ); @Override ContentItem toItem( String path ); @Override ContentItem toItem( StorageAsset assetPath ); @Override String toPath( ContentItem item ); @Override DataItem getMetadataItem( Version version ); @Override DataItem getMetadataItem( Project project ); @Override String getId( ); @Override ManagedRepository getRepository( ); @Override void setRepository( final ManagedRepository repo ); void setFiletypes( FileTypes filetypes ); void setMavenContentHelper( MavenContentHelper contentHelper ); MavenMetadataReader getMetadataReader( ); void setMetadataReader( MavenMetadataReader metadataReader ); }
ManagedDefaultRepositoryContent extends AbstractDefaultRepositoryContent implements ManagedRepositoryContent, BaseRepositoryContentLayout { @Override public void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException { try { StorageAsset asset = destination.getAsset( ); if ( !asset.exists( ) ) { asset.create( ); } asset.replaceDataFromFile( sourceFile ); } catch ( IOException e ) { log.error( "Could not push data to asset source={} destination={}. {}", sourceFile, destination.getAsset( ).getFilePath( ), e.getMessage( ) ); throw new ContentAccessException( e.getMessage( ), e ); } } ManagedDefaultRepositoryContent( );  ManagedDefaultRepositoryContent( ManagedRepository repository, FileTypes fileTypes, FileLockManager lockManager ); void setFileTypes( FileTypes fileTypes ); @Override T adaptItem( Class<T> clazz, ContentItem item ); @Override void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ); @Override void deleteItem( ContentItem item ); @Override ContentItem getItem( ItemSelector selector ); @Override Namespace getNamespace( final ItemSelector namespaceSelector ); @Override Project getProject( final ItemSelector selector ); @Override Version getVersion( final ItemSelector selector ); Artifact createArtifact( final StorageAsset artifactPath, final ItemSelector selector,
                                    final String classifier ); Namespace getNamespaceFromArtifactPath( final StorageAsset artifactPath ); Namespace getNamespaceFromPath( final StorageAsset nsPath ); Namespace createNamespaceFromPath( final StorageAsset namespacePath); @Override ManagedRepositoryContent getGenericContent( ); @Override Artifact getArtifact( final ItemSelector selectorArg ); @Override Artifact getArtifact( String path ); @Override List<? extends Project> getProjects( Namespace namespace ); @Override List<? extends Project> getProjects( ItemSelector selector ); @Override List<? extends Version> getVersions( final Project project ); @Override List<? extends Version> getVersions( final ItemSelector selector ); List<String> getArtifactVersions( final ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ItemSelector selector ); @Override Stream<? extends Artifact> newArtifactStream( ItemSelector selector ); @Override List<? extends Artifact> getArtifacts( ContentItem item ); Stream<? extends Artifact> newArtifactStream( Namespace item ); Stream<? extends Artifact> newArtifactStream( Project item ); Stream<? extends Artifact> newArtifactStream( Version item ); Stream<? extends Artifact> newArtifactStream( Artifact item ); @Override Stream<? extends Artifact> newArtifactStream( ContentItem item ); @Override Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ); @Override boolean hasContent( ItemSelector selector ); @Override ContentItem getParent( ContentItem item ); @Override List<? extends ContentItem> getChildren( ContentItem item ); @Override T applyCharacteristic( Class<T> clazz, ContentItem item ); @Override T getLayout( Class<T> clazz ); @Override boolean supportsLayout( Class<T> clazz ); @Override List<Class<? extends ManagedRepositoryContentLayout>> getSupportedLayouts( ); @Override void addArtifact( Path sourceFile, Artifact destination ); @Override ContentItem toItem( String path ); @Override ContentItem toItem( StorageAsset assetPath ); @Override String toPath( ContentItem item ); @Override DataItem getMetadataItem( Version version ); @Override DataItem getMetadataItem( Project project ); @Override String getId( ); @Override ManagedRepository getRepository( ); @Override void setRepository( final ManagedRepository repo ); void setFiletypes( FileTypes filetypes ); void setMavenContentHelper( MavenContentHelper contentHelper ); MavenMetadataReader getMetadataReader( ); void setMetadataReader( MavenMetadataReader metadataReader ); static final String SNAPSHOT_ARTIFACT_VERSION; static final String SNAPSHOT; static final Pattern UNIQUE_SNAPSHOT_PATTERN; static final Pattern CLASSIFIER_PATTERN; static final Pattern COMMON_EXTENSIONS; static final Pattern TIMESTAMP_PATTERN; static final Pattern GENERIC_SNAPSHOT_PATTERN; }