<commit_before>/*
 * The MIT License
 *
 * Copyright (c) 2011 OCTO Technology
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.appaloosastore.client;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

/**
 * Client for appaloosa, http://www.appaloosa-store.com. Usage : <br>
 * <code>
 * 	AppaloosaClient client = new AppaloosaClient("my_organisation_token"); <br>
 *  try {                                                                  <br>
 *    client.deployFile("/path/to/archive");                               <br>
 *    System.out.println("Archive deployed");                              <br>
 *  } catch (AppaloosaDeployException e) {                                 <br>
 *  	System.err.println("Something went wrong");                        <br>
 *  }                                                                      <br>
 * </code> Organisation token is available on settings page.
 * 
 * @author <NAME>
 */
public class AppaloosaClient {
	private final String organisationToken;
	private PrintStream logger = System.out;
	private HttpClient httpClient;
	private String appaloosaUrl = "http://www.appaloosa-store.com";
	private int appaloosaPort = 80;
	private int waitDuration = 1000;
	private String proxyHost;
    private String proxyUser;
    private String proxyPass;
    private int proxyPort;

	public AppaloosaClient(String organisationToken) {
		this.organisationToken = organisationToken;
		
		resetHttpConnection();
	}

	public AppaloosaClient(String organisationToken, String proxyHost, int proxyPort, String proxyUser, String proxyPass) {
		this.organisationToken = organisationToken;
		
		this.proxyHost = proxyHost;
		this.proxyUser = proxyUser;
		this.proxyPass = proxyPass;
		this.proxyPort = proxyPort;
		
		resetHttpConnection();
	}

	/**
	 * @param filePath
	 *            physical path of the file to upload
	 * @throws AppaloosaDeployException
	 *             when something went wrong
	 * */	
	public void deployFile(String filePath) throws AppaloosaDeployException {
		logger.println("== Deploy file " + filePath + " to Appaloosa");

		// Retrieve details from Appaloosa to do the upload
		logger.println("==   Ask for upload information");
		UploadBinaryForm uploadForm = getUploadForm();

		// Upload the file on Amazon
		logger.println("==   Upload file " + filePath);
		uploadFile(filePath, uploadForm);

		// Notify Appaloosa that the file is available
		logger.println("==   Start remote processing file");
		MobileApplicationUpdate update = notifyAppaloosaForFile(filePath,
				uploadForm);

		// Wait for Appaloosa to process the file
		while (!update.isProcessed()) {
			smallWait();
			logger.println("==   Check for application informations");
			update = getMobileApplicationUpdateDetails(update.id);
		}<commit_msg>better message for jenkins<commit_after>/*
 * The MIT License
 *
 * Copyright (c) 2011 OCTO Technology
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.appaloosastore.client;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

/**
 * Client for appaloosa, http://www.appaloosa-store.com. Usage : <br>
 * <code>
 * 	AppaloosaClient client = new AppaloosaClient("my_organisation_token"); <br>
 *  try {                                                                  <br>
 *    client.deployFile("/path/to/archive");                               <br>
 *    System.out.println("Archive deployed");                              <br>
 *  } catch (AppaloosaDeployException e) {                                 <br>
 *  	System.err.println("Something went wrong");                        <br>
 *  }                                                                      <br>
 * </code> Organisation token is available on settings page.
 * 
 * @author <NAME>
 */
public class AppaloosaClient {
	private final String organisationToken;
	private PrintStream logger = System.out;
	private HttpClient httpClient;
	private String appaloosaUrl = "http://www.appaloosa-store.com";
	private int appaloosaPort = 80;
	private int waitDuration = 1000;
	private String proxyHost;
    private String proxyUser;
    private String proxyPass;
    private int proxyPort;

	public AppaloosaClient(String organisationToken) {
		this.organisationToken = organisationToken;
		
		resetHttpConnection();
	}

	public AppaloosaClient(String organisationToken, String proxyHost, int proxyPort, String proxyUser, String proxyPass) {
		this.organisationToken = organisationToken;
		
		this.proxyHost = proxyHost;
		this.proxyUser = proxyUser;
		this.proxyPass = proxyPass;
		this.proxyPort = proxyPort;
		
		resetHttpConnection();
	}

	/**
	 * @param filePath
	 *            physical path of the file to upload
	 * @throws AppaloosaDeployException
	 *             when something went wrong
	 * */	
	public void deployFile(String filePath) throws AppaloosaDeployException {
		logger.println("== Deploy file " + filePath + " to Appaloosa");

		// Retrieve details from Appaloosa to do the upload
		logger.println("==   Ask for upload information");
		UploadBinaryForm uploadForm = getUploadForm();

		// Upload the file on Amazon
		logger.println("==   Upload file " + filePath);
		uploadFile(filePath, uploadForm);

		// Notify Appaloosa that the file is available
		logger.println("==   Start remote processing file");
		MobileApplicationUpdate update = notifyAppaloosaForFile(filePath,
				uploadForm);

		// Wait for Appaloosa to process the file
		while (!update.isProcessed()) {
			smallWait();
			logger.println("==  Check that appaloosa has processed the uploaded file (extract useful information and do some verifications)");
			update = getMobileApplicationUpdateDetails(update.id);
		}
{'fraction_non_alphanumeric': 0.0891515576480016, 'fraction_numerical': 0.0020034057898427327, 'mean_word_length': 3.5176470588235293, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3313706', 'n_tokens_mistral': 2804, 'n_tokens_neox': 2631, 'n_words': 854}