writing custom pmd rule that checks for method not followed by chained method? - pmd

I use the "fest-assert" library in unit tests, which produce "fluent assertions" that are easy to read from left to right.
If a developer hasn't written a test using TDD, they sometimes end up with a line of code like this:
assertThat(something);
This is wrong, because it has to do something more like this:
assertThat(something).is...
Where "is..." is one of many possible predicates, like "isEqualTo()" or "isTrue()" or "hasSize()", et cetera.
I'd like to see if it's possible to write a custom PMD rule that can detect that the return value from "assertThat()" is dropped on the table, as it's not followed by a chained method.
First, does anyone know if this is possible, and could provide an example of what this would look like?
Note that I'm using Sonar 3.7, which is using PMD 4.3. We're planning a Sona upgrade to either 4.1.2 or 4.2 very soon, but I don't know what version of PMD those versions use.

Please, do not double post. Thread closed. Continuing at http://sonarqube.15.x6.nabble.com/Write-a-custom-XPath-task-that-looks-for-a-method-that-is-NOT-followed-by-a-chained-method-call-td5024017.html

Related

Can XCUITEST can implement the cucumber Feature files

Can we write the Feature files and step definitions in Swift Automation framework using XCUITEST Framework ?Is yes , Any jar files or plugins we need to install ?
I am unable to find much support in this
While this is not an appropriate question for StackOverflow, I will oblige you an answer with Cucumberish. I have used it in the past, it works, but I generally steer clear of third party frameworks as they add a layer of complexity and leave you in the lurch if they lose support.
I have worked a bit with CucumberSwift and got it to work fine, reading German-language Feature files and letting me define steps in Swift using all the functionality that XCUITest provides.
However, we have not adopted this in the end but are writing Feature files in Gherkin and then write ordinary XCTestCases that we link to the Feature files by mentioning Scenario names in comments. We develop the same functionality for three platforms and it was difficult to see how BDD tooling would work across all three or how we could make it work given the resources we have. Like Mike Collins we also felt that running without the complexity of additional frameworks was an added benefit.
Having said this, CucumberSwift seems promising, perhaps check out this discussion about documentation and add to it?

Eclipse Source Editor: Some items are Shown as StrikeThrough. How Come? [duplicate]

While I'm making an Android app, Eclipse will strike out some things. More specifically, Gallery. Here is a screen shot:
When I hover my mouse over the warnings, it says The type Gallery is deprecated. I don't know what Deprecated means, but I do know that it's a Java term. Any help would be appreciated. Thanks!
(From the question before editing: The term is deprecated, not depreciated. It's a common typo, but worth being aware of for searching purposes :)
It's basically a bit like "obsolete" - you're encouraged not to use classes or methods which are deprecated. Typically the documentation will explain why you're not meant to use them, and give you a better alternative. The deprecated version is only present for backward compatibility, usually.
It's worth taking this seriously - a lot of the time if you're using a deprecated API, you're coming at something from a fundamentally flawed approach. Date is the clearest example of this, where the Java 1.0 API was almost entirely deprecated in 1.1, when Calendar was introduced. Using the deprecated methods in Date is a sure way of storing up problems for yourself.
See the Oracle "How and when to deprecate APIs" page for more information.
Deprecated means it used to support older SDK, but not anymore. Thats why you get the warning.
It is just a warning most of the times it works, but you most be careful because it could cause problem with newer versions.
Deprecated isn't a Java term. It is used in many other things but a lot in programming. It simply means that it is no longer supported...normally replaced with something else. The Android Docs will help you adapt it to what you need depending on what you're doing

Is there a revision control system that allows us to manage multiple parallel versions of the code and switch between them at runtime?

If I want to enable a new piece of functionality to a subset of known users first, is there any automated system of framework that exists to do this?
Perhaps not directly with version control - you might be interested to read how flickr goes about selectively deploying functionality: http://code.flickr.com/blog/page/2/
And this guy talks about implementing something similar in a rails app: http://www.alandelevie.com/2010/05/19/feature-flippers-with-rails/
Most programming languages have if statements.
I don't know what "switching between them at runtime" means. You usually don't check executable code into an SCM system. There's a separate process to check out, build, package, and deploy. That's the province of continuous integration and automated builds in agile techniques.
SCM systems like Subversion allow you to have tags and branches for parallel development. You're always free to build, package, and deploy those as you see fit.
As far as I know no...
If you wanted a revision control system that had multiple versions that you could switch between. Find a SCM you like and lookup branching.
But, it sounds like you want it to me able to switch versions in the SCM programmatically during runtime. The problem with that is, for a revision control system to be able to do that it would have to be aware of the language and how it's implemented.
It would have to know how load and run the next version. For example, if it was C code it would have to dynamically compile and run it on the fly. If it was PHP it would have to magically load the script in a sandbox http server that has PHP support. Etc... In which case, it isn't possible.
You can write an app to change the version in the scm by using the command line.
To do it during runtime, that functionality has to be part of the application itself.
The best (only) way I can think of doing it is to have one common piece of code that acts like a 'bootloader', which uses a system call to checkout the correct branch based on whatever your requirements are. It then (if necessary) compiles that code, and runs it.
It's not technically 'at runtime', but it appears that way if it works.
Your first other option is something that dynamically loads code, but that's very language-dependent, and you'd need to specify.
The other is to permanently have both in the working codebase (which doubles your size if it's a full duplication), and switch at runtime. You can save a good bit of space by using objects that are shared between both branches, and things like conditional compilation to use the same source files for both targets.

Bamboo Versioning

I have a situation where i need to maintain version information of my builds. By googling i found limited information. one way is to create a version file on source control and keep updating. other is to use the source control revision number. final one is to use bamboo build number. i haven't implemented anyone of this before. colud anyone point out the pros and cons of each method.
Thank you,
Reddy.
Please atleast tell me which method have u used to implement the same.
Thnq..
Visit http://confluence.atlassian.com/display/BAMBOO011/1.2.1+Using+Custom+Variables for more information about bamboo variables.
Remember to define a system property in your job configuration like this:
-DbambooBuildNumber=${bamboo.buildNumber} then you can use this property bambooBuildNumber in your maven or ant configuration file.
Good question. I've done this in kind of an ad-hoc manner before. I don't strongly advocate the following approach, but I'll list it anyway for comparison with the (I hope) better approaches that others will soon be posting.
In order to maintain the version information in a medium sized Java codebase, I created a simple class to hold the major, minor, and revision version numbers as static constants and produce a formatted version string. I then created a perl script to check the class out of version control, replace the version components with those specified as arguments to the script, and check it back in.
The script does most of the work, so the process of updating the version is fairly simple and quick. I had to implement this quickly, so there are probably better ways of doing it. I just didn't have time, or motivation, to research better alternatives.
I'm not entirely sure what your question is but I'm assuming you want build numbers? When you build your project with Ant you can use the BuildNumber task to keep track of build numbers.
you can use ${bamboo.buildNumber} in ant
look at the following thread
http://forums.atlassian.com/thread.jspa?messageID=257319944
The following link is a pretty good article. If you can get all the plugins working with the version of Bamboo you're on it should be fine.
Release Management with Atlassian Bamboo (outdated)
Release Management with Atlassian Bamboo via the Internet Archive

More fine grained sorting of methods using Eclipse Ganymede: Is there a good plugin available?

These are the options we have out of the box:
I would like a more fine grained sorting when it comes to methods. I would like to:
Have all methods with a name which does not start with get, is or set first.
Then have the accessor methods (with names starting with get, is or set).
Individually the methods in [1] and [2] above could be sorted in alphabetical order. Apart from my devision of normal methods into two parts I like the existing sort order.
I find this order (with the accessor methods last) better as I'm more likely to find the non-accessor methods interesting when I'm maintaining a class and I need to fix a bug etc.
Is there a plugin I could use? If there is none, would it be hard to create this kind of plugin myself? (I have never created a Eclipse plugin.)
I hope it's not to late for my answer.
As far as I know, there is no such plugin (I looked at eclipse plugin central right now).
If you want to write such plugin, it shouldn't be too hard to write the refactoring (the Java Editor is based on an AST, that can be reached via extension points) itself, but for building a working plugin it might need more study.
Some resources that might help:
Plugin development resources from stackoverflow: question 592391 (sorry, but cannot post two hyperlinks)
An open source refactoring plugin: http://code.google.com/p/tane/ (it currently contains a single refactoring plus the related gui elements, it might be a good example for you)
In 2011, an academic exercise resulted in an Eclipse plugin implementing methods sorting based on ideas in Robert C. Martin's book "Clean Code". I am still trying to work out if I like it or not.
There is an open bug report to enhance sort member functionality in Eclise: Sort Members doesn't provide a means to group getter/setter pairs. It was opened in 2004 and still has no plans to be implemented.