Skip to content

Commit

Permalink
Merge pull request #2490 from sswguo/version_metadata_fix
Browse files Browse the repository at this point in the history
Fix the incompatible issue on parsing npm version
  • Loading branch information
sswguo authored Jan 7, 2025
2 parents 733d4fd + 02048b7 commit ce6ad50
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,83 +35,83 @@ public class Directories

private static final String TEST = "test";

private Map<String, String> directoriesMap = new HashMap<String, String>();
private Map<String, Object> directoriesMap = new HashMap<String, Object>();

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<String, String> fetchDirectoriesMap()
public Map<String, Object> 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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit ce6ad50

Please sign in to comment.