Does ProjectManager.getInstance().loadAndOpenProject(filepath); cancel headless mode

Answered

Hello everyone, 

I have an application i want to run in headless mode. For that i overrite the main function and the isHeadless (to return true) function in the AppstarterService Extension point. in that main function i make the call ProjectManager.getInstance().loadAndOpenProject(filepath);

This opens the IDE Window. My question is, does the window open because i load the project or is there another reason for this behaviour? 

 

 

4 comments
Comment actions Permalink

Use com.intellij.ide.impl.ProjectUtil#openOrImport(java.nio.file.Path), see existing ApplicationStarter implementations.

0
Comment actions Permalink

Do you happen to have any recommendations where to find some functioning examples? 

0
Comment actions Permalink

There are usages in IntelliJ Community as well as in OSS Plugins use https://plugins.jetbrains.com/docs/intellij/explore-api.html as a guide

0
Comment actions Permalink
@Override
public void main(@NotNull List<String> args) {

try{
final ApplicationEx application = (ApplicationEx) ApplicationManager.getApplication();
application.setSaveAllowed(false);
Project project = ProjectUtil.openOrImport(Path.of("*projectpath*/untitled1"), null , false);

if (project == null) {
FileWriter error = new FileWriter("*projectpath*/untitled1/error.txt");
error.write("error");
error.close();
System.exit(0);
}

FileWriter File = new FileWriter("*projectpath*/untitled1/itworked.txt");
File.write(project.getBasePath());
File.close();

application.invokeAndWait(() -> VirtualFileManager.getInstance().refreshWithoutFileWatcher(false));
PatchProjectUtil.patchProject(project);

PsiFile[] file = FilenameIndex.getFilesByName(project, "test.js", GlobalSearchScope.projectScope(project));
FileWriter File2 = new FileWriter(project.getBasePath().concat("/FileIndex " + file.length + " .txt"));
File2.write(file.length);
File2.close();

}catch(Exception e){
}finally{
System.exit(0);
}

}
@Override
public boolean isHeadless() {
return true;
}

I wrote this little appstarter implementation for debug purposes. 
if i leave the projectutil.openorimport out it executes in headless mode. as soon as i load the project the headless mode gets cancelt. Is there a way to still remain in headless mode.

I allready checked with other plugin implementations and this test app is a copy of the MetricsReloaded appstarter who claim to have headless mode.

0

Please sign in to leave a comment.