Skip to content

Commit

Permalink
added archunit tests for no xbase/xtend/guava dep
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
  • Loading branch information
cdietrich committed Feb 22, 2023
1 parent da7e96a commit fcf9674
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ ext.versions = [
'gson_orbit': '2.10.1.v20230109-0753',
'websocket_jakarta': '2.0.0',
'websocket': '1.0',
'junit': '4.13.2'
'junit': '4.13.2',
'archunit': '1.0.1'
]
1 change: 1 addition & 0 deletions org.eclipse.lsp4j.debug/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
testImplementation "junit:junit:$versions.junit"
testImplementation "org.eclipse.xtend:org.eclipse.xtend.lib:$versions.xtend_lib"
testImplementation project(":org.eclipse.lsp4j.generator")
testImplementation "com.tngtech.archunit:archunit:$versions.archunit"
}

jar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.eclipse.lsp4j.debug.test;

import static com.tngtech.archunit.core.domain.JavaClass.Predicates.resideInAPackage;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.base.DescribedPredicate.not;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;

/**
* Test to make sure we don't depend to xbase.lib, xtend.lib and guava at
* runtime
*
* @author Christian Dietrich
*/
public class Lsp4jDebugArchitectureTest {

private static JavaClasses importedClasses;

@BeforeClass
public static void scan() {
importedClasses = new ClassFileImporter().importPackages("org.eclipse.lsp4j.debug");
}

@AfterClass
public static void cleanup() {
importedClasses = null;
}

@Test
public void testNoDependenyToXbaseLib() {
assertNoDependencyToPackage("org.eclipse.xtext..");
}

@Test
public void testNoDependenyToXtendLib() {
assertNoDependencyToPackage("org.eclipse.xtend..");
}

@Test
public void testNoDependenyToXtend2Lib() {
assertNoDependencyToPackage("org.eclipse.xtend2..");
}

@Test
public void testNoDependenyToGuava() {
assertNoDependencyToPackage("com.google.common..");
}

@Test
public void testNoDependenyToGenerator() {
assertNoDependencyToPackage("org.eclipse.lsp4j.generator..");
}

private void assertNoDependencyToPackage(String badPackage) {
ArchRule rule = noClasses()
.that(resideInAPackage("org.eclipse.lsp4j.debug..")
.and(not(resideInAPackage("org.eclipse.lsp4j.generator.."))))
.and(not(resideInAPackage("org.eclipse.lsp4j.debug.test.."))).should().dependOnClassesThat()
.resideInAPackage(badPackage);
rule.check(importedClasses);
}

}
1 change: 1 addition & 0 deletions org.eclipse.lsp4j/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
api project(":org.eclipse.lsp4j.jsonrpc")
testImplementation "junit:junit:$versions.junit"
testImplementation project(":org.eclipse.lsp4j.generator")
testImplementation "com.tngtech.archunit:archunit:$versions.archunit"
}

jar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/******************************************************************************
* Copyright (c) 2023 itemis AG and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
******************************************************************************/
package org.eclipse.lsp4j.test;

import static com.tngtech.archunit.core.domain.JavaClass.Predicates.resideInAPackage;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.base.DescribedPredicate.not;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;

/**
* Test to make sure we don't depend to xbase.lib, xtend.lib and guava at
* runtime
*
* @author Christian Dietrich
*/
public class Lsp4jArchitectureTest {

private static JavaClasses importedClasses;

@BeforeClass
public static void scan() {
importedClasses = new ClassFileImporter().importPackages("org.eclipse.lsp4j");
}

@AfterClass
public static void cleanup() {
importedClasses = null;
}

@Test
public void testNoDependenyToXbaseLib() {
assertNoDependencyToPackage("org.eclipse.xtext..");
}

@Test
public void testNoDependenyToXtendLib() {
assertNoDependencyToPackage("org.eclipse.xtend..");
}

@Test
public void testNoDependenyToXtend2Lib() {
assertNoDependencyToPackage("org.eclipse.xtend2..");
}

@Test
public void testNoDependenyToGuava() {
assertNoDependencyToPackage("com.google.common..");
}

@Test
public void testNoDependenyToGenerator() {
assertNoDependencyToPackage("org.eclipse.lsp4j.generator..");
}

private void assertNoDependencyToPackage(String badPackage) {
ArchRule rule = noClasses()
.that(resideInAPackage("org.eclipse.lsp4j..")
.and(not(resideInAPackage("org.eclipse.lsp4j.generator.."))))
.and(not(resideInAPackage("org.eclipse.lsp4j.test.."))).should().dependOnClassesThat()
.resideInAPackage(badPackage);
rule.check(importedClasses);
}

}

0 comments on commit fcf9674

Please sign in to comment.