use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method startServer.
private void startServer(@NotNull final DartSdk sdk) {
// DartPubActionBase will start the server itself when finished
if (DartPubActionBase.isInProgress())
return;
synchronized (myLock) {
mySdkHome = sdk.getHomePath();
final String runtimePath = FileUtil.toSystemDependentName(DartSdkUtil.getDartExePath(sdk));
String analysisServerPath = FileUtil.toSystemDependentName(mySdkHome + "/bin/snapshots/analysis_server.dart.snapshot");
analysisServerPath = System.getProperty("dart.server.path", analysisServerPath);
String dasStartupErrorMessage = "";
final File runtimePathFile = new File(runtimePath);
final File dasSnapshotFile = new File(analysisServerPath);
if (!runtimePathFile.exists()) {
dasStartupErrorMessage = "the Dart VM file does not exist at location: " + runtimePath;
} else if (!dasSnapshotFile.exists()) {
dasStartupErrorMessage = "the Dart Analysis Server snapshot file does not exist at location: " + analysisServerPath;
} else if (!runtimePathFile.canExecute()) {
dasStartupErrorMessage = "the Dart VM file is not executable at location: " + runtimePath;
} else if (!dasSnapshotFile.canRead()) {
dasStartupErrorMessage = "the Dart Analysis Server snapshot file is not readable at location: " + analysisServerPath;
}
if (!dasStartupErrorMessage.isEmpty()) {
LOG.warn("Failed to start Dart analysis server: " + dasStartupErrorMessage);
stopServer();
return;
}
final DebugPrintStream debugStream = str -> {
str = str.substring(0, Math.min(str.length(), MAX_DEBUG_LOG_LINE_LENGTH));
synchronized (myDebugLog) {
myDebugLog.add(str);
}
};
String vmArgsRaw;
try {
vmArgsRaw = Registry.stringValue("dart.server.vm.options");
} catch (MissingResourceException e) {
vmArgsRaw = "";
}
String serverArgsRaw = "";
serverArgsRaw += " --useAnalysisHighlight2";
//serverArgsRaw += " --file-read-mode=normalize-eol-always";
try {
serverArgsRaw += " " + Registry.stringValue("dart.server.additional.arguments");
} catch (MissingResourceException e) {
// NOP
}
myServerSocket = new StdioServerSocket(runtimePath, StringUtil.split(vmArgsRaw, " "), analysisServerPath, StringUtil.split(serverArgsRaw, " "), debugStream);
myServerSocket.setClientId(getClientId());
myServerSocket.setClientVersion(getClientVersion());
final AnalysisServer startedServer = new RemoteAnalysisServerImpl(myServerSocket);
try {
startedServer.start();
startedServer.server_setSubscriptions(Collections.singletonList(ServerService.STATUS));
if (Registry.is("dart.projects.without.pubspec", false)) {
startedServer.analysis_setGeneralSubscriptions(Collections.singletonList(GeneralAnalysisService.ANALYZED_FILES));
}
if (!myInitializationOnServerStartupDone) {
myInitializationOnServerStartupDone = true;
registerFileEditorManagerListener();
registerDocumentListener();
setDasLogger();
registerQuickAssistIntentions();
}
startedServer.addAnalysisServerListener(myAnalysisServerListener);
for (AnalysisServerListener listener : myAdditionalServerListeners) {
startedServer.addAnalysisServerListener(listener);
}
myHaveShownInitialProgress = false;
startedServer.addStatusListener(isAlive -> {
if (!isAlive) {
synchronized (myLock) {
if (startedServer == myServer) {
stopServer();
}
}
}
});
mySdkVersion = sdk.getVersion();
startedServer.analysis_updateOptions(new AnalysisOptions(true, true, true, true, true, false, true, false));
myServer = startedServer;
} catch (Exception e) {
LOG.warn("Failed to start Dart analysis server", e);
stopServer();
}
}
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartCoverageProgramRunner method startCollectingCoverage.
private static void startCollectingCoverage(@NotNull final ExecutionEnvironment env, @NotNull final ProcessHandler dartAppProcessHandler, @NotNull final String observatoryUrl) {
final DartCommandLineRunConfiguration dartRC = (DartCommandLineRunConfiguration) env.getRunProfile();
final DartCoverageEnabledConfiguration coverageConfiguration = (DartCoverageEnabledConfiguration) CoverageEnabledConfiguration.getOrCreate(dartRC);
final String coverageFilePath = coverageConfiguration.getCoverageFilePath();
final DartSdk sdk = DartSdk.getDartSdk(env.getProject());
LOG.assertTrue(sdk != null);
final GeneralCommandLine cmdline = new GeneralCommandLine().withExePath(DartSdkUtil.getPubPath(sdk)).withParameters("global", "run", "coverage:collect_coverage", "--uri", observatoryUrl, "--out", coverageFilePath, "--resume-isolates", "--wait-paused");
try {
final ProcessHandler coverageProcess = new OSProcessHandler(cmdline);
coverageProcess.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(@NotNull final ProcessEvent event, @NotNull final Key outputType) {
LOG.debug(event.getText());
}
});
coverageProcess.startNotify();
coverageConfiguration.setCoverageProcess(coverageProcess);
CoverageHelper.attachToProcess(dartRC, dartAppProcessHandler, env.getRunnerSettings());
} catch (ExecutionException e) {
LOG.error(e);
}
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartProjectComponent method removeGlobalDartSdkLib.
private void removeGlobalDartSdkLib() {
for (final Library library : ApplicationLibraryTable.getApplicationTable().getLibraries()) {
if (DartSdk.DART_SDK_LIB_NAME.equals(library.getName())) {
final DartSdk oldGlobalSdk = DartSdk.getSdkByLibrary(library);
if (oldGlobalSdk != null) {
DartSdkUtil.updateKnownSdkPaths(myProject, oldGlobalSdk.getHomePath());
}
ApplicationManager.getApplication().runWriteAction(() -> ApplicationLibraryTable.getApplicationTable().removeLibrary(library));
return;
}
}
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartOutdatedDependenciesInspection method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (!isOnTheFly)
return null;
if (!(psiFile instanceof DartFile))
return null;
if (DartPubActionBase.isInProgress())
return null;
final VirtualFile file = DartResolveUtil.getRealVirtualFile(psiFile);
if (file == null || !file.isInLocalFileSystem())
return null;
final Project project = psiFile.getProject();
if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file))
return null;
final DartSdk sdk = DartSdk.getDartSdk(project);
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module == null || sdk == null || !DartSdkLibUtil.isDartSdkEnabled(module))
return null;
if (FlutterUtil.isFlutterPluginInstalled() && FlutterUtil.isFlutterModule(module))
return null;
final VirtualFile pubspecFile = PubspecYamlUtil.findPubspecYamlFile(project, file);
if (pubspecFile == null || myIgnoredPubspecPaths.contains(pubspecFile.getPath()))
return null;
final String projectName = PubspecYamlUtil.getDartProjectName(pubspecFile);
// 'pub get' will fail anyway
if (projectName == null || !StringUtil.isJavaIdentifier(projectName))
return null;
final VirtualFile dotPackagesFile = pubspecFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);
if (dotPackagesFile == null) {
return createProblemDescriptors(manager, psiFile, pubspecFile, DartBundle.message("pub.get.never.done"));
}
if (FileDocumentManager.getInstance().isFileModified(pubspecFile) || pubspecFile.getTimeStamp() > dotPackagesFile.getTimeStamp()) {
return createProblemDescriptors(manager, psiFile, pubspecFile, DartBundle.message("pubspec.edited"));
}
return null;
}
use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.
the class DartLibraryIndex method getSdkLibByUri.
@Nullable
public static VirtualFile getSdkLibByUri(@NotNull final Project project, @NotNull final String sdkLibUri) {
final DartSdk sdk = DartSdk.getDartSdk(project);
final String relativeLibPath = sdk == null ? null : getSdkLibUriToRelativePathMap(project, sdk.getHomePath()).get(sdkLibUri);
return relativeLibPath == null ? null : LocalFileSystem.getInstance().findFileByPath(sdk.getHomePath() + "/lib/" + relativeLibPath);
}
Aggregations