Giter Club home page Giter Club logo

coding-rules's Introduction

coding-rules

Configuration files used to enforce our coding guidelines / formatting

Clone this project

  • git clone this project somewhere on your PC

Intellij User

  • Use File > Import settings and select settings.jar to import the settings in IntelliJ IDEA.

  • (Optional if you have already the "Eclipse code formatter" plugin installed) Install Eclipse Code Formatter plugin from the Plugins dialog screen:

    • on MacOS: Preferences -> Plugins
    • on GNU/Linux: File -> Settings -> Plugins
    • on Microsoft Windows: File -> Settings

    Click on Browse repositories, search for "Eclipse Code Formatter" and click on Install. To load this new plugin, you will need to restart IntelliJ.

  • Open up the Eclipse Code Formatter dialog screen:

    • on MacOS: Preferences -> Eclipse Code Formatter
    • on GNU/Linux: File -> Settings -> Eclipse Code Formatter
    • on Microsoft Windows: File -> Settings -> Other Settings -> Eclipse Code Formatter
  • Enable the plugin by ticking "Use the Eclipse code formatter"

  • Setting "Eclipse Java Formatter config file" by using the src/main/resource/ProactiveCodeFormatter.xml

  • Make sure the ProActive Rules is selected as "Java formatter profile"

  • Tick "Optimize Imports"

  • Select "Import order from file", which uses src/main/resources/proactive.importorder

  • Click on Apply or OK

  • Make sure that the selected Code Style Scheme is "Proactive" by opening the Code Style dialog screen:

    • on MacOS: Preferences -> Editor -> Code Style
    • on GNU/Linux: File -> Settings -> Editor -> Code Style

Eclipse User

Download Eclipse_Preferences.epf file (https://github.com/ow2-proactive/coding-rules/blob/master/Eclipse_Preferences.epf), and import it by doing in Eclipse: File > Import > General > Preferences, browse to file and Finish. This epf file contains already the ProactiveCodeFormatter.xml, no need to import the formatter again.

Code format during the project build

1.Merge the following buildscript into your project's build.gradle file

buildscript {
    repositories {
        maven { 
            url "https://plugins.gradle.org/m2/"
        }
        maven {        
            url "http://repository.activeeon.com/content/groups/proactive/"
        }       
    }

    dependencies {
        classpath "com.diffplug.gradle.spotless:spotless:2.4.0"
        classpath "org.ow2.proactive:coding-rules:1.0.0"
        delete "gradle/ext"
        ant.unjar src: configurations.classpath.find { it.name.startsWith("coding-rules") }, dest: 'gradle/ext'
    }
}

2.Apply the code format plugin in your project's build.gradle file with

apply from: "$rootDir/gradle/ext/coding-format.gradle"

3.Update your project's .gitignore by adding the line below to ignore the temporary folder

gradle/ext/

4.Build your project as usual, if any java files are bad formatted, build will fail with messages telling you to build again with task "spotlessApply".

5.Build again with either the custom task "formatCode" (defined in coding-format.gradle) or plugin task "spotlessApply" will automatically format your whole project.

Issue you may have after having applied the changes

1. gradle build failure

Some projects may have a build exception after having applied the changes above, the exception message looks like the following

An exception occurred applying plugin request [id: 'org.sonarqube', version: '2.2.1']
> Cannot change dependencies of configuration ':classpath' after it has been resolved.

This is because the sonarqube plugin is applied within the "plugins" block like this

plugins {
    id 'org.sonarqube' version '2.2.1'
}

The only way to solve this issue so far is to apply the plugin in the traditional manner, add dependencies in the "buildscript" block like this

dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
    }

then apply the plugin like this

apply plugin: 'org.sonarqube'

2. Code format check failure in windows

Due to the fact that the line ending character used in windows and in linux is different, the code format check might be failed in Windows environment.

The fix is to create .gitattributes file in the project's root path with the following content, this will force git to use the fix line ending character while checking out the project.

*.java eol=lf
*.gradle eol=lf
*.sh eol=lf
*.md eol=lf

*.bat eol=crlf

*.png binary
*.jpg binary

Run the following git commands on the jenkins windows slave machine to apply the .gitattributes rules inside the git local working directory, otherwise the current working directory will still have the windows line ending character.

  1. git rm --cached -r .
  2. git reset --hard

The jenkins workspace directory is kind of like C:\jenkins\workspace\${project_name}\jdk\JDK8\label\Windows

coding-rules's People

Contributors

paraita avatar yinan-liu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.