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

Bug Fix | Custom java component not loading properly #1316

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,12 +36,68 @@ 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());
}
};

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);

}
}
}