public Env() { try { this.repositories.put("spring-snapshots", new Repository("Spring Snapshots", new URL("https://repo.spring.io/snapshot"), true)); this.repositories.put("spring-milestones", new Repository("Spring Milestones", new URL("https://repo.spring.io/milestone"), false)); } catch (MalformedURLException ex) { throw new IllegalStateException("Cannot parse URL", ex); } }
private static JsonNode mapRepository(Repository repo) { ObjectNode node = nodeFactory.objectNode(); node.put("name", repo.getName()) .put("url", (repo.getUrl() != null) ? repo.getUrl().toString() : null) .put("snapshotEnabled", repo.isSnapshotsEnabled()); return node; }
public InitializrMetadataTestBuilder addRepository(String id, String name, String url, boolean snapshotsEnabled) { this.builder.withCustomizer((it) -> { Repository repo = new Repository(); repo.setName(name); try { repo.setUrl(new URL(url)); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Cannot create URL", ex); } repo.setSnapshotsEnabled(snapshotsEnabled); it.getConfiguration().getEnv().getRepositories().put(id, repo); }); return this; }
@Test void mapDependency() throws Exception { Dependency d = Dependency.withId("foo", "org.foo", "foo"); d.setRepository("my-repo"); d.setBom("my-bom"); Repository repository = new Repository(); repository.setName("foo-repo"); repository.setUrl(new URL("http://example.com/foo")); BillOfMaterials bom = BillOfMaterials.create("org.foo", "foo-bom", "1.0.0.RELEASE"); DependencyMetadata metadata = new DependencyMetadata( Version.parse("1.2.0.RELEASE"), Collections.singletonMap(d.getId(), d), Collections.singletonMap("repo-id", repository), Collections.singletonMap("bom-id", bom)); JSONObject content = new JSONObject(this.mapper.write(metadata)); assertThat(content.getJSONObject("dependencies").getJSONObject("foo") .getString("bom")).isEqualTo("my-bom"); assertThat(content.getJSONObject("dependencies").getJSONObject("foo") .getString("repository")).isEqualTo("my-repo"); assertThat(content.getJSONObject("repositories").getJSONObject("repo-id") .getString("name")).isEqualTo("foo-repo"); assertThat(content.getJSONObject("boms").getJSONObject("bom-id") .getString("artifactId")).isEqualTo("foo-bom"); assertThat(content.getJSONObject("boms").getJSONObject("bom-id") .getString("version")).isEqualTo("1.0.0.RELEASE"); }
@Test void repoFromBomAccordingToVersion() { DependencyMetadata dependencyMetadata = testRepoFromBomAccordingToVersion( "1.0.9.RELEASE"); assertThat(dependencyMetadata.getBootVersion()) .isEqualTo(Version.parse("1.0.9.RELEASE")); assertThat(dependencyMetadata.getDependencies()).hasSize(3); assertThat(dependencyMetadata.getRepositories()).hasSize(2); assertThat(dependencyMetadata.getBoms()).hasSize(1); assertThat(dependencyMetadata.getRepositories().get("repo-foo").getName()) .isEqualTo("foo"); assertThat(dependencyMetadata.getRepositories().get("repo-bar").getName()) .isEqualTo("bar"); assertThat(dependencyMetadata.getBoms().get("bom-foo").getGroupId()) .isEqualTo("org.foo"); assertThat(dependencyMetadata.getBoms().get("bom-foo").getArtifactId()) .isEqualTo("bom"); assertThat(dependencyMetadata.getBoms().get("bom-foo").getVersion()) .isEqualTo("2.0.0.RELEASE"); }
Node item = nodes.item(i); if (item instanceof Element) { Repository repository = new Repository(); Element element = (Element) item; NodeList type = element.getElementsByTagName("id"); NodeList name = element.getElementsByTagName("name"); if (name.getLength() > 0) { repository.setName(name.item(0).getTextContent()); repository.setUrl(new URL(url.item(0).getTextContent())); .getElementsByTagName("enabled"); if (snapshotsEnabled.getLength() > 0) { repository.setSnapshotsEnabled( "true".equals(snapshotsEnabled.item(0).getTextContent()));
@Test void repoFromBomAccordingToAnotherVersion() { DependencyMetadata dependencyMetadata = testRepoFromBomAccordingToVersion( "1.1.5.RELEASE"); assertThat(dependencyMetadata.getBootVersion()) .isEqualTo(Version.parse("1.1.5.RELEASE")); assertThat(dependencyMetadata.getDependencies()).hasSize(3); assertThat(dependencyMetadata.getRepositories()).hasSize(2); assertThat(dependencyMetadata.getBoms()).hasSize(1); assertThat(dependencyMetadata.getRepositories().get("repo-foo").getName()) .isEqualTo("foo"); assertThat(dependencyMetadata.getRepositories().get("repo-biz").getName()) .isEqualTo("biz"); assertThat(dependencyMetadata.getBoms().get("bom-foo").getGroupId()) .isEqualTo("org.foo"); assertThat(dependencyMetadata.getBoms().get("bom-foo").getArtifactId()) .isEqualTo("bom"); assertThat(dependencyMetadata.getBoms().get("bom-foo").getVersion()) .isEqualTo("3.0.0.RELEASE"); }
public PomAssert hasRepository(String id, String name, String url, Boolean snapshotsEnabled) { assertThat(this.repositories).containsKeys(id); Repository repository = this.repositories.get(id); if (name != null) { assertThat(repository.getName()).isEqualTo(name); } if (url != null) { try { assertThat(repository.getUrl()).isEqualTo(new URL(url)); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Cannot parse URL", ex); } } if (snapshotsEnabled) { assertThat(repository.isSnapshotsEnabled()).isEqualTo(snapshotsEnabled); } return this; }
@Test void invalidRepository() throws MalformedURLException { InitializrMetadata metadata = initializeMetadata(); Dependency foo = Dependency.withId("foo", "org.acme", "foo"); foo.setRepository("foo-repo"); addTestDependencyGroup(metadata, foo); metadata.getConfiguration().getEnv().getRepositories().put("my-repo", new Repository("repo", new URL("http://example.com/repo"), true)); assertThatExceptionOfType(InvalidInitializrMetadataException.class) .isThrownBy(metadata::validate).withMessageContaining("foo-repo") .withMessageContaining("my-repo"); }
@Test void mergeMetadataWithRepository() throws Exception { InitializrMetadata metadata = InitializrMetadataBuilder.create() .withInitializrMetadata( new ClassPathResource("metadata/config/test-repository.json")) .build(); Map<String, Repository> repositories = metadata.getConfiguration().getEnv() .getRepositories(); assertThat(repositories).hasSize(4); // 2 standard repos Repository myRepo = repositories.get("my-repo"); assertThat(myRepo).isNotNull(); assertThat(myRepo.getName()).isEqualTo("my repo"); assertThat(myRepo.getUrl()).isEqualTo(new URL("http://example.com/my")); assertThat(myRepo.isSnapshotsEnabled()).isEqualTo(true); Repository anotherRepo = repositories.get("another-repo"); assertThat(anotherRepo).isNotNull(); assertThat(anotherRepo.getName()).isEqualTo("another repo"); assertThat(anotherRepo.getUrl()).isEqualTo(new URL("http://example.com/another")); assertThat(anotherRepo.isSnapshotsEnabled()).isEqualTo(false); }