mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
improve ScmWebPlugin api
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class ScmWebPluginAdapter implements ScmWebPlugin {
|
||||
|
||||
@Override
|
||||
public Module[] getModules()
|
||||
{
|
||||
return new Module[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getScript()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,30 +5,28 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.ServiceUtil;
|
||||
package sonia.scm.web;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.List;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class ScmWebPluginContext
|
||||
public class ClasspathWebResource implements WebResource
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param contentPath
|
||||
*/
|
||||
public ScmWebPluginContext()
|
||||
public ClasspathWebResource(String contentPath)
|
||||
{
|
||||
plugins = ServiceUtil.getServices(ScmWebPlugin.class);
|
||||
this.contentPath = contentPath;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -39,13 +37,14 @@ public class ScmWebPluginContext
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<ScmWebPlugin> getPlugins()
|
||||
@Override
|
||||
public InputStream getContent()
|
||||
{
|
||||
return plugins;
|
||||
return ClasspathWebResource.class.getResourceAsStream(contentPath);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private List<ScmWebPlugin> plugins;
|
||||
private String contentPath;
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
@@ -22,19 +22,7 @@ import java.io.InputStream;
|
||||
public interface ScmWebPlugin
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Module[] getModules();
|
||||
public void contextInitialized( ScmWebPluginContext context );
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public InputStream getScript();
|
||||
public void contextDestroyed( ScmWebPluginContext context );
|
||||
}
|
||||
102
scm-web-api/src/main/java/sonia/scm/web/ScmWebPluginContext.java
Normal file
102
scm-web-api/src/main/java/sonia/scm/web/ScmWebPluginContext.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class ScmWebPluginContext
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param module
|
||||
*/
|
||||
public void addInjectModule(Module module)
|
||||
{
|
||||
injectModules.add(module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param resource
|
||||
*/
|
||||
public void addScriptResource(WebResource resource)
|
||||
{
|
||||
scriptResources.add(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param module
|
||||
*/
|
||||
public void removeInjectModule(Module module)
|
||||
{
|
||||
injectModules.remove(module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param resource
|
||||
*/
|
||||
public void removeScriptResource(WebResource resource)
|
||||
{
|
||||
scriptResources.remove(resource);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<Module> getInjectModules()
|
||||
{
|
||||
return injectModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<WebResource> getScriptResources()
|
||||
{
|
||||
return scriptResources;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Set<WebResource> scriptResources = new HashSet<WebResource>();
|
||||
|
||||
/** Field description */
|
||||
private Set<Module> injectModules = new HashSet<Module>();
|
||||
}
|
||||
31
scm-web-api/src/main/java/sonia/scm/web/WebResource.java
Normal file
31
scm-web-api/src/main/java/sonia/scm/web/WebResource.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface WebResource
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream getContent() throws IOException;
|
||||
}
|
||||
Reference in New Issue
Block a user