Deployment mapping's path update by plugin
I have a project with Git enabled as VCS. There is a deployment configuration defined for my project as you can see in the screenshot.
I work with many branches and I switch among them time to time. When I switch a branch, I then manually need to update these deployment mappings to upload my changes to the right branch hosted on my server as you see in the 2nd screenshot. Doing it manually is tedius task.
So what I did was: I wrote a powershell script which switchd the branch using git checkout command and then it modifies the deployment mappings settings in .idea/deployment.xml file and it is reflected on the Deployment Mapping screen correctly The problem is PHPStorm doesn't pick this change happened in the physical file unless I manually update it in the Deployment screen. As you can see in 3rd screenshot, it was uploading changes to the last path which was when it read the file last time.
To work around this, I wrote a plugin [Targets Intellij Ultimate & PHPStrom] to do so. But I can get it to work. Here is what I did:
- I registered a git branch change listener
- When the branch change happened, my powershell script had already updated the deployment.xml file
- I got this far with my plugin development that it receives the git branch update when I do so
- Here I used VirtualFileManager (VFS) to refresh the deployment.xml file, hoping it would inform PHPStrom to reflect the change, but it didn't work. Here is the code:
VirtualFileManager vfs = VirtualFileManager.getInstance();
Path relativePath = Paths.get(".idea", "deployment.xml");
Path absolutePath = Paths.get(project.getBasePath(), relativePath.toString());
if (!absolutePath.toFile().exists()) {
return;
}
vfs.findFileByNioPath(absolutePath).refresh(false, false);
I also did other things which I don't think really necessary or even right!
vfs.getFileSystem(null).refresh(false);
vfs.syncRefresh();
Please sign in to leave a comment.
Hi,
I suggest trying a different approach to the problem. Instead of modifying deployment.xml externally by a script, consider modifying the mapping object directly. Try getting the com.jetbrains.plugins.webDeployment.config.PublishConfig service, find the mapping, and then modify it:
Thank you for your reply. Really appreciate.
I am facing a problem.
Cannot resolve symbol 'PublishConfig'
Do I need add any dependencies for this in build.gradle.kts file? If yes, could you please tell me in details how to do it?
Thank you.
Yes, you should add a dependency on
com.jetbrains.plugins.webDeployment
plugin in the Gradle build script:and plugin.xml:
See: https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html for more information about adding dependencies.
Hi Karol,
I tried your approach, however found no luck! I have been able to update the deployment path mappings using PublishConfig. After changing the path using the plugin, I then modify a file and hit save[Ctrl + S], it then uploads to the last path!! Not to the updated one! Here is what I did:
Hi,
Why do you call
config.loadState(state)
? It loads the data from the storage, sodeployment.xml
file. It overwrites any changes you did before.Hello,
I followed your suggestion by removing this code:
Didn't make any difference. When the above line is removed it doesn't update mappings in the UI!
To help you understand what I have done so far, I have included two zip files.
Hi,
I can't even check the project, as it fails on:
Please prepare working plugin sources and describe the exact steps to reproduce the issue.
This can be closed.
Hi Abdul,
Could you please share the solution so other developers facing the same issue can use it?
Here is waht I did finally to update deployment mappings for default server and notify the IDE about that change to reflect: