Skip to content

Commit

Permalink
Rework task structure to allow configuration cache (#4).
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Oct 26, 2024
1 parent 774d86d commit e30c1b2
Show file tree
Hide file tree
Showing 30 changed files with 680 additions and 215 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
run: ./gradlew build check --stacktrace --parallel
- name: "Upload artifacts"
uses: actions/upload-artifact@v4
if: matrix.java == 17
with:
name: Artifacts
name: Artifacts_j${{ matrix.java }}
path: ./build/libs/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@
- Added some extra default file-types for C-style header comments,
specifically for common web languages and stylesheet formats ([#3]).

## 2.0.0

- Reworked tasks to work with the configuration cache.
- Tasks now use inputs.
- Source files input is now much more flexible.
- Made several data structures serializable.
- Switched from `PatternFilterable` to `Set<String>` for file matching in `HeaderCommentManager` as only extensions are matched.
- Adapted `LicenseYearSelectionMode` to not consume `Project` arguments anymore.

[#3]: https://github.com/YumiProject/yumi-gradle-licenser/pull/3
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Yumi Licenser Gradle Plugin

![Java 17](https://img.shields.io/badge/language-Java%2017-9B599A.svg?style=flat-square)
![Java 17](https://img.shields.io/badge/language-Java%2017-9115ff.svg?style=flat-square)
[![GitHub license](https://img.shields.io/github/license/YumiProject/yumi-gradle-licenser?style=flat-square)](https://raw.githubusercontent.com/YumiProject/yumi-gradle-licenser/main/LICENSE)
![Version](https://img.shields.io/github/v/tag/YumiProject/yumi-gradle-licenser?label=version&style=flat-square)

Expand All @@ -17,7 +17,7 @@ For a project you need to apply the plugin to your project:

```groovy
plugins {
id "dev.yumi.gradle.licenser" version "1.2.+"
id "dev.yumi.gradle.licenser" version "2.0.+"
}
```

Expand All @@ -39,11 +39,11 @@ The plugin can be configured using the `license` extension on the project.
```groovy
license {
// Add a license header rule, at least one must be present.
rule file("codeformat/HEADER")
rule(file("codeformat/HEADER"))
// Exclude/include certain file types, defaults are provided to easily deal with Java/Kotlin projects.
include "**/*.java" // Include Java files into the file resolution.
exclude "**/*.properties" // Exclude properties files from the file resolution.
include("**/*.java") // Include Java files into the file resolution.
exclude("**/*.properties") // Exclude properties files from the file resolution.
}
```

Expand Down
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id("dev.yumi.gradle.licenser") version "1.1.+"
id("dev.yumi.gradle.licenser") version "1.2.+"
id("com.gradle.plugin-publish") version "1.2.0"

kotlin("jvm") version "1.9.24"
kotlin("jvm") version "2.0.0"

`maven-publish`
signing
}

group = "dev.yumi"
version = "1.2.0"
version = "2.0.0"
val javaVersion = 17

repositories {
Expand All @@ -25,6 +25,8 @@ dependencies {
// Use JUnit Jupiter for testing.
testImplementation(libs.junit.jupiter)
testRuntimeOnly(libs.junit.launcher)
"functionalTestImplementation"(libs.junit.jupiter)
"functionalTestRuntimeOnly"(libs.junit.launcher)
}

gradlePlugin {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2024 Yumi Project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package dev.yumi.gradle.licenser.test;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* A configuration cache functional test for the 'dev.yumi.gradle.licenser' plugin.
* <p>
* Based on the {@link BaseJavaFunctionalTest base java functional test}.
*/
public class ConfigurationCacheFunctionalTest {
@TempDir
File projectDir;

@Test
public void canRunTask() throws IOException {
var runner = new ScenarioRunner("configuration_cache", projectDir.toPath());
runner.setup();

Path testClassPath = runner.path("src/main/java/test/TestClass.java");
Path testCrlfCheckClassPath = runner.path("src/main/java/test/TestClassCrlfCheck.java");
Path testCrlfApplyClassPath = runner.path("src/main/java/test/TestClassCrlfApply.java");
Path testClassWithOptionalPath = runner.path("src/main/java/test/TestClassWithOptional.java");
Path testPackageInfoPath = runner.path("src/main/java/test/package-info.java");

var result = runner.run("--configuration-cache", "applyLicenses", "--stacktrace");

// Verify the result
assertTrue(
result.getOutput().contains("- Updated file " + testClassPath),
"Missing updated file string in output log."
);
assertTrue(
result.getOutput().contains("- Updated file " + testCrlfApplyClassPath),
"Missing updated file string in output log."
);
assertTrue(
result.getOutput().contains("- Updated file " + testPackageInfoPath),
"Missing updated package-info file string in output log."
);
assertFalse(
result.getOutput().contains("- Updated file " + testCrlfCheckClassPath),
"Found updated Java with CRLF linefeed file string in output log while it's supposed to not change."
);
assertFalse(
result.getOutput().contains("- Updated file " + testClassWithOptionalPath),
"Found updated Java with optional line file string in output log while it's supposed to not change."
);
assertTrue(
result.getOutput().contains("Updated 3 out of 5 files."),
"Missing update status string in output log."
);

assertTrue(Files.readString(testClassPath).contains("Sample header "));
assertTrue(Files.readString(testPackageInfoPath).contains("Sample header "));
String testClassWithOptionalResult = Files.readString(testClassWithOptionalPath);
assertTrue(testClassWithOptionalResult.contains("Sample header "));
assertTrue(testClassWithOptionalResult.contains("Optional sample line."));

assertTrue(
Files.readString(testCrlfApplyClassPath).contains("\r\n"),
"TestClassCrlfApply.java is missing CRLF linefeed."
);

runner.runCheck();
// Test the caching.
runner.runCheck();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'dev.yumi.gradle.licenser'
id 'java'
}

license {
rule rootProject.file("HEADER")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test;

public class TestClass {
public static void main(String[] args) {
System.out.println("Hello world.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test;

// This source file is in CRLF to test proper Windows compatibility.
public class TestClassCrlfApply {
public static void main(String[] args) {
System.out.println("Hello world.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Sample header 2023.
*
* File: TestClassCrlfCheck.java
*/

package test;

// This source file is in CRLF to test proper Windows compatibility.
public class TestClassCrlfCheck {
public static void main(String[] args) {
System.out.println("Hello world.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Sample header 2023.
*
* File: TestClassWithOptional.java
*
* Optional sample line.
*/

package test;

public class TestClassWithOptional {
public static void main(String[] args) {
System.out.println("Hello world.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* meow meow
*/

/**
* A test package info!
*/

package test;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Represents the Yumi Licenser Gradle plugin.
*
* @author LambdAurora
* @version 1.1.1
* @version 2.0.0
* @since 1.0.0
*/
public class YumiLicenserGradlePlugin implements Plugin<Project> {
Expand All @@ -51,12 +51,12 @@ public void apply(Project project) {
.all(sourceSet -> {
project.getTasks().register(
getTaskName("check", sourceSet), CheckLicenseTask.class,
sourceSet.getAllSource(), ext
).configure(task -> task.onlyIf(t -> !ext.isSourceSetExcluded(sourceSet)));
ext
).configure(CheckLicenseTask.configureDefault(ext, project, sourceSet.getAllSource(), sourceSet.getName()));
project.getTasks().register(
getTaskName("apply", sourceSet), ApplyLicenseTask.class,
sourceSet.getAllSource(), ext
).configure(task -> task.onlyIf(t -> !ext.isSourceSetExcluded(sourceSet)));
ext
).configure(ApplyLicenseTask.configureDefault(ext, project, sourceSet.getAllSource(), sourceSet.getName()));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
* Represents the license comment reader and writer for C-style files.
*
* @author LambdAurora
* @version 1.0.0
* @version 2.0.0
* @since 1.0.0
*/
public class CStyleHeaderComment implements HeaderComment {
public final class CStyleHeaderComment implements HeaderComment {
/**
* The implementation instance of this header comment type.
*/
public static final CStyleHeaderComment INSTANCE = new CStyleHeaderComment();

private CStyleHeaderComment() {}

@Override
public @NotNull Result readHeaderComment(@NotNull String source) {
int start = 0, end;
Expand Down
Loading

0 comments on commit e30c1b2

Please sign in to comment.