Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Reality: The syntax of these files can be tricky, and it is quite easy to write

# Major update
The upcoming 2.0.0 release has been rewritten into Kotlin. This allows for more exact checks on nullability and improves code quality.
Most of the API has not been changed so using this from Java should be a simple migration.
Most of the API has not been changed so using this from Java should be a simple migration. This new version needs JVM 11 or newer.

# What is this
1) A Kotlin/Java library to read a CODEOWNERS file.
Expand All @@ -27,7 +27,7 @@ Most of the API has not been changed so using this from Java should be a simple

The intended goal is to make the build fail if the codeowners file does not cover all files and directories in the project.

- The libraries for the CODEOWNERS and gitignore files are usable in Java 8 and newer.
- The libraries for the CODEOWNERS and gitignore files are usable in Java 11 and newer.
- The Maven Enforcer rule needs Java 11 or newer.

# CodeOwners Enforcer rule
Expand Down
4 changes: 2 additions & 2 deletions codeowners-reader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>

Expand Down
13 changes: 5 additions & 8 deletions codeowners-reader/src/main/kotlin/nl/basjes/codeowners/Rule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@
*/
package nl.basjes.codeowners

import java.util.regex.Pattern

abstract class Rule(
/**
* @return The provided file expression used to build this rule
*/
@JvmField val fileExpression: String
val fileExpression: String
) {
fun getFileExpression() = fileExpression
/**
* The Pattern which was constructed from the provided fileExpression
*/
val filePattern: Pattern
val filePattern: Regex

var verbose: Boolean = false

Expand Down Expand Up @@ -63,7 +60,7 @@ abstract class Rule(
// The Globstar "foo/**/bar" must also match "foo/bar"
// Process trailing /** before middle /** to handle them correctly:
// 1. Trailing: "foo/**" matches "foo/" and its contents, but NOT "foo" or "foobar"
.replace( "/\\*\\*$".toRegex(), "/.*" )
.replace("/\\*\\*$".toRegex(), "/.*")
// 2. Middle: "foo/**/bar" matches both "foo/bar" and "foo/anything/bar"
.replace("/**", "(/.*)?")

Expand Down Expand Up @@ -93,14 +90,14 @@ abstract class Rule(
// Remove duplication
.replace("/+".toRegex(), "/")

filePattern = Pattern.compile(fileRegex)
filePattern = fileRegex.toRegex()
}

/**
* @return True if the provided file matches the configured fileExpression. If not it returns false.
*/
fun matches(filename: String): Boolean {
val matches = filePattern.matcher(filename).find()
val matches = filePattern.containsMatchIn(filename)
if (verbose) {
val result = if(matches) "MATCH " else "NO MATCH"
LOG.info("$result |{}| ~ |{}| --> {}", fileExpression, filePattern, filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package nl.basjes.codeowners

class Section(@JvmField val name: String) {
fun getName() = name
class Section(val name: String) {

var verbose = false
set(verbose) {
Expand Down

This file was deleted.

Loading
Loading