I want to skip warnings in PMD - pmd

I get the following when I run the PMD Report in my target/pmd.xml using teamcity
Now I wanted to skip the following warnings "Unused Code" . So how can I do that ?
Presently the build is failing , when I googled I got one option where I can use the
Annotation #Suppress warnings (But I wanted to skip these warnings from my maven goals
itself , is there any goal like skip warnings? or something like that)
<?xml version="1.0" encoding="UTF-8"?>
<pmd version="5.0.2" timestamp="2014-04-07T07:41:55.431">
<file name="/home/herc/teamcity/TeamCity/buildAgent/work/c2f0847f19a6b00d/src/main/java/com/ga/gameon/db/IapDAO.java">
<violation beginline="16" endline="16" begincolumn="16" endcolumn="61" rule="UnusedModifier" ruleset="Unused Code" package="com.ga.gameon.db" class="IapDAO" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0$
Avoid modifiers which are implied by the context
</violation>
<violation beginline="17" endline="17" begincolumn="16" endcolumn="56" rule="UnusedModifier" ruleset="Unused Code" package="com.ga.gameon.db" class="IapDAO" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0$
Avoid modifiers which are implied by the context
</violation>
</file>
<file name="/home/herc/teamcity/TeamCity/buildAgent/work/c2f0847f19a6b00d/src/main/java/com/ga/gameon/service/IapService.java">
<violation beginline="18" endline="18" begincolumn="16" endcolumn="83" rule="UnusedModifier" ruleset="Unused Code" package="com.ga.gameon.service" class="IapService" externalInfoUrl="http://pmd.sourceforge.ne$
Avoid modifiers which are implied by the context
</violation>
<violation beginline="20" endline="20" begincolumn="16" endcolumn="76" rule="UnusedModifier" ruleset="Unused Code" package="com.ga.gameon.service" class="IapService" externalInfoUrl="http://pmd.sourceforge.ne$
Avoid modifiers which are implied by the context
</violation>
</file>
<file name="/home/herc/teamcity/TeamCity/buildAgent/work/c2f0847f19a6b00d/src/main/java/com/ga/gameon/service/IapServiceImpl.java">
</file>
</pmd>

Consider simply removing unneeded rules from your pmd.xml. For example, if you don't want "unused modifiers" to be flagged, remove the "Unused Modifier" rule.
If you only want to suppress specific occurrences, you can specify suppressions in your pmd.xml as documented here.
For example, to suppress reporting specifically named parameters which are unused:
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter">
<property name="violationSuppressRegex" value=".*'mySpecialParamName'.*"/>
</rule>

Related

Accessing DOM element with namespace in Freemarker template

I have the following XML
<wmi xmlns="http://www.exmple.com/XMLSchema/fulfillment/v1/order/orderShipment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/XMLSchema/fulfillment/v1/order/orderShipment OrderShipmentNotification.xsd">
<wmiHeader>
<fileID>693401.20160229.130342.3541254</fileID>
<version>2.0.0</version>
<messageType>FSN</messageType>
<genDate>2016-02-29T13:03:42Z</genDate>
<from>
</from>
</wmiHeader>
<orderShipNotification>
<shipmentHeader dateTimeCreated="2016-02-29T13:03:42Z" requestNumber="2574445351883" />
<shipmentDetails actualShipmentDateTime="2016-02-29T12:18:54Z" carrierCode="XX" carrierMethodCode="XX-01">
<shipmentPackDetails trackingNumber="9361289672090007124848" trackingURL="https://example.com/go/TrackConfirmAction_input?qtc_tLabels1=323434">
<shipmentPackLineDetails requestLineNumber="1" partnerItemID="FXT-CC-LB" itemQtyShipped="1" />
</shipmentPackDetails>
</shipmentDetails>
</orderShipNotification>
</wmi>
I am getting error in Freemarker template when I am trying to access.
${orderShipNotification.shipmentDetails.#actualShipmentDateTime[0]!""}
If I delete the namespaces from the document it is working fine. I deleted the following content from the XML
xmlns="http://www.exmple.com/XMLSchema/fulfillment/v1/order/orderShipment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/XMLSchema/fulfillment/v1/order/orderShipment OrderShipmentNotification.xsd"
I did some investigation. The is a ftl directive. But it is still not clear how this will solve the problem. Please let me know how I can access the attributes.
http://freemarker.incubator.apache.org/docs/ref_directive_ftl.html#ref.directive.ftl
Start the template with
<#ftl ns_prefixes={"D":"http://www.exmple.com/XMLSchema/fulfillment/v1/order/orderShipment"}>
This sets the namespace as the default (D stands for default). Note that if you will also use XPath queries, there you will have to write out the D: before the element names (this is an XPath restriction).
This is documented here: http://freemarker.org/docs/xgui_imperative_learn.html

JAXB binding XBRL element does not work

I am trying to generate localised XBRL classes with JAXB in Eclipse, but I have been getting an error:
[ERROR] Property "Title" is already defined. Use <jaxb:property> to resolve this conflict.
line 145 of http://www.xbrl.org/2003/xl-2003-12-31.xsd
[ERROR] The following location is relevant to the above error
line 151 of http://www.xbrl.org/2003/xl-2003-12-31.xsd
As the error suggests, an element and an attribute name conflicts. These are lines 145 and 151:
<element ref="xl:title" minOccurs="0" maxOccurs="unbounded" />
<attribute ref="xlink:title" use="optional" />
So I'd need to rename either (or both). This is what I've been trying to do - bind the element title to titleElement:
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xl="http://www.xbrl.org/2003/XLink"
schemaLocation="http://www.xbrl.org/2003/xl-2003-12-31.xsd">
<jxb:bindings node="//element[#ref='xl:title']">
<jxb:property ref="xl:titleElement"/>
</jxb:bindings>
</jxb:bindings>
This produces the following error, plus the original "title already defined" errors:
[ERROR] XPath evaluation of "//element[#ref='xl:title']" results in empty target node
line 6 of titleElementAttributeFixer.xjb
Suggestions to get it working?
EDIT: as helderdarocha suggested, my expression was wrong. I am new to XML and XPath, and it was a bit confusing since the element does not have the "xs:" namespace typed excplicitly. After I fixed that error, I got another one:
[ERROR] XPath evaluation of "//xs:element[#ref='xl:title']" results in too many (3) target nodes
As all the "ref" attributes need to be updated, I put the tag "multiple='true'" in the binding. Now I am getting the following error, and cannot figure out how to solve it:
[ERROR] cvc-complex-type.3.2.2: Attribute 'ref' is not allowed to appear in element 'jxb:property'.
Ideas for this? I do want to bind the contents in the attribute 'ref' for the element in question to another name.
I solved the problem after all by applying these SO questions:
JAXB fails to generate Java classes for XBRL
JAXB XJC Two declarations cause a collision. Customized binding cannot be honored
So after I solved the original problem, I had additional problems with objectfactory collisions, which I fixed as well. This is how my working bindings.xjb looks in general:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.1">
<bindings schemaLocation="http://www.xbrl.org/2003/xl-2003-12-31.xsd"
node="//xsd:schema//xsd:element[#name='title']">
<property name="xlTitle"/>
</bindings>
<bindings schemaLocation="<local_dimension_file_D002>.xsd"
node="//xsd:schema//xsd:element[#name='AcceleratedDepreciation']">
<factoryMethod name="AcceleratedDepreciationD002"/>
</bindings>
...many more objectfactory collisions solved...
</bindings>
I hope this helps other XBRL/XML/JAXB newcomers to get started.
Your XPath expression is incorrect. Your bindings XML declares an xs prefix to qualify all XML Schema elements, but your XPath expression tries to find an element element from no-namespace since it's not qualified.
You should use:
<jxb:bindings node="//xs:element[#ref='xl:title']">
<jxb:property ref="xl:titleElement"/>
</jxb:bindings>

XDT Transform: InsertBefore - Locator Condition is ignored

I have a web.config file in which I need to either insert the <configSections /> element or manipulate children of that node if it already exists.
If it already exists I don't want to insert it again (obviously, as it is only allowed to exist once).
Normally, that would not be a problem, however:
If this element is in a configuration file, it must be the first child element of the element.
Source: MSDN.
So if I use xdt:Transform="InsertIfMissing" the <configSections /> element will always be inserted after any existing child elements (and there are always some), violating the above restriction of it having to be the first child element of <configuration />
I attempted to make this work in the following way:
<configSections
xdt:Transform="InsertBefore(/configuration/*[1])"
xdt:Locator="Condition(not(.))" />
Which works perfect, if the <configSections /> element doesn't already exist. However, the condition I've specified seems to be ignored.
In fact, I've tried a few conditions like:
Condition(not(/configuration[configSections]))
Condition(/configuration[configSections] = false())
Condition(not(/configuration/configSections))
Condition(/configuration/configSections = false())
Finally, out of desperation, I tried:
Condition(true() = false())
It still inserted the <configSections /> element.
It is important to note that I'm trying to include this in a NuGet package, so I will be unable to use a custom transform (like the one AppHarbor uses).
Is there any other clever way to get my element in the right place only if it doesn't yet exist?
To test this out, use AppHarbors config transform tester. Replace the Web.config with the following:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="initialSection" />
</configSections>
</configuration>
And Web.Debug.config with the following:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<configSections
xdt:Transform="InsertBefore(/configuration/*[1])"
xdt:Locator="Condition(true() = false())" />
<configSections>
<section name="mySection" xdt:Transform="Insert" />
</configSections>
</configuration>
The result will show two <configSections /> elements, the one containing "mySection" being the first, as specified in the InsertBefore Transform.
Why was the Locator Condition not taken into account?
So after facing the same issue, I came up with a solution. It's not pretty nor elegant, but it works. (At least on my machine)
I just split the logic into 3 different statements. First, I add an empty configSections at the correct position (first). Then I insert the new config to the last configSections, which would be the new one if it is the only one, or a previously existing one otherwise.
Lastly I remove any empty configSections elemnt which might exist. I'm using RemoveAll for no good reason, you should probably use Remove.
The overall code looks like so:
<configSections xdt:Transform="InsertBefore(/configuration/*[1])" />
<configSections xdt:Locator="XPath(/configuration/configSections[last()])">
<section name="initialSection" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</configSections>
<configSections xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />
The question which still remains unanswered is why Locator conditions are not taken into account for InsertBefore. Or why I can't handle an empty match set for InsertBefore, because that would allowed me to do fun things such as
//configuration/*[position()=1 and not(local-name()='configSections')]
Which to be honest is a much clearer way of doing what I want to achieve.

How to rewrite the magento core-cache-model (Mage_Core_Model_Cache)

I have to rewrite the core cache model. And this doesn't work. My first attempt to solve the problem was to try the rewrite with another model...
In my config.xml I declared the following
<global>
<models>
<core>
<rewrite>
<**layout**>MyCompany_MyModule_Model_Core_Cache</**layout**>
</rewrite>
</core>
</models>
....
and in my class I died in the consturctor.
This works perfectly!
So my may in rewriting models is the right one.
But If I don't use the layout-node in the xml but using the cache-node instead this does not work.
So my attempt is the following and this is not working:
<global>
<models>
<core>
<rewrite>
<cache>MyCompany_MyModule_Model_Core_Cache</cache>
</rewrite>
</core>
</models>
....
My question now: is there a way to rewrite / overload the "cache-core-model"???
The cache will be initialized before module configurations (config.xml) are loaded. The cache-Model was instanciated with Mage::getModel, which caches the modelnames in the registry.
So all later tries to get the custom cache-model will also fail.
Solution: put this rewrite statement in the etc/local.xml. This is a bit dirty because the local.xml should only hold module independent stuff. But this is better than copying core files to local.
I had the same question, but my solution is a little bit different to yours ;-)
Magento will load the XML file from /app/etc/*.xml (this files will not be cached) before everything else in magento.
So i created my own file here "cache.xml" and the content is
<?xml version="1.0"?>
<config>
<global>
<models>
<core>
<rewrite>
<cache>MyCompany_MyModule_Model_Core_Cache</cache>
</rewrite>
</core>
</models>
</global>
</config>
works perfect in 1.6,1.7 and 1.8
I'm also trying to do the same thing and i don't think it's possible. If you var_dump out $this->_xml->group->models in the method: getGroupedClassName (app/code/core/Mage/Core/Model/Config.php) you'll notice that your rewrite it's not yet available, hence why it's skipped.
If you try to overwrite translate or layout: your_class_model you'll notice that the $this->_xml... dumps the initial core classes (with no rewrite) and you'll see your rewrite down the line well past the core/cache. So, it's probably being overridden but the class is already instantiated, set up and used; so it's really not going to fire anything.
Hence i don't think it's possible to override the core/cache. You'll have to move it to the app/code/local. Pitty.

netbeans, xml autocomplete for attributes fails for default namespace

I've defined two namespaces: beans, aop.
If you cut & paste into a Netbeans the tag that i've written below, and you try to edit a tag inside beans:beans you should observe this behavior:
<beans:import />
typing this the autocomplete assists you, and after the element name, it proposes the list of attributes (in this case just one).
<aspectj-autoproxy />
typing this the autocomplete dosn't propose the list of attributes (there are two attributes: proxy-target-class, expose-proxy)
It happens for the attributes of the default namespace's elements.
Is it a bug? Am I doing something wrong?
I've tested on NB 6.9 and NB 7.0
thanks in advance
<beans:beans
xmlns:beans ="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
try here
</beans:beans>