Search in sources :

Example 1 with Repository

use of org.commonjava.indy.pkg.npm.model.Repository in project indy by Commonjava.

the class VersionMetadataDeserializer method deserialize.

@Override
public VersionMetadata deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    final ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
    final JsonNode vNode = mapper.readTree(jsonParser);
    VersionMetadata vm = new VersionMetadata(parseValue(vNode, "name"), parseValue(vNode, "version"));
    vm.setDescription(parseValue(vNode, "description"));
    JsonNode repoNode = vNode.get("repository");
    if (repoNode instanceof ArrayNode) {
        repoNode = repoNode.get(0);
    }
    vm.setRepository(new Repository(parseValue(repoNode, "type"), parseValue(repoNode, "url")));
    vm.setAuthor(parseObject(mapper, vNode.get("author"), UserInfo.class));
    vm.setBugs(parseObject(mapper, vNode.get("bugs"), Bugs.class));
    vm.setDist(parseObject(mapper, vNode.get("dist"), Dist.class));
    vm.setDirectories(parseObject(mapper, vNode.get("directories"), Directories.class));
    vm.setKeywords(parseList(mapper, vNode.get("keywords"), String.class));
    vm.setLicense(parseObject(mapper, vNode.get("license"), License.class));
    vm.setMain(parseValue(vNode, "main"));
    vm.setUrl(parseValue(vNode, "url"));
    vm.setContributors(parseList(mapper, vNode.get("contributors"), UserInfo.class));
    vm.setEngines(parseList(mapper, vNode.get("engines"), Engines.class));
    vm.setDependencies(parseObject(mapper, vNode.get("dependencies"), Map.class));
    vm.setDevDependencies(parseObject(mapper, vNode.get("devDependencies"), Map.class));
    vm.setMaintainers(parseList(mapper, vNode.get("maintainers"), UserInfo.class));
    vm.setLicenses(parseList(mapper, vNode.get("licenses"), License.class));
    vm.setScripts(parseObject(mapper, vNode.get("scripts"), Map.class));
    return vm;
}
Also used : Bugs(org.commonjava.indy.pkg.npm.model.Bugs) Dist(org.commonjava.indy.pkg.npm.model.Dist) License(org.commonjava.indy.pkg.npm.model.License) JsonNode(com.fasterxml.jackson.databind.JsonNode) UserInfo(org.commonjava.indy.pkg.npm.model.UserInfo) Engines(org.commonjava.indy.pkg.npm.model.Engines) Directories(org.commonjava.indy.pkg.npm.model.Directories) Repository(org.commonjava.indy.pkg.npm.model.Repository) VersionMetadata(org.commonjava.indy.pkg.npm.model.VersionMetadata) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Repository

use of org.commonjava.indy.pkg.npm.model.Repository in project indy by Commonjava.

the class PackageMetadataMergerTest method mergeOneTransferWithProviderContent.

@Test
public void mergeOneTransferWithProviderContent() throws Exception {
    String path = "jquery";
    HostedRepository h1 = new HostedRepository(NPM_PKG_KEY, "test-hosted-1");
    HostedRepository h2 = new HostedRepository(NPM_PKG_KEY, "test-hosted-2");
    Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
    initTestData(t1, VERSION_META + "package-1.json");
    Transfer t2 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h2), path));
    initTestData(t2, VERSION_META + "package-2.json");
    Group g = new Group(NPM_PKG_KEY, "test-group", h1.getKey(), h2.getKey());
    List<Transfer> sources = Arrays.asList(t1, t2);
    PackageMetadata provided = new PackageMetadata("jquery");
    provided.setDescription("provider description test");
    provided.setRepository(new Repository("svn", "svn+https://svn.host/jquery"));
    provided.setBugs(new Bugs("https://github.com/jquery2/jquery2/issues", "jquery2@bug.com"));
    List<UserInfo> added = new ArrayList<UserInfo>();
    added.add(new UserInfo("testa", "testa@test.com"));
    provided.setMaintainers(added);
    TestPackageMetadataProvider testProvider = new TestPackageMetadataProvider(provided);
    byte[] output = new PackageMetadataMerger(Collections.singletonList(testProvider), mapper).merge(sources, g, path);
    PackageMetadata merged = mapper.readValue(IOUtils.toString(new ByteArrayInputStream(output)), PackageMetadata.class);
    // normal object fields merging verification
    assertThat(merged.getName(), equalTo("jquery"));
    assertThat(merged.getDescription(), equalTo("provider description test"));
    assertThat(merged.getRepository().getType(), equalTo("svn"));
    assertThat(merged.getRepository().getUrl(), equalTo("svn+https://svn.host/jquery"));
    assertThat(merged.getBugs().getUrl(), equalTo("https://github.com/jquery2/jquery2/issues"));
    assertThat(merged.getBugs().getEmail(), equalTo("jquery2@bug.com"));
    // maintainers list merging verification
    List<UserInfo> maintainers = merged.getMaintainers();
    assertThat(maintainers, notNullValue());
    assertThat(maintainers.size(), equalTo(4));
    assertThat(maintainers.get(0).getName(), equalTo("dmethvin"));
    assertThat(maintainers.get(1).getName(), equalTo("mgol"));
    assertThat(maintainers.get(2).getName(), equalTo("scott.gonzalez"));
    assertThat(maintainers.get(3).getName(), equalTo("testa"));
}
Also used : Bugs(org.commonjava.indy.pkg.npm.model.Bugs) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) UserInfo(org.commonjava.indy.pkg.npm.model.UserInfo) Repository(org.commonjava.indy.pkg.npm.model.Repository) HostedRepository(org.commonjava.indy.model.core.HostedRepository) ByteArrayInputStream(java.io.ByteArrayInputStream) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Aggregations

Bugs (org.commonjava.indy.pkg.npm.model.Bugs)2 Repository (org.commonjava.indy.pkg.npm.model.Repository)2 UserInfo (org.commonjava.indy.pkg.npm.model.UserInfo)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Group (org.commonjava.indy.model.core.Group)1 HostedRepository (org.commonjava.indy.model.core.HostedRepository)1 Directories (org.commonjava.indy.pkg.npm.model.Directories)1 Dist (org.commonjava.indy.pkg.npm.model.Dist)1 Engines (org.commonjava.indy.pkg.npm.model.Engines)1 License (org.commonjava.indy.pkg.npm.model.License)1 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)1 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 Test (org.junit.Test)1