Skip to content

Commit

Permalink
take possible name errors into account
Browse files Browse the repository at this point in the history
  • Loading branch information
safirex committed Mar 23, 2021
1 parent c66d969 commit 13eb009
Showing 1 changed file with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Gluon and/or its affiliates.
* Copyright (c) 2017, 2020, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -48,6 +48,7 @@
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
Expand All @@ -71,11 +72,17 @@
*
*/
class LibraryFolderWatcher implements Runnable {


private static final Logger LOGGER = Logger.getLogger(LibraryFolderWatcher.class.getSimpleName());

private final UserLibrary library;

private enum FILE_TYPE {FXML, JAR, FOLDER_MARKER};

private enum FILE_TYPE {FXML, JAR, FOLDER_MARKER}

private static final List<String> JAVAFX_MODULES = Arrays.asList(
"javafx-base", "javafx-graphics", "javafx-controls",
"javafx-fxml", "javafx-media", "javafx-web", "javafx-swing");

public LibraryFolderWatcher(UserLibrary library) {
this.library = library;
}
Expand Down Expand Up @@ -347,20 +354,39 @@ private void exploreAndUpdateLibrary(Collection<Path> jarsOrFolders) throws IOEx
final List<JarReport> jarOrFolderReports = new ArrayList<>();
// boolean shouldShowImportGluonJarAlert = false;
for (Path currentJarOrFolder : jarsOrFolders) {
String jarName = currentJarOrFolder.getName(currentJarOrFolder.getNameCount() - 1).toString();
if (JAVAFX_MODULES.stream().anyMatch(jarName::startsWith)) {
continue;
}

JarReport jarReport;
String resultText = "";
if (LibraryUtil.isJarPath(currentJarOrFolder)) {
Logger.getLogger(this.getClass().getSimpleName()).info(I18N.getString("log.info.explore.jar", currentJarOrFolder));
LOGGER.info(I18N.getString("log.info.explore.jar", currentJarOrFolder));
final JarExplorer explorer = new JarExplorer(currentJarOrFolder);
JarReport jarReport = explorer.explore(classLoader);
jarOrFolderReports.add(jarReport);
jarReport = explorer.explore(classLoader);
resultText = I18N.getString("log.info.explore.jar.results", jarName);
}
else if (Files.isDirectory(currentJarOrFolder)) {
Logger.getLogger(this.getClass().getSimpleName()).info(I18N.getString("log.info.explore.folder", currentJarOrFolder));
LOGGER.info(I18N.getString("log.info.explore.folder", currentJarOrFolder));
final FolderExplorer explorer = new FolderExplorer(currentJarOrFolder);
JarReport jarReport = explorer.explore(classLoader);
jarOrFolderReports.add(jarReport);
jarReport = explorer.explore(classLoader);
resultText = I18N.getString("log.info.explore.folder.results", jarName);
} else {
continue;
}

jarOrFolderReports.add(jarReport);

StringBuilder sb = new StringBuilder(resultText).append("\n");
if (jarReport.getEntries().isEmpty()) {
sb.append("> ").append(I18N.getString("log.info.explore.no.results"));
} else {
jarReport.getEntries().forEach(entry -> sb.append("> ").append(entry.toString()).append("\n"));
}
LOGGER.info(sb.toString());

Logger.getLogger(this.getClass().getSimpleName()).info(I18N.getString("log.info.explore.end", currentJarOrFolder));
LOGGER.info(I18N.getString("log.info.explore.end", currentJarOrFolder));

// if (jarReport.hasGluonControls()) {
// // We check if the jar has already been imported to avoid showing the import gluon jar
Expand Down Expand Up @@ -411,18 +437,16 @@ private Collection<LibraryItem> makeLibraryItems(JarReport jarOrFolderReport) th
final String canonicalName = e.getKlass().getCanonicalName();
if (!excludedItems.contains(canonicalName) &&
!artifactsFilter.contains(canonicalName)) {

final String name = e.getKlass().getSimpleName();
String sectionName =jarOrFolderReport.getJar().toString();

// if some os don't use '/' for folder path (don't know if there is)
if (sectionName.lastIndexOf("\\")==-1)
sectionName=UserLibrary.TAG_USER_DEFINED;
else
sectionName=sectionName.substring(sectionName.lastIndexOf("\\")+1,
sectionName.lastIndexOf("."));

final String fxmlText = JarExplorer.makeFxmlText(e.getKlass());

final String name = e.getKlass().getSimpleName();
String sectionName;
try{
sectionName=jarOrFolderReport.getJar().toFile().getName().replace(".jar", "");
}catch(Exception exception){
//if getJar returns null or toFile not finding path
sectionName=UserLibrary.TAG_USER_DEFINED;
}
final String fxmlText = BuiltinLibrary.makeFxmlText(e.getKlass());
result.add(new LibraryItem(name, sectionName, fxmlText, iconURL, library));
}
}
Expand Down

0 comments on commit 13eb009

Please sign in to comment.