From 0b442a468607fce2abbeab36d24add7c3a27557d Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Sun, 18 Mar 2012 21:11:51 +0100 Subject: [PATCH] Started with the possibility to connect components; Corrected some bugs; Added some details; Repositories --- .../request/SelectedDependenciesBean.java | 21 +++++++ .../beans/session/DependencyUploadBean.java | 2 +- .../beans/session/SelectedProjectBean.java | 60 +++++++++---------- .../kieker/webgui/common/PluginFinder.java | 47 +++++++++++++-- Kieker.WebGUI/src/main/webapp/main.xhtml | 13 +++- .../main/webapp/main/connectionDialog.xhtml | 34 +++++++++++ .../webgui/common/PluginFinderTest.java | 4 +- 7 files changed, 142 insertions(+), 39 deletions(-) create mode 100644 Kieker.WebGUI/src/main/webapp/main/connectionDialog.xhtml diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/request/SelectedDependenciesBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/request/SelectedDependenciesBean.java index 14f57c5d..5361f515 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/request/SelectedDependenciesBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/request/SelectedDependenciesBean.java @@ -30,6 +30,7 @@ import javax.faces.context.FacesContext; import kieker.analysis.model.analysisMetaModel.MIDependency; import kieker.analysis.model.analysisMetaModel.MIProject; +import kieker.webgui.beans.application.DependenciesBean; import kieker.webgui.beans.session.SelectedProjectBean; /** @@ -62,8 +63,28 @@ public class SelectedDependenciesBean { final SelectedProjectBean selProjBean = context.getApplication().evaluateExpressionGet(context, "#{selectedProjectBean}", SelectedProjectBean.class); + final DependenciesBean depBean = context.getApplication().evaluateExpressionGet(context, "#{dependenciesBean}", + DependenciesBean.class); + if (selProjBean != null) { this.project = selProjBean.getSelectedProject(); + + /* + * The adding of the already existing dependencies within the project is troublesome. As the names cannot be compared, we have to do this manually and + * use our "own" dependencies which we have to compare with the dependencies in the project. + */ + if (depBean != null) { + List<MIDependency> availableDependencies = depBean.getDependencies(); + + for (MIDependency dependency : this.project.getDependencies()) { + for (MIDependency actDependency : availableDependencies) { + if (actDependency.getFilePath().equals(dependency.getFilePath())) { + this.dependencies.add(actDependency); + continue; + } + } + } + } } else { this.project = null; } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/DependencyUploadBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/DependencyUploadBean.java index 4f5f2d04..cfa80a3c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/DependencyUploadBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/DependencyUploadBean.java @@ -74,7 +74,7 @@ public class DependencyUploadBean { public void upload() { if (this.file != null) { final FacesContext context = FacesContext.getCurrentInstance(); - final DependenciesBean bean = context.getApplication().evaluateExpressionGet(context, "#{availableDependenciesBean}", + final DependenciesBean bean = context.getApplication().evaluateExpressionGet(context, "#{dependenciesBean}", DependenciesBean.class); if (bean != null) { bean.uploadDependency(this.file); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/SelectedProjectBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/SelectedProjectBean.java index 9006c55e..6dafef6a 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/SelectedProjectBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/SelectedProjectBean.java @@ -31,18 +31,24 @@ import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; -import kieker.analysis.model.analysisMetaModel.*; + +import kieker.analysis.model.analysisMetaModel.MIAnalysisPlugin; +import kieker.analysis.model.analysisMetaModel.MIDependency; +import kieker.analysis.model.analysisMetaModel.MIPlugin; +import kieker.analysis.model.analysisMetaModel.MIProject; +import kieker.analysis.model.analysisMetaModel.MIProperty; +import kieker.analysis.model.analysisMetaModel.MIReader; import kieker.analysis.model.analysisMetaModel.impl.MAnalysisMetaModelFactory; import kieker.analysis.plugin.AbstractAnalysisPlugin; import kieker.analysis.plugin.AbstractPlugin; import kieker.analysis.plugin.AbstractReaderPlugin; +import kieker.analysis.repository.AbstractRepository; import kieker.common.configuration.Configuration; import kieker.webgui.common.FileManager; import kieker.webgui.common.PluginClassLoader; import kieker.webgui.common.PluginFinder; import org.primefaces.event.NodeSelectEvent; -import org.primefaces.model.DefaultTreeNode; import org.primefaces.model.TreeNode; /** @@ -191,7 +197,7 @@ public class SelectedProjectBean { // TODO Log exception } try { - final List<Class<?>> plugins = PluginFinder.getAllPluginsWithinJar(new URL(SelectedProjectBean.URL_PROTOCOL_FILE, + final List<Class<AbstractPlugin>> plugins = PluginFinder.getAllPluginsWithinJar(new URL(SelectedProjectBean.URL_PROTOCOL_FILE, SelectedProjectBean.URL_LOCALHOST, FileManager.getInstance().getFullPath(lib))); for (final Class<?> plugin : plugins) { if (!Modifier.isAbstract(plugin.getModifiers()) && AbstractReaderPlugin.class.isAssignableFrom(plugin)) { @@ -225,7 +231,7 @@ public class SelectedProjectBean { // TODO Log exception } try { - final List<Class<?>> plugins = PluginFinder.getAllPluginsWithinJar(new URL(SelectedProjectBean.URL_PROTOCOL_FILE, + final List<Class<AbstractPlugin>> plugins = PluginFinder.getAllPluginsWithinJar(new URL(SelectedProjectBean.URL_PROTOCOL_FILE, SelectedProjectBean.URL_LOCALHOST, FileManager.getInstance().getFullPath(lib))); for (final Class<?> plugin : plugins) { if (!Modifier.isAbstract(plugin.getModifiers()) && AbstractAnalysisPlugin.class.isAssignableFrom(plugin)) { @@ -244,35 +250,27 @@ public class SelectedProjectBean { } /** - * Delivers the available plugins. + * This method delivers the available repositories for the current main project. The delivered repositories are never abstract. * - * @return A tree with the available plugins. + * @return A list with all repositories. */ - public final TreeNode getAvailablePluginsRoot() { - final TreeNode root = new DefaultTreeNode("Root", null); - - final TreeNode readerNode = new DefaultTreeNode("default", "Reader", root); - final TreeNode filterNode = new DefaultTreeNode("default", "AnalysisPlugins", root); + public final List<Class<AbstractRepository>> getAvailableRepositories() { + final List<Class<AbstractRepository>> list = new ArrayList<Class<AbstractRepository>>(); if (this.mainProject != null) { for (final MIDependency lib : this.mainProject.getDependencies()) { try { - PluginClassLoader.getInstance().addURL(new URL(SelectedProjectBean.URL_PROTOCOL_FILE, SelectedProjectBean.URL_LOCALHOST, lib.getFilePath())); + PluginClassLoader.getInstance().addURL( + new URL(SelectedProjectBean.URL_PROTOCOL_FILE, SelectedProjectBean.URL_LOCALHOST, FileManager.getInstance().getFullPath(lib))); } catch (final MalformedURLException ex) { // TODO Log exception } try { - final List<Class<?>> plugins = PluginFinder.getAllPluginsWithinJar(new URL(SelectedProjectBean.URL_PROTOCOL_FILE, + final List<Class<AbstractRepository>> repositories = PluginFinder.getAllRepositoriesWithinJar(new URL(SelectedProjectBean.URL_PROTOCOL_FILE, SelectedProjectBean.URL_LOCALHOST, FileManager.getInstance().getFullPath(lib))); - for (final Class<?> plugin : plugins) { - if (!Modifier.isAbstract(plugin.getModifiers())) { - if (AbstractReaderPlugin.class.isAssignableFrom(plugin)) { - new DefaultTreeNode("reader", plugin, readerNode); - } else { - if (AbstractAnalysisPlugin.class.isAssignableFrom(plugin)) { - new DefaultTreeNode("filter", plugin, filterNode); - } - } + for (final Class<AbstractRepository> repository : repositories) { + if (!Modifier.isAbstract(repository.getModifiers())) { + list.add((Class<AbstractRepository>) repository); } } } catch (final MalformedURLException ex) { @@ -281,7 +279,9 @@ public class SelectedProjectBean { } } } - return root; + + return list; + } private static void addConfiguration(final AbstractPlugin plugin, final MIPlugin mPlugin) { @@ -290,11 +290,11 @@ public class SelectedProjectBean { final MAnalysisMetaModelFactory factory = new MAnalysisMetaModelFactory(); /* Run through all entries. */ - Iterator<Map.Entry<Object, Object>> iterator = configuration.entrySet().iterator(); + final Iterator<Map.Entry<Object, Object>> iterator = configuration.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry<Object, Object> entry = iterator.next(); + final Map.Entry<Object, Object> entry = iterator.next(); /* Create a property object for the current entry. */ - MIProperty property = factory.createProperty(); + final MIProperty property = factory.createProperty(); property.setName(entry.getKey().toString()); property.setValue(entry.getValue().toString()); @@ -306,24 +306,24 @@ public class SelectedProjectBean { // TODO It seems like it is necessary to completly load all properties, including the available ports in order to work final MAnalysisMetaModelFactory factory = new MAnalysisMetaModelFactory(); try { - AbstractPlugin plugin = pluginClass.getConstructor(Configuration.class).newInstance(new Configuration()); + final AbstractPlugin plugin = pluginClass.getConstructor(Configuration.class).newInstance(new Configuration()); if (AbstractReaderPlugin.class.isAssignableFrom(pluginClass)) { final MIReader reader = factory.createReader(); reader.setClassname(pluginClass.getCanonicalName()); reader.setName(pluginClass.getSimpleName()); - addConfiguration(plugin, reader); + SelectedProjectBean.addConfiguration(plugin, reader); this.mainProject.getPlugins().add(reader); } else { final MIAnalysisPlugin filter = factory.createAnalysisPlugin(); filter.setClassname(pluginClass.getCanonicalName()); filter.setName(pluginClass.getSimpleName()); - addConfiguration(plugin, filter); + SelectedProjectBean.addConfiguration(plugin, filter); this.mainProject.getPlugins().add(filter); } - } catch (Exception ex) { + } catch (final Exception ex) { // TODO Log exception } } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginFinder.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginFinder.java index c8b003d2..44fce6b1 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginFinder.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginFinder.java @@ -28,7 +28,9 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import kieker.analysis.plugin.AbstractPlugin; import kieker.analysis.plugin.annotation.Plugin; +import kieker.analysis.repository.AbstractRepository; /** * @author Nils Christian Ehmke @@ -41,6 +43,43 @@ public final class PluginFinder { */ private PluginFinder() {} + public static List<Class<AbstractRepository>> getAllRepositoriesWithinJar(final URL url) { + try { + /* + * Open the jar file and run through all entries within this file. + */ + final JarFile jarFile = new JarFile(new File(url.getPath())); + final List<Class<AbstractRepository>> result = new ArrayList<Class<AbstractRepository>>(); + final Enumeration<JarEntry> jarEntries = jarFile.entries(); + while (jarEntries.hasMoreElements()) { + final JarEntry jarEntry = jarEntries.nextElement(); + try { + String name = jarEntry.toString(); + name = name.replace('/', '.'); + name = name.replace(".class", ""); + /* + * Try to find a class with the same name. + */ + final Class<?> c = PluginClassLoader.getInstance().loadClass(name); + /* + * If it is a class and has the annotation - put it into our + * list. + */ + if (AbstractRepository.class.isAssignableFrom(c)) { + result.add((Class<AbstractRepository>) c); + } + } catch (final Throwable ex) { // NOCS (IllegalCatchCheck) + /* Ignore error. */ + } + } + jarFile.close(); + return result; + } catch (final IOException ex) { + ex.printStackTrace(); + } + return null; + } + /** * This method delivers all classes which are available in the given jar and * has the Plugin-Annotation from the Kieker framework. @@ -50,13 +89,13 @@ public final class PluginFinder { * @return A list containing all available plugin-classes or null, if an * exception occured. */ - public static List<Class<?>> getAllPluginsWithinJar(final URL url) { + public static List<Class<AbstractPlugin>> getAllPluginsWithinJar(final URL url) { try { /* * Open the jar file and run through all entries within this file. */ final JarFile jarFile = new JarFile(new File(url.getPath())); - final List<Class<?>> result = new ArrayList<Class<?>>(); + final List<Class<AbstractPlugin>> result = new ArrayList<Class<AbstractPlugin>>(); final Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { final JarEntry jarEntry = jarEntries.nextElement(); @@ -72,8 +111,8 @@ public final class PluginFinder { * If it is a class and has the annotation - put it into our * list. */ - if (c.isAnnotationPresent(Plugin.class)) { - result.add(c); + if (c.isAnnotationPresent(Plugin.class) && AbstractPlugin.class.isAssignableFrom(c)) { + result.add((Class<AbstractPlugin>) c); } } catch (final Throwable ex) { // NOCS (IllegalCatchCheck) /* Ignore error. */ diff --git a/Kieker.WebGUI/src/main/webapp/main.xhtml b/Kieker.WebGUI/src/main/webapp/main.xhtml index 0450f9ac..8bb8ed45 100644 --- a/Kieker.WebGUI/src/main/webapp/main.xhtml +++ b/Kieker.WebGUI/src/main/webapp/main.xhtml @@ -107,6 +107,8 @@ <ui:repeat id="centerRepeat" value="#{selectedProjectBean.mainProject.plugins}" var="plugin"> <p:panel header="#{plugin.name}" closable="true" closeSpeed="200" toggleSpeed="200" toggleable="true" id="plugin" style="width: 30%"> <p:commandLink ajax="true" value="Configure" action="#{selectedPluginBean.setPlugin(plugin)}" update=":propertiesForm"/> + <br/> + <p:commandLink ajax="true" value="Connect" onclick="connectionDialog.show();"/> <p:ajax event="close" listener="#{selectedProjectBean.removePlugin(plugin)}" update=":centerForm"/> </p:panel> <p:draggable for="plugin"> @@ -163,9 +165,11 @@ <p:commandLink value="#{filter.simpleName}" action="#{selectedProjectBean.addPlugin(filter)}" update=":projectsForm :centerForm"/><br/> </ui:repeat> </p:tab> - <p:tab title="Repositories"> - - </p:tab> + <p:tab title="Repositories"> + <ui:repeat value="#{selectedProjectBean.availableRepositories}" var="repository"> + <p:commandLink value="#{repository.simpleName}" update=":projectsForm :centerForm"/><br/> + </ui:repeat> + </p:tab> </p:accordionPanel> </h:form> </p:layoutUnit> @@ -182,6 +186,9 @@ <!-- Include the about-dialog. --> <ui:include src="main\aboutDialog.xhtml" /> + + <!-- Include the dialog to handle the connections. --> + <ui:include src="main\connectionDialog.xhtml" /> </h:body> </f:view> diff --git a/Kieker.WebGUI/src/main/webapp/main/connectionDialog.xhtml b/Kieker.WebGUI/src/main/webapp/main/connectionDialog.xhtml new file mode 100644 index 00000000..fe4f777d --- /dev/null +++ b/Kieker.WebGUI/src/main/webapp/main/connectionDialog.xhtml @@ -0,0 +1,34 @@ +<ui:composition + xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:p="http://primefaces.org/ui"> + + <!-- ******************************************************************************** --> + <!-- This is the dialog for settings and properties. --> + <p:dialog id="connectionDialog" header="Manage Connections" resizable="false" + modal="true" widgetVar="connectionDialog"> + <h:form> + <h:panelGrid columns="4"> + <h:outputText value="Source"/> + <h:outputText value="Output-Port"/> + <h:outputText value="Destination"/> + <h:outputText value="Input-Ports"/> + + <p:selectOneListbox> + <f:selectItems value="#{selectedProjectBean.mainProject.plugins}" var="plugin" itemLabel="#{plugin.name}"/> + </p:selectOneListbox> + <p:selectOneListbox/> + <p:selectOneListbox> + <f:selectItems value="#{selectedProjectBean.mainProject.plugins}" var="plugin" itemLabel="#{plugin.name}"/> + </p:selectOneListbox> + <p:selectManyMenu/> + </h:panelGrid> + <center> + <p:commandButton value="Ok" oncomplete="connectionDialog.hide();" /> + </center> + </h:form> + </p:dialog> + <!-- ******************************************************************************** --> +</ui:composition> \ No newline at end of file diff --git a/Kieker.WebGUI/src/test/java/kieker/webgui/common/PluginFinderTest.java b/Kieker.WebGUI/src/test/java/kieker/webgui/common/PluginFinderTest.java index 66cae18a..cd0720f3 100644 --- a/Kieker.WebGUI/src/test/java/kieker/webgui/common/PluginFinderTest.java +++ b/Kieker.WebGUI/src/test/java/kieker/webgui/common/PluginFinderTest.java @@ -26,6 +26,7 @@ import java.util.List; import junit.framework.Assert; import junit.framework.TestCase; +import kieker.analysis.plugin.AbstractPlugin; import org.junit.Test; @@ -48,7 +49,8 @@ public class PluginFinderTest extends TestCase { /* It can be assumed that the kieker jar contains at least one plugin. */ try { PluginClassLoader.getInstance().addURL(new URL("file", "localhost", "lib/kieker-1.5-SNAPSHOT.jar")); - final List<Class<?>> availableKiekerPlugins = PluginFinder.getAllPluginsWithinJar(new URL("file", "localhost", "lib/kieker-1.5-SNAPSHOT.jar")); + final List<Class<AbstractPlugin>> availableKiekerPlugins = PluginFinder.getAllPluginsWithinJar(new URL("file", "localhost", + "lib/kieker-1.5-SNAPSHOT.jar")); Assert.assertTrue("Kieker-Jar seems to contain no plugins.", availableKiekerPlugins.size() > 0); } catch (final MalformedURLException ex) { Assert.fail("Exception occured."); -- GitLab