001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2010 Sun Microsystems, Inc. 015 * Portions Copyright 2011-2016 ForgeRock AS. 016 */ 017package org.opends.guitools.uninstaller; 018 019import static org.opends.messages.AdminToolMessages.*; 020import static org.opends.messages.ToolMessages.ERR_ERROR_PARSING_ARGS; 021import static com.forgerock.opendj.util.OperatingSystem.isWindows; 022import static com.forgerock.opendj.cli.Utils.wrapText; 023 024import org.forgerock.i18n.LocalizableMessage; 025import org.opends.messages.ToolMessages; 026 027import org.opends.quicksetup.CliApplication; 028import org.opends.quicksetup.Launcher; 029import org.opends.quicksetup.Installation; 030import org.opends.quicksetup.ReturnCode; 031import org.opends.quicksetup.util.Utils; 032import org.opends.server.util.DynamicConstants; 033import org.opends.server.util.ServerConstants; 034import com.forgerock.opendj.cli.ArgumentException; 035import com.forgerock.opendj.cli.ArgumentParser; 036 037/** 038 * This class is called by the uninstall command lines to launch the uninstall 039 * of the Directory Server. It just checks the command line arguments and the 040 * environment and determines whether the graphical or the command line 041 * based uninstall much be launched. 042 */ 043public class UninstallLauncher extends Launcher { 044 045 /** Prefix for log files. */ 046 public static final String LOG_FILE_PREFIX = "opendj-uninstall-"; 047 048 /** 049 * The main method which is called by the uninstall command lines. 050 * 051 * @param args the arguments passed by the command lines. In the case 052 * we want to launch the cli setup they are basically the arguments that we 053 * will pass to the org.opends.server.tools.InstallDS class. 054 */ 055 public static void main(String[] args) { 056 new UninstallLauncher(args).launch(); 057 } 058 059 private UninstallerArgumentParser argParser; 060 061 /** 062 * Creates a launcher. 063 * 064 * @param args the arguments passed by the command lines. 065 */ 066 public UninstallLauncher(String[] args) { 067 super(args, LOG_FILE_PREFIX); 068 069 String scriptName; 070 if (isWindows()) { 071 scriptName = Installation.WINDOWS_UNINSTALL_FILE_NAME; 072 } else { 073 scriptName = Installation.UNIX_UNINSTALL_FILE_NAME; 074 } 075 if (System.getProperty(ServerConstants.PROPERTY_SCRIPT_NAME) == null) 076 { 077 System.setProperty(ServerConstants.PROPERTY_SCRIPT_NAME, scriptName); 078 } 079 080 initializeParser(); 081 } 082 083 @Override 084 public void launch() { 085 // Validate user provided data 086 try 087 { 088 argParser.parseArguments(args); 089 if (argParser.isVersionArgumentPresent()) 090 { 091 System.exit(ReturnCode.PRINT_VERSION.getReturnCode()); 092 } 093 else if (argParser.usageOrVersionDisplayed()) 094 { 095 // If there was no problem parsing arguments, this means that the user 096 // asked to display the usage. 097 System.exit(ReturnCode.SUCCESSFUL.getReturnCode()); 098 } 099 else 100 { 101 super.launch(); 102 } 103 } 104 catch (ArgumentException ae) 105 { 106 argParser.displayMessageAndUsageReference(System.err, ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); 107 System.exit(ReturnCode.USER_DATA_ERROR.getReturnCode()); 108 } 109 } 110 111 /** Initialize the contents of the argument parser. */ 112 protected void initializeParser() 113 { 114 argParser = new UninstallerArgumentParser(getClass().getName(), 115 INFO_UNINSTALL_LAUNCHER_USAGE_DESCRIPTION.get(), false); 116 try 117 { 118 argParser.initializeGlobalArguments(System.out); 119 } 120 catch (ArgumentException ae) 121 { 122 LocalizableMessage message = 123 ToolMessages.ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage()); 124 System.err.println(wrapText(message, 125 Utils.getCommandLineMaxLineWidth())); 126 } 127 } 128 129 @Override 130 protected void guiLaunchFailed() { 131 System.err.println( 132 tempLogFile.isEnabled() ? ERR_UNINSTALL_LAUNCHER_GUI_LAUNCHED_FAILED_DETAILS.get(tempLogFile.getPath()) 133 : ERR_UNINSTALL_LAUNCHER_GUI_LAUNCHED_FAILED.get()); 134 } 135 136 @Override 137 public ArgumentParser getArgumentParser() { 138 return this.argParser; 139 } 140 141 @Override 142 protected void willLaunchGui() { 143 System.out.println(INFO_UNINSTALL_LAUNCHER_LAUNCHING_GUI.get()); 144 System.setProperty("org.opends.quicksetup.Application.class", 145 org.opends.guitools.uninstaller.Uninstaller.class.getName()); 146 } 147 148 @Override 149 protected CliApplication createCliApplication() { 150 return new Uninstaller(); 151 } 152 153 @Override 154 protected LocalizableMessage getFrameTitle() { 155 return Utils.getCustomizedObject("INFO_FRAME_UNINSTALL_TITLE", 156 INFO_FRAME_UNINSTALL_TITLE.get(DynamicConstants.PRODUCT_NAME), 157 LocalizableMessage.class); 158 } 159 160 @Override 161 protected boolean shouldPrintUsage() { 162 return argParser.isUsageArgumentPresent() && 163 !argParser.usageOrVersionDisplayed(); 164 } 165 166 @Override 167 protected boolean isQuiet() { 168 return argParser.isQuiet(); 169 } 170 171 /** 172 * Indicates whether the launcher should print a usage statement 173 * based on the content of the arguments passed into the constructor. 174 * @return boolean where true indicates usage should be printed 175 */ 176 protected boolean isNoPrompt() { 177 return !argParser.isInteractive(); 178 } 179 180 @Override 181 protected boolean shouldPrintVersion() { 182 return argParser.isVersionArgumentPresent() && 183 !argParser.usageOrVersionDisplayed(); 184 } 185 186 @Override 187 protected boolean isCli() { 188 return argParser.isCli(); 189 } 190}