/
MpsEnvironment.java
108 lines (94 loc) · 3.93 KB
/
MpsEnvironment.java
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
package jetbrains.mps.tool.environment;
/*Generated by MPS */
import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.logging.Logger;
import jetbrains.mps.core.platform.Platform;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.application.PathManager;
import jetbrains.mps.core.platform.PlatformFactory;
import jetbrains.mps.core.platform.PlatformOptionsBuilder;
import jetbrains.mps.library.LibraryInitializer;
import java.util.List;
import jetbrains.mps.library.contributor.LibraryContributor;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import jetbrains.mps.internal.collections.runtime.SetSequence;
import jetbrains.mps.project.Project;
import java.io.File;
import jetbrains.mps.core.tool.environment.util.FileMPSProject;
import jetbrains.mps.util.FileUtil;
@GeneratedClass(node = "r:2876f1ee-0b45-4db5-8c09-0682cdee5c67(jetbrains.mps.tool.environment)/7413225496542996633", model = "r:2876f1ee-0b45-4db5-8c09-0682cdee5c67(jetbrains.mps.tool.environment)")
public final class MpsEnvironment extends EnvironmentBase {
private static final Logger LOG = Logger.getLogger(MpsEnvironment.class);
private Platform myPlatform;
private PlatformPlugins myPlugins;
static {
EnvironmentBase.initializeLog();
}
public MpsEnvironment(@NotNull EnvironmentConfig config) {
super(config);
}
public void init() {
if (LOG.isInfoLevel()) {
LOG.info("Creating MPS environment");
}
// paths selector is a single property allows to define the locations for logs/caches/other system files of MPS
// see https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs
System.setProperty("java.awt.headless", Boolean.TRUE.toString());
if (System.getProperty(PathManager.PROPERTY_PATHS_SELECTOR) == null) {
System.setProperty(PathManager.PROPERTY_PATHS_SELECTOR, "MPSNoPlatform");
}
myPlatform = PlatformFactory.initPlatform(PlatformOptionsBuilder.ALL);
myPlugins = new PlatformPlugins(myConfig);
super.init(myPlatform);
}
@Override
protected void initLibraries(@NotNull LibraryInitializer libInitializer) {
// can do it only here as root CL is initialized in super.init(). Once I get rid of its uses in IdeaEnvironment,
// can move the field here and init CLs along with field initialization
myPlugins.buildClassLoaders(getRootClassLoader());
final List<LibraryContributor> libContribs = ListSequence.fromList(new ArrayList<LibraryContributor>());
LibraryContributorHelper helper = new LibraryContributorHelper();
if (SetSequence.fromSet(myConfig.getLibs()).isNotEmpty()) {
ListSequence.fromList(libContribs).addElement(helper.createLibContributorForLibs(myConfig.getLibs(), getRootClassLoader()));
}
// FIXME at the moment, we always build CP for a plugin, despite the fact it could be in a global CP already
// need to respect global CP scenario and to use rootCL as plugin CL directly in that case
if (!(myPlugins.isEmpty())) {
ListSequence.fromList(libContribs).addElement(helper.createLibContributorForPlugins(myPlugins));
}
libInitializer.load(libContribs);
}
@Override
@NotNull
public Project doOpenProject(@NotNull File projectFile) {
FileMPSProject project = new FileMPSProject(projectFile, myPlatform);
return project;
}
@NotNull
@Override
public Project createEmptyProject() {
checkInitialized();
if (LOG.isInfoLevel()) {
LOG.info("Creating an empty project");
}
File projectFile = FileUtil.createTmpDir();
projectFile.deleteOnExit();
Project project = openProject(projectFile);
return project;
}
@Override
public void doDispose() {
myPlatform.dispose();
myPlatform = null;
}
@Override
public void flushAllEvents() {
// do nothing
checkInitialized();
}
@Override
public Platform getPlatform() {
return myPlatform;
}
}