Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8ea8af14332591ccaeffad06ec8d65fb1b9fc687 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*******************************************************************************
 * Copyright (c) 2016 Red Hat, Inc. 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * 	Contributors:
 * 		 Red Hat Inc. - initial API and implementation and/or initial documentation
 *******************************************************************************/
package org.eclipse.wst.jsdt.js.common.build.system.launch;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.wst.jsdt.js.common.CommonPlugin;
import org.eclipse.wst.jsdt.js.common.build.system.ITask;

/**
 * @author "Ilya Buziuk (ibuziuk)"
 */
public class LaunchConfigurationAutoFill {

	/**
	 * Filters configurations for launch configurations with the same build file as a task.
	 *
	 * @param configurations - the launch configurations to filter
	 * @param task - the target task
	 * @param buildAttribute - the name of the launch configuration attribute that stores the build file.
	 * @return an array of launch configurations that target the same build file as task
	 */
	public static ILaunchConfiguration[] getAllLaunchConfigurations(
			ILaunchConfiguration[] configurations, ITask task, String buildAttribute) {

		List<ILaunchConfiguration> validConfigs = new ArrayList<>();
		try {
			for (ILaunchConfiguration conf : configurations) {
				String buildFileAttribute = conf.getAttribute(buildAttribute, (String) null);
				String buildFilePath = task.getBuildFile().getLocation().toOSString();
				// Launch Configuration per build file (i.e. Gruntfile.js / gulpfile.js)
				if (buildFilePath.equals(buildFileAttribute)) {
					validConfigs.add(conf);
				}
			}
		} catch (CoreException e) {
			CommonPlugin.logError(e, e.getMessage());
		}

		return validConfigs.toArray(new ILaunchConfiguration[validConfigs.size()]);
	}
}

Back to the top