diff --git a/config/UpdateWalletConfig/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java b/config/UpdateWalletConfig/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java deleted file mode 100644 index ddb02f11..00000000 --- a/config/UpdateWalletConfig/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - The Janus Wallet - Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB - - This program is free software: you can redistribute it and/or modify it under the terms of the - addended GNU Affero General Public License as published by the Free Software Foundation, version 3 - of the License (see COPYING and COPYING.addendum). - - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received an addended copy of the GNU Affero General Public License with this program. - If not, see and . - */ -package org.unigrid.updatewalletconfig; - -import com.jayway.jsonpath.DocumentContext; -import com.jayway.jsonpath.JsonPath; -import java.io.IOException; -import java.io.InputStream; -import java.io.Writer; -import java.net.URI; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Stream; -import org.update4j.Configuration; -import org.update4j.FileMetadata; -import org.update4j.OS; - -public class UpdateWalletConfig { - - private static final String MAVEN_BASE = "https://repo1.maven.org/maven2"; - - public static void main(String[] args) throws IOException { - - String configLocation = System.getProperty("user.dir"); - String homeDir = System.getProperty("user.home"); - String dir = configLocation; - String fxJarUrl = "https://github.com/unigrid-project/unigrid-update/releases/download/v1.0.9/fx-1.0.9-SNAPSHOT.jar"; - String linuxDaemon = "unigrid-2.9.3-x86_64-linux-gnu.tar.gz"; - String windowsDaemon = "unigrid-2.9.3-win64.zip"; - String osxDaemon = "unigrid-2.9.3-osx64.tar.gz"; - String fxVersion = "1.0.9"; - String[] filePath = new String[]{ - "/config-linux.xml", - "/config-linux-test.xml", - "/config-windows.xml", - "/config-windows-test.xml", - "/config-mac.xml", - "/config-mac-test.xml" - }; - String daemonPath = ""; - String url = ""; - String basePath = ""; - - for (int i = 0; i < filePath.length; i++) { - if ((i%2) == 0) { - fxJarUrl = "https://github.com/unigrid-project/unigrid-update/releases/download/v1.0.9/fx-1.0.9-SNAPSHOT.jar"; - } else { - fxJarUrl = "https://github.com/unigrid-project/unigrid-update-testing/releases/download/v1.0.9/fx-1.0.9-SNAPSHOT.jar"; - } - - if (filePath[i].contains("linux")) { - daemonPath = homeDir + "/Downloads/" + linuxDaemon; - url = getDaemonUrl(OS.LINUX); - basePath = "${user.home}/.unigrid/dependencies/lib/"; - } else if (filePath[i].contains("mac")) { - daemonPath = homeDir + "/Downloads/" + osxDaemon; - url = getDaemonUrl(OS.MAC); - basePath = "${user.home}/Library/Application Support/UNIGRID/dependencies/lib/"; - } else if (filePath[i].contains("windows")) { - daemonPath = homeDir + "/Downloads/" + windowsDaemon; - url = getDaemonUrl(OS.WINDOWS); - basePath = "${user.home}/AppData/Roaming/UNIGRID/dependencies/lib/"; - } - - Configuration config = Configuration.builder() - .basePath(basePath) - .file(FileMetadata.readFrom("../../fx/target/fx-1.0.9-SNAPSHOT.jar") - .uri(fxJarUrl).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/aopalliance-repackaged-3.0.3.jar") - .uri(mavenUrl("org.glassfish.hk2.external", "aopalliance-repackaged", "3.0.3")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/commons-beanutils-1.9.4.jar") - .uri(mavenUrl("commons-beanutils", "commons-beanutils", "1.9.4")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/commons-collections-3.2.2.jar") - .uri(mavenUrl("commons-collections", "commons-collections", "3.2.2")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/commons-configuration2-2.7.jar") - .uri(mavenUrl("org.apache.commons", "commons-configuration2", "2.7")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/commons-io-2.8.0.jar") - .uri("https://repo1.maven.org/maven2/commons-io/commons-io/2.8.0/commons-io-2.8.0.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/commons-lang3-3.8.1.jar") - .uri(mavenUrl("org.apache.commons", "commons-lang3", "3.8.1")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/commons-logging-1.2.jar") - .uri(mavenUrl("commons-logging", "commons-logging", "1.2")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/commons-text-1.8.jar") - .uri(mavenUrl("org.apache.commons", "commons-text", "1.8")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/controlsfx-11.1.1.jar") - .uri(mavenUrl("org.controlsfx", "controlsfx", "11.1.1")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/hk2-api-3.0.3.jar") - .uri("https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-api/3.0.3/hk2-api-3.0.3.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/hk2-locator-3.0.3.jar") - .uri("https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-locator/3.0.3/hk2-locator-3.0.3.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/hk2-utils-3.0.3.jar") - .uri("https://repo1.maven.org/maven2/org/glassfish/hk2/hk2-utils/3.0.3/hk2-utils-3.0.3.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/FastInfoset-2.1.0.jar") - .uri(mavenUrl("com.sun.xml.fastinfoset", "FastInfoset", "2.1.0")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/ikonli-core-12.3.0.jar") - .uri(mavenUrl("org.kordamp.ikonli", "ikonli-core", "12.3.0")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/ikonli-javafx-12.3.0.jar") - .uri(mavenUrl("org.kordamp.ikonli", "ikonli-javafx", "12.3.0")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/ikonli-fontawesome5-pack-12.3.0.jar") - .uri(mavenUrl("org.kordamp.ikonli", "ikonli-fontawesome5-pack", "12.3.0")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jackson-annotations-2.13.3.jar") - .uri("https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.13.3/jackson-annotations-2.13.3.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jackson-core-2.13.3.jar") - .uri("https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.13.3/jackson-core-2.13.3.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jackson-databind-2.13.3.jar") - .uri("https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.13.3/jackson-databind-2.13.3.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.annotation-api-2.0.0.jar") - .uri("https://repo1.maven.org/maven2/jakarta/annotation/jakarta.annotation-api/2.0.0/jakarta.annotation-api-2.0.0.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.el-api-4.0.0.jar") - .uri("https://repo1.maven.org/maven2/jakarta/el/jakarta.el-api/4.0.0/jakarta.el-api-4.0.0.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.enterprise.cdi-api-3.0.0.jar") - .uri("https://repo1.maven.org/maven2/jakarta/enterprise/jakarta.enterprise.cdi-api/3.0.0/jakarta.enterprise.cdi-api-3.0.0.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.inject-api-2.0.1.jar") - .uri("https://repo1.maven.org/maven2/jakarta/inject/jakarta.inject-api/2.0.1/jakarta.inject-api-2.0.1.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.interceptor-api-2.0.0.jar") - .uri("https://repo1.maven.org/maven2/jakarta/interceptor/jakarta.interceptor-api/2.0.0/jakarta.interceptor-api-2.0.0.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.json.bind-api-2.0.0.jar") - .uri("https://repo1.maven.org/maven2/jakarta/json/bind/jakarta.json.bind-api/2.0.0/jakarta.json.bind-api-2.0.0.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.json-2.0.0-RC1-module.jar") - .uri("https://repo1.maven.org/maven2/org/glassfish/jakarta.json/2.0.0-RC1/jakarta.json-2.0.0-RC1-module.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.json-api-2.0.2.jar") - .uri("https://repo1.maven.org/maven2/jakarta/json/jakarta.json-api/2.0.2/jakarta.json-api-2.0.2.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.ws.rs-api-3.0.0.jar") - .uri("https://repo1.maven.org/maven2/jakarta/ws/rs/jakarta.ws.rs-api/3.0.0/jakarta.ws.rs-api-3.0.0.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.xml.bind-api-3.0.1.jar").opens("jakarta.xml.bind", "fx") - .uri("https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api/3.0.1/jakarta.xml.bind-api-3.0.1.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/javassist-3.28.0-GA.jar") - .uri(mavenUrl("org.javassist", "javassist", "3.28.0-GA")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jaxb-core-3.0.2.jar") - .uri(mavenUrl("org.glassfish.jaxb", "jaxb-core", "3.0.2")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/istack-commons-runtime-4.0.1.jar") - .uri(mavenUrl("com.sun.istack", "istack-commons-runtime", "4.0.1")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/txw2-3.0.2.jar") - .uri(mavenUrl("org.glassfish.jaxb", "txw2", "3.0.2")).modulepath()) - /*.file(FileMetadata.readFrom("../../fx/target/jlink/cp/jaxb-impl-4.0.0.jar") - .uri(mavenUrl("com.sun.xml.bind", "jaxb-impl", "4.0.0")).modulepath())*/ - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jaxb-runtime-3.0.2.jar") - .uri(mavenUrl("org.glassfish.jaxb","jaxb-runtime","3.0.2")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jakarta.activation-2.0.1.jar") - .uri("https://repo1.maven.org/maven2/com/sun/activation/jakarta.activation/2.0.1/jakarta.activation-2.0.1.jar").modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jboss-classfilewriter-1.2.5.Final.jar") - .uri(mavenUrl("org.jboss.classfilewriter", "jboss-classfilewriter", "1.2.5.Final")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jboss-logging-3.4.3.Final.jar") - .uri(mavenUrl("org.jboss.logging", "jboss-logging", "3.4.3.Final")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jersey-hk2-3.0.5.jar") - .uri(mavenUrl("org.glassfish.jersey.inject", "jersey-hk2", "3.0.5")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jersey-client-3.0.5.jar") - .uri(mavenUrl("org.glassfish.jersey.core", "jersey-client", "3.0.5")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jersey-common-3.0.5.jar") - .uri(mavenUrl("org.glassfish.jersey.core", "jersey-common", "3.0.5")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jersey-media-json-binding-3.0.5.jar") - .uri(mavenUrl("org.glassfish.jersey.media", "jersey-media-json-binding", "3.0.5")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jersey-media-jaxb-3.0.5.jar") - .uri(mavenUrl("org.glassfish.jersey.media", "jersey-media-jaxb", "3.0.5")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jipsy-annotations-1.1.1.jar") - .uri(mavenUrl("org.kordamp.jipsy", "jipsy-annotations", "1.1.1")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jna-5.5.0.jar") - .uri(mavenUrl("net.java.dev.jna", "jna", "5.5.0")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jna-platform-5.5.0.jar") - .uri(mavenUrl("net.java.dev.jna", "jna-platform", "5.5.0")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/jsch-0.1.55.jar") - .uri(mavenUrl("com.jcraft", "jsch", "0.1.55")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/logback-classic-1.3.0-alpha16.jar") - .uri(mavenUrl("ch.qos.logback", "logback-classic", "1.3.0-alpha16")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/logback-core-1.3.0-alpha16.jar") - .uri(mavenUrl("ch.qos.logback", "logback-core", "1.3.0-alpha16")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/lombok-1.18.24.jar") - .uri(mavenUrl("org.projectlombok", "lombok", "1.18.24")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/osgi-resource-locator-1.0.3.jar") - .uri(mavenUrl("org.glassfish.hk2", "osgi-resource-locator", "1.0.3")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/parsson-1.0.0.jar") - .uri(mavenUrl("org.eclipse.parsson", "parsson", "1.0.0")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/slf4j-api-2.0.0-alpha7.jar") - .uri(mavenUrl("org.slf4j", "slf4j-api", "2.0.0-alpha7")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/weld-api-4.0.SP1.jar") - .uri(mavenUrl("org.jboss.weld", "weld-api", "4.0.SP1")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/weld-core-impl-4.0.3.Final.jar") - .uri(mavenUrl("org.jboss.weld", "weld-core-impl", "4.0.3.Final")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/weld-environment-common-4.0.3.Final.jar") - .uri(mavenUrl("org.jboss.weld.environment", "weld-environment-common", "4.0.3.Final")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/weld-probe-core-4.0.3.Final.jar") - .uri(mavenUrl("org.jboss.weld.probe", "weld-probe-core", "4.0.3.Final")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/weld-se-core-4.0.3.Final.jar") - .uri(mavenUrl("org.jboss.weld.se", "weld-se-core", "4.0.3.Final")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/weld-spi-4.0.SP1.jar") - .uri(mavenUrl("org.jboss.weld", "weld-spi", "4.0.SP1")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/yasson-2.0.0-M1.jar") - .uri(mavenUrl("org.eclipse", "yasson", "2.0.0-M1")).modulepath()) - .file(FileMetadata.readFrom("../../fx/target/jlink/cp/j8fu-1.23.0.jar") - .uri(mavenUrl("com.evolvedbinary.j8fu", "j8fu", "1.23.0")).modulepath()) - //.file(FileMetadata.readFrom("../../fx/target/jlink/cp/FXTrayIcon-3.3.0.jar") - // .uri(mavenUrl("com.dustinredmond.fxtrayicon", "FXTrayIcon", "3.3.0")).modulepath()) - .file(FileMetadata.readFrom(daemonPath).uri(url)) - .property("maven.central", MAVEN_BASE) - .property("fx.version", fxVersion) - .property("default.launcher.main.class", "org.unigrid.janus.Janus") - .build(); - - try ( Writer out = Files.newBufferedWriter(Paths.get(dir + filePath[i]))) { - config.write(out); - System.out.println(dir); - } - - } - - /* - String cacheLoc = System.getProperty("maven.dir") + "/fxcache"; - dir = configLocation + "/unigrid"; - - cacheJavafx(); - - config = Configuration.builder() - .basePath("${user.dir}/unigrid") - - .property("maven.central", MAVEN_BASE) - .property("maven.central.javafx", "${maven.central}/org/openjfx/") - .build(); - - try(Writer out = Files.newBufferedWriter(Paths.get(configLocation + "/setup.xml"))) { - config.write(out); - }*/ - } - - private String getDaemonPath() { - String s = ""; - - return s; - } - - private static String getDaemonUrl(OS os) { - String s = ""; - - String jsonSearch = "$['assets'][*]['browser_download_url']"; - DocumentContext jsonPath = null; - try { - jsonPath = JsonPath.parse(new URL("https://api.github.com/repos/unigrid-project/daemon/releases/latest")); - - } catch (Exception e) { - - } - List githubUrls = jsonPath.read(jsonSearch); - - if (os.equals(OS.LINUX)) { - /*List> data = jsonPath.read("$['assets'][*][?('linux' in @['browser_download_url'])]"); - s = data.get(0).toString(); - String arg = "linux-gnu.tar.gz"; - for (int i = 0; i < githubUrls.size(); i++) { - if(Pattern.matches(githubUrls.get(i), arg)){ - s = githubUrls.get(i); - } - }*/ - s = githubUrls.get(2); - System.out.println(s); - } else if (os.equals(OS.MAC)) { - s = githubUrls.get(0); - System.out.println(s); - } else if (os.equals(OS.WINDOWS)) { - s = githubUrls.get(1); - System.out.println(s); - } - return s; - } - - private static String mavenUrl(String groupId, String artifactId, String version, OS os) { - StringBuilder builder = new StringBuilder(); - builder.append(MAVEN_BASE + "/"); - builder.append(groupId.replace('.', '/') + "/"); - builder.append(artifactId.replace('.', '-') + "/"); - builder.append(version + '/'); - builder.append(artifactId.replace('.', '-') + "-" + version); - - if (os != null) { - builder.append("-" + os.getShortName()); - } - - builder.append(".jar"); - - return builder.toString(); - } - - private static String mavenUrl(String groupId, String artifactId, String version) { - return mavenUrl(groupId, artifactId, version, null); - } - - private static String extractJavafxURL(Path path, OS os) { - Pattern regex = Pattern.compile("javafx-([a-z]+)-([0-9.]+)(?:-(win|mac|linux))?\\.jar"); - Matcher match = regex.matcher(path.getFileName().toString()); - - if (!match.find()) { - return null; - } - - String module = match.group(1); - String version = match.group(2); - if (os == null && match.groupCount() > 2) { - os = OS.fromShortName(match.group(3)); - } - - return mavenUrl("org.openjfx", "javafx." + module, version, os); - } - - private static String injectOs(String file, OS os) { - return file.replaceAll("(.+)\\.jar", "$1-" + os.getShortName() + ".jar"); - } - - private static void cacheJavafx() throws IOException { - String names = System.getProperty("target") + "/javafx"; - Path cacheDir = Paths.get(System.getProperty("maven.dir"), "fxcache"); - - try ( Stream files = Files.list(Paths.get(names))) { - files.forEach(f -> { - try { - - if (!Files.isDirectory(cacheDir)) { - Files.createDirectory(cacheDir); - } - - for (OS os : EnumSet.of(OS.WINDOWS, OS.MAC, OS.LINUX)) { - Path file = cacheDir.resolve(injectOs(f.getFileName().toString(), os)); - - if (Files.notExists(file)) { - String download = extractJavafxURL(f, os); - URI uri = URI.create(download); - try ( InputStream in = uri.toURL().openStream()) { - Files.copy(in, file); - } - } - } - - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - } - } -} diff --git a/config/pom.xml b/config/pom.xml index 6616bce1..cd2c850a 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -61,12 +61,37 @@ jakarta.xml.bind-api 3.0.1 + + jakarta.ws.rs + jakarta.ws.rs-api + 3.0.0 + org.glassfish.jaxb jaxb-runtime 3.0.2 runtime + + org.glassfish.jersey.core + jersey-client + 3.0.5 + + + org.glassfish.jersey.inject + jersey-hk2 + 3.0.5 + + + org.glassfish.jersey.media + jersey-media-json-binding + 3.0.5 + + + org.glassfish.jersey.media + jersey-media-jaxb + 3.0.5 + org.projectlombok lombok @@ -77,6 +102,48 @@ commons-exec 1.3 + + org.jboss.weld.se + weld-se-core + 4.0.3.Final + + + com.evolvedbinary.j8fu + j8fu + 1.23.0 + + + org.jmockit + jmockit + 1.49 + test + + + net.jqwik + jqwik + 1.6.5 + test + + + org.awaitility + awaitility + 4.2.0 + test + + + + com.google.inject + guice + 5.1.0 + test + + + org.slf4j + slf4j-api + 2.0.0-alpha7 + test + + @@ -92,6 +159,21 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + -javaagent:"${settings.localRepository}"/org/jmockit/jmockit/1.49/jmockit-1.49.jar + + + + + + src/test/resources + + \ No newline at end of file diff --git a/config/src/main/java/org/unigrid/updatewalletconfig/ConfMarshaller.java b/config/src/main/java/org/unigrid/updatewalletconfig/ConfMarshaller.java index a0e784db..f44b7599 100644 --- a/config/src/main/java/org/unigrid/updatewalletconfig/ConfMarshaller.java +++ b/config/src/main/java/org/unigrid/updatewalletconfig/ConfMarshaller.java @@ -25,6 +25,7 @@ public class ConfMarshaller { public void mashal(Configuration configuration, String destination) { JAXBContext jaxbContext = null; Marshaller jaxbMarshaller = null; + try { jaxbContext = JAXBContext.newInstance(Configuration.class); jaxbMarshaller = jaxbContext.createMarshaller(); diff --git a/config/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java b/config/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java index 7904e8ed..05328ac5 100644 --- a/config/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java +++ b/config/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java @@ -15,8 +15,11 @@ of the License (see COPYING and COPYING.addendum). */ package org.unigrid.updatewalletconfig; -import com.jayway.jsonpath.DocumentContext; -import com.jayway.jsonpath.JsonPath; +import org.unigrid.updatewalletconfig.xml.Feed; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import java.io.IOException; import java.net.URL; import java.util.List; @@ -60,42 +63,45 @@ public class UpdateWalletConfig extends AbstractMavenLifecycleParticipant { private String fxVersion = ""; - @Requirement - private Logger logger; - @Override public void afterSessionEnd(MavenSession mavenSession) throws MavenExecutionException { if (!mavenSession.getResult().getExceptions().isEmpty()) { return; } + + if (!mavenSession.getGoals().contains("install") && !mavenSession.getGoals().contains("package") + && !mavenSession.getGoals().contains("validate")) { + return; + } + basedir = mavenSession.getRepositorySession().getLocalRepository().getBasedir(); MavenProject fxProject = null; - if (mavenSession.getGoals().contains("validate") || mavenSession.getGoals().contains("package") - || mavenSession.getGoals().contains("install")) { - logger.info("Goal: " + mavenSession.getGoals()); - for (MavenProject msp : mavenSession.getProjects()) { - if (msp.getArtifactId().equals("fx")) { - fxProject = msp; - } + System.out.println("Goal: " + mavenSession.getGoals()); + + for (MavenProject mp : mavenSession.getProjects()) { + if (mp.getArtifactId().equals("fx")) { + fxProject = mp; } + } - if (fxProject != null && fxProject.getDependencies().size() != 0) { - logger.info("Fx Project: " + fxProject.getGroupId() + ":" + fxProject.getArtifactId() - + ":" + fxProject.getVersion()); - if (fxVersion.isEmpty()) { - fxVersion = fxProject.getVersion().replace("-SNAPSHOT", ""); - configuration.getProperties().add(new Property("fx.version", fxVersion)); - } + if (fxProject != null && fxProject.getDependencies().size() != 0) { + System.out.println("Fx Project: " + fxProject.getGroupId() + ":" + fxProject.getArtifactId() + + ":" + fxProject.getVersion()); - OS[] os = new OS[]{OS.LINUX, OS.LINUX, OS.MAC, OS.MAC, OS.WINDOWS, OS.WINDOWS}; - for (int i = 0; i < os.length; i++) { - generateUpdateConfigFile(fxProject, os[i], i % 2 == 0); - } - } else { - throw new MavenExecutionException("Fx Project not found or no local dependencies found!" - + " Try mvn clean install or mvn clean package", new IllegalStateException()); + if (fxVersion.isEmpty()) { + fxVersion = fxProject.getVersion().replace("-SNAPSHOT", ""); + configuration.getProperties().add(new Property("fx.version", fxVersion)); } + + OS[] os = new OS[]{OS.LINUX, OS.LINUX, OS.MAC, OS.MAC, OS.WINDOWS, OS.WINDOWS}; + + for (int i = 0; i < os.length; i++) { + generateUpdateConfigFile(fxProject, os[i], i % 2 == 0); + } + } else { + throw new MavenExecutionException("Fx Project not found or no local dependencies found!" + + " Try mvn clean install or mvn clean package", new IllegalStateException()); } } @@ -109,10 +115,8 @@ public void generateUpdateConfigFile(MavenProject fx, OS os, boolean testing) th final String[] opens = fx.getProperties().getProperty("config.opens").split("\n"); final String[] exports = fx.getProperties().getProperty("config.exports").split("\n"); + for (FileMetadata file : files) { - /*logger.info("getUri: " + file.getUri()); - logger.info("getArtifactId: " + file.getArtifactId()); - logger.info("getGroupId: " + file.getGroupId());*/ List opensPackages = getOpensExports(file, opens); if (opensPackages != null && !opensPackages.isEmpty()) { file.setOpensPackages(getOpensExports(file, opens)); @@ -128,11 +132,13 @@ public void generateUpdateConfigFile(MavenProject fx, OS os, boolean testing) th ConfMarshaller marshaller = new ConfMarshaller(); marshaller.mashal(configuration, getFileUrl(os, testing)); - logger.info("Config File created: " + getFileUrl(os, testing)); + + System.out.println("Config File created: " + getFileUrl(os, testing)); } public List getOpensExports(FileMetadata file, String[] opensExportsList) { List packages = null; + for (String element : opensExportsList) { element.trim(); if (!element.isEmpty()) { @@ -148,6 +154,7 @@ public List getOpensExports(FileMetadata file, String[] opensExportsLis } } } + return packages; } @@ -164,6 +171,7 @@ public void serviceCreationFailed(Class type, Class impl, Throwable except type, impl, exception)); } }); + return locator.getService(RepositorySystem.class); } @@ -178,16 +186,16 @@ public List getDependencies(String currentArtifact) { Artifact artifact = new DefaultArtifact(currentArtifact); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, "")); - RepositorySystem system = newRepositorySystem(); - CollectResult collectResult = system.collectDependencies(defSession, collectRequest); + CollectResult collectResult = newRepositorySystem().collectDependencies(defSession, collectRequest); // Console Dependency Tree Dump // collectResult.getRoot().accept(new ConsoleDependencyGraphDumper()); - files = getListByRecursion(collectResult.getRoot().getChildren(), files); + files = getListByRecursion(collectResult.getRoot().getChildren(), files); } catch (DependencyCollectionException | NoLocalRepositoryManagerException e) { java.util.logging.Logger.getLogger(UpdateWalletConfig.class.getName()) .log(Level.SEVERE, null, e); } + return files; } @@ -203,17 +211,19 @@ public List getListByRecursion( node.getArtifact().getVersion(), node.getArtifact().getClassifier() )); + getListByRecursion(node.getChildren(), files); }); } + return files; } public List getExternalDependencies(OS os, File baseDir, boolean testing) throws MavenExecutionException { - String isTesting = testing ? "-testing" : ""; List list = new ArrayList(); + try { String version = ""; for (Property property : configuration.getProperties()) { @@ -235,12 +245,13 @@ public List getExternalDependencies(OS os, File baseDir, boolean t throw new MavenExecutionException("Local jar not found!" + " Try mvn clean install or mvn clean package", new IllegalStateException()); } + list.add(getFileByUrl(getDaemonUrl(os))); - // list.add(getFileByUrl(getHedgehogUrl(OS.CURRENT))); } catch (IOException ex) { java.util.logging.Logger.getLogger(UpdateWalletConfig.class.getName()) .log(Level.SEVERE, null, ex); } + return list; } @@ -248,6 +259,7 @@ public FileMetadata getFileMetadata(String groupId, String artifactId, String ve String localUrl = getLocalUrl(groupId, artifactId, version, classifier); File file = new File(localUrl); FileMetadata tempFile = null; + if (file.exists()) { try { String filePath = file.getAbsolutePath().replace(basedir.getPath(), "${maven.central}"); @@ -270,8 +282,9 @@ public FileMetadata getFileMetadata(String groupId, String artifactId, String ve .log(Level.SEVERE, null, ex); } } else { - logger.info(" !!! Url to file doesn't exist: " + localUrl); + System.out.println(" !!! Url to file doesn't exist: " + localUrl); } + return tempFile; } @@ -282,16 +295,20 @@ public String getFxDependencyString(MavenProject fxProject) { public FileMetadata getFileByUrl(String url) { try { URL tempUrl = new URL(url); + FileMetadata tempFile = new FileMetadata( tempUrl.toString(), ConfFileUtil.getFileSize(tempUrl), ConfFileUtil.getChecksumStringyByInputStream(tempUrl.openStream()) ); + tempFile.setModulePath(false); + return tempFile; } catch (IOException ex) { java.util.logging.Logger.getLogger(UpdateWalletConfig.class.getName()).log(Level.SEVERE, null, ex); } + return null; } @@ -314,70 +331,37 @@ public static String getBasePathUrl(OS os) { public static String getFileUrl(OS os, boolean testing) { String isTesting = testing ? "-test" : ""; + String osName = os.equals(os.WINDOWS) ? os.name().toLowerCase() : os.getShortName(); + return System.getProperty("user.dir").concat("/config/target/") + "config-" - + os.getShortName() + isTesting + ".xml"; + + osName + isTesting + ".xml"; } public static String getDaemonUrl(OS os) { - String s = ""; + String url = "https://github.com/unigrid-project/daemon/releases.atom"; + Client client = ClientBuilder.newBuilder().build(); + Response response = client.target(url).request(MediaType.APPLICATION_XML_TYPE).get(); + Feed result = response.readEntity(Feed.class); - String jsonSearch = "$['assets'][*]['browser_download_url']"; - DocumentContext jsonPath = null; - try { - jsonPath = JsonPath - .parse(new URL("https://api.github.com/repos/unigrid-project/daemon/releases/latest")); - List githubUrls = jsonPath.read(jsonSearch); - - if (os.equals(OS.LINUX)) { - /*List> data = jsonPath - .read("$['assets'][*][?('linux' in @['browser_download_url'])]"); - s = data.get(0).toString(); - String arg = "linux-gnu.tar.gz"; - for (int i = 0; i < githubUrls.size(); i++) { - if(Pattern.matches(githubUrls.get(i), arg)){ - s = githubUrls.get(i); - } - }*/ - s = githubUrls.get(2); - System.out.println(s); - } else if (os.equals(OS.MAC)) { - s = githubUrls.get(0); - System.out.println(s); - } else if (os.equals(OS.WINDOWS)) { - s = githubUrls.get(1); - System.out.println(s); - } - return s; - } catch (IOException e) { - } - return ""; + return getZipUrl(os, result.getEntry().get(0).getLink().getHref()); } - public static String getHedgehogUrl(OS os) { - String s = ""; - - String jsonSearch = "$['assets'][*]['browser_download_url']"; - DocumentContext jsonPath = null; - try { - jsonPath = JsonPath - .parse(new URL("https://api.github.com/repos/unigrid-project/hedgehog/releases/latest")); - List githubUrls = jsonPath.read(jsonSearch); - - if (os.equals(OS.LINUX)) { - s = githubUrls.get(2); - System.out.println(s); - } else if (os.equals(OS.MAC)) { - s = githubUrls.get(0); - System.out.println(s); - } else if (os.equals(OS.WINDOWS)) { - s = githubUrls.get(1); - System.out.println(s); - } - return s; - - } catch (IOException e) { + public static String getZipUrl(OS os, String daemonUrl) { + final String affix = "/unigrid-"; + String[] split = daemonUrl.split("/", 0); + final String version = split[split.length - 1].replace("v", ""); + daemonUrl = daemonUrl.replace("https://github.com/unigrid-project/daemon/releases/tag/", + "https://github.com/unigrid-project/daemon/releases/download/"); + + if (os.equals(OS.LINUX)) { + return daemonUrl + affix + version + "-x86_64-linux-gnu.tar.gz"; + } else if (os.equals(OS.MAC)) { + return daemonUrl + affix + version + "-osx64.tar.gz"; + } else if (os.equals(OS.WINDOWS)) { + return daemonUrl + affix + version + "-win64.zip"; } - return ""; + + return daemonUrl + affix + version + "-x86_64-linux-gnu.tar.gz"; } public static String getLocalUrl(String groupId, String artifactId, String version, String classifier) { @@ -387,10 +371,13 @@ public static String getLocalUrl(String groupId, String artifactId, String versi builder.append(artifactId).append("/"); builder.append(version).append('/'); builder.append(artifactId).append("-").append(version); + if (classifier.isEmpty() != true) { builder.append("-").append(classifier); } + builder.append(".jar"); + return builder.toString(); } } diff --git a/config/src/main/java/org/unigrid/updatewalletconfig/xml/Feed.java b/config/src/main/java/org/unigrid/updatewalletconfig/xml/Feed.java new file mode 100644 index 00000000..eb6324c2 --- /dev/null +++ b/config/src/main/java/org/unigrid/updatewalletconfig/xml/Feed.java @@ -0,0 +1,54 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.updatewalletconfig.xml; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlAttribute; +import lombok.Data; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@Data +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(namespace = "http://www.w3.org/2005/Atom") +public class Feed { + @XmlElement + private String id; + + @XmlElement + private List entry; + + @Data + @XmlAccessorType(XmlAccessType.NONE) + public static class Entry { + + @XmlElement + private String id; + + @XmlElement + private Link link; + + @Data + @XmlAccessorType(XmlAccessType.NONE) + public static class Link { + @XmlAttribute + private String href; + } + } +} diff --git a/config/src/main/java/org/unigrid/updatewalletconfig/xml/package-info.java b/config/src/main/java/org/unigrid/updatewalletconfig/xml/package-info.java new file mode 100644 index 00000000..a23ba26f --- /dev/null +++ b/config/src/main/java/org/unigrid/updatewalletconfig/xml/package-info.java @@ -0,0 +1,9 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/package-info.java to edit this template + */ +@XmlSchema(namespace = "http://www.w3.org/2005/Atom", elementFormDefault = XmlNsForm.QUALIFIED) +package org.unigrid.updatewalletconfig.xml; + +import jakarta.xml.bind.annotation.XmlNsForm; +import jakarta.xml.bind.annotation.XmlSchema; diff --git a/config/src/test/java/org/unigrid/jqwik/BaseMockedWeldTest.java b/config/src/test/java/org/unigrid/jqwik/BaseMockedWeldTest.java new file mode 100644 index 00000000..eb20efa6 --- /dev/null +++ b/config/src/test/java/org/unigrid/jqwik/BaseMockedWeldTest.java @@ -0,0 +1,29 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.jqwik; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import net.jqwik.api.lifecycle.AddLifecycleHook; +import net.jqwik.api.lifecycle.PropagationMode; + +@AddLifecycleHook(value = MockitHook.class, propagateTo = PropagationMode.ALL_DESCENDANTS) +@AddLifecycleHook(value = WeldHook.class, propagateTo = PropagationMode.ALL_DESCENDANTS) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class BaseMockedWeldTest { + /* Empty on purpose */ +} diff --git a/config/src/test/java/org/unigrid/jqwik/Instances.java b/config/src/test/java/org/unigrid/jqwik/Instances.java new file mode 100644 index 00000000..50c13435 --- /dev/null +++ b/config/src/test/java/org/unigrid/jqwik/Instances.java @@ -0,0 +1,28 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.jqwik; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Instances { + int value(); +} diff --git a/config/src/test/java/org/unigrid/jqwik/MockitHook.java b/config/src/test/java/org/unigrid/jqwik/MockitHook.java new file mode 100644 index 00000000..c6e67c02 --- /dev/null +++ b/config/src/test/java/org/unigrid/jqwik/MockitHook.java @@ -0,0 +1,41 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.jqwik; + +import mockit.integration.TestRunnerDecorator; +import net.jqwik.api.lifecycle.AroundPropertyHook; +import net.jqwik.api.lifecycle.AroundContainerHook; +import net.jqwik.api.lifecycle.ContainerLifecycleContext; +import net.jqwik.api.lifecycle.PropertyExecutionResult; +import net.jqwik.api.lifecycle.PropertyExecutor; +import net.jqwik.api.lifecycle.PropertyLifecycleContext; + +public class MockitHook extends TestRunnerDecorator implements AroundPropertyHook, AroundContainerHook { + + @Override + public PropertyExecutionResult aroundProperty(PropertyLifecycleContext context, PropertyExecutor property) { + handleMockFieldsForWholeTestClass(context.testInstance()); + final PropertyExecutionResult result = property.execute(); + prepareForNextTest(); + return result; + } + + @Override + public void afterContainer(ContainerLifecycleContext context) { + cleanUpAllMocks(); + } +} diff --git a/config/src/test/java/org/unigrid/jqwik/NamedCDIProvider.java b/config/src/test/java/org/unigrid/jqwik/NamedCDIProvider.java new file mode 100644 index 00000000..b7c5fbcc --- /dev/null +++ b/config/src/test/java/org/unigrid/jqwik/NamedCDIProvider.java @@ -0,0 +1,41 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.jqwik; + +import jakarta.enterprise.inject.spi.CDI; +import jakarta.enterprise.inject.spi.CDIProvider; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; +import org.jboss.weld.environment.se.WeldContainer; + +public class NamedCDIProvider implements CDIProvider { + public static final AtomicReference NAME_REFERENCE = new AtomicReference<>(); + + @Override + public CDI getCDI() { + if (Objects.isNull(NAME_REFERENCE.get())) { + throw new IllegalStateException("No namespace set for requested CDI instance"); + } + + return WeldContainer.instance(NAME_REFERENCE.get()); + } + + @Override + public int getPriority() { + return DEFAULT_CDI_PROVIDER_PRIORITY + 10; /* Bump ourselves up so we get precedence. */ + } +} diff --git a/config/src/test/java/org/unigrid/jqwik/WeldHook.java b/config/src/test/java/org/unigrid/jqwik/WeldHook.java new file mode 100644 index 00000000..42b2ff34 --- /dev/null +++ b/config/src/test/java/org/unigrid/jqwik/WeldHook.java @@ -0,0 +1,173 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.jqwik; + +import com.evolvedbinary.j8fu.function.TriConsumer; +import jakarta.enterprise.inject.Instance; +import jakarta.enterprise.inject.spi.CDI; +import jakarta.inject.Inject; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.function.BiConsumer; +import net.jqwik.api.lifecycle.AroundContainerHook; +import net.jqwik.api.lifecycle.AroundPropertyHook; +import net.jqwik.api.lifecycle.ContainerLifecycleContext; +import net.jqwik.api.lifecycle.PropertyExecutionResult; +import net.jqwik.api.lifecycle.PropertyExecutor; +import net.jqwik.api.lifecycle.PropertyLifecycleContext; +import org.apache.commons.lang3.StringUtils; +import org.jboss.weld.environment.se.Weld; +import org.jboss.weld.environment.se.WeldContainer; + +public class WeldHook implements AroundContainerHook, AroundPropertyHook { + private List> findWeldClasses(Object instance, Class clazz) { + final Set> beans = new HashSet<>(); + final WeldSetup weldSetup = clazz.getAnnotation(WeldSetup.class); + + if (Objects.nonNull(weldSetup)) { + beans.addAll(List.of(weldSetup.value())); + } + + Class superClass = clazz; + + do { + superClass = superClass.getSuperclass(); + } while (Objects.nonNull(superClass)); + + return new ArrayList<>(beans); + } + + private WeldContainer createOrGetWeld(String name, PropertyLifecycleContext context) { + WeldContainer instance = WeldContainer.instance(name); + + if (Objects.isNull(instance)) { + final List> weldClasses = findWeldClasses(context.testInstance(), context.containerClass()); + + instance = new Weld(name) + .beanClasses(weldClasses.toArray(new Class[0])) + .initialize(); + } + + return instance; + } + + private Type getGenericType(Field f) { + return ((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0]; + } + + private List forEachInjectionPoint(Type type, Field field, PropertyLifecycleContext context, + BiConsumer consumer) { + + final List lists = new ArrayList<>(); + + if (field.isAnnotationPresent(Inject.class)) { + field.setAccessible(true); + + if (List.class.equals(type)) { + lists.add(field); + } else if (Instance.class.equals(type)) { + consumer.accept(getGenericType(field), field); + } else { + consumer.accept(type, field); + } + } + + return lists; + } + + private void forEachListInjectionPoint(List fields, PropertyLifecycleContext context, + TriConsumer, Type, Field> consumer) { + + try { + for (Field f : fields) { + /* Only inject on the first run or if empty - otherwise we assume everything is injected */ + if (List.class.equals(f.getType()) && f.isAnnotationPresent(Inject.class) + && Objects.isNull(f.get(context.testInstance()))) { + + if (!f.isAnnotationPresent(Instances.class)) { + throw new IllegalStateException("Lists require an instances annotation."); + } + + final List entries = (List) f.get(context.testInstance()); + final List> weldClasses = findWeldClasses(context.testInstance(), + context.containerClass() + ); + + final List instances = new ArrayList(); + f.set(context.testInstance(), instances); + + for (int i = 0; i < f.getAnnotation(Instances.class).value(); i++) { + consumer.accept(instances, getGenericType(f), f); + } + } + } + } catch (ClassCastException | IllegalAccessException ex) { + ex.printStackTrace(); + } + } + + private Object inject(PropertyLifecycleContext context, Type type, Field field, String containerSuffix) { + final String name = context.containerClass().getSimpleName() + containerSuffix; + final WeldContainer instance = createOrGetWeld(name, context); + NamedCDIProvider.NAME_REFERENCE.set(name); + + try { + final Object obj = instance.select(type).get(); + + if (Objects.nonNull(field)) { + field.set(context.testInstance(), obj); + } + + return obj; + + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + throw new IllegalStateException("Injection failed."); + } + } + + @Override + public PropertyExecutionResult aroundProperty(PropertyLifecycleContext context, PropertyExecutor property) { + final List fields = Arrays.asList(context.testInstance().getClass().getDeclaredFields()); + + fields.stream().forEach(f -> { + final List listFields = forEachInjectionPoint(f.getType(), f, context, (type, field) -> { + inject(context, type, field, StringUtils.EMPTY); + }); + + forEachListInjectionPoint(listFields, context, (instances, type, field) -> { + forEachInjectionPoint(type, field, context, (secondaryType, secondaryField) -> { + instances.add(inject(context, type, null, Integer.toString(instances.size() + 1))); + }); + }); + }); + + return property.execute(); + } + + @Override + public void beforeContainer(ContainerLifecycleContext context) { + CDI.setCDIProvider(new NamedCDIProvider()); + } +} diff --git a/config/src/test/java/org/unigrid/jqwik/WeldSetup.java b/config/src/test/java/org/unigrid/jqwik/WeldSetup.java new file mode 100644 index 00000000..4df1605f --- /dev/null +++ b/config/src/test/java/org/unigrid/jqwik/WeldSetup.java @@ -0,0 +1,28 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.jqwik; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface WeldSetup { + Class[] value(); +} diff --git a/config/src/test/java/org/unigrid/updatewalletconfig/UpdateWalletConfigTest.java b/config/src/test/java/org/unigrid/updatewalletconfig/UpdateWalletConfigTest.java new file mode 100644 index 00000000..fed3ae21 --- /dev/null +++ b/config/src/test/java/org/unigrid/updatewalletconfig/UpdateWalletConfigTest.java @@ -0,0 +1,228 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.updatewalletconfig; + +import jakarta.inject.Inject; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import mockit.Invocation; +import mockit.Mock; +import mockit.MockUp; +import net.jqwik.api.Example; +import org.apache.maven.MavenExecutionException; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.DefaultMavenExecutionResult; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.codehaus.plexus.DefaultPlexusContainer; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.PlexusContainerException; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.collection.CollectResult; +import org.eclipse.aether.repository.LocalRepository; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import org.unigrid.jqwik.BaseMockedWeldTest; +import org.unigrid.jqwik.WeldSetup; +import org.update4j.OS; + +@WeldSetup(UpdateWalletConfig.class) +public class UpdateWalletConfigTest extends BaseMockedWeldTest { + @Inject + private UpdateWalletConfig config; + + private org.eclipse.aether.graph.Dependency createDependency(String name) { + final DefaultArtifact artifact = new org.eclipse.aether.artifact.DefaultArtifact(name); + return new org.eclipse.aether.graph.Dependency(artifact, ""); + } + + private void setupRootArtifact(String name, CollectRequest request) { + final DefaultArtifact artifact = new DefaultArtifact(name); + + request.setRootArtifact(artifact); + request.setRoot(new org.eclipse.aether.graph.Dependency(artifact, "")); + } + + @Example + public void shouldBeAbleToHandleSingleDependency() + throws PlexusContainerException, MavenExecutionException, IOException, URISyntaxException { + + new MockUp() { + @Mock + public List getDependencies(Invocation inv, String currentArtifact) { + currentArtifact = currentArtifact.contains("org.unigrid:bootstrap") + ? "org.unigrid.test:bootstrap:1.0.9-SNAPSHOT" : currentArtifact; + return inv.proceed(currentArtifact); + } + + @Mock + public List getExternalDependencies() { + return new ArrayList(); + } + + @Mock + public String getFileUrl(OS os, boolean testing) { + String isTesting = testing ? "-test" : ""; + String osName = os.equals(os.WINDOWS) ? os.name().toLowerCase() : os.getShortName(); + + return System.getProperty("user.dir").concat("/target/") + "config-" + + osName + isTesting + ".xml"; + } + }; + + new MockUp() { + @Mock + public void mashal(Invocation inv, Configuration configuration, String destination) { + configuration.setTimestamp("2022-10-07T12:33:24.850Z"); + inv.proceed(); + } + }; + + new MockUp() { + @Mock + public RepositorySystemSession getRepositorySession() { + return MavenRepositorySystemUtils.newSession(); + } + }; + + new MockUp() { + @Mock + public File getBasedir() { + return new File(System.getProperty("user.dir").concat("/src/test/resources")); + } + }; + + new MockUp() { + @Mock + public LocalRepository getLocalRepository() { + return new LocalRepository(System.getProperty("user.home") + .concat("/.m2/repository")); + } + }; + + new MockUp() { + @Mock + public CollectResult collectDependencies(Invocation inv, RepositorySystemSession defSession, + CollectRequest collectRequest) { + + if (collectRequest.getRoot().getArtifact().getGroupId().equals("org.unigrid.test")) { + if (collectRequest.getRoot().getArtifact().getArtifactId().equals("fx")) { + setupRootArtifact("org.unigrid.test:fx:1.0.9-SNAPSHOT", collectRequest); + + final org.eclipse.aether.graph.Dependency depOne + = createDependency("com.google.inject:guice:5.1.0"); + + final org.eclipse.aether.graph.Dependency depTwo + = createDependency("org.openjfx:javafx-controls:jar:17-ea+7"); + + final org.eclipse.aether.graph.Dependency depThree + = createDependency("org.slf4j:slf4j-api:2.0.0-alpha7"); + + collectRequest.setDependencies(Arrays.asList(depOne, depTwo, depThree)); + } else if (collectRequest.getRoot().getArtifact().getArtifactId().equals("bootstrap")) { + setupRootArtifact("org.unigrid.test:bootstrap:1.0.9-SNAPSHOT", collectRequest); + + final org.eclipse.aether.graph.Dependency dependency + = createDependency("org.openjfx:javafx-controls:jar:17-ea+7"); + collectRequest.setDependencies(Arrays.asList(dependency)); + } + } + + return inv.proceed(); + } + }; + + config.afterSessionEnd(setupMavenSession()); + + List filenames = Arrays.asList("linux-test", "linux", "mac-test", "mac", "windows-test", + "windows"); + for (String f : filenames) { + assertConfigFileIsEquals(f); + } + } + + public MavenSession setupMavenSession() throws PlexusContainerException { + Model projectModel = getModels("fx"); + Model bootstrapProjectModel = getModels("bootstrap"); + + Dependency dependencyOne = new Dependency(); + dependencyOne.setGroupId("com.google.inject"); + dependencyOne.setArtifactId("guice"); + dependencyOne.setVersion("5.1.0"); + + projectModel.addDependency(dependencyOne); + + Properties properties = new Properties(); + properties.setProperty("config.opens", "fx=com.google.guava/guava"); + properties.setProperty("config.exports", "fx=org.openjfx/javafx-controls"); + projectModel.setProperties(properties); + + PlexusContainer container = new DefaultPlexusContainer(); + MavenExecutionRequest request = new DefaultMavenExecutionRequest(); + MavenExecutionResult result = new DefaultMavenExecutionResult(); + + request.setGoals(Arrays.asList("install")); + + MavenSession session = new MavenSession(container, MavenRepositorySystemUtils.newSession(), + request, result); + + List list = new ArrayList(); + list.add(new MavenProject(projectModel)); + list.add(new MavenProject(bootstrapProjectModel)); + session.setProjects(list); + + return session; + } + + public Model getModels(String artifactId) { + Model projectModel = new Model(); + + projectModel.setModelVersion("4.0.0"); + projectModel.setGroupId("org.unigrid.test"); + projectModel.setArtifactId(artifactId); + projectModel.setVersion("1.0.9-SNAPSHOT"); + + return projectModel; + } + + public void assertConfigFileIsEquals(String suffix) throws IOException, URISyntaxException { + File FileTarget = new File(getClass().getResource("config-" + suffix + ".xml").toURI()); + File FileResource = new File(System.getProperty("user.dir") + .concat("/target/" + "config-" + suffix + ".xml")); + + boolean fileSizeIsEqual = FileTarget.length() == FileResource.length(); + long mismatch = Files.mismatch(FileTarget.toPath(), FileResource.toPath()); + + assertThat(fileSizeIsEqual, equalTo(true)); + assertThat(mismatch, equalTo(-1L)); + } +} diff --git a/config/src/test/resources/org/unigrid/updatewalletconfig/config-linux-test.xml b/config/src/test/resources/org/unigrid/updatewalletconfig/config-linux-test.xml new file mode 100644 index 00000000..09fc2d3b --- /dev/null +++ b/config/src/test/resources/org/unigrid/updatewalletconfig/config-linux-test.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/unigrid/updatewalletconfig/config-linux.xml b/config/src/test/resources/org/unigrid/updatewalletconfig/config-linux.xml new file mode 100644 index 00000000..6cb2f448 --- /dev/null +++ b/config/src/test/resources/org/unigrid/updatewalletconfig/config-linux.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/unigrid/updatewalletconfig/config-mac-test.xml b/config/src/test/resources/org/unigrid/updatewalletconfig/config-mac-test.xml new file mode 100644 index 00000000..b0e9b4e3 --- /dev/null +++ b/config/src/test/resources/org/unigrid/updatewalletconfig/config-mac-test.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/unigrid/updatewalletconfig/config-mac.xml b/config/src/test/resources/org/unigrid/updatewalletconfig/config-mac.xml new file mode 100644 index 00000000..bbb2a1c0 --- /dev/null +++ b/config/src/test/resources/org/unigrid/updatewalletconfig/config-mac.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/unigrid/updatewalletconfig/config-windows-test.xml b/config/src/test/resources/org/unigrid/updatewalletconfig/config-windows-test.xml new file mode 100644 index 00000000..6b7dc8d0 --- /dev/null +++ b/config/src/test/resources/org/unigrid/updatewalletconfig/config-windows-test.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/unigrid/updatewalletconfig/config-windows.xml b/config/src/test/resources/org/unigrid/updatewalletconfig/config-windows.xml new file mode 100644 index 00000000..78dc359a --- /dev/null +++ b/config/src/test/resources/org/unigrid/updatewalletconfig/config-windows.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fx/pom.xml b/fx/pom.xml index 9947d5c7..190ecf7b 100644 --- a/fx/pom.xml +++ b/fx/pom.xml @@ -15,6 +15,11 @@ org.unigrid.janus.Janus UTF-8 + + fx=jakarta.xml.bind/jakarta.xml.bind-api + + + @@ -299,6 +304,13 @@ + + + org.unigrid.janus + updateconfig + 1.0-SNAPSHOT + + diff --git a/fx/src/main/java/org/unigrid/janus/controller/OverlayController.java b/fx/src/main/java/org/unigrid/janus/controller/OverlayController.java index 98b02f32..8b0285e9 100644 --- a/fx/src/main/java/org/unigrid/janus/controller/OverlayController.java +++ b/fx/src/main/java/org/unigrid/janus/controller/OverlayController.java @@ -41,6 +41,7 @@ of the License (see COPYING and COPYING.addendum). import org.unigrid.janus.model.rpc.entity.Info; import org.unigrid.janus.model.rpc.entity.UnlockWallet; import org.unigrid.janus.model.signal.NodeRequest; +import org.unigrid.janus.model.signal.OverlayRequest; import org.unigrid.janus.model.signal.State; import org.unigrid.janus.model.signal.WalletRequest; import org.unigrid.janus.model.signal.UnlockRequest; @@ -182,8 +183,12 @@ private void hide() { pnlUnlock.setVisible(false); submitBtn.setDisable(false); - FxUtils.executeParentById("pnlOverlay", pnlUnlock, (node) -> { - node.setVisible(false); + eventOverlayRequest(OverlayRequest.CLOSE); + } + + private void eventOverlayRequest(@Observes OverlayRequest overlayRequest) { + FxUtils.executeParentById("pnlOverlay", pnlUnlock, node -> { + node.setVisible(overlayRequest == OverlayRequest.OPEN); }); } } diff --git a/fx/src/main/java/org/unigrid/janus/controller/SettingsController.java b/fx/src/main/java/org/unigrid/janus/controller/SettingsController.java index ed90ed09..a3d62d4b 100644 --- a/fx/src/main/java/org/unigrid/janus/controller/SettingsController.java +++ b/fx/src/main/java/org/unigrid/janus/controller/SettingsController.java @@ -32,7 +32,6 @@ of the License (see COPYING and COPYING.addendum). import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.Node; import javafx.scene.control.Alert; import javafx.stage.FileChooser; import javafx.stage.FileChooser.ExtensionFilter; @@ -68,10 +67,10 @@ of the License (see COPYING and COPYING.addendum). import org.unigrid.janus.model.signal.DebugMessage; import org.unigrid.janus.model.signal.Navigate; import static org.unigrid.janus.model.signal.Navigate.Location.*; +import org.unigrid.janus.model.signal.OverlayRequest; import org.unigrid.janus.model.signal.UnlockRequest; import org.unigrid.janus.model.signal.WalletRequest; import org.unigrid.janus.view.AlertDialog; -import org.unigrid.janus.view.FxUtils; @ApplicationScoped public class SettingsController implements Initializable, PropertyChangeListener, Showable { @@ -85,6 +84,7 @@ public class SettingsController implements Initializable, PropertyChangeListener @Inject private Wallet wallet; @Inject private Event navigateEvent; + @Inject private Event overlayRequest; @Inject private Event unlockRequestEvent; @Inject private Event walletRequestEvent; @@ -341,10 +341,7 @@ private void onDumpWallet(MouseEvent event) { if (wallet.getLocked()) { unlockRequestEvent.fire(UnlockRequest.builder().type(UnlockRequest.Type.FOR_DUMP).build()); - - FxUtils.executeParentById("pnlParent", (Node) event.getSource(), (node) -> { - node.getScene().lookup("#pnlOverlay").setVisible(true); - }); + overlayRequest.fire(OverlayRequest.OPEN); } else { eventWalletRequest(WalletRequest.DUMP_KEYS); } diff --git a/fx/src/main/java/org/unigrid/janus/controller/WalletController.java b/fx/src/main/java/org/unigrid/janus/controller/WalletController.java index 3dafc9e7..c40e9cec 100644 --- a/fx/src/main/java/org/unigrid/janus/controller/WalletController.java +++ b/fx/src/main/java/org/unigrid/janus/controller/WalletController.java @@ -75,9 +75,9 @@ of the License (see COPYING and COPYING.addendum). import org.unigrid.janus.model.service.PollingService; import org.unigrid.janus.model.signal.Navigate; import static org.unigrid.janus.model.signal.Navigate.Location.*; +import org.unigrid.janus.model.signal.OverlayRequest; import org.unigrid.janus.model.signal.UnlockRequest; import org.unigrid.janus.model.signal.WalletRequest; -import org.unigrid.janus.view.FxUtils; @ApplicationScoped public class WalletController implements Initializable, PropertyChangeListener { @@ -89,6 +89,7 @@ public class WalletController implements Initializable, PropertyChangeListener { @Inject private Wallet wallet; @Inject private Event navigateEvent; + @Inject private Event overlayRequest; @Inject private Event unlockRequestEvent; private int syncIntervalShort = 30000; @@ -354,9 +355,7 @@ private void submit() { UnlockRequest.builder().type(UnlockRequest.Type.FOR_SEND).build() ); - FxUtils.executeParentById("pnlParent", tblWalletTrans, (node) -> { - node.getScene().lookup("#pnlOverlay").setVisible(true); - }); + overlayRequest.fire(OverlayRequest.OPEN); } else { eventWalletRequest(WalletRequest.SEND_TRANSACTION); } diff --git a/fx/src/main/java/org/unigrid/janus/model/signal/OverlayRequest.java b/fx/src/main/java/org/unigrid/janus/model/signal/OverlayRequest.java new file mode 100644 index 00000000..47ef8ad3 --- /dev/null +++ b/fx/src/main/java/org/unigrid/janus/model/signal/OverlayRequest.java @@ -0,0 +1,21 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . +*/ + +package org.unigrid.janus.model.signal; + +public enum OverlayRequest { + OPEN, CLOSE; +} diff --git a/fx/src/main/resources/org/unigrid/janus/view/mainWindow.fxml b/fx/src/main/resources/org/unigrid/janus/view/mainWindow.fxml index a5c5b2da..028c29ca 100644 --- a/fx/src/main/resources/org/unigrid/janus/view/mainWindow.fxml +++ b/fx/src/main/resources/org/unigrid/janus/view/mainWindow.fxml @@ -26,7 +26,7 @@ - + @@ -328,7 +328,7 @@ - +