Skip to content
Snippets Groups Projects
Commit 6e45b562 authored by nie's avatar nie
Browse files

Added the new kieker-jar and modified the code to suit this new jar; Advanced...

Added the new kieker-jar and modified the code to suit this new jar; Advanced the ClassLoader; Modified code within the xhtml-files; Started with the dependency-choosing for a single project.
parent 778d1f18
No related branches found
No related tags found
No related merge requests found
Showing
with 184 additions and 124 deletions
No preview for this file type
......@@ -3,9 +3,9 @@
<action>
<actionName>run</actionName>
<goals>
<goal>package</goal>
<goal>jetty:run</goal>
</goals>
</action>
</actions>
......@@ -20,12 +20,16 @@
package kieker.webgui.beans.application;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import kieker.analysis.model.analysisMetaModel.MIDependency;
import kieker.common.logging.Log;
import kieker.common.logging.LogFactory;
import kieker.webgui.common.FileManager;
import kieker.webgui.common.PluginClassLoader;
......@@ -39,7 +43,10 @@ import org.primefaces.model.UploadedFile;
@ManagedBean
@ApplicationScoped
public class AvailableDependenciesBean {
/**
* The logger within this class.
*/
private static final Log LOG = LogFactory.getLog(AvailableDependenciesBean.class);
/**
* The list containing the depenencies.
*/
......@@ -80,8 +87,12 @@ public class AvailableDependenciesBean {
break;
}
}
PluginClassLoader.getInstance().addURL(dependency.getFilePath());
this.dependencies.add(dependency);
try {
PluginClassLoader.getInstance().addURL(new URL("file", "localhost", dependency.getFilePath()));
this.dependencies.add(dependency);
} catch (final MalformedURLException ex) {
AvailableDependenciesBean.LOG.error("Could not add the dependency to the ClassLoader.", ex);
}
}
}
}
......@@ -96,8 +107,13 @@ public class AvailableDependenciesBean {
synchronized (this) {
final boolean result = FileManager.getInstance().deleteDependency(dependency);
if (result) {
PluginClassLoader.getInstance().removeURL(dependency.getFilePath());
this.dependencies.remove(dependency);
try {
PluginClassLoader.getInstance().removeURL(new URL("file", "localhost", dependency.getFilePath()));
this.dependencies.remove(dependency);
} catch (final MalformedURLException ex) {
AvailableDependenciesBean.LOG.error("Could not remove the dependency from the ClassLoader.", ex);
}
}
}
}
......
......@@ -19,12 +19,14 @@
***************************************************************************/
package kieker.webgui.beans.application;
import java.io.File;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import kieker.analysis.model.analysisMetaModel.MIDependency;
import kieker.analysis.model.analysisMetaModel.MIPlugin;
import kieker.analysis.model.analysisMetaModel.MIProject;
import kieker.analysis.model.analysisMetaModel.impl.MAnalysisMetaModelFactory;
......@@ -107,11 +109,15 @@ public class AvailableProjectsBean {
for (final MIProject project : this.projects) {
final TreeNode projectNode = new DefaultTreeNode("project", project, root);
new DefaultTreeNode("dependencies", "Dependencies", projectNode);
final TreeNode dependenciesNode = new DefaultTreeNode("dependencies", "Dependencies", projectNode);
final TreeNode usedPluginsNode = new DefaultTreeNode("usedPlugins", "Used Plugins", projectNode);
for (final MIPlugin plugin : project.getPlugins()) {
new DefaultTreeNode("usedPlugin", plugin.getClassname(), usedPluginsNode);
}
for (final MIDependency dependency : project.getDependencies()) {
new DefaultTreeNode("dependencies", new File(dependency.getFilePath()).getName(), dependenciesNode);
}
}
return root;
......
......@@ -29,11 +29,8 @@ import javax.faces.context.FacesContext;
import kieker.analysis.model.analysisMetaModel.MIDependency;
import kieker.analysis.model.analysisMetaModel.MIProject;
import kieker.webgui.beans.application.AvailableDependenciesBean;
import kieker.webgui.beans.session.SelectedProjectBean;
import org.primefaces.model.DualListModel;
/**
* This bean contains the currently choosen dependencies.
*
......@@ -44,23 +41,11 @@ import org.primefaces.model.DualListModel;
@RequestScoped
public class SelectedDependenciesBean {
/**
* A dual model containing all available dependencies and the currently choosen one.
*/
private DualListModel<MIDependency> dependencies;
/**
* The currently selected project.
*/
private List<MIDependency> dependencies;
private final MIProject project;
/**
* Creates a new instance of this class.
*/
public SelectedDependenciesBean() {
final List<MIDependency> source = new ArrayList<MIDependency>();
final List<MIDependency> target = new ArrayList<MIDependency>();
this.dependencies = new DualListModel<MIDependency>(source, target);
this.dependencies = new ArrayList<MIDependency>();
final FacesContext context = FacesContext.getCurrentInstance();
......@@ -71,49 +56,94 @@ public class SelectedDependenciesBean {
} else {
this.project = null;
}
/* Get all available libs. */
final AvailableDependenciesBean availDepBean = context.getApplication().evaluateExpressionGet(context, "#{availableDependenciesBean}",
AvailableDependenciesBean.class);
this.dependencies.getSource().clear();
if (availDepBean != null) {
this.dependencies.getSource().addAll(availDepBean.getDependencies());
}
this.dependencies.getTarget().clear();
/* Now move the already selected to the right side. */
if (this.project != null) {
final List<MIDependency> projectLibs = this.project.getDependencies();
for (final MIDependency lib : projectLibs) {
this.dependencies.getSource().remove(lib);
this.dependencies.getTarget().add(lib);
}
}
}
/**
* Delivers the stored dependencies within this bean.
*
* @return The dependencies dual model.
*/
public final DualListModel<MIDependency> getDependencies() {
//
// /**
// * A dual model containing all available dependencies and the currently choosen one.
// */
// private DualListModel<MIDependency> dependencies;
// /**
// * The currently selected project.
// */
// private final MIProject project;
//
// /**
// * Creates a new instance of this class.
// */
// public SelectedDependenciesBean() {
// final List<MIDependency> source = new ArrayList<MIDependency>();
// final List<MIDependency> target = new ArrayList<MIDependency>();
//
// this.dependencies = new DualListModel<MIDependency>(source, target);
//
// final FacesContext context = FacesContext.getCurrentInstance();
//
// final SelectedProjectBean selProjBean = context.getApplication().evaluateExpressionGet(context, "#{selectedProjectBean}",
// SelectedProjectBean.class);
// if (selProjBean != null) {
// this.project = selProjBean.getSelectedProject();
// } else {
// this.project = null;
// }
//
// /* Get all available libs. */
//
// final AvailableDependenciesBean availDepBean = context.getApplication().evaluateExpressionGet(context, "#{availableDependenciesBean}",
// AvailableDependenciesBean.class);
// this.dependencies.getSource().clear();
// if (availDepBean != null) {
// this.dependencies.getSource().addAll(availDepBean.getDependencies());
// }
// this.dependencies.getTarget().clear();
//
// /* Now move the already selected to the right side. */
// if (this.project != null) {
// final List<MIDependency> projectLibs = this.project.getDependencies();
// for (final MIDependency lib : projectLibs) {
// this.dependencies.getSource().remove(lib);
// this.dependencies.getTarget().add(lib);
// }
// }
// }
//
// /**
// * Delivers the stored dependencies within this bean.
// *
// * @return The dependencies dual model.
// */
// public final DualListModel<MIDependency> getDependencies() {
// return this.dependencies;
// }
//
// /**
// * Sets the dependencies to be stored within this bean to a new value.
// *
// * @param dependencies
// * The new dependencies dual model.
// */
// public final void setDependencies(final DualListModel<MIDependency> dependencies) {
// this.dependencies = dependencies;
// /* Remember the selected libs. */
// if (this.project != null) {
// this.project.getDependencies().clear();
// this.project.getDependencies().addAll(dependencies.getTarget());
// }
// }
public List<MIDependency> getDependencies() {
return this.dependencies;
}
/**
* Sets the dependencies to be stored within this bean to a new value.
*
* @param dependencies
* The new dependencies dual model.
*/
public final void setDependencies(final DualListModel<MIDependency> dependencies) {
public void setDependencies(final List<MIDependency> dependencies) {
this.dependencies = dependencies;
}
/* Remember the selected libs. */
public void submit() {
// TODO Error while executing this method
if (this.project != null) {
this.project.getDependencies().clear();
this.project.getDependencies().addAll(dependencies.getTarget());
this.project.getDependencies().addAll(this.dependencies);
}
}
......
......@@ -144,7 +144,7 @@ public final class FileManager {
final File fileProject = new File(dirProject, projectName + FileManager.EXTENSION);
try {
final AnalysisController controller = new AnalysisController(project);
return controller.saveToFile(fileProject, projectName);
return controller.saveToFile(fileProject);
} catch (final Exception ex) {
FileManager.LOG.error("Could not save project '" + projectName + "'.");
return false;
......
......@@ -21,6 +21,11 @@
package kieker.webgui.common;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Iterator;
import kieker.analysis.AnalysisController;
/**
* This singleton class is responsible for the dynamic loading of classes.
......@@ -29,6 +34,7 @@ import java.net.URL;
* plugin objects have to be created.
*
* @author Nils Christian Ehmke
* @version 1.0
*/
public final class PluginClassLoader {
......@@ -36,6 +42,10 @@ public final class PluginClassLoader {
* The singleton instance of this class.
*/
private static final PluginClassLoader INSTANCE = new PluginClassLoader();
/**
* This list contains a class loader for each url added to this class loader.
*/
private final HashMap<URL, URLClassLoader> classLoaders = new HashMap<URL, URLClassLoader>();
/**
* The default constructor of this class.
......@@ -47,20 +57,23 @@ public final class PluginClassLoader {
/**
* This method can be used to add an url to the class loader.
*
* @param fileName
* The file name of the dependency to be added.
* @param url
* The URL of the dependency to be added.
*/
public void addURL(final String fileName) {
// TODO Implement
public void addURL(final URL url) {
final URLClassLoader newClassLoader = new URLClassLoader(new URL[] { url }, AnalysisController.class.getClassLoader());
synchronized (this) {
this.classLoaders.put(url, newClassLoader);
}
}
/**
* This method can be used to remove an url from the class loader.
*
* @param fileName
* The file name of the dependency to be removed.
* @param url
* The URL of the dependency to be added.
*/
public void removeURL(final String fileName) {
public void removeURL(final URL url) {
// TODO Implement
}
......@@ -80,9 +93,24 @@ public final class PluginClassLoader {
* @param name
* The name of the class to be loaded.
* @return The class.
* @throws ClassNotFoundException
* If a class with the given name could not be found.
*/
public Class<?> loadClass(final String name) {
// TODO Implement
return null;
public Class<?> loadClass(final String name) throws ClassNotFoundException {
synchronized (this) {
/* Run through all available class loaders and try to find the correct class. */
final Iterator<URLClassLoader> classLoaderIter = this.classLoaders.values().iterator();
while (classLoaderIter.hasNext()) {
final URLClassLoader currClassLoader = classLoaderIter.next();
/* If no exception is thrown, we found the correct class and return it. Otherwise we continue the search. */
try {
final Class<?> resultingClass = currClassLoader.loadClass(name);
return resultingClass;
} catch (final ClassNotFoundException ex) {
}
}
}
/* We were not able to found any class and throw an exception. */
throw new ClassNotFoundException();
}
}
......@@ -22,15 +22,13 @@ package kieker.webgui.common;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import kieker.analysis.AnalysisController;
import kieker.analysis.plugin.port.Plugin;
import kieker.analysis.plugin.annotation.Plugin;
/**
* @author Nils Christian Ehmke
......@@ -53,13 +51,7 @@ public final class PluginFinder {
* exception occured.
*/
public static List<Class<?>> getAllPluginsWithinJar(final URL url) {
URLClassLoader classLoader = null;
try {
/*
* Get a classloader and make sure that it has the system class
* loader as parent and that it knows the url.
*/
classLoader = new URLClassLoader(new URL[] { url }, AnalysisController.class.getClassLoader());
/*
* Open the jar file and run through all entries within this file.
*/
......@@ -75,7 +67,7 @@ public final class PluginFinder {
/*
* Try to find a class with the same name.
*/
final Class<?> c = classLoader.loadClass(name);
final Class<?> c = PluginClassLoader.getInstance().loadClass(name);
/*
* If it is a class and has the annotation - put it into our
* list.
......@@ -87,18 +79,10 @@ public final class PluginFinder {
/* Ignore error. */
}
}
//jarFile.close();
jarFile.close();
return result;
} catch (final IOException ex) {
ex.printStackTrace();
} finally {
/*try {
if (classLoader != null) {
classLoader.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}*/
}
return null;
}
......
......@@ -19,8 +19,8 @@
***************************************************************************/
package kieker.webgui.converter;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
......@@ -104,8 +104,8 @@ public class MIDependencyToCountPluginsConverter implements Converter {
return "";
} else {
/* Try to find the library within the cache. */
if (this.cache.containsKey((MIDependency) o)) {
return this.cache.get((MIDependency) o);
if (this.cache.containsKey(o)) {
return this.cache.get(o);
}
/* If the cache is too big, remove one of the objects. */
if (this.cache.size() > MIDependencyToCountPluginsConverter.MAX_CACHE_SIZE) {
......@@ -113,7 +113,7 @@ public class MIDependencyToCountPluginsConverter implements Converter {
}
String result;
try {
result = Integer.toString(PluginFinder.getAllPluginsWithinJar(new File(((MIDependency) o).getFilePath()).toURL()).size());
result = Integer.toString(PluginFinder.getAllPluginsWithinJar(new URL("file", "localhost", ((MIDependency) o).getFilePath())).size());
} catch (final MalformedURLException ex) {
result = "";
} catch (final NullPointerException ex) {
......
......@@ -17,9 +17,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.webgui.converter;
import java.io.File;
import java.util.HashMap;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
......@@ -29,8 +31,7 @@ import javax.faces.convert.FacesConverter;
import kieker.analysis.model.analysisMetaModel.MIDependency;
/**
* This converter can be used to convert an instance of <i>MIDependency</i> to a
* human readable string, but <b>not</b> vice versa.
* This converter can be used to convert an instance of <i>MIDependency</i> to a human readable string, but <b>not</b> vice versa.
*
* @author Nils Christian Ehmke
* @version 1.0
......@@ -47,7 +48,9 @@ public class MIDependencyToStringConverter implements Converter {
* Creates a new instance of this class.
*/
public MIDependencyToStringConverter() {
/* No code necessary. */
/*
* No code necessary.
*/
}
/**
......@@ -56,11 +59,10 @@ public class MIDependencyToStringConverter implements Converter {
* @param fc
* The FacesContext for the request being processed.
* @param uic
* The component with which this model object value is
* associated.
* The component with which this model object value is associated.
* @param string
* The string to be converted.
* @return null
* @return null;
*/
@Override
public Object getAsObject(final FacesContext fc, final UIComponent uic, final String string) {
......@@ -68,18 +70,15 @@ public class MIDependencyToStringConverter implements Converter {
}
/**
* This method converts the given object (on condition that it is an
* instance of the class <code>MIDependency</code>) to a human readable string.
* This method converts the given object (on condition that it is an instance of the class <code>MIDependency</code>) to a human readable string.
*
* @param fc
* The FacesContext for the request being processed.
* @param uic
* The component with which this model object value is
* associated.
* The component with which this model object value is associated.
* @param o
* The object to be converted.
* @return A human readable represantation of the given object or null, of
* the object is from the wrong class.
* @return A human readable represantation of the given object or null, of the object is from the wrong class.
*/
@Override
public String getAsString(final FacesContext fc, final UIComponent uic, final Object o) {
......
......@@ -18,9 +18,7 @@
<!-- The control panel to get back. -->
<h:form>
Click
<p:commandLink ajax="false" action="/main">
<h:outputText value="here" />
</p:commandLink>
<h:link outcome="/main">here</h:link>
to get back to the main menu.
</h:form>
</p:layoutUnit>
......
......@@ -15,24 +15,22 @@
<p:layout fullPage="true">
<p:layoutUnit header="Navigation" position="north" collapsible="true" resizable="true">
<!-- The control panel to get back. -->
<h:form>
Click
<p:commandLink ajax="false" action="/main">
<h:outputText value="here" />
</p:commandLink>
to get back to the main menu.
</h:form>
Click
<h:link outcome="/main">here</h:link>
to get back to the main menu.
</p:layoutUnit>
<p:layoutUnit header="Currently used Dependencies" position="center" >
<div align="center">
<p:pickList id="pickList" value="#{selectedDependenciesBean.dependencies}" var="dependency"
itemLabel="#{dependency.getFilePath()}" itemValue="#{dependency}"
converter="kieker.webgui.converter.MIDependencyToStringConverter" >
<f:facet name="sourceCaption">Available</f:facet>
<f:facet name="targetCaption">Project</f:facet>
</p:pickList>
</div>
<h:form>
<p:selectManyCheckbox value="#{selectedDependenciesBean.dependencies}"
layout="pageDirection">
<f:selectItems value="#{availableDependenciesBean.dependencies}" />
</p:selectManyCheckbox>
<p:spacer width="0px" height="20px"/>
<div align="center">
<p:commandButton ajax="false" value="Submit" actionListener="#{selectedDependenciesBean.submit()}"/>
</div>
</h:form>
</p:layoutUnit>
</p:layout>
......
......@@ -20,12 +20,13 @@
package kieker.webgui.common;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.Test;
/**
......@@ -43,8 +44,8 @@ public class PluginFinderTest extends TestCase {
public void testKiekerJarContainsPlugins() {
/* It can be assumed that the kieker jar contains at least one plugin. */
try {
final List<Class<?>> availableKiekerPlugins = PluginFinder.getAllPluginsWithinJar(new File("lib/kieker-1.5-SNAPSHOT.jar").toURL());
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"));
Assert.assertTrue("Kieker-Jar seems to contain no plugins.", availableKiekerPlugins.size() > 0);
} catch (final MalformedURLException ex) {
Assert.fail("Exception occured.");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment