Difference between revisions of "Globalyzer in IDE"

From Lingoport Wiki
Jump to: navigation, search
(Globalyzer Lite Plugin for VSCode)
(Globalyzer Lite Plugin for VSCode)
Line 176: Line 176:
 
}
 
}
 
</code>
 
</code>
**“label” is the name of the task - this can be changed to whatever makes the most sense
+
*“label” is the name of the task - this can be changed to whatever makes the most sense
“type” specifies that the command should be run in a shell - required
+
*“type” specifies that the command should be run in a shell - required
“command” is the command to execute in the shell - required
+
*“command” is the command to execute in the shell - required
“problemMatcher” used to auto-format the output,
+
*“problemMatcher” used to auto-format the output,
“args” specifies the arguments to be passed to the command at execution
+
*“args” specifies the arguments to be passed to the command at execution
“value” contains the actual arguments
+
*“value” contains the actual arguments
-jar specifies the jar to execute
+
**-jar specifies the jar to execute
Replace 'path/to/globalyzer-lite.jar' with the absolute path to your globalyzer-lite.jar.
+
***Replace 'path/to/globalyzer-lite.jar' with the absolute path to your globalyzer-lite.jar.
‘C:\Lingoport\globalyzer-lite-x.y.z\globalyzer-lite.jar’
+
***‘C:\Lingoport\globalyzer-lite-x.y.z\globalyzer-lite.jar’
-f is the name of the Project Definition file
+
**-f is the name of the Project Definition file
Replace the ‘/path/to/LiteProjectDefinition.xml’ with the workspace relative path of your Project Definition file
+
***Replace the ‘/path/to/LiteProjectDefinition.xml’ with the workspace relative path of your Project Definition file
E.g. ${workspaceFolder}/lingoport/LiteProjectDefinition.xml
+
***E.g. ${workspaceFolder}/lingoport/LiteProjectDefinition.xml
--project-path is the path of this project
+
**--project-path is the path of this project
Leave this as the ${workspaceFolder} VSCode environment variable
+
***Leave this as the ${workspaceFolder} VSCode environment variable
--scan-items Overrides the default settings for which files and directories to scan
+
**--scan-items Overrides the default settings for which files and directories to scan
Use ${file} to scan only the currently selected file in VSCode
+
***Use ${file} to scan only the currently selected file in VSCode
--console-output prints scan report output to console with specified format.
+
**--console-output prints scan report output to console with specified format.
Leave as "visual-studio" - format report output for visual studio. This allows the user to click on a candidate issue in the output and jump to its location within a file.
+
***Leave as "visual-studio" - format report output for visual studio. This allows the user to click on a candidate issue in the output and jump to its location within a file.
“quoting” specifies how to handle quoting within the args - required as “weak”
+
*“quoting” specifies how to handle quoting within the args - required as “weak”
“presentation” configures how the workspace should handle displaying the task as it executes
+
*“presentation” configures how the workspace should handle displaying the task as it executes
“problemMatcher” uses a regular expression to extract the problems found in the scan and display them in the problems panel
+
*“problemMatcher” uses a regular expression to extract the problems found in the scan and display them in the problems panel

Revision as of 18:33, 17 October 2019

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:

  1. Scan the currently selected file/directory.
  2. Scan everything within the parent directory of the currently selected file/directory.
  3. 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:

  1. Unzip the Globalyzer Lite zip file at a desired location
  2. Run either lite-setup.bat or lite-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 IDE 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.


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.

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.

LiteNlsCtrSpace.gif


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$.

NllTemplate.gif


This is one way of adding //$NON-NLS-L$ at the end of the line. Some developers will decide on other methods.

Globalyzer Lite Plugin for VSCode

To Configure the Plugin:

  • Install Globalyzer Lite as directed
  • Open your project folder in VSCode
  • Select “Terminal->Configure Tasks” from the top menu bar

Vccode1.png

  • Select “Create tasks.json file from template” from the popup option list

Vccode2.png

  • Select “Others” from the Task Template list

Vccode3.png Vccode4.png

  • Change the default template for the generated tasks.json file to match the following:

{

   "version": "2.0.0",
   "tasks": [
       {
           "label": "GlobalyzerLite",
           "type": "shell",
           "command": "java",
           "args": [
               {
                   "value": "-jar 'C:/Lingoport/globalyzer-lite-6.3.0_5.0/globalyzer-lite.jar' -f ${workspaceFolder}/lingoport/LiteProjectDefinition.xml --project-path ${workspaceFolder} --scan-items ${file} --console-output visual-studio",
                   "quoting": "weak"
               }
           ],
           "presentation": {
               "showReuseMessage": false,
               "clear": true,
               "revealProblems": "onProblem"
           },
           "problemMatcher": {
               "fileLocation": ["absolute"],
               "severity": "warning",
               "pattern": {
                   "regexp": "^(.*)\\((\\d*)\\):\\s+(.*),\\s+(P\\d+):\\s+(.*)",
                   "file": 1,
                   "line": 2,
                   "message": 3,
                   "severity": 4,
                   "code": 5
               }
           }
       }
   ]

}

  • “label” is the name of the task - this can be changed to whatever makes the most sense
  • “type” specifies that the command should be run in a shell - required
  • “command” is the command to execute in the shell - required
  • “problemMatcher” used to auto-format the output,
  • “args” specifies the arguments to be passed to the command at execution
  • “value” contains the actual arguments
    • -jar specifies the jar to execute
      • Replace 'path/to/globalyzer-lite.jar' with the absolute path to your globalyzer-lite.jar.
      • ‘C:\Lingoport\globalyzer-lite-x.y.z\globalyzer-lite.jar’
    • -f is the name of the Project Definition file
      • Replace the ‘/path/to/LiteProjectDefinition.xml’ with the workspace relative path of your Project Definition file
      • E.g. ${workspaceFolder}/lingoport/LiteProjectDefinition.xml
    • --project-path is the path of this project
      • Leave this as the ${workspaceFolder} VSCode environment variable
    • --scan-items Overrides the default settings for which files and directories to scan
      • Use ${file} to scan only the currently selected file in VSCode
    • --console-output prints scan report output to console with specified format.
      • Leave as "visual-studio" - format report output for visual studio. This allows the user to click on a candidate issue in the output and jump to its location within a file.
  • “quoting” specifies how to handle quoting within the args - required as “weak”
  • “presentation” configures how the workspace should handle displaying the task as it executes
  • “problemMatcher” uses a regular expression to extract the problems found in the scan and display them in the problems panel