From 497fcd787f9bca1dd281787220a9d849eb67d98f Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 19 Mar 2020 21:07:34 +0100 Subject: [PATCH] Move Springer key to environment (#6139) --- .github/workflows/deployment.yml | 37 ++++++++------- .github/workflows/tests-fetchers.yml | 3 ++ .github/workflows/tests-oracle.yml | 3 ++ .github/workflows/tests.yml | 3 ++ build.gradle | 1 + src/main/java/org/jabref/Globals.java | 4 +- src/main/java/org/jabref/JabRefGUI.java | 2 +- src/main/java/org/jabref/JabRefMain.java | 8 ++-- src/main/java/org/jabref/cli/JabRefCLI.java | 2 +- .../gui/entryeditor/RelatedArticlesTab.java | 2 +- .../errorconsole/ErrorConsoleViewModel.java | 2 +- .../jabref/gui/help/AboutDialogViewModel.java | 10 ++-- .../gui/help/SearchForUpdateAction.java | 2 +- .../importer/fetcher/SpringerFetcher.java | 3 +- .../java/org/jabref/logic/util/BuildInfo.java | 47 ++++--------------- src/main/resources/build.properties | 1 + .../org/jabref/logic/util/BuildInfoTest.java | 8 ++-- 17 files changed, 63 insertions(+), 75 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 5f4a449072a..d4671771481 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -15,6 +15,9 @@ on: - 'src/test/**' - 'README.md' +env: + SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }} + jobs: build: strategy: @@ -22,21 +25,21 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] include: - - os: ubuntu-latest - displayName: linux - jpackageDownload: https://download.java.net/java/early_access/jdk14/34/GPL/openjdk-14-ea+34_linux-x64_bin.tar.gz - jdk14Path: /jdk-14 - archivePortable: tar -c -C build/distribution JabRef | pigz --rsyncable > build/distribution/JabRef-portable_linux.tar.gz && rm -R build/distribution/JabRef - - os: windows-latest - displayName: windows - jpackageDownload: https://download.java.net/java/early_access/jdk14/34/GPL/openjdk-14-ea+34_windows-x64_bin.zip - jdk14Path: /jdk-14 - archivePortable: 7z a -r build/distribution/JabRef-portable_windows.zip ./build/distribution/JabRef && rm -R build/distribution/JabRef - - os: macOS-latest - displayName: macOS - jpackageDownload: https://download.java.net/java/early_access/jdk14/34/GPL/openjdk-14-ea+34_osx-x64_bin.tar.gz - jdk14Path: /jdk-14.jdk/Contents/Home - archivePortable: brew install pigz && tar -c -C build/distribution JabRef.app | pigz --rsyncable > build/distribution/JabRef-portable_macos.tar.gz && rm -R build/distribution/JabRef.app + - os: ubuntu-latest + displayName: linux + jpackageDownload: https://download.java.net/java/early_access/jdk14/34/GPL/openjdk-14-ea+34_linux-x64_bin.tar.gz + jdk14Path: /jdk-14 + archivePortable: tar -c -C build/distribution JabRef | pigz --rsyncable > build/distribution/JabRef-portable_linux.tar.gz && rm -R build/distribution/JabRef + - os: windows-latest + displayName: windows + jpackageDownload: https://download.java.net/java/early_access/jdk14/34/GPL/openjdk-14-ea+34_windows-x64_bin.zip + jdk14Path: /jdk-14 + archivePortable: 7z a -r build/distribution/JabRef-portable_windows.zip ./build/distribution/JabRef && rm -R build/distribution/JabRef + - os: macOS-latest + displayName: macOS + jpackageDownload: https://download.java.net/java/early_access/jdk14/34/GPL/openjdk-14-ea+34_osx-x64_bin.tar.gz + jdk14Path: /jdk-14.jdk/Contents/Home + archivePortable: brew install pigz && tar -c -C build/distribution JabRef.app | pigz --rsyncable > build/distribution/JabRef-portable_macos.tar.gz && rm -R build/distribution/JabRef.app runs-on: ${{ matrix.os }} name: Create installer and portable version for ${{ matrix.displayName }} @@ -49,7 +52,7 @@ jobs: - name: Install GitVersion uses: gittools/actions/gitversion/setup@v0.9.1 with: - versionSpec: '5.1.3' + versionSpec: '5.1.3' - name: Run GitVersion id: gitversion uses: gittools/actions/gitversion/execute@v0.9.1 @@ -127,7 +130,7 @@ jobs: - name: Install GitVersion uses: gittools/actions/gitversion/setup@v0.9.1 with: - versionSpec: '5.1.3' + versionSpec: '5.1.3' - name: Run GitVersion id: gitversion uses: gittools/actions/gitversion/execute@v0.9.1 diff --git a/.github/workflows/tests-fetchers.yml b/.github/workflows/tests-fetchers.yml index 5cefdd1cdd3..dfdab9a3672 100644 --- a/.github/workflows/tests-fetchers.yml +++ b/.github/workflows/tests-fetchers.yml @@ -21,6 +21,9 @@ on: # run on each Wednesday - cron: '2 3 * * 3' +env: + SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }} + jobs: fetchertests: name: Fetcher tests diff --git a/.github/workflows/tests-oracle.yml b/.github/workflows/tests-oracle.yml index dbaf5ddb361..a79768fe6d7 100644 --- a/.github/workflows/tests-oracle.yml +++ b/.github/workflows/tests-oracle.yml @@ -18,6 +18,9 @@ on: # run on each Wednesday - cron: '2 3 * * 3' +env: + SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }} + jobs: oracletests: name: Oracle tests diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4b1f876f1b9..085ead03b89 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,6 +7,9 @@ on: pull_request: # always run on pull requests +env: + SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }} + jobs: checkstyle: name: Checkstyle diff --git a/build.gradle b/build.gradle index 18e1e20617f..af780ad755f 100644 --- a/build.gradle +++ b/build.gradle @@ -284,6 +284,7 @@ processResources { "authors": new File('AUTHORS').readLines().findAll { !it.startsWith("#") }.join(", "), "developers": new File('DEVELOPERS').readLines().findAll { !it.startsWith("#") }.join(", "), "azureInstrumentationKey": System.getenv('AzureInstrumentationKey'), + "springerNatureAPIKey": System.getenv('SpringerNatureAPIKey'), "minRequiredJavaVersion": minRequiredJavaVersion, "allowJava9": allowJava9 diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index 2524305194e..5f8177ffbca 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -113,10 +113,10 @@ private static void stopTelemetryClient() { private static void startTelemetryClient() { TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.getActive(); - telemetryConfiguration.setInstrumentationKey(Globals.BUILD_INFO.getAzureInstrumentationKey()); + telemetryConfiguration.setInstrumentationKey(Globals.BUILD_INFO.azureInstrumentationKey); telemetryConfiguration.setTrackingIsDisabled(!Globals.prefs.shouldCollectTelemetry()); telemetryClient = new TelemetryClient(telemetryConfiguration); - telemetryClient.getContext().getProperties().put("JabRef version", Globals.BUILD_INFO.getVersion().toString()); + telemetryClient.getContext().getProperties().put("JabRef version", Globals.BUILD_INFO.version.toString()); telemetryClient.getContext().getProperties().put("Java version", StandardSystemProperty.JAVA_VERSION.value()); telemetryClient.getContext().getUser().setId(Globals.prefs.getOrCreateUserId()); telemetryClient.getContext().getSession().setId(UUID.randomUUID().toString()); diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index d1f4057818b..1ace4ffca4a 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -51,7 +51,7 @@ public JabRefGUI(Stage mainStage, List databases, boolean isBlank) mainFrame = new JabRefFrame(mainStage); openWindow(mainStage); - new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), Globals.TASK_EXECUTOR) + new VersionWorker(Globals.BUILD_INFO.version, Globals.prefs.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), Globals.TASK_EXECUTOR) .checkForNewVersionDelayed(); } diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index ec1cf738ac8..64caaf3e373 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -109,19 +109,19 @@ private static void ensureCorrectJavaVersion() { // Check if we are running an acceptable version of Java final BuildInfo buildInfo = Globals.BUILD_INFO; JavaVersion checker = new JavaVersion(); - final boolean java9Fail = !buildInfo.isAllowJava9() && checker.isJava9(); - final boolean versionFail = !checker.isAtLeast(buildInfo.getMinRequiredJavaVersion()); + final boolean java9Fail = !buildInfo.allowJava9 && checker.isJava9(); + final boolean versionFail = !checker.isAtLeast(buildInfo.minRequiredJavaVersion); if (java9Fail || versionFail) { StringBuilder versionError = new StringBuilder( Localization.lang("Your current Java version (%0) is not supported. Please install version %1 or higher.", checker.getJavaVersion(), - buildInfo.getMinRequiredJavaVersion())); + buildInfo.minRequiredJavaVersion)); versionError.append("\n"); versionError.append(Localization.lang("Your Java Runtime Environment is located at %0.", checker.getJavaInstallationDirectory())); - if (!buildInfo.isAllowJava9()) { + if (!buildInfo.allowJava9) { versionError.append("\n"); versionError.append(Localization.lang("Note that currently, JabRef does not run with Java 9.")); } diff --git a/src/main/java/org/jabref/cli/JabRefCLI.java b/src/main/java/org/jabref/cli/JabRefCLI.java index a279a266aa4..0f3baecdf59 100644 --- a/src/main/java/org/jabref/cli/JabRefCLI.java +++ b/src/main/java/org/jabref/cli/JabRefCLI.java @@ -255,7 +255,7 @@ public static void printUsage() { } private String getVersionInfo() { - return String.format("JabRef %s", Globals.BUILD_INFO.getVersion()); + return String.format("JabRef %s", Globals.BUILD_INFO.version); } public List getLeftOver() { diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index d1174993247..1e20b41c7b1 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -61,7 +61,7 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { progress.setMaxSize(100, 100); MrDLibFetcher fetcher = new MrDLibFetcher(Globals.prefs.get(JabRefPreferences.LANGUAGE), - Globals.BUILD_INFO.getVersion()); + Globals.BUILD_INFO.version); BackgroundTask .wrap(() -> fetcher.performSearch(entry)) .onRunning(() -> progress.setVisible(true)) diff --git a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java index a47ba6f02be..dd3ac174be4 100644 --- a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java +++ b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java @@ -92,7 +92,7 @@ public void clearLog() { public void reportIssue() { try { // System info - String systemInfo = String.format("JabRef %s%n%s %s %s %nJava %s", buildInfo.getVersion(), BuildInfo.OS, + String systemInfo = String.format("JabRef %s%n%s %s %s %nJava %s", buildInfo.version, BuildInfo.OS, BuildInfo.OS_VERSION, BuildInfo.OS_ARCH, BuildInfo.JAVA_VERSION); // Steps to reproduce String howToReproduce = "Steps to reproduce:\n\n1. ...\n2. ...\n3. ..."; diff --git a/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java b/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java index f6534230b57..b6ab45a5016 100644 --- a/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java +++ b/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java @@ -43,7 +43,7 @@ public class AboutDialogViewModel extends AbstractViewModel { public AboutDialogViewModel(DialogService dialogService, ClipBoardManager clipBoardManager, BuildInfo buildInfo) { this.dialogService = Objects.requireNonNull(dialogService); this.clipBoardManager = Objects.requireNonNull(clipBoardManager); - String[] version = buildInfo.getVersion().getFullVersion().split("--"); + String[] version = buildInfo.version.getFullVersion().split("--"); heading.set("JabRef " + version[0]); if (version.length == 1) { @@ -54,11 +54,11 @@ public AboutDialogViewModel(DialogService dialogService, ClipBoardManager clipBo Collectors.joining("--")); developmentVersion.set(dev); } - developers.set(buildInfo.getDevelopers()); - authors.set(buildInfo.getAuthors()); + developers.set(buildInfo.developers); + authors.set(buildInfo.authors); license.set(Localization.lang("License") + ":"); - changelogUrl = buildInfo.getVersion().getChangelogUrl(); - versionInfo = String.format("JabRef %s%n%s %s %s %nJava %s", buildInfo.getVersion(), BuildInfo.OS, + changelogUrl = buildInfo.version.getChangelogUrl(); + versionInfo = String.format("JabRef %s%n%s %s %s %nJava %s", buildInfo.version, BuildInfo.OS, BuildInfo.OS_VERSION, BuildInfo.OS_ARCH, BuildInfo.JAVA_VERSION); } diff --git a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java index 3e85c2fc9e1..5e39a0e6d7c 100644 --- a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java @@ -22,7 +22,7 @@ public SearchForUpdateAction(BuildInfo buildInfo, VersionPreferences versionPref @Override public void execute() { - new VersionWorker(buildInfo.getVersion(), versionPreferences.getIgnoredVersion(), dialogService, taskExecutor) + new VersionWorker(buildInfo.version, versionPreferences.getIgnoredVersion(), dialogService, taskExecutor) .checkForNewVersionAsync(); } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java index 7eefe067392..817f07f76aa 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java @@ -14,6 +14,7 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; +import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; @@ -38,7 +39,7 @@ public class SpringerFetcher implements SearchBasedParserFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(SpringerFetcher.class); private static final String API_URL = "http://api.springernature.com/meta/v1/json"; - private static final String API_KEY = "a98b4a55181ffcd27259bea45edad12e"; + private static final String API_KEY = new BuildInfo().springerNatureAPIKey; /** * Convert a JSONObject obtained from http://api.springer.com/metadata/json to a BibEntry diff --git a/src/main/java/org/jabref/logic/util/BuildInfo.java b/src/main/java/org/jabref/logic/util/BuildInfo.java index adbd7e00a94..74ca72bb903 100644 --- a/src/main/java/org/jabref/logic/util/BuildInfo.java +++ b/src/main/java/org/jabref/logic/util/BuildInfo.java @@ -7,7 +7,7 @@ import java.util.Locale; import java.util.Properties; -public class BuildInfo { +public final class BuildInfo { public static final String UNKNOWN_VERSION = "*unknown*"; @@ -16,14 +16,14 @@ public class BuildInfo { public static final String OS_ARCH = System.getProperty("os.arch", UNKNOWN_VERSION).toLowerCase(Locale.ROOT); public static final String JAVA_VERSION = System.getProperty("java.version", UNKNOWN_VERSION).toLowerCase(Locale.ROOT); - private final Version version; - private final String authors; - private final String developers; - private final String year; - private final String azureInstrumentationKey; - private final String minRequiredJavaVersion; - private final boolean allowJava9; - + public final Version version; + public final String authors; + public final String developers; + public final String year; + public final String azureInstrumentationKey; + public final String springerNatureAPIKey; + public final String minRequiredJavaVersion; + public final boolean allowJava9; public BuildInfo() { this("/build.properties"); @@ -47,35 +47,8 @@ public BuildInfo(String path) { year = properties.getProperty("year", ""); developers = properties.getProperty("developers", ""); azureInstrumentationKey = properties.getProperty("azureInstrumentationKey", ""); + springerNatureAPIKey = properties.getProperty("springerNatureAPIKey", ""); minRequiredJavaVersion = properties.getProperty("minRequiredJavaVersion", "1.8"); allowJava9 = "true".equals(properties.getProperty("allowJava9", "")); } - - public Version getVersion() { - return version; - } - - public String getAuthors() { - return authors; - } - - public String getDevelopers() { - return developers; - } - - public String getYear() { - return year; - } - - public String getAzureInstrumentationKey() { - return azureInstrumentationKey; - } - - public String getMinRequiredJavaVersion() { - return minRequiredJavaVersion; - } - - public boolean isAllowJava9() { - return allowJava9; - } } diff --git a/src/main/resources/build.properties b/src/main/resources/build.properties index 4b0475757d0..1380abc9330 100644 --- a/src/main/resources/build.properties +++ b/src/main/resources/build.properties @@ -3,5 +3,6 @@ year=${year} authors=${authors} developers=${developers} azureInstrumentationKey=${azureInstrumentationKey} +springerNatureAPIKey=${springerNatureAPIKey} minRequiredJavaVersion = ${minRequiredJavaVersion} allowJava9 = ${allowJava9} diff --git a/src/test/java/org/jabref/logic/util/BuildInfoTest.java b/src/test/java/org/jabref/logic/util/BuildInfoTest.java index 68f9d9c94b2..45a9ecf4d87 100644 --- a/src/test/java/org/jabref/logic/util/BuildInfoTest.java +++ b/src/test/java/org/jabref/logic/util/BuildInfoTest.java @@ -11,19 +11,19 @@ public class BuildInfoTest { @Test public void testDefaults() { BuildInfo buildInfo = new BuildInfo("asdf"); - assertEquals("*unknown*", buildInfo.getVersion().getFullVersion()); + assertEquals("*unknown*", buildInfo.version.getFullVersion()); } @Test public void testFileImport() { BuildInfo buildInfo = new BuildInfo("/org/jabref/util/build.properties"); - assertEquals("42", buildInfo.getVersion().getFullVersion()); + assertEquals("42", buildInfo.version.getFullVersion()); } @Test public void azureInstrumentationKeyIsNotEmpty() { BuildInfo buildInfo = new BuildInfo(); - assertNotNull(buildInfo.getAzureInstrumentationKey()); - assertNotEquals("", buildInfo.getAzureInstrumentationKey()); + assertNotNull(buildInfo.azureInstrumentationKey); + assertNotEquals("", buildInfo.azureInstrumentationKey); } }