CopyAgentFilesTask.java revision a5b4af20981ceecfbdf0186421baba60094635b3
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell/**
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell *
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * Copyright (c) 2010-2015 ForgeRock AS. All Rights Reserved
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell *
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * The contents of this file are subject to the terms
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * of the Common Development and Distribution License
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * (the License). You may not use this file except in
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * compliance with the License.
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell *
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * You can obtain a copy of the License at
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * http://forgerock.org/license/CDDLv1.0.html
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * See the License for the specific language governing
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * permission and limitations under the License.
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell *
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * When distributing Covered Code, include this CDDL
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * Header Notice in each file and include the License file
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * at http://forgerock.org/license/CDDLv1.0.html
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * If applicable, add the following below the CDDL Header,
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * with the fields enclosed by brackets [] replaced by
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * your own identifying information:
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * "Portions Copyrighted [year] [name of copyright owner]"
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell *
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell */
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellpackage com.sun.identity.agents.tools.tomcat.v6;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.install.tools.configurator.IStateAccess;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.install.tools.configurator.ITask;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.install.tools.configurator.InstallException;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.install.tools.util.ConfigUtil;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.install.tools.util.Debug;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.install.tools.util.LocalizedMessage;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.install.tools.util.FileUtils;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport java.io.File;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport java.util.Map;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell/**
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell *
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * @author Steve Ferris steve.ferris@forgerock.com
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell */
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellpublic class CopyAgentFilesTask extends AgentFilesBase implements ITask {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell public static final String LOC_TSK_MSG_COPY_AGENT_FILES_SCRIPT_EXECUTE
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell = "TSK_MSG_COPY_AGENT_FILES_SCRIPT_EXECUTE";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell public static final String LOC_TSK_MSG_COPY_AGENT_FILES_SCRIPT_ROLLBACK
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell = "TSK_MSG_COPY_AGENT_FILES_ROLLBACK";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell public boolean execute(String name, IStateAccess stateAccess, Map properties)
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell throws InstallException {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell boolean status = true;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell try {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell super.getAgentConfigLocation(stateAccess);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell status = status && copyAgentJarFiles();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell status = status && copyAgentLocaleFiles();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell status = status && copyAgentAppWarFile();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell } catch (Exception ex) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell status = false;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell Debug.log("CopyAgentFilesTask.execute() - encountered exception " +
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell ex.getMessage(), ex);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell }
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell return status;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell }
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private boolean copyAgentJarFiles() {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell boolean status = true;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell String srcDir = _agentLibPath;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell String destDir = _catalinaHomeDir + STR_FORWARD_SLASH + STR_TOMCAT_COMMON_LIB;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell try {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell for (int i = 0; i < libJarFiles.length; i++) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell FileUtils.copyJarFile(srcDir, destDir, libJarFiles[i]);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell Debug.log("CopyAgentFilesTask.copyAgentJarFiles() - copy " +
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell libJarFiles[i] + " from " + srcDir + " to " + destDir);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell }
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell } catch (Exception ex) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell Debug.log("CopyAgentFilesTask.copyAgentJarFiles() - " +
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell "Error occured while copying jar files from " + srcDir +
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell " to " + destDir + ": " + ex.getMessage());
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell status = false;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell }
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell return status;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell }
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private boolean copyAgentLocaleFiles() {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell boolean status = true;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell String srcDir = _agentLocalePath;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell String destDir = _catalinaHomeDir + STR_FORWARD_SLASH + STR_TOMCAT_COMMON_LIB;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell try {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell for (File localeFile : listAgentLocaleFiles()) {
FileUtils.copyFile(srcDir + System.getProperty("file.separator") + localeFile.getName(),
destDir + System.getProperty("file.separator") + localeFile.getName());
Debug.log("CopyAgentFilesTask.copyAgentLocaleFiles() - copy " +
localeFile.getName() + " from " + srcDir + " to " + destDir);
}
} catch (Exception ex) {
Debug.log("CopyAgentFilesTask.copyAgentLocaleFiles() - " +
"Error occured while copying locale files from " + srcDir +
" to " + destDir + ": " + ex.getMessage());
status = false;
}
return status;
}
private boolean copyAgentAppWarFile() {
boolean status = true;
String srcFile = new StringBuilder(ConfigUtil.getEtcDirPath()).append(File.separator)
.append(STR_AGENT_APP_WAR_FILE).toString();
String destFile = new StringBuilder(_catalinaHomeDir).append(File.separator).append(STR_WEBAPP_DIR)
.append(File.separator).append(STR_AGENT_APP_WAR_FILE).toString();
try {
FileUtils.copyFile(srcFile, destFile);
Debug.log("CopyAgentFilesTask.copyAgentAppWarFile() - copy "
+ STR_AGENT_APP_WAR_FILE + " from " + srcFile + " to " + destFile);
} catch (Exception e) {
Debug.log("CopyAgentFilesTask.copyAgentAppWarFile() - Error occurred while copying "
+ STR_AGENT_APP_WAR_FILE + " from " + srcFile + " to " + destFile, e);
status = false;
}
return status;
}
public LocalizedMessage getExecutionMessage(IStateAccess stateAccess,
Map properties) {
super.getAgentConfigLocation(stateAccess);
LocalizedMessage message = LocalizedMessage.get(
LOC_TSK_MSG_COPY_AGENT_FILES_SCRIPT_EXECUTE,
STR_TOMCAT_GROUP, null);
return message;
}
public LocalizedMessage getRollBackMessage(IStateAccess stateAccess,
Map properties) {
LocalizedMessage message = LocalizedMessage.get(
LOC_TSK_MSG_COPY_AGENT_FILES_SCRIPT_ROLLBACK,
STR_TOMCAT_GROUP, null);
return message;
}
public boolean rollBack(String name, IStateAccess stateAccess,
Map properties) throws InstallException {
boolean status = false;
status = super.removeAgentFiles(stateAccess);
return status;
}
}