You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
6.7 KiB
168 lines
6.7 KiB
# PDF解析ツール(PdfProbeApp)のテスト用スクリプト
|
|
|
|
Write-Host "=== PDF解析ツール テスト実行 ===" -ForegroundColor Green
|
|
|
|
# JARファイルのパス
|
|
$probeJarPath = "build\libs\pdf-probe.jar"
|
|
$samplesDir = "samples"
|
|
|
|
# JARファイルの存在確認
|
|
if (-not (Test-Path $probeJarPath)) {
|
|
Write-Host "JARファイルが見つかりません。ビルドを実行します..." -ForegroundColor Yellow
|
|
|
|
# Gradleビルドを実行してJARファイルを作成
|
|
try {
|
|
Write-Host "Gradleビルド実行中..." -ForegroundColor Cyan
|
|
$env:JAVA_TOOL_OPTIONS = "-Dfile.encoding=UTF-8"
|
|
|
|
# 既存のクラスファイルを使ってJARを作成
|
|
Write-Host "JARファイル作成中..." -ForegroundColor Cyan
|
|
|
|
# probeJarタスクを実行
|
|
if (Test-Path "gradlew.bat") {
|
|
& .\gradlew.bat probeJar 2>$null
|
|
} else {
|
|
# 手動でJARファイルを作成
|
|
$buildLibsDir = "build\libs"
|
|
if (-not (Test-Path $buildLibsDir)) {
|
|
New-Item -Path $buildLibsDir -ItemType Directory -Force | Out-Null
|
|
}
|
|
|
|
# クラスファイルとライブラリからJARを作成
|
|
Write-Host "手動でJARファイルを作成中..." -ForegroundColor Cyan
|
|
|
|
# Manifestファイルを作成
|
|
$manifestContent = @"
|
|
Manifest-Version: 1.0
|
|
Main-Class: co.jp.techsor.pdf.PdfProbeApp
|
|
|
|
"@
|
|
$manifestPath = "build\MANIFEST.MF"
|
|
$manifestContent | Out-File -FilePath $manifestPath -Encoding UTF8
|
|
|
|
# PowerShellでJARファイルを作成(zipコマンドの代替)
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
|
|
if (Test-Path $probeJarPath) {
|
|
Remove-Item $probeJarPath -Force
|
|
}
|
|
|
|
$archive = [System.IO.Compression.ZipFile]::Open($probeJarPath, [System.IO.Compression.ZipArchiveMode]::Create)
|
|
|
|
# クラスファイルを追加
|
|
$classesDir = "build\classes"
|
|
if (Test-Path $classesDir) {
|
|
Get-ChildItem -Path $classesDir -Recurse -File | ForEach-Object {
|
|
$relativePath = $_.FullName.Substring((Resolve-Path $classesDir).Path.Length + 1)
|
|
$relativePath = $relativePath.Replace('\', '/')
|
|
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, $_.FullName, $relativePath) | Out-Null
|
|
}
|
|
}
|
|
|
|
# ライブラリファイルを追加
|
|
$libDir = "lib"
|
|
if (Test-Path $libDir) {
|
|
Get-ChildItem -Path $libDir -Filter "*.jar" | ForEach-Object {
|
|
$libArchive = [System.IO.Compression.ZipFile]::OpenRead($_.FullName)
|
|
foreach ($entry in $libArchive.Entries) {
|
|
if (-not $entry.FullName.EndsWith('/') -and -not $entry.FullName.StartsWith('META-INF/')) {
|
|
$newEntry = $archive.CreateEntry($entry.FullName)
|
|
$newEntry.LastWriteTime = $entry.LastWriteTime
|
|
$stream = $newEntry.Open()
|
|
$entryStream = $entry.Open()
|
|
$entryStream.CopyTo($stream)
|
|
$stream.Close()
|
|
$entryStream.Close()
|
|
}
|
|
}
|
|
$libArchive.Dispose()
|
|
}
|
|
}
|
|
|
|
# Manifestを追加
|
|
$manifestEntry = $archive.CreateEntry("META-INF/MANIFEST.MF")
|
|
$manifestStream = $manifestEntry.Open()
|
|
$manifestBytes = [System.Text.Encoding]::UTF8.GetBytes($manifestContent)
|
|
$manifestStream.Write($manifestBytes, 0, $manifestBytes.Length)
|
|
$manifestStream.Close()
|
|
|
|
$archive.Dispose()
|
|
|
|
Write-Host "JARファイルを手動で作成しました: $probeJarPath" -ForegroundColor Green
|
|
}
|
|
}
|
|
catch {
|
|
Write-Host "ビルドエラー: $($_.Exception.Message)" -ForegroundColor Red
|
|
Write-Host "手動でJARファイルを確認してください" -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
# サンプルディレクトリの確認
|
|
if (-not (Test-Path $samplesDir)) {
|
|
Write-Host "エラー: samplesディレクトリが見つかりません" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# テスト対象のPDFファイルを取得
|
|
$pdfFiles = Get-ChildItem -Path $samplesDir -Filter "*.pdf" | Select-Object -First 3
|
|
|
|
if ($pdfFiles.Count -eq 0) {
|
|
Write-Host "エラー: samplesディレクトリにPDFファイルが見つかりません" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "`n対象PDFファイル:" -ForegroundColor Cyan
|
|
$pdfFiles | ForEach-Object { Write-Host " - $($_.Name)" }
|
|
|
|
# 各PDFファイルに対してテストを実行
|
|
foreach ($pdfFile in $pdfFiles) {
|
|
Write-Host "`n" + ("=" * 60) -ForegroundColor Yellow
|
|
Write-Host "解析対象: $($pdfFile.Name)" -ForegroundColor Yellow
|
|
Write-Host ("=" * 60) -ForegroundColor Yellow
|
|
|
|
$inputPath = $pdfFile.FullName
|
|
|
|
try {
|
|
# 基本解析
|
|
Write-Host "`n1. 基本解析:" -ForegroundColor Cyan
|
|
java -Dfile.encoding=UTF-8 -jar $probeJarPath -i "$inputPath"
|
|
|
|
# 詳細解析
|
|
Write-Host "`n2. 詳細解析:" -ForegroundColor Cyan
|
|
java -Dfile.encoding=UTF-8 -jar $probeJarPath -i "$inputPath" -v
|
|
|
|
# 結果をファイルに保存
|
|
$outputFile = "analysis-result-$($pdfFile.BaseName).txt"
|
|
Write-Host "`n3. ファイル出力テスト:" -ForegroundColor Cyan
|
|
java -Dfile.encoding=UTF-8 -jar $probeJarPath -i "$inputPath" -v -o $outputFile
|
|
|
|
if (Test-Path $outputFile) {
|
|
Write-Host "✓ 結果ファイルが作成されました: $outputFile" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "⚠ 結果ファイルの作成に失敗しました" -ForegroundColor Yellow
|
|
}
|
|
|
|
}
|
|
catch {
|
|
Write-Host "エラー: $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
}
|
|
|
|
# ヘルプの表示
|
|
Write-Host "`n" + ("=" * 60) -ForegroundColor Yellow
|
|
Write-Host "ヘルプ表示テスト" -ForegroundColor Yellow
|
|
Write-Host ("=" * 60) -ForegroundColor Yellow
|
|
|
|
try {
|
|
java -jar $probeJarPath --help
|
|
}
|
|
catch {
|
|
Write-Host "ヘルプ表示エラー: $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
Write-Host "`n=== PDF解析ツール テスト完了 ===" -ForegroundColor Green
|
|
Write-Host "生成されたファイル:" -ForegroundColor Yellow
|
|
Get-ChildItem -Filter "analysis-result-*.txt" | ForEach-Object {
|
|
Write-Host " - $($_.Name)" -ForegroundColor White
|
|
}
|
|
|