<commit_before><?php
	class GradleSupportMatrixTest extends PHPUnit_Framework_TestCase
	{
		private $_apiKey = "9dc08e8d93efd8622178f0c61faeaf112fbafcb4";

		// list of Android Plugins is available at http://tools.android.com/tech-docs/new-build-system
		// list of Gradle Wrappers is available at http://services.gradle.org/distributions

		public function setup() {
			parent::setup();

			$name = $this->getName();
			$prefix = "testGradleWrapper_";
			if (substr($name, 0, strlen($prefix)) == $prefix) {
				$name = substr($name, strlen($prefix));
				$p = strpos($name, "_AndroidPlugin_");
				$wrapperVersion = substr($name, 0, $p);
				$wrapperVersion = str_replace("_", ".", $wrapperVersion);
				$pluginVersion = substr($name, $p + strlen("_AndroidPlugin_"));
				$pluginVersion = str_replace("_", ".", $pluginVersion);

				$this->tryGradle($wrapperVersion, $pluginVersion);
			}
		}

		public function tearDown() {
			parent::tearDown();
		}

		/**
		 * Changes the distributionUrl inside a gradle-wrapper.properties file
		 *
		 * @param $filename
		 * @param $wrapperVersion
		 */
		private function changeDistributionUrl($filename, $wrapperVersion) {
			$lines = file($filename, FILE_IGNORE_NEW_LINES);
			for ($i=0; $i<count($lines); $i++) {
				if (substr($lines[$i], 0, strlen("distributionUrl=")) == "distributionUrl=") {
					$lines[$i] = "distributionUrl=http\\://services.gradle.org/distributions/gradle-" . $wrapperVersion . "-all.zip";
				}
			}

			file_put_contents($filename, implode("\n", $lines));
		}

		/**
		 * Automagically add testfairy gradle plugin to the gradle build script.
		 *
		 * @param $filename   string     path for build.gradle file being inspected
		 * @param $useMinify  boolean    should render script with 'minifyEnabled' instead of 'runProguard'?
		 */
		private function fixupBuildGradle($filename, $useMinify) {
			$lines = file($filename, FILE_IGNORE_NEW_LINES);
			$out = array();
			foreach($lines as $line) {

				if (preg_match("/^\\s*runProguard false/", $line)) {
					if ($useMinify) {
						$line = str_replace("runProguard false", "minifyEnabled true", $line);
					} else {
						$line = str_replace("runProguard false", "runProguard true", $line);
					}
				}

				$out[] = $line;

				if (strpos($line, "repositories {") !== FALSE) {
					$out[] = "        maven { url 'https://www.testfairy.com/maven' }";
//					$out[] = "        maven { url 'file://Users/gilm/github/testfairy-gradle-plugin/repo' }";
				}

				if (strpos($line, "dependencies {") !== FALSE) {
					$out[] = "        classpath 'com.testfairy.plugins.gradle:testfairy:1.+'";
				}

				if (strpos($line, "apply plugin") !== FALSE) {
					$out[] = "apply plugin: 'testfairy'";
				}

				if (strpos($line, "android {") !== FALSE) {
					$out[] = "    testfairyConfig {";
					//$out[] = "       serverEndpoint \"http://" . $this->_tested_server . "\"";
					$out[] = "       apiKey \"" . $this->_apiKey . "\"";
					$out[] = "       uploadProguardMapping true";
					$out[] = "    }";
				}
			}

			$lines = implode("\n", $out);
			file_put_contents($filename, $lines);
		}

		private function tryGradle($wrapper, $plugin) {

			$android = getenv("ANDROID_HOME");
			$this->assertNotEmpty($android, "Must define ANDROID_HOME env variable");
			$android = $android . "/tools/android";

			// create an empty project first
			$TEST_DIR="/tmp/.gradle-test";
			system("rm -rf $TEST_DIR");
			@mkdir($TEST_DIR);
			exec("$android create project -v $plugin -n GradleTest -t android-8 -p $TEST_DIR -g -k com.testfairy.tests.gradle -a MainActivity", $output);

			$useMinify = ($plugin >= "0.14");
			$this->changeDistributionUrl("$TEST_DIR/gradle/wrapper/gradle-wrapper.properties", $wrapper);
			$this->fixupBuildGradle("$TEST_DIR/build.gradle", $useMinify);

			// check plugin loaded successfully
			exec("cd $TEST_DIR; bash gradlew tasks", $output);
			$this->assertContains("testfairyRelease - Uploads the Release build to TestFairy", $output);
			$this->assertContains("testfairyDebug - Uploads the Debug build to TestFairy", $output);

			// try testfairyRelease task
			exec("cd $TEST_DIR; bash gradlew testfairyRelease", $output);
			$this->assertContains("Successfully uploaded to TestFairy, build is available at:", $output);

			/*
			// make sure symbols were uploaded
			$this->login("<EMAIL>", "10203040");
			$buildUrl = $this->getLatestBuildUrl();
			$this->open("$buildUrl/settings");
			$this->assertBodyContains("Proguard mapping file uploaded.", "Proguard mapping not uploaded");
			*/
		}

		// Gradle Wrapper 1.10
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_0() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_1() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_2() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_4() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_11_0() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_12_0() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_12_1() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_12_2() { }

                // Gradle Wrapper 1.11
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_0() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_1() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_2() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_4() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_11_0() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_12_0() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_12_1() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_12_2() { }

                // Gradle Wrapper 1.12
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_0() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_1() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_2() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_4() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_11_0() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_12_0() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_12_1() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_12_2() { }

                // Gradle Wrapper 2.1
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_0() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_1() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_2() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_3() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_0() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_1() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_2() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_3() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_4() { }

                // Gradle Wrapper 2.2
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_0() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_1() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_2() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_3() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_4() { }
	}
?><commit_msg>Testing zipalign Testing original signature kept intact Added Android Plugin versions 1.0.0 and 1.0.1<commit_after><?php
	class GradleSupportMatrixTest extends PHPUnit_Framework_TestCase
	{
		private $_apiKey = "9dc08e8d93efd8622178f0c61faeaf112fbafcb4";

		// list of Android Plugins is available at http://tools.android.com/tech-docs/new-build-system
		// list of Gradle Wrappers is available at http://services.gradle.org/distributions

		public function setup() {
			parent::setup();

			$name = $this->getName();
			$prefix = "testGradleWrapper_";
			if (substr($name, 0, strlen($prefix)) == $prefix) {
				$name = substr($name, strlen($prefix));
				$p = strpos($name, "_AndroidPlugin_");
				$wrapperVersion = substr($name, 0, $p);
				$wrapperVersion = str_replace("_", ".", $wrapperVersion);
				$pluginVersion = substr($name, $p + strlen("_AndroidPlugin_"));
				$pluginVersion = str_replace("_", ".", $pluginVersion);

				$this->tryGradle($wrapperVersion, $pluginVersion);
			}
		}

		public function tearDown() {
			parent::tearDown();
		}

		/**
		 * Changes the distributionUrl inside a gradle-wrapper.properties file
		 *
		 * @param $filename
		 * @param $wrapperVersion
		 */
		private function changeDistributionUrl($filename, $wrapperVersion) {
			$lines = file($filename, FILE_IGNORE_NEW_LINES);
			for ($i=0; $i<count($lines); $i++) {
				if (substr($lines[$i], 0, strlen("distributionUrl=")) == "distributionUrl=") {
					$lines[$i] = "distributionUrl=http\\://services.gradle.org/distributions/gradle-" . $wrapperVersion . "-all.zip";
				}
			}

			file_put_contents($filename, implode("\n", $lines));
		}

		/**
		 * Automagically add testfairy gradle plugin to the gradle build script.
		 *
		 * @param $filename   string     path for build.gradle file being inspected
		 * @param $useMinify  boolean    should render script with 'minifyEnabled' instead of 'runProguard'?
		 * @param $keystore   string     path to keystore file used for signing app
		 */
		private function fixupBuildGradle($filename, $useMinify, $keystore) {
			$lines = file($filename, FILE_IGNORE_NEW_LINES);
			$out = array();
			foreach($lines as $line) {

				if (preg_match("/^\\s*runProguard false/", $line)) {
					if ($useMinify) {
						$line = str_replace("runProguard false", "minifyEnabled true", $line);
					} else {
						$line = str_replace("runProguard false", "runProguard true", $line);
					}
				}

				$out[] = $line;

				if (strpos($line, "repositories {") !== FALSE) {
					$out[] = "        maven { url 'https://www.testfairy.com/maven' }";
					//$out[] = "        maven { url 'file://Users/gilm/git/testfairy-gradle-plugin/repo' }";
				}

				if (strpos($line, "dependencies {") !== FALSE) {
					$out[] = "        classpath 'com.testfairy.plugins.gradle:testfairy:1.+'";
				}

				if (strpos($line, "apply plugin") !== FALSE) {
					$out[] = "apply plugin: 'testfairy'";
				}

				if (strpos($line, "android {") !== FALSE) {
					$out[] = "signingConfigs {";
        				$out[] = "  release {";
                                        $out[] = "    storeFile file(\"$keystore\")";
                                        $out[] = "    storePassword \"<PASSWORD>\"";
                                        $out[] = "    keyAlias \"android_app\"";
                                        $out[] = "    keyPassword \"<PASSWORD>\"";
                                        $out[] = "  }";
                                        $out[] = "}";

					$out[] = "buildTypes {";
					$out[] = "  release {";
					$out[] = "    signingConfig signingConfigs.release";
					//runProguard true
					//proguardFile getDefaultProguardFile('proguard-android.txt')
					$out[] = "  }";
					$out[] = "}";

					$out[] = "    testfairyConfig {";
					//$out[] = "       serverEndpoint \"http://" . $this->_tested_server . "\"";
					$out[] = "       apiKey \"" . $this->_apiKey . "\"";
					$out[] = "       uploadProguardMapping true";
					$out[] = "    }";
				}
			}

			$lines = implode("\n", $out);
			file_put_contents($filename, $lines);
		}

		private function getAndroidHome() {
			$home = getenv("ANDROID_HOME");
			$this->assertNotEmpty($home, "Must define ANDROID_HOME env variable");
			return $home;
		}

		private function assertZipaligned($filename) {
			$home = $this->getAndroidHome();
			exec("${home}/build-tools/19.1.0/zipalign -c 4 ${TEST_DIR}/signed.apk", $output, $retval);
			$this->assertEquals(0, $retval, "APK file was not zipaligned");
		}

		private function assertSignedByCN($filename, $cn) {
			exec("jarsigner -certs -verbose -verify '{$filename}'", $output);
			$this->assertContains("jar verified.", $output, "Downloaded APK is not signed");
			$this->assertContains("CN=${cn},", implode("\n", $output), "Download APK is signed with another key");
		}

		private function tryGradle($wrapper, $plugin) {

			$android = $this->getAndroidHome() . "/tools/android";

			// create an empty project first
			$TEST_DIR="/tmp/.gradle-test";
			system("rm -rf $TEST_DIR");
			@mkdir($TEST_DIR);
			exec("$android create project -v $plugin -n GradleTest -t android-8 -p $TEST_DIR -g -k com.testfairy.tests.gradle -a MainActivity", $output);

			// create a certificate for this
			$time = time();
			$dname = "CN=${time},OU=organizational_unit,O=organization,L=locality,S=state,C=US";
			system("keytool -genkey -keystore ${TEST_DIR}/random.keystore -alias android_app -keyalg RSA -keysize 2048 -validity 3650 -keypass 'swordfish' -storepass '<PASSWORD>' -dname '$dname' 2>&1");

			$useMinify = ($plugin >= "0.14");
			$this->changeDistributionUrl("$TEST_DIR/gradle/wrapper/gradle-wrapper.properties", $wrapper);
			$this->fixupBuildGradle("$TEST_DIR/build.gradle", $useMinify, "random.keystore");

			// check plugin loaded successfully
			exec("cd $TEST_DIR; bash gradlew tasks", $output);
			$this->assertContains("testfairyRelease - Uploads the Release build to TestFairy", $output);
			$this->assertContains("testfairyDebug - Uploads the Debug build to TestFairy", $output);

			// try testfairyRelease task
			$output = array();
			exec("cd $TEST_DIR; bash gradlew testfairyRelease --debug", $output);

			// make sure it uploaded successfully to testfairy
			$found = null;
			foreach($output as $line) {
				if (preg_match("/Successfully uploaded to TestFairy, build is available at:/", $line)) {
					$found = true;
					break;
				}
			}

			$this->assertNotNull($found, "Compilation failed");

			$signedUrl = null;
			foreach($output as $line) {
				if (preg_match("/Signed instrumented file is available at: (.+)/", $line, $match)) {
					$signedUrl = $match[1];
					break;
				}
			}

			$this->assertNotNull($signedUrl, "Could not find signed instrumented file url in debug logs");

			// fetch signed apk
			copy($signedUrl, "${TEST_DIR}/signed.apk");

			// make sure app is signed
			$this->assertSignedByCN("${TEST_DIR}/signed.apk", $time);
			$this->assertZipAligned("${TEST_DIR}/signed.apk");
		}

		// Gradle Wrapper 1.10
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_0() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_1() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_2() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_10_4() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_11_0() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_12_0() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_12_1() { }
                public function testGradleWrapper_1_10_AndroidPlugin_0_12_2() { }

                // Gradle Wrapper 1.11
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_0() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_1() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_2() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_10_4() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_11_0() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_12_0() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_12_1() { }
                public function testGradleWrapper_1_11_AndroidPlugin_0_12_2() { }

                // Gradle Wrapper 1.12
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_0() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_1() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_2() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_10_4() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_11_0() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_12_0() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_12_1() { }
                public function testGradleWrapper_1_12_AndroidPlugin_0_12_2() { }

                // Gradle Wrapper 2.1
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_0() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_1() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_2() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_13_3() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_0() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_1() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_2() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_3() { }
                public function testGradleWrapper_2_1_AndroidPlugin_0_14_4() { }
                public function testGradleWrapper_2_1_AndroidPlugin_1_0_0() { }
                public function testGradleWrapper_2_1_AndroidPlugin_1_0_1() { }

                // Gradle Wrapper 2.2
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_0() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_1() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_2() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_3() { }
                public function testGradleWrapper_2_2_AndroidPlugin_0_14_4() { }
                public function testGradleWrapper_2_2_AndroidPlugin_1_0_0() { }
                public function testGradleWrapper_2_2_AndroidPlugin_1_0_1() { }
	}
?>
{'fraction_non_alphanumeric': 0.12523080265015749, 'fraction_numerical': 0.03470185728250244, 'mean_word_length': 2.986793678285343, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 44, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5523054', 'n_tokens_mistral': 6651, 'n_tokens_neox': 5642, 'n_words': 1093}