diff --git a/.github/ISSUE_TEMPLATE/new_rule_suggestion.md b/.github/ISSUE_TEMPLATE/new_rule_suggestion.md new file mode 100644 index 000000000..e1c6b4374 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/new_rule_suggestion.md @@ -0,0 +1,118 @@ +--- +name: New rule suggestion +about: Suggest an new rule idea for this project +title: '' +labels: 'rule' +assignees: '' + +--- + +# {Category: RuleTitle (Variant)} + +## Platform + +| OS | OS version | Langage | +|---------------|--------------|------------| +| {Android/IOS} | {OS version} | {Language} | + +## Main caracteristics + +| ID | Title | Category | Sub-category | +|----------|----------------------|-------------|----------------| +| {id} | {title} | {Category} | {SubCategory} | + +## Severity / Remediation Cost + +- **Case 1**: + | Severity | Remediation Cost | + |------------|---------------------| + | {Severity} | {Remediation_Cost} | +- **Case 2**: + | Severity | Remediation Cost | + |------------|---------------------| + | {Severity} | {Remediation_Cost} | + +## Rule short description + +- **Case 1**: {short description} +- **Case 2**: {short description} + +## Rule complete description + +## Text + +{big description} + +## HTML + + ```html +{html code} +``` + +## Implementation principle + +- {Implementation principe} +- {Implementation principe} + 17 h 17 + voici le template + 17 h 17 + et voici un example : + 17 h 17 + +# Optimized API: List Shallow Copy - Module copy + +## Platform + +| OS | OS version | Langage | +|----------|------------|-----------| +| - | - | Python | + +## Main caracteristics + +| ID | Title | Category | Sub-category | +|---------|----------------------------------|-------------|----------------| +| EOPT001 | List Shallow Copy - Module copy | Environment | Optimized API | + +## Severity / Remediation Cost + +| Severity | Remediation Cost | +|----------|------------------| +| Minor | Minor | + +## Rule short description + +Using `copy.copy(x)` of `module copy` to perform a shallow copy of a list is not energy efficient. + +## Rule complete description + +### Text + +Using `copy.copy(x)` of `module copy` to perform a shallow copy of a list is not energy efficient. +Prefer the usage of `list.copy()` which is more energy friendly. + +### HTML + + ```html +

Using copy.copy(x) of module copy to perform a shallow +copy of a list is not energy efficient.

+

Prefer the usage of list.copy() which is more energy friendly.

+

Noncompliant Code Example

+
+import copy
+ my_list = [1, 2, [3, 4], 5]
+list_copy = copy.copy(my_list)
+
+

Compliant Solution

+
+my_list = [1, 2, [3, 4], 5]
+list_copy = my_list.copy()
+
+``` + +## Implementation principle + +- Inspect the import node to find `copy` import +- Inspect the ARG_LIST node +- If the direct parent is CALL_EXPR tree and the function is `copy.copy()` +- If the function is present, check the first argument +- If it is a list, report the line \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96fd532cd..ae547eab0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,5 @@ name: Build and Tests + on: push: branches: @@ -9,7 +10,8 @@ on: tags: - '[0-9]+.[0-9]+.[0-9]+' pull_request: - types: [opened, synchronize, reopened] + types: [ opened, synchronize, reopened ] + jobs: build: name: Build @@ -18,27 +20,41 @@ jobs: pull-requests: read # allows SonarCloud to decorate PRs with analysis results steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'temurin' java-version: 11 - - name: Cache SonarCloud packages - uses: actions/cache@v1 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - - name: Build and analyze + + - name: Verify + run: mvn -e -B verify + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + + - name: Cache SonarQube packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: SonarQube Scan env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn -e -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode -Dsonar.exclusions=**/*.groovy,**/*.dummy + run: mvn -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c24abca7..2545fc5d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Added - ### Changed +- [ios#3](https://github.com/green-code-initiative/ecoCode-ios/issues/3) Move iOS rules into centralized rules repository +- [android#67](https://github.com/green-code-initiative/ecoCode-android/issues/67) Move Android rules into centralized rules repository +- [#216](https://github.com/green-code-initiative/ecoCode/issues/216) Upgrade rule EC2 for Java : Multiple if-else statement improvment +- [#106](https://github.com/green-code-initiative/ecoCode/issues/106) Upgrade RULES.md : rule EC67 not relevant neither for Python nor Rust +- [#225](https://github.com/green-code-initiative/ecoCode/pull/225) Upgrade licence system and licence headers of Java files +- [#140](https://github.com/green-code-initiative/ecoCode/issues/140) Upgrade rule EC3 for Python : no implementation possible for python +- [#136](https://github.com/green-code-initiative/ecoCode/issues/136) Upgrade rule EC53 for Python : no implementation possible for python +- [#128](https://github.com/green-code-initiative/ecoCode/pull/128) Adding EC35 rule for Python and PHP : EC35 rule replaces EC34 with a specific use case ("file not found" sepcific) + ### Deleted ## [1.4.0] - 2023-08-08 diff --git a/README.md b/README.md index 40b803849..4942fbea7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ refer to the contribution section. - [Java](java-plugin/) - [JavaScript](https://github.com/green-code-initiative/ecoCode-javascript) -- [PHP](php-plugin/) +- [PHP](https://github.com/green-code-initiative/ecoCode-php) - [Python](https://github.com/green-code-initiative/ecoCode-python) ![Screenshot](docs/resources/screenshot.PNG) @@ -78,24 +78,26 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code- | Plugins Version | SonarQube version | |------------------|-----------------------------| -| 0.1.+ | SonarQube 8.9.+ LTS to 9.3 | -| 0.2.+ | SonarQube 9.4.+ LTS to 9.9 | -| 1.0.+ | SonarQube 9.4.+ LTS to 9.9 | -| 1.1.+ | SonarQube 9.4.+ LTS to 9.9 | -| 1.2.+ | SonarQube 9.4.+ LTS to 10.0 | +| 1.4.+ | SonarQube 9.4.+ LTS to 10.1 | | 1.3.+ | SonarQube 9.4.+ LTS to 10.0 | +| 1.2.+ | SonarQube 9.4.+ LTS to 10.0 | +| 1.1.+ | SonarQube 9.4.+ LTS to 9.9 | +| 1.0.+ | SonarQube 9.4.+ LTS to 9.9 | +| 0.2.+ | SonarQube 9.4.+ LTS to 9.9 | +| 0.1.+ | SonarQube 8.9.+ LTS to 9.3 | ☕ Plugin Java part compatibility ------------------ | Plugins Version | Java version | |------------------|--------------| -| 0.1.+ | 11 / 17 | -| 0.2.+ | 11 / 17 | -| 1.0.+ | 11 / 17 | -| 1.1.+ | 11 / 17 | -| 1.2.+ | 11 / 17 | +| 1.4.+ | 11 / 17 | | 1.3.+ | 11 / 17 | +| 1.2.+ | 11 / 17 | +| 1.1.+ | 11 / 17 | +| 1.0.+ | 11 / 17 | +| 0.2.+ | 11 / 17 | +| 0.1.+ | 11 / 17 | 🤝 Contribution --------------- @@ -126,6 +128,7 @@ Then, if no answer, contact ... - [Olivier Le Goaër](https://olegoaer.perso.univ-pau.fr) - [Maxime DUBOIS](https://www.linkedin.com/in/maxime-dubois-%F0%9F%8C%B1-649a3a3/) - [David DE CARVALHO](https://www.linkedin.com/in/david%E2%80%8E-de-carvalho-8b395284/) +- [Maxime MALGORN](https://www.linkedin.com/in/maximemalgorn/) 🧐 Core Team Emeriti -------------------- diff --git a/RULES.md b/RULES.md index 3d03ed6d9..bb4581d9e 100644 --- a/RULES.md +++ b/RULES.md @@ -9,46 +9,47 @@ Some are applicable for different technologies. - 🚀 Rule to implement - 🚫 Non applicable rule -| Rule key | Name | Description | Reference/Validation | Java | Php | JS | Python | Rust | -|----------|------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|-----|----|--------|------| -| | Use official social media sharing buttons | These JavaScript plugins are very resource-intensive: to work, they require a large number of requests and download heavy files. It is better to prefer direct links. | [cnumr best practices (3rd edition) BP_019](https://github.com/cnumr/best-practices/blob/main/chapters/BP_019_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | -| | Non-grouped similar CSS declarations | When multiple Document Object Model (DOM) elements have common CSS properties, declare them together in the same style sheet. This method reduces the weight of CSS. | [cnumr best practices (3rd edition) BP_025](https://github.com/cnumr/best-practices/blob/main/chapters/BP_025_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | -| | CSS shorthand notations not used | Reduces the weight of the style sheet. | [cnumr best practices (3rd edition) BP_026](https://github.com/cnumr/best-practices/blob/main/chapters/BP_026_fr.md) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | -| | CSS print not included | This style sheet reduces the number of pages printed. | [cnumr best practices (3rd edition) BP_027](https://github.com/cnumr/best-practices/blob/main/chapters/BP_027_fr.md) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | -| | Non-standard fonts used | Prefer standard fonts, as they are already present on the user's computer, so they do not need to download them. This saves bandwidth, while speeding up the display of the site. | [cnumr best practices (3rd edition) BP_029](https://github.com/cnumr/best-practices/blob/main/chapters/BP_029_fr.md) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | -| | Non-outsourced CSS and Javascript | If you include CSS or JavaScript code in the body of the HTML file, while the HTML file is used by several pages (or even the entire site), this code must be transferred for each page requested by the user, which increases the volume of data transmitted. | [cnumr best practices (3rd edition) BP_032](https://github.com/cnumr/best-practices/blob/main/chapters/BP_032_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | -| | Resize images browser-side | Do not resize images using the HEIGHT and WIDTH attributes of the HTML code. This approach requires transferring these images to their original size, wasting bandwidth and CPU cycles. | [cnumr best practices (3rd edition) BP_034](https://github.com/cnumr/best-practices/blob/main/chapters/BP_034_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | -| EC10 | Use unoptimized vector images | Less heavy SVG images using less bandwidth | [cnumr best practices (3rd edition) BP_036](https://github.com/cnumr/best-practices/blob/main/chapters/BP_036_fr.md) | 🚧 | 🚀 | 🚀 | ✅ | 🚀 | -| | Using too many CSS/javascript animations | JavaScript/CSS animations can be very expensive in terms of CPU cycles and memory consumption. | [cnumr best practices (3rd edition) BP_039](https://github.com/cnumr/best-practices/blob/main/chapters/BP_039_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | -| | Modify the DOM when traversing it | Modifying the DOM (Document Object Model) as you traverse it can lead to situations where the loop becomes very resource-intensive, especially CPU cycles. | [cnumr best practices (3rd edition) BP_041](https://github.com/cnumr/best-practices/blob/main/chapters/BP_041_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | -| | Edit DOM elements to make it invisible | When an element of the Document Object Model (DOM) needs to be modified by several properties, each change in style or content will generate a repaint or reflow. | [cnumr best practices (3rd edition) BP_042](https://github.com/cnumr/best-practices/blob/main/chapters/BP_042_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | -| | Modify several CSS properties all at once | To limit the number of repaints/reflows, it is recommended not to modify properties one by one. (linter key : `@ecocode/no-multiple-style-changes`) | [cnumr best practices (3rd edition) BP_045](https://github.com/cnumr/best-practices/blob/main/chapters/BP_045_fr.md) | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | -| EC34 | Using try...catch...finally calls | When an exception is thrown, a variable (the exception itself) is created in the catch block and destroyed at the end of the block. Creating this variable and destroying it consumes CPU cycles and RAM unnecessarily. That is why it is important not to use this construction and to prefer, as much as possible, a logical test. | [cnumr best practices (3rd edition) BP_047 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | ✅ | 🚀 | ✅ | 🚀 | -| EC22 | The use of methods for basic operations | Using methods for basic operations consumes additional system resources. The interpreter must in effect and solve the objects and then the methods, just to carry out these simple operations of the language. | [cnumr best practices (3rd edition) BP_048 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | ✅ | 🚀 | 🚀 | 🚀 | -| ??? | Call a DOM element multiple times without caching (linter key : `@ecocode/no-multiple-access-dom-element`) | Access to the Document Object Model (DOM) is costly in terms of CPU resources (CPU cycles). Also, when you use the same DOM element from JavaScript multiple times, store its reference in a variable so that you do not go through the DOM again for the same element. | [cnumr best practices (3rd edition) BP_049](https://github.com/cnumr/best-practices/blob/main/chapters/BP_049_fr.md) | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | -| EC4 | Use global variables | When using a global variable, the interpretation engine must check: 1) that it exists in the current scope, in the one above, etc. ; 2) the variable has a value; 3) ... To avoid all these checks, it is often possible to pass the useful variables as arguments of routines, making them local. This process saves computational time (CPU cycles). | [cnumr best practices (3rd edition) BP_050 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | ✅ | 🚀 | -| EC53 | Using arrays in foreach loops | foreach deduplicates items in a list before starting the enumeration. It is therefore generally more economical to use a simple for loop when you have a good command of the collection. | [cnumr best practices (3rd edition) BP_053 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | 🚀 | 🚀 | 🚀 | 🚀 | -| EC7 | Rewrite native getter/setters | Overloading them lengthens the compilation and execution times of these methods, which are usually much better optimized by the language than by the developer. | [cnumr best practices (3rd edition) BP_062 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | 🚀 | 🚀 | ✅ | 🚀 | -| EC63 | Unnecessarily assigning values to variables | Avoid declaring and using variables when it is not indis-thinkable. Indeed, each allocation corresponds to the RAM occupied. | [cnumr best practices (3rd edition) BP_063 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | 🚀 | 🚀 | 🚀 | 🚀 | -| EC66 | Use single quote (') instead of quotation mark (") | The shape using the quotation marks allows the developer to insert variables that will be substituted at run time. But if the string does not have a variable, use quotes instead. Thus, language will not look for variables to subtituture, which will reduce the consumption of CPU cycles. | [cnumr best practices (3rd edition) BP_066 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | ✅ | 🚀 | ✅ | 🚀 | -| EC67 | Use the $i++ variable during an iteration | The $i++ form has the disadvantage of generating a tem-porary variable during incrementation, which is not the case with the ++$i form. | [cnumr best practices (3rd edition) BP_067 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | 🚀 | 🚀 | -| EC69 | Calling a function in the declaration of a for loop | Avoid calling the function each time the loop is iterated. | [cnumr best practices (3rd edition) BP_069 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | ✅ | 🚀 | -| EC72 | Perform an SQL query inside a loop | Servers are optimized to process multiple selections, insertions, or changes in a single query or transaction. consume CPU cycles, RAM, and bandwidth unnecessarily. | [cnumr best practices (3rd edition) BP_072](https://github.com/cnumr/best-practices/blob/main/chapters/BP_072_fr.md) | ✅ | ✅ | 🚀 | ✅ | 🚀 | -| EC74 | Write SELECT * FROM | The database server must resolve the fields based on the schema. If you are familiar with the diagram, it is strongly recommended to name the fields. | [cnumr best practices (3rd edition) BP_074 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | ✅ | 🚀 | -| EC1 | Calling a Spring repository inside a loop | The use of Spring repository in a loop induces unnecessary calculations by the CPU and therefore superfluous energy consumption. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC3 | Getting the size of the collection in the loop | When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power. | | ✅ | ✅ | 🚀 | 🚀 | 🚀 | -| EC2 | Multiple if-else statement | Using too many conditional if-else statements will impact performance since JVM will have to compare the conditions. Prefer using a switch statement instead of multiple if-else if possible, or refactor your code to reduce conditonnal statements on the same variable. Switch statement has a performance advantage over if – else. | | ✅ | ✅ | 🚀 | 🚧 | 🚀 | -| EC76 | Usage of static collections | Avoid usage of static collections. If you want to use static collections make them final and create for example a singleton if needed containing the collections. The static fields are more complicated for the Garbage Collector to manage and can lead to memory leaks. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC77 | Usage Pattern.compile() in a non-static context | Avoid using Pattern.compile() in a non-static context. This operation requires a non negligible amount of computational power, Using a single match saves CPU cycles and RAM consumption. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC75 | Concatenate Strings in loop | Don't concatenate Strings in loop. User StringBuilder instead. Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC78 | Const parameter in batch update | Don't set const parameter in batch update => Put its in query. Creating this parameter and destroying it consumes CPU cycles and RAM unnecessarily. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC79 | Free resources | try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface, it save computer resources. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC32 | Initialize builder/buffer with the appropriate size | If you know in advance how many characters would be appended, initialize builder/buffer with the appropriate size. They will thus never have to be resized. This saves CPU cycles and therefore consumes less energy. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC28 | Optimize read file exceptions | | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC5 | Usage of preparedStatement instead of Statement | SQL will only commit the query once, whereas if you used only one statement, it would commit the query every time and thus induce unnecessary calculations by the CPU and therefore superfluous energy consumption. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC27 | Usage of system.arraycopy to copy arrays | Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| EC404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | 🚫 | 🚫 | 🚫 | ✅ | 🚫 | -| EC203 | Detect unoptimized file formats | When it is possible, to use svg format image over other image format | | 🚀 | 🚀 | 🚀 | ✅ | 🚀 | -| | Avoid high accuracy geolocation | Avoid using high accuracy geolocation in web applications (linter key : `@ecocode/avoid-high-accuracy-geolocation`) | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | -| | No import all from library | Should not import all from library (linter key : `@ecocode/no-import-all-from-library`) | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | -| | Prefer collections with pagination | Prefer API collections with pagination (linter key : `@ecocode/prefer-collections-with-pagination`) | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | +| Rule key | Name | Description | Reference/Validation | Java | Php | JS | Python | Rust | +|----------|------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|-----|----|--------|------| +| | Use official social media sharing buttons | These JavaScript plugins are very resource-intensive: to work, they require a large number of requests and download heavy files. It is better to prefer direct links. | [cnumr best practices (3rd edition) BP_019](https://github.com/cnumr/best-practices/blob/main/chapters/BP_019_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | +| | Non-grouped similar CSS declarations | When multiple Document Object Model (DOM) elements have common CSS properties, declare them together in the same style sheet. This method reduces the weight of CSS. | [cnumr best practices (3rd edition) BP_025](https://github.com/cnumr/best-practices/blob/main/chapters/BP_025_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | +| | CSS shorthand notations not used | Reduces the weight of the style sheet. | [cnumr best practices (3rd edition) BP_026](https://github.com/cnumr/best-practices/blob/main/chapters/BP_026_fr.md) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | +| | CSS print not included | This style sheet reduces the number of pages printed. | [cnumr best practices (3rd edition) BP_027](https://github.com/cnumr/best-practices/blob/main/chapters/BP_027_fr.md) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | +| | Non-standard fonts used | Prefer standard fonts, as they are already present on the user's computer, so they do not need to download them. This saves bandwidth, while speeding up the display of the site. | [cnumr best practices (3rd edition) BP_029](https://github.com/cnumr/best-practices/blob/main/chapters/BP_029_fr.md) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | +| | Non-outsourced CSS and Javascript | If you include CSS or JavaScript code in the body of the HTML file, while the HTML file is used by several pages (or even the entire site), this code must be transferred for each page requested by the user, which increases the volume of data transmitted. | [cnumr best practices (3rd edition) BP_032](https://github.com/cnumr/best-practices/blob/main/chapters/BP_032_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | +| | Resize images browser-side | Do not resize images using the HEIGHT and WIDTH attributes of the HTML code. This approach requires transferring these images to their original size, wasting bandwidth and CPU cycles. | [cnumr best practices (3rd edition) BP_034](https://github.com/cnumr/best-practices/blob/main/chapters/BP_034_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | +| EC10 | Use unoptimized vector images | Less heavy SVG images using less bandwidth | [cnumr best practices (3rd edition) BP_036](https://github.com/cnumr/best-practices/blob/main/chapters/BP_036_fr.md) | 🚧 | 🚀 | 🚀 | ✅ | 🚀 | +| | Using too many CSS/javascript animations | JavaScript/CSS animations can be very expensive in terms of CPU cycles and memory consumption. | [cnumr best practices (3rd edition) BP_039](https://github.com/cnumr/best-practices/blob/main/chapters/BP_039_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | +| | Modify the DOM when traversing it | Modifying the DOM (Document Object Model) as you traverse it can lead to situations where the loop becomes very resource-intensive, especially CPU cycles. | [cnumr best practices (3rd edition) BP_041](https://github.com/cnumr/best-practices/blob/main/chapters/BP_041_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | +| | Edit DOM elements to make it invisible | When an element of the Document Object Model (DOM) needs to be modified by several properties, each change in style or content will generate a repaint or reflow. | [cnumr best practices (3rd edition) BP_042](https://github.com/cnumr/best-practices/blob/main/chapters/BP_042_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | +| | Modify several CSS properties all at once | To limit the number of repaints/reflows, it is recommended not to modify properties one by one. (linter key : `@ecocode/no-multiple-style-changes`) | [cnumr best practices (3rd edition) BP_045](https://github.com/cnumr/best-practices/blob/main/chapters/BP_045_fr.md) | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | +| EC34 | Using try...catch...finally calls (To be deleted becuse of new one EC35) | When an exception is thrown, a variable (the exception itself) is created in the catch block and destroyed at the end of the block. Creating this variable and destroying it consumes CPU cycles and RAM unnecessarily. That is why it is important not to use this construction and to prefer, as much as possible, a logical test. | [cnumr best practices (3rd edition) BP_047 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | ✅ | 🚀 | ✅ | 🚀 | +| EC35 | Using try...catch calls (on File Not Found Exception) | When an exception is thrown, a variable (the exception itself) is created in the catch block and destroyed at the end of the block. Creating this variable and destroying it consumes CPU cycles and RAM unnecessarily. That is why it is important not to use this construction and to prefer, as much as possible, a logical test. This new rule replace old EC34 only for a particular use case (FileNotFoundException) | [cnumr best practices (3rd edition) BP_047 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | ✅ | 🚀 | ✅ | 🚀 | +| EC22 | The use of methods for basic operations | Using methods for basic operations consumes additional system resources. The interpreter must in effect and solve the objects and then the methods, just to carry out these simple operations of the language. | [cnumr best practices (3rd edition) BP_048 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | ✅ | 🚀 | 🚀 | 🚀 | +| ??? | Call a DOM element multiple times without caching (linter key : `@ecocode/no-multiple-access-dom-element`) | Access to the Document Object Model (DOM) is costly in terms of CPU resources (CPU cycles). Also, when you use the same DOM element from JavaScript multiple times, store its reference in a variable so that you do not go through the DOM again for the same element. | [cnumr best practices (3rd edition) BP_049](https://github.com/cnumr/best-practices/blob/main/chapters/BP_049_fr.md) | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | +| EC4 | Use global variables | When using a global variable, the interpretation engine must check: 1) that it exists in the current scope, in the one above, etc. ; 2) the variable has a value; 3) ... To avoid all these checks, it is often possible to pass the useful variables as arguments of routines, making them local. This process saves computational time (CPU cycles). | [cnumr best practices (3rd edition) BP_050 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | ✅ | 🚀 | +| EC53 | Using arrays in foreach loops | foreach deduplicates items in a list before starting the enumeration. It is therefore generally more economical to use a simple for loop when you have a good command of the collection. | [cnumr best practices (3rd edition) BP_053 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | 🚀 | 🚀 | 🚫 | 🚀 | +| EC7 | Rewrite native getter/setters | Overloading them lengthens the compilation and execution times of these methods, which are usually much better optimized by the language than by the developer. | [cnumr best practices (3rd edition) BP_062 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | 🚀 | 🚀 | ✅ | 🚀 | +| EC63 | Unnecessarily assigning values to variables | Avoid declaring and using variables when it is not indis-thinkable. Indeed, each allocation corresponds to the RAM occupied. | [cnumr best practices (3rd edition) BP_063 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | 🚀 | 🚀 | 🚀 | 🚀 | +| EC66 | Use single quote (') instead of quotation mark (") | The shape using the quotation marks allows the developer to insert variables that will be substituted at run time. But if the string does not have a variable, use quotes instead. Thus, language will not look for variables to subtituture, which will reduce the consumption of CPU cycles. | [cnumr best practices (3rd edition) BP_066 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚀 | ✅ | 🚀 | ✅ | 🚀 | +| EC67 | Use the $i++ variable during an iteration | The $i++ form has the disadvantage of generating a tem-porary variable during incrementation, which is not the case with the ++$i form. | [cnumr best practices (3rd edition) BP_067 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | 🚫 | 🚫 | +| EC69 | Calling a function in the declaration of a for loop | Avoid calling the function each time the loop is iterated. | [cnumr best practices (3rd edition) BP_069 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | ✅ | 🚀 | +| EC72 | Perform an SQL query inside a loop | Servers are optimized to process multiple selections, insertions, or changes in a single query or transaction. consume CPU cycles, RAM, and bandwidth unnecessarily. | [cnumr best practices (3rd edition) BP_072](https://github.com/cnumr/best-practices/blob/main/chapters/BP_072_fr.md) | ✅ | ✅ | 🚀 | ✅ | 🚀 | +| EC74 | Write SELECT * FROM | The database server must resolve the fields based on the schema. If you are familiar with the diagram, it is strongly recommended to name the fields. | [cnumr best practices (3rd edition) BP_074 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | ✅ | ✅ | 🚀 | ✅ | 🚀 | +| EC1 | Calling a Spring repository inside a loop | The use of Spring repository in a loop induces unnecessary calculations by the CPU and therefore superfluous energy consumption. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC3 | Getting the size of the collection in the loop | When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power. | | ✅ | ✅ | 🚀 | 🚫 | 🚀 | +| EC2 | Multiple if-else statement | Using too many conditional if-else statements will impact performance since JVM will have to compare the conditions. Prefer using a switch statement instead of multiple if-else if possible, or refactor your code to reduce conditonnal statements on the same variable. Switch statement has a performance advantage over if – else. | | ✅ | ✅ | 🚀 | 🚧 | 🚀 | +| EC76 | Usage of static collections | Avoid usage of static collections. If you want to use static collections make them final and create for example a singleton if needed containing the collections. The static fields are more complicated for the Garbage Collector to manage and can lead to memory leaks. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC77 | Usage Pattern.compile() in a non-static context | Avoid using Pattern.compile() in a non-static context. This operation requires a non negligible amount of computational power, Using a single match saves CPU cycles and RAM consumption. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC75 | Concatenate Strings in loop | Don't concatenate Strings in loop. User StringBuilder instead. Strings are immutable so each time you concatenate a String, a new String is created. This is a waste of memory and CPU. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC78 | Const parameter in batch update | Don't set const parameter in batch update => Put its in query. Creating this parameter and destroying it consumes CPU cycles and RAM unnecessarily. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC79 | Free resources | try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface, it save computer resources. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC32 | Initialize builder/buffer with the appropriate size | If you know in advance how many characters would be appended, initialize builder/buffer with the appropriate size. They will thus never have to be resized. This saves CPU cycles and therefore consumes less energy. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC28 | Optimize read file exceptions | | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC5 | Usage of preparedStatement instead of Statement | SQL will only commit the query once, whereas if you used only one statement, it would commit the query every time and thus induce unnecessary calculations by the CPU and therefore superfluous energy consumption. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC27 | Usage of system.arraycopy to copy arrays | Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| EC404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | 🚫 | 🚫 | 🚫 | ✅ | 🚫 | +| EC203 | Detect unoptimized file formats | When it is possible, to use svg format image over other image format | | 🚀 | 🚀 | 🚀 | ✅ | 🚀 | +| | Avoid high accuracy geolocation | Avoid using high accuracy geolocation in web applications (linter key : `@ecocode/avoid-high-accuracy-geolocation`) | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | +| | No import all from library | Should not import all from library (linter key : `@ecocode/no-import-all-from-library`) | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | +| | Prefer collections with pagination | Prefer API collections with pagination (linter key : `@ecocode/prefer-collections-with-pagination`) | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | diff --git a/ecocode-rules-specifications/pom.xml b/ecocode-rules-specifications/pom.xml index 81977d3d7..5811cddb5 100644 --- a/ecocode-rules-specifications/pom.xml +++ b/ecocode-rules-specifications/pom.xml @@ -14,57 +14,19 @@ Repository that contains the specifications of every static-analysis rules available in ecoCode plugins. https://github.com/green-code-initiative/ecoCode/tree/main/ecocode-rules-specifications - - - org.sonarsource.sonarqube - sonar-plugin-api - provided - - - org.sonarsource.analyzer-commons - sonar-analyzer-commons - - - - org.junit.jupiter - junit-jupiter - test - - - - org.assertj - assertj-core - test - - - - - org.jacoco - jacoco-maven-plugin - - - prepare-agent - - prepare-agent - - - - report - - report - - - - - - org.asciidoctor asciidoctor-maven-plugin @@ -78,12 +40,13 @@ ${project.basedir}/src/main/rules - ${project.build.directory}/rules + ${project.build.directory}/rules-html coderay style true + true false true @@ -95,65 +58,33 @@ - - - org.apache.maven.plugins - maven-antrun-plugin - 3.1.0 + com.github.johnpoth + jshell-maven-plugin + 1.4 - process-resources + prepare-rules-resources + generate-resources run - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - + 0.0.6 + + + ${project.groupId} ecocode-rules-specifications - ${project.version} + ${ecocode-rules-specifications.version} java @@ -36,6 +43,11 @@ provided + + org.sonarsource.analyzer-commons + sonar-analyzer-commons + + com.google.re2j diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java index 5ca219399..b66e81cfa 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaCheckRegistrar.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java index 3ccc016e8..ff070c1b1 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaPlugin.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java index e8f7cccd3..958edc829 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java index 080fc83d1..b594af9d4 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ArrayCopyCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.ArrayList; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java index 90d68b852..99b732c50 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java index e8dd5d28b..88ff715c4 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.List; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java index 7112bb685..c81d79534 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java index 9460642ab..383365309 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java @@ -1,67 +1,346 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; -import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; +import org.sonar.plugins.java.api.tree.BinaryExpressionTree; import org.sonar.plugins.java.api.tree.BlockTree; +import org.sonar.plugins.java.api.tree.ExpressionTree; +import org.sonar.plugins.java.api.tree.IdentifierTree; import org.sonar.plugins.java.api.tree.IfStatementTree; +import org.sonar.plugins.java.api.tree.MethodTree; import org.sonar.plugins.java.api.tree.StatementTree; import org.sonar.plugins.java.api.tree.Tree; +import org.sonar.plugins.java.api.tree.Tree.Kind; import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey; +/** + * FUNCTIONAL DESCRIPTION : please see ASCIIDOC description file of this rule (inside `ecocode-rules-spcifications`) + * TECHNICAL CHOICES : + * - Kind.IF_STATEMENT, Kind.ELSE_STATEMENT, Kind.ELSEIF_STATEMENT not used because it isn't possible + * to keep parent references to check later if variables already used or not in parent tree + * - only one way to keep parent history : manually go throw the all tree and thus, start at method declaration + * - an "ELSE" statement is considered as a second IF statement using the same variables used on previous + * - IF and ELSEIF statements are considered as an IF statement + */ @Rule(key = "EC2") @DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "AMIES") public class AvoidMultipleIfElseStatement extends IssuableSubscriptionVisitor { - protected static final String RULE_MESSAGE = "Using a switch statement instead of multiple if-else if possible"; - private void checkIfStatement(Tree tree) { - int sizeBody = 0; - int idx = 0; - int countIfStatement = 0; + public static final String ERROR_MESSAGE = "Use a switch statement instead of multiple if-else if possible"; - Tree parentNode = tree.parent(); + public static final int NB_MAX_VARIABLE_USAGE = 2; - if (!(parentNode instanceof BlockTree)) + // data structure for following usage of variable inside all the AST tree + private VariablesPerLevelDataStructure variablesStruct = new VariablesPerLevelDataStructure(); + + // only visit each method to keep data of all conditional tree + // with IF, ELSE or ELSEIF statements, we can't keep all data of conditional tree + @Override + public List nodesToVisit() { + return List.of(Kind.METHOD); + } + + @Override + public void visitNode(@SuppressWarnings("NullableProblems") Tree pTree) { + + MethodTree method = (MethodTree)pTree; + + // reinit data structure before each method analysis + variablesStruct = new VariablesPerLevelDataStructure(); + + // starting visit + visitNodeContent(method.block().body(), 0); + + } + + /** + * Visit all content of a node for one level (with its statements list) + * + * @param pLstStatements statements list of current node + * @param pLevel level of current node + */ + private void visitNodeContent(List pLstStatements, int pLevel) { + if (pLstStatements == null || pLstStatements.isEmpty()) { return; - BlockTree node = (BlockTree) parentNode; - sizeBody = node.body().toArray().length; - while (idx < sizeBody) { - if (node.body().get(idx) instanceof IfStatementTree) - ++countIfStatement; - ++idx; - } - if (countIfStatement > 1) - reportIssue(tree, RULE_MESSAGE); + } + + for (StatementTree statement : pLstStatements) { + if (statement.is(Kind.BLOCK)) { + // the current node is a block : visit block content + visitNodeContent(((BlockTree)statement).body(), pLevel); + } else if (statement.is(Kind.IF_STATEMENT)) { + visitIfNode((IfStatementTree) statement, pLevel); + } + } } - private void checkElseIfStatement(Tree tree) { - IfStatementTree node = (IfStatementTree) tree; - int count = 0; - StatementTree statementTree; - - while (true) { - if (count >= 2) - reportIssue(tree, RULE_MESSAGE); - statementTree = node.elseStatement(); - if (statementTree instanceof IfStatementTree) { - ++count; - node = (IfStatementTree) statementTree; - } else { - break; + /** + * Visit an IF type node + * @param pIfTree the current node (Tree type) + * @param pLevel the level of node + */ + private void visitIfNode(IfStatementTree pIfTree, int pLevel) { + + if (pIfTree == null) return; + + // init current if structure with cleaning child levels + variablesStruct.reinitVariableUsageForLevel(pLevel + 1); + // init current if structure with cleaning for ELSE process checking + variablesStruct.reinitVariableUsageForLevelForCurrentIfStruct(pLevel); + + // analyze condition variables and raise error if needed + computeIfVariables(pIfTree, pLevel); + + // visit the content of if block + visitNodeContent(((BlockTree)pIfTree.thenStatement()).body(), pLevel + 1); + + // analyze ELSE clause et ELSE IF clauses + if (pIfTree.elseStatement() != null) { + if (pIfTree.elseStatement().is(Kind.BLOCK)) { // ELSE clause content + visitElseNode((BlockTree) pIfTree.elseStatement(), pLevel); + } else if (pIfTree.elseStatement().is(Kind.IF_STATEMENT)) { // ELSE IF clause + visitIfNode((IfStatementTree) pIfTree.elseStatement(), pLevel); } } } - @Override - public List nodesToVisit() { - return Arrays.asList(Tree.Kind.IF_STATEMENT); + /** + * Analyze and compute variables usage for IF AST structure + * @param pIfTree IF node + * @param pLevel the level of IF node + */ + private void computeIfVariables(IfStatementTree pIfTree, int pLevel) { + + if (pIfTree.condition() == null) return; + + // analysing content of conditions of IF node + ExpressionTree expr = pIfTree.condition(); + if (expr instanceof BinaryExpressionTree) { + computeConditionVariables((BinaryExpressionTree) expr, pLevel); + } + } - @Override - public void visitNode(Tree tree) { - checkIfStatement(tree); - checkElseIfStatement(tree); + /** + * Analyze and compute variables usage for Expression structure + * @param pBinExprTree binary expression to analyze + * @param pLevel The level of binary expression + */ + private void computeConditionVariables(BinaryExpressionTree pBinExprTree, int pLevel) { + + // if multiple conditions, continue with each part of complex expression + if (pBinExprTree.is(Kind.CONDITIONAL_AND) || pBinExprTree.is(Kind.CONDITIONAL_OR)) { + if (pBinExprTree.leftOperand() instanceof BinaryExpressionTree) { + computeConditionVariables((BinaryExpressionTree) pBinExprTree.leftOperand(), pLevel); + } + if (pBinExprTree.rightOperand() instanceof BinaryExpressionTree) { + computeConditionVariables((BinaryExpressionTree) pBinExprTree.rightOperand(), pLevel); + } + } else if (pBinExprTree.is(Kind.EQUAL_TO) + || pBinExprTree.is(Kind.NOT_EQUAL_TO) + || pBinExprTree.is(Kind.GREATER_THAN) + || pBinExprTree.is(Kind.GREATER_THAN_OR_EQUAL_TO) + || pBinExprTree.is(Kind.LESS_THAN_OR_EQUAL_TO) + || pBinExprTree.is(Kind.LESS_THAN) + ) { + // continue analysis with variables if some key-words are found + if (pBinExprTree.leftOperand().is(Kind.IDENTIFIER)) { + computeVariables((IdentifierTree) pBinExprTree.leftOperand(), pLevel); + } + if (pBinExprTree.rightOperand().is(Kind.IDENTIFIER)) { + computeVariables((IdentifierTree) pBinExprTree.rightOperand(), pLevel); + } + } + } + + /** + * Analyze and compute variables usage for Variable AST structure + * @param pVarIdTree The Variable AST structure + * @param pLevel the level of structure + */ + private void computeVariables(IdentifierTree pVarIdTree, int pLevel) { + if (pVarIdTree.is(Kind.IDENTIFIER)) { + // increment the variable counter to list of all variables + int nbUsed = variablesStruct.incrementVariableUsageForLevel(pVarIdTree.name(), pLevel); + + // increment variable counter to list of variables already declared for current if or elseif struture + variablesStruct.incrementVariableUsageForLevelForCurrentIfStruct(pVarIdTree.name(), pLevel); + + // raise an error if maximum + if (nbUsed > NB_MAX_VARIABLE_USAGE) { + reportIssue(pVarIdTree, ERROR_MESSAGE); + } + } + } + + /** + * Analyze and compute variables usage for ELSE AST structure + * @param pElseTree ELSE node + * @param pLevel the level of ELSE node + */ + private void visitElseNode(BlockTree pElseTree, int pLevel) { + + if (pElseTree == null) { return; } + + // analyze variables and raise error if needed + computeElseVariables(pElseTree, pLevel); + + // go to next child level + visitNodeContent(pElseTree.body(), pLevel + 1); } + + /** + * Analyze and compute variables usage for ELSE AST structure + * @param pElseTree ELSE node + * @param pLevel the level of ELSE node + */ + private void computeElseVariables(StatementTree pElseTree, int pLevel) { + + for (Map.Entry entry : variablesStruct.getVariablesForCurrentIfStruct(pLevel).entrySet()) { + String variableName = entry.getKey(); + + // increment usage of all variables in the same level of ELSE staetement + int nbUsed = variablesStruct.incrementVariableUsageForLevel(variableName, pLevel); + + // increment variable counter to list of variables already declared for current if or elseif struture + variablesStruct.incrementVariableUsageForLevelForCurrentIfStruct(variableName, pLevel); + + // raise an error if maximum + if (nbUsed > NB_MAX_VARIABLE_USAGE) { + reportIssue(pElseTree, ERROR_MESSAGE); + } + } + } + + /** + * Complex data structure representing variables counters per AST level (cumulative counts with parent levels) + * Map> ==> + * - Key : index of Level (0 = first level) + * - Value : Map + * - Key : name of variable in the current or parent level + * - Value : number of usage of this variable in an IF statement in current level or one of parent levels + * + */ + private static class VariablesPerLevelDataStructure { + + // global map variable counters per level + private final Map> mapVariablesPerLevel; + + // map variable counters per level for current If / ElseIf structure + // purpose : used by compute variables Else process (because Else structure is particular : + // we don't know previous variables and we need previous If / ElseIf structure to know variables) + private final Map> mapVariablesPerLevelForCurrentIfStruct; + + public VariablesPerLevelDataStructure() { + mapVariablesPerLevel = new HashMap<>(10); + mapVariablesPerLevelForCurrentIfStruct = new HashMap<>(10); + } + + /** + * increment variable counters on global map + */ + public int incrementVariableUsageForLevel(String variableName, int pLevel) { + return internalIncrementVariableUsage(mapVariablesPerLevel, variableName, pLevel); + } + + /** + * increment variable counters on input map + */ + private int internalIncrementVariableUsage(Map> pDataMap, String variableName, int pLevel) { + + // get variable usage map for current level and init if null + Map variablesMap = pDataMap.computeIfAbsent(pLevel, k -> new HashMap<>(5)); + + // get usage from parent if needed + Integer nbUsed = variablesMap.get(variableName); + if (nbUsed == null) { + Integer nbParentUsed = internalGetVariableUsageOfNearestParent(pDataMap, variableName, pLevel - 1); + nbUsed = nbParentUsed == null ? 0 : nbParentUsed; + } + + // increment usage for current level + nbUsed++; + variablesMap.put(variableName, nbUsed); + + return nbUsed; + } + + /** + * get usage of a variable in top tree (nearest top parent) + */ + private Integer internalGetVariableUsageOfNearestParent(Map> pDataMap, String variableName, int pLevel) { + + Integer nbParentUsed = null; + for (int i = pLevel; i >= 0 && nbParentUsed == null; i--) { + Map variablesParentLevelMap = pDataMap.get(i); + nbParentUsed = variablesParentLevelMap.get(variableName); + } + + return nbParentUsed; + } + + /** + * reinitialization of variable usages for input level and global map + */ + public void reinitVariableUsageForLevel(int pLevel) { + internalReinitVariableUsageForLevelForCurrentIfStruct(mapVariablesPerLevel, pLevel); + } + + /** + * reinitialization of variable usages in input level in input map + */ + private void internalReinitVariableUsageForLevelForCurrentIfStruct(Map> pDataMap, int pLevel) { + if (pDataMap.get(pLevel) == null) { return; } + + // cleaning of current If Structure beginning at level specified + for (int i = pLevel; i < pDataMap.size(); i++) { + pDataMap.remove(i); + } + + } + + /** + * reinitialization of variable usages for input level on if/elseif map + */ + public void reinitVariableUsageForLevelForCurrentIfStruct(int pLevel) { + internalReinitVariableUsageForLevelForCurrentIfStruct(mapVariablesPerLevelForCurrentIfStruct, pLevel); + } + + /** + * increment variable counters on if/elseif map + */ + public void incrementVariableUsageForLevelForCurrentIfStruct(String variableName, int pLevel) { + internalIncrementVariableUsage(mapVariablesPerLevelForCurrentIfStruct, variableName, pLevel); + } + + /** + * get usage of a variable in a level on if/elseif map + */ + public Map getVariablesForCurrentIfStruct(int pLevel) { + return mapVariablesPerLevelForCurrentIfStruct.get(pLevel); + } + + } + } diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java index a4e8e2f7e..2561a6c0f 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStatic.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collections; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java index 297895e08..7c4ff5623 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java index 4a014c2a3..4fe31abda 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchUpdate.java @@ -1,10 +1,28 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.sql.PreparedStatement; import java.util.List; import java.util.stream.Stream; -import static fr.greencodeinitiative.java.checks.ConstOrLiteralDeclare.isLiteral; +import fr.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare; +import static fr.greencodeinitiative.java.checks.enums.ConstOrLiteralDeclare.isLiteral; import static java.util.Arrays.asList; import org.sonar.check.Rule; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java index 6cf843392..e95d75e98 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java index f273ae707..04e7b619e 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueries.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collections; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java index c6eba94b7..18a7fb7f9 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollections.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collections; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java index bdc4dee1b..98bb254b4 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java index fb41ba0f7..47cbc2eb1 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterface.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.ArrayList; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java index 7b480b1c7..00c3094dd 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collections; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java index bb3cc4dd6..44caa8722 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSize.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collections; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java index 1c7c47347..d4088bd22 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.ArrayList; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java index 9766d2009..2362404be 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptions.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java index 8c6dde8f0..f5544d2e5 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariables.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.sonar.check.Rule; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java index 6da7c13c1..05e46a4ab 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/UseCorrectForLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ConstOrLiteralDeclare.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java similarity index 85% rename from java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ConstOrLiteralDeclare.java rename to java-plugin/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java index 8a5b459a0..db01a76bc 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/ConstOrLiteralDeclare.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/enums/ConstOrLiteralDeclare.java @@ -1,4 +1,21 @@ -package fr.greencodeinitiative.java.checks; +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package fr.greencodeinitiative.java.checks.enums; import java.math.BigDecimal; import java.util.Set; @@ -18,7 +35,7 @@ import static org.sonar.plugins.java.api.tree.Tree.Kind.TYPE_CAST; import org.sonar.plugins.java.api.tree.TypeCastTree; -enum ConstOrLiteralDeclare { +public enum ConstOrLiteralDeclare { BOOLEAN { @Override diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java index 7e796b1a3..2b709d790 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/PrinterVisitor.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java index bc6ec9d89..b9b81c526 100644 --- a/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java +++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/utils/StringUtils.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/test/files/ArrayCopyCheck.java b/java-plugin/src/test/files/ArrayCopyCheck.java index d18890515..09c780eaa 100644 --- a/java-plugin/src/test/files/ArrayCopyCheck.java +++ b/java-plugin/src/test/files/ArrayCopyCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ import java.util.Arrays; import java.util.Collection; import java.util.Collections; diff --git a/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java b/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java index b6b36b2f1..4e2a5877a 100644 --- a/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java +++ b/java-plugin/src/test/files/AvoidConcatenateStringsInLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.utils; public class AvoidConcatenateStringsInLoop { diff --git a/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java b/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java index 4a0994727..b388252af 100644 --- a/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java +++ b/java-plugin/src/test/files/AvoidFullSQLRequestCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java index 18d38b49b..46963cd7f 100644 --- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java +++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForEachLoopIgnored.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collection; diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java index dec9e0f8a..3c74c86dc 100644 --- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java +++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopBad.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collection; diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java index 840ace8cc..5f2bcd2e7 100644 --- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java +++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopGood.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collection; diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java index 719f620c2..544e08e7d 100644 --- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java +++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInForLoopIgnored.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collection; diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java index 32c74e128..f47570c9b 100644 --- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java +++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopBad.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collection; diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java index 7329fba97..57668687e 100644 --- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java +++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopGood.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collection; diff --git a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java index ca913f17d..10c752f40 100644 --- a/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java +++ b/java-plugin/src/test/files/AvoidGettingSizeCollectionInWhileLoopIgnored.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Collection; diff --git a/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java b/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java index 88e40ad0c..435218fa6 100644 --- a/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java +++ b/java-plugin/src/test/files/AvoidMultipleIfElseStatement.java @@ -1,38 +1,283 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; class AvoidMultipleIfElseStatementCheck { - AvoidMultipleIfElseStatementCheck(AvoidMultipleIfElseStatementCheck mc) { + +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// // +// // NON COMPLIANT use cases +// // +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // NON COMPLIANT + // USE CASE : Non compliant use case to check if following is NON OK : + // - two uses of the same variable + // - usage of the same variable on different levels of IF statements + public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements() + { + int nb1 = 0; + + if (nb1 == 1) { + nb1 = 2; + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } + } + + return nb1; } - public void methodWithMultipleIfElseIf() { + // NON COMPLIANT + // USE CASE : non compliant use case to check if a variable is not used max twice on several IF / ELSE statements + // at the same level + public int shouldBeNotCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed() + { int nb1 = 0; - int nb2 = 10; + int nb2 = 0; + int nb3 = 0; - if (nb1 == 1) { // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} + if (nb3 == 1 + && nb3 == 2 + && nb3 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} nb1 = 1; - } else if (nb1 == nb2) { - // - } else if (nb2 == nb1) { - // + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb2 = 2; + } + + if (nb2 == 2) { + nb1 = 3; } else { - // + nb1 = 4; } - nb1 = nb2; + + return nb1; } - public void methodWithMultipleIfElse() { + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT COMPLIANT : + // one variable is used maximum in two IF / ELSE / ELSEIF statements + public int shouldBeNotCompliantBecauseVariablesIsUsedMoreThanTwice() + { int nb1 = 0; - int nb2 = 10; - if (nb1 == 1) { // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} - nb1 = 1; + if (nb1 == 1) { + nb1 = 2; } else { - // + nb1 = 3; } - if (nb1 == 1) { // Noncompliant {{Using a switch statement instead of multiple if-else if possible}} - nb1 = 1; + + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 4; + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - same variable used maximum twice : no compliant because 2 IFs and 1 ELSE + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInIfStatementsAtDifferentsLevels() + { + int nb1 = 0; + + if (nb1 == 1) { + if (nb1 == 2) { + nb1 = 1; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 3; + } } else { - // + nb1 = 2; } + + return nb1; + } + + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatements() + { + int nb1 = 0; + + if (nb1 == 1) { + nb1 = 2; + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 3; + } + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario2() + { + int nb1 = 0; + + if (nb1 == 1) { + if (nb1 == 3) { + nb1 = 4; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 5; + } + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 3; + } + } + + return nb1; } -} \ No newline at end of file + + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario3() + { + int nb1 = 0; + int nb2 = 0; + + if (nb1 == 1) { + if (nb1 == 3) { + nb1 = 4; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 5; + } + } else if (nb2 == 2) { + if (nb1 == 4) { + nb1 = 5; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 6; + } + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : non compliant use case to check if following is NOT OK : + // - two uses of the same variable : use thre times with 2 IFs and 1 ELSE + // - usage of the same variable on different levels of IF statements + public int shouldBeNotCompliantBecauseVariableUsedMoreThanTwiceInComposedElseStatementsScenario4() + { + int nb1 = 0; + int nb2 = 0; + + if (nb1 == 1) { + if (nb2 == 3) { + nb1 = 4; + } else { + nb1 = 5; + } + } else if (nb2 == 2) { + if (nb1 == 3) { + nb1 = 4; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 5; + } + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - the same variable must used maximum twice + // - usage of the same variable on different levels of IF / ELSE statements + public int shouldBeNotCompliantBecauseVariableUsedMaximumTwiceInComposedElseStatements() + { + int nb1 = 0; + + if (nb1 == 1) { + nb1 = 2; + } else { + if (nb1 == 2) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 1; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + if (nb1 == 3) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 4; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb1 = 5; + } + } + } + + return nb1; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - more than twice uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeNotCompliantBecauseTheSameVariableIsUsedMoreThanTwice() // NOT Compliant + { + int nb1 = 0; + int nb2 = 10; + + if (nb1 == 1) { + nb2 = 1; + } else if (nb1 == nb2) { + nb2 = 2; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb2 = 4; + } + + return nb2; + } + + // NON COMPLIANT + // USE CASE : NON compliant use case to check if following is NOT OK : + // - more than twice uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeNotCompliantBecauseTheSameVariableIsUsedManyTimes() // NOT Compliant + { + int nb1 = 0; + int nb2 = 10; + int nb3 = 11; + + if (nb1 == 1) { + nb2 = 1; + } else if (nb1 == nb2) { + nb2 = 2; + } else if (nb3 == nb1) { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb2 = 3; + } else { // Noncompliant {{Use a switch statement instead of multiple if-else if possible}} + nb2 = 4; + } + + return nb2; + } + +} diff --git a/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java b/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java index 60d10293c..a56e9e599 100644 --- a/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java +++ b/java-plugin/src/test/files/AvoidMultipleIfElseStatementNoIssue.java @@ -1,31 +1,211 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; -class AvoidMultipleIfElseStatementNoIssueCheck { - AvoidMultipleIfElseStatementNoIssueCheck(AvoidMultipleIfElseStatementNoIssueCheck mc) { +class AvoidMultipleIfElseStatementCheckNoIssue { + + // inital RULES : please see HTML description file of this rule (resources directory) + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // COMPLIANT use cases + // + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // COMPLIANT + // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements + // at the same level AND no problem with several IF staments at the same level using different variables + public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsed() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb3 != 1 && nb1 > 1) { + nb1 = 1; + } else { + nb2 = 2; + } + + if (nb2 == 2) { + nb1 = 3; + } else { + nb1 = 4; + } + + return nb1; } - public void methodWithOneIfElseIf() { + // COMPLIANT + // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements + // at the same level AND no problem with several IF staments at the same level using different variables + public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDifferentsVariablesUsedAtDiffLevels() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb1 < 1) { + if (nb2 == 2) { + nb3 = 3; + } else { + nb3 = 4; + } + } else { + nb2 = 2; + } + + if (nb3 >= 1) { + if (nb2 == 2) { + nb1 = 3; + } else { + nb1 = 4; + } + } else { + nb1 = 2; + } + + return nb1; + } + + // COMPLIANT + // USE CASE : compliant use case to check if a variable is used maximum twice on several IF / ELSE statements + // at the same level AND no problem with several IF staments at the same level using different variables + public int shouldBeCompliantBecauseVariablesUsedMaximumTwiceAndDiffVariablesUsedAtDiffLevelsScenario2() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb1 <= 1) { + if (nb2 == 2) { + if (nb3 == 2) { + nb3 = 3; + } else { + nb3 = 4; + } + } else { + nb3 = 4; + } + } else { + nb2 = 2; + } + + if (nb3 == 1) { + if (nb2 == 2) { + nb1 = 3; + } else { + nb1 = 4; + } + } else { + nb1 = 2; + } + + return nb1; + } + + // COMPLIANT + // USE CASE : compliant use case to check if one variable is used maximum twice in different IF statements + public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfStatements() + { int nb1 = 0; - int nb2 = 10; if (nb1 == 1) { nb1 = 1; - } else if (nb1 == nb2) { - // + } + + if (nb1 == 2) { + nb1 = 3; + } + + return nb1; + } + + // COMPLIANT + // USE CASE : compliant use case to check if following is OK : + // - two uses of the same variable + // - usage of the same variable on different levels of IF statements + public int shouldBeCompliantBecauseSereralVariablesUsedMaximumTwiceInComposedElseStatements() + { + int nb1 = 0; + int nb2 = 0; + int nb3 = 0; + + if (nb1 == 1) { + nb1 = 2; } else { - // + if (nb2 == 2) { + nb1 = 1; + } else { + if (nb3 == 4) { + nb1 = 3; + } else { + nb1 = 6; + } + } } - nb1 = nb2; + + return nb1; } - public void methodWithOneIfElse() { + // COMPLIANT + // USE CASE : compliant use case to check if following is OK : + // - two uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeCompliantBecauseVariableUsedMaximumTwiceInIfOrElseIfStatements() // Compliant + { int nb1 = 0; int nb2 = 10; if (nb1 == 1) { - nb1 = 1; + nb2 = 1; + } else if (nb1 == nb2) { + nb2 = 2; + } + + return nb2; + } + + // COMPLIANT + // USE CASE : compliant use case to check if following is OK : + // - two uses of the same variable + // - usage of the same variable on different kind of test statements (IF and ELSEIF) + public int shouldBeCompliantBecauseSeveralVariablesUsedMaximumTwiceInIfOrElseIfStatements() // Compliant + { + int nb1 = 0; + int nb2 = 10; + int nb3 = 3; + int nb4 = 1; + int nb5 = 2; + + if (nb1 == 1) { + nb2 = 1; + } else if (nb3 == nb2) { + nb2 = 2; + } else if (nb4 == nb5) { + nb2 = 4; } else { - // + nb2 = 3; } + + return nb2; } -} \ No newline at end of file + +} diff --git a/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java b/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java index 0474e4520..b5e19c6e3 100644 --- a/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java +++ b/java-plugin/src/test/files/AvoidRegexPatternNotStatic.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java b/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java index 4981d0b4c..753a717a6 100644 --- a/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java +++ b/java-plugin/src/test/files/AvoidSQLRequestInLoopCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.sql.Connection; diff --git a/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java b/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java index 122a48b4d..03f5e86ab 100644 --- a/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java +++ b/java-plugin/src/test/files/AvoidSetConstantInBatchUpdateCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.math.BigDecimal; diff --git a/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java b/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java index c4aec153c..d2ae74e8a 100644 --- a/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java +++ b/java-plugin/src/test/files/AvoidSpringRepositoryCallInLoopCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.springframework.beans.factory.annotation.Autowired; diff --git a/java-plugin/src/test/files/AvoidStatementForDMLQueries.java b/java-plugin/src/test/files/AvoidStatementForDMLQueries.java index 70ba4ed5e..5059b0933 100644 --- a/java-plugin/src/test/files/AvoidStatementForDMLQueries.java +++ b/java-plugin/src/test/files/AvoidStatementForDMLQueries.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.sql.Connection; diff --git a/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java b/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java index ac1b9f0dc..353099720 100644 --- a/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java +++ b/java-plugin/src/test/files/AvoidUsageOfStaticCollections.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.*; diff --git a/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java b/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java index 362510eff..557d6fc92 100644 --- a/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java +++ b/java-plugin/src/test/files/AvoidUsingGlobalVariablesCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ public class Openclass { public static double price = 15.24; // Noncompliant {{Avoid using global variables}} public static long pages = 1053; // Noncompliant {{Avoid using global variables}} diff --git a/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java b/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java index e2ca15225..e1eaab59e 100644 --- a/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java +++ b/java-plugin/src/test/files/FreeResourcesOfAutoCloseableInterface.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.io.*; diff --git a/java-plugin/src/test/files/GoodUsageOfStaticCollections.java b/java-plugin/src/test/files/GoodUsageOfStaticCollections.java index 8f8e55c71..6d2d3c202 100644 --- a/java-plugin/src/test/files/GoodUsageOfStaticCollections.java +++ b/java-plugin/src/test/files/GoodUsageOfStaticCollections.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.*; diff --git a/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java b/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java index b4218d0d7..c11c1ab6a 100644 --- a/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java +++ b/java-plugin/src/test/files/GoodWayConcatenateStringsLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.utils; public class GoodWayConcatenateStringsLoop { diff --git a/java-plugin/src/test/files/IncrementCheck.java b/java-plugin/src/test/files/IncrementCheck.java index 6a6d1b536..54b20bf90 100644 --- a/java-plugin/src/test/files/IncrementCheck.java +++ b/java-plugin/src/test/files/IncrementCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ class MyClass { MyClass(MyClass mc) { } diff --git a/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java b/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java index 1b391c106..b5852a195 100644 --- a/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java +++ b/java-plugin/src/test/files/InitializeBufferWithAppropriateSize.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.sql.Connection; diff --git a/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java b/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java index 8b92a39a8..da72a3efd 100644 --- a/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java +++ b/java-plugin/src/test/files/NoFunctionCallWhenDeclaringForLoop.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ class NoFunctionCallWhenDeclaringForLoop { NoFunctionCallWhenDeclaringForLoop(NoFunctionCallWhenDeclaringForLoop mc) { } diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java index 6e7a6e29c..e9fd260cb 100644 --- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java +++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java index 2e1054925..689dc1878 100644 --- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java +++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck2.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java index e76f64a01..92dc15019 100644 --- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java +++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck3.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java index 89ca97340..5914e0fa5 100644 --- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java +++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck4.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java index b4c3388dd..6d8b553e2 100644 --- a/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java +++ b/java-plugin/src/test/files/OptimizeReadFileExceptionCheck5.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java index b61a58ec7..17eb069a5 100644 --- a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java +++ b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; class UnnecessarilyAssignValuesToVariablesTestCheck { diff --git a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java index f732e4945..f70c4c410 100644 --- a/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java +++ b/java-plugin/src/test/files/UnnecessarilyAssignValuesToVariablesTestCheckWithEmptyReturn.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; class UnnecessarilyAssignValuesToVariablesTestCheck { diff --git a/java-plugin/src/test/files/UseCorrectForLoopCheck.java b/java-plugin/src/test/files/UseCorrectForLoopCheck.java index dfdde5d16..350ed6ebb 100644 --- a/java-plugin/src/test/files/UseCorrectForLoopCheck.java +++ b/java-plugin/src/test/files/UseCorrectForLoopCheck.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.Arrays; diff --git a/java-plugin/src/test/files/ValidRegexPattern.java b/java-plugin/src/test/files/ValidRegexPattern.java index 5ed3652f4..aacb701e5 100644 --- a/java-plugin/src/test/files/ValidRegexPattern.java +++ b/java-plugin/src/test/files/ValidRegexPattern.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/java-plugin/src/test/files/ValidRegexPattern2.java b/java-plugin/src/test/files/ValidRegexPattern2.java index d6d9efd71..a674b9bc4 100644 --- a/java-plugin/src/test/files/ValidRegexPattern2.java +++ b/java-plugin/src/test/files/ValidRegexPattern2.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/java-plugin/src/test/files/ValidRegexPattern3.java b/java-plugin/src/test/files/ValidRegexPattern3.java index e19073454..086769384 100644 --- a/java-plugin/src/test/files/ValidRegexPattern3.java +++ b/java-plugin/src/test/files/ValidRegexPattern3.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import java.util.regex.Pattern; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java index 29cc52ae2..db1383ae5 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaCheckRegistrarTest.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java index 3d09e5b0e..0f2167d37 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java index bb6f796d3..2c6551436 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaRulesDefinitionTest.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java index e83a49e2f..5f0b12767 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/ArrayCopyCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java index d5e3e6fcb..00027474c 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidConcatenateStringsInLoopTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java index 516f31fec..25ead7c4d 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidFullSQLRequestCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java index 4a0bad7f8..8083c1db6 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidGettingSizeCollectionInLoopTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java index 84a7e5f32..568757e7c 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java index a3c8ba912..5350cc127 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidRegexPatternNotStaticTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java index 54f5f4a53..5abed41fd 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSQLRequestInLoopCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java index 73a7e58d3..8c138fde7 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSetConstantInBatchInsertTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java index ce5dfc36e..2ea1887bd 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidSpringRepositoryCallInLoopCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import fr.greencodeinitiative.java.utils.FilesUtils; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java index 1a8803440..40c5a51b6 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidStatementForDMLQueriesTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java index e72d271de..a9b8a2d84 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsageOfStaticCollectionsTests.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java index c8dbeb26a..f9e270e6c 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/AvoidUsingGlobalVariablesCheckCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java index 2736a12e3..9a9ca4929 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/FreeResourcesOfAutoCloseableInterfaceTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java index 4044341cd..e9d5b98ef 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/IncrementCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java index 5096eee2f..deef83e80 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/InitializeBufferWithAppropriateSizeTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java index f2876bb1d..ef3c983fe 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/NoFunctionCallWhenDeclaringForLoopTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java index 5dffac408..b3ef8c89e 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/OptimizeReadFileExceptionCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java index efcb2aa1b..09336e24a 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UnnecessarilyAssignValuesToVariablesTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java index f6add5776..815d097a1 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/UseCorrectLoopCheckTest.java @@ -1,3 +1,20 @@ +/* + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package fr.greencodeinitiative.java.checks; import org.junit.jupiter.api.Test; diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java index 121607764..ed06d4cef 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/FilesUtils.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java index 25b5b6791..9e6d9328a 100644 --- a/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java +++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/utils/StringUtilsTest.java @@ -1,15 +1,16 @@ /* - * Copyright (C) 2023 Green Code Initiative + * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs + * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . diff --git a/pom.xml b/pom.xml index 45989d064..1beefaee1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,7 @@ ecoCode Sonar Plugins Project Provides rules to reduce the environmental footprint of your programs https://github.com/green-code-initiative/ecocode + 2023 green-code-initiative https://github.com/green-code-initiative @@ -98,6 +99,8 @@ 11 ${java.version} ${java.version} + + ${java.version} UTF-8 ${encoding} @@ -217,6 +220,14 @@ shade + + + + + ${project.version} + + + commons-*:* @@ -244,6 +255,12 @@ META-INF/** + + io.ecocode:ecocode-rules-specifications:* + + META-INF/** + + @@ -261,6 +278,36 @@ + + + com.mycila + license-maven-plugin + 4.1 + + + Green Code Initiative + https://www.ecocode.io + + + +
com/mycila/maven/plugin/license/templates/GPL-3.txt
+ + **/*.java + +
+
+
+ + + validate + + check + + validate + + +
+
diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index a8b72a766..000000000 --- a/sonar-project.properties +++ /dev/null @@ -1,20 +0,0 @@ -# must be unique in a given SonarQube instance -sonar.projectKey=sonar-custom-plugin-example - -# --- optional properties --- - -# defaults to project key -#sonar.projectName=My project -# defaults to 'not provided' -#sonar.projectVersion=1.0 - -# Path is relative to the sonar-project.properties file. Defaults to . -#sonar.sources=. - -# Encoding of the source code. Default is default system encoding -#sonar.sourceEncoding=UTF-8 - -sonar.eslint.reportPaths=/opt/project/eslint-report.json -sonar.css.stylelint.reportPaths=/opt/project/stylelint-report.json -sonar.java.binaries=/opt/project/java-plugin/target/classes -sonar.scm.disabled=true \ No newline at end of file