Remove all unused code based off of a single Main method - java

Do you know any way to find (un)used code from the perspective of a specific main method (or what IntelliJ calls an entry point)?
The background is that we have a big java project in which we have custom code for several clients. Sometimes we give clients the current state of the project in source form but would obviously want to remove the parts which only concern other clients. We have a Main file for each client so it should be possible to follow imports from there to find exactly the files relevant to each client.
I was hoping to be able to run intellij's code inspection on a single entry point but was unable to find anything. I'm open to any solution though.

You could remove all other entry points and run intellij's code inspection again to detect unused code. Now that you have only one entry point it should be able to tell you what code is unused. With that knowledge you can revert you changes and remove this code.
Hope that helps.

Related

NetBeans save edited .jar

I am currently using a library for "Notify My Android". The library is using an outdated URL so i tried to change it. I attached the source file and now I can edit the code. Before attaching the source file it just said "compiled code". But when i save it it does not seem to save the changes. It is still using the old URL. Also the change I made is underlined in blue. I hope somebody knows how to make the .jar to accept my changes.
Thanks in advance
it's highly discouraged to modify jars you depend on simply because if you ever want to upgrade versions you'd need to modify the new jar you are looking for.
In those situations you have these options:
if it is an open source project, contribute to the project and correct the URL
try and set the property from your code (this may not be possible in certain situations)
try and extend the class you're trying to use and set the URL on the property you need (like the previous one, it may not be possible to do this)
this should be your last resource: create your own project (from the original jar), make the changes you require, package it up and add it to you app.

Eclipse custom builder: Identifying and cleaning generated files

I am creating a plugin for Eclipse, which contains tools for creating a custom type of project. These projects have a custom nature and builder. My builder (implements IncrementalProjectBuilder) takes a single input file, and generates a few (usually between 3 and 5) output files. When I run Clean Project, I need to remove the files the builder has previously generated.
Problem 1: The names of the generated files are not known exactly, but I do know the sort of files I expect to find (e.g. I know the extensions, and partial file names).
Problem 2: The user may add their own files to the project, which should not be affected by my build / clean steps.
My initial attempt was naive: remove every file except from the input file. This works, but has obvious problems.
My second attempt was better: I came up with a list of possible file names that may be generated, see if any of them exist and remove them.
By only knowing partial file names and matching them, I may inadvertently delete a user's file. E.g. I know I will generate a file called *_file.py. If the file I generate is called abc_file.py and the user has added their own xyz_file.py, I want to clean (remove) abc_file.py but leave xyz_file.py untouched.
The program which generates the output files from the input is constantly changing, and I don't want to rely on a concrete list of files that would need constant maintenance.
So, my question comes down to this. What methods exist for identifying the files generated by my custom builder, so I can remove them during a clean?
I've spent a couple of days Googling this one with not much to show for it. I am vaguely aware of a file system watcher in Java (Java7 WatchService?), but I don't know if that's the best solution to this problem.
Any information, advice or ideas appreciated.
One brute force approach would be to compare the project before and after the other program is invoked to get the list of files that were created/generated. Of course, it would be ideal if that program could somehow tell you which files it created. Once you have that list, you could iterate over those files as IFile's as use the setDerived() method to mark them as not being source files. When it comes time to clean the directory, you could use the derived setting to decide which files can be deleted.

when is debugging work for java

I am new to java.I have a doubt that only ".java" files supports debugging whereas the
".class" files does not supports debugging in IDE.
Can you please suggest an answer?
Most IDE's (I know eclipse does, and pretty sure IntelliJ and netbeans do) will allow you to step through the processing of a class file, however they won't let you see what code is being executed, however you can see the variables in use. However to get there you will need to add a breakpoint in your code, and step down to the relevant class file. If you can attach the source, it will let you see the code being executed, as well as add a breakpoint directly in the file in question.

How do I get my Etherpad changes to show up?

I change files like /etherpad/trunk/infrastructure/ace/www/ace2_inner.js and then run /etherpad/trunk/etherpad/rebuildjar.sh and yet when I run it again everything looks the same. Is there a trick I'm missing?
I've also tried running rebuildjar.sh with clearcache to no avail.
Look at bin/build.sh and track down which scripts are called directly and which scripts are called via subscripts. The whole thing is a mess :/
ace2_inner is perhaps one of the autogenerated .js files? What you need to do is read the first 10-20 lines of every source code file before you edit it, to make sure you're not editing an autogenerated file.
If you don't know the structure, then use bin/build.sh every time until you learn how to handle the source code. (This advice isn't actually etherpad-specific :)
And then make sure you've STOPPED all etherpad servers before starting up a new one.
Always clear the browser cache properly after changing the etherpad files. Otherwise none of your changes will show up.

How to avoid no main class and no class def found error using DropBox and Eclipse for Java

I use Eclipse to write Java code and use DropBox to sync my code with others' across our multiple computers. Most of the time, everything works as expected: if anyone makes a change on either end, the change is saved and when the other person refreshes the Eclipse workspace, the changes come through and can be viewed and run successfully.
Sometimes, one of several errors arises. Sometimes Eclipse says it cannot find a main class and sometimes it says it could not find the class itself. Sometimes it will not report an error but for some reason will not actually update the .class file and therefore run an old version even though the compiler displays the new source code and that saves. I've then noticed that if I manually copy the code into a new .java file elsewhere in the file system and then compile it, it works fine, but for some reason it refuses to regenerate the .class file and I have to delete it manually and replace it with the one generated in the other project--then it works. But for solving the other problems everything needs to be manually copied, deleted, and re-pasted....
[The actual errors include NoClassDefFoundError, UnsupportedClassVersionError, and some other error related to not having a main class.]
I realize that the description here is somewhat vague, but unfortunately I'm not entirely sure what's going on. I hope I'm just missing some basic fact that would help solve all these problems.
Thanks!
I'm sure you will see issues using Dropbox for sharing your source.
Eclipse does not know what Dropbox is doing whilst it's uploading and downloading updates and their activities will certainly not be synchronised. At arbitrary points in time when Eclipse tries to do builds etc. it will find unexpected activity going on, maybe even partially downloaded source files which might explain the specific errors you are seeing.
You're trying to do something more complex than sharing photos or documents. The advice I would give is to use a source control system like git or subversion for source code sharing and control. You can then make use of plugins for Eclipse that are designed to integrate these systems in an easy to use way. There's a learning curve there, but the skills will serve you well.
You can use online versions of these solutions like github and unfuddle if you want to consume sharing, backup and version control of source as a service like you do with Dropbox. They're free, too.
Subversion, Git and all version control software solve all of these problems for you.
Dropbox is not really an adapted system for sharing code. What you should do is set up a SVN, and commit only the source files. This way, you won't have these kind of errors.
Dropbox does have versioning (you can restore old versions of a file), and doesn't seem to be a horrible solution for the problem. I keep my Eclipse repository on Dropbox so it is available on any computer; but since I only use it myself, I haven't encountered your problems.
There is one case I can absolutely see you running into problems--it's if your class files are stored in the dropbox as well. This would just screw everything up. Make sure you specify a location on your local hard-drive for all build artifacts (classes, jars, ...) and that the only thing on your dropbox is the .java sources.
In fact, I suggest you don't keep your eclipse project in your dropbox, just create your eclipse project and point it to the java files in your dropbox.
If this doesn't work for you, go with what other people here said and set up a SVN repository somewhere, it's easier than you would think.
Oh, another possible problem--dates! You may want to make sure the date on your java files isn't jumping forwards and backwards (as might happen if one of your developers were in another time zone). In this case, Eclipse may prefer not to re-compile your file.
Also, instead of the copy/etc procedure you are currently going through, try forcing a project clean.
Response to request for more info:
When you start Eclipse, select/create a workspace that is NOT on your dropbox. The best place is probably off your home directory. If you have already specified a default workspace, there should be a switch workspace item in the file menu.
Create your project. select "Create project from existing source" and specify the source files in your dropbox. I think you want "create separate folders for source and class files" to keep your class files out of your dropbox. If you see anything saying "Copy files into your workspace, say "no".
This should give you a valid, working project. I hope you don't see those problems any more.
One more thing may help--and this may work on your existing project--without the above procedure...
Whenever you refresh your files (f5) to load in changes from the dropbox, select the Project/clean menu and select the project. This should delete all the class files and rebuild them.
If your classfiles are shared on the dropbox, this could still have strange consequences on other people with eclipse open, so I really do suggest rebuilding your workspace as I said above.
How to avoid no main class
Provide one. That issue has nothing to do with DropBox

Categories

Resources