Skip to content

Commit

Permalink
Merge commit 'a078564d53495e78687d2089e54569ae4106c3cd'
Browse files Browse the repository at this point in the history
  • Loading branch information
h1romas4 committed Oct 8, 2023
2 parents 5c76bbf + a078564 commit 8ddca64
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# create document
./gradlew docs
# output unused images and test Gradle task
./gradlew checkSyncImage
./gradlew -q checkSyncImage
- name: Build with Gradle (macOS)
if: startsWith(matrix.os, 'macos')
Expand All @@ -68,7 +68,7 @@ jobs:
# create document
./gradlew docs
# output unused images and test Gradle task
./gradlew checkSyncImage
./gradlew -q checkSyncImage
- name: Build with Gradle (Windows)
if: startsWith(matrix.os, 'windows')
Expand All @@ -79,7 +79,7 @@ jobs:
# create document
.\gradlew docs
# output unused images and test Gradle task
.\gradlew checkSyncImage
.\gradlew -q checkSyncImage
- name: Check
shell: bash
Expand All @@ -92,11 +92,23 @@ jobs:
file docs/index.pdf | grep PDF
file docs/index.html | grep HTML
- name: Output PDF information
- name: Output PDF information (Ubuntu)
if: startsWith(matrix.os, 'ubuntu')
run: |
echo "# PDF information"
pdfinfo docs/index.pdf
./gradlew -q checkPdfInfo
echo "# URLs in document"
pdfinfo -url docs/index.pdf | tail -n +2 | awk '{ print $3 }' | sort | uniq
echo "# Unused images"
- name: Output PDF information
if: startsWith(matrix.os, 'windows')
shell: pwsh
run: |
echo "# PDF information"
.\gradlew -q checkPdfInfo
- name: Output PDF information (macOS)
if: startsWith(matrix.os, 'macos')
run: |
echo "# PDF information"
./gradlew -q checkPdfInfo
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ tasks.register('checkSyncImage', SyncImageTask) {
imageExt = ['png', 'jpg', 'jpeg', 'svg']
}

/**
* PDF 文書のメタデータを確認するユーティリティタスク
*
* ./gradlew -q checkPdfInfo
*
* @see buildSrc/src/main/groovy/AsciidocTasks.groovy
*/
tasks.register('checkPdfInfo', PdfInfoTask) {
group 'documentation'
description 'Utility task to check PDF document metadata'
// 確認する PDF 文書
pdfFile = file('docs/index.pdf')
}

/**
* Asciidoc 文書から HTML/PDF 文書を生成し配布可能な状態で docs 配下に出力するタスク
*
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ dependencies {
implementation gradleApi()
implementation localGroovy()
implementation 'org.asciidoctor:asciidoctorj:2.5.6'
implementation 'org.apache.tika:tika-core:2.9.0'
implementation 'org.apache.tika:tika-parsers-standard-package:2.9.0'
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
}
39 changes: 39 additions & 0 deletions buildSrc/src/main/groovy/PdfInfoTask.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.InputFile

import org.apache.tika.metadata.Metadata
import org.apache.tika.parser.ParseContext
import org.apache.tika.parser.pdf.PDFParser
import org.apache.tika.sax.BodyContentHandler

/**
* PDF 文書のメタデータを確認するユーティリティタスク
*
*/
abstract class PdfInfoTask extends DefaultTask {
/**
* PDF 文書
*/
@InputFile
File pdfFile

/**
* Gradle タスクエントリーポイント
*/
@TaskAction
def checkPdfInfo() {
BodyContentHandler handler = new BodyContentHandler()
Metadata metadata = new Metadata()
FileInputStream input = new FileInputStream(pdfFile)
ParseContext context = new ParseContext()

PDFParser pdf = new PDFParser()
pdf.parse(input, handler, metadata, context)

metadata.names().sort().each { name ->
println "${name}: ${metadata.get(name)}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ abstract class SyncImageTask extends DefaultTask {
}
}
}

0 comments on commit 8ddca64

Please sign in to comment.