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>
This diff is collapsed. Click to expand it.
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 -/*
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
......