Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Directories and Multiple Jar files. #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions jarexplorer.iml

This file was deleted.

131 changes: 129 additions & 2 deletions src/main/java/org/jarexplorer/JarExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -328,12 +368,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);
Expand Down Expand Up @@ -414,6 +454,93 @@ private void indexJarFile(String canonicalPath) throws IOException {
fin.close();
}

/**
* Multi path indexing
* @param pathsStrArray
*/
private void scanPath(String[] pathsStrArray)
{
List<File> 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<File> 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.
*
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/jarexplorer/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br/>
* 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. <br/>
* 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);
}
}