Commits

Sebastian Sdorra committed 5fd6ec9

package refactoring

Comments (0)

Files changed (49)

scm-plugin-backend/src/main/java/sonia/scm/plugin/BaseDirectory.java

 {
 
   /** Field description */
+  static final String DIRECTORY_PROPERTY = "scm-backend.home";
+
+  /** Field description */
   private static final String DIRECTORY_DEFAULT = ".scm-backend";
 
   /** Field description */
   private static final String DIRECTORY_ENVIRONMENT = "SCMBACKEND_HOME";
 
   /** Field description */
-  static final String DIRECTORY_PROPERTY = "scm-backend.home";
-
-  /** Field description */
   private static BaseDirectory instance;
 
   //~--- constructors ---------------------------------------------------------

scm-plugin-backend/src/main/java/sonia/scm/plugin/PluginInformationNameComparator.java

  * @author Sebastian Sdorra
  */
 public class PluginInformationNameComparator
-        implements Comparator<PluginInformation>
+  implements Comparator<PluginInformation>
 {
 
   /** Field description */

scm-plugin-backend/src/main/java/sonia/scm/plugin/PluginInformationVersionComparator.java

  * @author Sebastian Sdorra
  */
 public class PluginInformationVersionComparator
-        implements Comparator<PluginInformation>
+  implements Comparator<PluginInformation>
 {
 
   /** Field description */
     if (Util.isNotEmpty(v1) && Util.isNotEmpty(v2))
     {
       if (PluginVersion.createVersion(v1).isNewer(
-              PluginVersion.createVersion(v2)))
+        PluginVersion.createVersion(v2)))
       {
         result = -1;
       }

scm-plugin-backend/src/main/java/sonia/scm/plugin/PluginUtil.java

    * @return
    */
   public static List<PluginInformation> filterSameVersions(
-          List<PluginInformation> plugins)
+    List<PluginInformation> plugins)
   {
     List<PluginInformation> filteredPlugins =
       new ArrayList<PluginInformation>();
    * @return
    */
   public static List<PluginInformation> filterSnapshots(
-          List<PluginInformation> allVersions)
+    List<PluginInformation> allVersions)
   {
     List<PluginInformation> filtered = new ArrayList<PluginInformation>();
 
    * @return
    */
   public static List<PluginInformation> getFilteredPluginVersions(
-          PluginBackend backend, String groupId, String artifactId)
+    PluginBackend backend, String groupId, String artifactId)
   {
     List<PluginInformation> pluginVersions =
       PluginUtil.getPluginVersions(backend, groupId, artifactId);
     if (Util.isNotEmpty(pluginVersions))
     {
       Collections.sort(pluginVersions,
-                       PluginInformationNameComparator.INSTANCE);
+        PluginInformationNameComparator.INSTANCE);
       pluginVersions = PluginUtil.filterSameVersions(pluginVersions);
     }
 
    * @return
    */
   public static PluginInformation getLatestPluginVersion(PluginBackend backend,
-          String groupId, String artifactId)
+    String groupId, String artifactId)
   {
     return getFilteredPluginVersions(backend, groupId, artifactId).get(0);
   }
    * @return
    */
   public static List<PluginInformation> getPluginVersions(
-          PluginBackend backend, final String groupId, final String artifactId)
+    PluginBackend backend, final String groupId, final String artifactId)
   {
     List<PluginInformation> pluginVersions =
       backend.getPlugins(new PluginFilter()
       public boolean accept(PluginInformation plugin)
       {
         return groupId.equals(plugin.getGroupId())
-               && artifactId.equals(plugin.getArtifactId());
+          && artifactId.equals(plugin.getArtifactId());
       }
     });
 

scm-plugin-backend/src/main/java/sonia/scm/plugin/RedirectFilter.java

 //~--- non-JDK imports --------------------------------------------------------
 
 import com.google.inject.Singleton;
+
 import sonia.scm.web.filter.HttpFilter;
 
 //~--- JDK imports ------------------------------------------------------------
 @Singleton
 public class RedirectFilter extends HttpFilter
 {
-  
+
+  /** Field description */
   private static final String STARTPAGE = "/page/index.html";
 
+  //~--- methods --------------------------------------------------------------
+
   /**
    * Method description
    *

scm-plugin-backend/src/main/java/sonia/scm/plugin/Roles.java

  * http://bitbucket.org/sdorra/scm-manager
  *
  */
+
+
+
 package sonia.scm.plugin;
 
 /**
  */
 public class Roles
 {
+
+  /** Field description */
   public static final String ADMIN = "admin";
 }

scm-plugin-backend/src/main/java/sonia/scm/plugin/ScmBackendModule.java

 import net.sf.ehcache.CacheManager;
 
 import sonia.scm.ConfigurationException;
-import sonia.scm.plugin.rest.PluginResource;
-import sonia.scm.plugin.rest.url.BitbucketUrlBuilder;
-import sonia.scm.plugin.rest.url.GithubUrlBuilder;
-import sonia.scm.plugin.rest.url.UrlBuilder;
-import sonia.scm.plugin.rest.url.UrlBuilderFactory;
+import sonia.scm.plugin.rest.api.PluginResource;
 import sonia.scm.plugin.scanner.DefaultPluginScannerFactory;
 import sonia.scm.plugin.scanner.PluginScannerFactory;
 import sonia.scm.plugin.scanner.PluginScannerScheduler;
 import sonia.scm.plugin.scanner.TimerPluginScannerScheduler;
+import sonia.scm.plugin.url.BitbucketUrlBuilder;
+import sonia.scm.plugin.url.GithubUrlBuilder;
+import sonia.scm.plugin.url.UrlBuilder;
+import sonia.scm.plugin.url.UrlBuilderFactory;
 import sonia.scm.web.proxy.ProxyConfigurationProvider;
 import sonia.scm.web.proxy.ProxyServlet;
 

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/AdminResource.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import com.google.inject.Inject;
-
-import sonia.scm.plugin.BackendConfiguration;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import com.sun.jersey.api.view.Viewable;
-
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-@Path("admin")
-public class AdminResource extends ViewableResource
-{
-
-  /** Field description */
-  private static final String PAGE_OVERVIEW = "/admin/index";
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param context
-   * @param configuration
-   */
-  @Inject
-  public AdminResource(ServletContext context,
-    BackendConfiguration configuration)
-  {
-    super(context, configuration);
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  @GET
-  @Path("index.html")
-  @Produces(MediaType.TEXT_HTML)
-  public Viewable overview()
-  {
-    Map<String, Object> env = createVarMap("Administrator");
-
-    return new Viewable(PAGE_OVERVIEW, env);
-  }
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/DefaultPluginFilter.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import sonia.scm.plugin.PluginCondition;
-import sonia.scm.plugin.PluginFilter;
-import sonia.scm.plugin.PluginInformation;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-public class DefaultPluginFilter implements PluginFilter
-{
-
-  /** Field description */
-  public static final String VERSION_SNAPSHOT = "SNAPSHOT";
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param version
-   * @param os
-   * @param arch
-   * @param snapshot
-   */
-  public DefaultPluginFilter(String version, String os, String arch,
-                             boolean snapshot)
-  {
-    this.version = version;
-    this.os = os;
-    this.arch = arch;
-    this.snapshot = snapshot;
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param plugin
-   *
-   * @return
-   */
-  @Override
-  public boolean accept(PluginInformation plugin)
-  {
-    PluginCondition condition = plugin.getCondition();
-
-    return (snapshot ||!plugin.getVersion().toUpperCase().contains(
-        VERSION_SNAPSHOT)) && ((condition != null) && condition.isSupported(
-            version, os, arch) || (condition == null));
-  }
-
-  //~--- fields ---------------------------------------------------------------
-
-  /** Field description */
-  private String arch;
-
-  /** Field description */
-  private String os;
-
-  /** Field description */
-  private boolean snapshot;
-
-  /** Field description */
-  private String version;
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/DetailResource.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-
-import net.sf.ehcache.CacheManager;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import sonia.scm.plugin.BackendConfiguration;
-import sonia.scm.plugin.PluginBackend;
-import sonia.scm.plugin.PluginInformation;
-import sonia.scm.plugin.PluginInformationVersionComparator;
-import sonia.scm.plugin.PluginUtil;
-import sonia.scm.plugin.rest.url.UrlBuilder;
-import sonia.scm.plugin.rest.url.UrlBuilderFactory;
-import sonia.scm.util.Util;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import com.sun.jersey.api.view.Viewable;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response.Status;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-@Singleton
-@Path("/page/detail/{groupId}/{artifactId}.html")
-public class DetailResource extends CachedViewableResource
-{
-
-  /** Field description */
-  public static final String CACHE = "sonia.cache.plugin-detail";
-
-  /** the logger for DetailResource */
-  private static final Logger logger =
-    LoggerFactory.getLogger(DetailResource.class);
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   *
-   * @param context
-   * @param backend
-   * @param configuration
-   * @param urlFactory
-   * @param cacheManager
-   */
-  @Inject
-  public DetailResource(ServletContext context, PluginBackend backend,
-                        BackendConfiguration configuration,
-                        UrlBuilderFactory urlFactory, CacheManager cacheManager)
-  {
-    super(context, backend, configuration, cacheManager, CACHE);
-    this.backend = backend;
-    this.urlFactory = urlFactory;
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param groupId
-   * @param artifactId
-   * @param snapshot
-   *
-   * @return
-   */
-  @GET
-  public Viewable getPluginDetails(@PathParam("groupId") String groupId,
-                                   @PathParam("artifactId") String artifactId,
-                                   @DefaultValue("false")
-  @QueryParam("snapshot") boolean snapshot)
-  {
-    String cacheKey = createCacheKey(groupId, artifactId, snapshot);
-    Viewable viewable = getFromCache(cacheKey);
-
-    if (viewable == null)
-    {
-      if (logger.isDebugEnabled())
-      {
-        logger.debug("create viewable from backend");
-      }
-
-      List<PluginInformation> pluginVersions =
-        PluginUtil.getFilteredPluginVersions(backend, groupId, artifactId);
-
-      if (Util.isEmpty(pluginVersions))
-      {
-        throw new WebApplicationException(Status.NOT_FOUND);
-      }
-
-      PluginInformation latest = pluginVersions.get(0);
-
-      if (!snapshot)
-      {
-        pluginVersions = PluginUtil.filterSnapshots(pluginVersions);
-      }
-
-      List<PluginDetailWrapper> detailList = createDetailList(latest,
-                                               pluginVersions);
-      Map<String, Object> vars = createVarMap(latest.getName());
-
-      vars.put("latest", PluginUtil.prepareForView(latest));
-      vars.put("versions", detailList);
-      viewable = new Viewable("/detail", vars);
-      putToCache(cacheKey, viewable);
-    }
-    else if (logger.isDebugEnabled())
-    {
-      logger.debug("create viewable from cache");
-    }
-
-    return viewable;
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param groupId
-   * @param artifactId
-   * @param snapshot
-   *
-   * @return
-   */
-  private String createCacheKey(String groupId, String artifactId,
-                                boolean snapshot)
-  {
-    return new StringBuilder(Util.nonNull(groupId)).append(
-        Util.nonNull(artifactId)).append(Boolean.toString(snapshot)).toString();
-  }
-
-  /**
-   * Method description
-   *
-   *
-   * @param latest
-   * @param pluginVersions
-   *
-   * @return
-   */
-  private List<PluginDetailWrapper> createDetailList(PluginInformation latest,
-          List<PluginInformation> pluginVersions)
-  {
-    List<PluginDetailWrapper> detailList = new ArrayList<PluginDetailWrapper>();
-
-    Collections.sort(pluginVersions,
-                     PluginInformationVersionComparator.INSTANCE);
-
-    Iterator<PluginInformation> pluginIterator = pluginVersions.iterator();
-    UrlBuilder urlBuilder = urlFactory.createCompareUrlBuilder(latest);
-    PluginInformation last = null;
-
-    while (pluginIterator.hasNext())
-    {
-      PluginInformation current = pluginIterator.next();
-
-      if (last != null)
-      {
-        String url = null;
-
-        if (urlBuilder != null)
-        {
-          url = urlBuilder.createCompareUrl(latest, last, current);
-        }
-
-        detailList.add(new PluginDetailWrapper(last, url));
-      }
-
-      last = current;
-    }
-
-    if (last != null)
-    {
-      detailList.add(new PluginDetailWrapper(last));
-    }
-
-    return detailList;
-  }
-
-  //~--- fields ---------------------------------------------------------------
-
-  /** Field description */
-  private PluginBackend backend;
-
-  /** Field description */
-  private UrlBuilderFactory urlFactory;
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/ErrorResource.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import com.google.inject.Inject;
-
-import sonia.scm.plugin.BackendConfiguration;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import com.sun.jersey.api.view.Viewable;
-
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-@Path("error")
-public class ErrorResource extends ViewableResource
-{
-
-  /** Field description */
-  private static final String PAGE_UNAUTHORIZED = "/error/Unauthorized.html";
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param context
-   * @param configuration
-   */
-  @Inject
-  public ErrorResource(ServletContext context,
-    BackendConfiguration configuration)
-  {
-    super(context, configuration);
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  @GET
-  @Path("unauthorized.html")
-  @Produces(MediaType.TEXT_HTML)
-  public Viewable unauthorized()
-  {
-    Map<String, Object> env = createVarMap("Unauthorized");
-
-    return new Viewable(PAGE_UNAUTHORIZED, env);
-  }
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/FreemarkerTemplateProvider.java

   {
     configuration = new Configuration();
     configuration.setServletContextForTemplateLoading(servletContext,
-            DIRECTORY_TEMPLATES);
+      DIRECTORY_TEMPLATES);
   }
 
   //~--- methods --------------------------------------------------------------
    */
   @Override
   public void writeTo(String resolvedPath, Viewable viewable, OutputStream out)
-          throws IOException
+    throws IOException
   {
     if (logger.isDebugEnabled())
     {

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/LoginResource.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import com.google.inject.Inject;
-
-import sonia.scm.plugin.BackendConfiguration;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import com.sun.jersey.api.view.Viewable;
-
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-@Path("/page/login.html")
-public class LoginResource extends ViewableResource
-{
-
-  /** Field description */
-  private static final String PAGE_LOGIN = "/login";
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param context
-   * @param configuration
-   */
-  @Inject
-  public LoginResource(ServletContext context,
-    BackendConfiguration configuration)
-  {
-    super(context, configuration);
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  @POST
-  @Produces(MediaType.TEXT_HTML)
-  public Viewable loginFailed()
-  {
-    Map<String, Object> vars = createVarMap("Login");
-
-    vars.put("error", "Login failed");
-
-    return new Viewable(PAGE_LOGIN, vars);
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  @GET
-  @Produces(MediaType.TEXT_HTML)
-  public Viewable getForm()
-  {
-    Map<String, Object> vars = createVarMap("Login");
-
-    return new Viewable(PAGE_LOGIN, vars);
-  }
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/OverviewResource.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import com.google.inject.Inject;
-
-import sonia.scm.plugin.BackendConfiguration;
-import sonia.scm.plugin.Category;
-import sonia.scm.plugin.CategoryNameComaparator;
-import sonia.scm.plugin.PluginBackend;
-import sonia.scm.plugin.PluginInformation;
-import sonia.scm.plugin.PluginUtil;
-import sonia.scm.util.Util;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import com.sun.jersey.api.view.Viewable;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-@Path("/page/index.html")
-public class OverviewResource extends ViewableResource
-{
-
-  /** Field description */
-  public static final String DEFAULT_CATEGORY = "Miscellaneous";
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   *
-   * @param context
-   * @param backend
-   * @param configuration
-   */
-  @Inject
-  public OverviewResource(ServletContext context, PluginBackend backend,
-    BackendConfiguration configuration)
-  {
-    super(context, configuration);
-    this.backend = backend;
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  @GET
-  public Viewable overview()
-  {
-    List<Category> categories = getPluginOverview();
-    Map<String, Object> vars = createVarMap("Plugin Overview");
-
-    vars.put("categories", categories);
-
-    return new Viewable("/index", vars);
-  }
-
-  /**
-   * Method description
-   *
-   *
-   * @param categories
-   * @param plugin
-   */
-  private void append(Map<String, Category> categories,
-    PluginInformation plugin)
-  {
-    String name = plugin.getCategory();
-
-    if (Util.isEmpty(name))
-    {
-      name = DEFAULT_CATEGORY;
-    }
-
-    Category category = categories.get(name);
-
-    if (category == null)
-    {
-      category = new Category(name, plugin);
-      categories.put(name, category);
-    }
-
-    category.getPlugins().add(PluginUtil.prepareForView(plugin));
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  private List<Category> getPluginOverview()
-  {
-    List<PluginInformation> allPlugins = backend.getPlugins();
-
-    Collections.sort(allPlugins, PluginInformationComparator.INSTANCE);
-
-    String pid = "";
-    Map<String, Category> categoryMap = new HashMap<String, Category>();
-
-    for (PluginInformation p : allPlugins)
-    {
-      String currentPid = p.getGroupId().concat(":").concat(p.getArtifactId());
-
-      if (!currentPid.equals(pid))
-      {
-        pid = currentPid;
-        append(categoryMap, p);
-      }
-    }
-
-    List<Category> categories = new ArrayList<Category>(categoryMap.values());
-
-    Collections.sort(categories, CategoryNameComaparator.INSTANCE);
-
-    return categories;
-  }
-
-  //~--- fields ---------------------------------------------------------------
-
-  /** Field description */
-  private PluginBackend backend;
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/PluginDetailWrapper.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import sonia.scm.plugin.PluginInformation;
-import sonia.scm.plugin.PluginUtil;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-public class PluginDetailWrapper
-{
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param plugin
-   */
-  public PluginDetailWrapper(PluginInformation plugin)
-  {
-    this(plugin, null);
-  }
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param plugin
-   * @param compareUrl
-   */
-  public PluginDetailWrapper(PluginInformation plugin, String compareUrl)
-  {
-    this.plugin = PluginUtil.prepareForView(plugin);
-    this.compareUrl = compareUrl;
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  public String getCompareUrl()
-  {
-    return compareUrl;
-  }
-
-  /**
-   * Method description
-   *
-   *
-   * @return
-   */
-  public PluginInformation getPlugin()
-  {
-    return plugin;
-  }
-
-  //~--- set methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param compareUrl
-   */
-  public void setCompareUrl(String compareUrl)
-  {
-    this.compareUrl = compareUrl;
-  }
-
-  /**
-   * Method description
-   *
-   *
-   * @param plugin
-   */
-  public void setPlugin(PluginInformation plugin)
-  {
-    this.plugin = plugin;
-  }
-
-  //~--- fields ---------------------------------------------------------------
-
-  /** Field description */
-  private String compareUrl;
-
-  /** Field description */
-  private PluginInformation plugin;
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/PluginInformationComparator.java

  * @author Sebastian Sdorra
  */
 public class PluginInformationComparator
-        implements Comparator<PluginInformation>
+  implements Comparator<PluginInformation>
 {
 
   /** Field description */

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/PluginResource.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.Element;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import sonia.scm.plugin.BackendConfiguration;
-import sonia.scm.plugin.PluginBackend;
-import sonia.scm.plugin.PluginBackendListener;
-import sonia.scm.plugin.PluginCenter;
-import sonia.scm.plugin.PluginInformation;
-import sonia.scm.plugin.PluginVersion;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-@Singleton
-@Path("/api/{version}/plugins")
-public class PluginResource implements PluginBackendListener
-{
-
-  /** Field description */
-  public static final String CACHE = "sonia.cache.plugin-backend";
-
-  /** the logger for PluginResource */
-  private static final Logger logger =
-    LoggerFactory.getLogger(PluginResource.class);
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param backend
-   * @param configuration
-   * @param cacheManager
-   */
-  @Inject
-  public PluginResource(PluginBackend backend,
-                        BackendConfiguration configuration,
-                        CacheManager cacheManager)
-  {
-    this.backend = backend;
-    this.configuration = configuration;
-    cache = cacheManager.getCache(CACHE);
-
-    // added listener to clear the cache on a event
-    this.backend.addListener(this);
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param plugins
-   */
-  @Override
-  public void addedNewPlugins(Collection<PluginInformation> plugins)
-  {
-    if (logger.isDebugEnabled())
-    {
-      logger.debug("clear cache {}", CACHE);
-    }
-
-    cache.removeAll();
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param version
-   * @param os
-   * @param arch
-   * @param snapshot
-   *
-   * @return
-   */
-  @GET
-  @Produces(MediaType.APPLICATION_XML)
-  public Response getPlugins(@PathParam("version") String version,
-                             @QueryParam("os") String os,
-                             @QueryParam("arch") String arch,
-                             @DefaultValue("false")
-  @QueryParam("snapshot") boolean snapshot)
-  {
-    if (logger.isDebugEnabled())
-    {
-      logger.debug("load plugins for version {}, include snapshots: {}",
-                   version, Boolean.toString(snapshot));
-    }
-
-    PluginCenter pc = null;
-    String key = createCacheKey(version, os, arch, snapshot);
-    Element el = cache.get(key);
-
-    if (el != null)
-    {
-      if (logger.isDebugEnabled())
-      {
-        logger.debug("load plugin center from cache");
-      }
-
-      pc = (PluginCenter) el.getObjectValue();
-    }
-    else
-    {
-      if (logger.isDebugEnabled())
-      {
-        logger.debug("load plugin center from backend");
-      }
-
-      List<PluginInformation> plugins =
-        backend.getPlugins(new DefaultPluginFilter(version, os, arch,
-          snapshot));
-
-      pc = new PluginCenter();
-      pc.setPlugins(getNewestPlugins(plugins));
-      pc.setRepositories(configuration.getRepositories());
-      cache.put(new Element(key, pc));
-    }
-
-    return Response.ok(pc).build();
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param version
-   * @param os
-   * @param arch
-   * @param snapshot
-   *
-   * @return
-   */
-  private String createCacheKey(String version, String os, String arch,
-                                boolean snapshot)
-  {
-    StringBuilder key = new StringBuilder(version);
-
-    key.append(":").append(os).append(":").append(arch).append(":");
-    key.append(Boolean.toString(snapshot));
-
-    return key.toString();
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param plugins
-   *
-   * @return
-   */
-  private Set<PluginInformation> getNewestPlugins(
-          List<PluginInformation> plugins)
-  {
-    Collections.sort(plugins, PluginInformationComparator.INSTANCE);
-
-    Set<PluginInformation> pluginSet = new HashSet<PluginInformation>();
-    PluginInformation newest = null;
-
-    for (PluginInformation plugin : plugins)
-    {
-      if (newest == null)
-      {
-        newest = plugin;
-      }
-      else if (isSamePlugin(plugin, newest))
-      {
-        if (isNewer(plugin, newest))
-        {
-          newest = plugin;
-        }
-      }
-      else
-      {
-        pluginSet.add(newest);
-        newest = plugin;
-      }
-    }
-
-    pluginSet.add(newest);
-
-    return pluginSet;
-  }
-
-  /**
-   * Method description
-   *
-   *
-   * @param plugin
-   * @param newest
-   *
-   * @return
-   */
-  private boolean isNewer(PluginInformation plugin, PluginInformation newest)
-  {
-    return new PluginVersion(plugin.getVersion()).isNewer(newest.getVersion());
-  }
-
-  /**
-   * Method description
-   *
-   *
-   * @param plugin
-   * @param otherPlugin
-   *
-   * @return
-   */
-  private boolean isSamePlugin(PluginInformation plugin,
-                               PluginInformation otherPlugin)
-  {
-    return plugin.getGroupId().equals(otherPlugin.getGroupId())
-           && plugin.getArtifactId().equals(otherPlugin.getArtifactId());
-  }
-
-  //~--- fields ---------------------------------------------------------------
-
-  /** Field description */
-  private PluginBackend backend;
-
-  /** Field description */
-  private Cache cache;
-
-  /** Field description */
-  private BackendConfiguration configuration;
-}

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/ScreenshotResource.java

-/**
- * 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.rest;
-
-//~--- non-JDK imports --------------------------------------------------------
-
-import com.google.inject.Inject;
-
-import org.imgscalr.Scalr;
-
-import sonia.scm.plugin.PluginBackend;
-import sonia.scm.plugin.PluginInformation;
-import sonia.scm.plugin.PluginUtil;
-import sonia.scm.util.ChecksumUtil;
-import sonia.scm.util.IOUtil;
-import sonia.scm.util.Util;
-
-//~--- JDK imports ------------------------------------------------------------
-
-import java.awt.image.BufferedImage;
-
-import java.io.File;
-import java.io.IOException;
-
-import java.net.URL;
-
-import java.util.List;
-
-import javax.imageio.ImageIO;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import sonia.scm.plugin.BaseDirectory;
-
-/**
- *
- * @author Sebastian Sdorra
- */
-@Path("/page/screenshot/{groupId}/{artifactId}/{number}/{size}.jpg")
-public class ScreenshotResource
-{
-
-  /** Field description */
-  public static final String EXTENSION_IMAGE = ".jpg";
-
-  /** Field description */
-  public static final String FORMAT = "jpg";
-
-  /** Field description */
-  public static final String PATH_IMAGE = "images";
-
-  /** Field description */
-  public static final int SIZE_LARGE = 640;
-
-  /** Field description */
-  public static final int SIZE_MEDIUM = 320;
-
-  /** Field description */
-  public static final int SIZE_SMALL = 200;
-
-  //~--- constructors ---------------------------------------------------------
-
-  /**
-   * Constructs ...
-   *
-   *
-   * @param backend
-   */
-  @Inject
-  public ScreenshotResource(PluginBackend backend)
-  {
-    this.backend = backend;
-  }
-
-  //~--- get methods ----------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param groupId
-   * @param artifactId
-   * @param number
-   * @param size
-   *
-   * @return
-   *
-   * @throws IOException
-   */
-  @GET
-  @Produces("image/jpeg")
-  public Response getScreenshot(
-    @PathParam("groupId") String groupId,
-    @PathParam("artifactId") String artifactId,
-    @PathParam("number") int number, 
-    @PathParam("size") String size)
-    throws IOException
-  {
-    PluginInformation plugin = PluginUtil.getLatestPluginVersion(backend,
-                                 groupId, artifactId);
-
-    if (plugin == null)
-    {
-      throw new WebApplicationException(Status.NOT_FOUND);
-    }
-
-    List<String> screenshots = plugin.getScreenshots();
-
-    if (Util.isEmpty(screenshots))
-    {
-      throw new WebApplicationException(Status.NOT_FOUND);
-    }
-
-    String screenshot = screenshots.get(number);
-
-    if (Util.isEmpty(screenshot))
-    {
-      throw new WebApplicationException(Status.NOT_FOUND);
-    }
-
-    String checksum = ChecksumUtil.createChecksum(screenshot);
-
-    File file = createThumbnailFile(groupId, artifactId, number, size,
-                  checksum);
-
-    if (!file.exists())
-    {
-      createThumbnail(file, screenshot, size.toCharArray()[0]);
-    }
-
-    return Response.ok(file).build();
-  }
-
-  //~--- methods --------------------------------------------------------------
-
-  /**
-   * Method description
-   *
-   *
-   * @param file
-   * @param screenshot
-   * @param size
-   *
-   * @throws IOException
-   */
-  private void createThumbnail(File file, String screenshot, char size)
-    throws IOException
-  {
-    IOUtil.mkdirs(file.getParentFile());
-
-    int width = SIZE_SMALL;
-