From 02048b76b6a7dfbd7d14b1fef8379c8f0a0d932a Mon Sep 17 00:00:00 2001 From: Wenjie Guo Date: Tue, 7 Jan 2025 10:53:43 +0800 Subject: [PATCH] Fix the incompatible issue on parsing npm version --- .../indy/pkg/npm/model/Directories.java | 32 +++++++++---------- .../pkg/npm/model/VersionMetadataTest.java | 24 ++++++++++++++ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Directories.java b/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Directories.java index aad4adacbe..e8dc4241cf 100644 --- a/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Directories.java +++ b/addons/pkg-npm/model-java/src/main/java/org/commonjava/indy/pkg/npm/model/Directories.java @@ -35,83 +35,83 @@ public class Directories private static final String TEST = "test"; - private Map directoriesMap = new HashMap(); + private Map directoriesMap = new HashMap(); protected Directories() { } - public String getLib() + public Object getLib() { return directoriesMap.get( LIB ); } - public void setLib( String lib ) + public void setLib( Object lib ) { directoriesMap.put( LIB, lib ); } - public String getBin() + public Object getBin() { return directoriesMap.get( BIN ); } - public void setBin( String bin ) + public void setBin( Object bin ) { directoriesMap.put( BIN, bin ); } - public String getMan() + public Object getMan() { return directoriesMap.get( MAN ); } - public void setMan( String man ) + public void setMan( Object man ) { directoriesMap.put( MAN, man ); } - public String getDoc() + public Object getDoc() { return directoriesMap.get( DOC ); } - public void setDoc( String doc ) + public void setDoc( Object doc ) { directoriesMap.put( DOC, doc ); } - public String getExample() + public Object getExample() { return directoriesMap.get( EXAMPLE ); } - public void setExample( String example ) + public void setExample( Object example ) { directoriesMap.put( EXAMPLE, example ); } - public String getTest() + public Object getTest() { return directoriesMap.get( TEST ); } - public void setTest( String test ) + public void setTest( Object test ) { directoriesMap.put( TEST, test ); } - public Map fetchDirectoriesMap() + public Map fetchDirectoriesMap() { return directoriesMap; } - public String getDirectory( String name ) + public Object getDirectory( String name ) { return directoriesMap.get( name ); } - public void putDirectory( String name, String value ) + public void putDirectory( String name, Object value ) { directoriesMap.put( name, value ); } diff --git a/addons/pkg-npm/model-java/src/test/java/org/commonjava/indy/pkg/npm/model/VersionMetadataTest.java b/addons/pkg-npm/model-java/src/test/java/org/commonjava/indy/pkg/npm/model/VersionMetadataTest.java index dab4200b76..a38190afa2 100644 --- a/addons/pkg-npm/model-java/src/test/java/org/commonjava/indy/pkg/npm/model/VersionMetadataTest.java +++ b/addons/pkg-npm/model-java/src/test/java/org/commonjava/indy/pkg/npm/model/VersionMetadataTest.java @@ -20,8 +20,12 @@ import org.commonjava.indy.pkg.npm.model.io.PackageSerializerModule; import org.junit.Test; +import java.net.URL; +import java.nio.charset.Charset; + import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.fail; public class VersionMetadataTest { @@ -76,4 +80,24 @@ public void customDeserializerTest() throws Exception assertThat( version.getLicenses().get( 0 ).getType(), equalTo( "GPLv2" ) ); assertThat( version.getDist().getTarball(), equalTo( "https://registry.npmjs.org/tmp/-/tmp-0.0.4.tgz" ) ); } + + //@Test + public void deserializeVersionMetadataTest() throws Exception + { + // Update this url for the specific package version + String url = "https://repository.engineering.redhat.com/nexus/repository/registry.npmjs.org/eslint-plugin-react/7.37.3"; + + final IndyObjectMapper mapper = new IndyObjectMapper( true ); + mapper.registerModule( new PackageSerializerModule() ); + String json = IOUtils.toString( new URL(url), Charset.defaultCharset() ); + + try + { + mapper.readValue(json, VersionMetadata.class); + } + catch (Exception e) + { + fail("Unexpected exception was thrown:" + e.getMessage()); + } + } }