Skip to content

Commit

Permalink
Fix missing runtime dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Nov 17, 2022
1 parent a94a9ac commit c515541
Show file tree
Hide file tree
Showing 19 changed files with 758 additions and 3 deletions.
7 changes: 7 additions & 0 deletions nbdemetra-anomalydetection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
<scope>provided</scope>
</dependency>

<!-- test only -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<!-- NetBeans -->
<dependency>
<groupId>org.netbeans.api</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ec.nbdemetra.anomalydetection;

import ec.nbdemetra.core.NbmMavenClassPath;
import nbbrd.io.FileParser;
import org.assertj.core.api.Condition;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.jar.Manifest;

import static org.assertj.core.api.Assertions.assertThat;

public class RuntimeDependenciesTest {

@Test
public void test() throws IOException {
assertThat(getRuntimeDependencies())
.describedAs("Check runtime dependencies")
.satisfies(RuntimeDependenciesTest::checkNoDemetra)
.satisfies(RuntimeDependenciesTest::checkNoJavaIoUtil)
.satisfies(RuntimeDependenciesTest::checkNoSlf4j)
.satisfies(RuntimeDependenciesTest::checkNoGuava)
.isEmpty();
}

private static void checkNoGuava(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.google.guava").isEmpty();
}

private static void checkNoSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "org.slf4j").isEmpty();
}

private static void checkNoJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util").isEmpty();
}

private static void checkNoDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat").isEmpty();
}

private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) {
return assertThat(coordinates)
.describedAs("Check " + groupId)
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId);
}

private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() {
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version");
}

private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException {
return FileParser.onParsingStream(Manifest::new)
.andThen(NbmMavenClassPath::parse)
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf");
}
}
7 changes: 7 additions & 0 deletions nbdemetra-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<url>https://github.com/jdemetra/jdemetra-app</url>

<dependencies>
<!-- test only -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<!-- NetBeans -->
<dependency>
<groupId>org.netbeans.api</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ec.nbdemetra.common;

import ec.nbdemetra.core.NbmMavenClassPath;
import nbbrd.io.FileParser;
import org.assertj.core.api.Condition;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.jar.Manifest;

import static org.assertj.core.api.Assertions.assertThat;

public class RuntimeDependenciesTest {

@Test
public void test() throws IOException {
assertThat(getRuntimeDependencies())
.describedAs("Check runtime dependencies")
.satisfies(RuntimeDependenciesTest::checkDemetra)
.satisfies(RuntimeDependenciesTest::checkNoJavaIoUtil)
.satisfies(RuntimeDependenciesTest::checkNoSlf4j)
.satisfies(RuntimeDependenciesTest::checkNoGuava)
.hasSize(2);
}

private static void checkNoGuava(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.google.guava").isEmpty();
}

private static void checkNoSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "org.slf4j").isEmpty();
}

private static void checkNoJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util").isEmpty();
}

private static void checkDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat")
.has(sameVersion())
.extracting(NbmMavenClassPath.GAV::getArtifactId)
.containsExactlyInAnyOrder("demetra-common");
}

private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) {
return assertThat(coordinates)
.describedAs("Check " + groupId)
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId);
}

private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() {
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version");
}

private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException {
return FileParser.onParsingStream(Manifest::new)
.andThen(NbmMavenClassPath::parse)
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf");
}
}
9 changes: 8 additions & 1 deletion nbdemetra-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
<artifactId>checker-qual</artifactId>
<scope>provided</scope>
</dependency>


<!-- test only -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<!-- NetBeans -->
<dependency>
<groupId>org.netbeans.api</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ec.nbdemetra.core;

import lombok.NonNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@lombok.experimental.UtilityClass
public class NbmMavenClassPath {

public static @NonNull List<GAV> parse(@NonNull Manifest manifest) {
String items = manifest.getMainAttributes().getValue("Maven-Class-Path");
return items != null
? splitAsStream(items, ' ').map(GAV::parse).collect(Collectors.toList())
: Collections.emptyList();
}

private static Stream<String> splitAsStream(String items, char sep) {
return Arrays.stream(items.split(String.valueOf(sep), -1));
}

@lombok.Value
public static class GAV {

public static @NonNull GAV parse(@NonNull CharSequence input) throws IllegalArgumentException {
String[] items = input.toString().split(":", -1);
if (items.length != 3) {
throw new IllegalArgumentException("Invalid GAV: '" + input + "'");
}
return new GAV(items[0], items[1], items[2]);
}

@NonNull String groupId;
@NonNull String artifactId;
@NonNull String version;

public static boolean haveSameVersion(@NonNull List<? extends GAV> list) {
return list
.stream()
.map(GAV::getVersion)
.distinct()
.count() == 1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package ec.nbdemetra.core;

import nbbrd.io.FileParser;
import org.assertj.core.api.Condition;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.jar.Manifest;

import static org.assertj.core.api.Assertions.assertThat;

public class RuntimeDependenciesTest {

@Test
public void test() throws IOException {
assertThat(getRuntimeDependencies())
.describedAs("Check runtime dependencies")
.satisfies(RuntimeDependenciesTest::checkDemetra)
.satisfies(RuntimeDependenciesTest::checkJavaIoUtil)
.satisfies(RuntimeDependenciesTest::checkSlf4j)
.satisfies(RuntimeDependenciesTest::checkGuava)
.hasSize(21);
}

private static void checkGuava(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.google.guava")
.extracting(NbmMavenClassPath.GAV::getArtifactId)
.contains("guava")
.hasSize(3);
}

private static void checkSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "org.slf4j")
.has(sameVersion())
.extracting(NbmMavenClassPath.GAV::getArtifactId)
.containsExactlyInAnyOrder("slf4j-api", "slf4j-jdk14", "jcl-over-slf4j");
}

private static void checkJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util")
.has(sameVersion())
.hasSize(3);
}

private static void checkDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat")
.has(sameVersion())
.extracting(NbmMavenClassPath.GAV::getArtifactId)
.containsExactlyInAnyOrder("demetra-tss", "demetra-tstoolkit", "demetra-utils", "demetra-workspace");
}

private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) {
return assertThat(coordinates)
.describedAs("Check " + groupId)
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId);
}

private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() {
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version");
}

private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException {
return FileParser.onParsingStream(Manifest::new)
.andThen(NbmMavenClassPath::parse)
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf");
}
}
7 changes: 7 additions & 0 deletions nbdemetra-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<scope>provided</scope>
</dependency>

<!-- test only -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<!-- NetBeans -->
<dependency>
<groupId>org.netbeans.api</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package ec.nbdemetra.jdbc;

import ec.nbdemetra.core.NbmMavenClassPath;
import nbbrd.io.FileParser;
import org.assertj.core.api.Condition;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.jar.Manifest;

import static org.assertj.core.api.Assertions.assertThat;

public class RuntimeDependenciesTest {

@Test
public void test() throws IOException {
assertThat(getRuntimeDependencies())
.describedAs("Check runtime dependencies")
.satisfies(RuntimeDependenciesTest::checkDemetra)
.satisfies(RuntimeDependenciesTest::checkJavaSqlUtil)
.satisfies(RuntimeDependenciesTest::checkNoJavaIoUtil)
.satisfies(RuntimeDependenciesTest::checkNoSlf4j)
.satisfies(RuntimeDependenciesTest::checkNoGuava)
.hasSize(2);
}

private static void checkNoGuava(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.google.guava").isEmpty();
}

private static void checkNoSlf4j(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "org.slf4j").isEmpty();
}

private static void checkNoJavaIoUtil(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.github.nbbrd.java-io-util").isEmpty();
}

private static void checkJavaSqlUtil(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "com.github.nbbrd.java-sql-util")
.has(sameVersion())
.extracting(NbmMavenClassPath.GAV::getArtifactId)
.containsExactlyInAnyOrder("java-sql-jdbc");
}

private static void checkDemetra(List<? extends NbmMavenClassPath.GAV> coordinates) {
assertThatGroupId(coordinates, "eu.europa.ec.joinup.sat")
.has(sameVersion())
.extracting(NbmMavenClassPath.GAV::getArtifactId)
.containsExactlyInAnyOrder("demetra-jdbc");
}

private static ListAssert<? extends NbmMavenClassPath.GAV> assertThatGroupId(List<? extends NbmMavenClassPath.GAV> coordinates, String groupId) {
return assertThat(coordinates)
.describedAs("Check " + groupId)
.filteredOn(NbmMavenClassPath.GAV::getGroupId, groupId);
}

private static Condition<List<? extends NbmMavenClassPath.GAV>> sameVersion() {
return new Condition<>(NbmMavenClassPath.GAV::haveSameVersion, "same version");
}

private static List<NbmMavenClassPath.GAV> getRuntimeDependencies() throws IOException {
return FileParser.onParsingStream(Manifest::new)
.andThen(NbmMavenClassPath::parse)
.parseResource(RuntimeDependenciesTest.class, "/runtime-dependencies.mf");
}
}
7 changes: 7 additions & 0 deletions nbdemetra-odbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<url>https://github.com/jdemetra/jdemetra-app</url>

<dependencies>
<!-- test only -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<!-- NetBeans -->
<dependency>
<groupId>org.netbeans.api</groupId>
Expand Down
Loading

0 comments on commit c515541

Please sign in to comment.