Skip to content

Commit

Permalink
Add setting to allow disabling of auto-inclusion of Jandex index in J…
Browse files Browse the repository at this point in the history
…AR (#1)
  • Loading branch information
stringbean committed Jun 2, 2023
1 parent 8491acb commit fd1b1db
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 29 deletions.
27 changes: 13 additions & 14 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Contributor Covenant Code of Conduct

## Our Pledge
Expand All @@ -15,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Expand Down
8 changes: 4 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Welcome and thanks for taking the time to contribute to this project!

Before submitting a PR please ensure that you have run the following sbt tasks:

* `test`
* `scripted`
* `scalafmt`
* `headerCheck`
* `test`
* `scripted`
* `scalafmt`
* `headerCheck`

This should ensure that everything works and meets the styleguide.

Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# sbt-jandex

[![Build Status](https://img.shields.io/github/actions/workflow/status/stringbean/sbt-jandex/ci.yml?branch=main)](https://github.com/stringbean/sbt-jandex/actions/workflows/ci.yml)
[![Codacy grade](https://img.shields.io/codacy/grade/aad472c1c869488e977a198e97253d8e?label=codacy)](https://app.codacy.com/gh/stringbean/sbt-jandex)
[![Known Vulnerabilities](https://snyk.io/test/github/stringbean/sbt-jandex/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/stringbean/sbt-jandex?targetFile=build.sbt)
[![sbt-jandex version](https://index.scala-lang.org/stringbean/sbt-jandex/sbt-jandex/latest.svg)](https://index.scala-lang.org/stringbean/sbt-jandex/sbt-jandex)
[![GitHub Discussions](https://img.shields.io/github/discussions/stringbean/sbt-jandex)](https://github.com/stringbean/sbt-jandex/discussions)

An sbt plugin to generate [Jandex][jandex] indexes for projects.

## Setup
Expand All @@ -12,4 +18,25 @@ addSbtPlugin("software.purpledragon" % "sbt-jandex" % "<version>")

Jandex indexes will automatically be generated and added to the binary JARs.

[jandex]: https://smallrye.io/jandex
## Tasks

### `jandex`

Generates Jandex index for the main classes and stores it in `jandexOutput.value / jandex.idx`.

## Settings

### `jandexOutput`

* **Description:** Directory to store generated Jandex index in.
* **Accepts:** `File`
* **Default:** `crossTarget.value / jandex`

### `jandexIncludeInPackage`

* **Description:** Whether to include Jandex index in the main JAR. If `true` then the index will be included under
\`META-INF/jandex.idx.
* **Accepts:** `Boolean`
* **Default:** `true`

[jandex]: https://smallrye.io/jandex
16 changes: 12 additions & 4 deletions src/main/scala/software/purpledragon/sbt/jandex/JandexPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,30 @@ object JandexPlugin extends AutoPlugin {
override val requires: Plugins = JvmPlugin

object autoImport {
lazy val jandex: TaskKey[File] = taskKey[File]("generate Jandex index")
lazy val jandexOutput = taskKey[File]("output dir")
lazy val jandex: TaskKey[File] = taskKey[File]("Generate Jandex index")

lazy val jandexOutput: TaskKey[sbt.File] = taskKey[File]("Output directory for generated index")
lazy val jandexIncludeInPackage: TaskKey[Boolean] =
taskKey[Boolean]("If true, then a generated Jandex index will be added to the binary JAR")
}

import autoImport.*

override def projectSettings: Seq[Def.Setting[?]] = Seq(
jandexOutput := crossTarget.value / "jandex",
jandexIncludeInPackage := true,
jandex := {
streams.value.log.info("Generating Jandex index")
val classDirs = (Runtime / products).value

JandexGenerator.generateIndex(classDirs, jandexOutput.value)
},
Compile / packageBin / mappings += {
jandex.value -> "META-INF/jandex.idx"
Compile / packageBin / mappings ++= {
if (jandexIncludeInPackage.value) {
Seq(jandex.value -> "META-INF/jandex.idx")
} else {
Seq.empty
}
},
)
}
11 changes: 5 additions & 6 deletions src/sbt-test/jandex/generate/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ verifyJarIndex := {

val projectJar = (Compile / packageBin).value

Using(new JarFile(projectJar)) { jarFile =>
val indexEntry = jarFile.getEntry("META-INF/jandex.idx")
val jarFile = new JarFile(projectJar)
val indexEntry = jarFile.getEntry("META-INF/jandex.idx")

if (indexEntry == null) {
sys.error("Missing index.idx in JAR")
}
if (indexEntry == null) {
sys.error("Missing jandex.idx in JAR")
}
}
}
22 changes: 22 additions & 0 deletions src/sbt-test/jandex/no-include/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name := "jandex-cdi"
scalaVersion := "2.13.10"

libraryDependencies += "jakarta.enterprise" % "jakarta.enterprise.cdi-api" % "4.0.1" % Provided

jandexIncludeInPackage := false

val verifyJarNoIndex = taskKey[Unit]("check Jandex index is not in JAR")

verifyJarNoIndex := {
import scala.util.Using
import java.util.jar.JarFile

val projectJar = (Compile / packageBin).value

val jarFile = new JarFile(projectJar)
val indexEntry = jarFile.getEntry("META-INF/jandex.idx")

if (indexEntry != null) {
sys.error("jandex.idx found in JAR")
}
}
7 changes: 7 additions & 0 deletions src/sbt-test/jandex/no-include/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
val pluginVersion = System.getProperty("plugin.version")
if (pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("software.purpledragon" % "sbt-jandex" % pluginVersion)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example

import jakarta.enterprise.context.ApplicationScoped

@ApplicationScoped
class Greeter {
def greet(name: String): String = {
s"Hello, $name!"
}
}
6 changes: 6 additions & 0 deletions src/sbt-test/jandex/no-include/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# check index file is generated
> jandex
$ exists target/scala-2.13/jandex/jandex.idx

# check that index file is included in JAR
> verifyJarNoIndex

0 comments on commit fd1b1db

Please sign in to comment.