| | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.tools.ToolConstants.*; |
| | | import static org.opends.server.tools.dsconfig.ArgumentExceptionFactory.*; |
| | | import static org.opends.server.util.ServerConstants.PROPERTY_SCRIPT_NAME; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | import java.io.BufferedWriter; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.util.EmbeddedUtils; |
| | | import org.opends.server.util.ServerConstants; |
| | | import org.opends.server.util.SetupUtils; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.opends.server.util.args.ArgumentException; |
| | | import org.opends.server.util.args.BooleanArgument; |
| | |
| | | // This CLI is always using the administration connector with SSL |
| | | private static final boolean alwaysSSL = true; |
| | | |
| | | private long sessionStartTime; |
| | | private boolean sessionStartTimePrinted = false; |
| | | private int sessionEquivalentOperationNumber = 0; |
| | | |
| | | /** |
| | | * Provides the command-line arguments to the main application for |
| | |
| | | OutputStream outStream, OutputStream errStream) { |
| | | DSConfig app = new DSConfig(System.in, outStream, errStream, |
| | | new LDAPManagementContextFactory(alwaysSSL)); |
| | | app.sessionStartTime = System.currentTimeMillis(); |
| | | // Only initialize the client environment when run as a standalone |
| | | // application. |
| | | if (initializeServer) { |
| | |
| | | // properties file. |
| | | private BooleanArgument noPropertiesFileArgument; |
| | | |
| | | // The boolean that is used to know if data must be appended to the file |
| | | // containing equivalent non-interactive commands. |
| | | private boolean alreadyWroteEquivalentCommand; |
| | | |
| | | /** |
| | | * Creates a new dsconfig application instance. |
| | | * |
| | |
| | | } |
| | | if (equivalentCommandFileArgument.isPresent()) |
| | | { |
| | | // Write to the file. |
| | | boolean append = alreadyWroteEquivalentCommand; |
| | | String file = equivalentCommandFileArgument.getValue(); |
| | | try |
| | | { |
| | | BufferedWriter writer = |
| | | new BufferedWriter(new FileWriter(file, append)); |
| | | new BufferedWriter(new FileWriter(file, true)); |
| | | |
| | | if (!sessionStartTimePrinted) |
| | | { |
| | | writer.write(SHELL_COMMENT_SEPARATOR+getSessionStartTimeMessage()); |
| | | writer.newLine(); |
| | | sessionStartTimePrinted = true; |
| | | } |
| | | |
| | | sessionEquivalentOperationNumber++; |
| | | writer.newLine(); |
| | | writer.write(SHELL_COMMENT_SEPARATOR+ |
| | | INFO_DSCFG_EQUIVALENT_COMMAND_LINE_SESSION_OPERATION_NUMBER.get( |
| | | sessionEquivalentOperationNumber)); |
| | | writer.newLine(); |
| | | |
| | | writer.write(SHELL_COMMENT_SEPARATOR+getCurrentOperationDateMessage()); |
| | | writer.newLine(); |
| | | |
| | | writer.write(commandBuilder.toString()); |
| | | writer.newLine(); |
| | | writer.newLine(); |
| | | |
| | | writer.flush(); |
| | | writer.close(); |
| | |
| | | println(ERR_DSCFG_ERROR_WRITING_EQUIVALENT_COMMAND_LINE.get(file, |
| | | ioe.toString())); |
| | | } |
| | | alreadyWroteEquivalentCommand = true; |
| | | } |
| | | } |
| | | |
| | | private void handleBatchFile(String[] args) { |
| | | /** |
| | | * Returns the message to be displayed in the file with the equivalent |
| | | * command-line with information about when the session started. |
| | | * @return the message to be displayed in the file with the equivalent |
| | | * command-line with information about when the session started. |
| | | */ |
| | | private String getSessionStartTimeMessage() |
| | | { |
| | | String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); |
| | | if ((scriptName == null) || (scriptName.length() == 0)) |
| | | { |
| | | scriptName = "dsconfig"; |
| | | } |
| | | String date = formatDateTimeStringForEquivalentCommand( |
| | | new Date(sessionStartTime)); |
| | | return INFO_DSCFG_SESSION_START_TIME_MESSAGE.get(scriptName, date). |
| | | toString(); |
| | | } |
| | | |
| | | private void handleBatchFile(String[] args) |
| | | { |
| | | BufferedReader reader = null; |
| | | try { |
| | | // Build a list of initial arguments, |
| | |
| | | println(ERR_DSCFG_ERROR_READING_BATCH_FILE.get(ex.toString())); |
| | | } |
| | | } |
| | | |
| | | } |