private boolean isEquals( ArtifactMetadata sourceArtifact, ArtifactMetadata targetArtifact ) { boolean isSame = false; if ( ( sourceArtifact.getNamespace().equals( targetArtifact.getNamespace() ) ) && ( sourceArtifact.getProject().equals( targetArtifact.getProject() ) ) && ( sourceArtifact.getId().equals( targetArtifact.getId() ) ) && ( sourceArtifact.getProjectVersion().equals( targetArtifact.getProjectVersion() ) ) ) { isSame = true; } return isSame; } }
getOrAddArtifactNode( repositoryId, namespace, projectId, projectVersion, artifactMeta.getId() ); cal.setTime( artifactMeta.getFileLastModified() ); node.setProperty( JCR_LAST_MODIFIED, cal ); cal.setTime( artifactMeta.getWhenGathered() ); node.setProperty( "whenGathered", cal ); node.setProperty( "size", artifactMeta.getSize() ); node.setProperty( "md5", artifactMeta.getMd5() ); node.setProperty( "sha1", artifactMeta.getSha1() ); node.setProperty( "version", artifactMeta.getVersion() ); MetadataFacet metadataFacet = artifactMeta.getFacet( facetId ); if ( metadataFacet == null )
private static ArtifactMetadata createArtifact( String type ) { ArtifactMetadata artifact = new ArtifactMetadata(); artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type ); artifact.setWhenGathered( new Date() ); artifact.setNamespace( TEST_NAMESPACE ); artifact.setProject( TEST_PROJECT ); artifact.setRepositoryId( TEST_REPO_ID ); artifact.setFileLastModified( System.currentTimeMillis() ); artifact.setVersion( TEST_PROJECT_VERSION ); artifact.setProjectVersion( TEST_PROJECT_VERSION ); artifact.setMd5( TEST_MD5 ); artifact.setSha1( TEST_SHA1 ); return artifact; }
@Override public int compare( ArtifactMetadata o1, ArtifactMetadata o2 ) { // sort by version (reverse), then ID int result = new DefaultArtifactVersion( o2.getVersion() ).compareTo( new DefaultArtifactVersion( o1.getVersion() ) ); return result != 0 ? result : o1.getId().compareTo( o2.getId() ); } }
private void updateArtifactFacets( ArtifactMetadata artifact, Properties properties ) { String propertyPrefix = "artifact:facet:" + artifact.getId() + ":"; for ( MetadataFacet facet : artifact.getFacetList() ) { for ( Map.Entry<String, String> e : facet.toProperties().entrySet() ) { String key = propertyPrefix + facet.getFacetId() + ":" + e.getKey(); properties.setProperty( key, e.getValue() ); } } }
@Override public void removeArtifact( ArtifactMetadata artifactMetadata, String baseVersion ) throws MetadataRepositoryException { logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'", artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(), artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() ); String key = new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace( artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion( baseVersion ).withProject( artifactMetadata.getProject() ).build(); this.artifactMetadataTemplate.deleteRow( key ); }
if ( artifactMetadata.getVersion().equals( artifact.getVersion() ) ) (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID ); artifactMetadata.removeFacet( MavenArtifactFacet.FACET_ID ); String groupId = artifact.getGroupId(), artifactId = artifact.getArtifactId(), version = artifact.getVersion(); metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifact.getVersion(), artifactMetadata.getId() ); artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getVersion(), artifactMetadata.getId() );
public Artifact build() ref.setArtifactId( artifactMetadata.getProject() ); ref.setGroupId( artifactMetadata.getNamespace() ); ref.setVersion( artifactMetadata.getVersion() ); MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID ); if ( facet != null ) artifact.setRepositoryId( artifactMetadata.getRepositoryId() ); artifact.setClassifier( classifier ); artifact.setPackaging( type ); artifact.setPath( managedRepositoryContent.toPath( ref ) ); double s = this.artifactMetadata.getSize(); String symbol = "b"; if ( s > 1024 )
ArtifactMetadata metadata = new ArtifactMetadata(); metadata.setId( id ); metadata.setNamespace( namespace ); metadata.setProject( projectId ); metadata.setRepositoryId( repoId ); metadata.setProjectVersion( projectVersion ); metadata.setVersion( version ); metadata.addFacet( facet );
clearMetadataFacetProperties( artifact.getFacetList(), properties, "artifact:facet:" + artifact.getId() + ":" ); String id = artifact.getId(); properties.setProperty( "artifact:updated:" + id, Long.toString( artifact.getFileLastModified().getTime() ) ); properties.setProperty( "artifact:whenGathered:" + id, Long.toString( artifact.getWhenGathered().getTime() ) ); properties.setProperty( "artifact:size:" + id, Long.toString( artifact.getSize() ) ); if ( artifact.getMd5() != null ) properties.setProperty( "artifact:md5:" + id, artifact.getMd5() ); if ( artifact.getSha1() != null ) properties.setProperty( "artifact:sha1:" + id, artifact.getSha1() ); properties.setProperty( "artifact:version:" + id, artifact.getVersion() ); Set<String> facetIds = new LinkedHashSet<>( artifact.getFacetIds( ) ); String property = "artifact:facetIds:" + id; facetIds.addAll( Arrays.asList( properties.getProperty( property, "" ).split( "," ) ) );
artifactMeta.getId() ).withProjectVersion( projectVersion ).build(); updater.setLong( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime() ); updater.setLong( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime() ); updater.setLong( SIZE.toString(), artifactMeta.getSize() ); addUpdateStringValue( updater, MD5.toString(), artifactMeta.getMd5() ); addUpdateStringValue( updater, SHA1.toString(), artifactMeta.getSha1() ); addUpdateStringValue( updater, VERSION.toString(), artifactMeta.getVersion() ); this.artifactMetadataTemplate.update( updater ); .addInsertion( key, cf, column( ID.toString(), artifactMeta.getId() ) )// .addInsertion( key, cf, column( PROJECT.toString(), artifactMeta.getProject() ) ) // .addInsertion( key, cf, column( VERSION.toString(), artifactMeta.getVersion() ) ) // .addInsertion( key, cf, column( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime() ) ) // .addInsertion( key, cf, column( SIZE.toString(), artifactMeta.getSize() ) ) // .withId( artifactMeta.getId() ) // .build(); .addEqualsExpression( VERSION.toString(), artifactMeta.getVersion() ) // .execute(); .addInsertion( key, cf, column( VERSION.toString(), artifactMeta.getVersion() ) ) // .execute(); artifactMetadataModel.setProject( projectId ); artifactMetadataModel.setProjectVersion( projectVersion );
project.setNamespace( artifact.getNamespace() ); project.setId( artifact.getProject() ); String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() ); new ReadMetadataRequest().repositoryId( repoId ).namespace( artifact.getNamespace() ).projectId( artifact.getProject() ).projectVersion( projectVersion ); versionMetadata = repositoryStorage.readProjectVersionMetadata( readMetadataRequest ); createVersionMetadata = true; artifact.setWhenGathered( whenGathered ); metadataRepository.updateArtifact( repoId, project.getNamespace(), project.getId(), projectVersion, artifact );
artifact.setGroupId( metadata.getNamespace() ); artifact.setArtifactId( metadata.getProject() ); artifact.setVersion( metadata.getVersion() ); MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID ); if ( facet != null )
String repositoryId = artifactMetadata.getRepositoryId(); getProjectVersionPath( repositoryId, artifactMetadata.getNamespace(), artifactMetadata.getProject(), baseVersion ); if ( StringUtils.equals( version, artifactMetadata.getVersion() ) )
private static void populateArtifactMetadataFromFile( ArtifactMetadata metadata, File file ) { metadata.setWhenGathered( new Date() ); metadata.setFileLastModified( file.lastModified() ); ChecksummedFile checksummedFile = new ChecksummedFile( file ); try { metadata.setMd5( checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 ) ); } catch ( IOException e ) { LOGGER.error( "Unable to checksum file {}: {},MD5", file, e.getMessage() ); } try { metadata.setSha1( checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 ) ); } catch ( IOException e ) { LOGGER.error( "Unable to checksum file {}: {},SHA1", file, e.getMessage() ); } metadata.setSize( file.length() ); }
@Test public void testGetArtifactsByMetadataAllRepositories() throws Exception { createArtifactWithMavenArtifactFacet(); tryAssert(()-> { Collection<ArtifactMetadata> artifactsByMetadata = repository.getArtifactsByMetadata("foo", TEST_METADATA_VALUE, null); assertThat(artifactsByMetadata).hasSize(1); ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next(); assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar"); assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1); assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID); MetadataFacet facet = artifactMetadata.getFacet(TEST_FACET_ID); assertThat(facet).isNotNull(); assertThat(facet.toProperties()).isEqualTo(Collections.singletonMap("foo", TEST_METADATA_VALUE)); }); }
private void updateVersionMetadata( Path versionMetaDataFileInTargetRepo, ArtifactMetadata artifactMetadata, Date lastUpdatedTimestamp ) throws RepositoryMetadataException { ArchivaRepositoryMetadata versionMetadata = getMetadata( versionMetaDataFileInTargetRepo ); if ( !Files.exists(versionMetaDataFileInTargetRepo) ) { versionMetadata.setGroupId( artifactMetadata.getNamespace() ); versionMetadata.setArtifactId( artifactMetadata.getProject() ); versionMetadata.setVersion( artifactMetadata.getProjectVersion() ); } versionMetadata.setLastUpdatedTimestamp( lastUpdatedTimestamp ); RepositoryMetadataWriter.write( versionMetadata, versionMetaDataFileInTargetRepo ); }
@Test public void testGetArtifactsByProjectVersionMetadata() throws Exception { createArtifactWithGenericMetadataFacet( 10 ); Collection<ArtifactMetadata> artifactsByMetadata = repository.getArtifactsByProjectVersionMetadata( TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID ); assertThat( artifactsByMetadata ).hasSize( 1 ); ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next(); assertThat( artifactMetadata.getId() ).isEqualTo( "projectId-1.0.jar" ); assertThat( artifactMetadata.getSha1() ).isEqualTo( TEST_SHA1 ); assertThat( artifactMetadata.getRepositoryId() ).isEqualTo( TEST_REPO_ID ); }
private Collection<String> createArtifactIdList( Collection<ArtifactMetadata> artifacts ) { Collection<String> artifactIds = new ArrayList<>(); for ( ArtifactMetadata artifact : artifacts ) { artifactIds.add( artifact.getId() ); } return artifactIds; } }
@Test public void testGetArtifactVersions() throws Exception { ArtifactMetadata artifact1 = createArtifact(); String version1 = "1.0-20091212.012345-1"; artifact1.setId( artifact1.getProject() + "-" + version1 + ".jar" ); artifact1.setVersion( version1 ); ArtifactMetadata artifact2 = createArtifact(); String version2 = "1.0-20091212.123456-2"; artifact2.setId( artifact2.getProject() + "-" + version2 + ".jar" ); artifact2.setVersion( version2 ); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 ); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 ); Collection<String> versions = repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); assertThat( versions ).isNotNull().isNotEmpty().contains( version1, version2 ); }