Skip to content
Open
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
104 changes: 46 additions & 58 deletions .github/workflows/build.yml
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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
.idea
!.idea/icon.png
*.iml
build
out
Expand Down
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Set<TestTag> getTags() {
static String formatWithPath(UniqueId uniqueId, String name) {
return Stream.concat(
uniqueId.getSegments().stream()
.filter(it -> it.getType().equals(ArchUnitTestDescriptor.CLASS_SEGMENT_TYPE))
.filter(it -> ArchUnitTestDescriptor.CLASS_SEGMENT_TYPE.equals(it.getType()))
.skip(1)
.map(UniqueId.Segment::getValue)
.map(Formatters::ensureSimpleName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Copy link
Author

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.

List<String> modulepath = Splitter.on(File.pathSeparatorChar).omitEmptyStrings().splitToList(modulepathProperty);
return modulepath.stream().map(Paths::get).toArray(Path[]::new);
return Splitter
Copy link
Author

Choose a reason for hiding this comment

The 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public InputStream get() {
@Internal
class FileToImport {
static boolean isRelevant(String simpleFileName) {
return simpleFileName.endsWith(".class") && !simpleFileName.equals("module-info.class");
return simpleFileName.endsWith(".class") && !"module-info.class".equals(simpleFileName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static boolean isAsmMethodHandle(Handle handle) {
}

static boolean isLambdaMetafactory(String asmObjectTypeName) {
return asmObjectTypeName.equals(LAMBDA_METAFACTORY_ASM_OBJECT_TYPE_NAME);
return LAMBDA_METAFACTORY_ASM_OBJECT_TYPE_NAME.equals(asmObjectTypeName);
}

static boolean isLambdaMethod(Handle methodHandle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static Iterable<URL> readClasspathEntriesFromManifests(List<URL> urls) {

// Use URI because of better equals / hashcode
private static void readClasspathUriEntriesFromManifests(Set<URI> result, Set<URI> uris) {
uris.stream().filter(url -> url.getScheme().equals("jar"))
uris.stream().filter(url -> "jar".equals(url.getScheme()))
.map(From::readClasspathEntriesFromManifest)
.map(manifestUris -> ImmutableSet.copyOf(difference(manifestUris, result))) // difference returns a dynamic SetView -> safe-copy
.forEach(unknownSoFar -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class WithWildcards<TEST extends List<Map<Map<?, ? extends File>, ? super Map<?
@SuppressWarnings("OptionalGetWithoutIsPresent")
private static Object[] createTestInput(Class<?> testClass) {
Type reflectionType = Arrays.stream(testClass.getTypeParameters())
.filter(v -> v.getName().equals("TEST"))
.filter(v -> "TEST".equals(v.getName()))
.map(v -> v.getBounds()[0])
.findFirst().get();
JavaType javaType = new ClassFileImporter().importClass(testClass).getTypeParameters().stream()
.filter(v -> v.getName().equals("TEST"))
.filter(v -> "TEST".equals(v.getName()))
.map(v -> v.getBounds().get(0))
.findFirst().get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private JavaClasses importJavaBase() {
// before Java 9 packages like java.lang were in rt.jar;
location.contains("rt.jar") ||
// from Java 9 on those packages were in a JRT with name 'java.base'
(location.asURI().getScheme().equals("jrt") && location.contains("java.base"))
("jrt".equals(location.asURI().getScheme()) && location.contains("java.base"))
)).importClasspath();
}

Expand All @@ -198,7 +198,7 @@ private ImportOption importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath() {
if (location.isJar() && (location.contains("junit") || location.contains("/rt.jar"))) {
return true;
}
return location.asURI().getScheme().equals("jrt") && location.contains("java.base");
return "jrt".equals(location.asURI().getScheme()) && location.contains("java.base");
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private void stringConcat() {
@SuppressWarnings("OptionalGetWithoutIsPresent")
private Set<JavaAccess<?>> importRelevantAccesses(Class<?> origin, Class<?> target) {
return new ClassFileImporter().importClasses(origin, target).get(origin).getMethods().stream()
.filter(m -> m.getName().equals("access"))
.filter(m -> "access".equals(m.getName()))
.findFirst()
.get()
.getAccessesFromSelf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static Location locationOf(Class<?> clazz) {
}

private static boolean comesFromJarArchive(Class<?> clazz) {
return LocationTest.urlOfClass(clazz).getProtocol().equals("jar");
return "jar".equals(LocationTest.urlOfClass(clazz).getProtocol());
}

private static class FolderPattern {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import static com.tngtech.archunit.core.domain.TestUtils.importClasses;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.*;
import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.DescribedRuleStart;
import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.described;
import static com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.everythingViolationPrintMemberName;
import static com.tngtech.java.junit.dataprovider.DataProviders.$;
import static com.tngtech.java.junit.dataprovider.DataProviders.$$;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Parameter get(String methodName, TypeToken<?> type) {
new SingleParameterProvider(String.class) {
@Override
protected boolean canHandle(String methodName, Class<?> type) {
return methodName.equals("respectTheirAllowedDependenciesDeclaredIn") && super.canHandle(methodName, type);
return "respectTheirAllowedDependenciesDeclaredIn".equals(methodName) && super.canHandle(methodName, type);
}

@Override
Expand All @@ -104,7 +104,7 @@ public Parameter get(String methodName, TypeToken<?> type) {

@Override
protected boolean canHandle(String methodName, Class<?> type) {
return methodName.equals("onlyDependOnEachOtherThroughPackagesDeclaredIn") && super.canHandle(methodName, type);
return "onlyDependOnEachOtherThroughPackagesDeclaredIn".equals(methodName) && super.canHandle(methodName, type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public void respectTheirAllowedDependenciesDeclaredIn_takes_allowed_dependencies
@Test
public void respectTheirAllowedDependenciesDeclaredIn_works_together_with_filtering_by_predicate() {
assertThatRule(modules().definedByAnnotation(TestModule.class)
.that(DescribedPredicate.describe("are not Module 1", it -> !it.getName().equals("Module 1")))
.and(DescribedPredicate.describe("are not Module 2", it -> !it.getName().equals("Module 2")))
.or(DescribedPredicate.describe("are Module 3", it -> it.getName().equals("Module 3")))
.that(DescribedPredicate.describe("are not Module 1", it -> !"Module 1".equals(it.getName())))
.and(DescribedPredicate.describe("are not Module 2", it -> !"Module 2".equals(it.getName())))
.or(DescribedPredicate.describe("are Module 3", it -> "Module 3".equals(it.getName())))
.should().respectTheirAllowedDependenciesDeclaredIn("allowedDependencies", consideringOnlyDependenciesBetweenModules()))
.checking(new ClassFileImporter().importPackagesOf(ClassInModule1.class, InternalClassInModule2.class, ClassInModule3.class))
.hasNoViolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public Parameter get(String methodName, TypeToken<?> type) {
|| methodName.toLowerCase().contains("declared")
|| methodName.toLowerCase().contains("type")) {
return new Parameter("some.Type", "some.Type");
} else if (methodName.equals("be") || methodName.equals("notBe")) {
} else if ("be".equals(methodName) || "notBe".equals(methodName)) {
return new Parameter("some.Type", "some.Type");
} else {
return new Parameter("string", "'string'");
Expand Down
Loading