Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am looking for a tool which verifies that a set of java source files (not the byte code) follows a set of predefined rules.
For example, if we have a predefined rule which says any method contains an assertion, the method name must have the suffix "xxxTest". In order to keep the code clean, all the developers must follow these rules/conventions. Of course code reviewing would solve this problem however there should be a way to automate these simple code style checking.
In addition, the developer should be able to run this tool locally on his change-set before committing.
To solve this problem, I started to write my own verifier using the javaparser which will be executed using a gradle task. However in order to avoid re-inventing the wheel, I was wondering if there are existing tools which allows me to do this or even close (may be I can contribute to it)!
UPDATE:
I am aware of CheckStyle and Sonar for static analysis. However I need to run this tool on the CI (ex, Jenkins) as part of the build. So the build should fail if the convention is not applied.
You can test JArchitect and its powerful query language CQLinq.
For your specific need you can execute the folowing query
You can easily build this tool combined JavaParser and java-symbol-solver. The first one produces an AST of your source code and with the second one you can solve symbols (for example finding all the ancestors of a given class).
If your rules are simple enough you could probably get away just using JavaParser. That would be nice because JavaParser has very few dependencies and it is very mature and established.
Use a tool like Checkstyle.
It either allows you to configure a rule-set for your styleguide or you can write an extension.
There is also extensive support to integrate it into IDEs and build process.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Problem:
I have a large, old, disorganized java project from the early 2000s.
The project is built using ant.
There is no dependency management, everything is handled by storing jars locally.
The compile and package targets for the build script are very broad, and mostly just compile and subsequently package the entire project, shuffling environment specific properties files around as needed.
At some point during the lifespan of the project, a few separate build targets were introduced, to enable a web interface for admin tooling and the like.
However, because there is no dependency management, and because the buildscript isn't very selective, the current process is packaging up the entire web application and deploying it along with the admin tools, with a very minimal list of differences between the two.
I am currently embarking on attempting to bring sanity to the codebase by deprecating and re-factoring the ant buildfiles and introducing build/deployment automation by way of CI tooling.
As a part of the next phase of this effort, I would like to attempt to refactor the project structure and the buildfiles to only package what it needs to package in the war files for the admin tools and production web-application, respectively, and hopefully, only compile one pass instead of several.
To solve this problem it seems likely that I will need to build a list of dependencies for a given JSP, or at least a list of java classes. Manually doing legwork to track some stuff down is hardly beneath me, but the scope of the project is large enough that without some automated assistance I have no hope of ever completing the task in a reasonable timeframe.
I have yet to find a solution to this that doesn't involve a hefty software license or a project that is already using Maven.
Given that Eclipse can take an arbitrary method from an arbitrary file of source in this project and find me the resource on the file-system that corresponds, it seems as though this must not be an unsolvable engineering quandary -
Does there exist a free (as in beer, ideally also as in software) solution to generating a dependency graph (or similar) for a project like this?
Failing that, can the good citizens of stack overflow suggest a different approach to my problem I may not have considered?
I see that this question is considered a duplicate.
In hopes of boosting someone's future google search results:
jdeps will recursively print dependencies for a given class name, class file, or jar to stdout, is probably the least cost solution for solving this exact problem, and comes pre-packaged with JDK 8 and above.
I found that buried 10 answers deep on a 4 year old question that was asked prior to the existence of the utility in question, on an answer that received 0 upvotes, so, I feel re-posting it here may be of potential value for future users of the site.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I have been vetting the process of Code Generators online. I started my search with a promising but not popular Eclipse plugin called FastCode (http://www.3pintech.com/products/fast-code/).
It had a higher learning curve with a tradeoff for flexibility. That was find for me because a lot of our application follows a certain standard that I would need to maintain with the generated code. Unfortunately it was very buggy and I think it may be a dead project.
On to SpringFuse. This looked promising, but I have a few problem with it.
1) We are far into our project development lifecycle and I only need to use it for a subset of new tables in our MYSql database. Springfuse seems to take a "let us generate your entire application" approach.
2) We don't use Hibernate and SpringFuse seems to be tied into this
3) It doesn't seem to be that configurable
What I would like to do is start with a database table, and from there generate a corresponding POJO, DAO for CRUD operations, Service Layer to call the DAO and a Unit test for testing each layer. We have a standard pattern for creating our DAO layer that I will be using.
I am considering using Perl or maybe another templating system to do this but that will involve a significant amount of coding on my part. I was wondering if the SO community knows of any good technologies to use here.
I actually think an online sevice would be awesome here, something like the awesome JSON2POJO, but I don't think it exists.
After some research, the solution that worked best for me was to use the FreeMarker Java Template Engine and write my own code generation system. Using regular expressions to parse our database file and converting some of our existing code into FreeMarker templates only took a couple of days and yielded a system that is going to save us a lot of time.
I recommend this approach to users who are in a similar spot for highly customized Enterprise Applications. Most of the rendered code is not fit for primetime, but the base boilerplate code I'm generating results in huge time-savings.
FreeMarker's templating system is very similar to other technologies like JSTL and it throws very descriptive error messages so designing the templates was very simple.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I've been trying to find a Java linter capable of running on the CLI that is separate from Eclipse that I can call as a commit hook for git or from our automated build script. Does such a thing exist?
Ideally it needs to check for unused imports and variables, that style guidelines are followed, exceptions are used properly, etc. Though some subset of those features would be better that what we have now - nothing!
SpotBugs (earlier Findbugs) for finding existing bugs. VERY GOOD!
PMD for finding patterns that can lead to bugs (e.g. unused variables)
Checkstyle to enforce coding standards and conventions (e.g. whitespace, Javadoc)
Error Prone hooks right into your application's compile step
clang-format supports java and may be available on your system already
All these tools have some overlapping rules. There are many other similar tools, but these are the most popular and supported.
Also, check out Sonar, which combines many of the other tools and provides a nice view for it too.
rules from Checkstyle, FindBugs, PMD, Clirr, fb-contrib.
Not sure exactly how to add it to a post-commit hook, but http://docs.codehaus.org/display/SONAR/Analyzing+with+Maven might be a good starting point (especially if you're using maven).
Maybe even consider using one of the approaches listed in http://docs.codehaus.org/display/SONAR/Continuous+Integration since it seems that you might be trying to look for better tooling for your whole team ("Though some subset of those features would be better that what we have now - nothing!"
This is EXACTLY what I am working on: a tool CLI-friendly to be used to check the quality of Java code. It has also an interactive modality. You can run single queries (to check for single warnings) or all queries together.
The tools is in its early stage but I am working on it almost every day. It is available here:
https://github.com/ftomassetti/effectivejava
Please let me know what do you think about it and feel free to ask questions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I am looking for a library/API that has some out of the box data and control dependence analyses for Java programs. This would be a static analysis on the control flow graph (CFG) of the given program to compute data dependences and control dependences. I would like to avoid reimplementing these techniques/algorithms if they have already been done. An inter-procedural analysis would be great, but I could work with a library that does an intra-procedural one as well.
Any suggestions would be greatly appreciated.
Edit: One thing I have found is jChord, but I haven't been able to determine yet if it actually has any of the out of the box functionality that I am looking for or if I would have to implement it myself.
Another possibility is the joeq library which seems to at least have the infrastructure necessary for doing this, but the documentation (or lack thereof) is making it difficult for me to tell what it is actually capable of.
I am sure Eclipse does plenty of data flow analysis underneath the hood, but I haven't seen anything yet that is public facing. Anyone know of the Eclipse API having stuff like this?
Try http://www.sable.mcgill.ca/soot/
OP says he is interested in non-open source systems too.
Our DMS Software Reengineering Toolkit with its Java Front End can parse Java source code in all dialects 1.4-1.7, producing full ASTs, build symbol tables, compute types of expressions, and determine control and dataflows within methods, including explicity control dependence as requested by OP.
Usually folks that are interested in advanced analyses have something other than the raw analysis in mind. DMS is an ecosystem of program analysis and transformation tools, that can be used to leverage such analyses into diagnostics about the existing code in terms of source location (drawn directly from the ASTs) or source code (prettyprinted from a subtree of interest), or to generate new code fragments (by assembling ASTs and prettyprinting them) or finally by actually changing the original code (by modifying the ASTs using procedural modifications or better yet, source-to-source transformation, and prettyprinting the modified AST).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I know this question has been asked many times, but here are my specific needs. The obfuscator needs to come in a form of a java library, so I can make an Ant task in order to automate the build process. IE7, 8, Firefox and Chrome must be able to interpret the resulting js very fast (original js file is pretty big - 18k lines of code). If none exist which satisfy these requirements I'm willing to consider a commercial solution.
Some options:
YUI compressor. See Julien Lecomte's blog for example use from Ant.
LCA Soft provide a free Ant task interface to the Dojo Toolkit compressor.
Jawr - Ant task.
(I've not used Jawr or Dojo, so can't comment on which is best.)
Google's closure-compiler is another alternative.
There is a newer free option for Javascript Obfuscation - Roquson. They provide completely free Javascript Obfuscation with additional features like Variable renaming, Domain Locking and Expiration Date.
Check it out here: http://roquson.com
I still believe that jsutility.pjoneil.net provides the best compression of any program available except for gzip. It's obfuscation support is avoids most of the problems with obfuscation. It also now support batch operations.