-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some tweaks to support a Spring Modulith style approach, where packag…
…es are considered to be components.
- Loading branch information
1 parent
4bab88f
commit 3db0c02
Showing
17 changed files
with
132 additions
and
15 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
25 changes: 25 additions & 0 deletions
25
...omponent/src/main/java/com/structurizr/component/naming/DefaultPackageNamingStrategy.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,25 @@ | ||
package com.structurizr.component.naming; | ||
|
||
import com.structurizr.component.Type; | ||
|
||
/** | ||
* Uses Apache commons-lang to split a camel-cased package name into separate words | ||
* (e.g. "com.example.order.package-info" -> "Order"). | ||
*/ | ||
public class DefaultPackageNamingStrategy implements NamingStrategy { | ||
|
||
@Override | ||
public String nameOf(Type type) { | ||
String packageName = type.getPackageName(); | ||
if (packageName.contains(".")) { | ||
packageName = packageName.substring(packageName.lastIndexOf(".") + 1); | ||
} | ||
|
||
String[] parts = org.apache.commons.lang3.StringUtils.splitByCharacterTypeCamelCase(packageName); | ||
String name = String.join(" ", parts); | ||
name = name.substring(0, 1).toUpperCase() + name.substring(1); | ||
|
||
return name; | ||
} | ||
|
||
} |
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
5 changes: 3 additions & 2 deletions
5
...InSamePackageSupportingTypesStrategy.java → ...ypesInPackageSupportingTypesStrategy.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
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
23 changes: 23 additions & 0 deletions
23
...n/java/com/structurizr/component/supporting/AllTypesInPackageSupportingTypesStrategy.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,23 @@ | ||
package com.structurizr.component.supporting; | ||
|
||
import com.structurizr.component.Type; | ||
import com.structurizr.component.TypeRepository; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* A strategy that finds all referenced types in the same package as the component type. | ||
*/ | ||
public class AllTypesInPackageSupportingTypesStrategy implements SupportingTypesStrategy { | ||
|
||
@Override | ||
public Set<Type> findSupportingTypes(Type type, TypeRepository typeRepository) { | ||
String packageName = type.getPackageName(); | ||
|
||
return typeRepository.getTypes().stream() | ||
.filter(dependency -> dependency.getPackageName().equals(packageName)) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ava/com/structurizr/component/supporting/AllTypesUnderPackageSupportingTypesStrategy.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,23 @@ | ||
package com.structurizr.component.supporting; | ||
|
||
import com.structurizr.component.Type; | ||
import com.structurizr.component.TypeRepository; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* A strategy that finds all referenced types in the same package as the component type. | ||
*/ | ||
public class AllTypesUnderPackageSupportingTypesStrategy implements SupportingTypesStrategy { | ||
|
||
@Override | ||
public Set<Type> findSupportingTypes(Type type, TypeRepository typeRepository) { | ||
String packageName = type.getPackageName(); | ||
|
||
return typeRepository.getTypes().stream() | ||
.filter(dependency -> dependency.getPackageName().startsWith(packageName)) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
} |
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
15 changes: 15 additions & 0 deletions
15
...ent/src/test/java/com/structurizr/component/naming/DefaultPackageNamingStrategyTests.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,15 @@ | ||
package com.structurizr.component.naming; | ||
|
||
import com.structurizr.component.Type; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DefaultPackageNamingStrategyTests { | ||
|
||
@Test | ||
void nameOf() { | ||
assertEquals("Order Management", new DefaultPackageNamingStrategy().nameOf(new Type("com.example.orderManagement.package-info"))); | ||
} | ||
|
||
} |
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