Exemplo n.º 1
0
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <returns>The application exit code.</returns>
        public static int Main()
        {
            // Parse arguments.
            var args = ArgumentTokenizer
                       .Tokenize(Environment.CommandLine)
                       .Skip(1) // Skip executable.
                       .ToArray();

            // Are we running on Mono?
            var mono = Type.GetType("Mono.Runtime") != null;

            if (!mono)
            {
                // Not using the mono compiler, but do we want to?
                if (args.Contains("-mono"))
                {
                    mono = true;
                }
            }

            using (var container = CreateContainer(mono))
            {
                // Resolve and run the application.
                var application = container.Resolve <CakeApplication>();
                return(application.Run(args));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <returns>The application exit code.</returns>
        public static int Main()
        {
            ICakeLog log = null;

            try
            {
                // Parse arguments.
                var args = ArgumentTokenizer
                           .Tokenize(Environment.CommandLine)
                           .Skip(1) // Skip executable.
                           .ToArray();

                var builder = new CakeContainerBuilder();
                builder.Registry.RegisterModule(new CakeModule());
                builder.Registry.RegisterModule(new CoreModule());
                builder.Registry.RegisterModule(new NuGetModule());

                // Build the container.
                using (var container = builder.Build())
                {
                    // Resolve the log.
                    log = container.Resolve <ICakeLog>();

                    // Parse the options.
                    var parser  = container.Resolve <IArgumentParser>();
                    var options = parser.Parse(args);

                    // Set verbosity.
                    log.Verbosity = options.Verbosity;

                    // Rebuild the container.
                    builder = new CakeContainerBuilder();
                    builder.Registry.RegisterModule(new ArgumentsModule(options));
                    builder.Registry.RegisterModule(new ConfigurationModule(container, options));
                    builder.Registry.RegisterModule(new ScriptingModule(options));
                    builder.Update(container);

                    // Load all modules.
                    var loader = container.Resolve <ModuleLoader>();
                    loader.LoadModules(container, options);

                    // Resolve and run the application.
                    var application = container.Resolve <CakeApplication>();
                    return(application.Run(options));
                }
            }
            catch (Exception ex)
            {
                log = log ?? new CakeBuildLog(new CakeConsole());
                if (log.Verbosity == Verbosity.Diagnostic)
                {
                    log.Error("Error: {0}", ex);
                }
                else
                {
                    log.Error("Error: {0}", ex.Message);
                }
                return(1);
            }
        }
Exemplo n.º 3
0
            public void Should_Return_Zero_Results_If_Input_String_Is_Null()
            {
                // Given
                var input = string.Empty;

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(0, result.Length);
            }
Exemplo n.º 4
0
            public void Should_Parse_Single_Quoted_Argument_With_Space_In_It()
            {
                // Given
                const string input = "\"C:\\cake walk\\cake.exe\"";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(1, result.Length);
                Assert.Equal("\"C:\\cake walk\\cake.exe\"", result[0]);
            }
Exemplo n.º 5
0
            public void Should_Parse_Multiple_Quoted_Arguments()
            {
                // Given
                const string input = "\"C:\\cake-walk\\cake.exe\" \"build.cake\" \"-dryrun\"";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(3, result.Length);
                Assert.Equal("\"C:\\cake-walk\\cake.exe\"", result[0]);
                Assert.Equal("\"build.cake\"", result[1]);
                Assert.Equal("\"-dryrun\"", result[2]);
            }
Exemplo n.º 6
0
            public void Should_Parse_Part_That_Contains_Quotes_With_Space_In_It()
            {
                // Given
                const string input = @"cake.exe build.cake -target=""te st""";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(3, result.Length);
                Assert.Equal("cake.exe", result[0]);
                Assert.Equal("build.cake", result[1]);
                Assert.Equal("-target=\"te st\"", result[2]);
            }
Exemplo n.º 7
0
            public void Should_Parse_Multiple_Mixed_Arguments()
            {
                // Given
                const string input = "\"C:\\cake-walk\\cake.exe\" build.cake -verbosity \"diagnostic\"";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(4, result.Length);
                Assert.Equal("\"C:\\cake-walk\\cake.exe\"", result[0]);
                Assert.Equal("build.cake", result[1]);
                Assert.Equal("-verbosity", result[2]);
                Assert.Equal("\"diagnostic\"", result[3]);
            }
    protected internal virtual string processNestedFunctions(string arguments)
    {
        StringBuilder evaluatedArguments = new StringBuilder();

        // Process nested function calls.
        if (arguments.Length > 0)
        {
            Evaluator argumentsEvaluator = new Evaluator(quoteCharacter, loadMathVariables, loadMathFunctions, loadStringFunctions, processNestedFunctions_Renamed);
            argumentsEvaluator.Functions        = Functions;
            argumentsEvaluator.Variables        = Variables;
            argumentsEvaluator.VariableResolver = VariableResolver;


            ArgumentTokenizer tokenizer = new ArgumentTokenizer(arguments, EvaluationConstants.FUNCTION_ARGUMENT_SEPARATOR);

            IList evalautedArgumentList = new ArrayList();
            while (tokenizer.hasMoreTokens())
            {
                string argument = tokenizer.nextToken().Trim();

                try
                {
                    argument = argumentsEvaluator.evaluate(argument);
                }
                catch (Exception e)
                {
                    throw new EvaluationException(e.Message, e);
                }

                evalautedArgumentList.Add(argument);
            }

            IEnumerator evaluatedArgumentIterator = evalautedArgumentList.GetEnumerator();

            while (evaluatedArgumentIterator.MoveNext())
            {
                if (evaluatedArguments.Length > 0)
                {
                    evaluatedArguments.Append(EvaluationConstants.FUNCTION_ARGUMENT_SEPARATOR);
                }

                string evaluatedArgument = (string)evaluatedArgumentIterator.Current;
                evaluatedArguments.Append(evaluatedArgument);
            }
        }

        return(evaluatedArguments.ToString());
    }
    /// <summary>
    /// This methods takes a string of input function arguments, evaluates each
    /// argument and creates a Double value for each argument from the result of
    /// the evaluations.
    /// </summary>
    /// <param name="arguments">
    ///            The arguments to parse. </param>
    /// <param name="delimiter">
    ///            The delimiter to use while parsing.
    /// </param>
    /// <returns> An array list of Double values found in the input string.
    /// </returns>
    /// <exception cref="FunctionException">
    ///                Thrown if the string does not properly parse into Double
    ///                values. </exception>
    //ORIGINAL LINE: public static java.util.ArrayList getDoubles(final String arguments, final char delimiter) throws FunctionException
    public static ArrayList getDoubles(string arguments, char delimiter)
    {
        ArrayList returnValues = new ArrayList();

        try
        {
            //ORIGINAL LINE: final net.sourceforge.jeval.ArgumentTokenizer tokenizer = new net.sourceforge.jeval.ArgumentTokenizer(arguments, delimiter);
            ArgumentTokenizer tokenizer = new ArgumentTokenizer(arguments, delimiter);
            while (tokenizer.hasMoreTokens())
            {
                //ORIGINAL LINE: final String token = tokenizer.nextToken().trim();
                string token = tokenizer.nextToken().Trim();
                returnValues.Add(Convert.ToDouble(token));
            }
        }
        catch (Exception e)
        {
            throw new FunctionException("Invalid values in string.", e);
        }
        return(returnValues);
    }
    /// <summary>
    /// This methods takes a string of input function arguments, evaluates each
    /// argument and creates a String value for each argument from the result of
    /// the evaluations.
    /// </summary>
    /// <param name="arguments">
    ///            The arguments of values to parse. </param>
    /// <param name="delimiter">
    ///            The delimiter to use while parsing.
    /// </param>
    /// <returns> An array list of String values found in the input string.
    /// </returns>
    /// <exception cref="FunctionException">
    ///                Thrown if the stirng does not properly parse into String
    ///                values. </exception>
    //ORIGINAL LINE: public static java.util.ArrayList getStrings(final String arguments, final char delimiter) throws FunctionException
    public static ArrayList getStrings(string arguments, char delimiter)
    {
        //ORIGINAL LINE: final java.util.ArrayList returnValues = new java.util.ArrayList();
        ArrayList returnValues = new ArrayList();

        try
        {
            ArgumentTokenizer tokenizer = new ArgumentTokenizer(arguments, delimiter);
            while (tokenizer.hasMoreTokens())
            {
                //ORIGINAL LINE: final String token = tokenizer.nextToken();
                string token = tokenizer.nextToken();
                returnValues.Add(token);
            }
        }
        catch (Exception e)
        {
            throw new FunctionException("Invalid values in string.", e);
        }
        return(returnValues);
    }
    /// <summary>
    /// This methods takes a string of input function arguments, evaluates each
    /// argument and creates a one String and two Integers value for each
    /// argument from the result of the evaluations.
    /// </summary>
    /// <param name="arguments">
    ///            The arguments of values to parse. </param>
    /// <param name="delimiter">
    ///            The delimiter to use while parsing.
    /// </param>
    /// <returns> An array list of object values found in the input string.
    /// </returns>
    /// <exception cref="FunctionException">
    ///                Thrown if the stirng does not properly parse into the
    ///                proper objects. </exception>
    //ORIGINAL LINE: public static java.util.ArrayList getOneStringAndTwoIntegers(final String arguments, final char delimiter) throws FunctionException
    public static ArrayList getOneStringAndTwoIntegers(string arguments, char delimiter)
    {
        //ORIGINAL LINE: final java.util.ArrayList returnValues = new java.util.ArrayList();
        ArrayList returnValues = new ArrayList();

        try
        {
            //ORIGINAL LINE: final net.sourceforge.jeval.ArgumentTokenizer tokenizer = new net.sourceforge.jeval.ArgumentTokenizer(arguments, delimiter);
            ArgumentTokenizer tokenizer = new ArgumentTokenizer(arguments, delimiter);
            int tokenCtr = 0;
            while (tokenizer.hasMoreTokens())
            {
                if (tokenCtr == 0)
                {
                    //ORIGINAL LINE: final String token = tokenizer.nextToken().trim();
                    string token = tokenizer.nextToken().Trim();
                    returnValues.Add(token);
                }
                else if (tokenCtr == 1 || tokenCtr == 2)
                {
                    //ORIGINAL LINE: final String token = tokenizer.nextToken().trim();
                    string token = tokenizer.nextToken().Trim();
                    //returnValues.Add(new int((Convert.ToDouble(token)).intValue()));
                }
                else
                {
                    throw new FunctionException("Invalid values in string.");
                }

                tokenCtr++;
            }
        }
        catch (Exception e)
        {
            throw new FunctionException("Invalid values in string.", e);
        }

        return(returnValues);
    }