/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2006-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package org.glassfish.server; import com.sun.enterprise.module.bootstrap.StartupContext; import com.sun.enterprise.universal.glassfish.ASenvPropertyReader; import com.sun.enterprise.util.SystemPropertyConstants; import java.io.*; import java.util.*; import org.glassfish.api.admin.RuntimeType; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.component.PostConstruct; import org.glassfish.api.admin.ServerEnvironment; /** * Defines various global configuration for the running GlassFish instance. * *
* This primarily replaces all the system variables in V2.
*
* @author Jerome Dochez
* @author Byron Nevins
*/
@Service
public class ServerEnvironmentImpl implements ServerEnvironment, PostConstruct {
@Inject
StartupContext startupContext;
/** folder where all generated code like compiled jsps, stubs is stored */
public static final String kGeneratedDirName = "generated";
public static final String kRepositoryDirName = "applications";
public static final String kEJBStubDirName = "ejb";
public static final String kGeneratedXMLDirName = "xml";
public static final String kPolicyFileDirName = "policy";
public static final String kConfigXMLFileName = "domain.xml";
public static final String kConfigXMLFileNameBackup = "domain.xml.bak";
public static final String kLoggingPropertiesFileName = "logging.properties";
/** folder where the configuration of this instance is stored */
public static final String kConfigDirName = "config";
/** init file name */
public static final String kInitFileName = "init.conf";
public static final String DEFAULT_ADMIN_CONSOLE_CONTEXT_ROOT = "/admin";
public static final String DEFAULT_ADMIN_CONSOLE_APP_NAME = "__admingui"; //same as folder
private /*almost final*/ File root;
private /*almost final*/ boolean verbose;
private /*almost final*/ boolean debug;
private ASenvPropertyReader asenv;
private /*almost final*/ String domainName;
private /*almost final*/ String instanceName;
private RuntimeType serverType = RuntimeType.DAS; //set to DAS to avoid null
private final static String INSTANCE_ROOT_PROP_NAME = "com.sun.aas.instanceRoot";
private static final String INSTALL_ROOT_PROP_NAME = "com.sun.aas.installRoot";
/**
* Compute all the values per default.
*/
public ServerEnvironmentImpl() {
}
public ServerEnvironmentImpl(File root) {
// the getParentFile() that we do later fails to work correctly if
// root is for example "new File(".")
this.root = root.getAbsoluteFile();
asenv = new ASenvPropertyReader();
}
/**
* This is where the real initialization happens.
*/
@Override
public void postConstruct() {
// todo : dochez : this will need to be reworked...
String installRoot = startupContext.getArguments().getProperty(INSTALL_ROOT_PROP_NAME);
if (installRoot == null) {
// Sahoo: This is truely a bad piece of code. During unit testing, we find an empty StartupContext.
// To be consistent with earlier code (i.e., code that relied on StartupContext.getRootDirectory()),
// I am setting user.dir as installRoot.
installRoot = System.getProperty("user.dir");
}
asenv = new ASenvPropertyReader(new File(installRoot));
// default
if(this.root==null) {
String envVar = System.getProperty(INSTANCE_ROOT_PROP_NAME);
if (envVar!=null) {
root = new File(envVar);
} else {
String instanceRoot = startupContext.getArguments().getProperty(INSTANCE_ROOT_PROP_NAME);
if (instanceRoot == null) {
// In client container, instanceRoot is not set. It is a different question altogether as to why
// an object called ServerEnvironmentImpl is at all active in client runtime. To be consistent
// with earlier code, we use installRoot as instanceRoot.
instanceRoot = installRoot;
}
root = new File(instanceRoot);
}
}
/*
* bnevins 12/12/11
* The following chunk of code sets things like hostname to be a file under instance root
* I.e. it's crazy. It's 1 hour until SCF so I'll just fix the current problem which is a NPE
* if the value is null.
* At any rate the weird values that get set into System Properties get un-done at
* the line of code in bootstrap (see end of this comment). It's easy to trace just step out of this method
* in a debugger
* createGlassFish(gfKernel, habitat, gfProps.getProperties())
*/
asenv.getProps().put(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, root.getAbsolutePath());
for (Map.Entry