<commit_before>/*******************************************************************************
 * Copyright (c) 2009, 2010, 2011 <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 java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;
import me.gladwell.eclipse.m2e.android.AndroidMavenPlugin;

import org.apache.maven.model.Model;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
import org.eclipse.m2e.tests.common.JobHelpers;
import org.eclipse.m2e.tests.common.WorkspaceHelpers;
import org.eclipse.m2e.tests.common.JobHelpers.IJobMatcher;

import com.android.ide.eclipse.adt.internal.sdk.Sdk;

public abstract class AndroidMavenPluginTestCase extends AbstractMavenProjectTestCase {

	static final int MAXIMUM_SECONDS_TO_LOAD_ADT = 120;

	protected AndroidMavenPlugin plugin;

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

	    plugin = AndroidMavenPlugin.getDefault();
		plugin.getInjector().injectMembers(this);

	    waitForAdtToLoad();
    }

	protected void waitForAdtToLoad() throws InterruptedException, Exception {
        try {
    		JobHelpers.waitForJobs(new IJobMatcher() {
    			public boolean matches(Job job) {
    				return job.getClass().getName().contains(Sdk.class.getName());
    			}
    			
    		}, MAXIMUM_SECONDS_TO_LOAD_ADT * 1000);
        } catch(Throwable t) {
            t.printStackTrace();
        }
	}

	protected IProject importAndroidProject(String name) throws Exception {
		IProject project = importProject("projects/"+name+"/pom.xml");
		waitForAndroidJobsToComplete();
		waitForAdtToLoad();
	    return project;
	}

	protected IProject importAndroidProject(String name, File folder) throws Exception {
        IProject project = importProject("projects/"+name+"/pom.xml", folder);
        waitForAndroidJobsToComplete();
        waitForAdtToLoad();
        return project;
	}

    private IProject importProject(String pomLocation, File parent) throws Exception {
        MavenModelManager mavenModelManager = MavenPlugin.getMavenModelManager();
        IWorkspaceRoot root = workspace.getRoot();

        File pomFile = new File(pomLocation);
        File src = new File(pomFile.getParentFile().getCanonicalPath());
        File dst = new File(parent, pomFile.getParentFile().getName());

        copyDir(src, dst);

        String pomName = pomFile.getName();
        pomFile = new File(dst, pomName);
        Model model = mavenModelManager.readMavenModel(pomFile);
        MavenProjectInfo projectInfo = new MavenProjectInfo(pomName, pomFile, model, null);
        File workspaceRoot = workspace.getRoot().getLocation().toFile();
        File basedir = projectInfo.getPomFile().getParentFile().getCanonicalFile();

        projectInfo.setBasedirRename(basedir.getParentFile().equals(workspaceRoot)? MavenProjectInfo.RENAME_REQUIRED: MavenProjectInfo.RENAME_NO);

        final ArrayList<MavenProjectInfo> projectInfos = new ArrayList<MavenProjectInfo>();
        projectInfos.add(projectInfo);

        final ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration(new ResolverConfiguration());

        final ArrayList<IMavenProjectImportResult> importResults = new ArrayList<IMavenProjectImportResult>();

        workspace.run(new IWorkspaceRunnable() {
            public void run(IProgressMonitor monitor) throws CoreException {
                importResults.addAll(MavenPlugin.getProjectConfigurationManager()
                        .importProjects(projectInfos, importConfiguration, monitor));
            }
        }, MavenPlugin.getProjectConfigurationManager().getRule(), IWorkspace.AVOID_UPDATE, monitor);<commit_msg>Remove unused instance of IWorkspaceRoot<commit_after>/*******************************************************************************
 * Copyright (c) 2009, 2010, 2011 <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 java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;
import me.gladwell.eclipse.m2e.android.AndroidMavenPlugin;

import org.apache.maven.model.Model;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.MavenProjectInfo;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
import org.eclipse.m2e.tests.common.JobHelpers;
import org.eclipse.m2e.tests.common.WorkspaceHelpers;
import org.eclipse.m2e.tests.common.JobHelpers.IJobMatcher;

import com.android.ide.eclipse.adt.internal.sdk.Sdk;

public abstract class AndroidMavenPluginTestCase extends AbstractMavenProjectTestCase {

	static final int MAXIMUM_SECONDS_TO_LOAD_ADT = 120;

	protected AndroidMavenPlugin plugin;

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

	    plugin = AndroidMavenPlugin.getDefault();
		plugin.getInjector().injectMembers(this);

	    waitForAdtToLoad();
    }

	protected void waitForAdtToLoad() throws InterruptedException, Exception {
        try {
    		JobHelpers.waitForJobs(new IJobMatcher() {
    			public boolean matches(Job job) {
    				return job.getClass().getName().contains(Sdk.class.getName());
    			}
    			
    		}, MAXIMUM_SECONDS_TO_LOAD_ADT * 1000);
        } catch(Throwable t) {
            t.printStackTrace();
        }
	}

	protected IProject importAndroidProject(String name) throws Exception {
		IProject project = importProject("projects/"+name+"/pom.xml");
		waitForAndroidJobsToComplete();
		waitForAdtToLoad();
	    return project;
	}

	protected IProject importAndroidProject(String name, File folder) throws Exception {
        IProject project = importProject("projects/"+name+"/pom.xml", folder);
        waitForAndroidJobsToComplete();
        waitForAdtToLoad();
        return project;
	}

    private IProject importProject(String pomLocation, File parent) throws Exception {
        MavenModelManager mavenModelManager = MavenPlugin.getMavenModelManager();

        File pomFile = new File(pomLocation);
        File src = new File(pomFile.getParentFile().getCanonicalPath());
        File dst = new File(parent, pomFile.getParentFile().getName());

        copyDir(src, dst);

        String pomName = pomFile.getName();
        pomFile = new File(dst, pomName);
        Model model = mavenModelManager.readMavenModel(pomFile);
        MavenProjectInfo projectInfo = new MavenProjectInfo(pomName, pomFile, model, null);
        File workspaceRoot = workspace.getRoot().getLocation().toFile();
        File basedir = projectInfo.getPomFile().getParentFile().getCanonicalFile();

        projectInfo.setBasedirRename(basedir.getParentFile().equals(workspaceRoot)? MavenProjectInfo.RENAME_REQUIRED: MavenProjectInfo.RENAME_NO);

        final ArrayList<MavenProjectInfo> projectInfos = new ArrayList<MavenProjectInfo>();
        projectInfos.add(projectInfo);

        final ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration(new ResolverConfiguration());

        final ArrayList<IMavenProjectImportResult> importResults = new ArrayList<IMavenProjectImportResult>();

        workspace.run(new IWorkspaceRunnable() {
            public void run(IProgressMonitor monitor) throws CoreException {
                importResults.addAll(MavenPlugin.getProjectConfigurationManager()
                        .importProjects(projectInfos, importConfiguration, monitor));
            }
        }, MavenPlugin.getProjectConfigurationManager().getRule(), IWorkspace.AVOID_UPDATE, monitor);
{'fraction_non_alphanumeric': 0.12656494522691705, 'fraction_numerical': 0.007042253521126761, 'mean_word_length': 4.605811403508772, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '6653505', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2837, 'n_words': 536}