Difference between revisions of "Globalyzer in IDE"
(→How do I install Globalyzer Lite?) |
|||
Line 72: | Line 72: | ||
<code>$ replace_xml_token "report-type" "ScanDetailedXML"</code> |
<code>$ replace_xml_token "report-type" "ScanDetailedXML"</code> |
||
+ | |||
+ | == Lite Ignore== |
||
+ | When using Lite in an IDE (see https://www.globalyzer.com/gzserver/help/referenceLite/globalyzer-lite-IDE-usage.html ), you can use the power of the IDE to mark some issues in the code as to be ignored. Globalyzer uses a set of standard comments, namely <code>$NON-NLS-L$</code>. There are many ways to do so. We will illustrate one such way with Lite in Eclipse. |
||
+ | = Lite is set in Eclipse = |
||
+ | To set Lite in your Eclipse environment, refer to https://www.globalyzer.com/gzserver/help/referenceLite/globalyzer-lite-IDE-usage.html#Eclipse ; There are two sections, one for Linux, one for Windows. |
||
+ | |||
+ | |||
+ | [[File:LiteConfigured.gif]] |
||
+ | |||
+ | = Run Lite = |
||
+ | * Select the directory or file you want to analyze |
||
+ | * Click on the external tools button |
||
+ | |||
+ | => Lite analyzes the relevant files based on the Globalyzer Project Definition file and shows the clickable results in the Console view. |
||
+ | |||
+ | [[File:LiteRun.gif]] |
||
+ | |||
+ | = Navigate to the Issue = |
||
+ | * Click on the issue in the Console |
||
+ | |||
+ | => It opens the file and highlights the line with the issue. |
||
+ | |||
+ | = Refactor the Code or Ignore the Issue= |
||
+ | Depending on what the developer sees, the issue either needs to be refactored or ignored. If the issue needs to be ignored, the //$NON-NLS-L$ comment needs to be added at the end of that line. One can simply add it by typing it. Some short cut exist and some can be created. For instance: |
||
+ | |||
+ | * Go to the end of the line to ignore and type <Ctr><Space> |
||
+ | * Choose "nls - non externalize string marker" in the list of templates. |
||
+ | |||
+ | or |
||
+ | |||
+ | * Add the string "nls" and type <Ctr><Space> |
||
+ | * Eclipse proposes the standard $NLS notation by default. Select that notation and type L. |
||
+ | |||
+ | [[File:LiteNlsCtrSpace.gif]] |
||
+ | |||
+ | |||
+ | |||
+ | The line now reads: |
||
+ | <code>Locale locale = new Locale("en", "US"); //$NON-NLS-L$</code> |
||
+ | |||
+ | * Repeat the process for other false positives |
||
+ | |||
+ | Lines tagged with the <code>//$NON-NLS-L$</code> will be ignored by Globalyzer the next time you run the Lite external tool. |
||
+ | |||
+ | = Advanced Template = |
||
+ | The previous illustration was done using the default template. You can modify the template to have directly <code>//$NON-NLS-L$</code> on other key combination or the same <code>nls<Ctr><Space></code>. |
||
+ | |||
+ | The following image shows how to use <code>nll<Ctr><Space></code> to insert directory <code>//$NON-NLS-L$</code>. |
||
+ | |||
+ | [[File:NllTemplate.gif]] |
||
+ | |||
+ | |||
+ | |||
+ | This is one way of adding <code>//$NON-NLS-L$</code> at the end of the line. Some developers will decide on other methods. |
Revision as of 22:22, 12 June 2019
Contents
- 1 Can I use Globalyzer Lite with my standard IDE?
- 2 Using Globalyzer Lite from an Integrated Development Environment
- 3 How do I install Globalyzer Lite?
- 4 Sharing Project Definition Files Between IDEs and Build Systems
- 5 Lite Ignore
- 6 Lite is set in Eclipse
- 7 Run Lite
- 8 Navigate to the Issue
- 9 Refactor the Code or Ignore the Issue
- 10 Advanced Template
Can I use Globalyzer Lite with my standard IDE?
The Globalyzer Lite client can be used with Eclipse, Visual Studio and IntelliJ IDEs.
Using Globalyzer Lite from an Integrated Development Environment
Globalyzer Lite may be used within many IDEs that support external tools, including Visual Studio, IntelliJ IDEA, and Eclipse. Configuring Lite as an external tool takes some initial setup, but is relatively easy to accomplish. Once configured, Lite may be used through the IDE's external tool menu with the click of a button. The recommended, documented tools:
- Scan the currently selected file/directory.
- Scan everything within the parent directory of the currently selected file/directory.
- Scan the entire project.
Demonstration videos are available for:
To configure Lite in the IDE, please see this page: Lite IDE Usage.
The developer can then use the power of the IDE to refactor the relevant issues or to mark false positives in the code using Globalyzer ignore comments, such as $NON-NLS-L$. For more information, see the Globalyzer Comment Tags in False Positives .
Those refactoring and the comment tags are now part of the code: The Continuous Globalization System using the same Lite project definition file will show the same results in the Dashboard.
How do I install Globalyzer Lite?
To install the Globalyzer Lite, you first need a Globalyzer account (see this FAQ). Once you have an account, you log into the Globalyzer Server and at the bottom of your home page there is a link to download Globalyzer Lite.
The Globalyzer Lite is a standalone Java application. It uses Rule Sets to scan code at the command line. It is used in Jenkins configured for the Continuous G11n System and can be integrated as an external tool in an IDE.
Please see installation for complete Globalyzer Lite download/installation instructions.
To install:
- Unzip the Globalyzer Lite zip file at a desired location
- Run either
lite-setup.bat
orlite-setup.sh
depending on your system.
To verify the installation, from a command line at the location that it was installed:
java -jar globalyzer-lite.jar -version
or, show the help info:
java -jar globalyzer-lite.jar -help
Sharing Project Definition Files Between IDEs and Build Systems
It is common to check in a single project definition file per code repository. However, the desired IDE configuration may sometimes be incompatible with the desired build system configuration.
These incompatibilities are best solved by modifying the project definition file within the build system. The IDE config can then be used as the default.
Here is an example: The desired report type for Globalyzer Lite may be ScanDetailedCSV for developer usage, but will need to be ScanDetailedXML within the build system. The project definition file would then be written out with the <report-type> set to ScanDetailedCSV:
<gzproject> ... <report-type>ScanDetailedCSV</report-type> ... </gzproject>
The build system can then be set to auto-replace "ScanDetailedCSV" with "ScanDetailedXML". The following Linux command will do so:
$ sed --in-place 's|ScanDetailedCSV|ScanDetailedXML|' $WORKSPACE/ProjectDefinition.xml
If desired, the opposite replacement also may be performed at the end of the build.
Finally, here is a bash function to replace the content of any XML field:
replace_xml_token() { token_name=$1 new_content=$2 sed -ri "s|(<${token_name}>).*(</${token_name}>)|\1${new_content}\2|g" $WORKSPACE/ProjectDefinition.xml }
It may be used like so:
$ replace_xml_token "report-type" "ScanDetailedXML"
Lite Ignore
When using Lite in an IDE (see https://www.globalyzer.com/gzserver/help/referenceLite/globalyzer-lite-IDE-usage.html ), you can use the power of the IDE to mark some issues in the code as to be ignored. Globalyzer uses a set of standard comments, namely $NON-NLS-L$
. There are many ways to do so. We will illustrate one such way with Lite in Eclipse.
Lite is set in Eclipse
To set Lite in your Eclipse environment, refer to https://www.globalyzer.com/gzserver/help/referenceLite/globalyzer-lite-IDE-usage.html#Eclipse ; There are two sections, one for Linux, one for Windows.
Run Lite
- Select the directory or file you want to analyze
- Click on the external tools button
=> Lite analyzes the relevant files based on the Globalyzer Project Definition file and shows the clickable results in the Console view.
- Click on the issue in the Console
=> It opens the file and highlights the line with the issue.
Refactor the Code or Ignore the Issue
Depending on what the developer sees, the issue either needs to be refactored or ignored. If the issue needs to be ignored, the //$NON-NLS-L$ comment needs to be added at the end of that line. One can simply add it by typing it. Some short cut exist and some can be created. For instance:
- Go to the end of the line to ignore and type <Ctr><Space>
- Choose "nls - non externalize string marker" in the list of templates.
or
- Add the string "nls" and type <Ctr><Space>
- Eclipse proposes the standard $NLS notation by default. Select that notation and type L.
The line now reads:
Locale locale = new Locale("en", "US"); //$NON-NLS-L$
- Repeat the process for other false positives
Lines tagged with the //$NON-NLS-L$
will be ignored by Globalyzer the next time you run the Lite external tool.
Advanced Template
The previous illustration was done using the default template. You can modify the template to have directly //$NON-NLS-L$
on other key combination or the same nls<Ctr><Space>
.
The following image shows how to use nll<Ctr><Space>
to insert directory //$NON-NLS-L$
.
This is one way of adding //$NON-NLS-L$
at the end of the line. Some developers will decide on other methods.