Thomas Vachuska
Committed by Gerrit Code Review

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

Change-Id: I82bbbc213c875a9dba4e5b4c4edaafdd04cb77ea
1 #!/bin/bash 1 #!/bin/bash
2 #------------------------------------------------------------------------------- 2 #-------------------------------------------------------------------------------
3 # Java Package Dependency viewer 3 # Java Package Dependency viewer
4 -#
5 -# written by Thomas Vachuska
6 -# -- Doobs --
7 #------------------------------------------------------------------------------- 4 #-------------------------------------------------------------------------------
8 5
9 -JDVUE_ROOT=${JDVUE_ROOT:-$(dirname $0)/..} 6 +VER=${JDVUE_VERSION:-2.0}
10 -cd $JDVUE_ROOT 7 +JAR=~/.m2/repository/org/onosproject/jdvue/$VER/jdvue-$VER.jar
11 -VER=1.7.0-SNAPSHOT
12 -JAR=$PWD/target/jdvue-${VER}.jar # start with the dev jar first
13 -cd - >/dev/null
14 8
15 -# If the dev jar is not available, use one from .m2/repository 9 +# Download the jdvue binary if needed
16 -[ -f ${JAR} ] || JAR=~/.m2/repository/org/onlab/tools/jdvue/${VER}/jdvue-${VER}.jar 10 +if [ ! -f $JAR ]; then
11 + printf "Downloading jdvue binary..."
12 + aux=/tmp/stc-$$.log
13 + mvn dependency:get -Dartifact=org.onosproject:jdvue:$VER -Dtransitive=false -B >$aux || fgrep '[ERROR]' $aux
14 + rm -f $aux
15 + [ -f $JAR ] && printf "Done.\n"
16 +fi
17 17
18 # Assume default project to be the base-name of the argument or of current dir 18 # Assume default project to be the base-name of the argument or of current dir
19 name=$(basename ${1:-$PWD}) 19 name=$(basename ${1:-$PWD})
......
1 -#!/bin/bash
2 -#-------------------------------------------------------------------------------
3 -# Java Package Dependency scanner
4 -#
5 -# written by Thomas Vachuska
6 -# -- Doobs --
7 -#-------------------------------------------------------------------------------
8 -
9 -find "${@:-.}" -type f -name \*.java \
10 - | grep -v -E '/lost+found/|/target/' \
11 - | xargs grep -E "^[ \t]*import .*;.*|^[ \t]*package .*;.*" \
12 - | tr -d '\r' > jpd.db
1 -<?xml version="1.0"?>
2 -<!--
3 - ~ Copyright 2015-present Open Networking Laboratory
4 - ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at
8 - ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~
11 - ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License.
16 - -->
17 -<project xmlns="http://maven.apache.org/POM/4.0.0"
18 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20 - <modelVersion>4.0.0</modelVersion>
21 - <prerequisites>
22 - <maven>3.0.4</maven>
23 - </prerequisites>
24 -
25 - <parent>
26 - <groupId>org.onosproject</groupId>
27 - <artifactId>onlab-utils</artifactId>
28 - <version>1.7.0-SNAPSHOT</version>
29 - </parent>
30 -
31 - <artifactId>jdvue</artifactId>
32 - <packaging>jar</packaging>
33 -
34 - <description>Java Package Dependency &amp; Analyzer</description>
35 -
36 - <properties>
37 - <!-- FIXME skipping checkstyle for now -->
38 - <checkstyle.skip>true</checkstyle.skip>
39 - </properties>
40 -
41 - <dependencies>
42 - <dependency>
43 - <groupId>com.google.guava</groupId>
44 - <artifactId>guava</artifactId>
45 - <version>19.0</version>
46 - </dependency>
47 - <dependency>
48 - <groupId>com.google.guava</groupId>
49 - <artifactId>guava-testlib</artifactId>
50 - <version>19.0</version>
51 - <scope>test</scope>
52 - </dependency>
53 - <dependency>
54 - <groupId>com.fasterxml.jackson.core</groupId>
55 - <artifactId>jackson-databind</artifactId>
56 - <version>2.7.3</version>
57 - <scope>compile</scope>
58 - </dependency>
59 - <dependency>
60 - <groupId>com.fasterxml.jackson.core</groupId>
61 - <artifactId>jackson-annotations</artifactId>
62 - <version>2.7.3</version>
63 - <scope>compile</scope>
64 - </dependency>
65 - <dependency>
66 - <groupId>org.onosproject</groupId>
67 - <artifactId>onlab-junit</artifactId>
68 - <scope>test</scope>
69 - </dependency>
70 - </dependencies>
71 -
72 - <build>
73 - <plugins>
74 - <plugin>
75 - <artifactId>maven-compiler-plugin</artifactId>
76 - <version>3.1</version>
77 - <configuration>
78 - <source>1.8</source>
79 - <target>1.8</target>
80 - </configuration>
81 - </plugin>
82 - <plugin>
83 - <groupId>org.apache.maven.plugins</groupId>
84 - <artifactId>maven-shade-plugin</artifactId>
85 - <version>2.4.2</version>
86 - <configuration>
87 - <transformers>
88 - <transformer
89 - implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
90 - <mainClass>org.onlab.jdvue.DependencyViewer
91 - </mainClass>
92 - </transformer>
93 - </transformers>
94 - </configuration>
95 - <executions>
96 - <execution>
97 - <phase>package</phase>
98 - <goals>
99 - <goal>shade</goal>
100 - </goals>
101 - </execution>
102 - </executions>
103 - </plugin>
104 - </plugins>
105 - </build>
106 -
107 -</project>
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -
19 -import java.io.BufferedReader;
20 -import java.io.FileInputStream;
21 -import java.io.IOException;
22 -import java.io.InputStream;
23 -import java.io.InputStreamReader;
24 -import java.util.ArrayList;
25 -import java.util.Collection;
26 -import java.util.Collections;
27 -import java.util.HashMap;
28 -import java.util.HashSet;
29 -import java.util.List;
30 -import java.util.Map;
31 -import java.util.Set;
32 -
33 -import static com.google.common.base.MoreObjects.toStringHelper;
34 -
35 -/**
36 - * Produces a package &amp; source catalogue.
37 - *
38 - * @author Thomas Vachuska
39 - */
40 -public class Catalog {
41 -
42 - private static final String PACKAGE = "package";
43 - private static final String IMPORT = "import";
44 - private static final String STATIC = "static";
45 - private static final String SRC_ROOT = "src/main/java/";
46 - private static final String WILDCARD = "\\.*$";
47 -
48 - private final Map<String, JavaSource> sources = new HashMap<>();
49 - private final Map<String, JavaPackage> packages = new HashMap<>();
50 - private final Set<DependencyCycle> cycles = new HashSet<>();
51 - private final Set<Dependency> cycleSegments = new HashSet<>();
52 - private final Map<JavaPackage, Set<DependencyCycle>> packageCycles = new HashMap<>();
53 - private final Map<JavaPackage, Set<Dependency>> packageCycleSegments = new HashMap<>();
54 -
55 - /**
56 - * Loads the catalog from the specified catalog file.
57 - *
58 - * @param catalogPath catalog file path
59 - * @throws IOException if unable to read the catalog file
60 - */
61 - public void load(String catalogPath) throws IOException {
62 - InputStream is = new FileInputStream(catalogPath);
63 - BufferedReader br = new BufferedReader(new InputStreamReader(is));
64 -
65 - String line;
66 - while ((line = br.readLine()) != null) {
67 - // Split the line into the two fields: path and pragmas
68 - String fields[] = line.trim().split(":");
69 - if (fields.length <= 1) {
70 - continue;
71 - }
72 - String path = fields[0];
73 -
74 - // Now split the pragmas on whitespace and trim punctuation
75 - String pragma[] = fields[1].trim().replaceAll("[;\n\r]", "").split("[\t ]");
76 -
77 - // Locate (or create) Java source entity based on the path
78 - JavaSource source = getOrCreateSource(path);
79 -
80 - // Now process the package or import statements
81 - if (pragma[0].equals(PACKAGE)) {
82 - processPackageDeclaration(source, pragma[1]);
83 -
84 - } else if (pragma[0].equals(IMPORT)) {
85 - if (pragma[1].equals(STATIC)) {
86 - processImportStatement(source, pragma[2]);
87 - } else {
88 - processImportStatement(source, pragma[1]);
89 - }
90 - }
91 - }
92 - }
93 -
94 - /**
95 - * Analyzes the catalog by resolving imports and identifying circular
96 - * package dependencies.
97 - */
98 - public void analyze() {
99 - resolveImports();
100 - findCircularDependencies();
101 - }
102 -
103 - /**
104 - * Identifies circular package dependencies through what amounts to be a
105 - * depth-first search rooted with each package.
106 - */
107 - private void findCircularDependencies() {
108 - cycles.clear();
109 - for (JavaPackage javaPackage : getPackages()) {
110 - findCircularDependencies(javaPackage);
111 - }
112 -
113 - cycleSegments.clear();
114 - packageCycles.clear();
115 - packageCycleSegments.clear();
116 -
117 - for (DependencyCycle cycle : getCycles()) {
118 - recordCycleForPackages(cycle);
119 - cycleSegments.addAll(cycle.getCycleSegments());
120 - }
121 - }
122 -
123 - /**
124 - * Records the specified cycle into a set for each involved package.
125 - *
126 - * @param cycle cycle to record for involved packages
127 - */
128 - private void recordCycleForPackages(DependencyCycle cycle) {
129 - for (JavaPackage javaPackage : cycle.getCycle()) {
130 - Set<DependencyCycle> cset = packageCycles.get(javaPackage);
131 - if (cset == null) {
132 - cset = new HashSet<>();
133 - packageCycles.put(javaPackage, cset);
134 - }
135 - cset.add(cycle);
136 -
137 - Set<Dependency> sset = packageCycleSegments.get(javaPackage);
138 - if (sset == null) {
139 - sset = new HashSet<>();
140 - packageCycleSegments.put(javaPackage, sset);
141 - }
142 - sset.addAll(cycle.getCycleSegments());
143 - }
144 - }
145 -
146 - /**
147 - * Identifies circular dependencies in which this package participates
148 - * using depth-first search.
149 - *
150 - * @param javaPackage Java package to inspect for dependency cycles
151 - */
152 - private void findCircularDependencies(JavaPackage javaPackage) {
153 - // Setup a depth trace anchored at the given java package.
154 - List<JavaPackage> trace = newTrace(new ArrayList<JavaPackage>(), javaPackage);
155 -
156 - Set<JavaPackage> searched = new HashSet<>();
157 - searchDependencies(javaPackage, trace, searched);
158 - }
159 -
160 - /**
161 - * Generates a new trace using the previous one and a new element
162 - *
163 - * @param trace old search trace
164 - * @param javaPackage package to add to the trace
165 - * @return new search trace
166 - */
167 - private List<JavaPackage> newTrace(List<JavaPackage> trace,
168 - JavaPackage javaPackage) {
169 - List<JavaPackage> newTrace = new ArrayList<>(trace);
170 - newTrace.add(javaPackage);
171 - return newTrace;
172 - }
173 -
174 -
175 - /**
176 - * Recursive depth-first search through dependency tree
177 - *
178 - * @param javaPackage java package being searched currently
179 - * @param trace search trace
180 - * @param searched set of java packages already searched
181 - */
182 - private void searchDependencies(JavaPackage javaPackage,
183 - List<JavaPackage> trace,
184 - Set<JavaPackage> searched) {
185 - if (!searched.contains(javaPackage)) {
186 - searched.add(javaPackage);
187 - for (JavaPackage dependency : javaPackage.getDependencies()) {
188 - if (trace.contains(dependency)) {
189 - cycles.add(new DependencyCycle(trace, dependency));
190 - } else {
191 - searchDependencies(dependency, newTrace(trace, dependency), searched);
192 - }
193 - }
194 - }
195 - }
196 -
197 - /**
198 - * Resolves import names of Java sources into imports of entities known
199 - * to this catalog. All other import names will be ignored.
200 - */
201 - private void resolveImports() {
202 - for (JavaPackage javaPackage : getPackages()) {
203 - Set<JavaPackage> dependencies = new HashSet<>();
204 - for (JavaSource source : javaPackage.getSources()) {
205 - Set<JavaEntity> imports = resolveImports(source);
206 - source.setImports(imports);
207 - dependencies.addAll(importedPackages(imports));
208 - }
209 - javaPackage.setDependencies(dependencies);
210 - }
211 - }
212 -
213 - /**
214 - * Produces a set of imported Java packages from the specified set of
215 - * Java source entities.
216 - *
217 - * @param imports list of imported Java source entities
218 - * @return list of imported Java packages
219 - */
220 - private Set<JavaPackage> importedPackages(Set<JavaEntity> imports) {
221 - Set<JavaPackage> packages = new HashSet<>();
222 - for (JavaEntity entity : imports) {
223 - packages.add(entity instanceof JavaPackage ? (JavaPackage) entity :
224 - ((JavaSource) entity).getPackage());
225 - }
226 - return packages;
227 - }
228 -
229 - /**
230 - * Resolves import names of the specified Java source into imports of
231 - * entities known to this catalog. All other import names will be ignored.
232 - *
233 - * @param source Java source
234 - * @return list of resolved imports
235 - */
236 - private Set<JavaEntity> resolveImports(JavaSource source) {
237 - Set<JavaEntity> imports = new HashSet<>();
238 - for (String importName : source.getImportNames()) {
239 - JavaEntity entity = importName.matches(WILDCARD) ?
240 - getPackage(importName.replaceAll(WILDCARD, "")) :
241 - getSource(importName);
242 - if (entity != null) {
243 - imports.add(entity);
244 - }
245 - }
246 - return imports;
247 - }
248 -
249 - /**
250 - * Returns either an existing or a newly created Java package.
251 - *
252 - * @param packageName Java package name
253 - * @return Java package
254 - */
255 - private JavaPackage getOrCreatePackage(String packageName) {
256 - JavaPackage javaPackage = packages.get(packageName);
257 - if (javaPackage == null) {
258 - javaPackage = new JavaPackage(packageName);
259 - packages.put(packageName, javaPackage);
260 - }
261 - return javaPackage;
262 - }
263 -
264 - /**
265 - * Returns either an existing or a newly created Java source.
266 - *
267 - * @param path Java source path
268 - * @return Java source
269 - */
270 - private JavaSource getOrCreateSource(String path) {
271 - String name = nameFromPath(path);
272 - JavaSource source = sources.get(name);
273 - if (source == null) {
274 - source = new JavaSource(name, path);
275 - sources.put(name, source);
276 - }
277 - return source;
278 - }
279 -
280 - /**
281 - * Extracts a fully qualified source class name from the given path.
282 - * <p>
283 - * For now, this implementation assumes standard Maven source structure
284 - * and thus will look for start of package name under 'src/main/java/'.
285 - * If it will not find such a prefix, it will simply return the path as
286 - * the name.
287 - *
288 - * @param path source path
289 - * @return source name
290 - */
291 - private String nameFromPath(String path) {
292 - int i = path.indexOf(SRC_ROOT);
293 - String name = i < 0 ? path : path.substring(i + SRC_ROOT.length());
294 - return name.replaceAll("\\.java$", "").replace("/", ".");
295 - }
296 -
297 - /**
298 - * Processes the package declaration pragma for the given source.
299 - *
300 - * @param source Java source
301 - * @param packageName Java package name
302 - */
303 - private void processPackageDeclaration(JavaSource source, String packageName) {
304 - JavaPackage javaPackage = getOrCreatePackage(packageName);
305 - source.setPackage(javaPackage);
306 - javaPackage.addSource(source);
307 - }
308 -
309 - /**
310 - * Processes the import pragma for the given source.
311 - *
312 - * @param source Java source
313 - * @param name name of the Java entity being imported (class or package)
314 - */
315 - private void processImportStatement(JavaSource source, String name) {
316 - source.addImportName(name);
317 - }
318 -
319 - /**
320 - * Returns the collection of java sources.
321 - *
322 - * @return collection of java sources
323 - */
324 - public Collection<JavaSource> getSources() {
325 - return Collections.unmodifiableCollection(sources.values());
326 - }
327 -
328 - /**
329 - * Returns the Java source with the specified name.
330 - *
331 - * @param name Java source name
332 - * @return Java source
333 - */
334 - public JavaSource getSource(String name) {
335 - return sources.get(name);
336 - }
337 -
338 - /**
339 - * Returns the collection of all Java packages.
340 - *
341 - * @return collection of java packages
342 - */
343 - public Collection<JavaPackage> getPackages() {
344 - return Collections.unmodifiableCollection(packages.values());
345 - }
346 -
347 - /**
348 - * Returns the set of all Java package dependency cycles.
349 - *
350 - * @return set of dependency cycles
351 - */
352 - public Set<DependencyCycle> getCycles() {
353 - return Collections.unmodifiableSet(cycles);
354 - }
355 -
356 - /**
357 - * Returns the set of all Java package dependency cycle segments.
358 - *
359 - * @return set of dependency cycle segments
360 - */
361 - public Set<Dependency> getCycleSegments() {
362 - return Collections.unmodifiableSet(cycleSegments);
363 - }
364 -
365 - /**
366 - * Returns the set of dependency cycles which involve the specified package.
367 - *
368 - * @param javaPackage java package
369 - * @return set of dependency cycles
370 - */
371 - public Set<DependencyCycle> getPackageCycles(JavaPackage javaPackage) {
372 - Set<DependencyCycle> set = packageCycles.get(javaPackage);
373 - return Collections.unmodifiableSet(set == null ? new HashSet<DependencyCycle>() : set);
374 - }
375 -
376 - /**
377 - * Returns the set of dependency cycle segments which involve the specified package.
378 - *
379 - * @param javaPackage java package
380 - * @return set of dependency cycle segments
381 - */
382 - public Set<Dependency> getPackageCycleSegments(JavaPackage javaPackage) {
383 - Set<Dependency> set = packageCycleSegments.get(javaPackage);
384 - return Collections.unmodifiableSet(set == null ? new HashSet<Dependency>() : set);
385 - }
386 -
387 - /**
388 - * Returns the Java package with the specified name.
389 - *
390 - * @param name Java package name
391 - * @return Java package
392 - */
393 - public JavaPackage getPackage(String name) {
394 - return packages.get(name);
395 - }
396 -
397 - @Override
398 - public String toString() {
399 - return toStringHelper(this)
400 - .add("packages", packages.size())
401 - .add("sources", sources.size())
402 - .add("cycles", cycles.size())
403 - .add("cycleSegments", cycleSegments.size()).toString();
404 - }
405 -
406 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import java.util.Objects;
19 -
20 -import static com.google.common.base.MoreObjects.toStringHelper;
21 -
22 -/**
23 - * Abstraction of a dependency segment.
24 - *
25 - * @author Thomas Vachuska
26 - */
27 -public class Dependency {
28 -
29 - private final JavaPackage source;
30 - private final JavaPackage target;
31 -
32 - /**
33 - * Creates a dependency from the specified source on the given target.
34 - *
35 - * @param source source of the dependency
36 - * @param target target of the dependency
37 - */
38 - public Dependency(JavaPackage source, JavaPackage target) {
39 - this.source = source;
40 - this.target = target;
41 - }
42 -
43 - /**
44 - * Returns the dependency source.
45 - *
46 - * @return source Java package
47 - */
48 - public JavaPackage getSource() {
49 - return source;
50 - }
51 -
52 - /**
53 - * Returns the dependency target.
54 - *
55 - * @return target Java package
56 - */
57 - public JavaPackage getTarget() {
58 - return target;
59 - }
60 -
61 - @Override
62 - public boolean equals(Object obj) {
63 - if (obj instanceof Dependency) {
64 - Dependency that = (Dependency) obj;
65 - return Objects.equals(source, that.source) &&
66 - Objects.equals(target, that.target);
67 - }
68 - return false;
69 - }
70 -
71 - @Override
72 - public int hashCode() {
73 - return Objects.hash(source, target);
74 - }
75 -
76 - @Override
77 - public String toString() {
78 - return toStringHelper(this)
79 - .add("source", source).add("target", target).toString();
80 - }
81 -
82 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import java.util.ArrayList;
19 -import java.util.Collections;
20 -import java.util.List;
21 -import java.util.Objects;
22 -
23 -import static com.google.common.base.MoreObjects.toStringHelper;
24 -
25 -/**
26 - * Simple representation of a Java package dependency cycle.
27 - */
28 -public class DependencyCycle {
29 -
30 - private final List<JavaPackage> cycle;
31 -
32 - /**
33 - * Creates a normalized dependency cycle represented by the specified list
34 - * of Java packages, which are expected to be given in order of dependency.
35 - * List is assumed to be non-empty.
36 - *
37 - * @param cycle list of Java packages in the dependency cycle
38 - * @param cause Java package that caused the cycle
39 - */
40 - DependencyCycle(List<JavaPackage> cycle, JavaPackage cause) {
41 - this.cycle = normalize(cycle, cause);
42 - }
43 -
44 - /**
45 - * Produces a normalized dependency cycle list. Normalization is performed
46 - * by rotating the list so that the package with the least lexicographic
47 - * name is at the start of the list.
48 - *
49 - * @param cycle list of Java packages in the dependency cycle
50 - * @param cause Java package that caused the cycle
51 - * @return normalized cycle
52 - */
53 - private List<JavaPackage> normalize(List<JavaPackage> cycle, JavaPackage cause) {
54 - int start = cycle.indexOf(cause);
55 - List<JavaPackage> clone = new ArrayList<>(cycle.subList(start, cycle.size()));
56 - int leastIndex = findIndexOfLeastName(clone);
57 - Collections.rotate(clone, -leastIndex);
58 - return Collections.unmodifiableList(clone);
59 - }
60 -
61 - /**
62 - * Returns the index of the Java package with the least name.
63 - *
64 - * @param cycle list of Java packages in the dependency cycle
65 - * @return index of the least Java package name
66 - */
67 - private int findIndexOfLeastName(List<JavaPackage> cycle) {
68 - int leastIndex = 0;
69 - String leastName = cycle.get(leastIndex).name();
70 - for (int i = 1, n = cycle.size(); i < n; i++) {
71 - JavaPackage javaPackage = cycle.get(i);
72 - if (leastName.compareTo(javaPackage.name()) > 0) {
73 - leastIndex = i;
74 - leastName = javaPackage.name();
75 - }
76 - }
77 - return leastIndex;
78 - }
79 -
80 - /**
81 - * Returns the normalized Java package dependency cycle
82 - *
83 - * @return list of packages in the dependency cycle
84 - */
85 - public List<JavaPackage> getCycle() {
86 - return cycle;
87 - }
88 -
89 - /**
90 - * Returns the dependency cycle in form of individual dependencies.
91 - *
92 - * @return list of dependencies forming the cycle
93 - */
94 - public List<Dependency> getCycleSegments() {
95 - List<Dependency> dependencies = new ArrayList<>();
96 - for (int i = 0, n = cycle.size(); i < n; i++) {
97 - dependencies.add(new Dependency(cycle.get(i), cycle.get(i < n - 1 ? i + 1 : 0)));
98 - }
99 - return dependencies;
100 - }
101 -
102 - @Override
103 - public boolean equals(Object o) {
104 - if (o instanceof DependencyCycle) {
105 - DependencyCycle that = (DependencyCycle) o;
106 - return Objects.equals(cycle, that.cycle);
107 - }
108 - return false;
109 - }
110 -
111 - @Override
112 - public int hashCode() {
113 - return cycle.hashCode();
114 - }
115 -
116 - @Override
117 - public String toString() {
118 - return toStringHelper(this).add("cycle", cycle).toString();
119 - }
120 -
121 - public String toShortString() {
122 - StringBuilder sb = new StringBuilder("[");
123 - for (JavaPackage javaPackage : cycle) {
124 - sb.append(javaPackage.name()).append(", ");
125 - }
126 - if (sb.length() > 1) {
127 - sb.delete(sb.length() - 2, sb.length());
128 - }
129 - sb.append("]");
130 - return sb.toString();
131 - }
132 -
133 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import com.fasterxml.jackson.databind.JsonNode;
19 -import com.fasterxml.jackson.databind.ObjectMapper;
20 -import com.fasterxml.jackson.databind.ObjectWriter;
21 -import com.fasterxml.jackson.databind.node.ArrayNode;
22 -import com.fasterxml.jackson.databind.node.ObjectNode;
23 -
24 -import java.io.BufferedReader;
25 -import java.io.FileWriter;
26 -import java.io.IOException;
27 -import java.io.InputStream;
28 -import java.io.InputStreamReader;
29 -import java.util.Set;
30 -
31 -/**
32 - * Generator of a self-contained HTML file which serves as a GUI for
33 - * visualizing Java package dependencies carried in the supplied catalog.
34 - *
35 - * The HTML file is an adaptation of D3.js Hierarchical Edge Bundling as
36 - * shown at http://bl.ocks.org/mbostock/7607999.
37 - *
38 - * @author Thomas Vachuska
39 - */
40 -public class DependencyViewer {
41 -
42 - private static final String JPD_EXT = ".db";
43 - private static final String HTML_EXT = ".html";
44 -
45 - private static final String INDEX = "index.html";
46 - private static final String D3JS = "d3.v3.min.js";
47 -
48 - private static final String TITLE_PLACEHOLDER = "TITLE_PLACEHOLDER";
49 - private static final String D3JS_PLACEHOLDER = "D3JS_PLACEHOLDER";
50 - private static final String DATA_PLACEHOLDER = "DATA_PLACEHOLDER";
51 -
52 - private final Catalog catalog;
53 -
54 - /**
55 - * Creates a Java package dependency viewer.
56 - *
57 - * @param catalog dependency catalog
58 - */
59 - public DependencyViewer(Catalog catalog) {
60 - this.catalog = catalog;
61 - }
62 -
63 - /**
64 - * Main program entry point.
65 - *
66 - * @param args command line arguments
67 - */
68 - public static void main(String[] args) {
69 - Catalog cat = new Catalog();
70 - DependencyViewer viewer = new DependencyViewer(cat);
71 - try {
72 - String path = args[0];
73 - cat.load(path + JPD_EXT);
74 - cat.analyze();
75 -
76 - System.err.println(cat);
77 - viewer.dumpLongestCycle(cat);
78 - viewer.writeHTMLFile(path);
79 - } catch (IOException e) {
80 - System.err.println("Unable to process catalog: " + e.getMessage());
81 - }
82 - }
83 -
84 - /**
85 - * Prints out the longest cycle; just for kicks.
86 - * @param cat catalog
87 - */
88 - private void dumpLongestCycle(Catalog cat) {
89 - DependencyCycle longest = null;
90 - for (DependencyCycle cycle : cat.getCycles()) {
91 - if (longest == null || longest.getCycleSegments().size() < cycle.getCycleSegments().size()) {
92 - longest = cycle;
93 - }
94 - }
95 -
96 - if (longest != null) {
97 - for (Dependency dependency : longest.getCycleSegments()) {
98 - System.out.println(dependency);
99 - }
100 - }
101 - }
102 -
103 - /**
104 - * Writes the HTML catalog file for the given viewer.
105 - *
106 - * @param path base file path
107 - * @throws IOException if issues encountered writing the HTML file
108 - */
109 - public void writeHTMLFile(String path) throws IOException {
110 - String index = slurp(getClass().getResourceAsStream(INDEX));
111 - String d3js = slurp(getClass().getResourceAsStream(D3JS));
112 -
113 - FileWriter fw = new FileWriter(path + HTML_EXT);
114 - ObjectWriter writer = new ObjectMapper().writer(); // .writerWithDefaultPrettyPrinter();
115 - fw.write(index.replace(TITLE_PLACEHOLDER, path)
116 - .replace(D3JS_PLACEHOLDER, d3js)
117 - .replace(DATA_PLACEHOLDER, writer.writeValueAsString(toJson())));
118 - fw.close();
119 - }
120 -
121 - /**
122 - * Slurps the specified input stream into a string.
123 - *
124 - * @param stream input stream to be read
125 - * @return string containing the contents of the input stream
126 - * @throws IOException if issues encountered reading from the stream
127 - */
128 - static String slurp(InputStream stream) throws IOException {
129 - StringBuilder sb = new StringBuilder();
130 - BufferedReader br = new BufferedReader(new InputStreamReader(stream));
131 - String line;
132 - while ((line = br.readLine()) != null) {
133 - sb.append(line).append(System.lineSeparator());
134 - }
135 - br.close();
136 - return sb.toString();
137 - }
138 -
139 - // Produces a JSON structure designed to drive the hierarchical visual
140 - // representation of Java package dependencies and any dependency cycles
141 - private JsonNode toJson() {
142 - ObjectMapper mapper = new ObjectMapper();
143 - ObjectNode root = mapper.createObjectNode();
144 - root.put("packages", jsonPackages(mapper));
145 - root.put("cycleSegments", jsonCycleSegments(mapper, catalog.getCycleSegments()));
146 - root.put("summary", jsonSummary(mapper));
147 - return root;
148 - }
149 -
150 - // Produces a JSON summary of dependencies
151 - private JsonNode jsonSummary(ObjectMapper mapper) {
152 - ObjectNode summary = mapper.createObjectNode();
153 - summary.put("packages", catalog.getPackages().size());
154 - summary.put("sources", catalog.getSources().size());
155 - summary.put("cycles", catalog.getCycles().size());
156 - summary.put("cycleSegments", catalog.getCycleSegments().size());
157 - return summary;
158 - }
159 -
160 - // Produces a JSON structure with package dependency data
161 - private JsonNode jsonPackages(ObjectMapper mapper) {
162 - ArrayNode packages = mapper.createArrayNode();
163 - for (JavaPackage javaPackage : catalog.getPackages()) {
164 - packages.add(json(mapper, javaPackage));
165 - }
166 - return packages;
167 - }
168 -
169 - // Produces a JSON structure with all cyclic segments
170 - private JsonNode jsonCycleSegments(ObjectMapper mapper,
171 - Set<Dependency> segments) {
172 - ObjectNode cyclicSegments = mapper.createObjectNode();
173 - for (Dependency dependency : segments) {
174 - String s = dependency.getSource().name();
175 - String t = dependency.getTarget().name();
176 - cyclicSegments.put(t + "-" + s,
177 - mapper.createObjectNode().put("s", s).put("t", t));
178 - }
179 - return cyclicSegments;
180 - }
181 -
182 - // Produces a JSON object structure describing the specified Java package.
183 - private JsonNode json(ObjectMapper mapper, JavaPackage javaPackage) {
184 - ObjectNode node = mapper.createObjectNode();
185 -
186 - ArrayNode imports = mapper.createArrayNode();
187 - for (JavaPackage dependency : javaPackage.getDependencies()) {
188 - imports.add(dependency.name());
189 - }
190 -
191 - Set<DependencyCycle> packageCycles = catalog.getPackageCycles(javaPackage);
192 - Set<Dependency> packageCycleSegments = catalog.getPackageCycleSegments(javaPackage);
193 -
194 - node.put("name", javaPackage.name());
195 - node.put("size", javaPackage.getSources().size());
196 - node.put("imports", imports);
197 - node.put("cycleSegments", jsonCycleSegments(mapper, packageCycleSegments));
198 - node.put("cycleCount", packageCycles.size());
199 - node.put("cycleSegmentCount", packageCycleSegments.size());
200 - return node;
201 - }
202 -
203 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import java.util.Objects;
19 -
20 -/**
21 - * Abstraction of a Java source entity.
22 - */
23 -public abstract class JavaEntity {
24 -
25 - private final String name;
26 -
27 - /**
28 - * Creates a new Java source entity with the given name.
29 - *
30 - * @param name source entity name
31 - */
32 - JavaEntity(String name) {
33 - this.name = name;
34 - }
35 -
36 - /**
37 - * Returns the Java source entity name.
38 - *
39 - * @return source entity name
40 - */
41 - public String name() {
42 - return name;
43 - }
44 -
45 - @Override
46 - public boolean equals(Object o) {
47 - if (o instanceof JavaEntity) {
48 - JavaEntity that = (JavaEntity) o;
49 - return getClass().equals(that.getClass()) &&
50 - Objects.equals(name, that.name);
51 - }
52 - return false;
53 - }
54 -
55 - @Override
56 - public int hashCode() {
57 - return Objects.hash(name);
58 - }
59 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import java.util.Collections;
19 -import java.util.HashSet;
20 -import java.util.Set;
21 -
22 -import static com.google.common.base.MoreObjects.toStringHelper;
23 -
24 -/**
25 - * Simple abstraction of a Java package for the purpose of tracking
26 - * dependencies and requirements.
27 - *
28 - * @author Thomas Vachuska
29 - */
30 -public class JavaPackage extends JavaEntity {
31 -
32 - private final Set<JavaSource> sources = new HashSet<>();
33 - private Set<JavaPackage> dependencies;
34 -
35 - /**
36 - * Creates a new Java package.
37 - *
38 - * @param name java package file name
39 - */
40 - JavaPackage(String name) {
41 - super(name);
42 - }
43 -
44 - /**
45 - * Returns the set of sources contained in this Java package.
46 - *
47 - * @return set of Java sources
48 - */
49 - public Set<JavaSource> getSources() {
50 - return Collections.unmodifiableSet(sources);
51 - }
52 -
53 - /**
54 - * Adds the specified Java source to the package. Only possible if the
55 - * Java package of the source is the same as this Java package.
56 - *
57 - * @param source Java source to be added
58 - */
59 - void addSource(JavaSource source) {
60 - if (source.getPackage().equals(this)) {
61 - sources.add(source);
62 - }
63 - }
64 -
65 - /**
66 - * Returns the set of packages directly required by this package.
67 - *
68 - * @return set of Java package dependencies
69 - */
70 - Set<JavaPackage> getDependencies() {
71 - return dependencies;
72 - }
73 -
74 - /**
75 - * Sets the set of resolved Java packages on which this package dependens.
76 - *
77 - * @param dependencies set of resolved Java packages
78 - */
79 - void setDependencies(Set<JavaPackage> dependencies) {
80 - if (this.dependencies == null) {
81 - this.dependencies = Collections.unmodifiableSet(new HashSet<>(dependencies));
82 - }
83 - }
84 -
85 - @Override
86 - public String toString() {
87 - return toStringHelper(this)
88 - .add("name", name())
89 - .add("sources", sources.size())
90 - .add("dependencies", (dependencies != null ? dependencies.size() : 0))
91 - .toString();
92 - }
93 -
94 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import java.util.*;
19 -
20 -import static com.google.common.base.MoreObjects.toStringHelper;
21 -
22 -/**
23 - * Simple abstraction of a Java source file for the purpose of tracking
24 - * dependencies and requirements.
25 - *
26 - * @author Thomas Vachuska
27 - */
28 -public class JavaSource extends JavaEntity {
29 -
30 - private String path;
31 - private JavaPackage javaPackage;
32 -
33 - private final Set<String> importNames = new HashSet<>();
34 - private Set<JavaEntity> imports;
35 -
36 - /**
37 - * Creates a new Java source entity.
38 - *
39 - * @param name java source file name
40 - * @param path source file path
41 - */
42 - JavaSource(String name, String path) {
43 - super(name);
44 - this.path = path;
45 - }
46 -
47 - /**
48 - * Returns the Java package for this Java source.
49 - *
50 - * @return Java package
51 - */
52 - public JavaPackage getPackage() {
53 - return javaPackage;
54 - }
55 -
56 - /**
57 - * Sets the Java package for this Java source.
58 - *
59 - * @param javaPackage Java package
60 - */
61 - void setPackage(JavaPackage javaPackage) {
62 - if (this.javaPackage == null) {
63 - this.javaPackage = javaPackage;
64 - }
65 - }
66 -
67 - /**
68 - * Returns the set of resolved imports for this Java source
69 - *
70 - * @return set of imports
71 - */
72 - public Set<JavaEntity> getImports() {
73 - return imports;
74 - }
75 -
76 - /**
77 - * Sets the set of resolved imported Java entities for this source.
78 - *
79 - * @param imports set of resolved Java entities imported by this source
80 - */
81 - void setImports(Set<JavaEntity> imports) {
82 - if (this.imports == null) {
83 - this.imports = Collections.unmodifiableSet(new HashSet<>(imports));
84 - }
85 - }
86 -
87 - /**
88 - * Adds a name of an imported, but unresolved, Java entity name.
89 - *
90 - * @param name name of an imported Java entity
91 - */
92 - void addImportName(String name) {
93 - importNames.add(name);
94 - }
95 -
96 - /**
97 - * Returns the set of imported, but unresolved, Java entity names.
98 - *
99 - * @return set of imported Java entity names
100 - */
101 - Set<String> getImportNames() {
102 - return importNames;
103 - }
104 -
105 - @Override
106 - public String toString() {
107 - return toStringHelper(this)
108 - .add("name", name())
109 - .add("javaPackage", (javaPackage != null ? javaPackage.name() : ""))
110 - .add("importNames", importNames.size())
111 - .add("imports", (imports != null ? imports.size() : 0))
112 - .toString();
113 - }
114 -
115 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Utility to analyze Java package dependencies.
19 - */
20 -package org.onlab.jdvue;
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
1 -<!DOCTYPE html>
2 -<html>
3 -<head>
4 - <meta charset="utf-8">
5 - <title>TITLE_PLACEHOLDER</title>
6 - <style>
7 -
8 - .node {
9 - font: 300 13px "Helvetica Neue", Helvetica, Arial, sans-serif;
10 - fill: #bbb;
11 - }
12 -
13 - .link {
14 - stroke: steelblue;
15 - stroke-opacity: .4;
16 - fill: none;
17 - pointer-events: none;
18 - }
19 -
20 - .node--focus {
21 - font-weight: 700;
22 - fill: #000;
23 - }
24 -
25 - .node:hover {
26 - fill: steelblue;
27 - }
28 -
29 - .node:hover,
30 - .node--source,
31 - .node--target {
32 - font-weight: 700;
33 - }
34 -
35 - .node--source {
36 - fill: #2ca02c;
37 - }
38 -
39 - .node--target {
40 - fill: #d59800;
41 - }
42 -
43 - .link--source,
44 - .link--target {
45 - stroke-opacity: 1;
46 - stroke-width: 3px;
47 - }
48 -
49 - .link--source {
50 - stroke: #d59800;
51 - }
52 -
53 - .link--target {
54 - stroke: #2ca02c;
55 - }
56 -
57 - .link--cycle {
58 - stroke: #ff0000;
59 - }
60 -
61 - .summary {
62 - font: 300 13px "Helvetica Neue", Helvetica, Arial, sans-serif;
63 - position: fixed;
64 - top: 32px;
65 - right: 32px;
66 - width: 192px;
67 - background-color: #ffffff;
68 - box-shadow: 2px 2px 4px 2px #777777;
69 - padding: 5px;
70 - }
71 -
72 - .details {
73 - display: none;
74 - font: 300 13px "Helvetica Neue", Helvetica, Arial, sans-serif;
75 - position: fixed;
76 - top: 220px;
77 - right: 32px;
78 - width: 192px;
79 - background-color: #ffffff;
80 - box-shadow: 2px 2px 4px 2px #777777;
81 - padding: 5px;
82 - }
83 -
84 - .shown {
85 - display:block;
86 - }
87 -
88 - .stat {
89 - text-align: right;
90 - width: 64px;
91 - }
92 -
93 - .title {
94 - font-size: 16px;
95 - font-weight: bold;
96 - }
97 -
98 - #package {
99 - font-size: 14px;
100 - font-weight: bold;
101 - }
102 - </style>
103 -</head>
104 -<body>
105 - <div class="summary">
106 - <div class="title">Project TITLE_PLACEHOLDER</div>
107 - <table>
108 - <tr>
109 - <td>Sources:</td>
110 - <td id="sourceCount" class="stat"></td>
111 - </tr>
112 - <tr>
113 - <td>Packages:</td>
114 - <td id="packageCount" class="stat"></td>
115 - </tr>
116 - <tr>
117 - <td>Cyclic Segments:</td>
118 - <td id="segmentCount" class="stat"></td>
119 - </tr>
120 - <tr>
121 - <td>Cycles:</td>
122 - <td id="cycleCount" class="stat"></td>
123 - </tr>
124 - </table>
125 - <div><hr size="1"></div>
126 - <div><input type="checkbox"> Highlight cycles</input></div>
127 - <div><input style="width: 95%" type="range" min="0" max="100" value="75"></div>
128 - </div>
129 - <div class="details">
130 - <div id="package">Package Details</div>
131 - <table>
132 - <tr>
133 - <td>Sources:</td>
134 - <td id="psourceCount" class="stat"></td>
135 - </tr>
136 - <tr>
137 - <td>Dependents:</td>
138 - <td id="pdependentCount" class="stat"></td>
139 - </tr>
140 - <tr>
141 - <td>Cyclic Segments:</td>
142 - <td id="psegmentCount" class="stat"></td>
143 - </tr>
144 - <tr>
145 - <td>Cycles:</td>
146 - <td id="pcycleCount" class="stat"></td>
147 - </tr>
148 - </table>
149 - </div>
150 -<script>
151 -D3JS_PLACEHOLDER
152 -
153 - var catalog =
154 -DATA_PLACEHOLDER
155 - ;
156 -
157 - var diameter = 1000,
158 - radius = diameter / 2,
159 - innerRadius = radius - 300;
160 -
161 - var cluster = d3.layout.cluster()
162 - .size([360, innerRadius])
163 - .sort(null)
164 - .value(function(d) { return d.size; });
165 -
166 - var bundle = d3.layout.bundle();
167 -
168 - var line = d3.svg.line.radial()
169 - .interpolate("bundle")
170 - .tension(.75)
171 - .radius(function(d) { return d.y; })
172 - .angle(function(d) { return d.x / 180 * Math.PI; });
173 -
174 - var svg = d3.select("body").append("svg")
175 - .attr("width", diameter)
176 - .attr("height", diameter)
177 - .append("g")
178 - .attr("transform", "translate(" + radius + "," + radius + ")");
179 -
180 - var link = svg.append("g").selectAll(".link"),
181 - node = svg.append("g").selectAll(".node"),
182 - cycles = {}, highlightCycles, selectedNode;
183 -
184 - function isCyclicLink(l) {
185 - return highlightCycles &&
186 - (cycles[l.source.key + "-" + l.target.key] || cycles[l.target.key + "-" + l.source.key]);
187 - }
188 -
189 - function isCyclicPackageLink(l, p) {
190 - var key = l.source.key + "-" + l.target.key,
191 - rKey = l.target.key + "-" + l.source.key;
192 - return isCyclicLink(l) && (p.cycleSegments[key] || p.cycleSegments[rKey]);
193 - }
194 -
195 - function refreshPaths() {
196 - svg.selectAll("path.link").classed("link--cycle", isCyclicLink);
197 - }
198 -
199 - function processCatalog() {
200 - var nodes = cluster.nodes(packageHierarchy(catalog.packages)),
201 - links = packageImports(nodes),
202 - splines = bundle(links);
203 - cycles = catalog.cycleSegments;
204 -
205 - d3.select("input[type=checkbox]").on("change", function() {
206 - highlightCycles = this.checked;
207 - refreshPaths();
208 - });
209 -
210 - link = link
211 - .data(splines)
212 - .enter().append("path")
213 - .each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
214 - .attr("class", "link")
215 - .classed("link--cycle", isCyclicLink)
216 - .attr("d", function(d, i) { return line(splines[i]); });
217 -
218 -
219 - node = node
220 - .data(nodes.filter(function(n) { return !n.children; }))
221 - .enter().append("text")
222 - .attr("class", "node")
223 - .attr("dy", ".31em")
224 - .attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + (d.y + 8) + ",0)" + (d.x < 180 ? "" : "rotate(180)"); })
225 - .style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
226 - .text(function(d) { return d.key; })
227 - .on("focus", processSelect)
228 - .on("blur", processSelect);
229 -
230 - d3.select("input[type=range]").on("change", function() {
231 - line.tension(this.value / 100);
232 - svg.selectAll("path.link")
233 - .data(splines)
234 - .attr("d", function(d, i) { return line(splines[i]); });
235 - });
236 -
237 - d3.select("#packageCount").text(catalog.summary.packages);
238 - d3.select("#sourceCount").text(catalog.summary.sources);
239 - d3.select("#segmentCount").text(catalog.summary.cycleSegments);
240 - d3.select("#cycleCount").text(catalog.summary.cycles);
241 - }
242 -
243 - function processSelect(d) {
244 - if (selectedNode === d) {
245 - deselected(d);
246 - selectedNode = null;
247 -
248 - } else if (selectedNode) {
249 - deselected(selectedNode);
250 - selectedNode = null;
251 - selected(d);
252 -
253 - } else {
254 - selected(d);
255 - selectedNode = d;
256 - }
257 - }
258 -
259 - function selected(d) {
260 - node
261 - .each(function(n) { n.target = n.source = false; })
262 - .classed("node--focus", function(n) { return n === d; });
263 -
264 - link
265 - .classed("link--cycle", function(l) { return isCyclicPackageLink(l, d); })
266 - .classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
267 - .classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
268 - .filter(function(l) { return l.target === d || l.source === d; })
269 - .each(function() { this.parentNode.appendChild(this); });
270 -
271 - node
272 - .classed("node--target", function(n) { return n.target; })
273 - .classed("node--source", function(n) { return n.source; });
274 -
275 - d3.select("#psourceCount").text(d.size);
276 - d3.select("#pdependentCount").text(d.imports.length);
277 - d3.select("#psegmentCount").text(d.cycleSegmentCount);
278 - d3.select("#pcycleCount").text(d.cycleCount);
279 - d3.select(".details").classed("shown", function() { return true; });
280 - }
281 -
282 - function deselected(d) {
283 - link
284 - .classed("link--cycle", isCyclicLink)
285 - .classed("link--target", false)
286 - .classed("link--source", false);
287 -
288 - node
289 - .classed("node--target", false)
290 - .classed("node--source", false)
291 - .classed("node--focus", false);
292 - d3.select(".details").classed("shown", function() { return false; });
293 - }
294 -
295 - d3.select(self.frameElement).style("height", diameter + "px");
296 -
297 - // Lazily construct the package hierarchy.
298 - function packageHierarchy(packages) {
299 - var map = {}, cnt = 0;
300 -
301 - // Builds the structure top-down to the specified leaf or until
302 - // another leaf in which case hook this leaf to the same parent
303 - function buildHierarchy(leaf, i) {
304 - var leafName = leaf.name,
305 - node, name, parent = map[""], start = 0;
306 - while (start < leafName.length) {
307 - name = parentName(leafName, start);
308 - node = map[name];
309 - if (!node) {
310 - node = map[name] = parentNode(name, parent);
311 - parent.children.push(node);
312 -
313 - } else if (node.imports) {
314 - leaf.parent = parent;
315 - parent.children.push(leaf);
316 - break;
317 - }
318 - parent = node;
319 - start = name.length + 1;
320 - }
321 - }
322 -
323 - function parentNode(name, parent) {
324 - return {name: name, parent: parent, key: name, children: []};
325 - }
326 -
327 - function parentName(leafName, start) {
328 - var i = leafName.indexOf(".", start);
329 - return i > 0 ? leafName.substring(0, i) : leafName;
330 - }
331 -
332 - // First populate all packages as leafs
333 - packages.forEach(function(d) {
334 - map[d.name] = d;
335 - d.key = d.name;
336 - });
337 -
338 - // Next synthesize the intermediate structure, by-passing any leafs
339 - map[""] = parentNode("", null);
340 - var i = 0;
341 - packages.forEach(function(d) {
342 - buildHierarchy(d, i++);
343 - });
344 -
345 - return map[""];
346 - }
347 -
348 - // Return a list of imports for the given array of nodes.
349 - function packageImports(nodes) {
350 - var map = {},
351 - imports = [];
352 -
353 - // Compute a map from name to node.
354 - nodes.forEach(function(d) {
355 - map[d.name] = d;
356 - });
357 -
358 - // For each import, construct a link from the source to target node.
359 - nodes.forEach(function(d) {
360 - if (d.imports) d.imports.forEach(function(i) {
361 - imports.push({source: map[d.name], target: map[i]});
362 - });
363 - });
364 -
365 - return imports;
366 - }
367 -
368 - processCatalog();
369 -</script>
370 -</body>
371 -</html>
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import org.junit.Test;
19 -import org.onlab.jdvue.Catalog;
20 -import org.onlab.jdvue.JavaPackage;
21 -import org.onlab.jdvue.JavaSource;
22 -
23 -import java.io.IOException;
24 -
25 -import static org.junit.Assert.assertEquals;
26 -import static org.junit.Assert.assertNotNull;
27 -
28 -/**
29 - * Unit test for the source catalog.
30 - *
31 - * @author Thomas Vachuska
32 - */
33 -public class CatalogTest {
34 -
35 - @Test
36 - public void basics() throws IOException {
37 - Catalog cat = new Catalog();
38 - cat.load("src/test/resources/catalog.db");
39 - cat.analyze();
40 -
41 - assertEquals("incorrect package count", 12, cat.getPackages().size());
42 - assertEquals("incorrect source count", 14, cat.getSources().size());
43 -
44 - JavaPackage pkg = cat.getPackage("k");
45 - assertNotNull("package should be found", pkg);
46 -
47 - JavaSource src = cat.getSource("k.K");
48 - assertNotNull("source should be found", src);
49 -
50 - assertEquals("incorrect package source count", 1, pkg.getSources().size());
51 - assertEquals("incorrect package dependency count", 1, pkg.getDependencies().size());
52 - assertEquals("incorrect package cycle count", 3, cat.getPackageCycles(pkg).size());
53 -
54 - assertEquals("incorrect segment count", 11, cat.getCycleSegments().size());
55 - assertEquals("incorrect cycle count", 5, cat.getCycles().size());
56 - }
57 -
58 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import org.junit.Test;
19 -import org.onlab.jdvue.DependencyCycle;
20 -import org.onlab.jdvue.JavaPackage;
21 -
22 -import java.util.Arrays;
23 -
24 -import static org.junit.Assert.*;
25 -
26 -/**
27 - * Unit test for the dependency cycle entity.
28 - *
29 - * @author Thomas Vachuska
30 - */
31 -public class DependencyCycleTest {
32 -
33 - @Test
34 - public void normalize() {
35 - JavaPackage x = new JavaPackage("x");
36 - JavaPackage y = new JavaPackage("y");
37 - JavaPackage z = new JavaPackage("z");
38 -
39 - DependencyCycle a = new DependencyCycle(Arrays.asList(new JavaPackage[] {x, y, z}), x);
40 - DependencyCycle b = new DependencyCycle(Arrays.asList(new JavaPackage[] {y, z, x}), y);
41 - DependencyCycle c = new DependencyCycle(Arrays.asList(new JavaPackage[] {z, x, y}), z);
42 -
43 - assertEquals("incorrect normalization", a, b);
44 - assertEquals("incorrect normalization", a, c);
45 - }
46 -
47 - @Test
48 - public void testToString() {
49 - JavaPackage x = new JavaPackage("x");
50 - JavaPackage y = new JavaPackage("y");
51 - JavaPackage z = new JavaPackage("z");
52 -
53 - DependencyCycle a = new DependencyCycle(Arrays.asList(new JavaPackage[] {x, y, z}), x);
54 - assertEquals("incorrect toString", "[x, y, z]", a.toShortString());
55 - assertEquals("incorrect toString",
56 - "DependencyCycle{cycle=[" +
57 - "JavaPackage{name=x, sources=0, dependencies=0}, " +
58 - "JavaPackage{name=y, sources=0, dependencies=0}, " +
59 - "JavaPackage{name=z, sources=0, dependencies=0}]}",
60 - a.toString());
61 - }
62 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import com.google.common.testing.EqualsTester;
19 -import org.junit.Test;
20 -import org.onlab.jdvue.Dependency;
21 -import org.onlab.jdvue.JavaPackage;
22 -
23 -import static org.junit.Assert.assertEquals;
24 -import static org.junit.Assert.assertNotEquals;
25 -
26 -/**
27 - * Unit test for the dependency entity.
28 - *
29 - * @author Thomas Vachuska
30 - */
31 -public class DependencyTest {
32 -
33 - @Test
34 - public void basics() {
35 - JavaPackage x = new JavaPackage("x");
36 - JavaPackage y = new JavaPackage("y");
37 -
38 - new EqualsTester()
39 - .addEqualityGroup(new Dependency(x, y), new Dependency(x, y))
40 - .addEqualityGroup(new Dependency(y, x), new Dependency(y, x))
41 - .testEquals();
42 - }
43 -
44 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.jdvue;
17 -
18 -import org.junit.Test;
19 -import org.onlab.jdvue.DependencyViewer;
20 -
21 -import java.io.FileInputStream;
22 -import java.io.IOException;
23 -
24 -import static org.junit.Assert.assertEquals;
25 -import static org.junit.Assert.assertNotEquals;
26 -import static org.onlab.jdvue.DependencyViewer.slurp;
27 -
28 -/**
29 - * Unit test for the dependency viewer.
30 - *
31 - * @author Thomas Vachuska
32 - */
33 -public class DependencyViewerTest {
34 -
35 - @Test
36 - public void basics() throws IOException {
37 - DependencyViewer.main(new String[]{"src/test/resources/catalog"});
38 -
39 - String expected = slurp(new FileInputStream("src/test/resources/expected.html"));
40 - String actual = slurp(new FileInputStream("src/test/resources/catalog.html"));
41 -
42 - // FIXME: add more manageable assertions here
43 -// assertEquals("incorrect html", expected, actual);
44 - }
45 -
46 -}
1 -src/main/java/a/A.java:package a;
2 -src/main/java/a/A.java:import b.B;
3 -src/main/java/a/A2.java:package a;
4 -src/main/java/a/A2.java:import c.C;
5 -src/main/java/b/B.java:package b;
6 -src/main/java/b/B.java:import c.C;
7 -src/main/java/c/C.java:package c;
8 -
9 -src/main/java/x/X.java:package x;
10 -src/main/java/x/X.java:import y.Y;
11 -src/main/java/y/Y.java:package y;
12 -src/main/java/y/Y.java:import z.Z;
13 -src/main/java/z/Z.java:package z;
14 -src/main/java/z/Z.java:import x.X;
15 -
16 -src/main/java/u/U.java:package u;
17 -src/main/java/u/U.java:import v.V;
18 -src/main/java/u/U2.java:package u;
19 -src/main/java/u/U2.java:import v.V;
20 -src/main/java/v/V.java:package v;
21 -src/main/java/v/V.java:import u.U;
22 -
23 -src/main/java/k/K.java:package k;
24 -src/main/java/k/K.java:import l.L;
25 -src/main/java/l/L.java:package l;
26 -src/main/java/l/L.java:import k.K;
27 -src/main/java/l/L.java:import m.M;
28 -src/main/java/l/L.java:import n.N;
29 -src/main/java/m/M.java:package m;
30 -src/main/java/m/M.java:import n.N;
31 -src/main/java/n/N.java:package n;
32 -src/main/java/n/N.java:import k.K;
33 -
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 @@ ...@@ -36,7 +36,6 @@
36 <module>yangutils</module> 36 <module>yangutils</module>
37 <module>osgi</module> 37 <module>osgi</module>
38 <module>rest</module> 38 <module>rest</module>
39 - <module>jdvue</module>
40 <module>osgiwrap</module> 39 <module>osgiwrap</module>
41 </modules> 40 </modules>
42 41
......