Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a7c12074d9da6d64db686dabd5745a06109bd160 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * Copyright (c) 2005, 2018 Intel Corporation and others.
 * 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:
 * Intel Corporation - Initial API and implementation
 * IBM Corporation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.core;

import org.eclipse.cdt.internal.core.SafeStringInterner;
import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver;
import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;

public class EnvVarBuildPath implements
		IEnvVarBuildPath {

	private int fType;
	private String fVariableNames[];
	private String fPathDelimiter;
	private IBuildPathResolver fBuildPathResolver;
	private IConfigurationElement fBuildPathResolverElement;


	/**
	 * Constructor to create an EnvVarBuildPath based on an element from the plugin
	 * manifest.
	 *
	 * @param element The element containing the information about the tool.
	 */
	public EnvVarBuildPath(ITool tool, IManagedConfigElement element) {
		loadFromManifest(element);
	}

	/* (non-Javadoc)
	 * Load the EnvVarBuildPath information from the XML element specified in the
	 * argument
	 * @param element An XML element containing the tool information
	 */
	protected void loadFromManifest(IManagedConfigElement element) {

		setType(convertPathTypeToInt(element.getAttribute(TYPE)));

		setVariableNames(SafeStringInterner.safeIntern(element.getAttribute(LIST)));

		setPathDelimiter(SafeStringInterner.safeIntern(element.getAttribute(PATH_DELIMITER)));

		// Store the configuration element IFF there is a build path resolver defined
		String buildPathResolver = element.getAttribute(BUILD_PATH_RESOLVER);
		if (buildPathResolver != null && element instanceof DefaultManagedConfigElement) {
			fBuildPathResolverElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
		}
	}

	@Override
	public int getType() {
		return fType;
	}

	public void setType(int type){
		this.fType = type;
	}

	@Override
	public String[] getVariableNames() {
		return fVariableNames;
	}

	public void setVariableNames(String names[]){
		fVariableNames = names;
		fVariableNames = SafeStringInterner.safeIntern(fVariableNames);
	}

	public void setVariableNames(String names){
		setVariableNames(getNamesFromString(names));
	}

	public String[] getNamesFromString(String names){
		if(names == null)
			return null;
		return names.split(NAME_SEPARATOR);
	}

	@Override
	public String getPathDelimiter() {
		return fPathDelimiter;
	}

	public void setPathDelimiter(String delimiter) {
		if(delimiter == null)
			delimiter = ManagedBuildManager.getEnvironmentVariableProvider().getDefaultDelimiter();
		fPathDelimiter = SafeStringInterner.safeIntern(delimiter);
	}

	private int convertPathTypeToInt(String pathType){
		if(pathType != null && TYPE_LIBRARY.equals(pathType))
			return BUILDPATH_LIBRARY;
		return BUILDPATH_INCLUDE;
	}

	@Override
	public IBuildPathResolver getBuildPathResolver() {
		if(fBuildPathResolver == null && fBuildPathResolverElement != null){
			try {
				if (fBuildPathResolverElement.getAttribute(BUILD_PATH_RESOLVER) != null) {
					fBuildPathResolver = (IBuildPathResolver) fBuildPathResolverElement.createExecutableExtension(BUILD_PATH_RESOLVER);
				}
			} catch (CoreException e) {}
		}
		return fBuildPathResolver;
	}

}

Back to the top