Enforcing Code Formatting Rules In Collaborative Java Development [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
We are a small team of developers working on a common Java/Maven project. We are using different versions of Eclipse, a common Mercurial repository (on Bitbucket) and three different operating systems. Since each developer has his/her personal preferences, we all use different coding styles and code formattings ("else" on the same line/on a different as the previous closing bracket, or using at most 80/100/120 charactes per line because some of use have bigger screens than others, etc.). As a result, when code is commited to the repository, it sometimes appears that there have been changes to a class, even though only the formatting was changed. This makes the real changes hard to trace.
So we were discussing solutions, and probably the best would be, if we would agree on a project standard and from now on, every code in the repo has to comply to this standard. If a collegue checks out code from the repo, a tool would convert it into his/her favourite format and just before committing it is converted back to the repo standard.
I was wondering if there is a tool for formatting code, that
could be run on any operating system
could be easily and extensively configured (such as the Eclipse formatter)
would allow for configurations to be shared
AND could be run, without the developer noticing that it is there.
OPTIONALLY could be run also from the console or as a separate task (eg. from maven)
OPTIONALLY is free
The point about automation is very important: I should easily integrate and ideally not bother the developer by forcing him/her to run a special script or press an extra button on each commit.
What I have done so far:
I added the following line to my .hgrc to create a hook.
[hooks]
precommit = python:.hg/perform_code_formatting.py:perform
and created a file called perform_code_formatting.py
import re,os,sys,mercurial
def perform(repo, **kwargs):
from subprocess import call
call(["ls", "-l"])
Of course, call will eventually replaced by a code formatting tool. But this approach is already flawed, because I am not sure what tool there is, that will run on any operating system and fulfill all the requirements mentioned above.
Tools
beautyj: runs on java, but not enough configuration options
indent/astyle: powerful tools, however, OS dependent
Jindent: not free
eclipse formatter: so far the best option. Could also be run from the console. However, since everybody has a different installation directory, some initial effort has to be made and the script/mercurial configuration has to be done on each working station individually.
My questions
Is there a tool, that fulfills all the requirements I listed? Does anybody have any experience with this "different formatting issue" and has come up with solutions / workflows / policies to deal with it?
Thank you in advance ;)

You can use Jalopy, an open source tool for code formatting. Probably your team can try this.
http://jalopy.sourceforge.net/

Related

how to protect sensitive data in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am looking for suggestions on tools/methods can be used to make sure , in java source code, sensitive information (like user password) is not accidentally been logged/printout .
You may specify some keywords for your critical variables and for their code behaviours.
After that, you need to install findbugs plug-in and you may create a custom bug detector.
Before you publish the app, run findbugs. It checks bugs and find them if exist.
Some examples are here :
http://lifelongprogrammer.blogspot.com.tr/2013/05/extending-findbugs-creating-our.html
http://www.danielschneller.com/2007/04/findbugs-writing-custom-detectors-part.html
http://findbugs.sourceforge.net/
Any other approach to protect your code, you have to obfusticate your code. (Not to printouts or logs, to protect your source code)
Good luck.
The do that you should be used some kind of Static Analysis tool. And check in their rule set.
For sure this kind of functionality is provided by Jtest (that is commercial tool). You can look on the FindBugs or even SonarQube.
For sure the tools will not be perfect and will not detect. The will try to be help full as much as possible.
But to 100% the best is the rule of four eyes. A code review by other developer might help. The Static Analysis tool should be treated as guardians for so called stupid mistake. A stupid mistake can be defined that is obvious when is pointed out. Everyone do them, so event having a review and general awareness in team there is chance to miss something.
From the code point of view, you want to be compartmentalising as much as reasonably possible. In static terms, the area of code that could access the sensitive information should be minimised. More importantly, scope of data should be minimised. In particular, no globals. No even logging. ("But logging is special!" No it isn't.) IIRC, "Growing Object-Oriented Software Guided by Tests" by Freeman and Pryce touches on what they call "auditing" rather static ad hoc loggers.
Everyone tests these days. A relevant testing technique is to use a known value for the sensitive data and mechanically search through files and network communications for that specific sequence.
If the format of the data is well defined, say credit card numbers, then this data can be scrubbed from the text output to log/audit files. It's not something that you would want to in anyway rely upon, but it could just save you.
There are no tools that can possibly automate that.
Instead, you need to have proper procedures in place for things like code reviews, and awareness among your programmers.
Just curious, how do you imagine such a tool working? How would it magically detect that something is sensitive and to what degree, and whether what's being done with it is or is not allowed?

Rewriting old/deprecated code java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
The company I work at has a piece of code they would like to rewrite. It uses Java/Java server faces. The problems with it are that it is old and uses depreciated code, was written in an IDE that is no longer available and doesn't work well with netbeans, and that it is kind of sloppy coding in the first place. No one really knows its structure and there is limited documentation.
Before beginning on the rewrite, we would like to find the structure of the old program and get a decent UML diagram. What tools would work the best in this situation? So far we have looked at one called Agilej.
Sorry if this is a little vague, I'm just a lowly intern an haven't been filled in on everything yet =p
You can use JArchitect, a pretty complete java static analysis tool
I'm not giving clickable hyperlinks as you should be able to find them easily through a web search and there may be more than 1 link that is useful for you
Sparx Systems Enterprise Architect has very powerful reverse engineering capabilities. Java (also compiled binary JAR) is in the list of supported languages.
I have used Enterprise Architect's reverse engineering features several years ago to help us understand and design modifications of legacy C++, QT code.
Enterprise Architect was able to automatically retrieve the class model. I then used the raw class model to drag/drop draw several other diagrams including only classes of my interest with level of detail I needed etc.
In the range of other static code analysis tools (e.g. the code flow visualization) I don't know which tool particularly supports Java well enough. Quick Google points e.g. to Coder Gears JArchitect. In the past project I have mentioned we used Doxygen's automatically generated documentation. Part of that were also some automatically generated graphviz dependency diagrams.
To clarify the design and visualize the flow (especially big legacy functions) I have found useful the Rapid Quality Systems Code Rocket flow visualizer
Once you get the basic facts at your hands through the various reverse engineering tools next step would be to go through them, annotate what is the unknown, what is doing what, basically apply some formal code review method (e.g. Fagan inspection or some of its derivatives).
(using evaluation versions of the various tools may be enough if you think ahead what are the required deliverables for your follow up actions. I guess the company is not planing to give you a >0$ budget)
The Agile Modeling site may have some good refactoring tips and some minimal UML mapping guidelines, start e.g. at Agile Legacy System Analysis and Integration Modeling

How to be proficient and efficient with NetBeans? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Dear people of stackoverflow,
I am learning to code Java and recently switched from programming in text editors and compiling in terminal windows to an actual IDE, NetBeans (I know, I'm a dinosaur. I inherited the habit from C++). The point is, I'm really lost.
I installed NetBeans because I saw some friends from school open the application and write about 50 lines of code in half the time it took me. I'm guessing they use some sort of templates or customized settings.
I would really appreciate it if you could shed some light in the subject, because I want to be as fast and efficient as possible when coding, especially when dealing with really long assignments.
This isn't something that can be quickly answered in this format.
The main advantages are:
Intellisense/Code completion (start typing code, press ctrl-space)
As-you-type error checking and reporting with automatic fixes in some places
Code generation (source->generate code)
Navigation (go to source, go to decleration, find references, etc).
Integrated debugging
Refactoring (renaming variables, methods and classes; introducing classes and methods; etc).
Try all of those things to get you started but there are many many more.
There's not going to be any one silver bullet; this is the accumulation of many small efficiencies, including keyboard shortcuts, advanced features, templates, etc.
You should take a closer look at what your friends do, and each time you see them doing something you don't, ask them about it. Better yet, each time you come across a task that intuitively seems like there should be a better way to do it (e.g. typing a similar pattern over and over), google around and see if there is a better way. There likely is!
For a more rigorous approach, of course, you can read the NetBeans manual end-to-end in order to get a comprehensive understanding of its features. I've never done that for my IDE of choice, though.
Ok, you have an IDE (that's good!). With it you can make a lot of shortcuts for developing. Here some tips:
You can create a project using a template by going File -> New Project -> <LANGUAGE> -> <TEMPLATE>. This template will autogenerate a basic source for what you want.
You can put breakpoints in any place only clicking in a line number.
You can debug by going to Debug -> Debug Project
You can auto-generate a double-clickable .jar by going to Build -> Clean and Build
You can run a console program directly in the IDE, by using Build -> Run Project
You can even install plugins for extending the IDE's functionality
There're lots of things I'm not telling you, cause it's a long list. You can see NetBeans Documentation for more info.

What is your recommended tool suite for internationalization of a complex multi-module java application? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I am currently doing an intership in a company and my task is to reevaluate the tool suite used to translate applications as it has become a problem internally. I've looked everywhere on the web and my conclusion is there is just no proper documented end to end workflow for this type of task, so I am asking the community to help me understand what they have seen in the field.
Our current flow looks like this:
java, properties files and resource bundles in the code
custom made tool to extract keys from code based on classes. bit clunky, as it uses class loading and therefore has many practical constraints
custom made web tool to do translations and handle code revisions
Here are some constraints and improvements we're looking towards:
we'd like for external translators to help us for additional languages our company cannot handle
we would like to add metadata to translation keys, such as validation flags, categorization data and description data, something not handled by properties files
we're going to have external translators and would wish to be able to use standards where possible to properly integrate with their tools
Here's what I've found on the web:
GNU Gettext's plural handling and context messages are nice. However, our existing code is written using keys and would not work with writing plain english messages in the code.
XLIFF provides means to have all the extra metadata we would like to add. However, all existing tools are either incomplete, buggy, or costly. Many of the tools add their own metadata which complicates working with XLIFF.
Pootle pretty much does what our custom made web tool does except fails to work on multiple Git branches.
Weblate, which is similar to Pootle, has the ability to work on multiple Git branches. However, updating a project with many languages and many translations takes time. It fails to meet our needs of continuous development.
So what is your recommended tool suite for internationalization of a complex multi-module java application?
Gettext (.po) is possible by a two stage key: key -> English, English as key. Disambiguation can be done with the original key. The original key can be preserved.
Gettext seems to be more extensively used than XLIFF - but I may be wrong meanwhile.
Web interfaces are fine - as a secondary tool. Translation agencies will complain when offered such a thing.
I cannot stress sufficiently that the delivery of the text is very important, to prevent that every translator has to do extra work. Almost the same text that might be united is such an example. A Translation Memory might give a fuzzy translation, but it is better to do processing by someone dedicated, before delivering things to translate. Also things like "Select from the menu 'Process thumbleweed'" and "Process thumbleweed" could well need a translation responsible person, to have coherent translations. XLIFF might offer more technicalities, but in general I think it is best to let an experienced developer ensure, develop this process. A common glossary of specific terms.
Also being able to have the application switch between showing a specific language and the key "[key]".
How about Tapiji? Not sure if it will meet all your requirements, but it is a time saver. If you are using Eclipse, or can use it, it might be worth a look. From the site:
The implemented editor is based on the Babel Messages Editor Resource-Bundle editor, which considers the whole Resource-Bundle as the object under modification instead of a single property file. Furthermore, a Resource-Bundle view adds rich functionality for browsing resources and directly comparing different languages. In parallel, RCP and RAP based stand-alone applications enable the translation of resources without the need of programming skills.
Weblate indeed is not the fastest tool for import (but there are many improvements in the upcoming 1.6 release), but there are several hints in the documentation how to improve this. Have you tried those?

Is there a macro recorder for Eclipse? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Is there a good Eclipse plugin for recording and playing back macros?
I've tried this one, but it didn't do me any good- it seemed like it wasn't ready for prime time.
I know about editor templates, but I'm looking for something that I can use to record my keystrokes and then apply multiple times against a wad of text.
This seems like a strange hole in an IDE. Am I missing some built-in facility for this?
I put something together over the last month or so that you may find useful. It has limitations since the Eclipse editor/commands weren't designed with macro support in mind, but I think it works reasonably well. I just posted Practical Macro at SourceForge a couple of days ago. It requires Eclipse 3.4.
Emacs+ Version 3.x adds keyboard macros (http://www.mulgasoft.com/emacsplus) to its feature set.
This seems like a strange hole in an IDE, am I missing some builtin facility for this?
This is a common problem. There are around four bugs opened in Eclipse tracker for this. Unfortunately you would probably see macros in Eclipse in v4.0 or later.
I've had success using AutoHotKey (Windows only, though).
There was a plug-in called Eclipse Monkey which allowed writing scripts that execute inside the IDE. It was terminated about a month ago due to lack of interest.
It is based on an older plug-in called Groovy Monkey. If you google it, you can still get it. The Aptana team has some more information on using it.
Note that this allows writing scripts, but not recording actions.
This is not an Eclipse-specific one, but it can be used there as well:
http://sikuli.org/
For simple text expansion on a Windows computer, you could use AutoHotkey. It's not as powerful as most macro tools, but since it's not tied to any one program, it can be used in other editors, emails, etc.
For example, if I type ";;ln" AutoHotkey instantly sends the keystrokes to delete this and replace it with "System.out.println();" with the cursor in between the parentheses.
Just for the record, there is another project called MacroSchmacro that does Eclipse macros, but it doesn't record many important things (like searching to navigate). It is also extremely slow.
Talking about Emacs, jEdit has a very strong macro facility. There are a lot of high quality macros and plug-ins, and several macros are already built it in. You can even add some logic using bean scripting, which is analogous to VBA. So, you can write very powerful stuff (any many people have done so).
jEdit is obviously a separate editor, but I think it's worth a shot. See http://www.jedit.org/

Categories