Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix execution of unit tests with Maven #15

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#10](https://github.com/green-code-initiative/ecoCode-php/pull/10) Adding EC35 rule : EC35 rule replaces EC34 with a specific use case ("file not found" specific)
- [#13](https://github.com/green-code-initiative/ecoCode-php/issues/13) Add build number to manifest
- Update ecocode-rules-specifications to 0.0.9
- [#12](https://github.com/green-code-initiative/ecoCode-php/issues/12) Fix unit tests execution with Maven

### Deleted

Expand All @@ -27,4 +28,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#205](https://github.com/green-code-initiative/ecoCode/issues/205) compatibility with SonarQube 10.1

[unreleased]: https://github.com/green-code-initiative/ecoCode-php/compare/v1.4.0...HEAD
[1.4.0]: https://github.com/green-code-initiative/ecoCode-php/compare/v0.0.0...1.4.0
[1.4.0]: https://github.com/green-code-initiative/ecoCode-php/compare/v0.0.0...1.4.0
58 changes: 20 additions & 38 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,34 @@
<groupId>io.ecocode</groupId>
<artifactId>ecocode-php-plugin</artifactId>
<version>1.4.1-SNAPSHOT</version>

<packaging>sonar-plugin</packaging>

<name>ecoCode - PHP language</name>
<description>Provides rules to reduce the environmental footprint of your PHP programs</description>
<inceptionYear>2023</inceptionYear>

<url>https://github.com/green-code-initiative/ecoCode-php</url>
<organization>
<name>green-code-initiative</name>
<url>https://github.com/green-code-initiative</url>
</organization>

<licenses>
<license>
<name>GPL v3</name>
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<connection>scm:git:https://github.com/green-code-initiative/ecocode-php</connection>
<developerConnection>scm:git:https://github.com/green-code-initiative/ecocode-php</developerConnection>
<url>https://github.com/green-code-initiative/ecocode-php</url>
<tag>HEAD</tag>
</scm>

<issueManagement>
<system>GitHub</system>
<url>https://github.com/green-code-initiative/ecoCode-php/issues</url>
Expand All @@ -52,20 +57,18 @@
<!-- max version with SonarQube 10.0 : check lib/extension directory -->
<sonarphp.version>3.28.0.9490</sonarphp.version>

<!-- max version with SonarQube 10.0 : check lib/extension directory -->
<sonarjava.version>7.17.0.31219</sonarjava.version>

<sonar-analyzer-commons.version>2.5.0.1358</sonar-analyzer-commons.version>
<sonar-packaging.version>1.23.0.740</sonar-packaging.version>
<sonar.skipDependenciesPackaging>true</sonar.skipDependenciesPackaging>

<junit.jupiter.version>5.9.1</junit.jupiter.version>
<assertJ.version>3.23.1</assertJ.version>
<mockito.version>5.3.1</mockito.version>

<!-- temporary version waiting for real automatic release in ecocode repository -->
<ecocode-rules-specifications.version>0.0.9</ecocode-rules-specifications.version>

<sonar-analyzer-commons.version>2.5.0.1358</sonar-analyzer-commons.version>
<maven-shade.version>3.5.0</maven-shade.version>

<junit.jupiter.version>5.9.2</junit.jupiter.version>
<assertj.version>3.24.2</assertj.version>
<mockito.version>5.3.1</mockito.version>
<jacoco.version>0.8.11</jacoco.version>

</properties>

Expand Down Expand Up @@ -101,13 +104,6 @@
</dependency>

<!-- TEST sources dependencies -->
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-checks-testkit</artifactId>
<version>${sonarjava.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand All @@ -118,7 +114,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertJ.version}</version>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -172,11 +168,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<output>file</output>
<append>false</append>
</configuration>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand All @@ -203,6 +195,7 @@
<pluginClass>fr.greencodeinitiative.php.PHPPlugin</pluginClass>
<sonarLintSupported>true</sonarLintSupported>
<pluginApiMinVersion>${sonarqube.version}</pluginApiMinVersion>
<skipDependenciesPackaging>true</skipDependenciesPackaging>
<jreMinVersion>${java.version}</jreMinVersion>
<archive>
<manifestEntries>
Expand Down Expand Up @@ -233,38 +226,27 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<!-- common configuration for shade plugin -->
<version>${maven-shade.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>commons-*:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.*:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
<exclude>org/sonar/api/batch/sensor/**</exclude>
<exclude>javax/annotation/**</exclude>
</excludes>
</filter>
<filter>
<artifact>com.*:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
<filter>
<artifact>junit:*</artifact>
<artifact>io.ecocode:ecocode-rules-specifications:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
*/
package fr.greencodeinitiative.php.checks;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

public class AvoidDoubleQuoteCheckTest {
import java.io.File;

class AvoidDoubleQuoteCheckTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new AvoidDoubleQuoteCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidDoubleQuote.php")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
package fr.greencodeinitiative.php.checks;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

public class AvoidFullSQLRequestCheckTest {
import java.io.File;

class AvoidFullSQLRequestCheckTest {

@Test
public void test() {
void test() {
PHPCheckTest.check(new AvoidFullSQLRequestCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidFullSQLRequest.php")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
package fr.greencodeinitiative.php.checks;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

import java.io.File;

public class AvoidGettingSizeCollectionInLoopTest {
class AvoidGettingSizeCollectionInLoopTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new AvoidGettingSizeCollectionInLoopCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidGettingSizeCollectionInLoop.php")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
*/
package fr.greencodeinitiative.php.checks;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

import java.io.File;

/**
* Test class to test the check implementation.
*/
public class AvoidMultipleIfElseStatementCheckTest {
class AvoidMultipleIfElseStatementCheckTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new AvoidMultipleIfElseStatementCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidMultipleIfElseStatement.php")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
package fr.greencodeinitiative.php.checks;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

public class AvoidSQLRequestInLoopCheckTest {
import java.io.File;

class AvoidSQLRequestInLoopCheckTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new AvoidSQLRequestInLoopCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidSQLRequestInLoop.php")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
*/
package fr.greencodeinitiative.php.checks;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

public class AvoidTryCatchWithFileOpenedCheckTest {
import java.io.File;

class AvoidTryCatchWithFileOpenedCheckTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new AvoidTryCatchWithFileOpenedCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidTryCatchWithFileOpenedCheck.php")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
*/
package fr.greencodeinitiative.php.checks;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

import java.io.File;

public class AvoidUsingGlobalVariablesCheckTest {
class AvoidUsingGlobalVariablesCheckTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new AvoidUsingGlobalVariablesCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidUsingGlobalVariablesCheck.php")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
*/
package fr.greencodeinitiative.php.checks;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

public class IncrementCheckTest {
import java.io.File;

class IncrementCheckTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new IncrementCheck(), new PhpTestFile(new File("src/test/resources/checks/IncrementCheck.php")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
package fr.greencodeinitiative.php.checks;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

public class NoFunctionCallWhenDeclaringForLoopTest {
import java.io.File;

class NoFunctionCallWhenDeclaringForLoopTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new NoFunctionCallWhenDeclaringForLoop(), new PhpTestFile(new File("src/test/resources/checks/NoFunctionCallWhenDeclaringForLoop.php")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
package fr.greencodeinitiative.php.checks;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.plugins.php.api.tests.PHPCheckTest;
import org.sonar.plugins.php.api.tests.PhpTestFile;

public class UseOfMethodsForBasicOperationsTest {
import java.io.File;

class UseOfMethodsForBasicOperationsTest {

@Test
public void test() throws Exception {
void test() throws Exception {
PHPCheckTest.check(new UseOfMethodsForBasicOperations(), new PhpTestFile(new File("src/test/resources/checks/UseOfMethodsForBasicOperations.php")));
}

}