Skip to content

Commit

Permalink
refactor: handled JDK versions within the same branch (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1nc3n4 authored Nov 27, 2024
1 parent e730f8d commit 7ab3dbd
Show file tree
Hide file tree
Showing 812 changed files with 35,536 additions and 1,329 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Actual results: ...

- OS: [e.g. Ubuntu 24.04, Windows 11 Pro, Mac OS X]
- JDK: [e.g. Adoptium Temurin JDK 21 64 bits]
- Gradle: [e.g. Gradle 8.10.2]
- Gradle: [e.g. Gradle 8.11.1]
- Frontend Gradle plugin: [e.g. 10.0.0 JDK 21]

Settings in `build.gradle[.kts]` file:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Explain what you would like the plugin do: ...

- OS: [e.g. Ubuntu 24.04, Windows 11 Pro, Mac OS X]
- JDK: [e.g. Adoptium Temurin JDK 21 64 bits]
- Gradle: [e.g. Gradle 8.10.2]
- Gradle: [e.g. Gradle 8.11.1]
- Frontend Gradle plugin: [e.g. 10.0.0 JDK 21]

Settings in `build.gradle[.kts]` file:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ jobs:
key: ${{ runner.os }}-sonar-${{ hashFiles('**/*.gradle*') }}

- name: Grant executable permission
run: chmod +x gradlew plugin/src/integrationTest/resources/*/bin/*
run: chmod +x gradlew plugins/frontend-jdk*/src/integrationTest/resources/*/bin/*

- name: Build plugin on Linux (with test coverage)
if: matrix.os == 'ubuntu-24.04'
run: ./gradlew :plugin:jacocoTestReport --console=plain
run: ./gradlew :plugins:frontend-jdk21:jacocoTestReport --console=plain

- name: Build plugin on MacOS
if: matrix.os == 'macos-14'
run: ./gradlew :plugin:build --console=plain
run: ./gradlew :plugins:frontend-jdk21:build --console=plain

- name: Build plugin on Windows
if: matrix.os == 'windows-2022'
run: |
Remove-Item Env:npm_config_prefix
./gradlew :plugin:build --console=plain
./gradlew :plugins:frontend-jdk21:build --console=plain
- name: Scan source code and test results
if: matrix.os == 'ubuntu-24.04'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew :plugin:sonar --console=plain -Dorg.gradle.jvmargs=-Xmx512m -i
run: ./gradlew :plugins:frontend-jdk21:sonar --console=plain -Dorg.gradle.jvmargs=-Xmx512m -i

- name: Stop Gradle before caching
run: ./gradlew -stop
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/plugin/buildSrc/out/
/plugin/out/
/frontend-jdk*/buildSrc/out/
/frontend-jdk*/out/
/site/.frontend-gradle-plugin
/site/.nuxt/
/site/.output/
Expand Down
24 changes: 11 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ After ensuring the problem was not reported already, any issue may be created us

#### Long-term branches

- Production branch: the `main` branch contains stable releases compiled with the most recent LTS JDK. The `HEAD`
revision matches generally the latest stable release, though it may sometimes contain above the latest release some
fixes unrelated to the packaged software (online documentation, CI workflows, etc.) It MUST receive commits only with
pull requests merged from version branches. No short-term branch should be created from this branch for feature
implementation or bug fixing.
- Version branches: branches `<X>.<Y>[-jdk<Z>]` contain history of each version `X.Y`, eventually compiled with a
certain version of the JDK.
- Production branch: the `main` branch contains latest changes being implemented with the multiple JDK. It MUST receive
commits only with pull requests merged from short-term branches, squashed.
- Version branches: these are legacy branches `<X>.<Y>[-jdk<Z>]` containing history of each version `X.Y`, eventually
compiled with a certain version of the JDK when the project was not configured with multiple Java toolchains yet.

#### Short-term branches

These branches are development branches. They are intended to reveive development of features, bug fixes, or updates of
the build process or documentation. A development branch SHALL be named depending on its content:
These branches are development branches, whose base is a commit from the `main` branch. They are intended to receive
development of features, bug fixes, or updates of the build process or documentation. A development branch SHALL be
named depending on its content:

- Feature: `feature/<issue-number>-<description>`
- Bug fix: `fix/<issue-number>-<description>`
Expand All @@ -35,9 +33,9 @@ together.
#### Commit

- Development branches MAY contain one or more commits to achieve the goal.
- A pull request MUST be created to merge commits in a development branch into a version branch.
- Linear history is expected in long-term branches: merge commits are forbidden.
- A single commit by feature/fix/task is expected in long-term branches: commits in a development branch MUST be
- A pull request MUST be created to merge commits from a development branch into the `main` branch.
- Linear history is expected in the `main` branch: merge commits are forbidden.
- A single commit by feature/fix/task is expected in the `main` branch: commits in a development branch MUST be
squashed before being merged in a long-term branch. If not done by the developer, squashing is forced when the pull
request is merged.
- Commit messages MUST follow the [Conventional commits][conventional-commits] specification.
Expand All @@ -59,7 +57,7 @@ components in the infrastructure layer, a maximal code coverage is expected as f
which cannot be done with unit tests due to the hard coupling with Gradle components
- Code conventions: natural language is a requirement during implementation. Authors privilege long understandable
names for classes, parameters, variables, to short fuzzy ones.
- Immutability: model classes are immutable to prevent side-effects.
- Immutability: model classes are immutable to prevent side-effects, especially in case of multi-threading.

#### Code layout

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.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-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
File renamed without changes.
28 changes: 0 additions & 28 deletions plugin/settings.gradle.kts

This file was deleted.

3 changes: 3 additions & 0 deletions plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import org.siouan.frontendgradleplugin.GradleTestListener

gradle.addListener(GradleTestListener(logger))
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void afterSuite(TestDescriptor testSuite, TestResult result) {
@Override
public void beforeTest(TestDescriptor testDescriptor) {
final String className = testDescriptor.getClassName();
logger.lifecycle("\n========== TEST {}.{} STARTED ==========", (className == null) ? "UNKNOWN TEST"
logger.info("\n========== TEST {}.{} STARTED ==========", (className == null) ? "UNKNOWN TEST"
: testDescriptor.getClassName().substring(testDescriptor.getClassName().lastIndexOf('.') + 1),
testDescriptor.getDisplayName());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.siouan.frontendgradleplugin.GradleTestListener

val fgpArtifactId: String by extra
val fgpJdkVersion: String by extra
val fgpGroup: String by extra
val fgpVersion: String by extra
val fgpDisplayName: String by extra
Expand Down Expand Up @@ -28,7 +28,7 @@ description = fgpDescription

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(fgpJdkVersion)
}
withJavadocJar()
withSourcesJar()
Expand All @@ -53,7 +53,7 @@ configurations["integrationTestRuntimeOnly"]
val mockitoAgent = configurations.create("mockitoAgent")
dependencies {
implementation(gradleApi())
implementation(libs.resilience4j.retry)
implementation(libs.resilience4j.retry.jdk11)
implementation(libs.httpclient5)
implementation(libs.commons.compress)
implementation(libs.json)
Expand Down Expand Up @@ -93,7 +93,7 @@ gradlePlugin {
vcsUrl.set(fgpVcsUrl)
plugins {
create("frontendPlugin") {
id = "$fgpGroup.$fgpArtifactId"
id = "${fgpGroup}.frontend-jdk${fgpJdkVersion}"
implementationClass = fgpImplementationClass
displayName = fgpDisplayName
description = fgpDescription
Expand All @@ -108,7 +108,7 @@ sonarqube {
property("sonar.organization", "siouan")
property("sonar.projectKey", "siouan_frontend-gradle-plugin")
property("sonar.projectName", "frontend-gradle-plugin")
property("sonar.projectVersion", "${fgpVersion}-jdk21")
property("sonar.projectVersion", "${fgpVersion}-jdk${fgpJdkVersion}")

property("sonar.links.homepage", "https://github.com/siouan/frontend-gradle-plugin")
property("sonar.links.ci", "https://github.com/siouan/frontend-gradle-plugin/actions")
Expand All @@ -132,10 +132,6 @@ sonarqube {
}
}

tasks.named<Wrapper>("wrapper") {
distributionType = Wrapper.DistributionType.ALL
}

tasks.withType<Test> {
useJUnitPlatform()
}
Expand Down Expand Up @@ -174,5 +170,3 @@ tasks.named<JacocoReport>("jacocoTestReport") {
xml.outputLocation.set(project.layout.buildDirectory.file("reports/jacoco/report.xml"))
}
}

gradle.addListener(GradleTestListener(logger))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fgpArtifactId=frontend-jdk21
fgpJdkVersion=11
fgpGroup=org.siouan
fgpVersion=10.0.0
fgpDisplayName=Frontend Gradle plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;

import static org.siouan.frontendgradleplugin.FrontendGradlePlugin.ASSEMBLE_TASK_NAME;
import static org.siouan.frontendgradleplugin.FrontendGradlePlugin.GRADLE_ASSEMBLE_TASK_NAME;
import static org.siouan.frontendgradleplugin.test.GradleBuildAssertions.assertAssembleTaskOutcomes;
import static org.siouan.frontendgradleplugin.test.GradleBuildFiles.createBuildFile;
import static org.siouan.frontendgradleplugin.test.GradleHelper.runGradle;
import static org.siouan.frontendgradleplugin.test.PluginTaskOutcome.SKIPPED;
import static org.siouan.frontendgradleplugin.test.PluginTaskOutcome.SUCCESS;
import static org.siouan.frontendgradleplugin.test.PluginTaskOutcome.UP_TO_DATE;
import static org.siouan.frontendgradleplugin.test.Resources.getResourcePath;

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

import org.gradle.testkit.runner.BuildResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.siouan.frontendgradleplugin.test.FrontendMapBuilder;

/**
* Functional tests to verify the {@link AssembleTask} integration in a Gradle build. Test cases uses fake
* Node/NPM/PNPM/Yarn distributions, to avoid the download overhead. The 'npm', 'pnpm', 'yarn' executables in these
* distributions simply call the 'node' executable with the same arguments.
*/
class AssembleFrontedTaskFuncTest {

@TempDir
Path projectDirectoryPath;

private Path packageJsonDirectoryPath;

@BeforeEach
void setUp() throws IOException {
packageJsonDirectoryPath = Files.createDirectory(projectDirectoryPath.resolve("frontend"));
}

@Test
void should_skip_task_when_package_json_file_does_not_exist() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("20.18.0")
.nodeDistributionUrl(getResourcePath("node-v20.18.0.zip"))
.assembleScript("run assemble")
.packageJsonDirectory(packageJsonDirectoryPath);
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result1, SUCCESS, SKIPPED, SUCCESS, SKIPPED, SKIPPED, SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result2, UP_TO_DATE, SKIPPED, UP_TO_DATE, SKIPPED, SKIPPED, SKIPPED, null);
}

@Test
void should_skip_task_when_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), packageJsonDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("20.18.0")
.nodeDistributionUrl(getResourcePath("node-v20.18.0.zip"))
.packageJsonDirectory(packageJsonDirectoryPath);
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result1, SUCCESS, SKIPPED, SUCCESS, SUCCESS, SUCCESS, SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result2, UP_TO_DATE, SKIPPED, UP_TO_DATE, UP_TO_DATE, SUCCESS, SKIPPED, null);
}

@Test
void should_skip_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), packageJsonDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("20.18.0")
.nodeDistributionUrl(getResourcePath("node-v20.18.0.zip"))
.packageJsonDirectory(packageJsonDirectoryPath);
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, GRADLE_ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result1, SUCCESS, SKIPPED, SUCCESS, SUCCESS, SUCCESS, SKIPPED, UP_TO_DATE);

final BuildResult result2 = runGradle(projectDirectoryPath, GRADLE_ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result2, UP_TO_DATE, SKIPPED, UP_TO_DATE, UP_TO_DATE, SUCCESS, SKIPPED, UP_TO_DATE);
}

@Test
void should_assemble_frontend() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), packageJsonDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("20.18.0")
.nodeDistributionUrl(getResourcePath("node-v20.18.0.zip"))
.packageJsonDirectory(packageJsonDirectoryPath)
.assembleScript("run assemble");
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, GRADLE_ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result1, SUCCESS, SKIPPED, SUCCESS, SUCCESS, SUCCESS, SUCCESS, SUCCESS);

final BuildResult result2 = runGradle(projectDirectoryPath, GRADLE_ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result2, UP_TO_DATE, SKIPPED, UP_TO_DATE, UP_TO_DATE, SUCCESS, SUCCESS, SUCCESS);
}
}
Loading

0 comments on commit 7ab3dbd

Please sign in to comment.