Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleMaven Plugins to Reformat Java code

Using the Eclipse Formatter file above and maven plugin configuration in pom.xml as per pom.xml 

(https://code.revelc.net/formatter-maven-plugin/ for Eclipse formatter and https://github.com/diffplug/spotless/tree/master/plugin-maven for import order)

Code Block
languagexml
titleExample pom.xml configuration
collapsetrue
            <plugins>
                <!--
                Using https://code.revelc.net/formatter-maven-plugin/ for Eclipse formatter
                Using https://github.com/diffplug/spotless/tree/master/plugin-maven for import order
                Use in combination to rewrite code and imports, then checkstyle
                
                mvn formatter:format spotless:apply process-sources
                -->
                <plugin>
                     <groupId>net.revelc.code.formatter</groupId>
                     <artifactId>formatter-maven-plugin</artifactId>
                     <version>2.8.1</version>
                     <configuration>
                        <configFile>${project.parent.basedir}/onap-java-formatter.xml</configFile>
                     </configuration>
                     <!-- https://code.revelc.net/formatter-maven-plugin/
                          use mvn formatter:format to rewrite source files
                          use mvn formatter:validate to validate source files -->
                 </plugin>
                <plugin>
                  <groupId>com.diffplug.spotless</groupId>
                  <artifactId>spotless-maven-plugin</artifactId>
                  <version>1.18.0</version>
                  <configuration>
                    <java>
                     <importOrder>
                       <order>com,java,javax,org</order>
                     </importOrder>
                    </java>
                  </configuration>
                <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven
                     use mvn spotless:apply to rewrite source files
                     use mvn spotless:check to validate source files -->
                </plugin>
            </plugins>


the The combination can be used in a maven command to rewrite code and imports, then checkstyle audit like so

Code Block
titleExample maven command
mvn formatter:format spotless:apply process-sources


...

Your projects should be imported in to Eclipse before this.


Expand
titleClick here to view detailed steps...
  • Right click on the project and select "SonarLint -> Bind to SonarQube or SonarCloud...".
  • Select "sonarcloud" and press "Next".
  • Click "Generate Token"
  • A browser opens and you are taken to a Sonarcloud login page
  • Login with an appropriate account from the list presented, most likely your GitHub account
  • You are now directed to a sonarcloud token generation page
  • Enter a name for your token and click "Generate"
  • Copy the token hex string that is generated from the browser and paste it into the "Token" field in Eclipse and click "Next"
  • In the "Organization" field, enter the string "onap" and press "Next"
  • The Connection name "SonarCloud/onap" should be found by the system, click "Next"
  • The connection should be successfully created, click "Finish"
  • Press "Add...".
  • Select the projects you want to add and press "OK".
  • Press "Next".
  • Start typing the name of your project, and it should appear in a list box where it should be selected.
  • Press "Finish".

...

In a shell, type the following command (assumes you installed python above) :  



Code Block
pip3 install git-review




To use git review, you have to be in a Git clone directory that already contains a (possibly hidden) .gitreview configuration file (see Gerrit/Advanced usage#Setting up a repository for git-remote)

...