Skip to content

Commit

Permalink
Print diff to log file (if PDFBox creates different output)
Browse files Browse the repository at this point in the history
  • Loading branch information
buchen committed Jan 6, 2025
1 parent 78a48b0 commit aeea8dd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion name.abuchen.portfolio.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ Require-Bundle: name.abuchen.portfolio;bundle-version="0.73.1",
org.eclipse.e4.ui.css.core,
org.eclipse.ui.themes,
org.eclipse.jface,
org.apache.httpcomponents.core5.httpcore5
org.apache.httpcomponents.core5.httpcore5,
io.github.java-diff-utils
Automatic-Module-Name: name.abuchen.portfolio.ui
Service-Component: OSGI-INF/name.abuchen.portfolio.ui.util.theme.ColorAndFontProviderImpl.xml,
OSGI-INF/name.abuchen.portfolio.ui.theme.CustomThemeEngineManager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
import java.util.stream.Collectors;

import jakarta.inject.Named;

Expand All @@ -18,6 +20,9 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.github.difflib.DiffUtils;
import com.github.difflib.UnifiedDiffUtils;

import name.abuchen.portfolio.datatransfer.pdf.PDFInputFile;
import name.abuchen.portfolio.money.CurrencyUnit;
import name.abuchen.portfolio.ui.Messages;
Expand Down Expand Up @@ -45,11 +50,31 @@ public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
{
File file = new File(fileDialog.getFilterPath(), fileName);
PDFInputFile inputFile = new PDFInputFile(file);

// create text from PDF
inputFile.convertPDFtoText();
var extractedText = inputFile.getText();
var pdfBoxVersion = inputFile.getPDFBoxVersion();

// check if the extracted text changed with the PDFBox version
inputFile.convertLegacyPDFtoText();
var legacyText = inputFile.getText();
var legacyPdfBoxVersion = inputFile.getPDFBoxVersion();
var isDifferent = !extractedText.equals(legacyText);

if (isDifferent)
{
var patch = DiffUtils.diff(legacyText, extractedText, null);
var unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff(legacyPdfBoxVersion, pdfBoxVersion,
Arrays.asList(legacyText.split("\n")), patch, 0);
PortfolioPlugin.info(
inputFile.getName() + "\n\n" + unifiedDiff.stream().collect(Collectors.joining("\n")));
}

StringBuilder textBuilder = new StringBuilder();
textBuilder.append("```").append("\n");
textBuilder.append("PDFBox Version: ").append(inputFile.getPDFBoxVersion()) //
textBuilder.append("PDFBox Version: ").append(pdfBoxVersion)
.append(isDifferent ? " != " + legacyPdfBoxVersion : "") //
.append("\n");
textBuilder.append("Portfolio Performance Version: ")
.append(PortfolioPlugin.getDefault().getBundle().getVersion().toString()) //
Expand All @@ -62,7 +87,7 @@ public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
.append(System.getProperty("java.vm.vendor", "unknown")).append("\n");

textBuilder.append("-----------------------------------------\n");
textBuilder.append(inputFile.getText().replace("\r", "")).append("\n");
textBuilder.append(extractedText).append("\n");
textBuilder.append("```");

String text = textBuilder.toString();
Expand Down
10 changes: 10 additions & 0 deletions portfolio-target-definition/portfolio-target-definition.target
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,15 @@
</dependency>
</dependencies>
</location>
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" label="io.github.java-diff-utils" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
<version>4.15</version>
<type>jar</type>
</dependency>
</dependencies>
</location>
</locations>
</target>

0 comments on commit aeea8dd

Please sign in to comment.