From 6298dcb6f74dd244ac8085d2470e2c31a02d3b50 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 25 Dec 2017 14:19:31 +0200 Subject: [PATCH] Proof of concept: it is really possible to render classes as extracted from jar file. --- .../java/CommandlineConfiguration.java | 9 ++++++-- .../eu/svjatoslav/inspector/java/Main.java | 21 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java b/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java index 4c2cbd7..cea0962 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java +++ b/src/main/java/eu/svjatoslav/inspector/java/CommandlineConfiguration.java @@ -7,22 +7,27 @@ import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParamet public class CommandlineConfiguration { + public FileParameter jarFile; + public StringParameter graphName; + public CommandlineConfiguration (String args[]){ Parser parser = buildCommandlineParameterParser(); if (!parser.parse(args)) { parser.showHelp(); + return; } + } public Parser buildCommandlineParameterParser() { Parser parser = new Parser(); - parser.add( + jarFile = parser.add( new FileParameter("JAR file")) .mustExist() .addAliases("-j"); - parser.add( + graphName = parser.add( new StringParameter("graph name")) .setMandatory() .addAliases("-n"); diff --git a/src/main/java/eu/svjatoslav/inspector/java/Main.java b/src/main/java/eu/svjatoslav/inspector/java/Main.java index eda82ee..d651d2e 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/Main.java +++ b/src/main/java/eu/svjatoslav/inspector/java/Main.java @@ -2,6 +2,11 @@ package eu.svjatoslav.inspector.java; import eu.svjatoslav.inspector.java.structure.ClassGraph; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; + import static java.io.File.separator; import static java.lang.System.getProperty; @@ -9,16 +14,26 @@ import static java.lang.System.getProperty; * This class acts as a commandline interface for JavaInspect. */ public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws MalformedURLException, ClassNotFoundException { CommandlineConfiguration commandlineConfiguration = new CommandlineConfiguration(args); System.out.println("Commandline config validated"); + File jarFile = commandlineConfiguration.jarFile.getValue(); + + URLClassLoader classLoader = new URLClassLoader( + new URL[]{jarFile.toURL()}, + commandlineConfiguration.getClass().getClassLoader()); + + Class classToLoad = Class.forName("eu.svjatoslav.sixth.e3d.gui.GuiComponent", true, classLoader); + + ClassGraph cg = new ClassGraph(); cg.setTargetDirectoryPath(getProperty("user.dir") + separator); // cg.addProject(projectDir); // cg.whitelistClassGlob(packageGlob); -// cg.setKeepDotFile(true); -// cg.generateGraph(graphName); + cg.setKeepDotFile(true); + cg.add(classToLoad); + cg.generateGraph(commandlineConfiguration.graphName.getValue()); } } -- 2.20.1