-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework task structure to allow configuration cache (#4).
- Loading branch information
1 parent
774d86d
commit e30c1b2
Showing
30 changed files
with
680 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/functionalTest/java/dev/yumi/gradle/licenser/test/ConfigurationCacheFunctionalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/functionalTest/resources/scenarios/configuration_cache/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
7 changes: 7 additions & 0 deletions
7
src/functionalTest/resources/scenarios/configuration_cache/src/main/java/test/TestClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...alTest/resources/scenarios/configuration_cache/src/main/java/test/TestClassCrlfApply.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...alTest/resources/scenarios/configuration_cache/src/main/java/test/TestClassCrlfCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...est/resources/scenarios/configuration_cache/src/main/java/test/TestClassWithOptional.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...nctionalTest/resources/scenarios/configuration_cache/src/main/java/test/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* meow meow | ||
*/ | ||
|
||
/** | ||
* A test package info! | ||
*/ | ||
|
||
package test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.