001/* 002 * Copyright 2010-2017 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2010-2017 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.util; 022 023 024 025import java.io.OutputStream; 026import java.io.PrintStream; 027 028import com.unboundid.ldap.listener.InMemoryDirectoryServerTool; 029import com.unboundid.ldap.sdk.ResultCode; 030import com.unboundid.ldap.sdk.Version; 031import com.unboundid.ldap.sdk.examples.AuthRate; 032import com.unboundid.ldap.sdk.examples.Base64Tool; 033import com.unboundid.ldap.sdk.examples.IdentifyReferencesToMissingEntries; 034import com.unboundid.ldap.sdk.examples.IdentifyUniqueAttributeConflicts; 035import com.unboundid.ldap.sdk.examples.LDAPCompare; 036import com.unboundid.ldap.sdk.examples.LDAPDebugger; 037import com.unboundid.ldap.sdk.examples.LDAPModify; 038import com.unboundid.ldap.sdk.examples.LDAPSearch; 039import com.unboundid.ldap.sdk.examples.ModRate; 040import com.unboundid.ldap.sdk.examples.SearchRate; 041import com.unboundid.ldap.sdk.examples.SearchAndModRate; 042import com.unboundid.ldap.sdk.examples.ValidateLDIF; 043import com.unboundid.ldap.sdk.persist.GenerateSchemaFromSource; 044import com.unboundid.ldap.sdk.persist.GenerateSourceFromSchema; 045import com.unboundid.ldap.sdk.transformations.TransformLDIF; 046 047 048 049/** 050 * This class provides an entry point that may be used to launch other tools 051 * provided as part of the LDAP SDK. This is primarily a convenience for 052 * someone who just has the jar file and none of the scripts, since you can run 053 * "<CODE>java -jar unboundid-ldapsdk.jar {tool-name} {tool-args}</CODE>" 054 * in order to invoke any of the example tools. Running just 055 * "<CODE>java -jar unboundid-ldapsdk.jar</CODE>" will display version 056 * information about the LDAP SDK. 057 * <BR><BR> 058 * The tool names are case-insensitive. Supported tool names include: 059 * <UL> 060 * <LI>authrate -- Launch the {@link AuthRate} tool.</LI> 061 * <LI>base64 -- Launch the {@link Base64Tool} tool.</LI> 062 * <LI>in-memory-directory-server -- Launch the 063 * {@link InMemoryDirectoryServerTool} tool.</LI> 064 * <LI>generate-schema-from-source -- Launch the 065 * {@link GenerateSchemaFromSource} tool.</LI> 066 * <LI>generate-source-from-schema -- Launch the 067 * {@link GenerateSourceFromSchema} tool.</LI> 068 * <LI>identify-references-to-missing-entries -- Launch the 069 * {@link IdentifyReferencesToMissingEntries} tool.</LI> 070 * <LI>identify-unique-attribute-conflicts -- Launch the 071 * {@link IdentifyUniqueAttributeConflicts} tool.</LI> 072 * <LI>in-memory-directory-server -- Launch the 073 * {@link InMemoryDirectoryServerTool} tool.</LI> 074 * <LI>ldapcompare -- Launch the {@link LDAPCompare} tool.</LI> 075 * <LI>ldapmodify -- Launch the {@link LDAPModify} tool.</LI> 076 * <LI>ldapsearch -- Launch the {@link LDAPSearch} tool.</LI> 077 * <LI>ldap-debugger -- Launch the {@link LDAPDebugger} tool.</LI> 078 * <LI>modrate -- Launch the {@link ModRate} tool.</LI> 079 * <LI>searchrate -- Launch the {@link SearchRate} tool.</LI> 080 * <LI>search-and-mod-rate -- Launch the {@link SearchAndModRate} tool.</LI> 081 * <LI>transform-ldif -- Launch the {@link TransformLDIF} tool.</LI> 082 * <LI>validate-ldif -- Launch the {@link ValidateLDIF} tool.</LI> 083 * <LI>version -- Display version information for the LDAP SDK.</LI> 084 * </UL> 085 */ 086@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 087public final class Launcher 088{ 089 /** 090 * Prevent this utility class from being externally instantiated. 091 */ 092 private Launcher() 093 { 094 // No implementation required. 095 } 096 097 098 099 /** 100 * Parses the command-line arguments and performs any appropriate processing 101 * for this program. 102 * 103 * @param args The command-line arguments provided to this program. 104 */ 105 public static void main(final String... args) 106 { 107 main(System.out, System.err, args); 108 } 109 110 111 112 /** 113 * Parses the command-line arguments and performs any appropriate processing 114 * for this program. 115 * 116 * @param outStream The output stream to which standard out should be 117 * written. It may be {@code null} if output should be 118 * suppressed. 119 * @param errStream The output stream to which standard error should be 120 * written. It may be {@code null} if error messages 121 * should be suppressed. 122 * @param args The command-line arguments provided to this program. 123 * 124 * @return A result code with information about the status of processing. 125 */ 126 public static ResultCode main(final OutputStream outStream, 127 final OutputStream errStream, 128 final String... args) 129 { 130 if ((args == null) || (args.length == 0) || 131 args[0].equalsIgnoreCase("version")) 132 { 133 if (outStream != null) 134 { 135 final PrintStream out = new PrintStream(outStream); 136 for (final String line : Version.getVersionLines()) 137 { 138 out.println(line); 139 } 140 } 141 142 return ResultCode.SUCCESS; 143 } 144 145 final String firstArg = StaticUtils.toLowerCase(args[0]); 146 final String[] remainingArgs = new String[args.length - 1]; 147 System.arraycopy(args, 1, remainingArgs, 0, remainingArgs.length); 148 149 if (firstArg.equals("authrate")) 150 { 151 return AuthRate.main(remainingArgs, outStream, errStream); 152 } 153 else if (firstArg.equals("base64")) 154 { 155 return Base64Tool.main(System.in, outStream, errStream, remainingArgs); 156 } 157 else if (firstArg.equals("identify-references-to-missing-entries")) 158 { 159 return IdentifyReferencesToMissingEntries.main(remainingArgs, outStream, 160 errStream); 161 } 162 else if (firstArg.equals("identify-unique-attribute-conflicts")) 163 { 164 return IdentifyUniqueAttributeConflicts.main(remainingArgs, outStream, 165 errStream); 166 } 167 else if (firstArg.equals("in-memory-directory-server")) 168 { 169 return InMemoryDirectoryServerTool.main(remainingArgs, outStream, 170 errStream); 171 } 172 else if (firstArg.equals("generate-schema-from-source")) 173 { 174 return GenerateSchemaFromSource.main(remainingArgs, outStream, errStream); 175 } 176 else if (firstArg.equals("generate-source-from-schema")) 177 { 178 return GenerateSourceFromSchema.main(remainingArgs, outStream, errStream); 179 } 180 else if (firstArg.equals("ldapcompare")) 181 { 182 return LDAPCompare.main(remainingArgs, outStream, errStream); 183 } 184 else if (firstArg.equals("ldapmodify")) 185 { 186 return LDAPModify.main(remainingArgs, outStream, errStream); 187 } 188 else if (firstArg.equals("ldapsearch")) 189 { 190 return LDAPSearch.main(remainingArgs, outStream, errStream); 191 } 192 else if (firstArg.equals("ldap-debugger")) 193 { 194 return LDAPDebugger.main(remainingArgs, outStream, errStream); 195 } 196 else if (firstArg.equals("modrate")) 197 { 198 return ModRate.main(remainingArgs, outStream, errStream); 199 } 200 else if (firstArg.equals("searchrate")) 201 { 202 return SearchRate.main(remainingArgs, outStream, errStream); 203 } 204 else if (firstArg.equals("search-and-mod-rate")) 205 { 206 return SearchAndModRate.main(remainingArgs, outStream, errStream); 207 } 208 else if (firstArg.equals("transform-ldif")) 209 { 210 return TransformLDIF.main(outStream, errStream, remainingArgs); 211 } 212 else if (firstArg.equals("validate-ldif")) 213 { 214 return ValidateLDIF.main(remainingArgs, outStream, errStream); 215 } 216 else 217 { 218 if (errStream != null) 219 { 220 final PrintStream err = new PrintStream(errStream); 221 err.println("Unrecognized tool name '" + args[0] + '\''); 222 err.println("Supported tool names include:"); 223 err.println(" authrate"); 224 err.println(" base64"); 225 err.println(" identify-references-to-missing-entries"); 226 err.println(" identify-unique-attribute-conflicts"); 227 err.println(" in-memory-directory-server"); 228 err.println(" generate-schema-from-source"); 229 err.println(" generate-source-from-schema"); 230 err.println(" ldapcompare"); 231 err.println(" ldapmodify"); 232 err.println(" ldapsearch"); 233 err.println(" ldap-debugger"); 234 err.println(" modrate"); 235 err.println(" searchrate"); 236 err.println(" search-and-mod-rate"); 237 err.println(" transform-ldif"); 238 err.println(" validate-ldif"); 239 err.println(" version"); 240 } 241 242 return ResultCode.PARAM_ERROR; 243 } 244 } 245}