<commit_before>/*
 *   Copyright 2004 The Apache Software Foundation
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package org.apache.directory.server.tools;

import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import org.apache.commons.cli.CommandLine;
import org.apache.directory.server.configuration.ServerStartupConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;


/**
 * The main() application which executes command targets.
 * 
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 * @version $Rev$
 */
public class ApachedsTools
{
    public static void main( String[] args ) throws Exception
    {
        BaseCommand tools = getInstance();
        
        if ( !BaseCommand.hasBannerOption( args ) )
        {
            tools.printBanner();
        }

        if ( args.length == 0 )
        {
            System.err.println( "Type " + tools.getProductCommand() + " help for usage." );
            System.exit( 1 );
        }

        // help is a special command 
        String command = args[0].toLowerCase();
        if ( "help".equals( command ) )
        {
            CommandLine cmdline = tools.getCommandLine( command, args );
            if ( cmdline.getArgs().length > 1 )
            {
                tools.helpOnCommand( cmdline.getArgs()[1] );
                System.exit( 0 );
            }
            else
            {
                tools.printUsage();
                System.exit( 0 );
            }
        }
        else if ( command.equals( "-version" ) )
        {
            System.out.println( tools.getProductCommand() + " version " + tools.getProductVersion() );
            System.exit( 0 );
        }

        ToolCommand cmd = ( ToolCommand ) tools.getCommands().get( command );
        if ( cmd == null )
        {
            System.err.println( "Unknown command: " + args[0] );
            System.err.println( "Type " + tools.getProductCommand() + " help for usage." );
            System.exit( 1 );
        }

        CommandLine cmdline = tools.getCommandLine( command, args );
        if ( cmdline.hasOption( 'd' ) )
        {
            cmd.setDebugEnabled( true );
            BaseCommand.dumpArgs( "raw command line arguments: ", args );
            BaseCommand.dumpArgs( "parsed arguments: ", cmdline.getArgs() );
        }

        cmd.setQuietEnabled( cmdline.hasOption( 'q' ) );
        cmd.setDebugEnabled( cmdline.hasOption( 'd' ) );
        cmd.setVerboseEnabled( cmdline.hasOption( 'v' ) );
        cmd.setVersion( tools.getProductVersion() );
        if ( cmdline.getOptionValue( 'i' ) != null )
        {
            cmd.setLayout( cmdline.getOptionValue( 'i' ) );
            if ( !cmd.isQuietEnabled() )
            {
                System.out.println( "loading settings from: " + cmd.getLayout().getConfigurationFile() );
            }
            ApplicationContext factory = null;
            URL configUrl = configUrl = cmd.getLayout().getConfigurationFile().toURL();
            factory = new FileSystemXmlApplicationContext( configUrl.toString() );
            cmd.setConfiguration( ( ServerStartupConfiguration ) factory.getBean( "configuration" ) );
        }
        else if ( cmdline.hasOption( 'c' ) )
        {
            System.err.println( "forced configuration load (-c) requires the -i option" );
            System.exit( 1 );
        }

        cmd.execute( cmdline );
    }


    public static BaseCommand getInstance() throws InstantiationException, IllegalAccessException, ClassNotFoundException
    {
        Properties props = new Properties();
        try
        {
            props.load( BaseCommand.class.getResourceAsStream( "product.properties" ) );
        }<commit_msg>Minor update for removing unnecassary code.<commit_after>/*
 *   Copyright 2004 The Apache Software Foundation
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package org.apache.directory.server.tools;

import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import org.apache.commons.cli.CommandLine;
import org.apache.directory.server.configuration.ServerStartupConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;


/**
 * The main() application which executes command targets.
 * 
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 * @version $Rev$
 */
public class ApachedsTools
{
    public static void main( String[] args ) throws Exception
    {
        BaseCommand tools = getInstance();
        
        if ( !BaseCommand.hasBannerOption( args ) )
        {
            tools.printBanner();
        }

        if ( args.length == 0 )
        {
            System.err.println( "Type " + tools.getProductCommand() + " help for usage." );
            System.exit( 1 );
        }

        // help is a special command 
        String command = args[0].toLowerCase();
        if ( "help".equals( command ) )
        {
            CommandLine cmdline = tools.getCommandLine( command, args );
            if ( cmdline.getArgs().length > 1 )
            {
                tools.helpOnCommand( cmdline.getArgs()[1] );
                System.exit( 0 );
            }
            else
            {
                tools.printUsage();
                System.exit( 0 );
            }
        }
        else if ( command.equals( "-version" ) )
        {
            System.out.println( tools.getProductCommand() + " version " + tools.getProductVersion() );
            System.exit( 0 );
        }

        ToolCommand cmd = ( ToolCommand ) tools.getCommands().get( command );
        if ( cmd == null )
        {
            System.err.println( "Unknown command: " + args[0] );
            System.err.println( "Type " + tools.getProductCommand() + " help for usage." );
            System.exit( 1 );
        }

        CommandLine cmdline = tools.getCommandLine( command, args );
        if ( cmdline.hasOption( 'd' ) )
        {
            cmd.setDebugEnabled( true );
            BaseCommand.dumpArgs( "raw command line arguments: ", args );
            BaseCommand.dumpArgs( "parsed arguments: ", cmdline.getArgs() );
        }

        cmd.setQuietEnabled( cmdline.hasOption( 'q' ) );
        cmd.setDebugEnabled( cmdline.hasOption( 'd' ) );
        cmd.setVerboseEnabled( cmdline.hasOption( 'v' ) );
        cmd.setVersion( tools.getProductVersion() );
        if ( cmdline.getOptionValue( 'i' ) != null )
        {
            cmd.setLayout( cmdline.getOptionValue( 'i' ) );
            if ( !cmd.isQuietEnabled() )
            {
                System.out.println( "loading settings from: " + cmd.getLayout().getConfigurationFile() );
            }
            ApplicationContext factory = null;
            URL configUrl = cmd.getLayout().getConfigurationFile().toURL();
            factory = new FileSystemXmlApplicationContext( configUrl.toString() );
            cmd.setConfiguration( ( ServerStartupConfiguration ) factory.getBean( "configuration" ) );
        }
        else if ( cmdline.hasOption( 'c' ) )
        {
            System.err.println( "forced configuration load (-c) requires the -i option" );
            System.exit( 1 );
        }

        cmd.execute( cmdline );
    }


    public static BaseCommand getInstance() throws InstantiationException, IllegalAccessException, ClassNotFoundException
    {
        Properties props = new Properties();
        try
        {
            props.load( BaseCommand.class.getResourceAsStream( "product.properties" ) );
        }
{'fraction_non_alphanumeric': 0.11103448275862068, 'fraction_numerical': 0.004367816091954023, 'mean_word_length': 2.151394422310757, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4049118', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2267, 'n_words': 592}