<commit_before>/*
 * Copyright (C) 2017 <NAME>
 *
 * 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 uk.co.reecedunn.intellij.plugin.marklogic.ui.runner;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.CommandLineState;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.execution.filters.RegexpFilter;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.actionSystem.AnAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import uk.co.reecedunn.intellij.plugin.marklogic.api.Connection;
import uk.co.reecedunn.intellij.plugin.marklogic.api.EvalRequestBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.debugger.stack.view.MarkLogicViewErrorAction;
import uk.co.reecedunn.intellij.plugin.marklogic.ui.configuration.MarkLogicRunConfiguration;
import uk.co.reecedunn.intellij.plugin.marklogic.query.Function;
import uk.co.reecedunn.intellij.plugin.marklogic.query.QueryBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.query.QueryBuilderFactory;

import java.io.IOException;

public class MarkLogicRunProfileState extends CommandLineState {
    public MarkLogicRunProfileState(@Nullable ExecutionEnvironment environment) {
        super(environment);
        if (environment != null) {
            addConsoleFilters(new RegexpFilter(environment.getProject(), "$FILE_PATH$:$LINE$"));
        }
    }

    @NotNull
    protected AnAction[] createActions(final ConsoleView console, final ProcessHandler processHandler, Executor executor) {
        if (console == null || !console.canPause() || (executor != null && !DefaultRunExecutor.EXECUTOR_ID.equals(executor.getId()))) {
            return new AnAction[] {
                new MarkLogicViewErrorAction()
            };
        }
        return new AnAction[] {
            new PauseOutputAction(console, processHandler),
            new MarkLogicViewErrorAction()
        };
    }

    @NotNull
    @Override
    protected ProcessHandler startProcess() throws ExecutionException {
        MarkLogicRunConfiguration configuration = (MarkLogicRunConfiguration)getEnvironment().getRunProfile();

        QueryBuilder queryBuilder = QueryBuilderFactory.createQueryBuilderForFile(configuration.getMainModulePath());
        if (queryBuilder == null) {
            throw new ExecutionException("Unsupported query file: " + configuration.getMainModulePath());
        }

        Function function = queryBuilder.createEvalBuilder(getEnvironment().getExecutor().getId(), configuration.getMarkLogicVersion());
        if (function == null) {
            throw new ExecutionException("Cannot run the query file with MarkLogic " + configuration.getMarkLogicVersion());
        }

        Connection connection = createConnection(configuration);
        EvalRequestBuilder builder = connection.createEvalRequestBuilder();
        builder.setContentDatabase(configuration.getContentDatabase());
        builder.setXQuery(function.buildQuery(configuration));
        return new MarkLogicRequestHandler(builder.build(), configuration.getMainModulePath());
    }

    public boolean run(String query, MarkLogicResultsHandler handler, MarkLogicRunConfiguration configuration) {
        Connection connection = createConnection(configuration);
        EvalRequestBuilder builder = connection.createEvalRequestBuilder();
        builder.setContentDatabase(configuration.getContentDatabase());
        builder.setXQuery(query);
        MarkLogicRequestHandler restHandler = new MarkLogicRequestHandler(builder.build(), "/eval");
        try {
            return restHandler.run(handler);
        } catch (IOException e) {
            return false;
        }
    }

    private Connection createConnection(MarkLogicRunConfiguration configuration) {
        return Connection.newConnection(
            configuration.getServer().getHostname(),
            configuration.getServer().getAppServerPort(),
            configuration.getServer().getUsername(),
            configuration.getServer().getPassword(),
            configuration.getMarkLogicVersion());
    }
}
<commit_msg>Don't display a pause button on the MarkLogic run console window, as pausing is not supported.<commit_after>/*
 * Copyright (C) 2017 <NAME>
 *
 * 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 uk.co.reecedunn.intellij.plugin.marklogic.ui.runner;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.CommandLineState;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.execution.filters.RegexpFilter;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.actionSystem.AnAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import uk.co.reecedunn.intellij.plugin.marklogic.api.Connection;
import uk.co.reecedunn.intellij.plugin.marklogic.api.EvalRequestBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.debugger.stack.view.MarkLogicViewErrorAction;
import uk.co.reecedunn.intellij.plugin.marklogic.ui.configuration.MarkLogicRunConfiguration;
import uk.co.reecedunn.intellij.plugin.marklogic.query.Function;
import uk.co.reecedunn.intellij.plugin.marklogic.query.QueryBuilder;
import uk.co.reecedunn.intellij.plugin.marklogic.query.QueryBuilderFactory;

import java.io.IOException;

public class MarkLogicRunProfileState extends CommandLineState {
    public MarkLogicRunProfileState(@Nullable ExecutionEnvironment environment) {
        super(environment);
        if (environment != null) {
            addConsoleFilters(new RegexpFilter(environment.getProject(), "$FILE_PATH$:$LINE$"));
        }
    }

    @NotNull
    protected AnAction[] createActions(final ConsoleView console, final ProcessHandler processHandler, Executor executor) {
        return new AnAction[] {
            new MarkLogicViewErrorAction()
        };
    }

    @NotNull
    @Override
    protected ProcessHandler startProcess() throws ExecutionException {
        MarkLogicRunConfiguration configuration = (MarkLogicRunConfiguration)getEnvironment().getRunProfile();

        QueryBuilder queryBuilder = QueryBuilderFactory.createQueryBuilderForFile(configuration.getMainModulePath());
        if (queryBuilder == null) {
            throw new ExecutionException("Unsupported query file: " + configuration.getMainModulePath());
        }

        Function function = queryBuilder.createEvalBuilder(getEnvironment().getExecutor().getId(), configuration.getMarkLogicVersion());
        if (function == null) {
            throw new ExecutionException("Cannot run the query file with MarkLogic " + configuration.getMarkLogicVersion());
        }

        Connection connection = createConnection(configuration);
        EvalRequestBuilder builder = connection.createEvalRequestBuilder();
        builder.setContentDatabase(configuration.getContentDatabase());
        builder.setXQuery(function.buildQuery(configuration));
        return new MarkLogicRequestHandler(builder.build(), configuration.getMainModulePath());
    }

    public boolean run(String query, MarkLogicResultsHandler handler, MarkLogicRunConfiguration configuration) {
        Connection connection = createConnection(configuration);
        EvalRequestBuilder builder = connection.createEvalRequestBuilder();
        builder.setContentDatabase(configuration.getContentDatabase());
        builder.setXQuery(query);
        MarkLogicRequestHandler restHandler = new MarkLogicRequestHandler(builder.build(), "/eval");
        try {
            return restHandler.run(handler);
        } catch (IOException e) {
            return false;
        }
    }

    private Connection createConnection(MarkLogicRunConfiguration configuration) {
        return Connection.newConnection(
            configuration.getServer().getHostname(),
            configuration.getServer().getAppServerPort(),
            configuration.getServer().getUsername(),
            configuration.getServer().getPassword(),
            configuration.getMarkLogicVersion());
    }
}

{'fraction_non_alphanumeric': 0.09099586382437162, 'fraction_numerical': 0.0016968925654894473, 'mean_word_length': 4.1222161868549705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4049856', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2342, 'n_words': 522}