2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * The contents of this file are subject to the terms
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * of the Common Development and Distribution License
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * (the License). You may not use this file except in
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * compliance with the License.
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * You can obtain a copy of the License at
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * https://opensso.dev.java.net/public/CDDLv1.0.html or
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * See the License for the specific language governing
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * permission and limitations under the License.
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * When distributing Covered Code, include this CDDL
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * Header Notice in each file and include the License file
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * If applicable, add the following below the CDDL Header,
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * with the fields enclosed by brackets [] replaced by
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * your own identifying information:
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * "Portions Copyrighted [year] [name of copyright owner]"
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper * $Id: ServerClasspathBase.java,v 1.1 2009/01/21 18:43:56 kanduls Exp $
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeperpackage com.sun.identity.agents.tools.jetty.v61;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeperimport com.sun.identity.install.tools.configurator.IStateAccess;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeperimport com.sun.identity.install.tools.util.ConfigUtil;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeperimport com.sun.identity.install.tools.util.Debug;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeperimport com.sun.identity.install.tools.util.FileUtils;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeperpublic class ServerClasspathBase implements IConstants, IConfigKeys {
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper protected boolean updateJettyStartupJarFile(IStateAccess stateAccess) {
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Debug.log("ServerClasspathBase.updateJettyStartupJarFile(): " +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper "Update jar file");
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper boolean status = false;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper ArrayList<String> agentClasspathsDirs = getAgentClasspathDirectories(
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String homeDir = (String) stateAccess.get(STR_KEY_JETTY_HOME_DIR);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Debug.log("ServerClasspathBase.updateJettyStartupJarFile(): " +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String startJarPath = homeDir + STR_FORWARD_SLASH + JETTY_START_JAR;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String newJarPath = homeDir + STR_FORWARD_SLASH + "start-temp.jar";
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper JarFile oldJarFile = new JarFile(startJarPath);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper new FileInputStream(new File(startJarPath)));
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper JarEntry entry = oldJarInputStream.getNextJarEntry();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper fos = new JarOutputStream(new FileOutputStream(newJarPath), m);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper fos.putNextEntry(new JarEntry(entry.getName()));
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper //byte[] bytes = new byte[BUFF_SIZE];
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper //int read = oldJarInputStream.read(bytes, 0, BUFF_SIZE);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper //while (read > 0) {
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper // fos.write(bytes, 0, read);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper // read = oldJarInputStream.read(bytes, 0, BUFF_SIZE);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper if (entry.getName().indexOf(JETTY_CLASSPATH_CONF_FILE) > 0 )
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Iterator<String> itr = agentClasspathsDirs.iterator();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper "updateJettyStartupJarFile(): Adding path"
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper "ServerClasspathBase.updateJettyStartupJarFile():" +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper " Updating jar failed with exception: " + ex.getMessage());
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper FileUtils.copyFile(newJarPath, startJarPath);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Debug.log("ServerClasspathBase.updateJettyStartupJarFile(): " +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper "Error copying jar file: " + ex.getMessage());
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper private ArrayList<String> getAgentClasspathDirectories(
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Debug.log("UpdateJettyServerClasspath.getAgentClasspathDirectories():" +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper " Get Agent Classpath Directories");
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper ArrayList<String> pathDirs = new ArrayList<String>();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String instanceName = stateAccess.getInstanceName();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String agentLibPath = ConfigUtil.getLibPath();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String agentJarPath = agentLibPath + STR_FORWARD_SLASH + AGENT_JAR;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String sdkJarPath = agentLibPath + STR_FORWARD_SLASH +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String agentLocaleDir = ConfigUtil.getLocaleDirPath();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper protected boolean removeClasspath(IStateAccess stateAccess) {
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Debug.log("ServerClasspathBase.removeClasspath(): " +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper "Remove agent classpath from start.jar.");
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper boolean status = false;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper ArrayList<String> agentClasspathsDirs = getAgentClasspathDirectories(
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String homeDir = (String) stateAccess.get(STR_KEY_JETTY_HOME_DIR);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Debug.log("ServerClasspathBase.removeClasspath(): " +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String startJarPath = homeDir + STR_FORWARD_SLASH + JETTY_START_JAR;
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String newJarPath = homeDir + STR_FORWARD_SLASH + "start-temp.jar";
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper String tempFile = TEMP_DIR + STR_FORWARD_SLASH + "start-conf.temp";
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper JarFile oldJarFile = new JarFile(startJarPath);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper new FileInputStream(new File(startJarPath)));
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper JarEntry entry = oldJarInputStream.getNextJarEntry();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper fos = new JarOutputStream(new FileOutputStream(newJarPath), m);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper fos.putNextEntry(new JarEntry(entry.getName()));
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper if (entry.getName().indexOf(JETTY_CLASSPATH_CONF_FILE) > 0)
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper writeToStream(oldJarInputStream, tempConfFileOut);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Iterator<String> itr = agentClasspathsDirs.iterator();
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper lineNo = FileUtils.getFirstOccurence(tempFile,
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper pathToDel, true, false, false);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper FileUtils.removeLinesByNum(tempFile, lineNo, 1);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper //Now write the file back to fos
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper "ServerClasspathBase.updateJettyStartupJarFile():" +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper " Updating jar failed with exception: " + ex.getMessage());
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper FileUtils.copyFile(newJarPath, startJarPath);
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper Debug.log("ServerClasspathBase.updateJettyStartupJarFile(): " +
2be3e935b5cdea10ddcaf8afff4790d7ce09e950Mark de Reeper "Error copying jar file: " + ex.getMessage());