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;
}
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"));
}
Aggregations