<commit_before>/*
 * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
 *  
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *  
 *  Contributors:
 *      <NAME> - <EMAIL> - Initial API and implementation
*/
package org.jboss.windup.reporting;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.windup.WindupEngine;
import org.jboss.windup.WindupEnvironment;
import org.jboss.windup.metadata.type.archive.ArchiveMetadata;
import org.jboss.windup.util.RPMToZipTransformer;
import org.springframework.context.ApplicationContext;


public class ReportEngine {
	private static final String[] RPM_EXTENSIONS = new String[] { ".rpm", ".rpm_" };
	private static final Logger LOG = LoggerFactory.getLogger(ReportEngine.class);

	private final Collection<Reporter> reporters;
	private final ApplicationContext context;
	private final WindupEngine windupEngine;
	private final WindupEnvironment settings;
	private final List<String> supportedExtensions;
	
	/**
	 * <p>
	 * Creates a new {@link ReportEngine} using the given
	 * {@link WindupEnvironment}. This new {@link ReportEngine} will use a newly
	 * created {@link WindupEngine}.
	 * </p>
	 * 
	 * @param settings
	 *            Windup settings to use for this {@link ReportEngine}
	 */
	public ReportEngine(WindupEnvironment settings) {
		this(settings, new WindupEngine(settings));
	}
	
	/**
	 * <p>
	 * Creates a {@link ReportEngine} using an already existing
	 * {@link WindupEngine}.
	 * </p>
	 * 
	 * <p>
	 * <b>IMPORTANT: keep in mind that {@link WindupEngine} is not inherently
	 * thread safe, so if you are using it for more then one task be sure to
	 * manage this risk yourself.
	 * </p>
	 * 
	 * @param settings
	 *            Windup settings to use for this {@link ReportEngine}
	 * @param engine
	 *            Windup engine to use for this {@link ReportEngine}
	 */
	public ReportEngine(WindupEnvironment settings, WindupEngine engine) {
		this.settings = settings;
		windupEngine = engine;
		context = windupEngine.getContext();
		reporters = (Collection<Reporter>)context.getBean("reporters");
		supportedExtensions = new ArrayList((Collection<String>) context.getBean("zipExtensions"));
	}
	
	/**
	 * Processes the input location based upon the environment passed
	 * in from the constructor
	 */
	public void process() throws IOException {
	    process(settings.getInputPath(), settings.getOutputPath());
	}
	
    /**
     * Processes the input location based on this engine's settings.
     * If in source mode, uses WindupEngine#processSourceDirectory().
     * Otherwise, if it's a directory, looks for archives with supported suffix,
     * and if not a directory, processes as a single archive.
     * 
     * @param inputLocation   Path to the archive or directory to process.
     * @param outputLocation  Where to store the resulting reports.
     *        If null, inputLocation + "-doc" is used. If the directory doesn't exist, it is created.
     */
	private void process(File inputLocation, File outputLocation) throws IOException {
        if( ! inputLocation.exists() ) {
            throw new FileNotFoundException("Input file or directory not found: " + inputLocation);
		}<commit_msg>Make process(input, output) public API again since Windup Eclipse depends on that API<commit_after>/*
 * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
 *  
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *  
 *  Contributors:
 *      <NAME> - <EMAIL> - Initial API and implementation
*/
package org.jboss.windup.reporting;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.windup.WindupEngine;
import org.jboss.windup.WindupEnvironment;
import org.jboss.windup.metadata.type.archive.ArchiveMetadata;
import org.jboss.windup.util.RPMToZipTransformer;
import org.springframework.context.ApplicationContext;


public class ReportEngine {
	private static final String[] RPM_EXTENSIONS = new String[] { ".rpm", ".rpm_" };
	private static final Logger LOG = LoggerFactory.getLogger(ReportEngine.class);

	private final Collection<Reporter> reporters;
	private final ApplicationContext context;
	private final WindupEngine windupEngine;
	private final WindupEnvironment settings;
	private final List<String> supportedExtensions;
	
	/**
	 * <p>
	 * Creates a new {@link ReportEngine} using the given
	 * {@link WindupEnvironment}. This new {@link ReportEngine} will use a newly
	 * created {@link WindupEngine}.
	 * </p>
	 * 
	 * @param settings
	 *            Windup settings to use for this {@link ReportEngine}
	 */
	public ReportEngine(WindupEnvironment settings) {
		this(settings, new WindupEngine(settings));
	}
	
	/**
	 * <p>
	 * Creates a {@link ReportEngine} using an already existing
	 * {@link WindupEngine}.
	 * </p>
	 * 
	 * <p>
	 * <b>IMPORTANT: keep in mind that {@link WindupEngine} is not inherently
	 * thread safe, so if you are using it for more then one task be sure to
	 * manage this risk yourself.
	 * </p>
	 * 
	 * @param settings
	 *            Windup settings to use for this {@link ReportEngine}
	 * @param engine
	 *            Windup engine to use for this {@link ReportEngine}
	 */
	public ReportEngine(WindupEnvironment settings, WindupEngine engine) {
		this.settings = settings;
		windupEngine = engine;
		context = windupEngine.getContext();
		reporters = (Collection<Reporter>)context.getBean("reporters");
		supportedExtensions = new ArrayList((Collection<String>) context.getBean("zipExtensions"));
	}
	
	/**
	 * Processes the input location based upon the environment passed
	 * in from the constructor
	 */
	public void process() throws IOException {
	    process(settings.getInputPath(), settings.getOutputPath());
	}
	
    /**
     * Processes the input location based on this engine's settings.
     * If in source mode, uses WindupEngine#processSourceDirectory().
     * Otherwise, if it's a directory, looks for archives with supported suffix,
     * and if not a directory, processes as a single archive.
     * 
     * @param inputLocation   Path to the archive or directory to process.
     * @param outputLocation  Where to store the resulting reports.
     *        If null, inputLocation + "-doc" is used. If the directory doesn't exist, it is created.
     */
	public void process(File inputLocation, File outputLocation) throws IOException {
        if( ! inputLocation.exists() ) {
            throw new FileNotFoundException("Input file or directory not found: " + inputLocation);
		}
{'fraction_non_alphanumeric': 0.09624079576282134, 'fraction_numerical': 0.00258364552383413, 'mean_word_length': 3.8845425867507886, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '1120622', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2086, 'n_words': 720}