<commit_before>/* 
 * Copyright (c) 2015 <NAME>
 * 
 * See the file LICENSE for copying permission.
 */
package latexstudio.editor.runtime;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import latexstudio.editor.ApplicationLogger;
import latexstudio.editor.util.ApplicationUtils;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteWatchdog;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.io.IOUtils;
import org.openide.util.Exceptions;

/**
 * The class responsible for execution of commands in runtime and handling the outputs
 * of external processes.
 * 
 * @author Sebastian
 */
public final class CommandLineExecutor {
    
    public static void executeGeneratePDF(String pathToSource, String outputDir, File workingFile) {
        executeGeneratePDF(pathToSource, outputDir, null, workingFile);
    }
    
    public static void executeGeneratePDF(String pathToSource, String outputDir, String jobname, File workingFile) {
        executeGeneratePDF(pathToSource, outputDir, jobname, workingFile, null);
    }
    
    public static void executeGeneratePDF(String pathToSource, String outputDir, String jobname, File workingFile, ApplicationLogger logger) {
        String outputDirectory = "--output-directory=" + outputDir;
        String outputFormat = "--output-format=pdf";
        
        String job = jobname == null ? "" : "--jobname=" + jobname.replaceAll(" ", "_");
        String includeDir = workingFile == null ? "" : "--include-directory=" + workingFile.getParentFile().getAbsolutePath();
        
        ByteArrayOutputStream outputStream = null;
        
        try {           
            String[] command =  new String[] {
                outputDirectory, outputFormat, job, includeDir, pathToSource};
         
            CommandLine cmdLine = new CommandLine(ApplicationUtils.PATH_TO_TEX);
            //For windows, we set handling quoting to true
            cmdLine.addArguments(command, ApplicationUtils.isWindows());
            
            DefaultExecutor executor = new DefaultExecutor();<commit_msg>Performance tweaks: disable pdflatex logging for preview generation<commit_after>/* 
 * Copyright (c) 2015 <NAME>
 * 
 * See the file LICENSE for copying permission.
 */
package latexstudio.editor.runtime;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import latexstudio.editor.ApplicationLogger;
import latexstudio.editor.util.ApplicationUtils;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteWatchdog;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.io.IOUtils;
import org.openide.util.Exceptions;

/**
 * The class responsible for execution of commands in runtime and handling the outputs
 * of external processes.
 * 
 * @author Sebastian
 */
public final class CommandLineExecutor {
    
    public static void executeGeneratePDF(String pathToSource, String outputDir, File workingFile) {
        executeGeneratePDF(pathToSource, outputDir, null, workingFile);
    }
    
    public static void executeGeneratePDF(String pathToSource, String outputDir, String jobname, File workingFile) {
        executeGeneratePDF(pathToSource, outputDir, jobname, workingFile, null);
    }
    
    public static void executeGeneratePDF(String pathToSource, String outputDir, String jobname, File workingFile, ApplicationLogger logger) {
        String outputDirectory = "--output-directory=" + outputDir;
        String outputFormat = "--output-format=pdf";
        
        String job = jobname == null ? "" : "--jobname=" + jobname.replaceAll(" ", "_");
        String includeDir = workingFile == null ? "" : "--include-directory=" + workingFile.getParentFile().getAbsolutePath();
        String quiet = logger  == null ? "--quiet" : "";
        
        ByteArrayOutputStream outputStream = null;
        
        try {           
            String[] command =  new String[] {
                outputDirectory, outputFormat, job, includeDir, quiet, pathToSource
            };
         
            CommandLine cmdLine = new CommandLine(ApplicationUtils.PATH_TO_TEX);
            //For windows, we set handling quoting to true
            cmdLine.addArguments(command, ApplicationUtils.isWindows());
            
            DefaultExecutor executor = new DefaultExecutor();
{'fraction_non_alphanumeric': 0.0931057415207271, 'fraction_numerical': 0.0017734426956328973, 'mean_word_length': 3.3259827420901247, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5137285', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1123, 'n_words': 312}