eclipse change content on save - eclipse

i have implement a ResourceChangeListener and catch the save event. Now i want to add some code to the File. How i can do that?? I try to use BufferedReader/BufferedWriter but than the i must refresh the file. If i try it with IFile.refreshlocal() i got an error that the file is lock?

May be the article "How You've Changed! Responding to resource changes in the Eclipse workspace"
You need to access a resource in a workspace in a thread safe manner. (From this post)
If you are making resource changes outside of a IWorkspaceRunnable (old) or WorkspaceJob (new), that could be the cause of your "is locked" message: the workspace could be
modified at anytime.
Placing your resource changes inside a WorkspaceJob ensures you will not have lock issues with other threads.
You will not need to update the resource view tree or run a refreshLocal(). WorkspaceJob, if all goes well, will handle that for you.
See also article "On the Job: The Eclipse Jobs API" for more on the WorkspaceJob.
[...] our job will not run if a scheduling rule is held by another thread for the workspace root itself or for any of the resources contained in the workspace.
Once this job is running, no other threads will be able to obtain a rule for the above-mentioned resources until the job in our example completes.

Related

Check Syntax of file if edited via Github Web GUI

Tech writers are going to edit text in JSON files via github in our project. Since they never used a IDE (and don't need to) we think about using the web GUI of github. We have a CI, but it would be very cool, if we could run a check before the commit gets done.
Example:
Step 1: tech writer opens in github the JSON file
Step 2: tech writer updates a string
Step 3: tech writer presses button to save the changes
Step 4: Some simple script executes and checks the content of this particular file.
Step 5a: Everything fine? Then commit - END
Step 5b: There is a syntax error. Show the error message to the tech writer.
Is this possible?
GitHub doesn't provide this functionality, and it's not likely anyone else does, either.
In order to do this, GitHub would have to have a non-bare repository on their servers and let you run an arbitrary script. Bare repositories are packed and can be much smaller than a full working tree, and even if GitHub had a working tree, it wouldn't necessarily be on your branch, which would delay the process. Running an arbitrary script is a security risk, and it's not guaranteed that your script would run fast enough for the process to complete in a reasonable amount of time. Your script would also need to run via the API, which has hard limits on response times.
There is GitHub Actions, which lets you do this, but that doesn't provide real-time checking like you want. It is appropriately sandboxed and single use so you can arbitrary scripts.
I should note that Git also doesn't provide real-time checking here: the best it can do is pre-commit hooks to prevent you from committing bad changes (if you've chosen to enable them).

How to move failed / stuck workflow to new version after fixed bug?

My understanding is if the bug was in Activity, the new code will be used since Activity does not have the concept of version. But what if there is a bug in Workflow code and causing some workflows to fail (or even worse, not fail but stuck), we fixed the bug and deployed the new version, but those failing workflows are stuck on old versions. Is there a way to automatically move those failed / stuck workflows to new version and re-run them?
This happening a lot to us because we just started to learn to use Cadence/Temporal
Thank you in advance!
It depends on the bug.
For bugs that cause workflow to get stuck (in Go a nil pointer dereferencing causes panic which blocks the workflow progress by default) deploying the new version of the code is usually enough to unblock them.
If the bugfix requires backwards incompatible change then the best option would be to reset workflow to the point before the bug. This way workflow will be rolled back and continue through the new code.
For situation when the breakage of workflow code is caused by a new bad build you can rollback the workers to the previous build and mark that build as broken and all workflows going to roll back their state to before that build automatically. See "Recovery from bad deployment" section of the Temporal documentation.
If you are using ElasticSearch integration then you can also perform batch reset of multiple workflows using a predicate to select workflows that match some criteria. See "Signal, cancel, terminate workflows as a batch job" section. Besides the name of the section the batch jobs apply to reset operations as well.

How to mention integration service name during importing workflow in a versioned repository from one environment to another

Whenever I try to import a workflow from Dev/Test environment of a versioned repository into Production environment which is also versioned, I get a option where it asks me if I want to Check in or continue without check in. What happens if I do not check in and continue? Will all the objects used in the workflow will not be checked in or is it just the workflow which will not be checked in? I am asking this because, it will be double work if all the objects used will not be checked in including the Workflow, then, I have to go one by one to check in the objects. If I check the check in option for the workflow, after importing the Workflow, the integration service is left blank and when I run it, it is pointing towards the Integration service not mentioned error. For this I generally check out the workflow once I import just to mention the Integration service name. I do not think this is a good practice. Any advices on this will be greatly appreciated.
Thanks
Dhruuv.
Will all the objects used in the workflow will not be checked in or is it just the workflow which will not be checked in?
The objects that will be left in the checked out state are:
the workflow,
the new objects (i.e. they were not present in the Prod repository before the import from Dev/Test),
the modified objects (i.e. they were present in the Prod repository but were overwritten because you chose the Replace option).
I have to go one by one to check in the objects
You don't have to check in every individual object - in Repository Manager open the Versioning menu and choose the Find Checkouts... option. All the checked out objects will be listed - you can select them and check in all of them at once.

Eclipse project creation detection

In Eclipse PDE, when looking for resource changes (using IResourceChangeEvent), how do I find out exactly when a project is created? Do I have access to the project (as an IProject) in this context?
Several parts to this answer:
When resources change, your listener gets an event. From that event you can get a delta describing the resources that were changes. You implement a visitor (passed to the delta with the accept() method) that actually implements your response to the change and controls how far down the delta you want to traverse by answering a boolean from its visit() method. You probably won't traverse too much since any new projects will be at the top of the delta. Once you've recognized that you're visiting a delta node representing a new project (you use flags() and getKind() to see whether or not it's a new project) you can take whatever action you'd like.
The other part of this answer is to warn you that often resource changes are batched, usually for performance reasons, so you might get notified of a new project being created after many files have been created into that project.
To augment the other answer that referenced resource change listeners...
Reliably detecting project creation is actually rather difficult. The issue is what you define as project creation. To the Eclipse resources layer, project creation is when a blank project is created (no metadata or files of any sort), but in a typical scenario you want to know when a particular kind of project is created.
This means that you cannot assume that when your code receives a project creation event, that you will be able to ask questions about that project. Project creation event may be delivered together with subsequent file events in a single batch or the events may trickle in separately.
Another consideration is that to Eclipse project creation is a number of different scenarios. It could be user running a project creation wizard, or importing existing project from disk, or importing from Git, or any number of other ways that a third party plugin may cause a project to be added to the workspace. Each of those scenarios will have slightly different way in which events are batched or trickle in.
The only solution is to look at file events as opposed to project events. Figure out what questions your listener needs to ask of the project, then figure out what files contain the answers and track those files. For instance, if you need to check for a nature and a classpath entry, monitor .project and .classpath files. Don't assume that the project is always in consistent state. It may not be if you are looking at it part way through a Git import.

Clearing commit message in Eclipse (while using Mylyn)

No matter what I do, I cannot seem to get Mylyn to stop inserting a commit message based on a Task even though that task is no longer active and closed. I've tried restarting the app, I've tried activating and inactivating tasks (which seems to simply change the commit message, although this is not consistent).
Switching to different perspectives also does not resolve the problem.
There must be some switch somewhere that I am neglecting to turn off. Please help me fix it!
Summary: Mylyn automatically creates meaningful commit messages based on the tasks you've worked on. To disable them see the Disabling section below.
Disabling: To disable Mylyn's commit messages go to Preferences -> Tasks -> Team and remove all content from the Commit Comment Template.
Details: Mylyn commit messages are automatically generated by using your context to determine which tasks where active when you changed the set of files you are about to commit. Thus, if you had the task implement the submit button active when you changed the file Submit.java then when you commit Submit.java the commit message will automatically be filled in with implement the submit button and a link to that task. Here's an example of a filled in commit message for the task improve upon associations prototype:
Many people find this more convenient than having to copy and paste from your task or type in a commit message yourself. Additionally, there are several advantages to having the commit message filled in by Mylyn, such as having traceability back to the task and having correct annotations. Here's an example of the traceability that having Mylyn-generated commit messages allows. You can see that the code annotations have links directly back to the tasks.
See this article for further details and advantages: Mastering Change-Sets
David Shepherd, Tasktop Technologies http://www.twitter.com/davidcshepherd
Go to Preferences -> Tasks -> Team : clear the Commit Comment Template