You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bu...@apache.org on 2017/03/07 07:50:35 UTC

svn commit: r1007872 - in /websites/staging/sling/trunk/content: ./ documentation/development/jsr-305.html

Author: buildbot
Date: Tue Mar  7 07:50:35 2017
New Revision: 1007872

Log:
Staging update by buildbot for sling

Modified:
    websites/staging/sling/trunk/content/   (props changed)
    websites/staging/sling/trunk/content/documentation/development/jsr-305.html

Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Mar  7 07:50:35 2017
@@ -1 +1 @@
-1785662
+1785804

Modified: websites/staging/sling/trunk/content/documentation/development/jsr-305.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/development/jsr-305.html (original)
+++ websites/staging/sling/trunk/content/documentation/development/jsr-305.html Tue Mar  7 07:50:35 2017
@@ -119,8 +119,12 @@ h2:hover > .headerlink, h3:hover > .head
 <li><a href="#introduction">Introduction</a></li>
 <li><a href="#annotations">Annotations</a></li>
 <li><a href="#use-with-eclipse">Use With Eclipse</a></li>
-<li><a href="#use-with-findbugs">Use With Findbugs</a></li>
-<li><a href="#use-with-maven">Use With Maven</a></li>
+<li><a href="#use-with-maven">Use With Maven</a><ul>
+<li><a href="#leveraging-eclipse-jdt-compiler-recommended">Leveraging Eclipse JDT Compiler (recommended)</a></li>
+<li><a href="#leveraging-findbugs">Leveraging FindBugs</a></li>
+</ul>
+</li>
+<li><a href="#use-with-findbugs">Use With FindBugs</a></li>
 <li><a href="#use-with-sonarqube">Use with SonarQube</a></li>
 </ul>
 </div>
@@ -137,29 +141,50 @@ h2:hover > .headerlink, h3:hover > .head
 <h1 id="use-with-eclipse">Use With Eclipse<a class="headerlink" href="#use-with-eclipse" title="Permanent link">&para;</a></h1>
 <p>Eclipse since Juno supports <a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcompiler%2Fref-preferences-errors-warnings.htm&amp;anchor=null_analysis">null analysis based on any annotations</a>. Those need to be enabled in 
 <em>Preferences-&gt;Java-&gt;Compiler-&gt;Errors/Warnings</em> via <strong>Enable annoation-based null analysis</strong>.
-Also the annotations need to be configured. For Sling those are</p>
+Also the annotations need to be configured. For Sling/JSR 305 those are</p>
 <ul>
-<li><code>javax.annotation.CheckForNull</code> as <strong>'Nullable' annotation</strong></li>
-<li><code>javax.annotation.Nonnull</code> as <strong>'NonNull' annotation</strong></li>
+<li><code>javax.annotation.CheckForNull</code> as <strong>'Nullable' annotation</strong> (primary annotation)</li>
+<li><code>javax.annotation.Nonnull</code> as <strong>'NonNull' annotation</strong> (primary annotation)</li>
 </ul>
 <p><img alt="Eclipse Settings for Null analysis" src="eclipse-settings-null-analysis.png" /></p>
 <p>Unfortunately Eclipse cannot infer information about fields which are for sure either null or not null (reasoning is available in <a href="https://wiki.eclipse.org/JDT_Core/Null_Analysis/Options#Risks_of_flow_analysis_for_fields">https://wiki.eclipse.org/JDT_Core/Null_Analysis/Options#Risks_of_flow_analysis_for_fields</a> and <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=247564">Eclipse Bug 247564</a>). This also affecs constants (static final fields) or enums which are known to be non null, but still Eclipse will emit a warning like <em>The expression of type 'String' needs unchecked conversion to conform to '@Nonnull String'</em>. The only known workaround is to disable the <strong>"Unchecked conversion from non-annotated type to @NonNull type"</strong> or to annotate also the field with <code>@Nonnull</code>.</p>
 <p>More information are available at <a href="https://wiki.eclipse.org/JDT_Core/Null_Analysis">https://wiki.eclipse.org/JDT_Core/Null_Analysis</a>.</p>
-<p>Since Eclipse 4.5 (Mars) external annotations are supported as well (i.e. annotations maintained outside of the source code of the libraries, e.g. for the JRE, Apache Commons Lang). There are some external annotations being mainted at <a href="http://www.lastnpe.org/">lastnpe.org</a> and <a href="https://github.com/tracecompass/tracecompass/tree/master/common/org.eclipse.tracecompass.common.core/annotations">TraceCompass</a>.
-The former provides also some m2e extension to ease setting up the classpaths with external annotations from within your pom.xml.</p>
-<h1 id="use-with-findbugs">Use With Findbugs<a class="headerlink" href="#use-with-findbugs" title="Permanent link">&para;</a></h1>
-<p>Findbugs evaluates the used annotations by default. You can restrict the rules to only the ones which check for those annotations, which are</p>
-<ul>
-<li>InconsistentAnnotations</li>
-<li>NoteUnconditionalParamDerefs</li>
-<li>FindNullDeref</li>
-<li>FindNullDerefsInvolvingNonShortCircuitEvaluation</li>
-</ul>
-<p>A complete list of visitors class names in Findbugs can be found in the <a href="https://code.google.com/p/findbugs/source/browse/#git%2Ffindbugs%2Fsrc%2Fjava%2Fedu%2Fumd%2Fcs%2Ffindbugs%2Fdetect%253Fstate%253Dclosed">sourcecode</a>. The according <a href="http://findbugs.sourceforge.net/bugDescriptions.html">bug patterns</a> have an identifier (in parenthesis) for which you can search in the according Java classes, in case you want to extend the checks.</p>
-<p>Findbugs is also integrated in <a href="http://docs.sonarqube.org/display/SONAR/Findbugs+Plugin">SonarQube</a> but for SonarQube you should now rather use the native Java plugin 
-(look at <a href="#use-with-sonarqube">Use with SonarQube</a>).</p>
+<p>Since Eclipse 4.5 (Mars) <strong>external annotations</strong> are supported as well (i.e. annotations maintained outside of the source code of the libraries, e.g. for the JRE, Apache Commons Lang). There are some external annotations being mainted at <a href="http://www.lastnpe.org/">lastnpe.org</a> and <a href="https://github.com/tracecompass/tracecompass/tree/master/common/org.eclipse.tracecompass.common.core/annotations">TraceCompass</a>. There is no official repository yet though (<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=449653">Eclipse Bug 449653</a>).
+<a href="http://www.lastnpe.org/">Lastnpe.org</a> provides also an m2e extension to ease setting up the classpaths with external annotations from within your pom.xml.</p>
 <h1 id="use-with-maven">Use With Maven<a class="headerlink" href="#use-with-maven" title="Permanent link">&para;</a></h1>
-<p>You can also let Maven automatically run Findbugs to execute those checks via the <strong>findbugs-maven-plugin</strong>. For that just add the following plugin to your <code>pom.xml</code></p>
+<h2 id="leveraging-eclipse-jdt-compiler-recommended">Leveraging Eclipse JDT Compiler (recommended)<a class="headerlink" href="#leveraging-eclipse-jdt-compiler-recommended" title="Permanent link">&para;</a></h2>
+<p>You can use Eclipse JDT also in Maven (with null analysis enabled) for the compilation in Maven as well. That way it will give out the same warnings/errors as Eclipse and will also consider external annotations.
+JDT in its most recent version is provided by the <code>tycho-compiler-plugin</code> which can be hooked up with the <code>maven-compiler-plugin</code>.
+The full list of options for JDT is described in <a href="http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_batch_compiler.htm">here</a>.</p>
+<div class="codehilite"><pre><span class="nt">&lt;plugin&gt;</span>
+  <span class="nt">&lt;artifactId&gt;</span>maven-compiler-plugin<span class="nt">&lt;/artifactId&gt;</span>
+  <span class="nt">&lt;version&gt;</span>3.5.1<span class="nt">&lt;/version&gt;</span>
+  <span class="nt">&lt;configuration&gt;</span>
+    <span class="nt">&lt;source&gt;</span>1.8<span class="nt">&lt;/source&gt;</span>
+    <span class="nt">&lt;target&gt;</span>1.8<span class="nt">&lt;/target&gt;</span>
+    <span class="nt">&lt;showWarnings&gt;</span>true<span class="nt">&lt;/showWarnings&gt;</span>
+    <span class="nt">&lt;compilerId&gt;</span>jdt<span class="nt">&lt;/compilerId&gt;</span>
+    <span class="nt">&lt;compilerArguments&gt;</span>
+      <span class="c">&lt;!-- just take the full Maven classpath as external annotations --&gt;</span>
+      <span class="nt">&lt;annotationpath&gt;</span>CLASSPATH<span class="nt">&lt;/annotationpath&gt;</span>
+    <span class="nt">&lt;/compilerArguments&gt;</span>
+    <span class="c">&lt;!-- maintain the org.eclipse.jdt.core.prefs properties to options listed on</span>
+<span class="c">         http://help.eclipse.org/neon/index.jsp?topic=/org.eclipse.jdt.doc.user/tasks/task-using_batch_compiler.htm --&gt;</span>
+    <span class="nt">&lt;compilerArgument&gt;</span>-err:nullAnnot,null,-missingNullDefault<span class="nt">&lt;/compilerArgument&gt;</span>
+ <span class="nt">&lt;/configuration&gt;</span>
+ <span class="nt">&lt;dependencies&gt;</span>
+    <span class="nt">&lt;dependency&gt;</span>
+       <span class="nt">&lt;groupId&gt;</span>org.eclipse.tycho<span class="nt">&lt;/groupId&gt;</span>
+       <span class="nt">&lt;artifactId&gt;</span>tycho-compiler-jdt<span class="nt">&lt;/artifactId&gt;</span>
+       <span class="nt">&lt;version&gt;</span>1.0.0<span class="nt">&lt;/version&gt;</span>
+    <span class="nt">&lt;/dependency&gt;</span>
+  <span class="nt">&lt;/dependencies&gt;</span>
+<span class="nt">&lt;/plugin&gt;</span>
+</pre></div>
+
+
+<h2 id="leveraging-findbugs">Leveraging FindBugs<a class="headerlink" href="#leveraging-findbugs" title="Permanent link">&para;</a></h2>
+<p>You can also let Maven automatically run FindBugs to execute those checks via the <strong>findbugs-maven-plugin</strong>. For that just add the following plugin to your <code>pom.xml</code></p>
 <div class="codehilite"><pre><span class="nt">&lt;plugin&gt;</span>
   <span class="nt">&lt;groupId&gt;</span>org.codehaus.mojo<span class="nt">&lt;/groupId&gt;</span>
   <span class="nt">&lt;artifactId&gt;</span>findbugs-maven-plugin<span class="nt">&lt;/artifactId&gt;</span>
@@ -180,10 +205,21 @@ The former provides also some m2e extens
 
 
 <p>The results are often very imprecise (<a href="http://jira.codehaus.org/browse/MFINDBUGS-208">MFINDBUGS-208</a>), especially when it comes to line numbers, therefore it is best to start the Findbugs GUI in case of errors found by this plugin via <code>mvn findbugs:gui</code>.</p>
+<h1 id="use-with-findbugs">Use With FindBugs<a class="headerlink" href="#use-with-findbugs" title="Permanent link">&para;</a></h1>
+<p>FindBugs evaluates the JSR-305 annotations by default. You can restrict the rules to only the ones which check for those annotations, which are</p>
+<ul>
+<li>InconsistentAnnotations</li>
+<li>NoteUnconditionalParamDerefs</li>
+<li>FindNullDeref</li>
+<li>FindNullDerefsInvolvingNonShortCircuitEvaluation</li>
+</ul>
+<p>A complete list of visitors class names in Findbugs can be found in the <a href="https://code.google.com/p/findbugs/source/browse/#git%2Ffindbugs%2Fsrc%2Fjava%2Fedu%2Fumd%2Fcs%2Ffindbugs%2Fdetect%253Fstate%253Dclosed">sourcecode</a>. The according <a href="http://findbugs.sourceforge.net/bugDescriptions.html">bug patterns</a> have an identifier (in parenthesis) for which you can search in the according Java classes, in case you want to extend the checks.</p>
+<p>Findbugs is also integrated in <a href="http://docs.sonarqube.org/display/SONAR/Findbugs+Plugin">SonarQube</a> but for SonarQube you should now rather use the native Java plugin 
+(look at <a href="#use-with-sonarqube">Use with SonarQube</a>).</p>
 <h1 id="use-with-sonarqube">Use with SonarQube<a class="headerlink" href="#use-with-sonarqube" title="Permanent link">&para;</a></h1>
 <p>At least rule <a href="https://sonarqube.com/coding_rules#rule_key=squid%3AS2259">squid:S2259</a> in SonarQube supports JSR 305 annotations as well for null checks.</p>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1785656 by kwin on Mon, 6 Mar 2017 14:33:24 +0000
+        Rev. 1785804 by kwin on Tue, 7 Mar 2017 07:50:17 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project