diff --git a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java index 6a726b3e3..31c742be5 100644 --- a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java +++ b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java @@ -286,6 +286,7 @@ public ElementLibrary registerComponentSource(ComponentSource source) { if (jarComponentManager == null) jarComponentManager = new JarComponentManager(this); source.registerComponents(jarComponentManager); + rescanFolder(); } catch (InvalidNodeException e) { exception = e; } diff --git a/src/test/java/de/neemann/digital/draw/library/JarComponentManagerTest.java b/src/test/java/de/neemann/digital/draw/library/JarComponentManagerTest.java index 880511f0c..b60403082 100644 --- a/src/test/java/de/neemann/digital/draw/library/JarComponentManagerTest.java +++ b/src/test/java/de/neemann/digital/draw/library/JarComponentManagerTest.java @@ -13,6 +13,14 @@ import java.io.File; +import de.neemann.digital.core.Model; +import de.neemann.digital.core.NodeException; +import de.neemann.digital.core.ObservableValues; +import de.neemann.digital.core.element.Element; +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.ElementTypeDescription; +import de.neemann.digital.core.element.Keys; + public class JarComponentManagerTest extends TestCase { public void testMissingJar() throws Exception { @@ -28,7 +36,8 @@ public void testJarAvailable() throws Exception { ToBreakRunner br = new ToBreakRunner("dig/jarLib/jarLibTest.dig") { @Override public void initLibrary(ElementLibrary library) { - library.addExternalJarComponents(new File(Resources.getRoot(), "dig/jarLib/pluginExample-1.0-SNAPSHOT.jar")); + library.addExternalJarComponents( + new File(Resources.getRoot(), "dig/jarLib/pluginExample-1.0-SNAPSHOT.jar")); assertNull(library.checkForException()); } }; @@ -36,4 +45,59 @@ public void initLibrary(ElementLibrary library) { for (Circuit.TestCase tc : br.getCircuit().getTestCases()) assertTrue(new TestExecutor(tc, br.getCircuit(), br.getLibrary()).execute().allPassed()); } + + public void testJarDebug() throws Exception { + ElementLibrary library = new ElementLibrary(); + library.registerComponentSource(new CustomTestComponentSource()); + LibraryNode component = library.getElementNodeOrNull("CustomTestComponent"); + assertTrue(component instanceof LibraryNode); + assertEquals(component.getName(), "CustomTestComponent"); + + + } + + private static class CustomTestComponent implements Element { + + /** + * Custom test component description + */ + public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription("CustomTestComponent", + CustomTestComponent.class) + .addAttribute(Keys.LABEL); + + /** + * Creates a new custom test component + * + * @param attr the attributes + */ + @SuppressWarnings("unused") + public CustomTestComponent(ElementAttributes attr) { + } + + @Override + public void setInputs(ObservableValues inputs) throws NodeException { + } + + @Override + public ObservableValues getOutputs() { + return ObservableValues.EMPTY_LIST; + } + + @Override + public void registerNodes(Model model) { + } + } + + private static class CustomTestComponentSource implements ComponentSource { + + /** + * Registers custom test component to component library + */ + @Override + public void registerComponents(ComponentManager manager) throws InvalidNodeException { + + manager.addComponent("CustomTestComponentsLibrary", CustomTestComponent.DESCRIPTION); + + } + } }