<commit_before>/*******************************************************************************
 * Copyright (c) 2013 <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
 * 
 * Contributors:      
 *     <NAME> <<EMAIL>> - initial API and implementation
 *******************************************************************************/
package org.eclipse.angularjs.internal.ui.handlers;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.angularjs.core.AngularNature;
import org.eclipse.angularjs.internal.ui.AngularUIMessages;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import tern.eclipse.ide.core.TernNature;

/**
 * Convert selected project to Angular project.
 * 
 */
public class ConvertProjectToAngularCommandHandler extends AbstractHandler {

	public Object execute(ExecutionEvent event) throws ExecutionException {

		final IProject project = getSelectedProject(event);

		if (project == null) {
			return null;
		}

		WorkspaceJob convertJob = new WorkspaceJob(
				AngularUIMessages.ConvertProjectToAngular_converting_project_job_title) {
			public IStatus runInWorkspace(IProgressMonitor monitor)
					throws CoreException {

				IProjectDescription projectDescription = project
						.getDescription();

				// Configure builders:
				/*
				 * List newBuildSpec = new LinkedList(); ICommand[] buildSpec =
				 * projectDescription.getBuildSpec(); for (int c = 0; c <
				 * buildSpec.length; ++c) { if
				 * (!buildSpec[c].getBuilderName().equals( PHPECLIPSE_BUILDER))
				 * { newBuildSpec.add(buildSpec[c]); } } ICommand command =
				 * projectDescription.newCommand();
				 * command.setBuilderName(PHPNature.VALIDATION_BUILDER_ID);
				 * newBuildSpec.add(command);
				 * 
				 * command = projectDescription.newCommand();
				 * newBuildSpec.add(command);
				 * 
				 * projectDescription.setBuildSpec((ICommand[]) newBuildSpec
				 * .toArray(new ICommand[newBuildSpec.size()]));
				 */
				// Configure natures:
				List newNatures = new LinkedList();
				String[] natures = projectDescription.getNatureIds();
				for (int c = 0; c < natures.length; ++c) {
					if (!natures[c].equals(AngularNature.ID)) {
						newNatures.add(natures[c]);
					} else if (!natures[c].equals(TernNature.ID)) {
						newNatures.add(natures[c]);
					}
				}
				newNatures.add(AngularNature.ID);
				newNatures.add(TernNature.ID);

				projectDescription.setNatureIds((String[]) newNatures
						.toArray(new String[newNatures.size()]));

				// Save project description:
				project.setDescription(projectDescription, monitor);
				return Status.OK_STATUS;
			}
		};
		convertJob.setUser(true);
		convertJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
		convertJob.schedule();

		return null;
	}

	private IProject getSelectedProject(ExecutionEvent event) {
		ISelection currentSelection = HandlerUtil.getCurrentSelection(event);

		if (currentSelection instanceof IStructuredSelection) {
			Object element = ((IStructuredSelection) currentSelection)
					.getFirstElement();
			return (IProject) Platform.getAdapterManager().getAdapter(element,
					IProject.class);
		}
		return null;
	}

}
<commit_msg>Convert To AngularJS Project action handler adds second Tern.java nature in case it already exists on a project.<commit_after>/*******************************************************************************
 * Copyright (c) 2013, 2014 <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
 * 
 * Contributors:      
 *     <NAME> <<EMAIL>> - initial API and implementation
 *******************************************************************************/
package org.eclipse.angularjs.internal.ui.handlers;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.angularjs.core.AngularNature;
import org.eclipse.angularjs.internal.ui.AngularUIMessages;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import tern.eclipse.ide.core.TernNature;

/**
 * Convert selected project to Angular project.
 * 
 */
public class ConvertProjectToAngularCommandHandler extends AbstractHandler {

	public Object execute(ExecutionEvent event) throws ExecutionException {

		final IProject project = getSelectedProject(event);

		if (project == null) {
			return null;
		}

		WorkspaceJob convertJob = new WorkspaceJob(
				AngularUIMessages.ConvertProjectToAngular_converting_project_job_title) {
			public IStatus runInWorkspace(IProgressMonitor monitor)
					throws CoreException {

				IProjectDescription projectDescription = project
						.getDescription();

				// Configure builders:
				/*
				 * List newBuildSpec = new LinkedList(); ICommand[] buildSpec =
				 * projectDescription.getBuildSpec(); for (int c = 0; c <
				 * buildSpec.length; ++c) { if
				 * (!buildSpec[c].getBuilderName().equals( PHPECLIPSE_BUILDER))
				 * { newBuildSpec.add(buildSpec[c]); } } ICommand command =
				 * projectDescription.newCommand();
				 * command.setBuilderName(PHPNature.VALIDATION_BUILDER_ID);
				 * newBuildSpec.add(command);
				 * 
				 * command = projectDescription.newCommand();
				 * newBuildSpec.add(command);
				 * 
				 * projectDescription.setBuildSpec((ICommand[]) newBuildSpec
				 * .toArray(new ICommand[newBuildSpec.size()]));
				 */
				// Configure natures:
				List newNatures = new LinkedList();
				String[] natures = projectDescription.getNatureIds();
				for (int c = 0; c < natures.length; ++c) {
					if (!AngularNature.ID.equals(natures[c]) && 
							!TernNature.ID.equals(natures[c])) {
						newNatures.add(natures[c]);
					}
				}
				newNatures.add(AngularNature.ID);
				newNatures.add(TernNature.ID);

				projectDescription.setNatureIds((String[]) newNatures
						.toArray(new String[newNatures.size()]));

				// Save project description:
				project.setDescription(projectDescription, monitor);
				return Status.OK_STATUS;
			}
		};
		convertJob.setUser(true);
		convertJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
		convertJob.schedule();

		return null;
	}

	private IProject getSelectedProject(ExecutionEvent event) {
		ISelection currentSelection = HandlerUtil.getCurrentSelection(event);

		if (currentSelection instanceof IStructuredSelection) {
			Object element = ((IStructuredSelection) currentSelection)
					.getFirstElement();
			return (IProject) Platform.getAdapterManager().getAdapter(element,
					IProject.class);
		}
		return null;
	}

}

{'fraction_non_alphanumeric': 0.14483269539449314, 'fraction_numerical': 0.002963328806025435, 'mean_word_length': 4.582356995175741, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '6749721', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2218, 'n_words': 455}