1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.tools
.development
;
5 import com
.google
.appengine
.tools
.info
.SdkInfo
;
7 import java
.util
.Iterator
;
10 * helper to load a {@link ContainerService} instance
13 public class ContainerUtils
{
15 * Load a {@link ContainerService} instance based on the implementation
16 * located by the {@code ServiceLoader}.
18 * When more than one implementations are found, an
19 * <code>IllegalArgumentException</code> will be thrown. In other words,
20 * only one {@link ContainerService} implementation should be packaged and
23 * To ease debugging/testing (e.g. from IDE), an internal system property is
24 * defined to explicitly specify a required container service provider, such
25 * as -Ddevappserver.container=OpenGSEContainerService.
27 * Classpath resource(s) that match
28 * META-INF/services/com.google.appengine.tools.development.ContainerService
29 * are used to resolve the ContainerService implementations.
31 * If using an IDE, create a package/directory called META-INF/services/ and
32 * add a text file with the name
33 * "com.google.appengine.tools.development.ContainerService" containing one
34 * line - the implementation class (some IDEs have a resource pattern that
35 * is used to determine which files are added to the runtime classpath. If
36 * your implementation class isn't being recognized, adjusting this pattern
37 * to include the text file may help.
40 * @return the deployed {@link ContainerService} instance.
41 * @throws IllegalArgumentException if {@code ServiceLoader} fails to find
42 * any {@link ContainerService} implementation or more than one
43 * {@link ContainerService} implementations are available.
45 public static ContainerService
loadContainer() {
46 @SuppressWarnings({"unchecked", "sunapi"})
47 Iterator
<ContainerService
> containerLoader
=
48 sun
.misc
.Service
.providers(ContainerService
.class,
49 DevAppServerImpl
.class.getClassLoader());
50 String containerClazz
= System
.getProperty("devappserver.container");
51 ContainerService result
= null;
52 while (containerLoader
.hasNext()) {
53 ContainerService container
= containerLoader
.next();
54 if (containerClazz
== null || containerClazz
.length() == 0) {
58 System
.err
.println("Warning: Found more than one servlet container provider: "
59 + result
.getClass() + ", " + container
.getClass()
60 + ". And the first one will be used!");
64 if (container
.getClass().getName().endsWith(containerClazz
)) {
71 throw new IllegalArgumentException("Cannot load any servlet container.");
77 * @return the server info string with the dev-appserver version
79 public static String
getServerInfo() {
80 return "Google App Engine Development/" + SdkInfo
.getLocalVersion().getRelease();