From 3a48c02d68755d79d009cf9600c60fef791a2f7e Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 14 Oct 2023 01:28:19 +0200 Subject: [PATCH 001/125] Remove Microsoft Telemetry Client (and try log4j-to-slf4j bridge) (#10493) Co-authored-by: Christoph --- build.gradle | 7 +- src/main/java/module-info.java | 8 +- src/main/java/org/jabref/gui/Telemetry.java | 30 +---- .../java/org/jabref/gui/TelemetryClient.java | 11 ++ .../logging/ApplicationInsightsLogEvent.java | 116 ------------------ .../logging/ApplicationInsightsWriter.java | 57 --------- .../search/indexing/IndexingTaskManager.java | 2 +- .../logic/pdf/search/indexing/PdfIndexer.java | 17 +-- .../fileformat/ACMPortalParserTest.java | 2 +- 9 files changed, 21 insertions(+), 229 deletions(-) create mode 100644 src/main/java/org/jabref/gui/TelemetryClient.java delete mode 100644 src/main/java/org/jabref/gui/logging/ApplicationInsightsLogEvent.java delete mode 100644 src/main/java/org/jabref/gui/logging/ApplicationInsightsWriter.java diff --git a/build.gradle b/build.gradle index 594caf871c1..a55c6675765 100644 --- a/build.gradle +++ b/build.gradle @@ -187,6 +187,8 @@ dependencies { // route all requests to java.util.logging to SLF4J (which in turn routes to tinylog) implementation 'org.slf4j:jul-to-slf4j:2.0.9' + // route all requests to log4j to SLF4J + implementation 'org.apache.logging.log4j:log4j-to-slf4j:2.20.0' implementation('de.undercouch:citeproc-java:3.0.0-beta.2') { exclude group: 'org.antlr' @@ -205,11 +207,6 @@ dependencies { exclude group: "org.apache.xmlgraphics" } - implementation group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.4.1' - implementation (group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.4.1') { - exclude module: "log4j-core" - } - implementation 'com.vladsch.flexmark:flexmark:0.64.8' implementation group: 'net.harawata', name: 'appdirs', version: '1.2.2' diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index bdb442a3f75..a0d8be51d9c 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -42,13 +42,13 @@ // Logging requires org.slf4j; requires jul.to.slf4j; + requires org.apache.logging.slf4j; requires org.tinylog.api; requires org.tinylog.api.slf4j; requires org.tinylog.impl; provides org.tinylog.writers.Writer - with org.jabref.gui.logging.GuiWriter, - org.jabref.gui.logging.ApplicationInsightsWriter; + with org.jabref.gui.logging.GuiWriter; // Preferences and XML requires java.prefs; @@ -75,10 +75,6 @@ // dependency injection using HK2 requires org.glassfish.hk2.api; - // Microsoft application insights - requires applicationinsights.core; - requires applicationinsights.logging.log4j2; - // http clients requires unirest.java; requires org.apache.httpcomponents.httpclient; diff --git a/src/main/java/org/jabref/gui/Telemetry.java b/src/main/java/org/jabref/gui/Telemetry.java index e68985690b8..6bb0a10195b 100644 --- a/src/main/java/org/jabref/gui/Telemetry.java +++ b/src/main/java/org/jabref/gui/Telemetry.java @@ -1,51 +1,23 @@ package org.jabref.gui; import java.util.Optional; -import java.util.UUID; - -import javafx.stage.Screen; import org.jabref.logic.util.BuildInfo; -import org.jabref.model.strings.StringUtil; import org.jabref.preferences.TelemetryPreferences; -import com.google.common.base.StandardSystemProperty; -import com.microsoft.applicationinsights.TelemetryClient; -import com.microsoft.applicationinsights.TelemetryConfiguration; -import com.microsoft.applicationinsights.telemetry.SessionState; - public class Telemetry { - private static TelemetryClient telemetryClient; - private Telemetry() { } public static Optional getTelemetryClient() { - return Optional.ofNullable(telemetryClient); + return Optional.empty(); } private static void start(TelemetryPreferences telemetryPreferences, BuildInfo buildInfo) { - TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.getActive(); - if (!StringUtil.isNullOrEmpty(buildInfo.azureInstrumentationKey)) { - telemetryConfiguration.setInstrumentationKey(buildInfo.azureInstrumentationKey); - } - telemetryConfiguration.setTrackingIsDisabled(!telemetryPreferences.shouldCollectTelemetry()); - telemetryClient = new TelemetryClient(telemetryConfiguration); - telemetryClient.getContext().getProperties().put("JabRef version", buildInfo.version.toString()); - telemetryClient.getContext().getProperties().put("Java version", StandardSystemProperty.JAVA_VERSION.value()); - telemetryClient.getContext().getUser().setId(telemetryPreferences.getUserId()); - telemetryClient.getContext().getSession().setId(UUID.randomUUID().toString()); - telemetryClient.getContext().getDevice().setOperatingSystem(StandardSystemProperty.OS_NAME.value()); - telemetryClient.getContext().getDevice().setOperatingSystemVersion(StandardSystemProperty.OS_VERSION.value()); - telemetryClient.getContext().getDevice().setScreenResolution(Screen.getPrimary().getVisualBounds().toString()); - - telemetryClient.trackSessionState(SessionState.Start); } public static void shutdown() { getTelemetryClient().ifPresent(client -> { - client.trackSessionState(SessionState.End); - client.flush(); }); } } diff --git a/src/main/java/org/jabref/gui/TelemetryClient.java b/src/main/java/org/jabref/gui/TelemetryClient.java new file mode 100644 index 00000000000..077010f5ef6 --- /dev/null +++ b/src/main/java/org/jabref/gui/TelemetryClient.java @@ -0,0 +1,11 @@ +package org.jabref.gui; + +import java.util.Map; + +public class TelemetryClient { + public void trackEvent(String actionName) { + } + + public void trackEvent(String actionName, Map source, Map of) { + } +} diff --git a/src/main/java/org/jabref/gui/logging/ApplicationInsightsLogEvent.java b/src/main/java/org/jabref/gui/logging/ApplicationInsightsLogEvent.java deleted file mode 100644 index 85c2488f22b..00000000000 --- a/src/main/java/org/jabref/gui/logging/ApplicationInsightsLogEvent.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.jabref.gui.logging; - -/* - * ApplicationInsightsJava - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import com.microsoft.applicationinsights.internal.common.ApplicationInsightsEvent; -import com.microsoft.applicationinsights.internal.logger.InternalLogger; -import com.microsoft.applicationinsights.telemetry.SeverityLevel; -import org.tinylog.core.LogEntry; - -// TODO: Remove this copy as soon as the one included in AI is compatible with log4j 3 -public final class ApplicationInsightsLogEvent extends ApplicationInsightsEvent { - - private final LogEntry logEvent; - - public ApplicationInsightsLogEvent(LogEntry logEvent) { - this.logEvent = logEvent; - } - - @Override - public String getMessage() { - String message = this.logEvent.getMessage() != null ? this.logEvent.getMessage() : "Tinylog Trace"; - - return message; - } - - @Override - public boolean isException() { - return this.logEvent.getException() != null; - } - - @Override - public Exception getException() { - Exception exception = null; - - if (isException()) { - Throwable throwable = this.logEvent.getException(); - exception = throwable instanceof Exception e ? e : new Exception(throwable); - } - - return exception; - } - - @Override - public Map getCustomParameters() { - Map metaData = new HashMap<>(); - - metaData.put("SourceType", "slf4j"); - - addLogEventProperty("LoggingLevel", logEvent.getLevel() != null ? logEvent.getLevel().name() : null, metaData); - addLogEventProperty("ThreadName", logEvent.getThread().getName(), metaData); - addLogEventProperty("TimeStamp", getFormattedDate(logEvent.getTimestamp().toInstant().toEpochMilli()), metaData); - - if (isException()) { - addLogEventProperty("Logger Message", getMessage(), metaData); - - for (StackTraceElement stackTraceElement : logEvent.getException().getStackTrace()) { - addLogEventProperty("ClassName", stackTraceElement.getClassName(), metaData); - addLogEventProperty("FileName", stackTraceElement.getFileName(), metaData); - addLogEventProperty("MethodName", stackTraceElement.getMethodName(), metaData); - addLogEventProperty("LineNumber", String.valueOf(stackTraceElement.getLineNumber()), metaData); - } - } - - for (Entry entry : logEvent.getContext().entrySet()) { - addLogEventProperty(entry.getKey(), entry.getValue(), metaData); - } - - // TODO: Username, domain and identity should be included as in .NET version. - // TODO: Should check, seems that it is not included in Log4j2. - - return metaData; - } - - @Override - public SeverityLevel getNormalizedSeverityLevel() { - org.tinylog.Level logEventLevel = logEvent.getLevel(); - - switch (logEventLevel) { - case ERROR: - return SeverityLevel.Error; - case WARN: - return SeverityLevel.Warning; - case INFO: - return SeverityLevel.Information; - case TRACE: - case DEBUG: - return SeverityLevel.Verbose; - default: - InternalLogger.INSTANCE.error("Unknown slf4joption, %d, using TRACE level as default", logEventLevel); - return SeverityLevel.Verbose; - } - } -} diff --git a/src/main/java/org/jabref/gui/logging/ApplicationInsightsWriter.java b/src/main/java/org/jabref/gui/logging/ApplicationInsightsWriter.java deleted file mode 100644 index fbcb43670e8..00000000000 --- a/src/main/java/org/jabref/gui/logging/ApplicationInsightsWriter.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.jabref.gui.logging; - -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Map; - -import com.microsoft.applicationinsights.telemetry.ExceptionTelemetry; -import com.microsoft.applicationinsights.telemetry.Telemetry; -import com.microsoft.applicationinsights.telemetry.TraceTelemetry; -import org.tinylog.core.LogEntry; -import org.tinylog.core.LogEntryValue; -import org.tinylog.writers.AbstractFormatPatternWriter; - -public class ApplicationInsightsWriter extends AbstractFormatPatternWriter { - - public ApplicationInsightsWriter(final Map properties) { - super(properties); - } - - public ApplicationInsightsWriter() { - this(Collections.emptyMap()); - } - - @Override - public Collection getRequiredLogEntryValues() { - return EnumSet.allOf(LogEntryValue.class); - } - - @Override - public void write(LogEntry logEntry) throws Exception { - ApplicationInsightsLogEvent event = new ApplicationInsightsLogEvent(logEntry); - - Telemetry telemetry; - if (event.isException()) { - ExceptionTelemetry exceptionTelemetry = new ExceptionTelemetry(event.getException()); - exceptionTelemetry.getProperties().put("Message", logEntry.getMessage()); - exceptionTelemetry.setSeverityLevel(event.getNormalizedSeverityLevel()); - telemetry = exceptionTelemetry; - } else { - TraceTelemetry traceTelemetry = new TraceTelemetry(event.getMessage()); - traceTelemetry.setSeverityLevel(event.getNormalizedSeverityLevel()); - telemetry = traceTelemetry; - } - telemetry.getContext().getProperties().putAll(event.getCustomParameters()); - - org.jabref.gui.Telemetry.getTelemetryClient().ifPresent(client -> client.track(telemetry)); - } - - @Override - public void flush() throws Exception { - } - - @Override - public void close() throws Exception { - } -} diff --git a/src/main/java/org/jabref/logic/pdf/search/indexing/IndexingTaskManager.java b/src/main/java/org/jabref/logic/pdf/search/indexing/IndexingTaskManager.java index a7457f327b1..ba8bc5e5d12 100644 --- a/src/main/java/org/jabref/logic/pdf/search/indexing/IndexingTaskManager.java +++ b/src/main/java/org/jabref/logic/pdf/search/indexing/IndexingTaskManager.java @@ -103,7 +103,7 @@ public void updateIndex(PdfIndexer indexer, BibDatabaseContext databaseContext) } public void addToIndex(PdfIndexer indexer, BibEntry entry, BibDatabaseContext databaseContext) { - enqueueTask(() -> addToIndex(indexer, entry, entry.getFiles(), databaseContext)); + addToIndex(indexer, entry, entry.getFiles(), databaseContext); } public void addToIndex(PdfIndexer indexer, BibEntry entry, List linkedFiles, BibDatabaseContext databaseContext) { diff --git a/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java b/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java index 4fea4b638a5..d10a6c0221a 100644 --- a/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java +++ b/src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java @@ -109,7 +109,7 @@ public void addToIndex(BibEntry entry, LinkedFile linkedFile, BibDatabaseContext this.databaseContext = databaseContext; } if (!entry.getFiles().isEmpty()) { - writeToIndex(entry, linkedFile); + addToIndex(entry, linkedFile); } } @@ -163,18 +163,6 @@ public void flushIndex() { } } - /** - * Writes all files linked to an entry to the index if the files are not yet in the index or the files on the fs are - * newer than the one in the index. - * - * @param entry the entry associated with the file - */ - private void writeToIndex(BibEntry entry) { - for (LinkedFile linkedFile : entry.getFiles()) { - writeToIndex(entry, linkedFile); - } - } - /** * Writes the file to the index if the file is not yet in the index or the file on the fs is newer than the one in * the index. @@ -182,7 +170,7 @@ private void writeToIndex(BibEntry entry) { * @param entry the entry associated with the file * @param linkedFile the file to write to the index */ - private void writeToIndex(BibEntry entry, LinkedFile linkedFile) { + private void addToIndex(BibEntry entry, LinkedFile linkedFile) { if (linkedFile.isOnlineLink() || !StandardFileType.PDF.getName().equals(linkedFile.getFileType())) { return; } @@ -191,6 +179,7 @@ private void writeToIndex(BibEntry entry, LinkedFile linkedFile) { LOGGER.debug("Could not find {}", linkedFile.getLink()); return; } + LOGGER.debug("Adding {} to index", linkedFile.getLink()); try { // Check if a document with this path is already in the index try (IndexReader reader = DirectoryReader.open(directoryToIndex)) { diff --git a/src/test/java/org/jabref/logic/importer/fileformat/ACMPortalParserTest.java b/src/test/java/org/jabref/logic/importer/fileformat/ACMPortalParserTest.java index 059890bd01b..07dc0f82d10 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/ACMPortalParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/ACMPortalParserTest.java @@ -18,7 +18,7 @@ import org.jabref.model.entry.types.StandardEntryType; import org.jabref.testutils.category.FetcherTest; -import com.microsoft.applicationinsights.core.dependencies.http.client.utils.URIBuilder; +import org.apache.http.client.utils.URIBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; From 621e0fa0126672e64563f5e301b74680d0658976 Mon Sep 17 00:00:00 2001 From: Caitlin Lilley Date: Sat, 14 Oct 2023 23:35:18 +1100 Subject: [PATCH 002/125] Added library and entry selection boxes to the UI on "Aux file import" screen --- .../jabref/gui/auximport/FromAuxDialog.fxml | 13 ++++++++- .../jabref/gui/auximport/FromAuxDialog.java | 27 +++++++++++++++++++ src/main/resources/build.properties | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.fxml b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.fxml index 7cdfefc611d..53b3075d769 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.fxml +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.fxml @@ -2,6 +2,7 @@ + @@ -12,7 +13,6 @@ - @@ -43,6 +43,17 @@