Skip to content

Commit

Permalink
Merge pull request #201 from green-code-initiative/clean-plugins
Browse files Browse the repository at this point in the history
Plugins clean-up
  • Loading branch information
dedece35 authored Jun 25, 2023
2 parents 39e7044 + 5308753 commit 3f7e7c4
Show file tree
Hide file tree
Showing 37 changed files with 186 additions and 427 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#19](https://github.com/green-code-initiative/ecoCode-common/issues/19) process changed for development environment installation : easier to initialize locally environment (check [`INSTALL.md`](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#howto-install-sonarqube-dev-environment) file)
- [#187](https://github.com/green-code-initiative/ecoCode/issues/187) upgrade librairies to SonarQube 10.0.0
- [#196](https://github.com/green-code-initiative/ecoCode/issues/196) updating PHP files to make them following the coding standards (PSR-12)
- [#201](https://github.com/green-code-initiative/ecoCode/pull/201) Clean-up plugins and dependencies
- technical : upgrade of maven plugins versions

### Deleted
Expand Down Expand Up @@ -159,3 +160,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.1.1]: https://github.com/green-code-initiative/ecoCode/compare/v0.1.0...v0.1.1

[0.1.0]: https://github.com/green-code-initiative/ecoCode/releases/tag/v0.1.0

17 changes: 6 additions & 11 deletions java-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,11 @@
<artifactId>sonar-plugin-api</artifactId>
</dependency>

<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
</dependency>

<dependency>
<groupId>org.sonarsource.analyzer-commons</groupId>
<artifactId>sonar-analyzer-commons</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>

<!-- for security on regex patterns : https://github.com/google/re2j -->
<dependency>
<groupId>com.google.re2j</groupId>
Expand All @@ -69,6 +58,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* SonarQube Java
* Copyright (C) 2012-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
* Copyright (C) 2023 Green Code Initiative
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,9 +11,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* SonarQube Java
* Copyright (C) 2012-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
* Copyright (C) 2023 Green Code Initiative
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,17 +11,13 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java;

import org.sonar.api.Plugin;

/**
* Entry point of your plugin containing your custom rules
*/
public class JavaPlugin implements Plugin {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* SonarQube Java
* Copyright (C) 2012-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
* Copyright (C) 2023 Green Code Initiative
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,25 +11,20 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java;

import org.sonar.api.SonarRuntime;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonarsource.analyzer.commons.RuleMetadataLoader;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;

import org.sonar.api.SonarEdition;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.Version;
import org.sonarsource.analyzer.commons.RuleMetadataLoader;

/**
* Declare rule metadata in server repository of rules.
* That allows to list the rules in the page "Rules".
Expand All @@ -48,12 +41,16 @@ public class JavaRulesDefinition implements RulesDefinition {
public static final String LANGUAGE = "java";
public static final String REPOSITORY_KEY = "ecocode-java";

private final SonarRuntime sonarRuntime;

public JavaRulesDefinition(SonarRuntime sonarRuntime) {
this.sonarRuntime = sonarRuntime;
}

@Override
public void define(Context context) {
NewRepository repository = context.createRepository(REPOSITORY_KEY, LANGUAGE).setName(NAME);

SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(10, 0), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);

RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, sonarRuntime);

ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(RulesList.getChecks()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* SonarQube Java
* Copyright (C) 2012-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
* Copyright (C) 2023 Green Code Initiative
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,9 +11,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,16 @@
package fr.greencodeinitiative.java.checks;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.CheckForNull;

import org.apache.commons.lang3.StringUtils;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
import org.sonar.plugins.java.api.tree.AssignmentExpressionTree;
import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
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.ForEachStatement;
import org.sonar.plugins.java.api.tree.IdentifierTree;
import org.sonar.plugins.java.api.tree.IfStatementTree;
import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;
import org.sonar.plugins.java.api.tree.MethodInvocationTree;
import org.sonar.plugins.java.api.tree.NewClassTree;
import org.sonar.plugins.java.api.tree.ReturnStatementTree;
import org.sonar.plugins.java.api.tree.StatementTree;
import org.sonar.plugins.java.api.tree.ThrowStatementTree;
import org.sonar.plugins.java.api.tree.Tree;
import org.sonar.plugins.java.api.tree.*;
import org.sonar.plugins.java.api.tree.Tree.Kind;
import org.sonar.plugins.java.api.tree.TypeCastTree;
import org.sonar.plugins.java.api.tree.UnaryExpressionTree;
import org.sonar.plugins.java.api.tree.VariableTree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;

import javax.annotation.CheckForNull;
import java.util.*;

@Rule(key = "EC63", name = "Developpement", description = "Do not unnecessarily assign values to variables", priority = Priority.MINOR,
tags = {"eco-design", "ecocode", "memory"})
@DeprecatedRuleKey(repositoryKey = "greencodeinitiative-java", ruleKey = "S63")
Expand Down Expand Up @@ -191,7 +168,7 @@ private void checkImmediatelyReturnedVariable(BlockTree tree) {
String lastStatementIdentifier = getReturnOrThrowIdentifier(lastStatement);
if (lastStatementIdentifier != null) {
String identifier = variableTree.simpleName().name();
if (StringUtils.equals(lastStatementIdentifier, identifier)) {
if (lastStatementIdentifier.equals(identifier)) {
context.reportIssue(this, variableTree.initializer(), errorMessage);
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* SonarQube Java
* Copyright (C) 2012-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
* Copyright (C) 2023 Green Code Initiative
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,9 +11,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java.utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* SonarQube Java
* Copyright (C) 2012-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
* Copyright (C) 2023 Green Code Initiative
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,9 +11,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java.utils;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* SonarQube Java
* Copyright (C) 2012-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
* Copyright (C) 2023 Green Code Initiative
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,16 +11,16 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.greencodeinitiative.java;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.java.api.CheckRegistrar;

import static org.assertj.core.api.Assertions.assertThat;

class JavaCheckRegistrarTest {

@Test
Expand All @@ -35,4 +33,5 @@ void checkNumberRules() {
assertThat(context.checkClasses()).hasSize(19);
assertThat(context.testCheckClasses()).isEmpty();
}

}
Loading

0 comments on commit 3f7e7c4

Please sign in to comment.