indent and fix wrong imports

This commit is contained in:
Sebastian Sdorra
2013-06-19 16:22:43 +02:00
parent d1ced572af
commit d0769a1962

View File

@@ -33,14 +33,15 @@
package sonia.scm; package sonia.scm;
import javax.servlet.RequestDispatcher; //~--- non-JDK imports --------------------------------------------------------
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import de.triology.scm.plugins.restart.ServletContainer; //~--- JDK imports ------------------------------------------------------------
import de.triology.scm.plugins.restart.ServletContainerDetector;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
/** /**
* Detects the ServletContainer. * Detects the ServletContainer.
@@ -51,331 +52,352 @@ import de.triology.scm.plugins.restart.ServletContainerDetector;
*/ */
public class ServletContainerDetector public class ServletContainerDetector
{ {
/** Make usage of the logging framework. */
private static final Logger LOGGER = LoggerFactory.getLogger(ServletContainerDetector.class);
/** Servlet request for alternate detection method. */
private HttpServletRequest request = null;
/** /** Make usage of the logging framework. */
* Constructs a new ServletContainerDetector. private static final Logger LOGGER =
* @deprecated Use {@link ServletContainerDetector#detect(HttpServletRequest)} instead. LoggerFactory.getLogger(ServletContainerDetector.class);
*/
@Deprecated
public ServletContainerDetector() {
} //~--- constructors ---------------------------------------------------------
/** /**
* Constructs a new ServletContainerDetector depending on the ServletRequest. * Constructs a new ServletContainerDetector.
* @param req The ServletRequest. * @deprecated Use {@link ServletContainerDetector#detect(HttpServletRequest)} instead.
*/ */
private ServletContainerDetector(final HttpServletRequest req) { @Deprecated
request = req; public ServletContainerDetector() {}
}
/** /**
* Detects the ServletContainer. * Constructs a new ServletContainerDetector depending on the ServletRequest.
* * @param req The ServletRequest.
* @deprecated Use {@link ServletContainerDetector#detect(HttpServletRequest)} instead. */
* @return the detected ServletContainer private ServletContainerDetector(final HttpServletRequest req)
*/ {
@Deprecated request = req;
public static ServletContainer detect() }
{
return new ServletContainerDetector().detectContainer();
}
/** //~--- methods --------------------------------------------------------------
* Alternate detection of ServletContainer using DefaultServletDetection.
* @param req The used Servlet instance.
* @return the detected ServletContainer.
*/
public static ServletContainer detect(final HttpServletRequest req)
{
return new ServletContainerDetector(req).detectContainer();
}
/** /**
* Detects the ServletContainer. * Detects the ServletContainer.
* *
* * @deprecated Use {@link ServletContainerDetector#detect(HttpServletRequest)} instead.
* @return the detected ServletContainer * @return the detected ServletContainer
*/ */
public ServletContainer detectContainer() @Deprecated
{ public static ServletContainer detect()
LOGGER.trace("Detecting servlet container..."); {
ServletContainer container = ServletContainer.UNKNOWN; return new ServletContainerDetector().detectContainer();
}
if (isScmServer()) /**
{ * Alternate detection of ServletContainer using DefaultServletDetection.
container = ServletContainer.SCM_SERVER; *
} * @param req The used Servlet instance.
else if (isGeronimo()) * @return the detected ServletContainer.
{ * @since 1.32
container = ServletContainer.GERONIMO; */
} public static ServletContainer detect(final HttpServletRequest req)
else if (isGlassfish()) {
{ return new ServletContainerDetector(req).detectContainer();
container = ServletContainer.GLASSFISH; }
}
else if (isJBoss())
{
container = ServletContainer.JBOSS;
}
else if (isJOnAS())
{
container = ServletContainer.JONAS;
}
else if (isOC4J())
{
container = ServletContainer.OC4J;
}
else if (isResin())
{
container = ServletContainer.RESIN;
}
else if (isWebLogic())
{
container = ServletContainer.WEBLOGIC;
}
else if (isWebSphere())
{
container = ServletContainer.WEBSPHERE;
}
else if (isJetty())
{
container = ServletContainer.JETTY;
}
else if (isEclipseJetty())
{
container = ServletContainer.ECLIPSE_JETTY;
}
else if (isTomcat())
{
container = ServletContainer.TOMCAT;
}
if (ServletContainer.UNKNOWN.equals(container)) { /**
LOGGER.trace("Servlet container is unknown."); * Detects the ServletContainer.
} *
*
* @return the detected ServletContainer
*/
public ServletContainer detectContainer()
{
LOGGER.trace("Detecting servlet container...");
return container; ServletContainer container = ServletContainer.UNKNOWN;
}
//~--- get methods ---------------------------------------------------------- if (isScmServer())
{
container = ServletContainer.SCM_SERVER;
}
else if (isGeronimo())
{
container = ServletContainer.GERONIMO;
}
else if (isGlassfish())
{
container = ServletContainer.GLASSFISH;
}
else if (isJBoss())
{
container = ServletContainer.JBOSS;
}
else if (isJOnAS())
{
container = ServletContainer.JONAS;
}
else if (isOC4J())
{
container = ServletContainer.OC4J;
}
else if (isResin())
{
container = ServletContainer.RESIN;
}
else if (isWebLogic())
{
container = ServletContainer.WEBLOGIC;
}
else if (isWebSphere())
{
container = ServletContainer.WEBSPHERE;
}
else if (isJetty())
{
container = ServletContainer.JETTY;
}
else if (isEclipseJetty())
{
container = ServletContainer.ECLIPSE_JETTY;
}
else if (isTomcat())
{
container = ServletContainer.TOMCAT;
}
/** if (ServletContainer.UNKNOWN.equals(container))
* Returns true if the ServletContainer is a Geronimo. {
* LOGGER.trace("Servlet container is unknown.");
* }
* @return true if the ServletContainer is a Geronimo
*/
public boolean isGeronimo()
{
return detect("/org/apache/geronimo/system/main/Daemon.class");
}
/** return container;
* Returns true if the ServletContainer is a Glassfish. }
*
*
* @return true if the ServletContainer is a Glassfish
*/
public boolean isGlassfish()
{
final String value = System.getProperty("com.sun.aas.instanceRoot");
if (value != null) //~--- get methods ----------------------------------------------------------
{
return true;
}
else
{
return false;
}
}
/** /**
* Returns true if the ServletContainer is a JBoss. * Returns true if the ServletContainer is a Eclipse Jetty.
* *
* * @since 1.32
* @return true if the ServletContainer is a JBos * @return true if the ServletContainer is a Eclipse Jetty
*/ */
public boolean isJBoss() public boolean isEclipseJetty()
{ {
return detect("/org/jboss/Main.class"); boolean jetty = detect("/org/eclipse/jetty/server/Server.class");
}
/** if (!jetty && (null != request))
* Returns true if the ServletContainer is a JOnAS. {
* jetty = detectDefaultServlet("org.eclipse.jetty");
* }
* @return true if the ServletContainer is a JOnAS
*/
public boolean isJOnAS()
{
boolean jonas = detect("/org/objectweb/jonas/server/Server.class");
if (!jonas && (System.getProperty("jonas.root") != null)) return jetty;
{ }
jonas = true;
}
return jonas; /**
} * Returns true if the ServletContainer is a Geronimo.
*
*
* @return true if the ServletContainer is a Geronimo
*/
public boolean isGeronimo()
{
return detect("/org/apache/geronimo/system/main/Daemon.class");
}
/** /**
* Returns true if the ServletContainer is a Jetty. * Returns true if the ServletContainer is a Glassfish.
* *
* *
* @return true if the ServletContainer is a Jetty * @return true if the ServletContainer is a Glassfish
*/ */
public boolean isJetty() public boolean isGlassfish()
{ {
return detect("/org/mortbay/jetty/Server.class"); final String value = System.getProperty("com.sun.aas.instanceRoot");
}
/** if (value != null)
* Returns true if the ServletContainer is a Eclipse Jetty. {
* return true;
* @since 1.32 }
* @return true if the ServletContainer is a Eclipse Jetty else
*/ {
public boolean isEclipseJetty() return false;
{ }
boolean jetty = detect("/org/eclipse/jetty/server/Server.class"); }
if (!jetty && null != request) {
jetty = detectDefaultServlet("org.eclipse.jetty");
}
return jetty;
}
/** /**
* Returns true if the ServletContainer is a OC4J. * Returns true if the ServletContainer is a JBoss.
* *
* *
* @return true if the ServletContainer is a OC4J * @return true if the ServletContainer is a JBos
*/ */
public boolean isOC4J() public boolean isJBoss()
{ {
return detect("oracle.oc4j.util.ClassUtils"); return detect("/org/jboss/Main.class");
} }
/** /**
* Returns true if the ServletContainer is a Resin. * Returns true if the ServletContainer is a JOnAS.
* *
* *
* @return true if the ServletContainer is a Resin * @return true if the ServletContainer is a JOnAS
*/ */
public boolean isResin() public boolean isJOnAS()
{ {
return detect("/com/caucho/server/resin/Resin.class"); boolean jonas = detect("/org/objectweb/jonas/server/Server.class");
}
/** if (!jonas && (System.getProperty("jonas.root") != null))
* Returns true if the ServletContainer is a SCM-Server. {
* jonas = true;
* }
* @return true if the ServletContainer is a SCM-Server
*/
public boolean isScmServer()
{
LOGGER.debug("App name is: " + System.getProperty("app.name"));
return "scm-server".equals(System.getProperty("app.name"));
}
/** return jonas;
* Returns true if the ServletContainer is a Tomcat. }
*
*
* @return true if the ServletContainer is a Tomcat
*/
public boolean isTomcat()
{
boolean tomcat = detect("/org/apache/catalina/startup/Bootstrap.class");
if (!tomcat) /**
{ * Returns true if the ServletContainer is a Jetty.
tomcat = detect("/org/apache/catalina/startup/Embedded.class"); *
} *
* @return true if the ServletContainer is a Jetty
*/
public boolean isJetty()
{
return detect("/org/mortbay/jetty/Server.class");
}
return tomcat; /**
} * Returns true if the ServletContainer is a OC4J.
*
*
* @return true if the ServletContainer is a OC4J
*/
public boolean isOC4J()
{
return detect("oracle.oc4j.util.ClassUtils");
}
/** /**
* Returns true if the ServletContainer is a WebLogic. * Returns true if the ServletContainer is a Resin.
* *
* *
* @return true if the ServletContainer is a WebLogic * @return true if the ServletContainer is a Resin
*/ */
public boolean isWebLogic() public boolean isResin()
{ {
return detect("/weblogic/Server.class"); return detect("/com/caucho/server/resin/Resin.class");
} }
/** /**
* Returns true if the ServletContainer is a WebSphere. * Returns true if the ServletContainer is a SCM-Server.
* *
* *
* @return true if the ServletContainer is a WebSpere * @return true if the ServletContainer is a SCM-Server
*/ */
public boolean isWebSphere() public boolean isScmServer()
{ {
return detect("/com/ibm/websphere/product/VersionInfo.class"); LOGGER.debug("App name is: " + System.getProperty("app.name"));
}
//~--- methods -------------------------------------------------------------- return "scm-server".equals(System.getProperty("app.name"));
}
/** /**
* Returns true if the given class exists in the system classpath. * Returns true if the ServletContainer is a Tomcat.
* *
* *
* @param clazz class name to search in classpath * @return true if the ServletContainer is a Tomcat
* */
* @return true if class exists in system classpath public boolean isTomcat()
*/ {
private boolean detect(final String clazz) boolean tomcat = detect("/org/apache/catalina/startup/Bootstrap.class");
{
try
{
final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
systemClassLoader.loadClass(clazz); if (!tomcat)
{
tomcat = detect("/org/apache/catalina/startup/Embedded.class");
}
return true; return tomcat;
} }
catch (final ClassNotFoundException cnfe)
{
final Class<?> classObj = getClass();
if (classObj.getResource(clazz) != null) /**
{ * Returns true if the ServletContainer is a WebLogic.
return true; *
} *
else * @return true if the ServletContainer is a WebLogic
{ */
return false; public boolean isWebLogic()
} {
} return detect("/weblogic/Server.class");
} }
/** /**
* An alternate detection. The default servlet that must be implemented by each application, so we can get it's * Returns true if the ServletContainer is a WebSphere.
* class name and compare against our suggestion. *
* *
* @since 1.32 * @return true if the ServletContainer is a WebSpere
* @param keyword Part of the class path that is needed at the implementation class. */
*/ public boolean isWebSphere()
private boolean detectDefaultServlet(final String keyword) {
{ return detect("/com/ibm/websphere/product/VersionInfo.class");
// Request the default servlet (its pretty safe to say it will always be there) }
final RequestDispatcher dispatcher = request.getSession().getServletContext().getNamedDispatcher("default");
if (dispatcher == null)
{
return false;
}
// If the request dispatcher implementation contains the keyword, we can claim a match //~--- methods --------------------------------------------------------------
return dispatcher.getClass().getName().contains(keyword);
} /**
} * Returns true if the given class exists in the system classpath.
*
*
* @param clazz class name to search in classpath
*
* @return true if class exists in system classpath
*/
private boolean detect(final String clazz)
{
try
{
final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
systemClassLoader.loadClass(clazz);
return true;
}
catch (final ClassNotFoundException cnfe)
{
final Class<?> classObj = getClass();
if (classObj.getResource(clazz) != null)
{
return true;
}
else
{
return false;
}
}
}
/**
* An alternate detection. The default servlet that must be implemented by each application, so we can get it's
* class name and compare against our suggestion.
*
* @since 1.32
* @param keyword Part of the class path that is needed at the implementation class.
*
* @return
*/
private boolean detectDefaultServlet(final String keyword)
{
// Request the default servlet (its pretty safe to say it will always be there)
final RequestDispatcher dispatcher =
request.getSession().getServletContext().getNamedDispatcher("default");
if (dispatcher == null)
{
return false;
}
// If the request dispatcher implementation contains the keyword, we can claim a match
return dispatcher.getClass().getName().contains(keyword);
}
//~--- fields ---------------------------------------------------------------
/** Servlet request for alternate detection method. */
private HttpServletRequest request = null;
}