remove old ui

This commit is contained in:
Sebastian Sdorra
2018-08-27 15:45:56 +02:00
parent 56b629fa9d
commit b09c46abcf
35 changed files with 99 additions and 3374 deletions

View File

@@ -63,10 +63,6 @@ import sonia.scm.repository.api.HookContextFactory;
import sonia.scm.repository.api.RepositoryServiceFactory;
import sonia.scm.repository.spi.HookEventFacade;
import sonia.scm.repository.xml.XmlRepositoryDAO;
import sonia.scm.resources.DefaultResourceManager;
import sonia.scm.resources.DevelopmentResourceManager;
import sonia.scm.resources.ResourceManager;
import sonia.scm.resources.ScriptResourceServlet;
import sonia.scm.schedule.QuartzScheduler;
import sonia.scm.schedule.Scheduler;
import sonia.scm.security.*;
@@ -266,16 +262,6 @@ public class ScmServletModule extends ServletModule
transformers.addBinding().to(JsonContentTransformer.class);
bind(AdvancedHttpClient.class).to(DefaultAdvancedHttpClient.class);
// bind resourcemanager
if (context.getStage() == Stage.DEVELOPMENT)
{
bind(ResourceManager.class, DevelopmentResourceManager.class);
}
else
{
bind(ResourceManager.class, DefaultResourceManager.class);
}
// bind repository service factory
bind(RepositoryServiceFactory.class);
@@ -295,9 +281,6 @@ public class ScmServletModule extends ServletModule
// debug servlet
serve(PATTERN_DEBUG).with(DebugServlet.class);
// plugin resources
serve(PATTERN_PLUGIN_SCRIPT).with(ScriptResourceServlet.class);
// template
serve(PATTERN_INDEX, "/").with(TemplateServlet.class);

View File

@@ -1,215 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.Collections;
import java.util.List;
/**
*
* @author Sebastian Sdorra
*/
public abstract class AbstractResource implements Resource
{
/**
* the logger for AbstractResource
*/
private static final Logger logger =
LoggerFactory.getLogger(AbstractResource.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
* @param pluginLoader
* @param resources
* @param resourceHandlers
*/
public AbstractResource(PluginLoader pluginLoader, List<String> resources,
List<ResourceHandler> resourceHandlers)
{
this.pluginLoader = pluginLoader;
this.resources = resources;
this.resourceHandlers = resourceHandlers;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param stream
*
* @throws IOException
*/
protected void appendResources(OutputStream stream) throws IOException
{
if (Util.isNotEmpty(resources))
{
for (String resource : resources)
{
appendResource(stream, resource);
}
}
if (Util.isNotEmpty(resourceHandlers))
{
Collections.sort(resourceHandlers, new ResourceHandlerComparator());
for (ResourceHandler resourceHandler : resourceHandlers)
{
processResourceHandler(stream, resourceHandler);
}
}
}
/**
* Method description
*
*
* @param stream
* @param path
*
* @throws IOException
*/
private void appendResource(OutputStream stream, String path)
throws IOException
{
URL resource = getResourceAsURL(path);
if (resource != null)
{
Resources.copy(resource, stream);
}
else if (logger.isWarnEnabled())
{
logger.warn("could not find resource {}", path);
}
}
/**
* Method description
*
*
* @param stream
* @param resourceHandler
*
* @throws IOException
*/
private void processResourceHandler(OutputStream stream,
ResourceHandler resourceHandler)
throws IOException
{
if (resourceHandler.getType() == getType())
{
if (logger.isTraceEnabled())
{
logger.trace("process resource handler {}", resourceHandler.getClass());
}
URL resource = resourceHandler.getResource();
if (resource != null)
{
Resources.copy(resource, stream);
}
else if (logger.isDebugEnabled())
{
logger.debug("resource handler {} does not return a resource",
resourceHandler.getClass());
}
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param path
*
* @return
*/
private URL getResourceAsURL(String path)
{
URL resource = null;
ClassLoader classLoader = pluginLoader.getUberClassLoader();
if (classLoader != null)
{
String classLoaderResource = path;
if (classLoaderResource.startsWith("/"))
{
classLoaderResource = classLoaderResource.substring(1);
}
resource = classLoader.getResource(classLoaderResource);
}
return resource;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected final List<ResourceHandler> resourceHandlers;
/** Field description */
protected final List<String> resources;
/** Field description */
private final PluginLoader pluginLoader;
}

View File

@@ -1,314 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.PluginResources;
//~--- JDK imports ------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
import sonia.scm.plugin.PluginWrapper;
/**
*
* @author Sebastian Sdorra
*/
public abstract class AbstractResourceManager implements ResourceManager
{
/**
* Constructs ...
*
* @param pluginLoader
* @param resourceHandlers
*/
protected AbstractResourceManager(PluginLoader pluginLoader,
Set<ResourceHandler> resourceHandlers)
{
this.pluginLoader = pluginLoader;
this.resourceHandlers = resourceHandlers;
collectResources(resourceMap);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resourceMap
*/
protected abstract void collectResources(Map<ResourceKey,
Resource> resourceMap);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param type
* @param name
*
* @return
*/
@Override
public Resource getResource(ResourceType type, String name)
{
return resourceMap.get(new ResourceKey(name, type));
}
/**
* Method description
*
*
* @param type
*
* @return
*/
@Override
public List<Resource> getResources(ResourceType type)
{
List<Resource> resources = new ArrayList<>();
for (Entry<ResourceKey, Resource> e : resourceMap.entrySet())
{
if (e.getKey().getType() == type)
{
resources.add(e.getValue());
}
}
Collections.sort(resources, ResourceNameComparator.INSTANCE);
return resources;
}
/**
* Method description
*
*
* @return
*/
protected List<String> getScriptResources()
{
List<String> resources = new ArrayList<>();
Collection<PluginWrapper> wrappers = pluginLoader.getInstalledPlugins();
if (wrappers != null)
{
for (PluginWrapper plugin : wrappers)
{
processPlugin(resources, plugin.getPlugin());
}
}
// fix order of script resources, see https://goo.gl/ok03l4
Collections.sort(resources);
return resources;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resources
* @param plugin
*/
private void processPlugin(List<String> resources, Plugin plugin)
{
PluginResources pluginResources = plugin.getResources();
if (pluginResources != null)
{
Set<String> scriptResources = pluginResources.getScriptResources();
if (scriptResources != null)
{
// filter new resources and keep only the old ones, which are starting with a /
List<String> filtered = scriptResources.stream()
.filter((res) -> res.startsWith("/"))
.collect(Collectors.toList());
resources.addAll(filtered);
}
}
}
//~--- inner classes --------------------------------------------------------
/**
* Class description
*
*
* @version Enter version here..., 12/02/03
* @author Enter your name here...
*/
protected static class ResourceKey
{
/**
* Constructs ...
*
*
* @param name
* @param type
*/
public ResourceKey(String name, ResourceType type)
{
this.name = name;
this.type = type;
}
//~--- methods ------------------------------------------------------------
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final ResourceKey other = (ResourceKey) obj;
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
return this.type == other.type;
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
int hash = 7;
hash = 53 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 53 * hash + ((this.type != null)
? this.type.hashCode()
: 0);
return hash;
}
//~--- get methods --------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getName()
{
return name;
}
/**
* Method description
*
*
* @return
*/
public ResourceType getType()
{
return type;
}
//~--- fields -------------------------------------------------------------
/** Field description */
private final String name;
/** Field description */
private final ResourceType type;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected PluginLoader pluginLoader;
/** Field description */
protected Set<ResourceHandler> resourceHandlers;
/** Field description */
protected Map<ResourceKey, Resource> resourceMap = new HashMap<>();
/** Field description */
protected ServletContext servletContext;
}

View File

@@ -1,165 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Sebastian Sdorra
*/
public abstract class AbstractResourceServlet extends HttpServlet
{
/** Field description */
private static final long serialVersionUID = -1774434741744054387L;
/**
* the logger for AbstractResourceServlet
*/
private static final Logger logger =
LoggerFactory.getLogger(AbstractResourceServlet.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param resourceManager
*/
public AbstractResourceServlet(ResourceManager resourceManager)
{
this.resourceManager = resourceManager;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
protected abstract ResourceType getType();
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param request
* @param response
*
* @throws IOException
* @throws ServletException
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String uri = HttpUtil.getStrippedURI(request);
ResourceType type = getType();
String nameSeparator = HttpUtil.SEPARATOR_PATH.concat(
type.getExtension()).concat(
HttpUtil.SEPARATOR_PATH);
int index = uri.indexOf(nameSeparator);
if (index > 0)
{
String name = uri.substring(index + nameSeparator.length());
Resource resource = resourceManager.getResource(type, name);
if (resource != null)
{
printResource(response, resource);
}
else
{
if (logger.isWarnEnabled())
{
logger.warn("no resource with type {} and name {} found", type, name);
}
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
else
{
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
/**
* Method description
*
*
* @param response
* @param resource
*
* @throws IOException
*/
private void printResource(HttpServletResponse response, Resource resource)
throws IOException
{
response.setContentType(resource.getType().getContentType());
try (OutputStream output = response.getOutputStream())
{
resource.copyTo(output);
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final ResourceManager resourceManager;
}

View File

@@ -1,135 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.plugin.PluginLoader;
import sonia.scm.util.ChecksumUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
/**
*
* @author Sebastian Sdorra
*/
public final class DefaultResource extends AbstractResource
{
/**
* Constructs ...
*
*
* @param pluginLoader
* @param resources
* @param resourceHandlers
* @param type
*
* @throws IOException
*/
public DefaultResource(PluginLoader pluginLoader, List<String> resources,
List<ResourceHandler> resourceHandlers, ResourceType type)
throws IOException
{
super(pluginLoader, resources, resourceHandlers);
this.type = type;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream())
{
appendResources(baos);
this.content = baos.toByteArray();
this.name = ChecksumUtil.createChecksum(this.content).concat(".").concat(
type.getExtension());
}
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param output
*
* @throws IOException
*/
@Override
public void copyTo(OutputStream output) throws IOException
{
output.write(content);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getName()
{
return name;
}
/**
* Method description
*
*
* @return
*/
@Override
public ResourceType getType()
{
return type;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final byte[] content;
/** Field description */
private final String name;
/** Field description */
private final ResourceType type;
}

View File

@@ -1,111 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.Lists;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.plugin.PluginLoader;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class DefaultResourceManager extends AbstractResourceManager
{
/**
* the logger for DefaultResourceManager
*/
private static final Logger logger =
LoggerFactory.getLogger(DefaultResourceManager.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
* @param pluginLoader
* @param resourceHandlers
*/
@Inject
public DefaultResourceManager(PluginLoader pluginLoader,
Set<ResourceHandler> resourceHandlers)
{
super(pluginLoader, resourceHandlers);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resourceMap
*/
@Override
protected void collectResources(Map<ResourceKey, Resource> resourceMap)
{
List<String> resources = getScriptResources();
try
{
Resource resource = new DefaultResource(pluginLoader, resources,
Lists.newArrayList(resourceHandlers),
ResourceType.SCRIPT);
resourceMap.put(new ResourceKey(resource.getName(), ResourceType.SCRIPT),
resource);
}
catch (IOException ex)
{
logger.error("could not collect resources", ex);
}
}
}

View File

@@ -1,135 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.plugin.PluginLoader;
import sonia.scm.util.HttpUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
/**
*
* @author Sebastian Sdorra
*/
public final class DevelopmentResource extends AbstractResource
{
/**
* Constructs ...
*
*
* @param pluginLoader
* @param resources
* @param resourceHandlers
* @param name
* @param type
*/
public DevelopmentResource(PluginLoader pluginLoader, List<String> resources,
List<ResourceHandler> resourceHandlers, String name, ResourceType type)
{
super(pluginLoader, resources, resourceHandlers);
this.type = type;
if (name.startsWith(HttpUtil.SEPARATOR_PATH))
{
name = name.substring(1);
}
String ext = ".".concat(type.getExtension());
if (!name.endsWith(ext))
{
name = name.concat(ext);
}
this.name = name;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param output
*
* @throws IOException
*/
@Override
public void copyTo(OutputStream output) throws IOException
{
appendResources(output);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getName()
{
return name;
}
/**
* Method description
*
*
* @return
*/
@Override
public ResourceType getType()
{
return type;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final String name;
/** Field description */
private final ResourceType type;
}

View File

@@ -1,117 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
import sonia.scm.plugin.PluginLoader;
//~--- JDK imports ------------------------------------------------------------
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class DevelopmentResourceManager extends AbstractResourceManager
{
/** Field description */
public static final String PREFIX_HANDLER = "handler/";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param pluginLoader
* @param resourceHandlers
*/
@Inject
public DevelopmentResourceManager(PluginLoader pluginLoader,
Set<ResourceHandler> resourceHandlers)
{
super(pluginLoader, resourceHandlers);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resourceMap
*/
@Override
@SuppressWarnings("unchecked")
protected void collectResources(Map<ResourceKey, Resource> resourceMap)
{
List<String> scripts = getScriptResources();
for (String script : scripts)
{
Resource resource = new DevelopmentResource(pluginLoader,
Arrays.asList(script), Collections.EMPTY_LIST,
script, ResourceType.SCRIPT);
resourceMap.put(new ResourceKey(resource.getName(), ResourceType.SCRIPT),
resource);
}
for (ResourceHandler handler : resourceHandlers)
{
String name = handler.getName();
if (name.startsWith("/"))
{
name = name.substring(1);
}
name = PREFIX_HANDLER.concat(name);
resourceMap.put(new ResourceKey(name, ResourceType.SCRIPT),
new DevelopmentResource(pluginLoader, Collections.EMPTY_LIST,
Arrays.asList(handler), name, ResourceType.SCRIPT));
}
}
}

View File

@@ -1,78 +0,0 @@
/**
* 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.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class ScriptResourceServlet extends AbstractResourceServlet
{
/** Field description */
private static final long serialVersionUID = 1279211769033477225L;
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param resourceManager
*/
@Inject
public ScriptResourceServlet(ResourceManager resourceManager)
{
super(resourceManager);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected ResourceType getType()
{
return ResourceType.SCRIPT;
}
}

View File

@@ -38,30 +38,23 @@ package sonia.scm.template;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.SCMContextProvider;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.resources.ResourceManager;
import sonia.scm.resources.ResourceType;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//~--- JDK imports ------------------------------------------------------------
/**
*
@@ -100,15 +93,12 @@ public class TemplateServlet extends HttpServlet
* @param context
* @param templateEngineFactory
* @param configuration
* @param resourceManager
*/
@Inject
public TemplateServlet(SCMContextProvider context,
TemplateEngineFactory templateEngineFactory,
ResourceManager resourceManager, ScmConfiguration configuration)
TemplateEngineFactory templateEngineFactory, ScmConfiguration configuration)
{
this.templateEngineFactory = templateEngineFactory;
this.resourceManager = resourceManager;
this.configuration = configuration;
this.version = context.getVersion();
}
@@ -123,21 +113,17 @@ public class TemplateServlet extends HttpServlet
* @param response
*
* @throws IOException
* @throws ServletException
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> params = new HashMap<>();
String contextPath = request.getContextPath();
params.put("contextPath", contextPath);
params.put("configuration", configuration);
params.put("version", version);
params.put("scripts", resourceManager.getResources(ResourceType.SCRIPT));
Locale l = request.getLocale();
if (l == null)
@@ -242,9 +228,6 @@ public class TemplateServlet extends HttpServlet
/** Field description */
private final ScmConfiguration configuration;
/** Field description */
private final ResourceManager resourceManager;
/** Field description */
private final TemplateEngineFactory templateEngineFactory;