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

Compatibility with Sonar 10 and 9.5+ #375

Merged
merged 5 commits into from
Jul 15, 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
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 17 ]
java: [ 11, 17, 20 ]
steps:
- uses: actions/checkout@v3
- name: Setup java
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: adopt
distribution: temurin
- name: Build with Maven
run: |
mvn -B clean
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node/
.idea/
*.iml
.vscode/
docker/plugins/*.jar
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3"

services:
sonarqube:
image: sonarqube:10.1.0-community
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- ./target/sonarqube-licensecheck-plugin-6.0.0-SNAPSHOT.jar:/opt/sonarqube/extensions/plugins/sonarqube-licensecheck-plugin-6.0.0-SNAPSHOT.jar
- sonarqube_logs:/opt/sonarqube/logs
ports:
- "9000:9000"
db:
image: postgres:14-alpine
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data

volumes:
sonarqube_data:
sonarqube_logs:
postgresql:
postgresql_data:
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"include": [
"./src/main/web/**/*"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"build": "webpack --mode=production",
"watch": "concurrently --kill-others \"webpack -w\" \"node test-server.js\"",
"watch": "concurrently --kill-others \"webpack --watch --mode development --devtool inline-source-map\" \"node test-server.js\"",
"generate-icons": "vsvg -s ./svg-icons -t ./src/compiled-icons"
},
"author": "Christian Köberl",
Expand Down
73 changes: 35 additions & 38 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.sources>src/main,pom.xml,package.json</sonar.sources>
<sonar.pluginTermsConditionsUrl>https://github.com/porscheinformatik/sonarqube-licensecheck/blob/master/LICENSE</sonar.pluginTermsConditionsUrl>
<sonarqube.version>8.9.0.43852</sonarqube.version>
<java.version>1.8</java.version>
<sonar.apiVersion>9.5.0.71</sonar.apiVersion>
<sonar.apiImplVersion>9.5.0.56709</sonar.apiImplVersion>
<java.version>11</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -73,23 +74,22 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonarqube.version}</version>
<version>${sonar.apiVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-application</artifactId>
<version>${sonarqube.version}</version>
<scope>system</scope>
<systemPath>${project.build.directory}/sonarqube-${sonarqube.version}/lib/sonar-application-${sonarqube.version}.jar</systemPath>
<artifactId>sonar-plugin-api-impl</artifactId>
<version>${sonar.apiImplVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xpp3</groupId>
Expand Down Expand Up @@ -117,33 +117,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>unpack</id>
<phase>clean</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-application</artifactId>
<version>${sonarqube.version}</version>
<type>zip</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<includes>sonarqube-*/lib/sonar-application*</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
Expand Down Expand Up @@ -232,6 +205,30 @@
<npmVersion>8.11.0</npmVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/docker/plugins</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import at.porscheinformatik.sonarqube.licensecheck.dependencymapping.DependencyMapping;
import at.porscheinformatik.sonarqube.licensecheck.dependencymapping.DependencyMappingService;
import at.porscheinformatik.sonarqube.licensecheck.dependencymapping.DependencyMappingSettingsService;
import at.porscheinformatik.sonarqube.licensecheck.license.License;
import at.porscheinformatik.sonarqube.licensecheck.license.LicenseService;
import at.porscheinformatik.sonarqube.licensecheck.license.LicenseSettingsService;
import at.porscheinformatik.sonarqube.licensecheck.licensemapping.LicenseMapping;
import at.porscheinformatik.sonarqube.licensecheck.licensemapping.LicenseMappingService;
import at.porscheinformatik.sonarqube.licensecheck.licensemapping.LicenseMappingSettingsService;
import at.porscheinformatik.sonarqube.licensecheck.projectlicense.ProjectLicense;
import at.porscheinformatik.sonarqube.licensecheck.projectlicense.ProjectLicenseService;
import at.porscheinformatik.sonarqube.licensecheck.projectlicense.ProjectLicenseSettingsService;
import at.porscheinformatik.sonarqube.licensecheck.web.LicenseCheckWebService;
import org.sonar.api.Plugin;
import org.sonar.api.PropertyType;
import org.sonar.api.config.PropertyDefinition;
Expand Down Expand Up @@ -41,14 +36,9 @@ private List<?> getExtensions()
LicenseCheckPageDefinition.class,
LicenseCheckRulesDefinition.class,
LicenseService.class,
LicenseSettingsService.class,
DependencyMappingService.class,
DependencyMappingSettingsService.class,
LicenseMappingService.class,
LicenseMappingSettingsService.class,
ProjectLicenseService.class,
ProjectLicenseSettingsService.class,
LicenseCheckWebService.class,
PropertyDefinition.builder(LicenseCheckPropertyKeys.LICENSE_SET)
.category(LicenseCheckPropertyKeys.CATEGORY)
.type(PropertyType.PROPERTY_SET)
Expand Down Expand Up @@ -112,7 +102,7 @@ private List<?> getExtensions()
.category(LicenseCheckPropertyKeys.CATEGORY)
.type(PropertyType.PROPERTY_SET)
.name("Project Licenses")
.description("Allow/disallow licences for specific projects.")
.description("Allow/disallow licenses for specific projects.")
.fields(
PropertyFieldDefinition.build(ProjectLicense.FIELD_PROJECT_KEY)
.name("Project key")
Expand All @@ -129,22 +119,6 @@ private List<?> getExtensions()
)
.index(6)
.build(),
PropertyDefinition.builder(LicenseCheckPropertyKeys.LICENSE_KEY)
.hidden()
.type(PropertyType.TEXT)
.build(),
PropertyDefinition.builder(LicenseCheckPropertyKeys.ALLOWED_DEPENDENCIES_KEY)
.hidden()
.type(PropertyType.TEXT)
.build(),
PropertyDefinition.builder(LicenseCheckPropertyKeys.LICENSE_REGEX)
.hidden()
.type(PropertyType.TEXT)
.build(),
PropertyDefinition.builder(LicenseCheckPropertyKeys.PROJECT_LICENSE_KEY)
.hidden()
.type(PropertyType.TEXT)
.build(),
PropertyDefinition.builder(LicenseCheckPropertyKeys.NPM_RESOLVE_TRANSITIVE_DEPS)
.category(LicenseCheckPropertyKeys.CATEGORY)
.name("NPM Transitive Dependencies")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,6 @@ public class LicenseCheckPropertyKeys
*/
public static final String NPM_RESOLVE_TRANSITIVE_DEPS = "licensecheck.npm.resolvetransitive";

/**
* @deprecated replaced with {@link #LICENSE_SET}
*/
@Deprecated
public static final String LICENSE_KEY = "licensecheck.licenses";

/**
* @deprecated replaced with {@link #LICENSE_MAPPING}
*/
@Deprecated
public static final String LICENSE_REGEX = "licensecheck.licensesregex";

/**
* @deprecated replaced with {@link #DEPENDENCY_MAPPING}
*/
@Deprecated
public static final String ALLOWED_DEPENDENCIES_KEY = "licensecheck.alloweddependencies";

/**
* @deprecated replaced with {@link #PROJECT_LICENSE_SET}
*/
@Deprecated
public static final String PROJECT_LICENSE_KEY = "licensecheck.projectlicense";

private LicenseCheckPropertyKeys()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package at.porscheinformatik.sonarqube.licensecheck.dependencymapping;

import static at.porscheinformatik.sonarqube.licensecheck.LicenseCheckPropertyKeys.ALLOWED_DEPENDENCIES_KEY;
import static at.porscheinformatik.sonarqube.licensecheck.LicenseCheckPropertyKeys.DEPENDENCY_MAPPING;
import static at.porscheinformatik.sonarqube.licensecheck.dependencymapping.DependencyMapping.FIELD_KEY;
import static at.porscheinformatik.sonarqube.licensecheck.dependencymapping.DependencyMapping.FIELD_LICENSE;
import static at.porscheinformatik.sonarqube.licensecheck.dependencymapping.DependencyMapping.FIELD_OVERWRITE;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonReader;

import org.sonar.api.config.Configuration;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.server.ServerSide;
Expand Down Expand Up @@ -47,26 +39,4 @@ public List<DependencyMapping> getDependencyMappings()
.collect(Collectors.toList());
}

/**
* @return maven dependencies via deprecated setting
* @deprecated use {@link #getDependencyMappings()} instead
*/
@Deprecated
public List<DependencyMapping> getDependencyMappingsOld()
{
final List<DependencyMapping> dependencyMappings = new ArrayList<>();
String dependencyString = configuration.get(ALLOWED_DEPENDENCIES_KEY).orElse("[]");

JsonReader jsonReader = Json.createReader(new StringReader(dependencyString));
JsonArray jsonArray = jsonReader.readArray();
jsonReader.close();

for (int i = 0; i < jsonArray.size(); i++)
{
JsonObject jsonObject = jsonArray.getJsonObject(i);
dependencyMappings.add(
new DependencyMapping(jsonObject.getString("nameMatches"), jsonObject.getString("license"), true));
}
return dependencyMappings;
}
}
Loading