-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ls1intum/feature/github-workflow-maven
Add workflow to build package and run tests
- Loading branch information
Showing
13 changed files
with
574 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | ||
|
||
name: Java CI with Maven | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build-and-test: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '21' | ||
distribution: 'adopt' | ||
|
||
- name: Install Maven | ||
run: | | ||
sudo rm -rf /usr/bin/mvn | ||
sudo wget -q -O - "https://apache.osuosl.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz" | sudo tar xzf - -C /usr/share | ||
sudo ln -s /usr/share/apache-maven-3.9.8/bin/mvn /usr/bin/mvn | ||
- name: Build and Test with Maven | ||
run: mvn -B package --file pom.xml | ||
|
||
- name: Run Tests on Student Submission | ||
run: | | ||
git config --global url.https://github.com/.insteadOf git://github.com/ | ||
git clone https://github.com/sarpsahinalp/test-student-submission.git | ||
mkdir test-student-submission/libs | ||
cp target/*.jar test-student-submission/libs | ||
cd test-student-submission | ||
./gradlew build | ||
./gradlew test |
30 changes: 17 additions & 13 deletions
30
...n/java/de/tum/cit/ase/ares/api/architecturetest/java/postcompile/CustomClassResolver.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 |
---|---|---|
@@ -1,37 +1,41 @@ | ||
package de.tum.cit.ase.ares.api.architecturetest.java.postcompile; | ||
|
||
import com.tngtech.archunit.ArchConfiguration; | ||
import com.tngtech.archunit.core.domain.JavaClass; | ||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.resolvers.ClassResolverFromClasspath; | ||
|
||
import java.net.URL; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Custom class resolver to resolve classes that are outside classpath to be able to analyze them transitively. | ||
*/ | ||
public class CustomClassResolver { | ||
|
||
private CustomClassResolver() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
/** | ||
* Class file importer to import the class files. | ||
* This is used to import the class files from the URL. | ||
*/ | ||
private static final ClassFileImporter classFileImporter = new ClassFileImporter(); | ||
private final JavaClasses allClasses; | ||
|
||
public CustomClassResolver() { | ||
// We need to import all classes to be able to resolve them later. | ||
// TODO: We definitely need to improve this. We should not import all classes as it is not memory efficient. | ||
// https://www.javadoc.io/doc/com.tngtech.archunit/archunit/0.10.2/com/tngtech/archunit/core/importer/ClassFileImporter.html | ||
allClasses = new ClassFileImporter() | ||
.importClasspath(); | ||
} | ||
|
||
/** | ||
* Try to resolve the class by the given type name. | ||
* | ||
* @param typeName The type name of the class to resolve. | ||
* @return The resolved class if it exists. | ||
*/ | ||
public static Optional<JavaClass> tryResolve(String typeName) { | ||
ArchConfiguration.get().setClassResolver(ClassResolverFromClasspath.class); | ||
URL url = CustomClassResolver.class.getResource("/" + typeName.replace(".", "/") + ".class"); | ||
return url != null ? Optional.of(classFileImporter.importUrl(url).get(typeName)) : Optional.empty(); | ||
public Optional<JavaClass> tryResolve(String typeName) { | ||
try { | ||
// Try to resolve the class by the given type name. | ||
return Optional.ofNullable(allClasses.get(typeName)); | ||
} catch (IllegalArgumentException e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Set to false to ignore missing dependencies in the classpath, as they are resolved manually by the de.tum.cit.ase.ares.api.architecturetest.java.postcompile.CustomClassResolver | ||
resolveMissingDependenciesFromClassPath=false | ||
archRule.failOnEmptyShould=false |
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
2 changes: 0 additions & 2 deletions
2
...t/java/de/tum/cit/ase/ares/integration/testuser/subject/pathaccess/PathAccessPenguin.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
Oops, something went wrong.