Skip to content
Snippets Groups Projects
Commit dbd943b8 authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Minor corrections; Started with a singleton class loader; Modified some code for the quality tools

parent 9e95b83f
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ import javax.faces.bean.ManagedBean; ...@@ -27,6 +27,7 @@ import javax.faces.bean.ManagedBean;
import kieker.analysis.model.analysisMetaModel.MIDependency; import kieker.analysis.model.analysisMetaModel.MIDependency;
import kieker.webgui.common.FileManager; import kieker.webgui.common.FileManager;
import kieker.webgui.common.PluginClassLoader;
import org.primefaces.model.UploadedFile; import org.primefaces.model.UploadedFile;
...@@ -66,19 +67,22 @@ public class AvailableDependenciesBean { ...@@ -66,19 +67,22 @@ public class AvailableDependenciesBean {
* @param file * @param file
* The file to be uploaded. * The file to be uploaded.
*/ */
public synchronized void uploadDependency(final UploadedFile file) { public void uploadDependency(final UploadedFile file) {
final MIDependency dependency = FileManager.getInstance().uploadDependency(file); synchronized (this) {
if (dependency != null) { final MIDependency dependency = FileManager.getInstance().uploadDependency(file);
/* if (dependency != null) {
* Is is possible that we already have a dependency with the same name and have to remove it first. /*
*/ * Is is possible that we already have a dependency with the same name and have to remove it first.
for (final MIDependency dep : this.dependencies) { */
if (dep.getFilePath().equals(dependency.getFilePath())) { for (final MIDependency dep : this.dependencies) {
this.dependencies.remove(dep); if (dep.getFilePath().equals(dependency.getFilePath())) {
break; this.dependencies.remove(dep);
break;
}
} }
PluginClassLoader.getInstance().addURL(dependency.getFilePath());
this.dependencies.add(dependency);
} }
this.dependencies.add(dependency);
} }
} }
...@@ -88,10 +92,13 @@ public class AvailableDependenciesBean { ...@@ -88,10 +92,13 @@ public class AvailableDependenciesBean {
* @param dependency * @param dependency
* The dependency to be removed. * The dependency to be removed.
*/ */
public synchronized void deleteDependency(final MIDependency dependency) { public void deleteDependency(final MIDependency dependency) {
final boolean result = FileManager.getInstance().deleteDependency(dependency); synchronized (this) {
if (result) { final boolean result = FileManager.getInstance().deleteDependency(dependency);
this.dependencies.remove(dependency); if (result) {
PluginClassLoader.getInstance().removeURL(dependency.getFilePath());
this.dependencies.remove(dependency);
}
} }
} }
} }
...@@ -68,29 +68,31 @@ public class AvailableProjectsBean { ...@@ -68,29 +68,31 @@ public class AvailableProjectsBean {
* @param projectName * @param projectName
* The name of the new project. * The name of the new project.
*/ */
public final synchronized void addProject(final String projectName) { public final void addProject(final String projectName) {
/* synchronized (this) {
* Create a new project.
*/
final MIProject project = this.factory.createProject();
project.setName(projectName);
/*
* Try to save the project.
*/
if (FileManager.getInstance().saveNewProject(project)) {
/* /*
* Set the new project as the main project, if the current * Create a new project.
* user doesn't have one.
*/ */
final FacesContext context = FacesContext.getCurrentInstance(); final MIProject project = this.factory.createProject();
final SelectedProjectBean bean = context.getApplication().evaluateExpressionGet(context, "#{selectedProjectBean}", project.setName(projectName);
SelectedProjectBean.class);
if (bean != null && bean.getMainProject() == null) {
bean.setMainProject(project);
}
this.projects.add(project); /*
* Try to save the project.
*/
if (FileManager.getInstance().saveNewProject(project)) {
/*
* Set the new project as the main project, if the current
* user doesn't have one.
*/
final FacesContext context = FacesContext.getCurrentInstance();
final SelectedProjectBean bean = context.getApplication().evaluateExpressionGet(context, "#{selectedProjectBean}",
SelectedProjectBean.class);
if (bean != null && bean.getMainProject() == null) {
bean.setMainProject(project);
}
this.projects.add(project);
}
} }
} }
...@@ -99,19 +101,21 @@ public class AvailableProjectsBean { ...@@ -99,19 +101,21 @@ public class AvailableProjectsBean {
* *
* @return The root of the currently available projects. * @return The root of the currently available projects.
*/ */
public final synchronized TreeNode getProjectsRoot() { public final TreeNode getProjectsRoot() {
final TreeNode root = new DefaultTreeNode("Root", null); synchronized (this) {
final TreeNode root = new DefaultTreeNode("Root", null);
for (final MIProject project : this.projects) {
final TreeNode projectNode = new DefaultTreeNode("project", project, root); for (final MIProject project : this.projects) {
final TreeNode dependenciesNode = new DefaultTreeNode("dependencies", "Dependencies", projectNode); final TreeNode projectNode = new DefaultTreeNode("project", project, root);
final TreeNode usedPluginsNode = new DefaultTreeNode("usedPlugins", "Used Plugins", projectNode); new DefaultTreeNode("dependencies", "Dependencies", projectNode);
for (final MIPlugin plugin : project.getPlugins()) { final TreeNode usedPluginsNode = new DefaultTreeNode("usedPlugins", "Used Plugins", projectNode);
final TreeNode usedPluginNode = new DefaultTreeNode("usedPlugin", plugin.getClassname(), usedPluginsNode); for (final MIPlugin plugin : project.getPlugins()) {
new DefaultTreeNode("usedPlugin", plugin.getClassname(), usedPluginsNode);
}
} }
}
return root; return root;
}
} }
/** /**
...@@ -121,8 +125,10 @@ public class AvailableProjectsBean { ...@@ -121,8 +125,10 @@ public class AvailableProjectsBean {
* @param project * @param project
* The project to be saved. * The project to be saved.
*/ */
public synchronized void saveProject(final MIProject project) { public void saveProject(final MIProject project) {
FileManager.getInstance().saveProject(project); synchronized (this) {
FileManager.getInstance().saveProject(project);
}
} }
/** /**
...@@ -131,10 +137,12 @@ public class AvailableProjectsBean { ...@@ -131,10 +137,12 @@ public class AvailableProjectsBean {
* @param project * @param project
* The project to be removed. * The project to be removed.
*/ */
public synchronized void deleteProject(final MIProject project) { public void deleteProject(final MIProject project) {
final boolean result = FileManager.getInstance().deleteProject(project); synchronized (this) {
if (result) { final boolean result = FileManager.getInstance().deleteProject(project);
this.projects.remove(project); if (result) {
this.projects.remove(project);
}
} }
} }
...@@ -145,7 +153,13 @@ public class AvailableProjectsBean { ...@@ -145,7 +153,13 @@ public class AvailableProjectsBean {
* @param project * @param project
* The project to be reloaded. * The project to be reloaded.
*/ */
public synchronized void resetProject(final MIProject project) { public void resetProject(final MIProject project) {
// TODO Fill method synchronized (this) {
final MIProject result = FileManager.getInstance().reloadProject(project);
if (result != null) {
this.projects.remove(project);
this.projects.add(result);
}
}
} }
} }
...@@ -52,10 +52,6 @@ public class SelectedDependenciesBean { ...@@ -52,10 +52,6 @@ public class SelectedDependenciesBean {
* The currently selected project. * The currently selected project.
*/ */
private final MIProject project; private final MIProject project;
/**
* The faces context of this bean.
*/
private final FacesContext context;
/** /**
* Creates a new instance of this class. * Creates a new instance of this class.
...@@ -66,9 +62,9 @@ public class SelectedDependenciesBean { ...@@ -66,9 +62,9 @@ public class SelectedDependenciesBean {
this.dependencies = new DualListModel<MIDependency>(source, target); this.dependencies = new DualListModel<MIDependency>(source, target);
this.context = FacesContext.getCurrentInstance(); final FacesContext context = FacesContext.getCurrentInstance();
final SelectedProjectBean selProjBean = this.context.getApplication().evaluateExpressionGet(this.context, "#{selectedProjectBean}", final SelectedProjectBean selProjBean = context.getApplication().evaluateExpressionGet(context, "#{selectedProjectBean}",
SelectedProjectBean.class); SelectedProjectBean.class);
if (selProjBean != null) { if (selProjBean != null) {
this.project = selProjBean.getSelectedProject(); this.project = selProjBean.getSelectedProject();
...@@ -78,7 +74,7 @@ public class SelectedDependenciesBean { ...@@ -78,7 +74,7 @@ public class SelectedDependenciesBean {
/* Get all available libs. */ /* Get all available libs. */
final AvailableDependenciesBean availDepBean = this.context.getApplication().evaluateExpressionGet(this.context, "#{availableDependenciesBean}", final AvailableDependenciesBean availDepBean = context.getApplication().evaluateExpressionGet(context, "#{availableDependenciesBean}",
AvailableDependenciesBean.class); AvailableDependenciesBean.class);
this.dependencies.getSource().clear(); this.dependencies.getSource().clear();
if (availDepBean != null) { if (availDepBean != null) {
...@@ -112,7 +108,6 @@ public class SelectedDependenciesBean { ...@@ -112,7 +108,6 @@ public class SelectedDependenciesBean {
* The new dependencies dual model. * The new dependencies dual model.
*/ */
public final void setDependencies(final DualListModel<MIDependency> dependencies) { public final void setDependencies(final DualListModel<MIDependency> dependencies) {
System.out.println(dependencies);
this.dependencies = dependencies; this.dependencies = dependencies;
/* Remember the selected libs. */ /* Remember the selected libs. */
......
...@@ -159,8 +159,8 @@ public class SelectedProjectBean { ...@@ -159,8 +159,8 @@ public class SelectedProjectBean {
public final TreeNode getAvailablePluginsRoot() { public final TreeNode getAvailablePluginsRoot() {
final TreeNode root = new DefaultTreeNode("Root", null); final TreeNode root = new DefaultTreeNode("Root", null);
final TreeNode readerNode = new DefaultTreeNode("default", "Reader", root); new DefaultTreeNode("default", "Reader", root);
final TreeNode analysisPluginsNode = new DefaultTreeNode("default", "AnalysisPlugins", root); new DefaultTreeNode("default", "AnalysisPlugins", root);
return root; return root;
} }
......
...@@ -350,4 +350,26 @@ public final class FileManager { ...@@ -350,4 +350,26 @@ public final class FileManager {
} }
return false; return false;
} }
/**
* This method reloads the given project from the file system.
*
* @param project
* The project to be reloaded.
* @return The reloaded project.
*/
public MIProject reloadProject(final MIProject project) {
final String projectName = project.getName();
final File projectFile = new File(FileManager.PROJECT_DIR + File.separator + projectName + File.separator + projectName + EXTENSION);
if (projectFile.isFile()) {
try {
return AnalysisController.loadFromFile(projectFile);
} catch (Exception ex) {
FileManager.LOG.warn("Error reloaded project '" + projectName + "'");
}
}
return null;
}
} }
/***************************************************************************
* Copyright 2012 by
* + Christian-Albrechts-University of Kiel
* + Department of Computer Science
* + Software Engineering Group
* and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.webgui.common;
import java.net.URL;
/**
* This singleton class is responsible for the dynamic loading of classes.
* Unlike a normal <code>URLClassLoader</code> it is possible to dynamically add
* and remove urls from the class loader. This instance should always be used if
* plugin objects have to be created.
*
* @author Nils Christian Ehmke
*/
public final class PluginClassLoader {
/**
* The singleton instance of this class.
*/
private static final PluginClassLoader INSTANCE = new PluginClassLoader();
/**
* The default constructor of this class.
*/
private PluginClassLoader() {
// Nothing to do
}
/**
* This method can be used to add an url to the class loader.
*
* @param fileName
* The file name of the dependency to be added.
*/
public void addURL(final String fileName) {
// TODO Implement
}
/**
* This method can be used to remove an url from the class loader.
*
* @param fileName
* The file name of the dependency to be removed.
*/
public void removeURL(final String fileName) {
// TODO Implement
}
/**
* Delivers the only instance of this class.
*
* @return The singleton instance of this class.
*/
public static final synchronized PluginClassLoader getInstance() {
return PluginClassLoader.INSTANCE;
}
/**
* This method tries to load the class with the given name using the
* currently loaded dependencies.
*
* @param name
* The name of the class to be loaded.
* @return The class.
*/
public Class<?> loadClass(final String name) {
// TODO Implement
return null;
}
}
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
***************************************************************************/ ***************************************************************************/
package kieker.webgui.common; package kieker.webgui.common;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
...@@ -32,8 +31,6 @@ import java.util.jar.JarFile; ...@@ -32,8 +31,6 @@ import java.util.jar.JarFile;
import kieker.analysis.AnalysisController; import kieker.analysis.AnalysisController;
import kieker.analysis.plugin.port.Plugin; import kieker.analysis.plugin.port.Plugin;
import kieker.common.logging.Log;
import kieker.common.logging.LogFactory;
/** /**
* @author Nils Christian Ehmke * @author Nils Christian Ehmke
...@@ -41,11 +38,6 @@ import kieker.common.logging.LogFactory; ...@@ -41,11 +38,6 @@ import kieker.common.logging.LogFactory;
*/ */
public final class PluginFinder { public final class PluginFinder {
/**
* The logger of this class.
*/
private static final Log LOG = LogFactory.getLog(PluginFinder.class);
/** /**
* Creates a new instance of this class. * Creates a new instance of this class.
*/ */
...@@ -61,12 +53,13 @@ public final class PluginFinder { ...@@ -61,12 +53,13 @@ public final class PluginFinder {
* exception occured. * exception occured.
*/ */
public static List<Class<?>> getAllPluginsWithinJar(final URL url) { public static List<Class<?>> getAllPluginsWithinJar(final URL url) {
URLClassLoader classLoader = null;
try { try {
/* /*
* Get a classloader and make sure that it has the system class * Get a classloader and make sure that it has the system class
* loader as parent and that it knows the url. * loader as parent and that it knows the url.
*/ */
final ClassLoader classLoader = new URLClassLoader(new URL[] { url }, AnalysisController.class.getClassLoader()); classLoader = new URLClassLoader(new URL[] { url }, AnalysisController.class.getClassLoader());
/* /*
* Open the jar file and run through all entries within this file. * Open the jar file and run through all entries within this file.
*/ */
...@@ -98,7 +91,15 @@ public final class PluginFinder { ...@@ -98,7 +91,15 @@ public final class PluginFinder {
return result; return result;
} catch (final IOException ex) { } catch (final IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
return null; } finally {
try {
if (classLoader != null) {
classLoader.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
} }
return null;
} }
} }
...@@ -21,7 +21,6 @@ package kieker.webgui.converter; ...@@ -21,7 +21,6 @@ package kieker.webgui.converter;
import java.io.File; import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.text.DecimalFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
......
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