<commit_before>/**
 * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright ownership. Apereo
 * licenses this file to you 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 the
 * following location:
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>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.apereo.portal.shell;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.tools.ant.util.FileUtils;
import org.apereo.portal.utils.PortalApplicationContextLocator;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.tools.shell.Groovysh;
import org.codehaus.groovy.tools.shell.IO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;

/** @author <NAME> */
public class PortalShell {
    static final Logger LOGGER = LoggerFactory.getLogger(PortalShell.class);

    protected static Options getOptions() {
        final Options options = new Options();

        options.addOption(
                new Option("s", "script", true, "Groovy script to execute in the uPortal Shell."));

        return options;
    }

    public static void main(String[] args) throws Exception {
        final Options options = getOptions();

        final CommandLineParser parser = new PosixParser();
        final CommandLine commandLine;
        try {
            commandLine = parser.parse(options, args);
        } catch (ParseException e) {
            System.err.println(e.getMessage());
            printHelp(options);
            return;
        }

        final ApplicationContext applicationContext =
                PortalApplicationContextLocator.getApplicationContext();
        try {
            final Binding binding = new SpringBinding(applicationContext);
            binding.setVariable("logger", LOGGER);

            if (commandLine.hasOption("script")) {
                final String scriptName = commandLine.getOptionValue("script");
                final File scriptFile = getAbsoluteFile(scriptName);

                final CompilerConfiguration conf =
                        new CompilerConfiguration(System.getProperties());
                final GroovyShell shell = new GroovyShell(binding, conf);
                shell.run(scriptFile, args);
            }
        } finally {<commit_msg>UP-4731: Re-add a groovy shell call<commit_after>/**
 * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright ownership. Apereo
 * licenses this file to you 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 the
 * following location:
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>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.apereo.portal.shell;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.tools.ant.util.FileUtils;
import org.apereo.portal.utils.PortalApplicationContextLocator;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;

/** @author <NAME> */
public class PortalShell {
    static final Logger LOGGER = LoggerFactory.getLogger(PortalShell.class);

    protected static Options getOptions() {
        final Options options = new Options();

        options.addOption(
                new Option("s", "script", true, "Groovy script to execute in the uPortal Shell."));

        return options;
    }

    public static void main(String[] args) throws Exception {
        final Options options = getOptions();

        final CommandLineParser parser = new PosixParser();
        final CommandLine commandLine;
        try {
            commandLine = parser.parse(options, args);
        } catch (ParseException e) {
            System.err.println(e.getMessage());
            printHelp(options);
            return;
        }

        final ApplicationContext applicationContext =
                PortalApplicationContextLocator.getApplicationContext();
        try {
            final Binding binding = new SpringBinding(applicationContext);
            binding.setVariable("logger", LOGGER);
            final CompilerConfiguration conf =
                    new CompilerConfiguration(System.getProperties());
            final GroovyShell shell = new GroovyShell(binding, conf);

            if (commandLine.hasOption("script")) {
                final String scriptName = commandLine.getOptionValue("script");
                final File scriptFile = getAbsoluteFile(scriptName);

                shell.run(scriptFile, args);

            } else {
                String[] noArgs = {};
                shell.run("", "", noArgs);
            }
        } finally {
{'fraction_non_alphanumeric': 0.08734756097560975, 'fraction_numerical': 0.0024390243902439024, 'mean_word_length': 3.176320814767664, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5831895', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1622, 'n_words': 514}