本文整理汇总了Java中com.google.common.graph.MutableGraph类的典型用法代码示例。如果您正苦于以下问题:Java MutableGraph类的具体用法?Java MutableGraph怎么用?Java MutableGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MutableGraph类属于com.google.common.graph包,在下文中一共展示了MutableGraph类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: depsForSingleFileComponentsInDifferentPackage
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests dependency behavior when a single file depends on a file in another package/directory.
* Behavior should not differ from when they were in the same directory.
*/
@Test
public void depsForSingleFileComponentsInDifferentPackage() {
MutableGraph<BuildRule> buildRuleGraph = newGraph();
ProjectBuildRule src =
newProjectBuildRule("/workspace/java/package/", "/workspace/java/package/Example.java");
ProjectBuildRule dst =
newProjectBuildRule("/workspace/java/other/", "/workspace/java/other/Other.java");
buildRuleGraph.putEdge(src, dst);
ImmutableList<String> actual = computeBuildozerCommands(buildRuleGraph);
assertThat(actual)
.containsExactly(
"new java_library Example|//java/package:__pkg__",
"add srcs Example.java|//java/package:Example",
"new java_library Other|//java/other:__pkg__",
"add srcs Other.java|//java/other:Other",
"add deps //java/other:Other|//java/package:Example");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:24,代码来源:BuildozerCommandCreatorTest.java
示例2: map
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Converts the class file dependency graph into the source file dependency graph, by
* consolidating classes from the same source file. Given as input:
*
* <p>ul>
* <li>a directed graph where the nodes are classes (both inner and outer) and edges are
* dependencies between said classes
* <li>a mapping between outer class files and source files.
* </ul>
*
* This function outputs a directed graph where the nodes are source files and the edges are
* dependencies between said source files.
*/
// TODO(bazel-team): Migrate this function into Guava graph library
public static ImmutableGraph<Path> map(
Graph<String> classGraph, Map<String, Path> classToSourceFileMap) {
MutableGraph<Path> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String sourceNode : classGraph.nodes()) {
if (isInnerClass(sourceNode)) {
throw new GraphProcessorException(
String.format("Found inner class %s when mapping classes to source files", sourceNode));
}
Path sourcePath = classToSourceFileMap.get(sourceNode);
graph.addNode(sourcePath);
for (String successorNode : classGraph.successors(sourceNode)) {
Path successorPath = classToSourceFileMap.get(successorNode);
if (!sourcePath.equals(successorPath)) {
graph.putEdge(sourcePath, successorPath);
}
}
}
return ImmutableGraph.copyOf(graph);
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:34,代码来源:ClassToSourceGraphConsolidator.java
示例3: trimClassGraph
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Removes all outgoing edges from classes that are not white listed. */
private static ImmutableGraph<String> trimClassGraph(
ImmutableGraph<String> classGraph, Pattern whiteList, Pattern blackList) {
MutableGraph<String> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String src : classGraph.nodes()) {
if (!whiteList.matcher(src).find() || blackList.matcher(src).find()) {
continue;
}
graph.addNode(src);
for (String dst : classGraph.successors(src)) {
if (blackList.matcher(dst).find()) {
continue;
}
graph.putEdge(src, dst);
}
}
return ImmutableGraph.copyOf(graph);
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessor.java
示例4: collapseInnerClasses
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Collapses inner classes into their top level parent class */
private static ImmutableGraph<String> collapseInnerClasses(ImmutableGraph<String> classGraph) {
MutableGraph<String> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String src : classGraph.nodes()) {
String outerSrc = getOuterClassName(src);
graph.addNode(outerSrc);
for (String dst : classGraph.successors(src)) {
String outerDst = getOuterClassName(dst);
if (outerSrc.equals(outerDst)) {
continue;
}
graph.putEdge(outerSrc, outerDst);
}
}
return ImmutableGraph.copyOf(graph);
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:17,代码来源:ClassGraphPreprocessor.java
示例5: createBuildRuleDAG
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Creates the build rule DAG using provided resolvers. Each resolver maps a top level class name
* to a build rule. We combine the resolvers to create one huge Map from class to rule.
*
* <p>We make the following stipulations. First, a class must not map to more than one build rule.
* Otherwise, we throw an error. However, a class need not map to any rule. In which case we will
* not include it in the resulting build rule Graph. Second, the resulting graph must not have
* cycles.
*
* <p>TODO(bazel-team) Report/Crash if the resulting graph has cycles.
*/
ImmutableGraph<BuildRule> createBuildRuleDAG(Iterable<ClassToRuleResolver> resolvers) {
ImmutableMap<String, BuildRule> ruleMap = createClassToRuleMap(resolvers);
MutableGraph<BuildRule> buildRuleDAG = GraphBuilder.directed().allowsSelfLoops(false).build();
for (String className : classGraph.nodes()) {
BuildRule srcRule = ruleMap.get(className);
if (srcRule == null) {
continue;
}
buildRuleDAG.addNode(srcRule);
for (String successor : classGraph.successors(className)) {
BuildRule dstRule = ruleMap.get(successor);
if (dstRule == null || srcRule.equals(dstRule)) {
continue;
}
buildRuleDAG.putEdge(srcRule, dstRule);
}
}
return ImmutableGraph.copyOf(buildRuleDAG);
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:31,代码来源:GraphProcessor.java
示例6: bijectiveClassRuleMapping
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Tests behavior of graph processor when each class is mapped to its own build rule. */
@Test
public void bijectiveClassRuleMapping() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));
String packagePath = "/java/com/";
BuildRule ruleA = newBuildRule(packagePath, "/java/com/A.java");
BuildRule ruleB = newBuildRule(packagePath, "/java/com/B.java");
BuildRule ruleC = newBuildRule(packagePath, "/java/com/C.java");
ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
when(resolver.resolve(classgraph.nodes()))
.thenReturn(ImmutableMap.of("com.A", ruleA, "com.B", ruleB, "com.C", ruleC));
Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));
MutableGraph<BuildRule> expected = GraphBuilder.directed().allowsSelfLoops(false).build();
expected.putEdge(ruleA, ruleB);
expected.putEdge(ruleB, ruleC);
assertThatGraphsEqual(actual, expected);
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:26,代码来源:GraphProcessorTest.java
示例7: manyClassesToOneRuleNoSelfLoop
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests behavior when multiple classes map to the same build rule. Ensures that the resulting
* build rule graph has no self loops.
*/
@Test
public void manyClassesToOneRuleNoSelfLoop() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));
String packagePath = "/java/com/";
BuildRule ruleA = newBuildRule(packagePath, "/java/com/A.java");
BuildRule ruleC = newBuildRule(packagePath, "/java/com/C.java");
ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
when(resolver.resolve(classgraph.nodes()))
.thenReturn(ImmutableMap.of("com.A", ruleA, "com.B", ruleA, "com.C", ruleC));
Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));
assertThat(actual.edges()).doesNotContain(EndpointPair.ordered(ruleA, ruleA));
MutableGraph<BuildRule> expected = GraphBuilder.directed().allowsSelfLoops(false).build();
expected.putEdge(ruleA, ruleC);
assertThatGraphsEqual(actual, expected);
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:28,代码来源:GraphProcessorTest.java
示例8: doesNotSupportInnerClassNames
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Ensures that given an inner class, the graph processor throws an illegal state exception. */
@Test
public void doesNotSupportInnerClassNames() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.A$InnerClass");
try {
new GraphProcessor(ImmutableGraph.copyOf(classgraph));
fail("Expected an exception, but nothing was thrown.");
} catch (IllegalStateException e) {
assertThat(e)
.hasMessageThat()
.isEqualTo(
"Argument contained inner class name com.A$InnerClass but expected no inner classes");
}
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:17,代码来源:GraphProcessorTest.java
示例9: emptyMapping
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests behavior of graph processor when no classes are mapped to build rules. The resulting DAG
* should be empty.
*/
@Test
public void emptyMapping() {
MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
classgraph.putEdge("com.C", "com.D");
GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));
ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
when(resolver.resolve(classgraph.nodes())).thenReturn(ImmutableMap.of());
Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));
assertThat(actual.nodes()).isEmpty();
assertThat(actual.edges()).isEmpty();
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:21,代码来源:GraphProcessorTest.java
示例10: filteredDAGWithUniqueTargets
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests behavior of resolver on a graph where each class is uniquely mapped to a target, AND only
* a subset of classes have been asked to be resolved. Resulting map should have each class, in
* the provided list, uniquely mapped to a build rule.
*/
@Test
public void filteredDAGWithUniqueTargets() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A", "com.B");
ProjectClassToRuleResolver resolver =
newResolver(
classgraph,
WHITELIST_DEFAULT,
ImmutableMap.of(
"com.A",
workspace.resolve("java/com/A.java"),
"com.B",
workspace.resolve("java/com/B.java")));
ImmutableMap<String, BuildRule> actual = resolver.resolve(ImmutableSet.of("com.A"));
String packagePath = "/src/java/com/";
assertThat(actual).containsExactly("com.A", buildRule(packagePath, "/src/java/com/A.java"));
assertThat(actual).doesNotContainKey("com.B");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:27,代码来源:ProjectClassToRuleResolverTest.java
示例11: graphWithOnlyOneTarget
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests behavior of resolver on a graph where all classes map to the same target. Resulting map
* should have each class map to the same build rule.
*/
@Test
public void graphWithOnlyOneTarget() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
classgraph.putEdge("com.C", "com.A");
ProjectClassToRuleResolver resolver =
newResolver(
classgraph,
WHITELIST_DEFAULT,
ImmutableMap.of(
"com.A",
workspace.resolve("java/com/A.java"),
"com.B",
workspace.resolve("java/com/B.java"),
"com.C",
workspace.resolve("java/com/C.java")));
ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
assertThat(actual).containsKey("com.A");
assertThat(actual.get("com.A")).isEqualTo(actual.get("com.B"));
assertThat(actual.get("com.B")).isEqualTo(actual.get("com.C"));
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:29,代码来源:ProjectClassToRuleResolverTest.java
示例12: graphWithInnerClass
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests behavior of resolver on a graph when an inner class is provided. Resolver should throw an
* Illegal State Exception in this event.
*/
@Test
public void graphWithInnerClass() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A$hello", "com.B");
try {
newResolver(classgraph, WHITELIST_DEFAULT, ImmutableMap.of());
fail("Expected an exception, but nothing was thrown.");
} catch (IllegalStateException e) {
assertThat(e)
.hasMessageThat()
.isEqualTo(
"Argument contained inner class name com.A$hello but expected no inner classes");
}
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:20,代码来源:ProjectClassToRuleResolverTest.java
示例13: noMatchingClassNames
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests behavior of resolver when there are no classes that match white list pattern. The
* resulting map should contain no entries.
*/
@Test
public void noMatchingClassNames() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A", "com.B");
classgraph.putEdge("com.B", "com.C");
ProjectClassToRuleResolver resolver =
newResolver(
classgraph,
Pattern.compile("com.hello.*"),
ImmutableMap.of(
"com.A",
workspace.resolve("java/com/A.java"),
"com.B",
workspace.resolve("java/com/B.java"),
"com.C",
workspace.resolve("java/com/C.java")));
ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
assertThat(actual).isEmpty();
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:26,代码来源:ProjectClassToRuleResolverTest.java
示例14: ignoresUnresolvedClass_smallerThanThreshold
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* If a class's source file cannot be found, then that class name should not be in the ensuing
* class. Since less than the default threshold are unresolved, BFG should NOT error out.
*/
@Test
public void ignoresUnresolvedClass_smallerThanThreshold() throws IOException {
MutableGraph<String> classgraph = newGraph(String.class);
classgraph.putEdge("com.A", "com.DoesNotExist");
ProjectClassToRuleResolver resolver =
newResolver(
classgraph,
WHITELIST_DEFAULT,
ImmutableMap.of("com.A", workspace.resolve("java/com/A.java")));
ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
assertThat(actual)
.containsExactly("com.A", buildRule("/src/java/com/", "/src/java/com/A.java"));
assertThat(actual).doesNotContainKey("com.DoesNotExist");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:20,代码来源:ProjectClassToRuleResolverTest.java
示例15: trimRemovesBlackListedClasses
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Tests whether the black listed class names are removed from the class graph. */
@Test
public void trimRemovesBlackListedClasses() {
MutableGraph<String> graph = newGraph();
graph.putEdge("com.BlackList", "com.WhiteList");
graph.putEdge("com.WhiteList", "com.BlackList");
Pattern blackList = Pattern.compile("BlackList");
Graph<String> actual =
preProcessClassGraph(ImmutableGraph.copyOf(graph), EVERYTHING, blackList);
MutableGraph<String> expected = newGraph();
expected.addNode("com.WhiteList");
assertEquivalent(actual, expected);
assertThat(actual.nodes()).doesNotContain("com.BlackList");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessorTest.java
示例16: trimRemovesTransitiveDependenciesToNonWhiteListedClasses
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Asserts that the only nodes in the trimmed graph are white listed classes and classes that the
* white listed classes are directly dependent on.
*/
@Test
public void trimRemovesTransitiveDependenciesToNonWhiteListedClasses() {
MutableGraph<String> graph = newGraph();
graph.putEdge("com.WhiteList", "com.OtherList");
graph.putEdge("com.OtherList", "com.TransitiveDependency");
Pattern whiteList = Pattern.compile("WhiteList");
Graph<String> actual = preProcessClassGraph(ImmutableGraph.copyOf(graph), whiteList, NOTHING);
MutableGraph<String> expected = newGraph();
expected.putEdge("com.WhiteList", "com.OtherList");
assertEquivalent(actual, expected);
assertThat(actual.nodes()).doesNotContain("com.TransitiveDependency");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:21,代码来源:ClassGraphPreprocessorTest.java
示例17: trimRemovesTransitiveDepsOfBlackListedClasses
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests whether black listed classes names as well as their non-whitelisted dependencies are
* removed from the class graph. In addition to not containing the black listed class, the
* resulting graph should also not contain nonwhite listed classes only black listed classes are
* dependent on. For example, say we were to have the following class graph
*
* <p>com.Whitelist --> com.Blacklist --> com.NonWhitelist
*
* <p>Then the resulting class graph should only contain com.Whitelist
*/
@Test
public void trimRemovesTransitiveDepsOfBlackListedClasses() {
MutableGraph<String> graph = newGraph();
graph.putEdge("com.BlackList", "com.OtherList");
graph.putEdge("com.WhiteList", "com.BlackList");
Pattern blackList = Pattern.compile("BlackList");
Pattern whiteList = Pattern.compile("WhiteList");
Graph<String> actual = preProcessClassGraph(ImmutableGraph.copyOf(graph), whiteList, blackList);
MutableGraph<String> expected = newGraph();
expected.addNode("com.WhiteList");
assertEquivalent(actual, expected);
assertThat(actual.nodes()).doesNotContain("com.BlackList");
assertThat(actual.nodes()).doesNotContain("com.OtherList");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:29,代码来源:ClassGraphPreprocessorTest.java
示例18: depsForSingleFileComponents
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests dependency behavior when a single file depends on another file. This should result in two
* build rules, one with an empty deps field and another with a dependency.
*/
@Test
public void depsForSingleFileComponents() {
MutableGraph<BuildRule> buildRuleGraph = newGraph();
String packagePath = "/workspace/java/package/";
ProjectBuildRule src = newProjectBuildRule(packagePath, "/workspace/java/package/Example.java");
ProjectBuildRule dst = newProjectBuildRule(packagePath, "/workspace/java/package/Other.java");
buildRuleGraph.putEdge(src, dst);
ImmutableList<String> actual = computeBuildozerCommands(buildRuleGraph);
assertThat(actual)
.containsExactly(
"new java_library Example|//java/package:__pkg__",
"add srcs Example.java|//java/package:Example",
"new java_library Other|//java/package:__pkg__",
"add srcs Other.java|//java/package:Other",
"add deps //java/package:Other|//java/package:Example");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:23,代码来源:BuildozerCommandCreatorTest.java
示例19: depsForExternalTargetShouldBeEmpty
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Tests dependency behavior when an external build rule (A) depends on another external build
* rule (B). There should be no add deps buildozer command for external build rule A.
*/
@Test
public void depsForExternalTargetShouldBeEmpty() {
MutableGraph<BuildRule> buildRuleGraph = newGraph();
ProjectBuildRule src =
newProjectBuildRule("/workspace/java/package/", "/workspace/java/package/Example.java");
ExternalBuildRule dstA = ExternalBuildRule.create("//java/other:Other");
ExternalBuildRule dstB = ExternalBuildRule.create("//java/something:Something");
buildRuleGraph.putEdge(src, dstA);
buildRuleGraph.putEdge(dstA, dstB);
ImmutableList<String> actual = computeBuildozerCommands(buildRuleGraph);
assertThat(actual)
.containsExactly(
"new java_library Example|//java/package:__pkg__",
"add srcs Example.java|//java/package:Example",
"add deps //java/other:Other|//java/package:Example");
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:23,代码来源:BuildozerCommandCreatorTest.java
示例20: classGraphWithOneToOneMapping
import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
* Example 1. Class Graph with a one to one mapping between class files and source files.
*
* <p>Here each class in the class graph is uniquely mapped to a source file. No source file
* contains more than one class file.
*/
@Test
public void classGraphWithOneToOneMapping() {
MutableGraph<String> graph = newGraph(String.class);
graph.putEdge("com.A", "com.B");
graph.putEdge("com.B", "com.C");
graph.putEdge("com.C", "com.A");
Map<String, Path> map =
ImmutableMap.of(
"com.A", Paths.get("A.java"),
"com.B", Paths.get("B.java"),
"com.C", Paths.get("C.java"));
Graph<Path> actual = ClassToSourceGraphConsolidator.map(graph, map);
MutableGraph<Path> expected = newGraph(Path.class);
expected.putEdge(Paths.get("A.java"), Paths.get("B.java"));
expected.putEdge(Paths.get("B.java"), Paths.get("C.java"));
expected.putEdge(Paths.get("C.java"), Paths.get("A.java"));
assertEquivalent(actual, expected);
}
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:29,代码来源:ClassToSourceGraphConsolidatorTest.java
注:本文中的com.google.common.graph.MutableGraph类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论