From 8a5ce6c345f782acf102e7bacbe1f00b2e1b08a6 Mon Sep 17 00:00:00 2001 From: damjad Date: Thu, 31 Aug 2017 00:25:01 +0500 Subject: [PATCH 1/2] Refactoring: 1. Improved readability. --- .../java/org/jarexplorer/JarExplorer.java | 4 ++-- src/main/java/org/jarexplorer/Util.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jarexplorer/JarExplorer.java b/src/main/java/org/jarexplorer/JarExplorer.java index be43cd9..dfbe51f 100755 --- a/src/main/java/org/jarexplorer/JarExplorer.java +++ b/src/main/java/org/jarexplorer/JarExplorer.java @@ -328,12 +328,12 @@ private void search() { found = results.size(); if(found == 0) { - results = index.search(Util.convertFqnToPath(searchTF.getText(), false)); + results = index.search(Util.convertFqnToPathWithExtension(searchTF.getText())); found = results.size(); } if(found == 0) { - results = index.search(Util.convertFqnToPath(searchTF.getText(), true)); + results = index.search(Util.convertFqnToPathWithoutExtension(searchTF.getText())); found = results.size(); } resultsPanel.setResults("Found substring '" + searchTF.getText() + "' in all jars:", results); diff --git a/src/main/java/org/jarexplorer/Util.java b/src/main/java/org/jarexplorer/Util.java index 687e6f0..fdbdcf7 100755 --- a/src/main/java/org/jarexplorer/Util.java +++ b/src/main/java/org/jarexplorer/Util.java @@ -94,4 +94,25 @@ public static String convertFqnToPath(String resourceName, boolean withExtension return resourceName.replace(".", "/"); } + /** + * Converts a fully qualified name of a java class to its path.
+ * For example: com.hello.world.MainClass.java will converted to com/hello/world/MainClass.java + * @param resourceName Fqn of a file with dots + * @return resource path + */ + public static String convertFqnToPathWithExtension(String resourceName) + { + return convertFqnToPath(resourceName, true); + } + + /** + * Converts a fully qualified name of a java class to its path.
+ * For example: com.hello.world.MainClass will converted to com/hello/world/MainClass + * @param resourceName Fqn of a file with dots + * @return resource path + */ + public static String convertFqnToPathWithoutExtension(String resourceName) + { + return convertFqnToPath(resourceName, false); + } } \ No newline at end of file From 2db8a686d6696e413c26f62ae3ee1b74056ab5a4 Mon Sep 17 00:00:00 2001 From: damjad Date: Wed, 20 Sep 2017 23:06:44 +0500 Subject: [PATCH 2/2] Loading Jar Files from different directories. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added functionality to load JAR’s from different folders or different jars from different folders. This can be done by pasting the comma separated list of paths in the load from csv data box. File -> Load from different directories or Jar Files. --- jarexplorer.iml | 15 --- .../java/org/jarexplorer/JarExplorer.java | 127 ++++++++++++++++++ 2 files changed, 127 insertions(+), 15 deletions(-) delete mode 100644 jarexplorer.iml diff --git a/jarexplorer.iml b/jarexplorer.iml deleted file mode 100644 index fa897cf..0000000 --- a/jarexplorer.iml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/org/jarexplorer/JarExplorer.java b/src/main/java/org/jarexplorer/JarExplorer.java index dfbe51f..570f78f 100755 --- a/src/main/java/org/jarexplorer/JarExplorer.java +++ b/src/main/java/org/jarexplorer/JarExplorer.java @@ -216,6 +216,37 @@ private void showJarContent(String jarFile) { resultsPanel.setResults("Contents of " + jarFile, matchingClasses); } + private void scanFromCSVData() { + + JTextField delimiter = new JTextField(); + JTextField pathData = new JTextField(); + + delimiter.setText(";"); + + final JComponent[] inputs = new JComponent[] { + new JLabel("Delimiter"), + delimiter, + new JLabel("Please enter the paths of different directories or jar files separated by the above delimiter."), + pathData + + }; + + int result = JOptionPane.showConfirmDialog(GUIUtil.getMainFrame(), inputs, "CSV Input", JOptionPane.PLAIN_MESSAGE); + if (result == JOptionPane.OK_OPTION) + { + if (Util.isBlankString(delimiter.getText()) || Util.isBlankString(pathData.getText())) + { + JOptionPane.showInternalMessageDialog(GUIUtil.getMainFrame(), + "Delimiter or path data is missing. Please enter correct delimiter or csv data", + "Error!", + JOptionPane.ERROR_MESSAGE); + } + + scanPath(pathData.getText().split(delimiter.getText())); + } + + } + private void scanPath() { JFileChooser fc; if (prevFile != null) { @@ -262,6 +293,15 @@ public void actionPerformed(ActionEvent e) { fileM.add(loadMI); + JMenuItem loadCommaSeparated = new JMenuItem("Load from Multiple directories or Jar Files"); + loadCommaSeparated.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + scanFromCSVData(); + } + }); + + fileM.add(loadCommaSeparated); + JMenuItem exitMI = new JMenuItem("Exit"); exitMI.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -414,6 +454,93 @@ private void indexJarFile(String canonicalPath) throws IOException { fin.close(); } + /** + * Multi path indexing + * @param pathsStrArray + */ + private void scanPath(String[] pathsStrArray) + { + List files = new ArrayList<>(); + + for (String path : pathsStrArray) + { + File f = new File(path.trim()); + + if (!f.getPath().endsWith(".jar") && f.isFile()) { + GUIUtil.messageBox(this, "Message:", "Can process jar files only"); + return; + } + + files.add(f); + } + scanPath(files); + } + + + /** + * Multi path indexing + * + */ + private void scanPath(final List files) + { + init(); + + Runnable r = new Runnable() + { + public void run() + { + setCursor(new Cursor(Cursor.WAIT_CURSOR)); + progressBar.setIndeterminate(true); + progressBar.setString("Parsing multiple paths !!"); + ArrayList jarNameList = new ArrayList(); + try + { + for (File topDirectory : files) + { + + String treeRoot; + + treeRoot = topDirectory.getCanonicalPath(); + + + if (!topDirectory.exists()) + { + throw new RuntimeException("Path: '" + treeRoot + "' does not exist"); + } + + if (topDirectory.isFile()) + { + jarNameList.add(topDirectory.getCanonicalPath()); + indexJarFile(topDirectory.getCanonicalPath()); + } else + { + scanDirectory(topDirectory, jarNameList); + + } + } + Collections.sort(jarNameList); + jarFilePanel.setJarList(jarNameList); + } catch (Exception e) + { + e.printStackTrace(); + progressBar.setString("failed to parse multi paths"); + GUIUtil.messageBoxWithDetails(JarExplorer.this, "Error Condition:", e); + } finally + { + progressBar.setValue(0); + progressBar.setIndeterminate(false); + progressBar.setString("done path parsing"); + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + GUIUtil.getMainFrame().setTitle(JarExplorer.APP_NAME); + GUIUtil.getMainFrame().repaint(); + } + + } + }; + + new Thread(r, "Parsing Thread").start(); + } + /** * This is where indexing is done. *