001/* 002 * Copyright 2010-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2010-2019 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.IndentLDAPFilter; 036import com.unboundid.ldap.sdk.examples.LDAPCompare; 037import com.unboundid.ldap.sdk.examples.LDAPDebugger; 038import com.unboundid.ldap.sdk.examples.LDAPModify; 039import com.unboundid.ldap.sdk.examples.LDAPSearch; 040import com.unboundid.ldap.sdk.examples.ModRate; 041import com.unboundid.ldap.sdk.examples.SearchRate; 042import com.unboundid.ldap.sdk.examples.SearchAndModRate; 043import com.unboundid.ldap.sdk.examples.ValidateLDIF; 044import com.unboundid.ldap.sdk.persist.GenerateSchemaFromSource; 045import com.unboundid.ldap.sdk.persist.GenerateSourceFromSchema; 046import com.unboundid.ldap.sdk.transformations.TransformLDIF; 047import com.unboundid.util.ssl.cert.ManageCertificates; 048 049 050 051/** 052 * This class provides an entry point that may be used to launch other tools 053 * provided as part of the LDAP SDK. This is primarily a convenience for 054 * someone who just has the jar file and none of the scripts, since you can run 055 * "<CODE>java -jar unboundid-ldapsdk.jar {tool-name} {tool-args}</CODE>" 056 * in order to invoke any of the example tools. Running just 057 * "<CODE>java -jar unboundid-ldapsdk.jar</CODE>" will display version 058 * information about the LDAP SDK. 059 * <BR><BR> 060 * The tool names are case-insensitive. Supported tool names include: 061 * <UL> 062 * <LI>authrate -- Launch the {@link AuthRate} tool.</LI> 063 * <LI>base64 -- Launch the {@link Base64Tool} 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>indent-ldap-filter -- Launch the {@link IndentLDAPFilter} tool.</LI> 073 * <LI>in-memory-directory-server -- Launch the 074 * {@link InMemoryDirectoryServerTool} tool.</LI> 075 * <LI>ldapcompare -- Launch the {@link LDAPCompare} tool.</LI> 076 * <LI>ldapmodify -- Launch the {@link LDAPModify} tool.</LI> 077 * <LI>ldapsearch -- Launch the {@link LDAPSearch} tool.</LI> 078 * <LI>ldap-debugger -- Launch the {@link LDAPDebugger} tool.</LI> 079 * <LI>manage-certificates -- Launch the {@link ManageCertificates} tool.</LI> 080 * <LI>modrate -- Launch the {@link ModRate} tool.</LI> 081 * <LI>searchrate -- Launch the {@link SearchRate} tool.</LI> 082 * <LI>search-and-mod-rate -- Launch the {@link SearchAndModRate} tool.</LI> 083 * <LI>transform-ldif -- Launch the {@link TransformLDIF} tool.</LI> 084 * <LI>validate-ldif -- Launch the {@link ValidateLDIF} tool.</LI> 085 * <LI>version -- Display version information for the LDAP SDK.</LI> 086 * </UL> 087 */ 088@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 089public final class Launcher 090{ 091 /** 092 * Prevent this utility class from being externally instantiated. 093 */ 094 private Launcher() 095 { 096 // No implementation required. 097 } 098 099 100 101 /** 102 * Parses the command-line arguments and performs any appropriate processing 103 * for this program. 104 * 105 * @param args The command-line arguments provided to this program. 106 */ 107 public static void main(final String... args) 108 { 109 main(System.out, System.err, args); 110 } 111 112 113 114 /** 115 * Parses the command-line arguments and performs any appropriate processing 116 * for this program. 117 * 118 * @param outStream The output stream to which standard out should be 119 * written. It may be {@code null} if output should be 120 * suppressed. 121 * @param errStream The output stream to which standard error should be 122 * written. It may be {@code null} if error messages 123 * should be suppressed. 124 * @param args The command-line arguments provided to this program. 125 * 126 * @return A result code with information about the status of processing. 127 */ 128 public static ResultCode main(final OutputStream outStream, 129 final OutputStream errStream, 130 final String... args) 131 { 132 133 134 if ((args == null) || (args.length == 0) || 135 args[0].equalsIgnoreCase("version")) 136 { 137 if (outStream != null) 138 { 139 final PrintStream out = new PrintStream(outStream); 140 for (final String line : Version.getVersionLines()) 141 { 142 out.println(line); 143 } 144 } 145 146 return ResultCode.SUCCESS; 147 } 148 149 final String firstArg = StaticUtils.toLowerCase(args[0]); 150 final String[] remainingArgs = new String[args.length - 1]; 151 System.arraycopy(args, 1, remainingArgs, 0, remainingArgs.length); 152 153 if (firstArg.equals("authrate")) 154 { 155 return AuthRate.main(remainingArgs, outStream, errStream); 156 } 157 else if (firstArg.equals("base64")) 158 { 159 return Base64Tool.main(System.in, outStream, errStream, remainingArgs); 160 } 161 else if (firstArg.equals("identify-references-to-missing-entries")) 162 { 163 return IdentifyReferencesToMissingEntries.main(remainingArgs, outStream, 164 errStream); 165 } 166 else if (firstArg.equals("identify-unique-attribute-conflicts")) 167 { 168 return IdentifyUniqueAttributeConflicts.main(remainingArgs, outStream, 169 errStream); 170 } 171 else if (firstArg.equals("indent-ldap-filter")) 172 { 173 return IndentLDAPFilter.main(outStream, errStream, remainingArgs); 174 } 175 else if (firstArg.equals("in-memory-directory-server")) 176 { 177 return InMemoryDirectoryServerTool.main(remainingArgs, outStream, 178 errStream); 179 } 180 else if (firstArg.equals("generate-schema-from-source")) 181 { 182 return GenerateSchemaFromSource.main(remainingArgs, outStream, errStream); 183 } 184 else if (firstArg.equals("generate-source-from-schema")) 185 { 186 return GenerateSourceFromSchema.main(remainingArgs, outStream, errStream); 187 } 188 else if (firstArg.equals("ldapcompare")) 189 { 190 return LDAPCompare.main(remainingArgs, outStream, errStream); 191 } 192 else if (firstArg.equals("ldapmodify")) 193 { 194 return LDAPModify.main(remainingArgs, outStream, errStream); 195 } 196 else if (firstArg.equals("ldapsearch")) 197 { 198 return LDAPSearch.main(remainingArgs, outStream, errStream); 199 } 200 else if (firstArg.equals("ldap-debugger")) 201 { 202 return LDAPDebugger.main(remainingArgs, outStream, errStream); 203 } 204 else if (firstArg.equals("manage-certificates")) 205 { 206 return ManageCertificates.main(System.in, outStream, errStream, 207 remainingArgs); 208 } 209 else if (firstArg.equals("modrate")) 210 { 211 return ModRate.main(remainingArgs, outStream, errStream); 212 } 213 else if (firstArg.equals("searchrate")) 214 { 215 return SearchRate.main(remainingArgs, outStream, errStream); 216 } 217 else if (firstArg.equals("search-and-mod-rate")) 218 { 219 return SearchAndModRate.main(remainingArgs, outStream, errStream); 220 } 221 else if (firstArg.equals("transform-ldif")) 222 { 223 return TransformLDIF.main(outStream, errStream, remainingArgs); 224 } 225 else if (firstArg.equals("validate-ldif")) 226 { 227 return ValidateLDIF.main(remainingArgs, outStream, errStream); 228 } 229 else 230 { 231 if (errStream != null) 232 { 233 final PrintStream err = new PrintStream(errStream); 234 err.println("Unrecognized tool name '" + args[0] + '\''); 235 err.println("Supported tool names include:"); 236 err.println(" authrate"); 237 err.println(" base64"); 238 err.println(" generate-schema-from-source"); 239 err.println(" generate-source-from-schema"); 240 err.println(" identify-references-to-missing-entries"); 241 err.println(" identify-unique-attribute-conflicts"); 242 err.println(" indent-ldap-filter"); 243 err.println(" in-memory-directory-server"); 244 err.println(" ldapcompare"); 245 err.println(" ldapmodify"); 246 err.println(" ldapsearch"); 247 err.println(" ldap-debugger"); 248 err.println(" manage-certificates"); 249 err.println(" modrate"); 250 err.println(" searchrate"); 251 err.println(" search-and-mod-rate"); 252 err.println(" transform-ldif"); 253 err.println(" validate-ldif"); 254 err.println(" version"); 255 } 256 257 return ResultCode.PARAM_ERROR; 258 } 259 } 260}