<commit_before>/*******************************************************************************
 * Copyright (c) 2009-2013 <NAME> and <NAME>
 * 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
 *******************************************************************************/

package me.gladwell.eclipse.m2e.android.test;

import static me.gladwell.eclipse.m2e.android.configuration.MavenAndroidClasspathConfigurer.ANDROID_CLASSES_FOLDER;

import java.io.File;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.jdt.IClasspathManager;

import com.android.ide.eclipse.adt.AdtConstants;

/**
 * Test suite for configuring and building Android applications.
 *
 * @author <NAME> <<EMAIL>>
 */
@SuppressWarnings("restriction")
public class ApplicationAndroidMavenPluginTest extends AndroidMavenPluginTestCase {

	private IProject project;
	private IJavaProject javaProject;

    protected String getAndroidProjectName() {
        return "android-application";
    }

    @Override
	protected void setUp() throws Exception {
		super.setUp();

		project = importAndroidProject(getAndroidProjectName());
		javaProject = JavaCore.create(project);
	}

	public void testConfigure() throws Exception {
		assertNoErrors(project);
	}

	public void testConfigureAddsAndroidNature() throws Exception {
	    assertTrue("configurer failed to add android nature", project.hasNature(AdtConstants.NATURE_DEFAULT));
	}

	public void testConfigureApkBuilderBeforeMavenBuilder() throws Exception {
		boolean foundApkBuilder = false;
		for(ICommand command : project.getDescription().getBuildSpec()) {
			if("com.android.ide.eclipse.adt.ApkBuilder".equals(command.getBuilderName())) {
				foundApkBuilder = true;
			} else if(IMavenConstants.BUILDER_ID.equals(command.getBuilderName())) {
				assertTrue("project APKBuilder not configured before maven builder", foundApkBuilder);
				return;
			}
		}

		fail("project does not contain maven builder build command");
	}

	public void testConfigureDoesNotAddTargetDirectoryToClasspath() throws Exception {
		for(IClasspathEntry entry : javaProject.getRawClasspath()) {
			assertFalse("classpath contains reference to target directory: cause infinite build loops and build conflicts", entry.getPath().toOSString().contains("target"));
		}
	}

	public void testConfigureGeneratedResourcesFolderInRawClasspath() throws Exception {
		assertClasspathContains(javaProject, "gen");
	}

	public void testConfigureAddsCompileDependenciesToClasspath() throws Exception {
		assertClasspathContains(javaProject, "commons-lang-2.4.jar");
	}

	public void testConfigureDoesNotAddNonCompileDependenciesToClasspath() throws Exception {
		assertClasspathDoesNotContain(javaProject, "android-2.1.2.jar");
	}

	public void testConfigureDoesNotAddNonCompileTransitiveDependenciesToClasspath() throws Exception {
		assertClasspathDoesNotContain(javaProject, "commons-logging-1.1.1.jar");
	}

	public void testConfigureDoesRemoveJreClasspathContainer() throws Exception {
		assertClasspathDoesNotContain(javaProject, JavaRuntime.JRE_CONTAINER);
	}

	// TODO quarantined intermittently failing integration test
	public void ignoreTestBuildDirectoryContainsCompiledClasses() throws Exception {
		File outputLocation = new File(ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toOSString(), javaProject.getPath().toOSString());
		File apiDemosApplication  = new File(outputLocation, "bin/classes/your/company/HelloAndroidActivity.class");
<commit_msg>Fixed test that was broken when test project was modified without properly updating the unit tests.<commit_after>/*******************************************************************************
 * Copyright (c) 2009-2013 <NAME> and <NAME>
 * 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
 *******************************************************************************/

package me.gladwell.eclipse.m2e.android.test;

import static me.gladwell.eclipse.m2e.android.configuration.MavenAndroidClasspathConfigurer.ANDROID_CLASSES_FOLDER;

import java.io.File;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.jdt.IClasspathManager;

import com.android.ide.eclipse.adt.AdtConstants;

/**
 * Test suite for configuring and building Android applications.
 *
 * @author <NAME> <<EMAIL>>
 */
@SuppressWarnings("restriction")
public class ApplicationAndroidMavenPluginTest extends AndroidMavenPluginTestCase {

	private IProject project;
	private IJavaProject javaProject;

    protected String getAndroidProjectName() {
        return "android-application";
    }

    @Override
	protected void setUp() throws Exception {
		super.setUp();

		project = importAndroidProject(getAndroidProjectName());
		javaProject = JavaCore.create(project);
	}

	public void testConfigure() throws Exception {
		assertNoErrors(project);
	}

	public void testConfigureAddsAndroidNature() throws Exception {
	    assertTrue("configurer failed to add android nature", project.hasNature(AdtConstants.NATURE_DEFAULT));
	}

	public void testConfigureApkBuilderBeforeMavenBuilder() throws Exception {
		boolean foundApkBuilder = false;
		for(ICommand command : project.getDescription().getBuildSpec()) {
			if("com.android.ide.eclipse.adt.ApkBuilder".equals(command.getBuilderName())) {
				foundApkBuilder = true;
			} else if(IMavenConstants.BUILDER_ID.equals(command.getBuilderName())) {
				assertTrue("project APKBuilder not configured before maven builder", foundApkBuilder);
				return;
			}
		}

		fail("project does not contain maven builder build command");
	}

	public void testConfigureDoesNotAddTargetDirectoryToClasspath() throws Exception {
		for(IClasspathEntry entry : javaProject.getRawClasspath()) {
			assertFalse("classpath contains reference to target directory: cause infinite build loops and build conflicts", entry.getPath().toOSString().contains("target"));
		}
	}

	public void testConfigureGeneratedResourcesFolderInRawClasspath() throws Exception {
		assertClasspathContains(javaProject, "gen");
	}

	public void testConfigureAddsCompileDependenciesToClasspath() throws Exception {
		assertClasspathContains(javaProject, "commons-lang-2.4.jar");
	}

	public void testConfigureDoesNotAddNonCompileDependenciesToClasspath() throws Exception {
		assertClasspathDoesNotContain(javaProject, "android-2.3.3.jar");
	}

	public void testConfigureDoesNotAddNonCompileTransitiveDependenciesToClasspath() throws Exception {
		assertClasspathDoesNotContain(javaProject, "commons-logging-1.1.1.jar");
	}

	public void testConfigureDoesRemoveJreClasspathContainer() throws Exception {
		assertClasspathDoesNotContain(javaProject, JavaRuntime.JRE_CONTAINER);
	}

	// TODO quarantined intermittently failing integration test
	public void ignoreTestBuildDirectoryContainsCompiledClasses() throws Exception {
		File outputLocation = new File(ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toOSString(), javaProject.getPath().toOSString());
		File apiDemosApplication  = new File(outputLocation, "bin/classes/your/company/HelloAndroidActivity.class");

{'fraction_non_alphanumeric': 0.12835857352222765, 'fraction_numerical': 0.005862237420615535, 'mean_word_length': 6.34439461883408, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4746284', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2183, 'n_words': 483}