From e21e661fb6985cd289ddf767955901e41bc4c317 Mon Sep 17 00:00:00 2001 From: liyu Date: Mon, 9 Dec 2024 18:33:34 +0800 Subject: [PATCH 1/5] check tarball string as well in the generation phase --- .../indy/pkg/npm/content/PackageMetadataGenerator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java index f490a103a7..6a9fb93cbb 100644 --- a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java +++ b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java @@ -321,9 +321,10 @@ private boolean writePackageMetadata( List firstLevelFiles, Artif } // Generate tarball url if missing - if ( versionMetadata.getDist() == null ) + String tarball = "http://indy/" + packagePath.getTarPath(); // here we use mock host. indy will amend it with the right hostname + + if ( versionMetadata.getDist() == null || !versionMetadata.getDist().getTarball().equals(tarball) ) { - String tarball = "http://indy/" + packagePath.getTarPath(); // here we use mock host. indy will amend it with the right hostname //logger.debug( "Generate dist tarball: {}", tarball ); versionMetadata.setDist( new Dist( tarball ) ); } From d2b2fd3d6d9ffac5378334f0bfc811119b3faa0b Mon Sep 17 00:00:00 2001 From: liyu Date: Tue, 10 Dec 2024 12:27:09 +0800 Subject: [PATCH 2/5] correct tarball path compare --- .../indy/pkg/npm/content/PackageMetadataGenerator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java index 6a9fb93cbb..e40b3731f2 100644 --- a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java +++ b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java @@ -321,10 +321,9 @@ private boolean writePackageMetadata( List firstLevelFiles, Artif } // Generate tarball url if missing - String tarball = "http://indy/" + packagePath.getTarPath(); // here we use mock host. indy will amend it with the right hostname - - if ( versionMetadata.getDist() == null || !versionMetadata.getDist().getTarball().equals(tarball) ) + if ( versionMetadata.getDist() == null || !versionMetadata.getDist().getTarball().endsWith(packagePath.getTarPath()) ) { + String tarball = "http://indy/" + packagePath.getTarPath(); // here we use mock host. indy will amend it with the right hostname //logger.debug( "Generate dist tarball: {}", tarball ); versionMetadata.setDist( new Dist( tarball ) ); } From 4686237749ba6deb4f2c87d4557fc73d0480b19f Mon Sep 17 00:00:00 2001 From: liyu Date: Wed, 11 Dec 2024 17:12:49 +0800 Subject: [PATCH 3/5] update to preserve Dist content while update it's path only --- .../pkg/npm/content/PackageMetadataGenerator.java | 13 ++++++++++--- .../org/commonjava/indy/pkg/npm/model/Dist.java | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java index e40b3731f2..5b0bd3a3e2 100644 --- a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java +++ b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java @@ -321,11 +321,18 @@ private boolean writePackageMetadata( List firstLevelFiles, Artif } // Generate tarball url if missing - if ( versionMetadata.getDist() == null || !versionMetadata.getDist().getTarball().endsWith(packagePath.getTarPath()) ) + String tarball = "http://indy/" + packagePath.getTarPath(); // here we use mock host. indy will amend it with the right hostname + if ( versionMetadata.getDist() == null ) { - String tarball = "http://indy/" + packagePath.getTarPath(); // here we use mock host. indy will amend it with the right hostname //logger.debug( "Generate dist tarball: {}", tarball ); - versionMetadata.setDist( new Dist( tarball ) ); + versionMetadata.setDist( new Dist( tarball ) ); + } else { + if ( !versionMetadata.getDist().getTarball().endsWith(packagePath.getTarPath()) ) + { + versionMetadata.setDist( new Dist( tarball, versionMetadata.getDist().getShasum(), versionMetadata.getDist().getIntegrity(), + versionMetadata.getDist().getFileCount(), versionMetadata.getDist().getUnpackedSize(), + versionMetadata.getDist().getSignatures(), versionMetadata.getDist().getNpmSignature() ) ); + } } } catch ( IOException e ) diff --git a/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java b/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java index cf0ae0c680..c1981096a2 100644 --- a/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java +++ b/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java @@ -59,6 +59,17 @@ public Dist( final String tarball ) this.npmSignature = null; } + public Dist( final String tarball, final String shasum, final String integrity, final Integer fileCount, final Long unpackedSize, final List> signatures, final String npmSignature ) + { + this.tarball = tarball; + this.shasum = shasum; + this.integrity = integrity; + this.fileCount = fileCount; + this.unpackedSize = unpackedSize; + this.signatures = signatures; + this.npmSignature = npmSignature; + } + public String getShasum() { return shasum; From 7e25a0cde688141a976a3eb0b3b3f5a7cb8904e5 Mon Sep 17 00:00:00 2001 From: liyu Date: Thu, 12 Dec 2024 10:13:19 +0800 Subject: [PATCH 4/5] add detection of null in dist --- .../indy/pkg/npm/content/PackageMetadataGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java index 5b0bd3a3e2..ac9761c5f0 100644 --- a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java +++ b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java @@ -327,7 +327,7 @@ private boolean writePackageMetadata( List firstLevelFiles, Artif //logger.debug( "Generate dist tarball: {}", tarball ); versionMetadata.setDist( new Dist( tarball ) ); } else { - if ( !versionMetadata.getDist().getTarball().endsWith(packagePath.getTarPath()) ) + if ( versionMetadata.getDist().getTarball() == null || !versionMetadata.getDist().getTarball().endsWith(packagePath.getTarPath()) ) { versionMetadata.setDist( new Dist( tarball, versionMetadata.getDist().getShasum(), versionMetadata.getDist().getIntegrity(), versionMetadata.getDist().getFileCount(), versionMetadata.getDist().getUnpackedSize(), From 9556e4ce3b7df3416a23bf6e13364ebcfc8a17aa Mon Sep 17 00:00:00 2001 From: liyu Date: Thu, 12 Dec 2024 10:32:01 +0800 Subject: [PATCH 5/5] add setter --- .../npm/content/PackageMetadataGenerator.java | 7 ++++--- .../commonjava/indy/pkg/npm/model/Dist.java | 18 ++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java index ac9761c5f0..f8289bf14b 100644 --- a/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java +++ b/addons/pkg-npm/common/src/main/java/org/commonjava/indy/pkg/npm/content/PackageMetadataGenerator.java @@ -327,11 +327,12 @@ private boolean writePackageMetadata( List firstLevelFiles, Artif //logger.debug( "Generate dist tarball: {}", tarball ); versionMetadata.setDist( new Dist( tarball ) ); } else { + // Detect bad tarball and replace with correct one if ( versionMetadata.getDist().getTarball() == null || !versionMetadata.getDist().getTarball().endsWith(packagePath.getTarPath()) ) { - versionMetadata.setDist( new Dist( tarball, versionMetadata.getDist().getShasum(), versionMetadata.getDist().getIntegrity(), - versionMetadata.getDist().getFileCount(), versionMetadata.getDist().getUnpackedSize(), - versionMetadata.getDist().getSignatures(), versionMetadata.getDist().getNpmSignature() ) ); + Dist dist = versionMetadata.getDist(); + dist.setTarball( tarball ); + versionMetadata.setDist( dist ); } } } diff --git a/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java b/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java index c1981096a2..4d70edbfce 100644 --- a/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java +++ b/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Dist.java @@ -25,7 +25,7 @@ public class Dist private final String shasum; - private final String tarball; + private String tarball; private final String integrity; @@ -59,17 +59,6 @@ public Dist( final String tarball ) this.npmSignature = null; } - public Dist( final String tarball, final String shasum, final String integrity, final Integer fileCount, final Long unpackedSize, final List> signatures, final String npmSignature ) - { - this.tarball = tarball; - this.shasum = shasum; - this.integrity = integrity; - this.fileCount = fileCount; - this.unpackedSize = unpackedSize; - this.signatures = signatures; - this.npmSignature = npmSignature; - } - public String getShasum() { return shasum; @@ -80,6 +69,11 @@ public String getTarball() return tarball; } + public void setTarball( String tarball ) + { + this.tarball = tarball; + } + public String getIntegrity() { return integrity;