The Liferay Core Development Environment includes a tool called 'Format Source' that checks several of the Java Coding Style conventions. Run it always before committing code or sending a patch.

From the command line #

cd portal-impl
ant format-source

The output will be similar to:

  [java] Java2HTML: portal-ejb/src/com/liferay/portlet/mail/util/multiaccount/MyCustomAccountFinder.java
  [java] (c): portal-kernel/src/com/liferay/portal/kernel/cal/Recurrence.java
  [java] > 80: portal-impl/src/com/liferay/portlet/journal/service/impl/JournalTemplateLocalServiceImpl.java 113
  [java] > 80: util-bridges/src/com/liferay/util/bridges/jsf/icefaces/FileUploadManagedBean.java 62
  [java] ./portal-web/docroot/html/common/themes/top_js.jspf
  [java] ./portal-web/docroot/html/portlet/layout_configuration/view_category.jsp
  [java] tab: portal-impl/src/com/liferay/portlet/messageboards/messaging/MessageListener.java

The characters after [java] gives you information. The meaning of the most important ones are:

Code Meaning
'.' Means that you've modified this file. These are the only files that you should care about in the output. Ignore all others
>80 There are some lines that exceed the 80 columns rule. Fix them.
(c) The copyright message is missing or incorrect
Java2HTML The class Javadoc is not correct
tab Means that you are using space instead of tab to indent. Fix them.
} Means that you are missing a blank line before the last curly brace of your class
xss(variable) Means that you have a vulnerability in your code as you haven't scaped a variable that might have malicious code and is sent to the server. This variable is indicated in brackets.
taglib wrong use of nested quotes in a taglib in this line

From your favorite IDE #

Navigate to:

SourceFormatterTest

Run the test. (In Eclipse: Right-click, "Debug as JUnit test")

This does almost exactly the same as running "ant format-source" from the command line, without having to leave the IDE. If your Portal source code complies with Liferay coding conventions, the test will pass. If not, the test will fail and display the full list of non-compliances.

However, this test will not fix problems in your source files automatically like the command line would. Instead, the test will fail with a full diff showing the locations where code needs to be changed. If you wish, you can examine the non-compliances and fix them yourself, or instead you can switch to the command line and let Source Formatter do it.

Protip: Test failing but you can't guess exactly what rule it is you're breaking? Place a breakpoint at:

com.liferay.portal.tools.sourceformatter.BaseSourceProcessor.processErrorMessage(String, String)

Then follow the stacktrace until you find the rule.

Fast format-source for IntelliJ #

Fast format-source (for Liferay developers and contributors)

Promedio (1 Votar)
La valoración media es de 5.0 estrellas de 5.
Comentarios
No hay ningún comentario aún. Sea usted el primero.