private Schema retainRoots(IdentifierSet identifierSet, Schema schema) { Stopwatch stopwatch = Stopwatch.createStarted(); int oldSize = countTypes(schema); Schema prunedSchema = schema.prune(identifierSet); int newSize = countTypes(prunedSchema); for (String rule : identifierSet.unusedIncludes()) { getLog().warn(String.format("Unused include: %s", rule)); } for (String rule : identifierSet.unusedExcludes()) { getLog().warn(String.format("Unused exclude: %s", rule)); } getLog().info(String.format("Pruned schema from %s types to %s types in %s", oldSize, newSize, stopwatch)); return prunedSchema; }
@Test public void trackingUnusedExcludes() throws Exception { IdentifierSet set = new IdentifierSet.Builder() .exclude("a.*") .exclude("b.ExcludedType") .exclude("c.ExcludedMember#member") .build(); assertThat(set.unusedExcludes()).containsExactly( "a.*", "b.ExcludedType", "c.ExcludedMember#member"); set.includes(ProtoType.get("a.*")); assertThat(set.unusedExcludes()).containsExactly( "b.ExcludedType", "c.ExcludedMember#member"); set.includes(ProtoType.get("b.ExcludedType")); assertThat(set.unusedExcludes()).containsExactly( "c.ExcludedMember#member"); set.includes(ProtoMember.get("c.ExcludedMember#member")); assertThat(set.unusedExcludes()).isEmpty(); }
@Test public void trackingUnusedPrecedence() throws Exception { IdentifierSet set = new IdentifierSet.Builder() .include("a.*") .exclude("a.*") .build(); set.includes(ProtoType.get("a.Message")); assertThat(set.unusedExcludes()).isEmpty(); assertThat(set.unusedIncludes()).containsExactly("a.*"); }
@Test public void trackingUnusedExcludesPrecedence() throws Exception { IdentifierSet set = new IdentifierSet.Builder() .exclude("a.*") .exclude("a.IncludedType") .build(); set.includes(ProtoMember.get("a.IncludedType#member")); assertThat(set.unusedExcludes()).containsExactly("a.IncludedType"); }