-
Notifications
You must be signed in to change notification settings - Fork 329
Add com.tngtech.archunit.openrewrite.SanityCheck
#1562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Pankraz76
wants to merge
1
commit into
TNG:main
Choose a base branch
from
Pankraz76:spotless-fix-sanity-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,138 +1,126 @@ | ||
| name: CI | ||
|
|
||
| name: CI 🚦 | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - release-* | ||
| pull_request: | ||
|
|
||
| env: | ||
| build_java_version: 21 | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build 📦 | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| - name: Checkout 📥 | ||
| uses: actions/checkout@v6 | ||
| - name: Set up Java | ||
| - name: Setup Java ☕️ | ||
| uses: actions/setup-java@v5.1.0 | ||
| with: | ||
| distribution: 'zulu' | ||
| distribution: zulu | ||
| java-version: ${{ env.build_java_version }} | ||
| - name: Set Up Gradle | ||
| - name: Setup Gradle 🐘 | ||
| uses: gradle/actions/setup-gradle@v5 | ||
| - name: Build | ||
| - name: Spotless ✨ | ||
| run: ./gradlew spotlessCheck | ||
| - name: Sanity Check 🕊 | ||
| run: ./gradlew rewriteDryRun | ||
| - name: Build 🏗️ | ||
| run: ./gradlew build | ||
| - name: Check project files unmodified | ||
| - name: Verify No Modified Files 📋 | ||
| run: | | ||
| directoryState="$(git status --porcelain)" | ||
| directoryState="$(git.status --porcelain)" | ||
| if [ -n "$directoryState" ]; then | ||
| echo "Some files were modified during build. Please run the build locally before checking in, as it ensures some source file conventions (like copyright header)." | ||
| echo "The following files were modified:" | ||
| echo "Some files were modified during build. Please run the build locally before checking in." | ||
| echo "Modified files:" | ||
| echo "$directoryState" | ||
| exit 1 | ||
| fi | ||
|
|
||
| test: | ||
| name: Unit Tests 🧪 (${{ matrix.os }} - JDK ${{ matrix.test_java_version }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: | ||
| - ubuntu-latest | ||
| - macos-latest | ||
| - windows-latest | ||
| test_java_version: | ||
| - 8 | ||
| - 11 | ||
| - 17 | ||
| - 21 | ||
| os: [ubuntu-latest, macos-latest, windows-latest] | ||
| test_java_version: [8, 11, 17, 21] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - name: Checkout | ||
| - name: Checkout 📥 | ||
| uses: actions/checkout@v6 | ||
| - name: Set up Build JDK | ||
| - name: Setup Build JDK ☕ | ||
| uses: actions/setup-java@v5.1.0 | ||
| with: | ||
| distribution: 'zulu' | ||
| distribution: zulu | ||
| java-version: ${{ env.build_java_version }} | ||
| - name: Set up Test JDK | ||
| - name: Setup Test JDK ☕ | ||
| uses: actions/setup-java@v5.1.0 | ||
| with: | ||
| distribution: 'zulu' | ||
| distribution: zulu | ||
| java-version: ${{ matrix.test_java_version }} | ||
| - name: Provide installed JDKs | ||
| uses: actions/github-script@v8 | ||
| - name: Resolve Installed JDK Paths 🔍 | ||
| id: provideJdkPaths | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| for ( let envVarName in process.env ) { | ||
| for (let envVarName in process.env) { | ||
| if (/JAVA_HOME_\d.*64/.test(envVarName)) { | ||
| const version = envVarName.match(/JAVA_HOME_(\d+).*64/)[1]; | ||
| if (version === "${{ matrix.test_java_version }}") { | ||
| core.exportVariable('test_jdk_path', process.env[envVarName]); | ||
| core.exportVariable("test_jdk_path", process.env[envVarName]); | ||
| } else if (version === "${{ env.build_java_version }}") { | ||
| core.exportVariable('build_jdk_path', process.env[envVarName]); | ||
| core.exportVariable("build_jdk_path", process.env[envVarName]); | ||
| } | ||
| } | ||
| } | ||
| - name: Set Up Gradle | ||
| - name: Setup Gradle 🐘 | ||
| uses: gradle/actions/setup-gradle@v5 | ||
| - name: Test | ||
| - name: Run Tests 🧪 | ||
| run: ./gradlew test -PallTests -PtestJavaVersion=${{ matrix.test_java_version }} "-Porg.gradle.java.installations.paths=${{ env.test_jdk_path }}" | ||
| env: | ||
| JAVA_HOME: ${{ env.build_jdk_path }} | ||
|
|
||
| integration-test: | ||
| name: Integration Tests 🧩 (${{ matrix.os }} - JDK ${{ matrix.test_java_version }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: | ||
| - ubuntu-latest | ||
| - macos-latest | ||
| - windows-latest | ||
| test_java_version: | ||
| - 8 | ||
| - 11 | ||
| - 17 | ||
| - 21 | ||
| os: [ubuntu-latest, macos-latest, windows-latest] | ||
| test_java_version: [8, 11, 17, 21] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - name: Checkout | ||
| - name: Checkout 📥 | ||
| uses: actions/checkout@v6 | ||
| - name: Set up Build JDK | ||
| - name: Setup Build JDK ☕ | ||
| uses: actions/setup-java@v5.1.0 | ||
| with: | ||
| distribution: 'zulu' | ||
| distribution: zulu | ||
| java-version: ${{ env.build_java_version }} | ||
| - name: Set up Test JDK | ||
| - name: Setup Test JDK ☕ | ||
| uses: actions/setup-java@v5.1.0 | ||
| with: | ||
| distribution: 'zulu' | ||
| distribution: zulu | ||
| java-version: ${{ matrix.test_java_version }} | ||
| - name: Provide installed JDKs | ||
| uses: actions/github-script@v8 | ||
| - name: Resolve Installed JDK Paths 🔍 | ||
| id: provideJdkPaths | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| for ( let envVarName in process.env ) { | ||
| for (let envVarName in process.env) { | ||
| if (/JAVA_HOME_\d.*64/.test(envVarName)) { | ||
| const version = envVarName.match(/JAVA_HOME_(\d+).*64/)[1]; | ||
| if (version === "${{ matrix.test_java_version }}") { | ||
| core.exportVariable('test_jdk_path', process.env[envVarName]); | ||
| core.exportVariable("test_jdk_path", process.env[envVarName]); | ||
| } else if (version === "${{ env.build_java_version }}") { | ||
| core.exportVariable('build_jdk_path', process.env[envVarName]); | ||
| core.exportVariable("build_jdk_path", process.env[envVarName]); | ||
| } | ||
| } | ||
| } | ||
| - name: Set Up Gradle | ||
| - name: Setup Gradle 🐘 | ||
| uses: gradle/actions/setup-gradle@v5 | ||
| - name: Publish to Maven Local | ||
| - name: Publish to Maven Local 📦 | ||
| run: ./gradlew build -xtest -xspotbugsMain -xjavadoc publishToMavenLocal | ||
| env: | ||
| JAVA_HOME: ${{ env.build_jdk_path }} | ||
| - name: Integration test | ||
| - name: Run Integration Tests 🧩 | ||
| run: ./gradlew runMavenTest -PtestJavaVersion=${{ matrix.test_java_version }} "-Porg.gradle.java.installations.paths=${{ env.test_jdk_path }}" | ||
| env: | ||
| JAVA_HOME: ${{ env.build_jdk_path }} |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| .gradle | ||
| .idea | ||
| !.idea/icon.png | ||
| *.iml | ||
| build | ||
| out | ||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -15,44 +15,46 @@ | |
| */ | ||
| package com.tngtech.archunit.core.importer; | ||
|
|
||
| import java.io.File; | ||
| import com.google.common.base.Splitter; | ||
|
|
||
| import java.lang.module.ModuleFinder; | ||
| import java.lang.module.ModuleReference; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URI; | ||
| import java.net.URL; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import com.google.common.base.Splitter; | ||
|
|
||
| import static com.google.common.base.Strings.nullToEmpty; | ||
| import static com.google.common.collect.Iterables.concat; | ||
| import static com.tngtech.archunit.core.importer.UrlSource.From.iterable; | ||
| import static java.io.File.pathSeparatorChar; | ||
| import static java.lang.System.getProperty; | ||
| import static java.util.stream.Collectors.toList; | ||
|
|
||
| class ModuleLocationResolver implements LocationResolver { | ||
| private static final String JDK_MODULE_PATH = "jdk.module.path"; | ||
| private final FromClasspathAndUrlClassLoaders standardResolver = new FromClasspathAndUrlClassLoaders(); | ||
|
|
||
| @Override | ||
| public UrlSource resolveClassPath() { | ||
| Iterable<URL> classpath = standardResolver.resolveClassPath(); | ||
| Set<ModuleReference> systemModuleReferences = ModuleFinder.ofSystem().findAll(); | ||
| Set<ModuleReference> configuredModuleReferences = ModuleFinder.of(modulepath()).findAll(); | ||
| Iterable<URL> modulepath = Stream.concat(systemModuleReferences.stream(), configuredModuleReferences.stream()) | ||
| .flatMap(moduleReference -> moduleReference.location().stream()) | ||
| .map(this::toUrl) | ||
| .collect(toList()); | ||
|
|
||
| return UrlSource.From.iterable(concat(classpath, modulepath)); | ||
| return iterable(concat( | ||
| standardResolver.resolveClassPath(), | ||
| Stream.concat(ModuleFinder.ofSystem().findAll().stream(), | ||
| ModuleFinder.of(modulepath()).findAll().stream()) | ||
| .flatMap(moduleReference -> moduleReference.location().stream()) | ||
| .map(this::toUrl) | ||
| .collect(toList()))); | ||
| } | ||
|
|
||
| private Path[] modulepath() { | ||
| String modulepathProperty = nullToEmpty(System.getProperty("jdk.module.path")); | ||
| List<String> modulepath = Splitter.on(File.pathSeparatorChar).omitEmptyStrings().splitToList(modulepathProperty); | ||
| return modulepath.stream().map(Paths::get).toArray(Path[]::new); | ||
| return Splitter | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following SoC SRP the code could have 100% cohesion, instead of 100% coupling overhead. When refining the code this seems to be the final version. |
||
| .on(pathSeparatorChar) | ||
| .omitEmptyStrings() | ||
| .splitToList(nullToEmpty(getProperty(JDK_MODULE_PATH))) | ||
| .stream() | ||
| .map(Paths::get) | ||
| .toArray(Path[]::new); | ||
| } | ||
|
|
||
| private URL toUrl(URI uri) { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change was done by me as somehow here an random compile issue emerged.
This class is actually pretty nice structured having no coupling actually, all the references technically obsolete.