<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://chem-bla-ics.linkedchemistry.info/feed/by_tag/pmd.xml" rel="self" type="application/atom+xml" /><link href="https://chem-bla-ics.linkedchemistry.info/" rel="alternate" type="text/html" /><updated>2026-08-31T19:33:33+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/feed/by_tag/pmd.xml</id><title type="html">chem-bla-ics</title><subtitle>Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.</subtitle><author><name>Egon Willighagen</name></author><entry><title type="html">PMD code checking: checking for programming against CDK interfaces</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/05/23/pmd-code-checking-checking-for.html" rel="alternate" type="text/html" title="PMD code checking: checking for programming against CDK interfaces" /><published>2010-05-23T00:00:00+00:00</published><updated>2010-05-23T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/05/23/pmd-code-checking-checking-for</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/05/23/pmd-code-checking-checking-for.html"><![CDATA[<p>I wrote recently about <a href="https://chem-bla-ics.linkedchemistry.info/2010/05/15/cleaner-cdk-code-5-developer-against.html">programming against interfaces <i class="fa-solid fa-recycle fa-xs"></i></a>,
which led to some discussion. <a href="http://blog.rguha.net/">Rajarshi</a> <a href="http://sourceforge.net/tracker/?func=detail&amp;aid=3005355&amp;group_id=20024&amp;atid=320024">commented</a>:</p>

<blockquote>
  <p>patch 2 seems to replace usage of Molecule with Molecule, rather than IMolecule</p>
</blockquote>

<p>Now, this particularly problem was <a href="http://www.eclipse.org/">Eclipse</a> being overly active cleaning up the imports, but we reached the
point that it is actually interesting to have <a href="http://pmd.sf.net/">PMD</a> warn about these issues. PMD is a cool piece of software used
by the CDK project for a long time one. One particular cool thing is that you can write <em>code warnings</em> as
<a href="http://www.w3schools.com/xpath/default.asp">XPath</a> queries.</p>

<p>So, I promised Rajarshi to have a look at a custom rule to look at using IMolecule instead of Molecule. The code is actually pretty simple, using the aforementioned XPath feature:</p>

<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;rule</span> <span class="na">name=</span><span class="s">"ReplaceMoleculeWithIMolecule"</span>
      <span class="na">language=</span><span class="s">"java"</span>
      <span class="na">message=</span><span class="s">"Use the IMolecule interfaces instead of the Molecule implementation"</span>
      <span class="na">class=</span><span class="s">"net.sourceforge.pmd.rules.XPathRule"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;description&gt;</span>
      Programming against the CDK interfaces allows users to pick their favorite
      implementation (nonotify, datadebug).
  <span class="nt">&lt;/description&gt;</span>
  <span class="nt">&lt;priority&gt;</span>3<span class="nt">&lt;/priority&gt;</span>
  <span class="nt">&lt;properties&gt;</span>
    <span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">"xpath"</span><span class="nt">&gt;</span>
      <span class="nt">&lt;value&gt;</span>
 <span class="cp">&lt;![CDATA[
   //Type/ReferenceType/ClassOrInterfaceType[@Image='Molecule']
 ]]&gt;</span>
      <span class="nt">&lt;/value&gt;</span>
    <span class="nt">&lt;/property&gt;</span>
  <span class="nt">&lt;/properties&gt;</span>
    <span class="nt">&lt;example&gt;</span>
    <span class="cp">&lt;![CDATA[
      Molecule mol = builder.newInstance(IMolecule.class);
    ]]&gt;</span>
  <span class="nt">&lt;/example&gt;</span>
<span class="nt">&lt;/rule&gt;</span>
</code></pre></div></div>

<p>Patch pending…</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="java" /><category term="pmd" /><summary type="html"><![CDATA[I wrote recently about programming against interfaces , which led to some discussion. Rajarshi commented:]]></summary></entry><entry><title type="html">Cleaner CDK Code #3: run the PMD tests</title><link href="https://chem-bla-ics.linkedchemistry.info/2010/03/26/cleaner-cdk-code-3-run-pmd-tests.html" rel="alternate" type="text/html" title="Cleaner CDK Code #3: run the PMD tests" /><published>2010-03-26T00:00:00+00:00</published><updated>2010-03-26T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2010/03/26/cleaner-cdk-code-3-run-pmd-tests</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2010/03/26/cleaner-cdk-code-3-run-pmd-tests.html"><![CDATA[<p><a href="http://pmd.sourceforge.net/">PMD</a> is a tool to run some tests against your source code. The check for code style,
common problems, and places where code could be improved. The <a href="http://cdk.sf.net/">CDK</a> has been using it for years
now, such as <a href="http://pele.farmbio.uu.se/nightly/pmdsummary.html">here for CDK 1.3.x</a>.</p>

<h2 id="running-the-pmd-tests-from-the-command-line">Running the PMD tests from the command line</h2>
<p>When you are writing patches for the CDK, you can run the PMD tests via an Ant file, for example via the command line:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ ant -f pmd.xml
</code></pre></div></div>

<p>However, when working on a single file, you will likely appreciated running the tests against a single module. This can be done with (for the data module):</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ ant -f pmd.xml -Dpmd.test=custom -Dmodule=data test-module
</code></pre></div></div>

<p>The <a href="http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk/cdk;a=tree;f=pmd;h=80f6f928bf7b24acdb3c2a909550832b15365ef5;hb=HEAD">custom.xml</a>
defines the tests we normally run.</p>

<p>The pmd.xml does not create HTML pages, like Nightly does. Instead, an XML file is currently created. The
<a href="http://manpages.ubuntu.com/manpages/lucid/en/man1/xpath.1p.html">xpath</a> utility can be used to filter out the
information we are interested in. For example, if we want to reports just about DefaultChemObjectBuilder, we issue:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ xpath -e "//violation[@class='DefaultChemObjectBuilder']" \\
    reports/pmd/data.xml
</code></pre></div></div>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="pmd" /><summary type="html"><![CDATA[PMD is a tool to run some tests against your source code. The check for code style, common problems, and places where code could be improved. The CDK has been using it for years now, such as here for CDK 1.3.x.]]></summary></entry><entry><title type="html">PMD 2.4.5 installed in the CDK 1.2.x branch</title><link href="https://chem-bla-ics.linkedchemistry.info/2009/10/16/pmd-245-installed-in-cdk-12x-branch.html" rel="alternate" type="text/html" title="PMD 2.4.5 installed in the CDK 1.2.x branch" /><published>2009-10-16T00:00:00+00:00</published><updated>2009-10-16T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2009/10/16/pmd-245-installed-in-cdk-12x-branch</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2009/10/16/pmd-245-installed-in-cdk-12x-branch.html"><![CDATA[<p>Today I installed <a href="http://pmd.sf.net/">PMD</a> 4.2.5 in the <a href="http://github.com/egonw/cdk/tree/cdk-1.2.x">CDK 1.2.x branch</a> which contains
mostly <a href="http://sourceforge.net/project/shownotes.php?release_id=659603&amp;group_id=56262">bug fixes</a> compared to the 4.2.2 version we had
earlier. Several of these include false positives: warnings which were not really problems, but tests going bad.</p>

<p><img src="/assets/images/supernightly2.png" alt="" /></p>

<p>The number of these false positives seems to be significant as the number of PMD violations for the CDK 1.2.x branch seems to have
dropped about 1500! warnings :)</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="pmd" /><summary type="html"><![CDATA[Today I installed PMD 4.2.5 in the CDK 1.2.x branch which contains mostly bug fixes compared to the 4.2.2 version we had earlier. Several of these include false positives: warnings which were not really problems, but tests going bad.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://chem-bla-ics.linkedchemistry.info/assets/images/supernightly2.png" /><media:content medium="image" url="https://chem-bla-ics.linkedchemistry.info/assets/images/supernightly2.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Nightly CDK builds now available</title><link href="https://chem-bla-ics.linkedchemistry.info/2006/05/01/nightly-cdk-builds-now-available.html" rel="alternate" type="text/html" title="Nightly CDK builds now available" /><published>2006-05-01T00:00:00+00:00</published><updated>2006-05-01T00:00:00+00:00</updated><id>https://chem-bla-ics.linkedchemistry.info/2006/05/01/nightly-cdk-builds-now-available</id><content type="html" xml:base="https://chem-bla-ics.linkedchemistry.info/2006/05/01/nightly-cdk-builds-now-available.html"><![CDATA[<p><a href="http://web.archive.org/web/20060815001811/http://cheminfo.informatics.indiana.edu/~rguha/">Rajarshi Guha <i class="fa-solid fa-box-archive fa-xs"></i></a>
has set a <a href="http://blue.chem.psu.edu/~rajarshi/code/java/nightly/">nightly build service <i class="fa-solid fa-link-slash fa-xs"></i></a>
for the <a href="http://cdk.sf.net/">Chemistry Development Kit</a> (CDK). The output is pretty, but information rich: it includes results for the
<a href="http://www.junit.org/">JUnit test</a>, <a href="http://java.sun.com/j2se/javadoc/doccheck/">DocCheck</a>, and <a href="http://pmd.sourceforge.net/">PMD</a>.
The compiled jar and the corresponding JavaDoc can be downloaded, offering a cutting edge distribution for users.</p>]]></content><author><name>Egon Willighagen</name></author><category term="cdk" /><category term="junit" /><category term="pmd" /><category term="opensource" /><summary type="html"><![CDATA[Rajarshi Guha has set a nightly build service for the Chemistry Development Kit (CDK). The output is pretty, but information rich: it includes results for the JUnit test, DocCheck, and PMD. The compiled jar and the corresponding JavaDoc can be downloaded, offering a cutting edge distribution for users.]]></summary></entry></feed>