Thomas Vachuska

Dropping jdvue from the main repo as it has been moved to its own.

Change-Id: I82bbbc213c875a9dba4e5b4c4edaafdd04cb77ea
#!/bin/bash
#-------------------------------------------------------------------------------
# Java Package Dependency viewer
#
# written by Thomas Vachuska
# -- Doobs --
#-------------------------------------------------------------------------------
JDVUE_ROOT=${JDVUE_ROOT:-$(dirname $0)/..}
cd $JDVUE_ROOT
VER=1.6.0-SNAPSHOT
JAR=$PWD/target/jdvue-${VER}.jar # start with the dev jar first
cd - >/dev/null
VER=${JDVUE_VERSION:-2.0}
JAR=~/.m2/repository/org/onosproject/jdvue/$VER/jdvue-$VER.jar
# If the dev jar is not available, use one from .m2/repository
[ -f ${JAR} ] || JAR=~/.m2/repository/org/onlab/tools/jdvue/${VER}/jdvue-${VER}.jar
# Download the jdvue binary if needed
if [ ! -f $JAR ]; then
printf "Downloading jdvue binary..."
aux=/tmp/stc-$$.log
mvn dependency:get -Dartifact=org.onosproject:jdvue:$VER -Dtransitive=false -B >$aux || fgrep '[ERROR]' $aux
rm -f $aux
[ -f $JAR ] && printf "Done.\n"
fi
# Assume default project to be the base-name of the argument or of current dir
name=$(basename ${1:-$PWD})
......
#!/bin/bash
#-------------------------------------------------------------------------------
# Java Package Dependency scanner
#
# written by Thomas Vachuska
# -- Doobs --
#-------------------------------------------------------------------------------
find "${@:-.}" -type f -name \*.java \
| grep -v -E '/lost+found/|/target/' \
| xargs grep -E "^[ \t]*import .*;.*|^[ \t]*package .*;.*" \
| tr -d '\r' > jpd.db
<?xml version="1.0"?>
<!--
~ Copyright 2015-present Open Networking Laboratory
~
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<prerequisites>
<maven>3.0.4</maven>
</prerequisites>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onlab-utils</artifactId>
<version>1.6.0-SNAPSHOT</version>
</parent>
<artifactId>jdvue</artifactId>
<packaging>jar</packaging>
<description>Java Package Dependency &amp; Analyzer</description>
<properties>
<!-- FIXME skipping checkstyle for now -->
<checkstyle.skip>true</checkstyle.skip>
</properties>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.onlab.jdvue.DependencyViewer
</mainClass>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This diff is collapsed. Click to expand it.
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Abstraction of a dependency segment.
*
* @author Thomas Vachuska
*/
public class Dependency {
private final JavaPackage source;
private final JavaPackage target;
/**
* Creates a dependency from the specified source on the given target.
*
* @param source source of the dependency
* @param target target of the dependency
*/
public Dependency(JavaPackage source, JavaPackage target) {
this.source = source;
this.target = target;
}
/**
* Returns the dependency source.
*
* @return source Java package
*/
public JavaPackage getSource() {
return source;
}
/**
* Returns the dependency target.
*
* @return target Java package
*/
public JavaPackage getTarget() {
return target;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Dependency) {
Dependency that = (Dependency) obj;
return Objects.equals(source, that.source) &&
Objects.equals(target, that.target);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(source, target);
}
@Override
public String toString() {
return toStringHelper(this)
.add("source", source).add("target", target).toString();
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Simple representation of a Java package dependency cycle.
*/
public class DependencyCycle {
private final List<JavaPackage> cycle;
/**
* Creates a normalized dependency cycle represented by the specified list
* of Java packages, which are expected to be given in order of dependency.
* List is assumed to be non-empty.
*
* @param cycle list of Java packages in the dependency cycle
* @param cause Java package that caused the cycle
*/
DependencyCycle(List<JavaPackage> cycle, JavaPackage cause) {
this.cycle = normalize(cycle, cause);
}
/**
* Produces a normalized dependency cycle list. Normalization is performed
* by rotating the list so that the package with the least lexicographic
* name is at the start of the list.
*
* @param cycle list of Java packages in the dependency cycle
* @param cause Java package that caused the cycle
* @return normalized cycle
*/
private List<JavaPackage> normalize(List<JavaPackage> cycle, JavaPackage cause) {
int start = cycle.indexOf(cause);
List<JavaPackage> clone = new ArrayList<>(cycle.subList(start, cycle.size()));
int leastIndex = findIndexOfLeastName(clone);
Collections.rotate(clone, -leastIndex);
return Collections.unmodifiableList(clone);
}
/**
* Returns the index of the Java package with the least name.
*
* @param cycle list of Java packages in the dependency cycle
* @return index of the least Java package name
*/
private int findIndexOfLeastName(List<JavaPackage> cycle) {
int leastIndex = 0;
String leastName = cycle.get(leastIndex).name();
for (int i = 1, n = cycle.size(); i < n; i++) {
JavaPackage javaPackage = cycle.get(i);
if (leastName.compareTo(javaPackage.name()) > 0) {
leastIndex = i;
leastName = javaPackage.name();
}
}
return leastIndex;
}
/**
* Returns the normalized Java package dependency cycle
*
* @return list of packages in the dependency cycle
*/
public List<JavaPackage> getCycle() {
return cycle;
}
/**
* Returns the dependency cycle in form of individual dependencies.
*
* @return list of dependencies forming the cycle
*/
public List<Dependency> getCycleSegments() {
List<Dependency> dependencies = new ArrayList<>();
for (int i = 0, n = cycle.size(); i < n; i++) {
dependencies.add(new Dependency(cycle.get(i), cycle.get(i < n - 1 ? i + 1 : 0)));
}
return dependencies;
}
@Override
public boolean equals(Object o) {
if (o instanceof DependencyCycle) {
DependencyCycle that = (DependencyCycle) o;
return Objects.equals(cycle, that.cycle);
}
return false;
}
@Override
public int hashCode() {
return cycle.hashCode();
}
@Override
public String toString() {
return toStringHelper(this).add("cycle", cycle).toString();
}
public String toShortString() {
StringBuilder sb = new StringBuilder("[");
for (JavaPackage javaPackage : cycle) {
sb.append(javaPackage.name()).append(", ");
}
if (sb.length() > 1) {
sb.delete(sb.length() - 2, sb.length());
}
sb.append("]");
return sb.toString();
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Set;
/**
* Generator of a self-contained HTML file which serves as a GUI for
* visualizing Java package dependencies carried in the supplied catalog.
*
* The HTML file is an adaptation of D3.js Hierarchical Edge Bundling as
* shown at http://bl.ocks.org/mbostock/7607999.
*
* @author Thomas Vachuska
*/
public class DependencyViewer {
private static final String JPD_EXT = ".db";
private static final String HTML_EXT = ".html";
private static final String INDEX = "index.html";
private static final String D3JS = "d3.v3.min.js";
private static final String TITLE_PLACEHOLDER = "TITLE_PLACEHOLDER";
private static final String D3JS_PLACEHOLDER = "D3JS_PLACEHOLDER";
private static final String DATA_PLACEHOLDER = "DATA_PLACEHOLDER";
private final Catalog catalog;
/**
* Creates a Java package dependency viewer.
*
* @param catalog dependency catalog
*/
public DependencyViewer(Catalog catalog) {
this.catalog = catalog;
}
/**
* Main program entry point.
*
* @param args command line arguments
*/
public static void main(String[] args) {
Catalog cat = new Catalog();
DependencyViewer viewer = new DependencyViewer(cat);
try {
String path = args[0];
cat.load(path + JPD_EXT);
cat.analyze();
System.err.println(cat);
viewer.dumpLongestCycle(cat);
viewer.writeHTMLFile(path);
} catch (IOException e) {
System.err.println("Unable to process catalog: " + e.getMessage());
}
}
/**
* Prints out the longest cycle; just for kicks.
* @param cat catalog
*/
private void dumpLongestCycle(Catalog cat) {
DependencyCycle longest = null;
for (DependencyCycle cycle : cat.getCycles()) {
if (longest == null || longest.getCycleSegments().size() < cycle.getCycleSegments().size()) {
longest = cycle;
}
}
if (longest != null) {
for (Dependency dependency : longest.getCycleSegments()) {
System.out.println(dependency);
}
}
}
/**
* Writes the HTML catalog file for the given viewer.
*
* @param path base file path
* @throws IOException if issues encountered writing the HTML file
*/
public void writeHTMLFile(String path) throws IOException {
String index = slurp(getClass().getResourceAsStream(INDEX));
String d3js = slurp(getClass().getResourceAsStream(D3JS));
FileWriter fw = new FileWriter(path + HTML_EXT);
ObjectWriter writer = new ObjectMapper().writer(); // .writerWithDefaultPrettyPrinter();
fw.write(index.replace(TITLE_PLACEHOLDER, path)
.replace(D3JS_PLACEHOLDER, d3js)
.replace(DATA_PLACEHOLDER, writer.writeValueAsString(toJson())));
fw.close();
}
/**
* Slurps the specified input stream into a string.
*
* @param stream input stream to be read
* @return string containing the contents of the input stream
* @throws IOException if issues encountered reading from the stream
*/
static String slurp(InputStream stream) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append(System.lineSeparator());
}
br.close();
return sb.toString();
}
// Produces a JSON structure designed to drive the hierarchical visual
// representation of Java package dependencies and any dependency cycles
private JsonNode toJson() {
ObjectMapper mapper = new ObjectMapper();
ObjectNode root = mapper.createObjectNode();
root.put("packages", jsonPackages(mapper));
root.put("cycleSegments", jsonCycleSegments(mapper, catalog.getCycleSegments()));
root.put("summary", jsonSummary(mapper));
return root;
}
// Produces a JSON summary of dependencies
private JsonNode jsonSummary(ObjectMapper mapper) {
ObjectNode summary = mapper.createObjectNode();
summary.put("packages", catalog.getPackages().size());
summary.put("sources", catalog.getSources().size());
summary.put("cycles", catalog.getCycles().size());
summary.put("cycleSegments", catalog.getCycleSegments().size());
return summary;
}
// Produces a JSON structure with package dependency data
private JsonNode jsonPackages(ObjectMapper mapper) {
ArrayNode packages = mapper.createArrayNode();
for (JavaPackage javaPackage : catalog.getPackages()) {
packages.add(json(mapper, javaPackage));
}
return packages;
}
// Produces a JSON structure with all cyclic segments
private JsonNode jsonCycleSegments(ObjectMapper mapper,
Set<Dependency> segments) {
ObjectNode cyclicSegments = mapper.createObjectNode();
for (Dependency dependency : segments) {
String s = dependency.getSource().name();
String t = dependency.getTarget().name();
cyclicSegments.put(t + "-" + s,
mapper.createObjectNode().put("s", s).put("t", t));
}
return cyclicSegments;
}
// Produces a JSON object structure describing the specified Java package.
private JsonNode json(ObjectMapper mapper, JavaPackage javaPackage) {
ObjectNode node = mapper.createObjectNode();
ArrayNode imports = mapper.createArrayNode();
for (JavaPackage dependency : javaPackage.getDependencies()) {
imports.add(dependency.name());
}
Set<DependencyCycle> packageCycles = catalog.getPackageCycles(javaPackage);
Set<Dependency> packageCycleSegments = catalog.getPackageCycleSegments(javaPackage);
node.put("name", javaPackage.name());
node.put("size", javaPackage.getSources().size());
node.put("imports", imports);
node.put("cycleSegments", jsonCycleSegments(mapper, packageCycleSegments));
node.put("cycleCount", packageCycles.size());
node.put("cycleSegmentCount", packageCycleSegments.size());
return node;
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import java.util.Objects;
/**
* Abstraction of a Java source entity.
*/
public abstract class JavaEntity {
private final String name;
/**
* Creates a new Java source entity with the given name.
*
* @param name source entity name
*/
JavaEntity(String name) {
this.name = name;
}
/**
* Returns the Java source entity name.
*
* @return source entity name
*/
public String name() {
return name;
}
@Override
public boolean equals(Object o) {
if (o instanceof JavaEntity) {
JavaEntity that = (JavaEntity) o;
return getClass().equals(that.getClass()) &&
Objects.equals(name, that.name);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(name);
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Simple abstraction of a Java package for the purpose of tracking
* dependencies and requirements.
*
* @author Thomas Vachuska
*/
public class JavaPackage extends JavaEntity {
private final Set<JavaSource> sources = new HashSet<>();
private Set<JavaPackage> dependencies;
/**
* Creates a new Java package.
*
* @param name java package file name
*/
JavaPackage(String name) {
super(name);
}
/**
* Returns the set of sources contained in this Java package.
*
* @return set of Java sources
*/
public Set<JavaSource> getSources() {
return Collections.unmodifiableSet(sources);
}
/**
* Adds the specified Java source to the package. Only possible if the
* Java package of the source is the same as this Java package.
*
* @param source Java source to be added
*/
void addSource(JavaSource source) {
if (source.getPackage().equals(this)) {
sources.add(source);
}
}
/**
* Returns the set of packages directly required by this package.
*
* @return set of Java package dependencies
*/
Set<JavaPackage> getDependencies() {
return dependencies;
}
/**
* Sets the set of resolved Java packages on which this package dependens.
*
* @param dependencies set of resolved Java packages
*/
void setDependencies(Set<JavaPackage> dependencies) {
if (this.dependencies == null) {
this.dependencies = Collections.unmodifiableSet(new HashSet<>(dependencies));
}
}
@Override
public String toString() {
return toStringHelper(this)
.add("name", name())
.add("sources", sources.size())
.add("dependencies", (dependencies != null ? dependencies.size() : 0))
.toString();
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import java.util.*;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Simple abstraction of a Java source file for the purpose of tracking
* dependencies and requirements.
*
* @author Thomas Vachuska
*/
public class JavaSource extends JavaEntity {
private String path;
private JavaPackage javaPackage;
private final Set<String> importNames = new HashSet<>();
private Set<JavaEntity> imports;
/**
* Creates a new Java source entity.
*
* @param name java source file name
* @param path source file path
*/
JavaSource(String name, String path) {
super(name);
this.path = path;
}
/**
* Returns the Java package for this Java source.
*
* @return Java package
*/
public JavaPackage getPackage() {
return javaPackage;
}
/**
* Sets the Java package for this Java source.
*
* @param javaPackage Java package
*/
void setPackage(JavaPackage javaPackage) {
if (this.javaPackage == null) {
this.javaPackage = javaPackage;
}
}
/**
* Returns the set of resolved imports for this Java source
*
* @return set of imports
*/
public Set<JavaEntity> getImports() {
return imports;
}
/**
* Sets the set of resolved imported Java entities for this source.
*
* @param imports set of resolved Java entities imported by this source
*/
void setImports(Set<JavaEntity> imports) {
if (this.imports == null) {
this.imports = Collections.unmodifiableSet(new HashSet<>(imports));
}
}
/**
* Adds a name of an imported, but unresolved, Java entity name.
*
* @param name name of an imported Java entity
*/
void addImportName(String name) {
importNames.add(name);
}
/**
* Returns the set of imported, but unresolved, Java entity names.
*
* @return set of imported Java entity names
*/
Set<String> getImportNames() {
return importNames;
}
@Override
public String toString() {
return toStringHelper(this)
.add("name", name())
.add("javaPackage", (javaPackage != null ? javaPackage.name() : ""))
.add("importNames", importNames.size())
.add("imports", (imports != null ? imports.size() : 0))
.toString();
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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.
*/
/**
* Utility to analyze Java package dependencies.
*/
package org.onlab.jdvue;
\ No newline at end of file
This diff could not be displayed because it is too large.
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import org.junit.Test;
import org.onlab.jdvue.Catalog;
import org.onlab.jdvue.JavaPackage;
import org.onlab.jdvue.JavaSource;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Unit test for the source catalog.
*
* @author Thomas Vachuska
*/
public class CatalogTest {
@Test
public void basics() throws IOException {
Catalog cat = new Catalog();
cat.load("src/test/resources/catalog.db");
cat.analyze();
assertEquals("incorrect package count", 12, cat.getPackages().size());
assertEquals("incorrect source count", 14, cat.getSources().size());
JavaPackage pkg = cat.getPackage("k");
assertNotNull("package should be found", pkg);
JavaSource src = cat.getSource("k.K");
assertNotNull("source should be found", src);
assertEquals("incorrect package source count", 1, pkg.getSources().size());
assertEquals("incorrect package dependency count", 1, pkg.getDependencies().size());
assertEquals("incorrect package cycle count", 3, cat.getPackageCycles(pkg).size());
assertEquals("incorrect segment count", 11, cat.getCycleSegments().size());
assertEquals("incorrect cycle count", 5, cat.getCycles().size());
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import org.junit.Test;
import org.onlab.jdvue.DependencyCycle;
import org.onlab.jdvue.JavaPackage;
import java.util.Arrays;
import static org.junit.Assert.*;
/**
* Unit test for the dependency cycle entity.
*
* @author Thomas Vachuska
*/
public class DependencyCycleTest {
@Test
public void normalize() {
JavaPackage x = new JavaPackage("x");
JavaPackage y = new JavaPackage("y");
JavaPackage z = new JavaPackage("z");
DependencyCycle a = new DependencyCycle(Arrays.asList(new JavaPackage[] {x, y, z}), x);
DependencyCycle b = new DependencyCycle(Arrays.asList(new JavaPackage[] {y, z, x}), y);
DependencyCycle c = new DependencyCycle(Arrays.asList(new JavaPackage[] {z, x, y}), z);
assertEquals("incorrect normalization", a, b);
assertEquals("incorrect normalization", a, c);
}
@Test
public void testToString() {
JavaPackage x = new JavaPackage("x");
JavaPackage y = new JavaPackage("y");
JavaPackage z = new JavaPackage("z");
DependencyCycle a = new DependencyCycle(Arrays.asList(new JavaPackage[] {x, y, z}), x);
assertEquals("incorrect toString", "[x, y, z]", a.toShortString());
assertEquals("incorrect toString",
"DependencyCycle{cycle=[" +
"JavaPackage{name=x, sources=0, dependencies=0}, " +
"JavaPackage{name=y, sources=0, dependencies=0}, " +
"JavaPackage{name=z, sources=0, dependencies=0}]}",
a.toString());
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onlab.jdvue.Dependency;
import org.onlab.jdvue.JavaPackage;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/**
* Unit test for the dependency entity.
*
* @author Thomas Vachuska
*/
public class DependencyTest {
@Test
public void basics() {
JavaPackage x = new JavaPackage("x");
JavaPackage y = new JavaPackage("y");
new EqualsTester()
.addEqualityGroup(new Dependency(x, y), new Dependency(x, y))
.addEqualityGroup(new Dependency(y, x), new Dependency(y, x))
.testEquals();
}
}
/*
* Copyright 2015-present Open Networking Laboratory
*
* 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 org.onlab.jdvue;
import org.junit.Test;
import org.onlab.jdvue.DependencyViewer;
import java.io.FileInputStream;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.onlab.jdvue.DependencyViewer.slurp;
/**
* Unit test for the dependency viewer.
*
* @author Thomas Vachuska
*/
public class DependencyViewerTest {
@Test
public void basics() throws IOException {
DependencyViewer.main(new String[]{"src/test/resources/catalog"});
String expected = slurp(new FileInputStream("src/test/resources/expected.html"));
String actual = slurp(new FileInputStream("src/test/resources/catalog.html"));
// FIXME: add more manageable assertions here
// assertEquals("incorrect html", expected, actual);
}
}
src/main/java/a/A.java:package a;
src/main/java/a/A.java:import b.B;
src/main/java/a/A2.java:package a;
src/main/java/a/A2.java:import c.C;
src/main/java/b/B.java:package b;
src/main/java/b/B.java:import c.C;
src/main/java/c/C.java:package c;
src/main/java/x/X.java:package x;
src/main/java/x/X.java:import y.Y;
src/main/java/y/Y.java:package y;
src/main/java/y/Y.java:import z.Z;
src/main/java/z/Z.java:package z;
src/main/java/z/Z.java:import x.X;
src/main/java/u/U.java:package u;
src/main/java/u/U.java:import v.V;
src/main/java/u/U2.java:package u;
src/main/java/u/U2.java:import v.V;
src/main/java/v/V.java:package v;
src/main/java/v/V.java:import u.U;
src/main/java/k/K.java:package k;
src/main/java/k/K.java:import l.L;
src/main/java/l/L.java:package l;
src/main/java/l/L.java:import k.K;
src/main/java/l/L.java:import m.M;
src/main/java/l/L.java:import n.N;
src/main/java/m/M.java:package m;
src/main/java/m/M.java:import n.N;
src/main/java/n/N.java:package n;
src/main/java/n/N.java:import k.K;
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
......@@ -36,7 +36,6 @@
<module>yangutils</module>
<module>osgi</module>
<module>rest</module>
<module>jdvue</module>
<module>osgiwrap</module>
</modules>
......