+ Moved Demo project from test source directory to dedicated project directory.
+ Added SVG and PNG outputs as configurable options.
+ Migrated to java 8.
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.myproject</groupId>
- <artifactId>myproject</artifactId>
- <version>0.0</version>
- <packaging>jar</packaging>
- <name>MyProject</name>
- <description>MyProject</description>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
+++ /dev/null
-package com.myproject;
-
-public interface Behavior {
-
- String translate(Object obj);
-
- default String serialize(Object obj) {
- return obj.toString();
- }
-}
+++ /dev/null
-package com.myproject;
-
-public class NumberTranslator implements Behavior {
-
- public String translate(Object obj) {
- return serialize(obj);
- }
-}
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6">
- <output url="file://$MODULE_DIR$/target/classes" />
- <output-test url="file://$MODULE_DIR$/target/test-classes" />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/target" />
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
+ <output url="file://$MODULE_DIR$/../../target/classes" />
+ <output-test url="file://$MODULE_DIR$/../../target/test-classes" />
+ <content url="file://$MODULE_DIR$/../..">
+ <sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/../../doc/example" isTestSource="false" />
+ <excludeFolder url="file://$MODULE_DIR$/../../target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Maven: eu.svjatoslav:svjatoslavcommons:1.5" level="project" />
+ <orderEntry type="library" name="Maven: eu.svjatoslav:svjatoslavcommons:1.6" level="project" />
</component>
</module>
\ No newline at end of file
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.8</source>
+ <target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>eu.svjatoslav.inspector.java.methods.Main</mainClass>
+ <mainClass>eu.svjatoslav.inspector.java.Main</mainClass>
</transformer>
</transformers>
</configuration>
<dependency>
<groupId>eu.svjatoslav</groupId>
<artifactId>svjatoslavcommons</artifactId>
- <version>1.5</version>
+ <version>1.6</version>
</dependency>
</dependencies>
--- /dev/null
+package eu.svjatoslav.inspector.java;
+
+import eu.svjatoslav.inspector.java.structure.ClassGraph;
+
+import static java.io.File.separator;
+import static java.lang.System.getProperty;
+
+public class Main {
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ System.err.println("usage: javainspect [PROJECT_DIR] [PACKAGE_GLOB] [GRAPH_NAME]");
+ System.exit(1);
+ }
+
+ String projectDir = args[0];
+ String packageGlob = args[1];
+ String graphName = args[2];
+
+ ClassGraph cg = new ClassGraph();
+ cg.setTargetDirectoryPath(getProperty("user.dir") + separator);
+
+ cg.addProject(projectDir);
+ cg.whitelistClassPattern(packageGlob);
+ cg.setKeepDotFile(true);
+ cg.generateGraph(graphName);
+
+ System.exit(0);
+ }
+}
--- /dev/null
+/*
+ * JavaInspect - Utility to visualize java software
+ * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.inspector.java;
+
+import eu.svjatoslav.inspector.java.structure.ClassGraph;
+import eu.svjatoslav.inspector.java.structure.Utils;
+
+import java.io.FileNotFoundException;
+
+public class RenderJavaInspect {
+
+ private static void fullProjectExample() {
+ // Create graph
+ final ClassGraph graph = new ClassGraph();
+
+ // Recursively scan current directory for Java source code and attempt
+ // to detect class names from there to be added to the graph.
+ graph.addProject(".");
+
+ // do not show single classes with no relationships on the graph
+ graph.hideOrphanedClasses();
+
+ // Produce SVG image titled "JavaInspect full project.png" to the
+ // user Desktop directory.
+ graph.generateGraph("JavaInspect full project");
+ }
+
+ private static void handpickClassesExample() {
+ /*
+ * This example demonstrates generating of class graph from hand picked
+ * classes and visualizing GraphViz itself.
+ */
+
+ // Create graph
+ final ClassGraph graph = new ClassGraph();
+
+ // Add some random object to the graph. GraphViz will detect Class from
+ // the object.
+ graph.add(graph);
+
+ // Also add some random class to the graph.
+ graph.add(Utils.class);
+
+ // Keep intermediary GraphViz DOT file for reference.
+ graph.setKeepDotFile(true);
+
+ // Produce SVG image titled "JavaInspect.svg" to the user Desktop
+ // directory
+ graph.generateGraph("JavaInspect");
+ }
+
+ public static void main(final String[] args) throws FileNotFoundException {
+
+ handpickClassesExample();
+
+ fullProjectExample();
+
+ }
+}
+++ /dev/null
-package eu.svjatoslav.inspector.java.methods;
-
-import eu.svjatoslav.inspector.java.structure.ClassGraph;
-
-import java.io.File;
-
-import static java.lang.System.getProperty;
-
-public class Main {
- public static void main(String[] args) {
- if (args.length == 0) {
- System.err.println("usage: javainspect [PROJECT_DIR] [PACKAGE_GLOB] [GRAPH_NAME]");
- System.exit(1);
- }
-
- String projectDir = args[0];
- String packageGlob = args[1];
- String graphName = args[2];
-
- ClassGraph cg = new ClassGraph();
- cg.setTargetDirectory(getProperty("user.dir") + File.separator);
-
- cg.addProject(projectDir);
- cg.whitelistClassPattern(packageGlob);
- cg.setKeepDotFile(true);
- cg.generateGraph(graphName);
-
- System.exit(0);
- }
-}
/**
* This package contains quickly hacked together Java language parser.
* Goal is to start visualizing method call references and other things
- * which are not easily readable at runtime via reflection.
+ * which are not easily readable at runtime via reflection but are available
+ * when parsing java source code directly.
* <p>
* Work in progress...
* <p>
import java.util.Map;
import static eu.svjatoslav.inspector.java.methods.JavaFile.UTF_8;
+import static java.io.File.separator;
public class ClassGraph {
private final List<String> whitelistClassPatterns = new ArrayList<String>();
- private String targetDirectory = CommonPathResolver.getDesktopDirectory()
- .getAbsolutePath() + "/";
+ private String targetDirectoryPath = CommonPathResolver.getDesktopDirectory()
+ .getAbsolutePath() + separator;
private boolean keepDotFile;
+ TargetImageType targetImageType = TargetImageType.SVG;
+
public ClassGraph() {
}
blacklistClassPatterns.add(pattern);
}
+ public void setTargetImageType(TargetImageType targetImageType) {
+ this.targetImageType = targetImageType;
+ }
+
/**
* @param resultFileName file name for the generated graph. File extension will be
* added automatically. Existing file with the same name will be
public void generateGraph(final String resultFileName) {
- final String dotFilePath = targetDirectory + resultFileName + ".dot";
- final String imageFilePath = targetDirectory + resultFileName + ".svg";
-
- System.out.println("Dot file path:" + dotFilePath);
+ final String dotFilePath = targetDirectoryPath + resultFileName + ".dot";
+ final String imageFilePath = targetDirectoryPath + resultFileName + "." + targetImageType.fileExtension;
try {
// write DOT file to disk
// execute GraphViz to visualize graph
try {
Runtime.getRuntime()
- .exec(new String[]{"dot", "-Tsvg", dotFilePath, "-o",
+ .exec(new String[]{"dot", "-T" + targetImageType.fileExtension, dotFilePath, "-o",
imageFilePath}).waitFor();
} catch (final InterruptedException ignored) {
}
if (!keepDotFile)
// delete dot file
- if (!new File(dotFilePath).delete()) throw new RuntimeException("Cannot delete file: " + dotFilePath);
+ if (!new File(dotFilePath).delete())
+ throw new RuntimeException("Cannot delete file: " + dotFilePath);
+
} catch (final IOException e) {
- System.err.println(e);
+ throw new RuntimeException("Unable to generate graph: " + e.getMessage(), e);
}
}
return this;
}
- public ClassGraph setTargetDirectory(String directoryPath) {
- if (!directoryPath.endsWith("/"))
- directoryPath += "/";
+ public ClassGraph setTargetDirectoryPath(String directoryPath) {
+ if (!directoryPath.endsWith(separator))
+ directoryPath += separator;
- targetDirectory = directoryPath;
+ targetDirectoryPath = directoryPath;
return this;
}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure;
+
+public enum TargetImageType {
+ PNG("png"),
+ SVG("svg");
+
+ public final String fileExtension;
+
+ TargetImageType(String fileExtension){
+ this.fileExtension = fileExtension;
+ }
+}
--- /dev/null
+/*
+ * JavaInspect - Utility to visualize java software
+ * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.inspector.java.structure;
+
+/**
+ * This package contains mostly code that inspects java application by traversing
+ * class references using reflection at runtime.
+ */
+
+++ /dev/null
-/*
- * JavaInspect - Utility to visualize java software
- * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.inspector.java.structure.example;
-
-import eu.svjatoslav.inspector.java.structure.ClassGraph;
-import eu.svjatoslav.inspector.java.structure.example.structure.SampleClass;
-import eu.svjatoslav.inspector.java.structure.example.structure.SampleClass2;
-
-public class RenderDemoClasses {
-
- public static void main(final String[] args) {
-
- new ClassGraph().add(SampleClass.class, SampleClass2.class)
- .generateGraph("example");
- }
-
-}
+++ /dev/null
-/*
- * JavaInspect - Utility to visualize java software
- * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.inspector.java.structure.example;
-
-import eu.svjatoslav.inspector.java.structure.ClassGraph;
-import eu.svjatoslav.inspector.java.structure.Utils;
-
-import java.io.FileNotFoundException;
-
-public class RenderJavaInspect {
-
- private static void fullProjectExample() {
- // Create graph
- final ClassGraph graph = new ClassGraph();
-
- // Recursively scan current directory for Java source code and attempt
- // to detect class names from there to be added to the graph.
- graph.addProject(".");
-
- // Blacklist example classes from being shown on the graph
- graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
-
- // do not show single classes with no relationships on the graph
- graph.hideOrphanedClasses();
-
- // Produce bitmap image titled "JavaInspect full project.png" to the
- // user Desktop directory.
- graph.generateGraph("JavaInspect full project");
- }
-
- private static void handpickClassesExample() {
- /*
- * This example demonstrates generating of class graph from hand picked
- * classes and visualizing GraphViz itself.
- */
-
- // Create graph
- final ClassGraph graph = new ClassGraph();
-
- // Add some random object to the graph. GraphViz will detect Class from
- // the object.
- graph.add(graph);
-
- // Also add some random class to the graph.
- graph.add(Utils.class);
-
- // Keep intermediary GraphViz DOT file for reference.
- graph.setKeepDotFile(true);
-
- // Produce bitmap image titled "JavaInspect.png" to the user Desktop
- // directory
- graph.generateGraph("JavaInspect");
- }
-
- public static void main(final String[] args) throws FileNotFoundException {
-
- handpickClassesExample();
-
- fullProjectExample();
-
- }
-}
+++ /dev/null
-package eu.svjatoslav.inspector.java.structure.example.structure;
-
-public class ObjectReturnedByMethod {
-
-}
+++ /dev/null
-package eu.svjatoslav.inspector.java.structure.example.structure;
-
-public class ObjectVisibleAsClassField {
-
-}
+++ /dev/null
-package eu.svjatoslav.inspector.java.structure.example.structure;
-
-public class SampleClass extends SampleSuperClass {
-
- ObjectVisibleAsClassField sampleClassField;
-
- public ObjectReturnedByMethod sampleMethod() {
- return new ObjectReturnedByMethod();
- }
-
-}
+++ /dev/null
-package eu.svjatoslav.inspector.java.structure.example.structure;
-
-public class SampleClass2 extends SampleSuperClass {
-
-}
+++ /dev/null
-package eu.svjatoslav.inspector.java.structure.example.structure;
-
-public enum SampleEnum {
-
- ONE, TWO, THREE, FOUR
-
-}
+++ /dev/null
-package eu.svjatoslav.inspector.java.structure.example.structure;
-
-public interface SampleInterface {
- SampleEnum getSomeValue();
-}
+++ /dev/null
-package eu.svjatoslav.inspector.java.structure.example.structure;
-
-public class SampleSuperClass implements SampleInterface {
-
- @Override
- public SampleEnum getSomeValue() {
- return SampleEnum.ONE;
- }
-
-}
--- /dev/null
+/.idea/
+/target/
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: eu.svjatoslav:javainspect:1.7-SNAPSHOT" level="project" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>eu.svjatoslav</groupId>
+ <artifactId>javainspect-demo</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Java inspect demo</name>
+ <description>Demonstration project for Java inspect utility</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>eu.svjatoslav</groupId>
+ <artifactId>javainspect</artifactId>
+ <version>1.7-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>svjatoslav.eu</id>
+ <name>Svjatoslav repository</name>
+ <url>http://www2.svjatoslav.eu/maven/</url>
+ </repository>
+ </repositories>
+</project>
--- /dev/null
+/*
+ * JavaInspect - Utility to visualize java software
+ * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.inspector.java.structure.example;
+
+import eu.svjatoslav.inspector.java.structure.ClassGraph;
+import eu.svjatoslav.inspector.java.structure.example.torender.SampleClass;
+import eu.svjatoslav.inspector.java.structure.example.torender.SampleClass2;
+
+public class RenderUsingReflection {
+
+ public static void main(final String[] args) {
+
+ new ClassGraph().add(SampleClass.class, SampleClass2.class)
+ .generateGraph("example");
+ }
+
+}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example.torender;
+
+public class ObjectReturnedByMethod {
+
+}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example.torender;
+
+public class ObjectVisibleAsClassField {
+
+}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example.torender;
+
+public class SampleClass extends SampleSuperClass {
+
+ ObjectVisibleAsClassField sampleClassField;
+
+ public ObjectReturnedByMethod sampleMethod() {
+ return new ObjectReturnedByMethod();
+ }
+
+}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example.torender;
+
+public class SampleClass2 extends SampleSuperClass {
+
+}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example.torender;
+
+public enum SampleEnum {
+
+ ONE, TWO, THREE, FOUR
+
+}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example.torender;
+
+public interface SampleInterface {
+ SampleEnum getSomeValue();
+}
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example.torender;
+
+public class SampleSuperClass implements SampleInterface {
+
+ @Override
+ public SampleEnum getSomeValue() {
+ return SampleEnum.ONE;
+ }
+
+}
--- /dev/null
+#!/bin/bash
+
+cd "${0%/*}"
+
+cd ..
+idea .