bnd
bnd copied to clipboard
[sync] Workspace sync interfering with template project creation
I was just trying to create a new Bnd project using the templates. I kept getting an error dialog during import saying:
Error generating project contents from template "<template name>": Can only create plain Folder parent containers.
Some of the folders were created, others not.
Turns out that this is due to the Syncer being too eager to do its thing. I sprinkled some tracing into the code and discovered that the syncer is getting notified of the changes in the bnd workspace as the files are being copied one-by-one. The template creates the project in the (Eclipse) workspace, and before it can finish copying all of the files across that would mark it is a full-fledged Bnd project, the syncer has removed it because it doesn't have a bnd file yet.
The easy fix for this would be (I think) for the template creation to lock the (Eclipse) project while it is creating it. Maybe, it would be necessary to get a write lock on the Bnd workspace object too.
A bigger question is: should the syncer be removing projects from the Eclipse workspace at all? If yes, do the rules need to be tightened a little?
I noticed that yesterday as well. Will be working on it.
Thanks. I had a go but out wasn't as simple as I had thought, because the Java new project Wizard creates the project without any locking before handing off to our subclass, so there's always a window in which the syncer can get in there and mess things up. At least, that was my initial impression - I didn't get a chance to dig more.
The alternate solution you proposed in #4705 I think will work. A custom wizard that completely abandons the Java project wizard would also present less configuration options and reduce the opportunity for misconfiguring the new project. Two concerns I have:
- Some project templates have .project and .classpath files. How will the syncer interact?
- Slightly related: I also noted that the syncer doesn't update existing projects. What is the workflow for resyncing a project whose relevant Bnd configuration has changed? (Eg, src dir changed or added, javac changed, etc)
I think we fundamentally were hopping between 2 strategies: create in Eclipse or create in bnd and sync. The latter is way easier because you're in Java land. And syncing must work anyway. E.g. .project & .classpath are correctly synced by Eclipse. Remember how the quickfix buildpath augment became a lot easier when we just refreshed the file?
In general, I find that a staggering amount of code can be removed when you collapse the initialization & the update. As bonus,. it tends to work much more reliable. (This was the core idea behind the Managed Service (Factory)).
For syncing, that is the strategy I think we need to adopt fanatically. I think we should fully sync the bnd workspace for bnd projects. I.e. the src & test folders for projects must come from the Workspace. I had a discussion with BJ about the .classpath file but I think that for bnd projects the content should be 100% defined by the bnd.bnd & workspace files. Any custom entries in the .classpath will not be recognized by gradle or other drivers so any customization is bound to cause problems in CI. Although there are, imho theoretical, use cases for custom .classpath entries, I think the problems that are caused by us not controlling it are magnitudes higher. We could have flag of course to control this behavior.
We could have flag of course to control this behavior.
This is a must so one can opt out of tyranny. Remember that people have been using Bnd and Bndtools for a long time and people do weird things. We need to not suddenly destroy their workspaces and their work flows. For a first release, syncing should probably be an opt-in where people can enable it if they want. With some experience and time, we can consider moving to opt-out.
As an example of a weird thing someone might fo in their workspace, i had a cxf project that was generating source using a Maven plugin. Of course ideally I'd port the cxf codegen plugin to bnd generate, but that was extra work I didn't have time for, and the only other alternative was to go full Maven which I wanted to avoid as I needed p2 repos. I got around the CI issue by checking the generated source in to source control.
Another one was when i had a launch- only project, which for some reason I still needed to have the Bndtools nature (I think so that the .bndrun editor would work properly). The project had no bnd.bnd file and the syncer kept removing it until I created a dummy bnd.bnd.
I think we need:
- option to turn off auto syncing, either as a whole or individual types (the types being add, update and remove project)
- manual update command a la m2e's "update project" command.
- in the new project wizard, toggle switch to preserve .classpath and .project (if present in the template) or regenerate them.
moving it to abeyance since I do not think I've time for this.