public static org.apache.maven.index.artifact.Gav convert(final Gav gav) { final org.apache.maven.index.artifact.Gav.HashType ht = gav.getHashType() != null ? org.apache.maven.index.artifact.Gav.HashType.valueOf(gav.getHashType().name()) : null; final org.apache.maven.index.artifact.Gav.SignatureType st = gav.getSignatureType() != null ? org.apache.maven.index.artifact.Gav.SignatureType .valueOf(gav.getSignatureType().name()) : null; return new org.apache.maven.index.artifact.Gav(gav.getGroupId(), gav.getArtifactId(), gav.getVersion(), gav.getClassifier(), gav.getExtension(), gav.getSnapshotBuildNumber(), gav.getSnapshotTimeStamp(), gav.getName(), gav.isHash(), ht, gav.isSignature(), st); }
latest = gav.getBaseVersion(); if ( !StringUtils.isEmpty( latest ) && Gav.isSnapshot( latest ) ) getLogger().debug( "Resolved gav version from '" + gav.getVersion() + "' to '" + latest + "'" ); new Gav( gav.getGroupId(), gav.getArtifactId(), latest, gav.getClassifier(), gav.getExtension(), buildNo, buildTs, gav.getName(), gav.isHash(), gav.getHashType(), gav.isSignature(), gav.getSignatureType() );
@VisibleForTesting boolean doesImpactMavenMetadata( final Gav requestGav ) { // hashes and signatures are "meta" // released artifacts with classifiers do not change metadata return !( requestGav.isHash() || requestGav.isSignature() || ( StringUtils.isNotBlank( requestGav.getClassifier() ) && !requestGav.isSnapshot() ) ); }
protected boolean pathIsValidSnapshotGav( MavenRepository repository, String path ) { final Gav gav = repository.getGavCalculator().pathToGav( path ); return gav != null && gav.isSnapshot() && !gav.isHash() && !gav.isSignature(); } }
if (gav == null || gav.isSignature() || gav.isHash()) { response.setData(data); data.setGroupId(gav.getGroupId()); data.setArtifactId(gav.getArtifactId()); data.setBaseVersion(gav.getBaseVersion()); data.setVersion(gav.getVersion()); data.setExtension(gav.getExtension()); data.setClassifier(gav.getClassifier());
resource.setGroupId(resolvedGav.getGroupId()); resource.setArtifactId(resolvedGav.getArtifactId()); resource.setVersion(resolvedGav.getVersion()); resource.setClassifier(resolvedGav.getClassifier()); resource.setExtension(resolvedGav.getExtension()); resource.setFileName(resolvedGav.getName()); resource.setSnapshot(resolvedGav.isSnapshot()); resource.setBaseVersion(resolvedGav.getBaseVersion()); if (resolvedGav.getSnapshotBuildNumber() != null) { resource.setSnapshotBuildNumber(resolvedGav.getSnapshotBuildNumber()); resource.setSnapshotTimeStamp(resolvedGav.getSnapshotTimeStamp());
public StorageFileItem retrieveArtifactPom( ArtifactStoreRequest gavRequest ) throws IllegalOperationException, ItemNotFoundException, StorageException, AccessDeniedException { Gav pomGav = new Gav( gavRequest.getGav().getGroupId(), gavRequest.getGav().getArtifactId(), gavRequest.getGav().getVersion(), null, // gavRequest.getGav().getClassifier(), "pom", // gavRequest.getGav().getExtension(), gavRequest.getGav().getSnapshotBuildNumber(), gavRequest.getGav().getSnapshotTimeStamp(), gavRequest.getGav().getName(), gavRequest.getGav().isHash(), gavRequest.getGav().getHashType(), gavRequest.getGav().isSignature(), gavRequest.getGav().getSignatureType() ); ArtifactStoreRequest pomRequest = new ArtifactStoreRequest( gavRequest.getMavenRepository(), pomGav, gavRequest.isRequestLocalOnly(), gavRequest.isRequestRemoteOnly() ); return retrieveArtifact( pomRequest ); }
protected Gav resolveSnapshotFromM3Metadata( final ArtifactStoreRequest gavRequest, final Gav gav, final Metadata gavMd ) throws IOException { for ( SnapshotVersion sv : gavMd.getVersioning().getSnapshotVersions() ) { if ( StringUtils.equals( sv.getExtension(), gav.getExtension() ) && StringUtils.equals( StringUtils.defaultString( sv.getClassifier(), "" ), StringUtils.defaultString( gav.getClassifier(), "" ) ) ) { Long buildTs = getTimeFromMetadataTimestampMaven3Updated( sv.getUpdated() ); Integer buildNo = getBuildNumberForMetadataMaven3Value( sv.getVersion() ); return new Gav( gav.getGroupId(), gav.getArtifactId(), sv.getVersion(), gav.getClassifier(), gav.getExtension(), buildNo, buildTs, gav.getName(), gav.isHash(), gav.getHashType(), gav.isSignature(), gav.getSignatureType() ); } } // even if model version is 1.1.0, we have no snapshots versions? return resolveSnapshotFromM2Metadata( gavRequest, gav, gavMd ); }
private String generateDependencyXml(Gav gav) { StringBuilder buffer = new StringBuilder(); buffer.append("<dependency>\n"); buffer.append(" <groupId>").append(gav.getGroupId()).append("</groupId>\n"); buffer.append(" <artifactId>").append(gav.getArtifactId()).append("</artifactId>\n"); buffer.append(" <version>").append(gav.getBaseVersion()).append("</version>\n"); if (StringUtils.isNotEmpty(gav.getClassifier())) { buffer.append(" <classifier>").append(gav.getClassifier()).append("</classifier>\n"); } if (StringUtils.isNotEmpty(gav.getExtension()) && !StringUtils.equalsIgnoreCase("jar", gav.getExtension())) { buffer.append(" <type>").append(gav.getExtension()).append("</type>\n"); } buffer.append("</dependency>"); return buffer.toString(); }
public String calculateArtifactName( Gav gav ) if ( gav.getName() != null && gav.getName().trim().length() > 0 ) return gav.getName(); StringBuilder path = new StringBuilder( gav.getArtifactId() ); path.append( gav.getVersion() ); if ( gav.getClassifier() != null && gav.getClassifier().trim().length() > 0 ) path.append( gav.getClassifier() ); if ( gav.getExtension() != null ) path.append( gav.getExtension() ); if ( gav.isSignature() ) path.append( gav.getSignatureType().toString() ); if ( gav.isHash() ) path.append( gav.getHashType().toString() );
if ( gav.isSnapshot() && ( !gav.getVersion().equals( gav.getBaseVersion() ) ) ) "Resolving snapshot version for GAV: " + gav.getGroupId() + " : " + gav.getArtifactId() + " : " + gav.getVersion() + " in repository " + repository.getId() );
path.append( gav.getGroupId() ); if ( gav.getClassifier() == null ) path.append( gav.getExtension() ); if ( gav.getClassifier().startsWith( "source" ) ) else if ( gav.getClassifier().startsWith( "client" ) ) path.append( gav.getClassifier() ); path.append( gav.getArtifactId() ); path.append( gav.getVersion() ); if ( gav.getClassifier() != null ) path.append( gav.getClassifier() ); path.append( gav.getExtension() ); if ( gav.isHash() ) path.append( gav.getHashType().toString() );
protected Gav getPomGav( ArtifactStoreRequest request ) { Gav pomGav = new Gav( request.getGav().getGroupId(), // groupId request.getGav().getArtifactId(), // artifactId request.getGav().getVersion(), // version null, // classifier "pom", // extension request.getGav().getSnapshotBuildNumber(), // snapshotBuildNumber request.getGav().getSnapshotTimeStamp(), // snapshotTimeStamp null, // name false, // hash null, // hashType false, // signature null // signatureType ); return pomGav; }
private String getGAVString(NexusArtifactEvent event) { if (event.getNexusItemInfo() == null) { return "unknown:unknown:unknown"; } Gav gav = buildGAV(event); if (gav == null) { return event.getNexusItemInfo().getPath(); } StringBuilder result = new StringBuilder(gav.getGroupId()) .append(":").append(gav.getArtifactId()).append(":").append( gav.getVersion() != null ? gav.getVersion() : "unknown"); if (gav.getClassifier() != null) { result.append(":").append(gav.getClassifier()); } return result.toString(); }
/** * Only when it's a pom file or the file has a classifier will we build the maven artifact entry */ @Override public boolean shouldBuildEntry(NexusArtifactEvent event) { if (!super.shouldBuildEntry(event)) { return false; } Gav gav = buildGAV(event); if (gav == null) { return false; } if (gav.isHash() || gav.isSignature()) { return false; } if ("pom".equalsIgnoreCase(gav.getExtension())) { return true; } if (!StringUtils.isEmpty(gav.getClassifier())) { return true; } return false; } }
public String gavToPath( Gav gav ) { StringBuilder path = new StringBuilder( "/" ); path.append( gav.getGroupId().replaceAll( "(?m)(.)\\.", "$1/" ) ); // replace all '.' except the first char path.append( "/" ); path.append( gav.getArtifactId() ); path.append( "/" ); path.append( gav.getBaseVersion() ); path.append( "/" ); path.append( calculateArtifactName( gav ) ); return path.toString(); }
protected boolean pathIsValidGav( MavenRepository repository, String path ) { final Gav gav = repository.getGavCalculator().pathToGav( path ); return gav != null && !gav.isHash() && gav.isSignature(); } }
if ( !gav.isHash() && !gav.isSignature() && gav.getExtension().equals( "pom" ) ) if ( gav.getSnapshotTimeStamp() != null ) long itemTimestamp = gav.getSnapshotTimeStamp().longValue();
private SnapshotVersion[] buildVersion( Gav gav ) throws MetadataException { if ( gav.getBaseVersion().equals( gav.getVersion() ) ) { return new SnapshotVersion[0]; } SnapshotVersion snap = new SnapshotVersion(); snap.setClassifier( gav.getClassifier() ); snap.setExtension( gav.getExtension() ); snap.setVersion( gav.getVersion() ); Snapshot timestamp = buildSnapshot( gav ); if ( timestamp != null ) { snap.setUpdated( timestamp.getTimestamp().replace( ".", "" ) ); } else { snap.setUpdated( TimeUtil.getUTCTimestamp().replace( ".", "" ) ); } return new SnapshotVersion[] { snap }; }
/** * Transforms a full artifact path from M1 layout to M2 layout. * * @param path * @return */ protected String transformM1toM2( final String path ) { final Gav gav = getM1GavCalculator().pathToGav( path ); // Unsupported path if ( gav == null ) { return null; } // m2 repo is layouted as: // g/i/d // aid // version // files StringBuilder sb = new StringBuilder( RepositoryItemUid.PATH_ROOT ); sb.append( gav.getGroupId().replaceAll( "\\.", "/" ) ); sb.append( RepositoryItemUid.PATH_SEPARATOR ); sb.append( gav.getArtifactId() ); sb.append( RepositoryItemUid.PATH_SEPARATOR ); sb.append( gav.getVersion() ); sb.append( RepositoryItemUid.PATH_SEPARATOR ); sb.append( gav.getName() ); return sb.toString(); }