Skip to content

Commit

Permalink
Move Springer key to environment (JabRef#6139)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusDietz authored Mar 19, 2020
1 parent 99183e1 commit 497fcd7
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 75 deletions.
37 changes: 20 additions & 17 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,31 @@ on:
- 'src/test/**'
- 'README.md'

env:
SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }}

jobs:
build:
strategy:
fail-fast: false
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 }}
Expand All @@ -49,7 +52,7 @@ jobs:
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.1.3'
versionSpec: '5.1.3'
- name: Run GitVersion
id: gitversion
uses: gittools/actions/gitversion/[email protected]
Expand Down Expand Up @@ -127,7 +130,7 @@ jobs:
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.1.3'
versionSpec: '5.1.3'
- name: Run GitVersion
id: gitversion
uses: gittools/actions/gitversion/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests-fetchers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ on:
# run on each Wednesday
- cron: '2 3 * * 3'

env:
SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }}

jobs:
fetchertests:
name: Fetcher tests
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests-oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ on:
# run on each Wednesday
- cron: '2 3 * * 3'

env:
SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }}

jobs:
oracletests:
name: Oracle tests
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
pull_request:
# always run on pull requests

env:
SpringerNatureAPIKey: ${{ secrets.SpringerNatureAPIKey }}

jobs:
checkstyle:
name: Checkstyle
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public JabRefGUI(Stage mainStage, List<ParserResult> 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();
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getLeftOver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. ...";
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/gui/help/AboutDialogViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
47 changes: 10 additions & 37 deletions src/main/java/org/jabref/logic/util/BuildInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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*";

Expand All @@ -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");
Expand All @@ -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;
}
}
1 change: 1 addition & 0 deletions src/main/resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ year=${year}
authors=${authors}
developers=${developers}
azureInstrumentationKey=${azureInstrumentationKey}
springerNatureAPIKey=${springerNatureAPIKey}
minRequiredJavaVersion = ${minRequiredJavaVersion}
allowJava9 = ${allowJava9}
8 changes: 4 additions & 4 deletions src/test/java/org/jabref/logic/util/BuildInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 497fcd7

Please sign in to comment.