CLion: CompilerManager.addBeforeTask/addAfterTask alternative

Hi, I've implemented a small plugin for CLion, which allows to debug Serial port right from the IDE(https://plugins.jetbrains.com/plugin/8031 ). Currently I'm looking for a way to implement the following feature request: https://bitbucket.org/dmitry_cherkas/intellij-serial-monitor/issues/5 

I need some API, which would allow my plugin to listen for "Build Project" events. In Open API I have discovered the following APIs, which pretty much serve my needs:

com.intellij.openapi.compiler.CompilerManager#addBeforeTask

com.intellij.openapi.compiler.CompilerManager#addAfterTask

Unfortunately, those APIs are not available in CLion.

Any hint on replacement APIs for CLion are highly appreciated!

1

Dmitry,

currently there is only com.jetbrains.cidr.lang.workspace.OCWorkspaceModificationListener#buildFinished. Will it be enough? 

(in platform version 163)

0

Hi Anton,

Thanks for your reply. Unfortunately, this API does not allow me to listen to "build started" event. Possibly, I could use some workaround to execute my code before build execution? If it's not possible currently, is there any chance to have such API in upcoming releases?

1
Avatar
Permanently deleted user

+1. The issue here is that Dmitriy's plugin and build process both need an access to the serial port, which is exclusive. So the plugin need to hook up to both build started event (to release the port) and build finished event (to acquire the port again).

0

I am trying to do the same in CLion 2018.3 and although there is a CidrBuildListener.TOPIC which would serve this purpose, the plugin instance of this topic is not the same one as seen by CLion core code. So the message is generated but my plugin is not being informed.

These might as well be different topics.

Is there a way to listen to build start/finish build messages? The one above would be perfect since it gives all the necessary information about the build configuration.

 

0

Solved. There was duplicate library in the project.

0

Hi Vladimir,

Since I never managed to implement the desired functionality, could you please share your approach (may be, a code snippet), that allowed you to track the build start/end events?

0

This is new and only available in CLion 2018.3. I checked and all previous versions are missing
the interfaces.

I implemented the mechanism for disconnecting the serial port on build start and
reconnecting on build end in my own implementation of serial monitor and arduino development goes much smoother.

BTW, it would be good for us to figure out how we can get multiple plugins to make use of the
JSSC library. Right now the first plugin to load the native libs gets to use it. The rest fail
because native libs were loaded by another class loader. So my `Arduino Support` and your
`Serial Monitor` plugin are mutually exclusive.

I added my own serial monitor to eliminate the problem but this will creep up in the future more
often. We probably need to move JSSC into a separate plugin which exposes the library through
IDE Services. We can mark it as a required dependency of ours. We then use that plugin's
Services and API to access JSSC. This way any number of plugins can access JSSC without
conflict.

Here is a bare bones example of getting build events (flattened indents by copy/paste):

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.util.messages.MessageBusConnection;
import com.jetbrains.cidr.cpp.cmake.model.CMakeConfiguration;
import com.jetbrains.cidr.execution.CidrBuildConfiguration;
import com.jetbrains.cidr.execution.build.CidrBuildEvent;
import com.jetbrains.cidr.execution.build.CidrBuildListener;
import com.jetbrains.cidr.execution.build.CidrBuildResult;
import org.jetbrains.annotations.NotNull;

public class BuildListenerProjectComponent implements ProjectComponent, CidrBuildListener {
final Project myProject;
MessageBusConnection myConnection;

public BuildListenerProjectComponent(final Project project) {
myProject = project;
}

@Override
public void projectOpened() {
myConnection = myProject.getMessageBus().connect(myProject);
myConnection.subscribe(CidrBuildListener.TOPIC, this);
}

@Override
public void projectClosed() {
}

@Override
public void beforeStarted(@NotNull final CidrBuildEvent buildEvent) {
CidrBuildConfiguration configuration = buildEvent.getBuildConfiguration();
String targetName = configuration.getName();
if (configuration instanceof CMakeConfiguration) {
CMakeConfiguration makeConfiguration = (CMakeConfiguration) configuration;
String name = makeConfiguration.getTarget().getName();
targetName = name;
}

// do something based on build target
}

@Override
public void afterFinished(@NotNull final CidrBuildEvent buildEvent, @NotNull final CidrBuildResult result) {
if (result.getSucceeded()) {
// do something after successful build

} else {
// do something else after failed build

}
}

@Override
public void initComponent() {

}

@Override
public void disposeComponent() {

}

@Override
public @NotNull String getComponentName() {
return "Arduino Support Terminal Component";
}

public static BuildListenerProjectComponent getInstance(@NotNull Project project) {
return project.getComponent(BuildListenerProjectComponent.class);
}
}
1

Hi,

Vladimir is correct - CidrBuildListener was introduced only in 2018.3.

Dmitry, you could try using it - it should solve your problems.

0

请先登录再写评论。