From 911c85a004e92d6ce0f6a4d8ff8962a57d8df5ff Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 10 May 2024 12:22:15 +0000 Subject: [PATCH] Rework dev environment setup --- .gitignore | 1 + CONTRIBUTING.md | 9 +++- app/build.gradle | 2 - .../xpipe/app/core/AppExtensionManager.java | 4 +- .../java/io/xpipe/app/core/AppProperties.java | 45 +++++++++++++++---- .../io/xpipe/app/update/AppInstaller.java | 3 +- build.gradle | 7 ++- .../io/xpipe/core/util/XPipeInstallation.java | 25 ++++------- gradle/gradle_scripts/dev_default.properties | 14 ++++++ .../gradle_scripts/modules.gradle | 0 setup.sh | 14 ------ 11 files changed, 77 insertions(+), 47 deletions(-) create mode 100644 gradle/gradle_scripts/dev_default.properties rename modules.gradle => gradle/gradle_scripts/modules.gradle (100%) delete mode 100755 setup.sh diff --git a/.gitignore b/.gitignore index 65de11c7f..48b701855 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ bin ComponentsGenerated.wxs !dist/javafx/**/lib !dist/javafx/**/bin +dev.properties diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24f3f8891..0c4645b70 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,7 +28,14 @@ You can find the available version tags at https://github.com/xpipe-io/xpipe/tag So for example if you currently have XPipe `9.0` installed, you should run `git reset --hard 9.0` first to properly compile against it. You need to have JDK for Java 21 installed to compile the project. -If you are on Linux or macOS, you can easily accomplish that by running the `setup.sh` script. +If you are on Linux or macOS, you can easily accomplish that by running +```bash +curl -s "https://get.sdkman.io" | bash +. "$HOME/.sdkman/bin/sdkman-init.sh" +sdk install java 21.0.1-graalce +sdk default java 21.0.1-graalce +``` +. On Windows, you have to manually install a JDK, e.g. from [Adoptium](https://adoptium.net/temurin/releases/?version=21). ## Building and Running diff --git a/app/build.gradle b/app/build.gradle index d4ce1bbba..5c2bc1fab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -79,13 +79,11 @@ application { run { systemProperty 'io.xpipe.app.useVirtualThreads', 'false' systemProperty 'io.xpipe.app.mode', 'gui' - systemProperty 'io.xpipe.app.dataDir', "$projectDir/local_git23/" systemProperty 'io.xpipe.app.writeLogs', "true" systemProperty 'io.xpipe.app.writeSysOut', "true" systemProperty 'io.xpipe.app.developerMode', "true" systemProperty 'io.xpipe.app.logLevel', "trace" systemProperty 'io.xpipe.app.fullVersion', rootProject.fullVersion - systemProperty 'io.xpipe.app.showcase', 'true' systemProperty 'io.xpipe.app.staging', isStage // systemProperty "io.xpipe.beacon.port", "21724" // systemProperty "io.xpipe.beacon.printMessages", "true" diff --git a/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java b/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java index 81f486949..9f7de75d8 100644 --- a/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java +++ b/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java @@ -88,7 +88,7 @@ public class AppExtensionManager { } if (!AppProperties.get().isFullVersion()) { - var localInstallation = XPipeInstallation.getLocalDefaultInstallationBasePath(); + var localInstallation = XPipeInstallation.getLocalDefaultInstallationBasePath(AppProperties.get().isStaging() || AppProperties.get().isLocatePtb()); Path p = Path.of(localInstallation); if (!Files.exists(p)) { throw new IllegalStateException( @@ -103,7 +103,7 @@ public class AppExtensionManager { : AppProperties.get().getVersion(); var sourceVersion = AppVersion.parse(sv) .orElseThrow(() -> new IllegalArgumentException("Invalid source version: " + sv)); - if (!installVersion.equals(sourceVersion)) { + if (AppProperties.get().isLocatorVersionCheck() && !installVersion.equals(sourceVersion)) { throw new IllegalStateException("Incompatible development version. Source: " + iv + ", Installation: " + sv + "\n\nPlease try to check out the matching release version in the repository."); } diff --git a/app/src/main/java/io/xpipe/app/core/AppProperties.java b/app/src/main/java/io/xpipe/app/core/AppProperties.java index c85755a87..f210944e4 100644 --- a/app/src/main/java/io/xpipe/app/core/AppProperties.java +++ b/app/src/main/java/io/xpipe/app/core/AppProperties.java @@ -1,23 +1,20 @@ package io.xpipe.app.core; +import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.core.util.ModuleHelper; -import io.xpipe.core.util.XPipeInstallation; - import lombok.Getter; import lombok.Value; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; @Value public class AppProperties { - private static final String EXTENSION_PATHS_PROP = "io.xpipe.app.extensions"; private static AppProperties INSTANCE; boolean fullVersion; @@ -41,8 +38,22 @@ public class AppProperties { Path dataDir; boolean showcase; AppVersion canonicalVersion; + boolean locatePtb; + boolean locatorVersionCheck; public AppProperties() { + var appDir = Path.of(System.getProperty("user.dir")).resolve("app"); + Path propsFile = appDir.resolve("dev.properties"); + if (Files.exists(propsFile)) { + try { + Properties props = new Properties(); + props.load(Files.newInputStream(propsFile)); + props.forEach((key, value) -> System.setProperty(key.toString(), value.toString())); + } catch (IOException e) { + ErrorEvent.fromThrowable(e).handle(); + } + } + image = ModuleHelper.isImage(); fullVersion = Optional.ofNullable(System.getProperty("io.xpipe.app.fullVersion")) .map(Boolean::parseBoolean) @@ -58,18 +69,34 @@ public class AppProperties { languages = Arrays.stream(System.getProperty("io.xpipe.app.languages").split(",")) .sorted() .toList(); - staging = XPipeInstallation.isStaging(); + staging = Optional.ofNullable(System.getProperty("io.xpipe.app.staging")) + .map(Boolean::parseBoolean) + .orElse(false); useVirtualThreads = Optional.ofNullable(System.getProperty("io.xpipe.app.useVirtualThreads")) .map(Boolean::parseBoolean) .orElse(true); debugThreads = Optional.ofNullable(System.getProperty("io.xpipe.app.debugThreads")) .map(Boolean::parseBoolean) .orElse(false); - dataDir = XPipeInstallation.getDataDir(); + dataDir = Optional.ofNullable(System.getProperty("io.xpipe.app.dataDir")) + .map(s -> { + var p = Path.of(s); + if (!p.isAbsolute()) { + p = appDir.resolve(p); + } + return p; + }) + .orElse(Path.of(System.getProperty("user.home"), isStaging() ? ".xpipe-ptb" : ".xpipe")); showcase = Optional.ofNullable(System.getProperty("io.xpipe.app.showcase")) .map(Boolean::parseBoolean) .orElse(false); canonicalVersion = AppVersion.parse(version).orElse(null); + locatePtb = Optional.ofNullable(System.getProperty("io.xpipe.app.locator.usePtbInstallation")) + .map(Boolean::parseBoolean) + .orElse(false); + locatorVersionCheck = Optional.ofNullable(System.getProperty("io.xpipe.app.locator.disableInstallationVersionCheck")) + .map(Boolean::parseBoolean) + .orElse(false); } public static void logSystemProperties() { diff --git a/app/src/main/java/io/xpipe/app/update/AppInstaller.java b/app/src/main/java/io/xpipe/app/update/AppInstaller.java index f3f1f26b6..5b54a145f 100644 --- a/app/src/main/java/io/xpipe/app/update/AppInstaller.java +++ b/app/src/main/java/io/xpipe/app/update/AppInstaller.java @@ -1,5 +1,6 @@ package io.xpipe.app.update; +import io.xpipe.app.core.AppLogs; import io.xpipe.app.core.AppProperties; import io.xpipe.app.util.LocalShell; import io.xpipe.app.util.ScriptHelper; @@ -72,7 +73,7 @@ public class AppInstaller { : XPipeInstallation.getCurrentInstallationBasePath()) .resolve(XPipeInstallation.getDaemonExecutablePath(OsType.getLocal())) .toString(); - var logsDir = FileNames.join(XPipeInstallation.getDataDir().toString(), "logs"); + var logsDir = AppLogs.get().getSessionLogsDirectory().getParent().toString(); var logFile = FileNames.join(logsDir, "installer_" + FileNames.getFileName(file) + ".log"); var command = LocalShell.getShell().getShellDialect().equals(ShellDialects.CMD) ? getCmdCommand(file, logFile, exec) diff --git a/build.gradle b/build.gradle index f46529232..a247e5c18 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ allprojects { subproject -> extraJavaModuleInfo { failOnMissingModuleInfo.set(false) } - apply from: "$rootDir/modules.gradle" + apply from: "$rootDir/gradle/gradle_scripts/modules.gradle" } subprojects {subproject -> @@ -41,6 +41,11 @@ subprojects {subproject -> } } +var devProps = file("$rootDir/app/dev.properties") +if (!devProps.exists()) { + devProps.text = file("$rootDir/gradle/gradle_scripts/dev_default.properties").text +} + def getArchName() { var arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT) if (arch == 'amd64' || arch == 'x86_64') { diff --git a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java index 07f9e20af..48fe51572 100644 --- a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java +++ b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java @@ -1,15 +1,13 @@ package io.xpipe.core.util; -import io.xpipe.core.process.*; +import io.xpipe.core.process.OsType; import io.xpipe.core.store.FileNames; - import lombok.Getter; import lombok.SneakyThrows; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.util.Optional; @@ -32,17 +30,6 @@ public class XPipeInstallation { } } - public static Path getDataDir() { - if (System.getProperty(DATA_DIR_PROP) != null) { - try { - return Path.of(System.getProperty(DATA_DIR_PROP)); - } catch (InvalidPathException ignored) { - } - } - - return Path.of(System.getProperty("user.home"), isStaging() ? ".xpipe-ptb" : ".xpipe"); - } - private static String getPkgId() { return isStaging() ? "io.xpipe.xpipe-ptb" : "io.xpipe.xpipe"; } @@ -260,14 +247,18 @@ public class XPipeInstallation { } public static String getLocalDefaultInstallationBasePath() { + return getLocalDefaultInstallationBasePath(staging); + } + + public static String getLocalDefaultInstallationBasePath(boolean stage) { String path; if (OsType.getLocal().equals(OsType.WINDOWS)) { var base = System.getenv("LOCALAPPDATA"); - path = FileNames.join(base, isStaging() ? "XPipe PTB" : "XPipe"); + path = FileNames.join(base, stage ? "XPipe PTB" : "XPipe"); } else if (OsType.getLocal().equals(OsType.LINUX)) { - path = isStaging() ? "/opt/xpipe-ptb" : "/opt/xpipe"; + path = stage ? "/opt/xpipe-ptb" : "/opt/xpipe"; } else { - path = isStaging() ? "/Applications/XPipe PTB.app" : "/Applications/XPipe.app"; + path = stage ? "/Applications/XPipe PTB.app" : "/Applications/XPipe.app"; } return path; diff --git a/gradle/gradle_scripts/dev_default.properties b/gradle/gradle_scripts/dev_default.properties new file mode 100644 index 000000000..f12fd39e3 --- /dev/null +++ b/gradle/gradle_scripts/dev_default.properties @@ -0,0 +1,14 @@ +# XPipe will attempt to locate a local XPipe installation with the matching version to fetch production resources from it. +# If your installation version and development version do not match up, there is the possibility of errors occurring. +# If you know what you are doing, you can disable this version check. +io.xpipe.app.locator.disableInstallationVersionCheck=false + +# By default, XPipe will try to locate a normal local installation. +# If you also have a PTB version installed, you can also choose to use it if the version matches the development version more closely. +io.xpipe.app.locator.usePtbInstallation=false + +# Start up in fixed 16/9 window size, useful for demos and showcases +io.xpipe.app.showcase=false + +# Location in which your local development connection should be stored. If left empty, it will use your global XPipe storage in ~/.xpipe. +io.xpipe.app.dataDir=local diff --git a/modules.gradle b/gradle/gradle_scripts/modules.gradle similarity index 100% rename from modules.gradle rename to gradle/gradle_scripts/modules.gradle diff --git a/setup.sh b/setup.sh deleted file mode 100755 index 3d762428d..000000000 --- a/setup.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -which sdk -if [ $? -ne 0 ]; then - curl -s "https://get.sdkman.io" | bash - if [ $? -ne 0 ]; then - echo "sdkman failed" - exit 1 - fi; - . "$HOME/.sdkman/bin/sdkman-init.sh" -fi; - -sdk install java 21.0.1-graalce -sdk default java 21.0.1-graalce