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

#591, replaced the header with a new version

parent 18c0eefc
No related branches found
No related tags found
No related merge requests found
Showing
with 97 additions and 219 deletions
/***************************************************************************
* Copyright 2012 Kieker Project (http://kieker-monitoring.net)
*
* 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.exception;
/**
* This exception shows that a library with the same name exists already.
*
* @author Nils Christian Ehmke
*/
public final class LibraryAlreadyExistingException extends AbstractKiekerWebGUIException {
private static final long serialVersionUID = 1L;
/**
* Creates a new instance of this class.
*/
public LibraryAlreadyExistingException() {
super();
}
/**
* Creates a new instance of this class using the given parameters.
*
* @param msg
* The message used for the exception.
*/
public LibraryAlreadyExistingException(final String msg) {
super(msg);
}
/**
* Creates a new instance of this class using the given parameters.
*
* @param msg
* The message used for the exception.
* @param cause
* The cause for the exception.
*/
public LibraryAlreadyExistingException(final String msg, final Throwable cause) {
super(msg, cause);
}
}
......@@ -28,7 +28,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import kieker.analysis.model.analysisMetaModel.MIDependency;
import kieker.analysis.model.analysisMetaModel.MIProject;
import kieker.webgui.common.ClassAndMethodContainer;
import kieker.webgui.common.exception.LibraryAlreadyExistingException;
import kieker.webgui.common.exception.NewerProjectException;
import kieker.webgui.common.exception.ProjectAlreadyExistingException;
import kieker.webgui.common.exception.ProjectNotExistingException;
......@@ -144,7 +143,7 @@ public interface IProjectDAO {
public abstract long getCurrTimeStamp(String projectName) throws ProjectNotExistingException;
/**
* This method tries to upload a dependency to the given project.
* This method tries to upload a dependency to the given project. AN existing version will be overwritten.
*
* @param file
* The file to be uploaded to the project.
......@@ -154,11 +153,9 @@ public interface IProjectDAO {
* If a project with the given name does not exist.
* @throws IOException
* If something went wrong during the uploading.
* @throws LibraryAlreadyExistingException
* If a library with the same name exists already.
*/
@PreAuthorize("hasAnyRole('User', 'Administrator')")
public abstract void uploadLibrary(UploadedFile file, String projectName) throws ProjectNotExistingException, IOException, LibraryAlreadyExistingException;
public abstract void uploadLibrary(UploadedFile file, String projectName) throws ProjectNotExistingException, IOException;
/**
* This method delivers a class loader containing the currently available libraries of the given project.
......@@ -228,4 +225,7 @@ public interface IProjectDAO {
@PreAuthorize("isAuthenticated()")
public abstract File getProjectFile(String projectName);
@PreAuthorize("hasAnyRole('User', 'Administrator')")
public abstract boolean deleteLibrary(String projectName, String libName);
}
......@@ -19,15 +19,12 @@ package kieker.webgui.persistence.impl;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.ByteChannel;
import java.nio.channels.FileChannel;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
......@@ -55,7 +52,6 @@ import kieker.analysis.model.analysisMetaModel.impl.MAnalysisMetaModelFactory;
import kieker.common.logging.Log;
import kieker.common.logging.LogFactory;
import kieker.webgui.common.ClassAndMethodContainer;
import kieker.webgui.common.exception.LibraryAlreadyExistingException;
import kieker.webgui.common.exception.NewerProjectException;
import kieker.webgui.common.exception.ProjectAlreadyExistingException;
import kieker.webgui.common.exception.ProjectNotExistingException;
......@@ -197,12 +193,12 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
try {
if (dstProjDir.mkdir() && dstLibDir.mkdir()) {
// Copy the kax file
this.copyFile(srcKaxFile, dstKaxFile);
FileCopyUtils.copy(srcKaxFile, dstKaxFile);
// Copy the libs
for (final File lib : srcLibDir.listFiles()) {
final File dstLibFile = new File(dstLibDir, lib.getName());
this.copyFile(lib, dstLibFile);
FileCopyUtils.copy(lib, dstLibFile);
}
} else {
throw new IOException("Could not create directories.");
......@@ -312,7 +308,7 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
*/
@Override
@PreAuthorize("hasAnyRole('User', 'Administrator')")
public void uploadLibrary(final UploadedFile file, final String projectName) throws ProjectNotExistingException, IOException, LibraryAlreadyExistingException {
public void uploadLibrary(final UploadedFile file, final String projectName) throws ProjectNotExistingException, IOException {
// Check whether the project exists
if (!this.projectExists(projectName)) {
throw new ProjectNotExistingException("A project with the name '" + projectName + "' does not exist.");
......@@ -322,49 +318,12 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
final File libDir = this.assembleLibDir(projectName);
final File dstFile = new File(libDir, file.getFileName());
// Now copy the file - if it doesn't already exist
if (dstFile.exists()) {
throw new LibraryAlreadyExistingException("The library with the name '" + file.getFileName() + "' exists already.");
}
// Get the streams
final BufferedInputStream in = new BufferedInputStream(file.getInputstream());
final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile));
BufferedInputStream in = null;
BufferedOutputStream out = null;
IOException occException = null;
try {
// Get the streams.
in = new BufferedInputStream(file.getInputstream());
out = new BufferedOutputStream(new FileOutputStream(dstFile));
final byte[] buf = new byte[FSProjectDAOImpl.BUF_SIZE_BYTES];
int count;
// Transfer the file.
count = in.read(buf);
while (count != -1) {
out.write(buf, 0, count);
count = in.read(buf);
}
} finally {
// Try to make sure that the streams will be closed.
try {
if (in != null) {
in.close();
}
} catch (final IOException ex) {
occException = ex;
}
try {
if (out != null) {
out.close();
}
} catch (final IOException ex) {
occException = ex;
}
}
// If something went wrong, rethrow the exception
if (occException != null) {
throw occException;
}
// Copy the data - the streams will be closed in this method.
FileCopyUtils.copy(in, out);
}
/*
......@@ -477,83 +436,6 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
return result;
}
/**
* This method copies the given source file to the given destination file.
*
* @param src
* The source element. This should be a file.
* @param dst
* The destination element. This should be a (non existing) file.
* @throws IOException
* If something went wrong. In this case the method will try to close all streams nevertheless.
*/
private void copyFile(final File src, final File dst) throws IOException {
boolean result = true;
// Open the files
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try {
fileInputStream = new FileInputStream(src);
fileOutputStream = new FileOutputStream(dst);
final FileChannel inputChannel = fileInputStream.getChannel();
final FileChannel outputChannel = fileOutputStream.getChannel();
// Copy the data
this.transfer(inputChannel, outputChannel, src.length());
// This is just necessary to calm findbugs
result = dst.setLastModified(src.lastModified());
} catch (final IOException ex) {
FSProjectDAOImpl.LOG.error("An IO error occured", ex);
result = false;
} finally {
// Try to close the streams
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (final IOException ex) {
FSProjectDAOImpl.LOG.error("An IO error occured", ex);
result = false;
}
}
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (final IOException ex) {
FSProjectDAOImpl.LOG.error("An IO error occured", ex);
result = false;
}
}
}
if (!result) {
throw new IOException("An IO error occured");
}
}
/**
* This method transfers data from one channel to the other.
*
* @param fileChannel
* The input channel.
* @param byteChannel
* The output channel.
* @param lengthInBytes
* The size in bytes to be copied.
* @throws IOException
* If something went wrong.
*/
private void transfer(final FileChannel fileChannel, final ByteChannel byteChannel, final long lengthInBytes) throws IOException {
long overallBytesTransfered = 0L;
while (overallBytesTransfered < lengthInBytes) {
final long count = Math.min(FSProjectDAOImpl.BUF_SIZE_BYTES, lengthInBytes - overallBytesTransfered);
final long bytesTransfered = fileChannel.transferTo(overallBytesTransfered, count, byteChannel);
overallBytesTransfered += bytesTransfered;
}
}
/**
* Checks whether a project with the name exists on the file system.
*
......@@ -611,6 +493,19 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
return new File(FSProjectDAOImpl.ROOT_DIRECTORY + File.separator + projectName + File.separator + FSProjectDAOImpl.LIB_DIRECTORY);
}
/*
* (non-Javadoc)
*
* @see kieker.webgui.persistence.IProjectDAO#deleteLibrary(java.lang.String, java.lang.String)
*/
@Override
@PreAuthorize("hasAnyRole('User', 'Administrator')")
public boolean deleteLibrary(final String projectName, final String libName) {
final File libDir = this.assembleLibDir(projectName);
final File libFile = new File(libDir, libName);
return libFile.delete();
}
/*
* (non-Javadoc)
*
......
......@@ -29,7 +29,6 @@ import kieker.webgui.common.ClassAndMethodContainer;
import kieker.webgui.common.exception.AnalysisInitializationException;
import kieker.webgui.common.exception.AnalysisStateException;
import kieker.webgui.common.exception.DisplayNotFoundException;
import kieker.webgui.common.exception.LibraryAlreadyExistingException;
import kieker.webgui.common.exception.LibraryLoadException;
import kieker.webgui.common.exception.NewerProjectException;
import kieker.webgui.common.exception.ProjectAlreadyExistingException;
......@@ -142,7 +141,7 @@ public interface IProjectService {
public long getCurrTimeStamp(final String projectName) throws ProjectNotExistingException;
/**
* This method tries to upload a dependency to the given project.
* This method tries to upload a dependency to the given project. An existing version of the library will be overwritten.
*
* @param file
* The file to be uploaded to the project.
......@@ -152,10 +151,8 @@ public interface IProjectService {
* If a project with the given name does not exist.
* @throws IOException
* If something went wrong during the uploading.
* @throws LibraryAlreadyExistingException
* If a library with the same name exists already.
*/
public void uploadLibrary(final UploadedFile file, final String projectName) throws ProjectNotExistingException, IOException, LibraryAlreadyExistingException;
public void uploadLibrary(final UploadedFile file, final String projectName) throws ProjectNotExistingException, IOException;
/**
* This method delivers a class loader containing the currently available libraries of the given project.
......@@ -198,6 +195,7 @@ public interface IProjectService {
* @return A list with all repository-classes.
* @throws LibraryLoadException
* If something went wrong during the loading of the library.
* @throws IOException
*/
public List<Class<AbstractRepository>> getAllRepositoriesWithinLib(final MIDependency lib, final String project, final ClassLoader classLoader,
final ClassAndMethodContainer classAndMethodContainer) throws LibraryLoadException;
......@@ -346,4 +344,6 @@ public interface IProjectService {
* If the analysis is in an invalid state to deliver the entries.
*/
public Object[] getLogEntries(final String projectName) throws AnalysisStateException;
public boolean deleteLibrary(String projectName, String libName);
}
......@@ -34,7 +34,6 @@ import kieker.webgui.common.ClassAndMethodContainer;
import kieker.webgui.common.exception.AnalysisInitializationException;
import kieker.webgui.common.exception.AnalysisStateException;
import kieker.webgui.common.exception.DisplayNotFoundException;
import kieker.webgui.common.exception.LibraryAlreadyExistingException;
import kieker.webgui.common.exception.LibraryLoadException;
import kieker.webgui.common.exception.NewerProjectException;
import kieker.webgui.common.exception.ProjectAlreadyExistingException;
......@@ -144,7 +143,7 @@ public final class ProjectServiceImpl implements IProjectService {
}
@Override
public void uploadLibrary(final UploadedFile file, final String projectName) throws ProjectNotExistingException, IOException, LibraryAlreadyExistingException {
public void uploadLibrary(final UploadedFile file, final String projectName) throws ProjectNotExistingException, IOException {
final Object projectLock = this.getLock(projectName, this.fileSystemLocks);
synchronized (projectLock) {
......@@ -171,6 +170,8 @@ public final class ProjectServiceImpl implements IProjectService {
return this.pluginFinder.getAllRepositoriesWithinJar(this.projectDAO.getURL(lib, projectName), classLoader, classAndMethodContainer);
} catch (final MalformedURLException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
} catch (final IOException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
}
}
}
......@@ -185,6 +186,8 @@ public final class ProjectServiceImpl implements IProjectService {
return this.pluginFinder.getAllPluginsWithinJar(this.projectDAO.getURL(lib, projectName), classLoader, classAndMethodContainer);
} catch (final MalformedURLException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
} catch (final IOException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
}
}
}
......@@ -197,6 +200,8 @@ public final class ProjectServiceImpl implements IProjectService {
} catch (final NullPointerException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
} catch (final IOException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
}
}
......@@ -205,9 +210,10 @@ public final class ProjectServiceImpl implements IProjectService {
LibraryLoadException {
try {
return this.pluginFinder.getAllPluginsWithinJar(this.projectDAO.getKiekerURL(), classLoader, classAndMethodContainer);
} catch (final NullPointerException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
} catch (final IOException ex) {
throw new LibraryLoadException("An error occured while loading the library.", ex);
}
}
......@@ -318,4 +324,18 @@ public final class ProjectServiceImpl implements IProjectService {
return this.acManager.getLogEntries(projectName);
}
}
/*
* (non-Javadoc)
*
* @see kieker.webgui.service.IProjectService#deleteLibrary(java.lang.String)
*/
@Override
public boolean deleteLibrary(final String projectName, final String libName) {
final Object projectLock = this.getLock(projectName, this.fileSystemLocks);
synchronized (projectLock) {
return this.projectDAO.deleteLibrary(projectName, libName);
}
}
}
......@@ -53,9 +53,10 @@ public final class PluginFinder {
* @param classAndMethodContainer
* The container for the necessary reflection methods.
* @return A list containing all available repository-classes or null, if an exception occurred.
* @throws IOException
*/
public List<Class<AbstractRepository>> getAllRepositoriesWithinJar(final URL url, final ClassLoader classLoader,
final ClassAndMethodContainer classAndMethodContainer) {
final ClassAndMethodContainer classAndMethodContainer) throws IOException {
// Get a list containing all available classes within the given jar
final List<Class<?>> clazzes = this.getAllClassesWithinJar(url, classLoader);
......@@ -86,9 +87,10 @@ public final class PluginFinder {
* @param classAndMethodContainer
* The container for the necessary reflection methods.
* @return A list containing all available plugin-classes or null, if an exception occurred.
* @throws IOException
*/
public List<Class<AbstractPlugin>> getAllPluginsWithinJar(final URL url, final ClassLoader classLoader,
final ClassAndMethodContainer classAndMethodContainer) {
final ClassAndMethodContainer classAndMethodContainer) throws IOException {
final List<Class<?>> clazzes = this.getAllClassesWithinJar(url, classLoader);
List<Class<AbstractPlugin>> result = null;
......@@ -115,7 +117,7 @@ public final class PluginFinder {
* The classloader which should be used to load the classes.
* @return A list containing all available classes or null, if an exception occurred.
*/
private List<Class<?>> getAllClassesWithinJar(final URL url, final ClassLoader classLoader) {
private List<Class<?>> getAllClassesWithinJar(final URL url, final ClassLoader classLoader) throws IOException {
JarInputStream stream = null;
try {
final List<Class<?>> result = new ArrayList<Class<?>>();
......@@ -139,17 +141,16 @@ public final class PluginFinder {
// Don't forget to close the jar file again.
stream.close();
return result;
} catch (final IOException ex) {
} finally {
if (stream != null) {
try {
stream.close();
} catch (final IOException ex1) {
// Ignore this
ex1.printStackTrace();
}
}
ex.printStackTrace();
}
return null;
}
}
......@@ -23,6 +23,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.faces.application.FacesMessage;
......@@ -54,7 +55,6 @@ import kieker.analysis.repository.AbstractRepository;
import kieker.common.logging.Log;
import kieker.common.logging.LogFactory;
import kieker.webgui.common.ClassAndMethodContainer;
import kieker.webgui.common.exception.LibraryAlreadyExistingException;
import kieker.webgui.common.exception.LibraryLoadException;
import kieker.webgui.common.exception.NewerProjectException;
import kieker.webgui.common.exception.ProjectLoadException;
......@@ -85,6 +85,9 @@ import org.eclipse.emf.ecore.EObject;
*/
@Component
@Scope("view")
// TODO Remove libraries in a clean way
// TODO Receive libraries once as MIDependencies instead of Strings
// TODO Use a possibility to reload the classloader explicitly - in this case the manager can close it directly in order to avoid too much memory use
public final class CurrentAnalysisEditorBean {
/**
* This field contains the log-object for the whole class, which will be used to log all important errors and exceptions which occur.
......@@ -222,22 +225,29 @@ public final class CurrentAnalysisEditorBean {
* @throws ProjectLoadException
* If something went wrong during the loading of the libraries.
*/
private synchronized void initializeToolPalette() throws ProjectLoadException {
try {
// Clean our tool palette
this.availableFilters.clear();
this.availableReaders.clear();
this.availableRepositories.clear();
// Run through all libraries and add their content to our lists
for (final MIDependency lib : this.project.getDependencies()) {
private synchronized void initializeToolPalette() {
// Clean our tool palette
this.availableFilters.clear();
this.availableReaders.clear();
this.availableRepositories.clear();
// Run through all libraries and add their content to our lists
final Iterator<MIDependency> dependencies = this.project.getDependencies().iterator();
while (dependencies.hasNext()) {
final MIDependency lib = dependencies.next();
try {
this.addContentsToToolPalette(lib);
} catch (final NullPointerException ex) {
dependencies.remove();
} catch (final LibraryLoadException ex) {
CurrentAnalysisEditorBean.LOG.error("A library could not be loaded correctly.", ex);
}
}
try {
// Run also through the kieker library
this.addKiekerContentsToToolPalette();
} catch (final LibraryLoadException ex) {
CurrentAnalysisEditorBean.LOG.error("A library could not be loaded correctly.", ex);
throw new ProjectLoadException("A library could not be loaded correctly.", ex);
}
}
......@@ -621,9 +631,6 @@ public final class CurrentAnalysisEditorBean {
// We have to reinitialize the tool palette completely! This is necessary as some of the already existing classes could need the newly loaded classes.
this.initializeToolPalette();
} catch (final LibraryAlreadyExistingException ex) {
CurrentAnalysisEditorBean.LOG.info("A library with the same name exists already.", ex);
GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_WARN, this.globalPropertiesBean.getMsgLibraryExistingException());
} catch (final IOException ex) {
CurrentAnalysisEditorBean.LOG.error("An error occured while uploading the library.", ex);
GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgLibraryUploadingException());
......@@ -639,6 +646,17 @@ public final class CurrentAnalysisEditorBean {
}
}
public synchronized void deleteLibrary(final String name) {
if (this.projectService.deleteLibrary(this.projectName, name)) {
// Update our class loader and the available plugins & repositories
this.reloadClassLoader();
this.reloadClassesAndMethods();
// We have to reinitialize the tool palette completely! This is necessary as some of the already existing classes could need the newly loaded classes.
this.initializeToolPalette();
}
}
/**
* This method delivers the available libraries of this project as a pair of strings. The first element is the name of the library, the second one the size in
* MiBytes as human readable string. The first element is always the kieker-library.
......@@ -653,12 +671,11 @@ public final class CurrentAnalysisEditorBean {
return result;
} catch (final ProjectNotExistingException ex) {
CurrentAnalysisEditorBean.LOG.error("The project does not exist.", ex);
return new ArrayList<String>();
} catch (final NullPointerException ex) {
// This exception occurs when a property has not been initialized correctly.
CurrentAnalysisEditorBean.LOG.error("A null pointer exception occured.", ex);
return new ArrayList<String>();
}
return new ArrayList<String>();
}
/**
......
......@@ -19,6 +19,7 @@
<intercept-url pattern="/faces/pages/admin/**" access="hasRole('Administrator')"/>
<!-- The is the guest area. -->
<intercept-url pattern="/pages/" access="isAuthenticated()"/>
<intercept-url pattern="/pages/analysisEditor" access="isAuthenticated()"/>
<intercept-url pattern="/pages/cockpit" access="isAuthenticated()"/>
<intercept-url pattern="/faces/pages/analysisEditor" access="isAuthenticated()"/>
......
......@@ -26,6 +26,6 @@ div.background {
background: #ffffff;
padding: 0 0 0 0;
margin: auto;
width: 1000px;
width: 960px;
min-height: 100%;
}
\ No newline at end of file
......@@ -17,7 +17,7 @@
</p:column>
<p:column headerText="#{localizedAnalysisEditorPageMessages.libOptions}" style="text-align: center; width:40px">
<p:commandButton id="deleteButton" icon="ui-icon-delete" disabled="true"/>
<p:commandButton id="deleteButton" icon="ui-icon-delete" action="#{currentAnalysisEditorBean.deleteLibrary(dependency)}" update=":dependenciesForm :messages :toolpalette"/>
<p:tooltip for="deleteButton" value="Delete Library"/>
</p:column>
</p:dataTable>
......
Kieker.WebGUI/src/main/webapp/img/kieker-header.jpg

84.4 KiB

Kieker.WebGUI/src/main/webapp/img/kieker-header.png

116 KiB

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