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) 2013, 2015 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.cdt.internal.qt.core.index;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.internal.qt.core.Activator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
/**
* Represents a manager of registered qmakeEnvProvider extensions.
*/
public final class QMakeEnvProviderManager {
private static QMakeEnvProviderManager INSTANCE = new QMakeEnvProviderManager();
private final List<QMakeEnvProviderDescriptor> descriptors;
public static QMakeEnvProviderManager getInstance() {
return INSTANCE;
}
private QMakeEnvProviderManager() {
descriptors = loadDescriptors();
}
/**
* Returns a list of all registerd qmakeEnvProvider extensions.
*
* @return the list of extensions
*/
private static List<QMakeEnvProviderDescriptor> loadDescriptors() {
List<QMakeEnvProviderDescriptor> descriptors = new ArrayList<QMakeEnvProviderDescriptor>();
IConfigurationElement[] elements = Platform.getExtensionRegistry()
.getConfigurationElementsFor(Activator.ID, Activator.QMAKE_ENV_PROVIDER_EXT_POINT_NAME);
for (IConfigurationElement element : elements) {
descriptors.add(new QMakeEnvProviderDescriptor(element));
}
Collections.sort(descriptors);
return descriptors;
}
/**
* Called by QMakeProjectInfo to create IQMakeEnv for a specified IController.
* It asks each qmakeEnvProvider extensions to provide the instance. If none of them provides, then the default IQMakeEnvProvider is returned.
*
* @param controller the controller
* @return the IQMakeEnv instance for specifying the QMake environment
*/
public IQMakeEnv createEnv(IQMakeEnvProvider.IController controller) {
for (QMakeEnvProviderDescriptor descriptor : descriptors) {
IQMakeEnv env = descriptor.createEnv(controller);
if (env != null) {
return env;
}
}
return new ConfigurationQMakeEnv(controller.getConfiguration());
}
/**
* Represents a fallback IQMakeEnvProvider that is used for a project that has QtNature
* while there is no registered IQMakeEnvProvider that would provide any IQMakeEnv.
*/
private static class ConfigurationQMakeEnv implements IQMakeEnv2 {
private static final String PRO_FILE_SUFFIX = ".pro"; //$NON-NLS-1$
private static final String ENV_VAR_QMAKE = "QMAKE"; //$NON-NLS-1$
private final ICConfigurationDescription configuration;
public ConfigurationQMakeEnv(ICConfigurationDescription configuration) {
this.configuration = configuration;
}
@Override
public void init() {
}
@Override
public void destroy() {
}
/**
* Returns QMakeEnvInfo resolved from a project in a generic way.
* If exists, the root-level .pro file is resolved as the one that is located directly under the project and has the same name.
* If exists, qmake executable is resolved from "QMAKE" environment variable that is stored in the project configuration.
*
* @return the QMakeEnvInfo instance if the project configuration exists; otherwise null.
*/
@Override
public QMakeEnvInfo getQMakeEnvInfo() {
if (configuration == null) {
return null;
}
IProject project = configuration.getProjectDescription().getProject();
IFile proFile = project != null ? project.getFile(project.getName() + PRO_FILE_SUFFIX) : null;
IEnvironmentVariable variable = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENV_VAR_QMAKE, configuration, true);
String qmakeFilePath = variable != null ? variable.getValue() : null;
return new QMakeEnvInfo(proFile, qmakeFilePath, Collections.<String,String>emptyMap(), Collections.<IFile>emptyList());
}
}
}
|