From d6d3610d388b8500a152cf7f3c8bbccca6244b08 Mon Sep 17 00:00:00 2001 From: Andrey Manzharov Date: Fri, 11 Aug 2023 07:33:30 +0300 Subject: [PATCH] Allow configuring persistent index format version in the Maven plugin --- maven-plugin/src/it/indexVersion/pom.xml | 45 +++++++++++++++++++ .../jandex/maven/indexVersion/SomeClass.java | 4 ++ .../src/it/indexVersion/verify.groovy | 13 ++++++ maven-plugin/src/it/smoketest/pom.xml | 2 +- .../org/jboss/jandex/maven/JandexGoal.java | 12 ++++- 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 maven-plugin/src/it/indexVersion/pom.xml create mode 100644 maven-plugin/src/it/indexVersion/src/main/java/org/jboss/jandex/maven/indexVersion/SomeClass.java create mode 100644 maven-plugin/src/it/indexVersion/verify.groovy diff --git a/maven-plugin/src/it/indexVersion/pom.xml b/maven-plugin/src/it/indexVersion/pom.xml new file mode 100644 index 00000000..98371f00 --- /dev/null +++ b/maven-plugin/src/it/indexVersion/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + org.jboss.jandex + jandex-maven-plugin-indexVersion + 1.0-SNAPSHOT + + + UTF-8 + UTF-8 + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @version.maven-compiler-plugin@ + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + make-index + + jandex + + + + 6 + + + + + + + diff --git a/maven-plugin/src/it/indexVersion/src/main/java/org/jboss/jandex/maven/indexVersion/SomeClass.java b/maven-plugin/src/it/indexVersion/src/main/java/org/jboss/jandex/maven/indexVersion/SomeClass.java new file mode 100644 index 00000000..58818f75 --- /dev/null +++ b/maven-plugin/src/it/indexVersion/src/main/java/org/jboss/jandex/maven/indexVersion/SomeClass.java @@ -0,0 +1,4 @@ +package org.jboss.jandex.maven.indexVersion; + +public class SomeClass { +} diff --git a/maven-plugin/src/it/indexVersion/verify.groovy b/maven-plugin/src/it/indexVersion/verify.groovy new file mode 100644 index 00000000..8d4d7d9c --- /dev/null +++ b/maven-plugin/src/it/indexVersion/verify.groovy @@ -0,0 +1,13 @@ +import org.jboss.jandex.IndexReader +import org.jboss.jandex.PackedDataInputStream + +def jandexFile = new File(basedir, 'target/classes/META-INF/jandex.idx') +assert jandexFile.exists() : "File ${jandexFile} does not exist" +assert jandexFile.length() > 0 : "File ${jandexFile} is empty" + +def data = new PackedDataInputStream(jandexFile.newInputStream()) +assert data.readInt() == 0xBABE1F15 as int // magic +assert data.readUnsignedByte() == 6 // version + +def index = new IndexReader(jandexFile.newInputStream()).read() +assert index.getKnownClasses().size() == 1 : "Index ${jandexFile} does not contain exactly 1 class" diff --git a/maven-plugin/src/it/smoketest/pom.xml b/maven-plugin/src/it/smoketest/pom.xml index d0edf1c0..a227c6dc 100644 --- a/maven-plugin/src/it/smoketest/pom.xml +++ b/maven-plugin/src/it/smoketest/pom.xml @@ -42,4 +42,4 @@ - \ No newline at end of file + diff --git a/maven-plugin/src/main/java/org/jboss/jandex/maven/JandexGoal.java b/maven-plugin/src/main/java/org/jboss/jandex/maven/JandexGoal.java index 2e8ae10a..8d61ef9c 100644 --- a/maven-plugin/src/main/java/org/jboss/jandex/maven/JandexGoal.java +++ b/maven-plugin/src/main/java/org/jboss/jandex/maven/JandexGoal.java @@ -113,6 +113,12 @@ public class JandexGoal extends AbstractMojo { @Parameter(defaultValue = "jandex.idx") private String indexName; + /** + * Persistent index format version to write. Defaults to max supported version. + */ + @Parameter + private Integer indexVersion; + /** * Skip execution if set. */ @@ -169,7 +175,11 @@ public void execute() throws MojoExecutionException { Files.createDirectories(indexDir.toPath()); try (OutputStream out = new CachingOutputStream(indexFile)) { IndexWriter writer = new IndexWriter(out); - writer.write(index); + if (indexVersion != null) { + writer.write(index, indexVersion); + } else { + writer.write(index); + } } } catch (IOException e) { throw new MojoExecutionException("Could not save index " + indexFile, e);