mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-27 17:59:09 +01:00
store plugin informations with jaxb
This commit is contained in:
@@ -38,6 +38,11 @@ package sonia.scm.plugin;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ConfigurationException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
@@ -45,6 +50,9 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -52,6 +60,18 @@ import java.util.List;
|
||||
public class DefaultPluginBackend implements PluginBackend
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String FILE_STORE = "store.xml";
|
||||
|
||||
/** Field description */
|
||||
private static final Object LOCK_OBJECT = new Object();
|
||||
|
||||
/** the logger for DefaultPluginBackend */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(DefaultPluginBackend.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -64,6 +84,23 @@ public class DefaultPluginBackend implements PluginBackend
|
||||
@Named(ScmBackendModule.DIRECTORY_PROPERTY) File baseDirectory)
|
||||
{
|
||||
this.baseDirectory = baseDirectory;
|
||||
this.storeFile = new File(baseDirectory, FILE_STORE);
|
||||
|
||||
try
|
||||
{
|
||||
storeContext = JAXBContext.newInstance(PluginBackendStore.class);
|
||||
|
||||
if (storeFile.exists())
|
||||
{
|
||||
pluginStore =
|
||||
(PluginBackendStore) storeContext.createUnmarshaller().unmarshal(
|
||||
storeFile);
|
||||
}
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
throw new ConfigurationException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -77,7 +114,14 @@ public class DefaultPluginBackend implements PluginBackend
|
||||
@Override
|
||||
public void addPlugin(PluginInformation plugin)
|
||||
{
|
||||
plugins.add(plugin);
|
||||
if (!pluginStore.contains(plugin))
|
||||
{
|
||||
synchronized (LOCK_OBJECT)
|
||||
{
|
||||
pluginStore.add(plugin);
|
||||
store();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -103,7 +147,7 @@ public class DefaultPluginBackend implements PluginBackend
|
||||
@Override
|
||||
public List<PluginInformation> getPlugins()
|
||||
{
|
||||
return plugins;
|
||||
return pluginStore.getPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +164,7 @@ public class DefaultPluginBackend implements PluginBackend
|
||||
List<PluginInformation> filteredPlugins =
|
||||
new ArrayList<PluginInformation>();
|
||||
|
||||
for (PluginInformation plugin : plugins)
|
||||
for (PluginInformation plugin : pluginStore)
|
||||
{
|
||||
if (filter.accept(plugin))
|
||||
{
|
||||
@@ -131,17 +175,22 @@ public class DefaultPluginBackend implements PluginBackend
|
||||
return filteredPlugins;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param plugins
|
||||
*/
|
||||
public void setPlugins(List<PluginInformation> plugins)
|
||||
private void store()
|
||||
{
|
||||
this.plugins = plugins;
|
||||
try
|
||||
{
|
||||
storeContext.createMarshaller().marshal(pluginStore, storeFile);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
logger.error("could not store pluginStore", ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@@ -150,5 +199,11 @@ public class DefaultPluginBackend implements PluginBackend
|
||||
private File baseDirectory;
|
||||
|
||||
/** Field description */
|
||||
private List<PluginInformation> plugins = new ArrayList<PluginInformation>();
|
||||
private PluginBackendStore pluginStore;
|
||||
|
||||
/** Field description */
|
||||
private JAXBContext storeContext;
|
||||
|
||||
/** Field description */
|
||||
private File storeFile;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlRootElement(name = "plugin-backend")
|
||||
public class PluginBackendStore implements Iterable<PluginInformation>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param e
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean add(PluginInformation e)
|
||||
{
|
||||
return plugins.add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param plugin
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(PluginInformation plugin)
|
||||
{
|
||||
return plugins.contains(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Iterator<PluginInformation> iterator()
|
||||
{
|
||||
return plugins.iterator();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<PluginInformation> getPlugins()
|
||||
{
|
||||
return plugins;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param plugins
|
||||
*/
|
||||
public void setPlugins(List<PluginInformation> plugins)
|
||||
{
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "plugin")
|
||||
@XmlElementWrapper(name = "plugins")
|
||||
private List<PluginInformation> plugins = new ArrayList<PluginInformation>();
|
||||
}
|
||||
@@ -35,6 +35,9 @@ package sonia.scm.plugin.scanner;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.plugin.BackendConfiguration;
|
||||
import sonia.scm.plugin.PluginBackend;
|
||||
|
||||
@@ -51,6 +54,12 @@ import java.util.TimerTask;
|
||||
public class PluginScannerTimerTask extends TimerTask
|
||||
{
|
||||
|
||||
/** the logger for PluginScannerTimerTask */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(PluginScannerTimerTask.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -76,6 +85,11 @@ public class PluginScannerTimerTask extends TimerTask
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("start scann");
|
||||
}
|
||||
|
||||
for (File directory : configuration.getDirectories())
|
||||
{
|
||||
PluginScanner scanner = scannerFactory.createScanner();
|
||||
|
||||
2
scm-plugin-backend/src/main/webapp/META-INF/context.xml
Normal file
2
scm-plugin-backend/src/main/webapp/META-INF/context.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Context antiJARLocking="true" path="/scm-plugin-backend"/>
|
||||
Reference in New Issue
Block a user