How to add logging to an existing Eclipse plugin to work in 2019-12? - eclipse

I'm trying to fix a problem in an Eclipse plugin at https://github.com/davidmichaelkarr/e4macs . The repo is a fork of the original application, which is now abandonware.
I have a couple problems with this, but I'm going to limit the scope of the question, hopefully making it simpler for someone to provide an answer.
The main problem I'm having with the plugin is that some operations (the operation "split-window-vertically" in particular) simply do nothing when I execute them. This didn't used to be the case. In some recent versions of Eclipse, this was working fine. It stopped working about 2019-09.
What I want to do first is add log statements that show it's at least getting to the handler method. I've concluded that I don't know how to add logging to an Eclipse plugin. The existing code for the plugin doesn't do any logging, so I don't have an example to go by. I've searched the net for documentation on how to do this, but all the articles I've found are either incomplete or just don't work.
I know of at least one handler that IS working properly. I added what I thought was the correct logging code to that handler, and it never appeared in the ".metadata/.log" file, so I assume that that was not the correct way to do logging.
I saw a reference to using "Activator.getDefault()", but that posting didn't say what the FQCN is, and all the completion offerings I found didn't have a "getDefault()" method.
Update:
I added something like the following to two classes:
private ILog logger = Platform.getLog(<ContainingClass>.class);
And then in a method in each of these classes, I used logger.info("message");
I ran this in my debug instance and tested the operations in both classes. The log messages appeared.
I then uninstalled the plugin from the main installation, then built the plugin in my RPC instance, then reinstalled the plugin in the main installation, from the local update site defined by the "...Update" project.
I then tested both operations, and I saw nothing in the log.
I may have solved my logging problem at this point, but I'm still having some sort of problem with deployment. I have a feeling that the process I went through to reinstall the changed plugin is not working.

To get an activator with a getDefault() method you must specify that the plugin contributes to the UI when you create it and that you want an Activator to be created. This should create an activator class extending AbstractUIPlugin and with a getDefault() static method.
In any plugin you can always use:
IStatus status = new Status(....);
ILog log = Platform.getLog(getClass());
log.log(status);
to log a status object.
Status has numerous constructors. A simple one just to log a message is:
new Status(IStatus.INFO, "plugin id", "message");
Platform is org.eclipse.core.runtime.Platform
Status is org.eclipse.core.runtime.Status

Related

hot swapped warning without making any changes (Spring tool suite 3.9)

When running my code in debug mode, I keep getting 2 error messages:
Could not delete [path_to]\productiondb.log. May be locked by another process
I don't know what process might be locking it. It comes when I make changes to the code while my Pivotal tc Server is running in debug mode, but it dosent seem to create a lot's of trouble. Sometimes however, I get this warning:
Also due to some changes. I usally just restart the server and move on. This isen't the real problem, the real problem is that I get these messages when I havent doen any changes. Somethimes it accures when I run a certen part of the code, other times i occurs when I open certen codes in sts, however, it doen't seem to stop at the same place twice.
I am suspecting that this has something to do with git. I am using git to change between versions and doing tests. So I am thinking that STS has some of the code in memory from before I changed branche with git, and isen't updating it before I run or open the file with that code. But I am rather new to both sts and git, and can't be certan that it would work that way. If it is, does anyone know how to update sts after I have changed branch? If it is not, does anyone know what might causing it?
If you run an app in debug mode, the Eclipse Debugger tells the application when code gets changed and tries to use the debug API to swap in the new code into the running application. This is especially useful if you debug your code, hit a breakpoint, step through the code, fit the issue, change the code, and press save. At that moment, the Eclipse compiler updates the class file and tells the running JVM to swap in the new code. If that succeeds, the debugger will jump back to the last stack frame and the execution of your app will continue with the beginning of the method that you entered. This allows you to directly continue to debug and step through the updated code without restarting the app.
While this is a great feature of the JVM, it is very limited in terms of what scope of changes to the classes the JVM can deal with while doing this hot-swap. It is usually limited to method implementations. So adding new methods, adding or deleting members of the class, etc, are not supported. As a result, the above screenshot will appear. It means that the JVM wasn't able to hot-swap the changed code and will continue to run with the previously loaded code instead of the changed one.

Process files crash unexpectedly

I am working on a project in Drools6. I have defined a few custom tasks using workitemhandler. When I create a new process file(*.bpmn file) and model it by adding my custom tasks and other inbuilt blocks, everything works fine in the beginning. But, if the complexity of the .bpmn flow diagram increase i.e, I add about 4-5 custom tasks, create sub-processes, add a few gateways etc, the program crashes and I will not be able to open my flow diagram again. It says there is a parse error.
I have tried reinstalling eclipse, but it still gives me the same error. I have not used exception handling in the java class of my custom tasks. Could this be why my program is crashing.
please guys, if anyone has come across a similar issue, let me know how you resolved it.
Thank you
it seems that for some reason your business process is corrupted and it cannot be opened by the editor. Do you have a previous version of your process? Try opening another process.
You can also try the web designer, which is usually more powerful than the eclipse one.
Regards

Groovy debugger out of sync

I am having a difficulty while attempting to debug some code in grails. It is difficult to put into text, so I have posted a screencast showing exactly what the problem is here. In short, while I am debugging the debugger starts jumping from place to place and not following the program logic I have in place. The only other similar question I have found is a year old, had no solution, and can be found here.
The best guess I have so far is that the debugger is displaying the text I have typed in, but is actually executing an older version of the class file which it has cached somewhere. Therefore, I tried:
cleaning the project
manually deleting all of the class files from the target folder and from the target-eclipse folder
Searching my entire hdd for additional files with similar names
removing my project from the workspace and re-adding it
closing and reopening the IDE
grails refresh-dependencies
Importing the project into a new IDE (I was using GGTS, I switched to IntelliJ)
None of those solutions had any effect. I realized that the issue was in a .groovy file, and I was writing almost pure Java, so I deleted the .groovy file, and re-created the class in a .java file. That solved my problem. Unfortunately I am having the problem again, and this time it is in a controller that heavily relies on the grails framework, so that solution is not an option. Other than also being in a .groovy file, another similarity is that the code breaks on an if statement.
My next steps:
Verify that the application is not executing the code I see by using print functions to monitor actual execution flow.
comment out the entire function and re-add functionality one line at a time to see if I can see what breaks it.
Delete the .groovy file, and re-create it as another .groovy file.
Any help is appreciated, and since I can't find any answers online I will continue to update this question as I learn more.
See my comment on the jira issue that you raised. You have found a problem with the groovy compiler and how it calculates line numbers. This is not a problem with executing the wrong class files or using a broken debugger. The debugger is doing exactly what it is expected to do. It is the compiler that is providing erroneous line number information.
The next step, as described in the issue, is to provide a simple project that recreates the bug. I tried to do so myself, but could not. So, please supply something that we can work with. Then we can notify the groovy compiler team.

Eclipse IDE debugging with code change

I am using Eclipse IDE for Java Developers
Version: Helios Service Release 1
Build id: 20100917-0705
In remote debugging Web app with tomcat 7.0.37, when I make some changes, even a line, the changes can not be made into the runtime, so I need to recompile and re-deploy the war application. Wast a lot of time. The message:
Hot code replace failed - Delete method not implemented
I do not understand the message.
Anyone know the secret on how to auto reflect the code change in debug mode? Thanks.
I've found that for hot code replacement to work the code being modified/replaced must be in the execution stack. So you can hot replace changes made to a method you've stopped in, but you can't hot replace changes to that method once you step out of that method... unless you first stop back in the method on a successive call to the method.
With the standard JVM (Oracle's), you can only modify existing methods. Both adding and deleting methods, and changing structure of class (moving methods, fields) are NOT supported. For that, go to JRebel!
One thing to notice is that changes to seemingly "normal code" inside some method will actually need for the java compiler to add or delete methods - and hence it will fail. This happens e.g. if you in an inner class accesses private fields in the outer class - the java compiler will need to add synthetic accessor-methods to the outer class to let the inner class access those fields - which hence will fail to Hot Code Replace. Also, if you remove some code accessing such fields, the java compiler wants to remove the corresponding synthetic accessor-method, which also will fail.
I think there is no way to reflect the code change in debug mode
Debug mode is to trace program flow and find if any issues or errors at particular piece of code....
it just points to line of code in eclipse, which is running in your tomcat, ie. code in eclipse is not used to run application the code u have installed or put in tomcat runs
hence your changes made in eclipse cant reflect in tomcat code

How to get Eclipselink samples to work: "student" and "mysports" samples

I've been trying to get the following Eclipselink samples to work, with less than 0% success:
A)
http://wiki.eclipse.org/EclipseLink/Examples/JPARS/Simple
B)
git://git.eclipse.org/gitroot/eclipselink/examples/mysports.git
Both samples are quite recent and should work "out of the box". My results:
A) starts and deploys on glassfish, but application is totally unresponsive
B) does not deploy, since glassfish does not find the data-source mentioned in the persistence xml's: java:global/mysports
For both I tried to get information on how they are supposed to work, but after two days of searching for documentation, I can safely state: there is literally NOTHING documented.
For A) I am totally clueless, there is nothing to configure for this sample, but the provided URLs for interacting with the REST service always return with 404 and no log or error message whatsoever.
For B) Beside the broken data source (I guess my fault), I tried setting default JDBC data-sources, to see if at least the REST service itself works: it looks dead, I get exceptions when opening the sample JSF pages (the reference variables inside the pages all resolve to NULL).
Anybody ever tried to actually run these samples? I am totally frustrated after many hours of being far away to anything testable...
Maybe some questions as a starting point:
- How does the JPA-RS get registered in the appserver? how do I tell if it was at all? And which URL it maps to?
- How does this magic "java:global/mysports" data source work?
- The maven configuration acts funny, I couldn't get any of the two samples to properly debug (no breakpoints were hit at any point in time). Any ideas?
If you are using Glassfish earlier than Glassfish 4.0 (http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/) you will need to download newer version of EclipseLink 2.4.2 binaries from http://www.eclipse.org/eclipselink/downloads/nightly.php (2.4.2 Nightly Build Results) and replace following files under $GLASSFISH_HOME/glassfish/modules with corresponding jars you downloaded above:
org.eclipse.persistence.antlr.jar
org.eclipse.persistence.jpa.jar
org.eclipse.persistence.asm.jar
org.eclipse.persistence.jpa.modelgen.jar
org.eclipse.persistence.core.jar
org.eclipse.persistence.oracle.jar
javax.persistence.jar
org.eclipse.persistence.dbws.jar
org.eclipse.persistence.jpa.jpql.jar
Make sure you clear Glassfish osgi cache by removing the $GLASSFISH_HOME\glassfish\domains\your_domain\osgi-cache directory after you replaced the bundles listed above, and before you restart the Glassfish.
These are both advanced examples, unless you are looking for these specific features, I would recommend starting out with simpler examples.
There are many EclipseLink JPA examples documented here,
http://wiki.eclipse.org/EclipseLink/Examples
Most of the examples are still in SVN here,
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/
For documentation on the JPA-RS examples see,
http://wiki.eclipse.org/EclipseLink/Examples/JPA#JPA-RS
Try adding question to the example's wiki discussion page if you are having specific problems.
The MySports example is very advanced. Unless you are looking for extendable entities and multi-tenancy, I would not recommend starting with this example.
To add to James' comments, if you are specifically interested in JPA-RS, perhaps these additional comments will help. I also recommend asking questions on the wiki discussion page.
JPA-RS gets registered in the appserver by the existence of the org.eclipse.persistence.jpars_[version].jar in the WEB-INF/lib directory. This jar contains the web-fragment.xml which is what defines the JPA-RS service. You will know if it was deployed if the following URL pattern returns persistence unit metadata:
http://<server>:<port>/<applicationName>/persistence
Some additional documentation for JPA-RS:
- http://www.eclipse.org/eclipselink/documentation/2.4/solutions/restful_jpa001.htm
- wiki.eclipse.org/EclipseLink/Development/2.4.0/JPA-RS/REST-API
One thing that will help you debug is to view the Glassfish server log. If you are running in Eclipse, right click on your Glassfish server in the Server view, go to Glassfish->View Log File, which will open the server log in your console view. This will show you what is happening with deployment, and will alert you to any errors. Also be sure to double check your URLs.
Ok, ladies. A friend of mine had the brilliant idea of forcing ALL logging on eclipselink-jpars library (by setting this value in every single file we could think of) and indeed we found an exception that is FOR NO GOOD REASON hidden in the lowest log level:
javax.xml.bind.PropertyException: name: eclipselink.json.include-root value: false
Whatever that means, but that again convinces me that I will not use this feature/lib for the time being. An exception should be visible on all log levels, especially if I go down to FINE (as stated in the samples!)! I almost lost three days just because of this.