Skip to content

Commit

Permalink
Fix up error notification
Browse files Browse the repository at this point in the history
  • Loading branch information
cwisniew committed Aug 26, 2023
1 parent 8230680 commit ca7fe70
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.model.library.Library;
import net.rptools.maptool.model.library.LibraryManager;
import net.rptools.maptool.model.library.LibraryType;
Expand All @@ -35,12 +36,14 @@
/** Class for managing {@link AddOnLibrary} objects. */
public class BuiltInLibraryManager {


/** "Protocol" for built in add-on libraries. */
private static final String LIBRARY_PROTOCOL = "lib";

/** The add-on libraries that are registered. */
private final Map<String, Library> namespaceLibraryMap = new ConcurrentHashMap<>();


public BuiltInLibraryManager() {
registerLibrary(new MapToolBuiltInLibrary());
}
Expand Down Expand Up @@ -130,20 +133,20 @@ public Library getLibrary(URL path) {

/** Initializes the built in libraries. */
public void loadBuiltIns() {
var addonPath = "net/rptools/maptool/libraries/builtin";
var classLoader = Thread.currentThread().getContextClassLoader();

URI uri;
try {
uri = classLoader.getResource(addonPath).toURI();
uri = classLoader.getResource(ClassPathAddOnLibrary.BUILTIN_LIB_CLASSPATH_DIR).toURI();
} catch (URISyntaxException e) {
// TODO: CDW
throw new RuntimeException(e);
MapTool.showError("msg.error.library.builtin.path", e);
return;
}

try (var fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
var resourcePath = fs.getPath(addonPath);
var libs = Files.walk(resourcePath, 1).filter(p -> p.toString().endsWith(".mtlib")).toList();
var resourcePath = fs.getPath(ClassPathAddOnLibrary.BUILTIN_LIB_CLASSPATH_DIR);
var libs =
Files.walk(resourcePath, 1).filter(p -> p.toString().endsWith(AddOnLibraryImporter.DROP_IN_LIBRARY_EXTENSION)).toList();

libs.stream().forEach(System.out::println);
var importer = new AddOnLibraryImporter();
Expand All @@ -157,19 +160,11 @@ public void loadBuiltIns() {
clib.initialize();

} catch (Exception e) {
// TODO: CDW
e.printStackTrace();
MapTool.showError("msg.error.library.builtin.load", e);
}
});
new LibraryManager()
.getLibraries(LibraryType.ADD_ON).stream()
.forEach(
l -> {
System.out.println("Library: " + l.namespace());
});
} catch (IOException | ExecutionException | InterruptedException e) {
// TODO: CDW
e.printStackTrace();
} catch (IOException e) {
MapTool.showError("msg.error.library.builtin.load", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,25 @@

public class ClassPathAddOnLibrary implements BuiltInLibrary {

private final String classPath;
private final String resourceFilePath;

private final AddOnLibrary addOnLibrary;

public ClassPathAddOnLibrary(String classPath, AddOnLibrary addOnLibrary) {
this.classPath = classPath;
/**
* Creates a new instance of {@link ClassPathAddOnLibrary}.
* @param resourceFilePath the resource path for the library.
* @param addOnLibrary the add-on library that was loaded.
*/
public ClassPathAddOnLibrary(String resourceFilePath, AddOnLibrary addOnLibrary) {
this.resourceFilePath = resourceFilePath;
this.addOnLibrary = addOnLibrary;
}

/**
* The directory on the class path for the built in libraries.
*/
public static final String BUILTIN_LIB_CLASSPATH_DIR = "net/rptools/maptool/libraries/builtin";

@Override
public CompletableFuture<String> getVersion() {
return addOnLibrary.getVersion();
Expand Down Expand Up @@ -182,8 +192,8 @@ public Set<MacroDetails> getSlashCommands() {
return addOnLibrary.getSlashCommands();
}

public String getClassPath() {
return classPath;
public String getResourceFilePath() {
return resourceFilePath;
}

void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,8 @@ msg.error.playerDB.errorUpdatingPlayer = Error updating player {0}.
msg.error.playerDB.cantRemovePlayer = Can't remove player {0} to a database which doesn't support removing players.
msg.error.playerDB.noSuchPlayer = Player {0} does not exist in active player database.
msg.error.parsing.handlebars = Error parsing handlebars template {0}.
msg.error.library.builtin.path = Can't resd built-in library path.
msg.error.library.builtin.load = Can't load built-in library {0}.


msg.info.action.disableFoW = FoW disabled.
Expand Down

0 comments on commit ca7fe70

Please sign in to comment.