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

Remove dependency on Google Guava library #9546

Merged
merged 5 commits into from
Jul 23, 2024
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
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<sonar.api.impl.version>10.6.0.92116</sonar.api.impl.version>
<jdk.min.version>17</jdk.min.version>
<maven.compiler.release>${jdk.min.version}</maven.compiler.release>
<guava.version>33.2.1-jre</guava.version>
<!-- See: https://github.com/SonarSource/sonar-plugin-api#compatibility -->
<plugin.api.min.version>9.14.0.375</plugin.api.min.version>

Expand Down Expand Up @@ -139,12 +138,6 @@
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions sonar-csharp-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@
*/
package org.sonar.plugins.csharp;

import com.google.common.collect.ImmutableList;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.sonar.api.Plugin;
import org.sonar.api.SonarEdition;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.Version;
import org.sonarsource.dotnet.shared.plugins.AnalysisWarningsSensor;
Expand All @@ -49,6 +45,7 @@
import org.sonarsource.dotnet.shared.plugins.WrongEncodingFileFilter;

import static org.assertj.core.api.Assertions.assertThat;
import static org.sonarsource.dotnet.shared.PropertyUtils.nonProperties;

class CSharpPluginTest {

Expand Down Expand Up @@ -97,14 +94,4 @@ void getExtensions() {
+ new CSharpPropertyDefinitions(sonarRuntime).create().size());
}

private static List nonProperties(List extensions) {
ImmutableList.Builder builder = ImmutableList.builder();
for (Object extension : extensions) {
if (!(extension instanceof PropertyDefinition)) {
builder.add(extension);
}
}
return builder.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
*/
package org.sonar.plugins.csharp;

import com.google.common.collect.Sets;
import com.sonar.plugins.security.api.CsRules;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -57,7 +57,7 @@ void sonar_security_with_already_activated_rule() {
Mockito.when(profile.activateRule(CSharpPlugin.REPOSITORY_KEY, "TEST")).thenThrow(IllegalArgumentException.class);
Context context = Mockito.mock(Context.class);
Mockito.when(context.createBuiltInQualityProfile(anyString(), anyString())).thenReturn(profile);
CsRules.ruleKeys = Sets.newHashSet("TEST");
CsRules.ruleKeys = Set.of("TEST");

CSharpSonarWayProfile profileDef = new CSharpSonarWayProfile();
profileDef.define(context);
Expand All @@ -73,7 +73,7 @@ void sonar_security_with_unknown_rule_repository() {
Mockito.when(profile.activateRule("roslyn.TEST", "TEST")).thenThrow(IllegalStateException.class);
Context context = Mockito.mock(Context.class);
Mockito.when(context.createBuiltInQualityProfile(anyString(), anyString())).thenReturn(profile);
CsRules.ruleKeys = Sets.newHashSet("TEST");
CsRules.ruleKeys = Set.of("TEST");
CsRules.returnRepository = true;

CSharpSonarWayProfile profileDef = new CSharpSonarWayProfile();
Expand All @@ -85,7 +85,7 @@ void sonar_security_with_unknown_rule_repository() {
@Test
void sonar_security_with_custom_frontend_plugin() {
Context context = new Context();
CsRules.ruleKeys = Sets.newHashSet("S3649");
CsRules.ruleKeys = Set.of("S3649");
CsRules.returnRepository = true;

CSharpSonarWayProfile profileDef = new CSharpSonarWayProfile();
Expand All @@ -102,7 +102,7 @@ void sonar_security_with_duplicated_quality_profile_name() {
NewBuiltInQualityProfile sonarWay = context.createBuiltInQualityProfile("Sonar way", CSharpPlugin.LANGUAGE_KEY);
sonarWay.activateRule(CSharpPlugin.REPOSITORY_KEY, "S1");
sonarWay.done();
CsRules.ruleKeys = Sets.newHashSet("S2");
CsRules.ruleKeys = Set.of("S2");

CSharpSonarWayProfile profileDef = new CSharpSonarWayProfile();

Expand All @@ -126,7 +126,7 @@ void sonar_security_missing() {
@Test
void sonar_security_7_3_present() {
Context context = new Context();
CsRules.ruleKeys = Sets.newHashSet("S3649");
CsRules.ruleKeys = Set.of("S3649");
CsRules.returnRepository = false;

CSharpSonarWayProfile profileDef = new CSharpSonarWayProfile();
Expand Down
4 changes: 0 additions & 4 deletions sonar-dotnet-shared-library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* SonarSource :: .NET :: Shared library
* Copyright (C) 2014-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* 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 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.
*
* 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.
*/

package org.sonarsource.dotnet.shared;

import org.sonar.api.config.PropertyDefinition;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class PropertyUtils {
private PropertyUtils() { }

public static Set<Object> nonProperties(List<Object> extensions) {
return extensions.stream()
.filter(extension -> !(extension instanceof PropertyDefinition))
.collect(Collectors.toSet());
}

public static Set<String> propertyKeys(List<Object> extensions) {
return extensions.stream()
.filter(PropertyDefinition.class::isInstance)
.map(extension -> ((PropertyDefinition) extension).key())
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
*/
package org.sonar.plugins.dotnet.tests;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -247,20 +247,14 @@ private SensorContextTester computeCoverageMeasures(boolean isIntegrationTest) {
String bazPath = new File(baseDir, "Baz.java").getAbsolutePath();
String barPath = new File(baseDir, "Bar.cs").getAbsolutePath();
when(coverage.files()).thenReturn(new HashSet<>(asList(fooPath, barPath, bazPath)));
when(coverage.hits(fooPath)).thenReturn(ImmutableMap.<Integer, Integer>builder()
.put(2, 1)
.put(4, 0)
.build());
when(coverage.hits(barPath)).thenReturn(ImmutableMap.<Integer, Integer>builder()
.put(42, 1)
.build());
when(coverage.hits(bazPath)).thenReturn(ImmutableMap.<Integer, Integer>builder()
.put(42, 1)
.build());
when(coverage.getBranchCoverage(fooPath)).thenReturn(ImmutableList.<BranchCoverage>builder()
.add(new BranchCoverage(5, 2, 1))
.add(new BranchCoverage(6, 3, 2))
.build());
when(coverage.hits(fooPath)).thenReturn(Map.of(
2, 1,
4, 0));
when(coverage.hits(barPath)).thenReturn(Map.of(42, 1));
when(coverage.hits(bazPath)).thenReturn(Map.of(42, 1));
when(coverage.getBranchCoverage(fooPath)).thenReturn(List.of(
new BranchCoverage(5, 2, 1),
new BranchCoverage(6, 3, 2)));

DefaultInputFile inputFile = new TestInputFileBuilder("foo", baseDir, new File(baseDir, "Foo.cs"))
.setLanguage("cs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package org.sonar.plugins.dotnet.tests;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -34,39 +34,39 @@ public void test() {

coverage.addHits("foo.txt", 42, 1);
assertThat(coverage.files()).containsExactlyInAnyOrder("foo.txt");
assertThat(coverage.hits("foo.txt")).isEqualTo(ImmutableMap.of(42, 1));
assertThat(coverage.hits("foo.txt")).isEqualTo(Map.of(42, 1));

coverage.addHits("foo.txt", 42, 3);
assertThat(coverage.files()).containsExactlyInAnyOrder("foo.txt");
assertThat(coverage.hits("foo.txt")).isEqualTo(ImmutableMap.of(42, 4));
assertThat(coverage.hits("foo.txt")).isEqualTo(Map.of(42, 4));

coverage.addHits("foo.txt", 1234, 11);
assertThat(coverage.files()).containsExactlyInAnyOrder("foo.txt");
assertThat(coverage.hits("foo.txt")).isEqualTo(ImmutableMap.of(42, 4, 1234, 11));
assertThat(coverage.hits("foo.txt")).isEqualTo(Map.of(42, 4, 1234, 11));

coverage.addHits("bar.txt", 1, 2);
assertThat(coverage.files()).containsExactlyInAnyOrder("foo.txt", "bar.txt");
assertThat(coverage.hits("foo.txt")).isEqualTo(ImmutableMap.of(42, 4, 1234, 11));
assertThat(coverage.hits("bar.txt")).isEqualTo(ImmutableMap.of(1, 2));
assertThat(coverage.hits("foo.txt")).isEqualTo(Map.of(42, 4, 1234, 11));
assertThat(coverage.hits("bar.txt")).isEqualTo(Map.of(1, 2));

Coverage other = new Coverage();

coverage.mergeWith(other);
assertThat(coverage.files()).containsExactlyInAnyOrder("foo.txt", "bar.txt");
assertThat(coverage.hits("foo.txt")).isEqualTo(ImmutableMap.of(42, 4, 1234, 11));
assertThat(coverage.hits("bar.txt")).isEqualTo(ImmutableMap.of(1, 2));
assertThat(coverage.hits("foo.txt")).isEqualTo(Map.of(42, 4, 1234, 11));
assertThat(coverage.hits("bar.txt")).isEqualTo(Map.of(1, 2));

other.addHits("baz.txt", 2, 7);
assertThat(other.files()).containsExactlyInAnyOrder("baz.txt");
assertThat(other.hits("baz.txt")).isEqualTo(ImmutableMap.of(2, 7));
assertThat(other.hits("baz.txt")).isEqualTo(Map.of(2, 7));

coverage.mergeWith(other);
assertThat(other.files()).containsExactlyInAnyOrder("baz.txt");
assertThat(other.hits("baz.txt")).isEqualTo(ImmutableMap.of(2, 7));
assertThat(other.hits("baz.txt")).isEqualTo(Map.of(2, 7));
assertThat(coverage.files()).containsExactlyInAnyOrder("foo.txt", "bar.txt", "baz.txt");
assertThat(coverage.hits("foo.txt")).isEqualTo(ImmutableMap.of(42, 4, 1234, 11));
assertThat(coverage.hits("bar.txt")).isEqualTo(ImmutableMap.of(1, 2));
assertThat(coverage.hits("baz.txt")).isEqualTo(ImmutableMap.of(2, 7));
assertThat(coverage.hits("foo.txt")).isEqualTo(Map.of(42, 4, 1234, 11));
assertThat(coverage.hits("bar.txt")).isEqualTo(Map.of(1, 2));
assertThat(coverage.hits("baz.txt")).isEqualTo(Map.of(2, 7));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.sonar.plugins.dotnet.tests;

import com.google.common.base.Joiner;
import java.io.File;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -249,7 +248,7 @@ public void given_pattern_with_mixed_folder_separator_listFiles_supports_pattern
}

private static String path(String... elements) {
return Joiner.on(File.separator).join(elements);
return String.join(File.separator, elements);
}

private static Set<File> listFiles(String pattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
*/
package org.sonarsource.dotnet.shared.plugins;

import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.config.PropertyDefinition;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonarsource.dotnet.shared.PropertyUtils.nonProperties;
import static org.sonarsource.dotnet.shared.PropertyUtils.propertyKeys;

public class CodeCoverageProviderTest {

Expand Down Expand Up @@ -113,25 +111,4 @@ private static CodeCoverageProvider createTestProvider() {
return new CodeCoverageProvider(pluginMetadata);
}

private static Set<Object> nonProperties(List extensions) {
ImmutableSet.Builder<Object> builder = ImmutableSet.builder();
for (Object extension : extensions) {
if (!(extension instanceof PropertyDefinition)) {
builder.add(extension);
}
}
return builder.build();
}

private static Set<String> propertyKeys(List extensions) {
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (Object extension : extensions) {
if (extension instanceof PropertyDefinition) {
PropertyDefinition property = (PropertyDefinition) extension;
builder.add(property.key());
}
}
return builder.build();
}

}
Loading
Loading