The Holy Java

Building the right thing, building it right, fast

Archive for the ‘eclipse’ Category

Tip: How to Easily Customize PMD Rules in Eclipse

Posted by Jakub Holý on August 21, 2012

The default PMD rules are little too strict for me (especially when starting on a legacy project) so I need to adjust them, usually by decreasing priority to warning. It’s however quite difficult to find the rule responsible for an error message unless you know how to do it. The answer is the PMD Violations Overview view, which lists the rule names (such as “ConstructorCallsOverridableMethod”, as opposed to the error message such as “Overridable method ‘addSummaryPeriod’ called during object construction”).

Read the rest of this entry »

Posted in eclipse, Tools | Tagged: , | 1 Comment »

Most interesting links of December

Posted by Jakub Holý on December 31, 2011

Recommended Readings

  • The Netflix Chaos Monkey – how to test your preparedness for dealing with a system failure so that you won’t experience nasty wakeup when something really fails in Sunday 3 am? Release a wild, armed monkey into your datacenter. Watch carefuly what happens as it randoly kills your instances. This is exactly what Netflix does with their with their cloud infrastructure – also a great inspiration for my recent project. Do you need to be always available? Than consider employing the chaos monkey – or a whole army of monkeys!
    (PS: There is also a post with a picture of the scary monky.)

Links to Keep

  • BDD: Write specifications, not scripts (from the Concordion site) – relatively brief yet very enriching practical description of how to do behavior-driven development a.k.a. Specification by Example right, the key point here being “Write specifications, not scripts.” It says why not (for scripts overspecify -> are brittle, specs should be stable) and how to do it (decouple the stable spec and the volatile system via fixture code, expose minimal stuff to the spec, perhaps evolve a DSL between the fixture and the system). It also lists common “smells” of BDD done wrong. If it still isn’t clear to you, read the Script to Specification Makeover example (or perhaps read it anyway). BTW, Concordion is a new tool for doing BDD based on JUnit and HTML, which was created as a response to the weaknesses of Fit[Nesse], i.e. exactly the tendency to do scripting instead of specifications. It looks very promissing to me!

SW Utilities

  • (Linux/Mac) Autojump – superfast navigation between favorite directories in the command line (via Jake McCrary) – it keeps track of how much time you spend in each directory and when you execute j <substring of directory path/name>, it jumps into the most frequently used one matching the substring. It awesome! (You can also run jumpstat to see the statistics.)
  • (Linux) Tcpkill – service/network outage testing (via Jake McCrary) – kill connections to or from a particular host, network, port, or combination of all – useful e.g. when you want to test that your software is resilient to the outage of a particular service or server – less brutal than actually killing the database etc. instances. We need to test that our application recoveres properly when one of our MongoDB nodes dies so this may be quite useful.
  • Manik Hot Deploy Plugin for Maven Projects (v1.0.2 in 5/2011; older version in the Marketplace) – plugin that can do hot and incremental deployment to any app server (simply by copying to its hotdeploy directory or the directory of an installed webapp) whenever you run mvn install or automatically whenever sources change, multi-module support

Clojure Corner

  • Jake McCrary: Continuous Testing With Clojure and Expectations – continuous test runner lein-autoexpect for Clojure tests written using the library expectations by Jay Field.
  • Jake McCrary: Quickly Starting a Powerful Clojure REPL – Clojure REPL only two steps away: 1) Run Emacs, 2) Execute M-x clojure-swank (no more need to open an existing Leinigen project) – the trick is to install the Leinigen plugin swank-clojure and use Jake’s elisp function clojure-swank that automatically starts the swank-clojure server. (I had to hack the function for the clojure-swank output contained “null” instead of “localhost”, likely due to incorrect DNS setup.)

Posted in eclipse, General, Testing, Top links of month | Tagged: , , , , , , , | Comments Off

Most interesting links of October

Posted by Jakub Holý on October 31, 2011

Recommended Readings

  • Steve Yegge’s Execution in the Kingdom of Nouns – I guess you’ve already read this one but if not – it is a well-written and amusing post about why not having functions as first class citizens in Java causes developers to suffer. Highly recommended.
  • Reply to Comparing Java Web Frameworks – a very nice and objective response to a recent blog summarizing a JavaOne presentation about the “top 4″ web frameworks. The author argues that based on number of resources such as job trends, StackOverflow questions etc. (however data from each of them on its own is biased in a way) JSF is a very popular framework – and rightly so for even though JSF 1 sucked, JSF 2 is really good (and still improving). Interesting links too (such as What’s new in JSF 2.2?). Corresponds to my belief that GWT and JSF are some of the best frameworks available.
  • Using @Nullable – use javax.annotation.Nullable with Guava’s checkNotNull to fail fast when an unexpected null appeares in method arguments
  • JavaOne 2011: Migrating Spring Applications to Java EE 6 (slides) – nice (and visually attractive) comparison of JavaEE and Spring and proposal of a migration path. It’s fun and worthy to see.
  • xUnitPatterns – one of the elementary sources that anybody interested in testing should read through. Not only it explains all the basic concepts (mocks, stubs, fakes,…) but also many pitfalls to avoid (various test smells such as fragile tests due to Data Sensitivity, Behavior Sensitivity, Overspecified Software [due to mocks] etc.), various strategies (such as for fixture setup), and general testing principles. The materials on the site were turned into the book xUnit Test Patterns: Refactoring Test Code (2007), which is more up-to-date and thus a better source.
  • Eclipse tip: Automatically insert at correct position: Semicolon, Braces – in “while(|)” type “true {” to get “while(true) {|” i.e. the ‘{‘ is moved to the end where it belongs, the same works for ‘;’
  • Google Test Analytics – Now in Open Source – introduces Google’s Attributes-Components-Capabilities (ACC) application intended to replace laborous and write&forget test plans with something much more usable and quicker to set up, it’s both a methodology for determining what needs to be tested and a tool for doing so and tracking the progress and high-risk areas (based not just on estimates but also actual data such as test coverage and bug count). The article is a good and brief introduction, you may also want to check a live hosted version and a little more detailed explanation on the project’s wiki.
  • JSF and Facelets: build-time vs. render-time (component) tags (2007) – avoid mixing them incorrectly
  • StackOverflow: What are the main disadvantages of Java Server Faces 2.0? Answer: The negative image of JSF comes from 1.x, JSF 2 is very good (and 2.2 is expected to be just perfect :-)). Nice summary and JSF history review.
  • Ola Bini: JavaScript in the small – best practices for projects using partly JavaScript – the module pattern (code in the body of an immediately executed function not to polute the global var namespace), handling module dependencies with st. like RequireJS, keeping JS out of HTML, functions generating functions for more readable code, use of many anonymous functions e.g. as a kind of named parameters, testing, open questions.

Talks

  • Kent Beck’s JavaZone talk Software G Forces: The Effects of Acceleration is absolutely worth the 1h time. Kent describes how the development process, practices and partly the whole organization have to change as you go from annual to monthly to weekly, daily, hourly deployments. What is a best practice for one of these speeds becomes an impediment for another one – so know where you are. You can get an older version of the slides and there is also a detailed summary of the talk from another event.
  • Rich Hickey: Simple Made Easy - Rich, the author of Clojure, argues very well that we should primarily care for our tools, constructs and artifacts to be “simple”, i.e. with minimal complexity, rather than “easy” i.e. not far from our current understanding and skill set. Simple means minimal interleaving – one concept, one task, one role, minimal mixing of who, what, how, when, where, why. While easy tools may make us start faster, only simplicity will make it possible to keep going fast because (growing) comlexity is the main cause of slowness.  And simplicity is a choice – we can create the same programs we do today with the tools of complexity with drastically simpler tools. Rich of course explains what, according to him, are complex tools and their simple(r) alternatives – see below. The start of the 1h talk is little slow but it is worth the time. I agree with him that we should much more thing about the simplicity/complexity of the things we use and create rather than easiness (think ORM).
    Read also Uncle Bob’s affirmative reaction (“All too often we do what’s easy, at the expense of what’s simple. And so we make a mess. [...] doing what is simple as opposed to what is easy is one of the defining characteristics of a software craftsman.”).

Random Notes from Rich’s Simple Made Easy Talk:

There are also better notes by Alex Baranosky and you may want to check a follow-up discussion with some Rich’s answers.

The complex vs. simple toolkit (around 0:31):

COMPLEXITY                             SIMPLICITY
State, objects                            Values
Methods                                   Functions, namespaces
vars                                          Managed refs
Inheritance, switch, matching  Polymorphism a la carte
Syntax                                      Data
Imperative loops, fold              Set functions
Actors                                      Queues
ORM                                         Declarative data manipulation
Conditionals                             Rules
Inconsistency                            Consistency

What each of the complexity constructs mixes (complects) together

CONSTRUCT                        COMPLECTS (MIXES)
State, objects – everything that touches it (for state complects time and value)
Methods – function and state, namespaces (2 classes, same m. name)
Syntax – Meaning, order
Inheritance – Types (ancestors, child)
Switch/matching – Multiple who/what pairs (1.decide who, 2.do what ?)
var(iable)s – Value, time
Imperative loops, fold – what/how (fold – order)
Actors – what/who
ORM – OMG :-)
Conditionals – Why, rest of program (rules what program does are intertw. with the structure and order of the program, distributed all over it)

HE SIMPLICITY TOOLKIT (around 0:44)
CONSTRUCT            GET IT IVA…
Values – Final, persistent collections
Functions – a.k.a. stateless methods
Namespaces – Language support
Data – Maps, arrays, sets, XML, JSON etc.
Polymorphism a la carte – Protocols, Haskell type classes
Managed refs – Clojure/Haskell refs (compose time and value , not mix)
Set functions – Libraries
Queues – Libraries
Declarative data manipulation – SQL/LINQ/Datalog
Rules – Libraries, Prolog
Consistency – Transactions, values

True abstraction isn’t hiding complexity but drawing things away – along one of the dimensions of who, what, when, where, why [policy&rules of the app.], how.
Abstraction => there are things I don’t need – and don’t want – to know.
Why – do explore rules and declarative logic systems.
When, where – when obj. A communicates with obj. B. => put a queue in between them so that A doesn’t need to know where B is; you should use Qs extensively.

Links to Keep

  • Incredibly Useful CSS Snippets –  “a list of CSS snippets that will help you minimize headaches, frustration and save your time while writing css” – few float resets, targetting specific browsers & browser hacks, cross-rowser transparency/min height/drop shadow, Google Font API, link styled by file type,

DevOps: Tools and libraries for system monitoring and (time series) data plotting

  • Hyperic SIGAR API – open-source library that unifies collection of system-related metrics such as memory, CPU load, processes, file system metrics across most common operating systems
  • rrd4j – Java clone of the famous RRDTool, which stores, aggregates and plots time-series data (RRD = round-robin database, i.e. keeps only a given number of samples and thus has a fixed size)
  • JRDS “is performance collector, much like cacti or munins”, uses rrd4j. The documentation could be better and it seems to be just a one man project but it might be interesting to look at it.

Clojure Corner

  • Alex Miller: Real world Clojure – a summary of experiences with using Clojure in enterprise data integration and analytics products at Revelytix, since early 2011 with a team of 5-10 devs. Some observations: Clojure code is 1-2 order of magnitude smaller than Java. It might take more time to learn than Java but not much. Clojure tooling is acceptable, Emacs is still the best. Debugging tools are unsurprisingly quite inferior to those for Java. Java profiling tools work but it may be hard to interpret the results. “[..]  I’ve come to appreciate the data-centric approach to building software.” Performance has been generally good so far.
  • Article series Real World Clojure at World Singles – the series focuses on various aspects of using Clojure and how it was used to solve particular problems at a large dating site that starting to migrate to it in 2010. Very interesting. F. ex. XML generation, multi-environment configuration, tooling (“If Eclipse is your drug of choice, CCW [Counter ClockWise] will be a good way to work with Clojure.”, “Clojure tooling is still pretty young [..]  – but given how much simpler Clojure is than most languages, you may not miss various features as much as you might expect!”)
  • StackOverflow: Comparing Clojure books – Programming Clojure, Clojure in Action, The Joy of Clojure, Practical Clojure – which one to pick? A pretty good comparison.
  • Clojure is a Get Stuff Done Language – experience report – “For all that people think of Clojure as a “hard” “propeller-head” language, it’s actually designed right from the start not for intellectual purity, but developer productivity.”

Posted in eclipse, General, j2ee, Languages, Testing, Top links of month | Tagged: , , , , , , , , , , | 3 Comments »

Comparison of Eclipse 3.6 and IntelliJ IDEA 10.5: Pros and Cons

Posted by Jakub Holý on October 18, 2011

After having worked with Eclipse for over 5 years I’ve came to use IntelliJ IDEA intensively on a J2EE project in three months and took this as an opportunity to compare the two. You can’t really compare 5 years and 3 months but I still believe that it is long enough to get a pretty good overview of what a tool is like.

For the impatient:

IntelliJ is a very good tool, its killing feature for me is its excellent support for other languages such as Groovy (e.g. for unit tests) and Clojure. Many details are more worked-out and with a higher usability then in Eclipse, f.ex. search & replace with match highlighting and replacement preview. Its support for navigability and refactoring across multiple languages (Java, JSP, JSF, HQL, Spring config in my case) is also an absolutely great feature for productivity. And of course I have to add it credits for being a Czech product [1] (interestingly enough, NetBeans also comes from the Czech Republic [2]; it’s a pity Eclipse hasn’t this link too) :-).

My main issue with IntelliJ is its performance. First, running tests is slow because IntelliJ only does (re)compile the test/source when you hit the run button as opposed to Eclipse’ incremental compilation. And that makes TDD very painful. (I tried to use the old Eclipse Mode plugin but it has problems with IntelliJ 9/10.) Second, sometimes the UI freezes* and you have to wait seconds or tens of seconds for it to respond again (even after disabling most plugins and some analysis). It doesn’t happen too often but often enough to be noticed, to be annoying, and to interrupt the development flow.

*) Update: UI freezes may be a specific issue of Mac 64b 1.6 JDK

So I guess I’ll use either Eclipse or IntelliJ with respect to the needs of the project at hand and hope for IntelliJ to resolve its performance issues (as NetBeans did). Read the rest of this entry »

Posted in eclipse, Languages, Tools | Tagged: , , | Comments Off

EMF tips: Accessing model meta data, serializing into element/attribute

Posted by Jakub Holý on January 11, 2011

Two tips for the Eclipse Modeling Framework (EMF) 2.2.1:

  1. Accessing model’s meta model – accessing EClass/attribute by name – so that you can set an attribute when you only know its name and haven’t its EAttribute
  2. How to force EMF to serialize an object as an XML element instead of an XML attribute

Read the rest of this entry »

Posted in eclipse, Languages | Tagged: , | Comments Off

More Eclipse & svn fun: Can’t share a project (only Team – Apply Patch)

Posted by Jakub Holý on November 23, 2010

With Subversive it may happen that it completely ignores some projects while it perfectly works for other ones. If a project seems to have no SVN information in Eclipse (thoug it actually contains all the .svn/ folders) and the Team context manu only contains Apply Patch… (i.e. especially not Share project…) then you have likely mixed up Eclipse metadata about the project (for instance by sharing it previously with Subclipse).

This is a well known problem and the solution is to Delete the project (without deleting its content) and to re-import it into Eclipse. Also make sure that the Subversive back-end version supports the version of Subversion (too many *versions here :)) recorded in the project metadata. If needed, you can use a script to up/down-grade the SVN metadata, as described in a FAQ.

Posted in eclipse, Tools | Tagged: , , | Comments Off

Tip: Enable a shortcut for Occurrences in File in Eclipse under Gnome (default C+S+u)

Posted by Jakub Holý on November 2, 2010

The useful Eclipse action Search – Occurrences in File – Identifier has by default the shortcut Control+Shift+U. But under Gnome the shortcut Control+Shift+U is used for Unicode character input, indicated by an underlined u when pressed. Assigning a different shortcut is easy but there are few “traps”:

  1. In Eclipse, go to Window – Preferences – General – Keys
  2. Type the filter occurr and click on “Shows the Occurrences in File Quick Menu“. Do not confuse it with “Occurences in File” (binding C+S+A, when Editing in Structured T. Ed.)!
    1. Make sure that When is “In Windows“, Category is “Search
    2. Click [Unbind Command], click into the Binding field and type the keys that you want. Beware that some keys could conflict with existing bindings or global Gnome/system bindings. For me e.g. Control+Shift+S or F8 worked (though I might have to unbind conflicting bindings, I don’t remember anymore).

Environment: Eclipse 3.5, Gnome 2.30.2, Ubuntu 10.04.

Posted in eclipse, Tools | Tagged: , | Comments Off

Eclipse Profile configuration: The launch requires at least one data collector

Posted by Jakub Holý on May 13, 2010

I just installed TPTP into my Eclipse 3.5 under Ubuntu 9.04 and tried to profile a class. The Profile Configuration opened with a red warning reading “the launch requires at least one data collector to be selected“. Clicking the configuration’s Monitor tab reveals a more detailed error (and nothing to select):

IWATO435E An error occured when connecting to the host.

A quick check of the error log (Window – Show View – Other… – General – Error Log) reveals the cause:

RAServer generated the following output:  [Error Stream]:ACServer: error while loading shared libraries: /home/jholy/development/tools/eclipse-ide/pulse2-2.4.2/Common/plugins/org.eclipse.tptp.platform.ac.linux_ia32_4.4.202.v201002100300/agent_controller/bin/../lib/libtptpUtils.so.4: file too short

Checking the content of the lib/ folder revealed an interesting thing:

-rw-r–r– 1 jholy jholy   17 2010-02-16 23:16 libtptpUtils.so
-rw-r–r– 1 jholy jholy   21 2010-02-16 23:16 libtptpUtils.so.4
-rwxr-xr-x 1 jholy jholy 100K 2010-02-16 23:16 libtptpUtils.so.4.5.0

As also the content of the two small files suggests (they contain a name of the corresponding file with a longer name), the *.so and *.so.4 files should have been links but the installer failed to create them.

Solution

List all files in the lib/ folder, you will see that there are many real files like libtptpUtils.so.4.5.0 and libxerces-c.so.26.0 and many should-be-links files. The solution is, of course, to replace all those files that shoud be links with actual links.

For me the solution was:

$ cd .../plugins/org.eclipse.tptp.platform.ac.linux_ia32_4.4.202.v201002100300/agent_controller/lib
# Move out the files that are OK
lib$ mkdir tmp
lib$ mv libswt-* libcbe.so tmp/
# Fix the links
lib$ for FILE in `ls *.so`; do ln -sf "${FILE}.4.5.0" $FILE; ln -sf "${FILE}.4.5.0" "${FILE}.4"; done
# Move the correct files back
lib$ mv tmp/* .
lib$ rmdir tmp
# Fix links for files with *.26 instead of *.4.5.0
lib$ ln -sf libxerces-c.so.26.0 libxerces-c.so.26
lib$ ln -sf libxerces-c.so.26.0 libxerces-c.so
lib$ ln -sf libxerces-depdom.so.26.0 libxerces-depdom.so.26
lib$ ln -sf libxerces-depdom.so.26.0 libxerces-depdom.so
lib$ rm libxerces-depdom.so.4 libxerces-c.so.4
# Done!

Try to open the profile configuration now, the IWATO435E should have disappeared and you should be able to select a data collector.

If not, restart Eclipse, try again, check the error log.

My environment

  • Ubuntu 9.04
  • Eclipse 3.5
  • TPTP – see above

Related

There is a similar post of the same problem but with different cause: Get Eclipse TPTP to run on Ubuntu Karmic Koala – the cause was: “the Agent Controller was built against old C++ libraries which were no longer available on my system (Ubuntu 9.10 Karmic Koala, amd64)”.

Posted in eclipse | Tagged: , , , , | Comments Off

Broken Eclipse shortcut under Gnome for Occurrences in File

Posted by Jakub Holý on March 17, 2010

Broken Eclipse shortcut under Gnome for Occurrences in File

One of the extremely useful keyboard shortcuts for Eclipse is Shift+Control+U which finds all occurrences of a selected identifier in the current file. Unfortunately  this doesn’t work under Linux with Gnome because Gnome uses this shortcut for composing Unicode characters. You can check it by typing Shift+Control+U followed by 123 and a space into your browser’s address bar: first it will render an underlined u and then a strange g-like character.

The conclusion is that you cannot use the shortcut Shift+Control+U and perhaps also a few others (I experienced troubles with Shift+Ctrl+A) in Eclipse under Gnome. You can the shortcut in preferences accessible e.g. via pressing twice Shift+Ctrl+L. For instance Shift+Ctrl+F1 is OK.

Environment: Eclipse 3.4/3.5, Ubuntu 9.04 with Gnome 2.26.1.

Posted in eclipse | Comments Off

Eclipse: Open Type/Resource working again under Linux!

Posted by Jakub Holý on February 26, 2010

Some weeks ago the extremely useful features of Eclipse Open Type and Open Resource stopped working, throwing an uninformative  Error instead, no matter which version or JRE vendor. I was desperate. Until finally I found a bug regarding this issue which pointed me to the solution – switching off Gnome’s assistive technologies (System – Preferences – Assistive Technologies – uncheck Enable assistive technologies under my Ubuntu 9.04 Jaunty). Thanks, allmighty powers of digitalized universe!

Posted in eclipse | Comments Off