Skip to content

Commit

Permalink
Allow configuring persistent index format version in the Maven plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-afk authored and Ladicek committed Aug 15, 2023
1 parent ad1785b commit d6d3610
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
45 changes: 45 additions & 0 deletions maven-plugin/src/it/indexVersion/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin-indexVersion</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@version.maven-compiler-plugin@</version>
</plugin>

<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
<configuration>
<!-- oldest version of V2 index -->
<indexVersion>6</indexVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.jboss.jandex.maven.indexVersion;

public class SomeClass {
}
13 changes: 13 additions & 0 deletions maven-plugin/src/it/indexVersion/verify.groovy
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion maven-plugin/src/it/smoketest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d6d3610

Please sign in to comment.