-
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.
Makes Slices more customizable. Background: In legacy applications th…
…e package structure might not be as neat as myapp.(*) where * catches all reasonable domain slices. Instead it might be necessary to really tweak which classes from which locations form a 'slice'. The new approach allows to freely define a mapping JavaClass -> SliceIdentifier to group arbitrary classes together into one slice (defined by the common SliceIdentifier). Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
- Loading branch information
1 parent
ee43a5e
commit e2c9b22
Showing
11 changed files
with
501 additions
and
79 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
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
35 changes: 35 additions & 0 deletions
35
archunit/src/main/java/com/tngtech/archunit/library/dependencies/SliceAssignment.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,35 @@ | ||
/* | ||
* Copyright 2019 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.library.dependencies; | ||
|
||
import com.tngtech.archunit.PublicAPI; | ||
import com.tngtech.archunit.base.HasDescription; | ||
import com.tngtech.archunit.core.domain.JavaClass; | ||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
|
||
import static com.tngtech.archunit.PublicAPI.Usage.INHERITANCE; | ||
|
||
/** | ||
* A mapping {@link JavaClass} -> {@link SliceIdentifier} which defines how to partition | ||
* a set of {@link JavaClasses} into {@link Slices}. All classes that are mapped to the same | ||
* {@link SliceIdentifier} will belong to the same {@link Slice}.<br> | ||
* A {@link SliceAssignment} must provide a description to be used for the rule text of a rule | ||
* formed via {@link SlicesRuleDefinition}. | ||
*/ | ||
@PublicAPI(usage = INHERITANCE) | ||
public interface SliceAssignment extends HasDescription { | ||
SliceIdentifier getIdentifierOf(JavaClass javaClass); | ||
} |
90 changes: 90 additions & 0 deletions
90
archunit/src/main/java/com/tngtech/archunit/library/dependencies/SliceIdentifier.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,90 @@ | ||
/* | ||
* Copyright 2019 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.library.dependencies; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.tngtech.archunit.PublicAPI; | ||
import com.tngtech.archunit.core.domain.JavaClass; | ||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static com.tngtech.archunit.PublicAPI.Usage.ACCESS; | ||
|
||
/** | ||
* An unique identifier of a {@link Slice}. All {@link JavaClasses} that are assigned to the same | ||
* {@link SliceIdentifier} are considered to belong to the same {@link Slice}.<br> | ||
* A {@link SliceIdentifier} consists of textual parts. Two {@link SliceIdentifier} are considered to | ||
* be equal if and only if their parts are equal. The parts can also be referred to from | ||
* {@link Slices#namingSlices(String)} via '{@code $x}' where '{@code x}' is the number of the part. | ||
*/ | ||
public final class SliceIdentifier { | ||
private final List<String> parts; | ||
|
||
private SliceIdentifier(List<String> parts) { | ||
this.parts = ImmutableList.copyOf(parts); | ||
} | ||
|
||
List<String> getParts() { | ||
return parts; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(parts); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final SliceIdentifier other = (SliceIdentifier) obj; | ||
return Objects.equals(this.parts, other.parts); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + parts; | ||
} | ||
|
||
@PublicAPI(usage = ACCESS) | ||
public static SliceIdentifier of(String... parts) { | ||
return of(ImmutableList.copyOf(parts)); | ||
} | ||
|
||
@PublicAPI(usage = ACCESS) | ||
public static SliceIdentifier of(List<String> parts) { | ||
checkNotNull(parts, "Supplied parts may not be null"); | ||
checkArgument(!parts.isEmpty(), | ||
"Parts of a %s must not be empty. Use %s.ignore() to ignore a %s", | ||
SliceIdentifier.class.getSimpleName(), SliceIdentifier.class.getSimpleName(), JavaClass.class.getSimpleName()); | ||
|
||
return new SliceIdentifier(parts); | ||
} | ||
|
||
@PublicAPI(usage = ACCESS) | ||
public static SliceIdentifier ignore() { | ||
return new SliceIdentifier(Collections.<String>emptyList()); | ||
} | ||
} |
Oops, something went wrong.