Skip to content

Commit

Permalink
Adjust user guide to explain the extended API
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Mar 10, 2019
1 parent e2c9b22 commit c5d089d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/userguide/008_The_Library_API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,39 @@ SlicesRuleDefinition.slices().matching("..myapp.(**)").should().notDependOnEachO
SlicesRuleDefinition.slices().matching("..myapp.(**).service..").should().notDependOnEachOther()
----

If this constraint is too rigid, e.g. in legacy applications where the package structure is rather
inconsistent, it is possible to further customize the slice creation. This can be done by specifying
a mapping of `JavaClass` to `SliceIdentifier` where classes with the same `SliceIdentifier` will
be sorted into the same slice. Consider this example:

[source,java,options="nowrap"]
----
SliceAssignment legacyPackageStructure = new SliceAssignment() {
// this will specify which classes belong together in the same slice
@Override
public SliceIdentifier getIdentifierOf(JavaClass javaClass) {
if (javaClass.getPackageName().startsWith("com.oldapp")) {
return SliceIdentifier.of("Legacy");
}
if (javaClass.getName().contains(".esb.")) {
return SliceIdentifier.of("ESB");
}
// ... further custom mappings
// if the class does not match anything, we ignore it
return SliceIdentifier.ignore();
}
// this will be part of the rule description if the test fails
@Override
public String getDescription() {
return "legacy package structure";
}
};
SlicesRuleDefinition.slices().assignedFrom(legacyPackageStructure).should().beFreeOfCycles()
----

=== General Coding Rules

The Library API also offers a small set of coding rules that might be useful in various projects.
Expand Down
34 changes: 34 additions & 0 deletions docs/userguide/html/000_Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,40 @@ <h3 id="_slices"><a class="anchor" href="#_slices"></a>8.2. Slices</h3>
SlicesRuleDefinition.slices().matching("..myapp.(**).service..").should().notDependOnEachOther()</code></pre>
</div>
</div>
<div class="paragraph">
<p>If this constraint is too rigid, e.g. in legacy applications where the package structure is rather
inconsistent, it is possible to further customize the slice creation. This can be done by specifying
a mapping of <code>JavaClass</code> to <code>SliceIdentifier</code> where classes with the same <code>SliceIdentifier</code> will
be sorted into the same slice. Consider this example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-java hljs" data-lang="java">SliceAssignment legacyPackageStructure = new SliceAssignment() {
// this will specify which classes belong together in the same slice
@Override
public SliceIdentifier getIdentifierOf(JavaClass javaClass) {
if (javaClass.getPackageName().startsWith("com.oldapp")) {
return SliceIdentifier.of("Legacy");
}
if (javaClass.getName().contains(".esb.")) {
return SliceIdentifier.of("ESB");
}
// ... further custom mappings

// if the class does not match anything, we ignore it
return SliceIdentifier.ignore();
}

// this will be part of the rule description if the test fails
@Override
public String getDescription() {
return "legacy package structure";
}
};

SlicesRuleDefinition.slices().assignedFrom(legacyPackageStructure).should().beFreeOfCycles()</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_general_coding_rules"><a class="anchor" href="#_general_coding_rules"></a>8.3. General Coding Rules</h3>
Expand Down

0 comments on commit c5d089d

Please sign in to comment.