-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add automatic conversions to violation handling (#1251)
The extensive freedom of how to create a `ConditionEvent` causes problems for any client that needs more structured results (e.g. tools). `ViolationHandler` provides a convenient API to obtain only those sort of violations that can be handled by a client (e.g. tackling dependencies). However, the type of the `correspondingObject` attached to the `ConditionEvent` can take many forms. From classes to methods, method calls, dependencies or aggregated dependencies (like module dependencies) it's hard to determine the possibilities and handle them all. Furthermore, the type of some objects (e.g. `ComponentDependency` isn't even public, so there is hardly any clean way to handle these objects. To mitigate this a little we now support transparent conversions between compatible objects. E.g. a component dependency can also be considered a set of class dependencies. `ViolationHandler` now allows to be used including these conversions that are implemented by standard ArchUnit objects where reasonable. This allows e.g. to obtain all module dependencies as `Set<Dependency>` for every violation.
- Loading branch information
Showing
36 changed files
with
731 additions
and
126 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
97 changes: 45 additions & 52 deletions
97
...egration-test/src/test/java/com/tngtech/archunit/integration/ExamplesIntegrationTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
46 changes: 46 additions & 0 deletions
46
archunit/src/main/java/com/tngtech/archunit/core/Convertible.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2014-2024 TNG Technology Consulting GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.tngtech.archunit.core; | ||
|
||
import java.util.Set; | ||
|
||
import com.tngtech.archunit.PublicAPI; | ||
import com.tngtech.archunit.core.domain.Dependency; | ||
import com.tngtech.archunit.core.domain.JavaAccess; | ||
|
||
import static com.tngtech.archunit.PublicAPI.Usage.INHERITANCE; | ||
|
||
/** | ||
* Can be implemented to express that this object might also be considered as object(s) of a different type. | ||
* E.g. {@link JavaAccess} and {@link Dependency} (compare {@link #convertTo(Class)}). | ||
*/ | ||
@PublicAPI(usage = INHERITANCE) | ||
public interface Convertible { | ||
/** | ||
* Converts this type to a set of other types. | ||
* For example a {@link JavaAccess} can also be | ||
* considered a {@link Dependency}, so <code>javaAccess.convertTo(Dependency.class)</code> | ||
* will yield a set with a single {@link Dependency} representing this access. | ||
* Or a component dependency grouping many class dependencies could be considered a set of exactly | ||
* these class dependencies. | ||
* The result will be an empty set if no conversion is possible | ||
* (e.g. calling <code>javaAccess.convertTo(Integer.class)</code>. | ||
* | ||
* @param type The type to convert to | ||
* @return A set of converted elements, empty if no conversion is possible | ||
*/ | ||
<T> Set<T> convertTo(Class<T> type); | ||
} |
Oops, something went wrong.