diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index c58fbed..0ad5293 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -22,7 +22,9 @@ jobs:
java-version: 11
distribution: temurin
- name: Build with Maven
- run: mvn clean package source:jar javadoc:jar verify spotless:check
+ env:
+ SONARLINT4NETBEANS_TEST_REMOTE_PROJECT_MAVEN1_TOKEN: ${{ secrets.SONAR_TOKEN }}
+ run: mvn -D clean package source:jar javadoc:jar verify spotless:check
timeout-minutes: 10
- name: Test Report
uses: dorny/test-reporter@v1
diff --git a/pom.xml b/pom.xml
index 81fa259..0b568b6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,6 +106,11 @@
sonarlint4netbeans.test.skip.javascript
${sonarlint4netbeans.test.skip.javascript}
+
+
+ sonarlint4netbeans.test.remote.project-maven1.token
+ ${sonarlint4netbeans.test.remote.project-maven1.token}
+
@@ -135,11 +140,6 @@
maven-surefire-report-plugin
3.2.2
-
- org.apache.maven.plugins
- maven-surefire-report-plugin
- 3.2.2
-
org.jacoco
jacoco-maven-plugin
@@ -516,5 +516,8 @@
plain
warn
+
+ ${env.SONARLINT4NETBEANS_TEST_REMOTE_PROJECT_MAVEN1_TOKEN}
+
diff --git a/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManager.java b/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManager.java
index 00faf69..69559a7 100644
--- a/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManager.java
+++ b/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManager.java
@@ -34,10 +34,17 @@
* @author FICHET Philippe <philippe.fichet@laposte.net>
*/
public interface SonarLintDataManager {
+ /**
+ * Retrieve project preferences data for remote configuration (sonarcloud/sonarqube)
+ * @param project project to retrieve preference
+ * @return project preferences data for remote configuration (sonarcloud/sonarqube) or global settings preference if project is null
+ */
+ public Preferences getRemoteConfigurationPreferences(Project project);
+
/**
* Retrieve project preferences data
* @param project project to retrieve preference
- * @return project preferences data or global settings preference if project if null
+ * @return project preferences data or global settings preference if project is null
*/
public Preferences getPreferences(Project project);
diff --git a/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerImpl.java b/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerImpl.java
index 1f8ce36..4ecba50 100644
--- a/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerImpl.java
+++ b/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerImpl.java
@@ -20,6 +20,7 @@
package com.github.philippefichet.sonarlint4netbeans;
import com.github.philippefichet.sonarlint4netbeans.project.SonarLintProjectPreferenceScope;
+import com.github.philippefichet.sonarlint4netbeans.remote.configuration.SonarLintRemoteProjectConfiguration;
import java.awt.Image;
import java.io.File;
import java.nio.charset.Charset;
@@ -43,6 +44,14 @@
*/
public class SonarLintDataManagerImpl implements SonarLintDataManager {
private static final String PREFERENCE_SCOPE_KEY = "sonarlint-preference-scope";
+ @Override
+ public Preferences getRemoteConfigurationPreferences(Project project) {
+ if (project == null) {
+ return getGlobalSettingsPreferences();
+ }
+ return ProjectUtils.getPreferences(project, SonarLintRemoteProjectConfiguration.class, true);
+ }
+
@Override
public Preferences getPreferences(Project project) {
if (project == null) {
diff --git a/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImpl.java b/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImpl.java
index 74765f9..89a03af 100644
--- a/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImpl.java
+++ b/src/main/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImpl.java
@@ -88,8 +88,17 @@ public final class SonarLintEngineImpl implements SonarLintEngine {
private final List> configurationChanged = Collections.synchronizedList(new ArrayList<>());
private final Map pluginPaths = new HashMap<>();
private final Lookup lookup = Lookup.getDefault();
+ private final Language[] languages;
+ /**
+ * Default constructor for lookup
+ */
public SonarLintEngineImpl() {
+ this(Language.values());
+ }
+
+ public SonarLintEngineImpl(Language[] languages) {
+ this.languages = languages;
SonarLintDataManager sonarLintDataManager = getSonarLintDataManager();
pluginPaths.put("java", sonarLintDataManager.getInstalledFile("sonar/plugins/sonar-java-plugin-" + SONAR_JAVA_PLUGIN_VERSION + ".jar").toPath());
pluginPaths.put("javascript", sonarLintDataManager.getInstalledFile("sonar/plugins/sonar-javascript-plugin-" + SONAR_JAVASCRIPT_PLUGIN_VERSION + ".jar").toPath());
@@ -160,7 +169,7 @@ private void createInternalEngine(StandaloneSonarLintEngineImpl oldStandaloneSon
List allPluginPaths = new ArrayList<>(allPlugins.values());
StandaloneGlobalConfiguration.Builder configBuilder = StandaloneGlobalConfiguration.builder()
- .addEnabledLanguages(Language.values())
+ .addEnabledLanguages(languages)
.addPlugins(allPluginPaths.toArray(new Path[allPluginPaths.size()]));
Optional nodeJSPathOptional = getNodeJSPath();
Optional nodeJSVersionOptional = getNodeJSVersion();
diff --git a/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/SonarLintRemoteEngine.java b/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/SonarLintRemoteEngine.java
index bfe4b98..3b2d42c 100644
--- a/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/SonarLintRemoteEngine.java
+++ b/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/SonarLintRemoteEngine.java
@@ -70,6 +70,7 @@ public final class SonarLintRemoteEngine {
private static final String RUNTIME_NODE_JS_VERSION_PREFERENCE = "nodejs.version";
private final Clock clock = Clock.systemUTC();
private final Lookup lookup = Lookup.getDefault();
+ private final Language[] languages;
private final Map connectedSonarLintEngineImpls = Collections.synchronizedMap(new HashMap<>());
@@ -77,8 +78,16 @@ public final class SonarLintRemoteEngine {
* Default constructor for Lookup
*/
public SonarLintRemoteEngine() {
+ this.languages = Language.values();
}
-
+
+ /**
+ * Constructor testing, reduce downloads (plugin, rules, ...)
+ */
+ public SonarLintRemoteEngine(Language[] languages) {
+ this.languages = languages;
+ }
+
private String toKey(SonarLintRemoteProjectConfiguration sonarLintRemoteProjectConfiguration) {
return sonarLintRemoteProjectConfiguration.getProjectKey() + "-" +
sonarLintRemoteProjectConfiguration.getOrganization() + "-" +
@@ -139,13 +148,13 @@ private ConnectedSonarLintEngineImpl getConnectedSonarLintEngineImpl(SonarLintRe
String sonarLintHome = System.getProperty("user.home") + File.separator + ".sonarlint4netbeans";
return connectedSonarLintEngineImpls.computeIfAbsent(
sonarLintRemoteProjectConfiguration.getConnectionId(),
- c ->
+ (String connectionId) ->
new ConnectedSonarLintEngineImpl(
createBuilder()
- .setConnectionId(c)
+ .setConnectionId(connectionId)
.setStorageRoot(Paths.get(sonarLintHome, "storage"))
.setWorkDir(Paths.get(sonarLintHome, "work"))
- .addEnabledLanguages(Language.values())
+ .addEnabledLanguages(languages)
.build()
)
);
diff --git a/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/configuration/SonarLintRemoteProjectConfiguration.java b/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/configuration/SonarLintRemoteProjectConfiguration.java
index dc35f3a..7bba2d6 100644
--- a/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/configuration/SonarLintRemoteProjectConfiguration.java
+++ b/src/main/java/com/github/philippefichet/sonarlint4netbeans/remote/configuration/SonarLintRemoteProjectConfiguration.java
@@ -19,17 +19,18 @@
*/
package com.github.philippefichet.sonarlint4netbeans.remote.configuration;
+import com.github.philippefichet.sonarlint4netbeans.SonarLintDataManager;
import java.io.File;
import java.util.Map;
import java.util.Optional;
import java.util.prefs.Preferences;
import org.netbeans.api.project.Project;
-import org.netbeans.api.project.ProjectUtils;
import org.netbeans.libs.git.GitBranch;
import org.netbeans.libs.git.GitException;
import org.netbeans.libs.git.GitRepository;
import org.netbeans.libs.git.progress.ProgressMonitor;
import org.openide.filesystems.FileUtil;
+import org.openide.util.Lookup;
/**
*
@@ -54,7 +55,8 @@ public SonarLintRemoteProjectConfiguration(Project project, String connectionId,
}
public static SonarLintRemoteProjectConfiguration fromProject(Project project) {
- Preferences preferences = ProjectUtils.getPreferences(project, SonarLintRemoteProjectConfiguration.class, true);
+ SonarLintDataManager sonarLintDataManager = Lookup.getDefault().lookup(SonarLintDataManager.class);
+ Preferences preferences = sonarLintDataManager.getRemoteConfigurationPreferences(project);
return new SonarLintRemoteProjectConfiguration(
project,
preferences.get(PROP_CONNECTION_ID, null),
@@ -66,6 +68,7 @@ public static SonarLintRemoteProjectConfiguration fromProject(Project project) {
public static SonarLintRemoteProjectConfiguration fromProject(Project project, String connectionId, String projectKey, String organization) {
File projectDir = FileUtil.toFile(project.getProjectDirectory());
+ // TODO
GitRepository instance = GitRepository.getInstance(projectDir);
Map branches = null;
try {
@@ -82,7 +85,8 @@ public static SonarLintRemoteProjectConfiguration fromProject(Project project, S
}
public static void save(Project project, String sonarLintRemoteConnectionId, String projectKey, String organization) {
- Preferences preferences = ProjectUtils.getPreferences(project, SonarLintRemoteProjectConfiguration.class, true);
+ SonarLintDataManager sonarLintDataManager = Lookup.getDefault().lookup(SonarLintDataManager.class);
+ Preferences preferences = sonarLintDataManager.getRemoteConfigurationPreferences(project);
preferences.put(PROP_CONNECTION_ID, sonarLintRemoteConnectionId);
preferences.put(PROP_PROJECT_KEY, projectKey);
preferences.put(PROP_ORGANIZATION, organization);
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerMockedBuilder.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerMockedBuilder.java
index 0366686..fe9c54c 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerMockedBuilder.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintDataManagerMockedBuilder.java
@@ -27,6 +27,7 @@
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.netbeans.api.project.Project;
+import org.openide.filesystems.FileUtil;
/**
*
@@ -53,6 +54,24 @@ public SonarLintDataManagerMockedBuilder createPreferences(Project project)
{
Mockito.when(sonarLintDataManagerMocked.getPreferences(project))
.thenReturn(new SonarLintPreferencesForTesting());
+ Mockito.when(sonarLintDataManagerMocked.getRemoteConfigurationPreferences(project))
+ .thenReturn(new SonarLintPreferencesForTesting());
+ return this;
+ }
+
+ public SonarLintDataManagerMockedBuilder createPreferences(Project project, SonarLintProjectPreferenceScope scope)
+ {
+ createPreferences(project);
+ preferencesScope(project, scope);
+ return this;
+ }
+
+ public SonarLintDataManagerMockedBuilder addFileToProject(Project project, File file)
+ {
+ Mockito.when(sonarLintDataManagerMocked.getProject(file))
+ .thenReturn(Optional.of(project));
+ Mockito.when(sonarLintDataManagerMocked.getProject(FileUtil.toFileObject(file)))
+ .thenReturn(Optional.of(project));
return this;
}
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavaPluginTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavaPluginTest.java
index 15ed31f..bbd5594 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavaPluginTest.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavaPluginTest.java
@@ -32,6 +32,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
+import org.sonarsource.sonarlint.core.commons.Language;
import org.sonarsource.sonarlint.core.commons.RuleType;
/**
@@ -54,6 +55,7 @@ static Arguments[] parametersForAnalyze() throws IOException
Arguments.of(
SonarLintEngineTestConfiguration.builder()
.requirePlugin("java")
+ .enabledLanguages(Language.JAVA)
.description("SonarLintFileDemo.java with rule java:S115 but without java:S122 and java:S1118 to check CODE_SMELL CRITICAL")
.includeRules("java:S115")
.excludeRules("java:S1220", "java:S1118")
@@ -75,6 +77,7 @@ static Arguments[] parametersForAnalyze() throws IOException
Arguments.of(
SonarLintEngineTestConfiguration.builder()
.requirePlugin("java")
+ .enabledLanguages(Language.JAVA)
.description("NewClass.java with rule java:S1133 but without java:S1186, java:S1598, java:S100, java:S1134, java:S2168 and java:S115 to check CODE_SMELL INFO")
.includeRules("java:S1133")
.excludeRules("java:S1186", "java:S1598", "java:S100", "java:S1134", "java:S2168", "java:S115")
@@ -96,6 +99,7 @@ static Arguments[] parametersForAnalyze() throws IOException
Arguments.of(
SonarLintEngineTestConfiguration.builder()
.requirePlugin("java")
+ .enabledLanguages(Language.JAVA)
.description("SonarLintFileDemo.java with rule java:S115 but without java:S1220 and S1118 rule with default parameters")
.includeRules("java:S115")
.excludeRules("java:S1220", "java:S1118")
@@ -117,6 +121,7 @@ static Arguments[] parametersForAnalyze() throws IOException
Arguments.of(
SonarLintEngineTestConfiguration.builder()
.requirePlugin("java")
+ .enabledLanguages(Language.JAVA)
.description("SonarLintFileDemo.java with rule java:S115 but without java:S1220 and S1118 rule with custom parameters")
.includeRules("java:S115")
.excludeRules("java:S1220", "java:S1118")
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavascriptPluginTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavascriptPluginTest.java
index d19eba8..e4988db 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavascriptPluginTest.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplJavascriptPluginTest.java
@@ -34,6 +34,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
+import org.sonarsource.sonarlint.core.commons.Language;
import org.sonarsource.sonarlint.core.commons.RuleType;
/**
@@ -63,6 +64,7 @@ public static Arguments[] parametersForAnalyze() throws IOException
SonarLintEngineTestConfiguration.builder()
.description("sonarlint-example.js with rule javascript:S108 to check javascript plugin that require nodejs")
.requirePlugin("javascript")
+ .enabledLanguages(Language.JS)
.requireNodeJS()
.excludeRules("javascript:S3504", "javascript:S3827", "javascript:S3504")
.includeRules("javascript:S108")
@@ -85,6 +87,7 @@ public static Arguments[] parametersForAnalyze() throws IOException
SonarLintEngineTestConfiguration.builder()
.description("sonarlint-example-with-global-variables.js with rule javascript:S3827 to check 3 issues from global variable declaring without extra properties \"sonar.javascript.globals\"")
.requirePlugin("javascript")
+ .enabledLanguages(Language.JS)
.requireNodeJS()
.excludeRules("javascript:S3504")
.includeRules("javascript:S3827")
@@ -130,8 +133,9 @@ public static Arguments[] parametersForAnalyze() throws IOException
SonarLintEngineTestConfiguration.builder()
.description("sonarlint-example-with-global-variables.js with rule javascript:S3827 to check one issue from global variable declaring in extra properties \"sonar.javascript.globals\" for \"globalVariables,api\"")
.requirePlugin("javascript")
+ .enabledLanguages(Language.JS)
.requireNodeJS()
- .excludeRules("javascript:S3504")
+ .excludeRules("javascript:S3504")
.includeRules("javascript:S3827")
.addClientInputFile(new File("./src/test/resources/sonarlint-example-with-global-variables.js"))
.addExtraProperty("sonar.javascript.globals", "globalVariables,api", SonarLintEngine.GLOBAL_SETTINGS_PROJECT)
@@ -155,6 +159,7 @@ public static Arguments[] parametersForAnalyze() throws IOException
.description("sonarlint-example-with-global-variables.js with rule javascript:S3827 to check two issues from global variable declaring with extra properties \"sonar.javascript.globals\" for \"AapiI\"")
.requirePlugin("javascript")
.requireNodeJS()
+ .enabledLanguages(Language.JS)
.excludeRules("javascript:S3504")
.includeRules("javascript:S3827")
.addClientInputFile(new File("./src/test/resources/sonarlint-example-with-global-variables.js"))
@@ -189,6 +194,7 @@ public static Arguments[] parametersForAnalyze() throws IOException
SonarLintEngineTestConfiguration.builder()
.description("sonarlint-example.css with rule css:S1116 to check one issue on line \"4\"")
.requirePlugin("javascript")
+ .enabledLanguages(Language.JS)
.requireNodeJS()
.includeRules("css:S1116")
.addClientInputFile(new File("./src/test/resources/sonarlint-example.css"))
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplPhpPluginTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplPhpPluginTest.java
index c3a0563..f1e1438 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplPhpPluginTest.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplPhpPluginTest.java
@@ -33,6 +33,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
+import org.sonarsource.sonarlint.core.commons.Language;
import org.sonarsource.sonarlint.core.commons.RuleType;
/**
@@ -57,6 +58,7 @@ public static Arguments[] parametersForAnalyze() throws IOException
SonarLintEngineTestConfiguration.builder()
.description("sonarlin-example.php with rule php:S101 but without php:S1105 to check php plugin")
.requirePlugin("php")
+ .enabledLanguages(Language.PHP)
.excludeRules("php:S1105", "php:S1808", "php:S1779")
.includeRules("php:S101")
.addClientInputFile(new File("./src/test/resources/sonarlint-example.php"))
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTest.java
index a0f62a8..762511c 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTest.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTest.java
@@ -34,6 +34,7 @@
import org.mockito.Mockito;
import org.netbeans.api.project.Project;
import org.netbeans.spi.project.ProjectManagerImplementation;
+import org.sonarsource.sonarlint.core.commons.Language;
/**
*
@@ -66,7 +67,7 @@ public void getRuleParameter() throws MalformedURLException, BackingStoreExcepti
String parameterName = "max";
String parameterValueOnProjectScope = "5";
String parameterValueOnGlobalScope = "4";
- SonarLintEngineImpl sonarLintEngine = new SonarLintEngineImpl();
+ SonarLintEngineImpl sonarLintEngine = new SonarLintEngineImpl(new Language[] {Language.JAVA});
sonarLintEngine.waitingInitialization();
sonarLintEngine.getPreferences(SonarLintEngine.GLOBAL_SETTINGS_PROJECT).removeNode();
sonarLintEngine.setRuleParameter(ruleKey, parameterName, parameterValueOnProjectScope, mockedProjectWithProjectScope);
@@ -132,7 +133,7 @@ public void getMergedExtraProperties(
Map exptectedProperties
) {
// Given
- SonarLintEngineImpl sonarLintEngine = new SonarLintEngineImpl();
+ SonarLintEngineImpl sonarLintEngine = new SonarLintEngineImpl(new Language[] {});
sonarLintEngine.waitingInitialization();
sonarLintEngine.setExtraProperties(actualGlobalProperties, SonarLintEngine.GLOBAL_SETTINGS_PROJECT);
sonarLintEngine.setExtraProperties(actualProjectProperties, project);
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTestUtils.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTestUtils.java
index 43c52aa..8b42293 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTestUtils.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplTestUtils.java
@@ -51,7 +51,7 @@ private SonarLintEngineImplTestUtils() {
public static void analyzeTesting(SonarLintEngineTestConfiguration testConfiguration, List expectedIssue) throws BackingStoreException, IOException
{
- SonarLintEngineImpl sonarLintEngine = new SonarLintEngineImpl();
+ SonarLintEngineImpl sonarLintEngine = new SonarLintEngineImpl(testConfiguration.getEnabledLanguages());
sonarLintEngine.waitingInitialization();
if (testConfiguration.isRequireNodeJS()) {
SonarLintTestUtils.installNodeJS();
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplWebPluginTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplWebPluginTest.java
index 266ef39..407e52c 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplWebPluginTest.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplWebPluginTest.java
@@ -33,6 +33,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
+import org.sonarsource.sonarlint.core.commons.Language;
import org.sonarsource.sonarlint.core.commons.RuleType;
/**
@@ -57,6 +58,7 @@ public static Arguments[] parametersForAnalyze() throws IOException
SonarLintEngineTestConfiguration.builder()
.description("sonarlin-example.php with rule php:S101 but without php:S1105 to check php plugin")
.requirePlugin("web")
+ .enabledLanguages(Language.HTML)
.includeRules("Web:BoldAndItalicTagsCheck", "Web:S5254")
.addClientInputFile(new File("./src/test/resources/sonarlint-example.html"))
.build(),
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplXmlPluginTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplXmlPluginTest.java
index b39475a..4714539 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplXmlPluginTest.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineImplXmlPluginTest.java
@@ -33,6 +33,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
+import org.sonarsource.sonarlint.core.commons.Language;
import org.sonarsource.sonarlint.core.commons.RuleType;
/**
@@ -57,6 +58,7 @@ public static Arguments[] parametersForAnalyze() throws IOException
SonarLintEngineTestConfiguration.builder()
.description("sonarlin-example.php with rule php:S101 but without php:S1105 to check php plugin")
.requirePlugin("xml")
+ .enabledLanguages(Language.XML)
.includeRules("xml:S1134")
.addClientInputFile(new File("./src/test/resources/sonarlint-example.xml"))
.build(),
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineTestConfiguration.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineTestConfiguration.java
index 0e49acc..eb4f2c2 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineTestConfiguration.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintEngineTestConfiguration.java
@@ -30,6 +30,7 @@
import java.util.Map;
import org.netbeans.api.project.Project;
import org.sonarsource.sonarlint.core.analysis.api.ClientInputFile;
+import org.sonarsource.sonarlint.core.commons.Language;
import org.sonarsource.sonarlint.core.commons.RuleKey;
/**
@@ -44,6 +45,7 @@ public final class SonarLintEngineTestConfiguration {
private final List ruleParameters;
private final Map> extraProperties;
private final List requirePlugin;
+ private final Language[] enabledLanguages;
private final boolean requireNodeJS;
@@ -56,6 +58,7 @@ private SonarLintEngineTestConfiguration(Builder builder) {
this.requireNodeJS = builder.requireNodeJS;
this.extraProperties = builder.extraProperties;
this.requirePlugin = builder.requirePlugin;
+ this.enabledLanguages = builder.enabledLanguages;
}
public List getExcludedRules() {
@@ -86,6 +89,10 @@ public Map> getExtraProperties() {
return extraProperties;
}
+ public Language[] getEnabledLanguages() {
+ return enabledLanguages;
+ }
+
@Override
public String toString() {
return description;
@@ -128,6 +135,7 @@ public static final class Builder {
private final Map> extraProperties = new HashMap<>();
private final List requirePlugin = new ArrayList<>();
private boolean requireNodeJS = false;
+ private Language[] enabledLanguages = Language.values();
public Builder description(String description) {
this.description = description;
@@ -181,6 +189,11 @@ public Builder requirePlugin(String pluginKey) {
return this;
}
+ public Builder enabledLanguages(Language ... enabledLanguages) {
+ this.enabledLanguages = enabledLanguages;
+ return this;
+ }
+
public SonarLintEngineTestConfiguration build() {
return new SonarLintEngineTestConfiguration(this);
}
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintUtilsTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintUtilsTest.java
index 65a9809..cb0fed5 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintUtilsTest.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/SonarLintUtilsTest.java
@@ -19,6 +19,7 @@
*/
package com.github.philippefichet.sonarlint4netbeans;
+import com.github.philippefichet.sonarlint4netbeans.junit.jupiter.extension.SonarLintEngineEnableLanguage;
import com.github.philippefichet.sonarlint4netbeans.junit.jupiter.extension.SonarLintLookupMockedExtension;
import com.github.philippefichet.sonarlint4netbeans.project.SonarLintProjectPreferenceScope;
import com.github.philippefichet.sonarlint4netbeans.treenode.SonarLintAnalyzerRootNode;
@@ -68,6 +69,7 @@
import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneRuleDetails;
import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneRuleParam;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
+import org.sonarsource.sonarlint.core.commons.Language;
import org.sonarsource.sonarlint.core.commons.RuleKey;
import org.sonarsource.sonarlint.core.commons.RuleType;
import org.sonarsource.sonarlint.core.commons.Version;
@@ -82,38 +84,34 @@ class SonarLintUtilsTest {
@Nested
class ProjectBased {
- private final Project mockedProjectWithProjectScope = Mockito.mock(Project.class);
- private final Project mockedSecondProjectWithGlobalScope = Mockito.mock(Project.class);
- private final Project mockedThirdProjectWithGlobalScope = Mockito.mock(Project.class);
- private final Project mockedFirstProjectWithGlobalScope = Mockito.mock(Project.class);
+ private final Project mockedProjectWithProjectScope = new ProjectMockedBuilder().build();
+ private final Project mockedSecondProjectWithGlobalScope = new ProjectMockedBuilder().build();
+ private final Project mockedThirdProjectWithGlobalScope = new ProjectMockedBuilder().build();
+ private final Project mockedFirstProjectWithGlobalScope = new ProjectMockedBuilder().build();
+ private final Project sonarlint4netbeansSampleMavenProject = new ProjectMockedBuilder()
+ .projectDirectory(new File("./src/test/samples/sonarlint4netbeans-sample-mavenproject"))
+ .build();
@RegisterExtension
private final SonarLintLookupMockedExtension lookupExtension = SonarLintLookupMockedExtension.builder()
.logCall()
- .mockLookupMethodInstanceWith(SonarLintEngine.class, () -> {
- SonarLintEngineImpl engine = new SonarLintEngineImpl();
- engine.waitingInitialization();
- return engine;
- })
.mockLookupMethodWith(ProjectManagerImplementation.class, Mockito.mock(ProjectManagerImplementation.class))
.mockLookupMethodWith(SonarLintOptions.class, Mockito.mock(SonarLintOptions.class))
.mockLookupMethodWith(
SonarLintDataManager.class,
new SonarLintDataManagerMockedBuilder()
- .createPreferences(mockedProjectWithProjectScope)
- .preferencesScope(mockedProjectWithProjectScope, SonarLintProjectPreferenceScope.PROJECT)
- .createPreferences(mockedFirstProjectWithGlobalScope)
- .preferencesScope(mockedFirstProjectWithGlobalScope, SonarLintProjectPreferenceScope.GLOBAL)
- .createPreferences(mockedSecondProjectWithGlobalScope)
- .preferencesScope(mockedSecondProjectWithGlobalScope, SonarLintProjectPreferenceScope.GLOBAL)
- .createPreferences(mockedThirdProjectWithGlobalScope)
- .preferencesScope(mockedThirdProjectWithGlobalScope, SonarLintProjectPreferenceScope.GLOBAL)
+ .createPreferences(mockedProjectWithProjectScope, SonarLintProjectPreferenceScope.PROJECT)
+ .createPreferences(mockedFirstProjectWithGlobalScope, SonarLintProjectPreferenceScope.GLOBAL)
+ .createPreferences(mockedSecondProjectWithGlobalScope, SonarLintProjectPreferenceScope.GLOBAL)
+ .createPreferences(mockedThirdProjectWithGlobalScope, SonarLintProjectPreferenceScope.GLOBAL)
.preferencesScope(SonarLintEngine.GLOBAL_SETTINGS_PROJECT, SonarLintProjectPreferenceScope.GLOBAL)
+ .createPreferences(sonarlint4netbeansSampleMavenProject, SonarLintProjectPreferenceScope.REMOTE)
.build()
).build();
@Test
@DisplayName("Analyze hierarchical tree used in \"Analyze with Sonarlint\"")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void likeAnalyzeWithSonarlint() throws IOException, BackingStoreException {
// first step, check all issue in file
List actualIssues = new ArrayList<>();
@@ -249,6 +247,7 @@ void likeAnalyzeWithSonarlint() throws IOException, BackingStoreException {
@Test
@DisplayName("Analyze with custom rule parameter value on project with global scope")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void ruleParameterChangedOnProjectWithGlobalScope() throws IOException, BackingStoreException {
SonarLintDataManager sonarlintDataMangerMocked = lookupExtension.lookupMocked(SonarLintDataManager.class).get();
SonarLintEngine sonarLintEngine = SonarLintTestUtils.getCleanSonarLintEngine();
@@ -303,6 +302,7 @@ void ruleParameterChangedOnProjectWithGlobalScope() throws IOException, BackingS
@Test
@DisplayName("Analyze with custom rule parameter value on project")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void ruleParameterChangedOnProject() throws IOException, BackingStoreException {
SonarLintDataManager sonarlintDataMangerMocked = lookupExtension.lookupMocked(SonarLintDataManager.class).get();
SonarLintEngine sonarLintEngine = SonarLintTestUtils.getCleanSonarLintEngine();
@@ -351,6 +351,7 @@ void ruleParameterChangedOnProject() throws IOException, BackingStoreException {
@Test
@DisplayName("Check custom rule parameter value from extractRuleParameters on project with global scope")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void extractRuleParametersWithCustomValueOnProjectWithGlobalScope() throws BackingStoreException, MalformedURLException {
SonarLintEngine sonarLintEngine = new SonarLintEngineImpl();
SonarLintTestUtils.cleanSonarLintEngine(sonarLintEngine);
@@ -386,6 +387,7 @@ void extractRuleParametersWithCustomValueOnProjectWithGlobalScope() throws Backi
@Test
@DisplayName("Analyze with extra properties on project")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void extraPropertiesOnProject() throws IOException, BackingStoreException {
String commonExtraPropertyName = "sonar.java.source";
SonarLintDataManager sonarlintDataMangerMocked = lookupExtension.lookupMocked(SonarLintDataManager.class).get();
@@ -473,6 +475,7 @@ void extraPropertiesOnProject() throws IOException, BackingStoreException {
@Test
@DisplayName("Check custom rule parameter value from extractRuleParameters")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void extractRuleParametersWithCustomValue() throws BackingStoreException {
SonarLintEngine sonarLintEngine = SonarLintTestUtils.getCleanSonarLintEngine();
String ruleKeyString = "java:S115";
@@ -487,6 +490,7 @@ void extractRuleParametersWithCustomValue() throws BackingStoreException {
@Test
@DisplayName("Check default rule parameter value from extractRuleParameters")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void extractRuleParametersWithDefaultValue() throws BackingStoreException {
SonarLintEngine sonarLintEngine = SonarLintTestUtils.getCleanSonarLintEngine();
String ruleKeyString = "java:S115";
@@ -500,6 +504,7 @@ void extractRuleParametersWithDefaultValue() throws BackingStoreException {
@Test
@DisplayName("Analyze hierarchical tree used in \"Analyze with Sonarlint\" with a custom rule parameter value")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void likeAnalyzeWithSonarlintWithParameter() throws BackingStoreException, IOException {
SonarLintEngine sonarLintEngine = SonarLintTestUtils.getCleanSonarLintEngine();
sonarLintEngine.getAllRuleDetails().forEach(ruleKey -> sonarLintEngine.excludeRuleKey(RuleKey.parse(ruleKey.getKey()), SonarLintEngine.GLOBAL_SETTINGS_PROJECT));
@@ -585,6 +590,7 @@ void likeAnalyzeWithSonarlintWithParameter() throws BackingStoreException, IOExc
@Test
@DisplayName("Analyze with custom rule parameter value")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void ruleParameterChanged() throws BackingStoreException, IOException {
SonarLintEngine sonarLintEngine = SonarLintTestUtils.getCleanSonarLintEngine();
String ruleKeyString = "java:S115";
@@ -602,6 +608,7 @@ void ruleParameterChanged() throws BackingStoreException, IOException {
@Test
@DisplayName("Analyze with custom rule parameter value to check ${projectDir}")
+ @SonarLintEngineEnableLanguage(languages = Language.JAVA)
void analyseFilesOnTwoProjectWithProjectDirInProperties(
@TempDir File projectDir1,
@TempDir File projectDir2,
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/junit/jupiter/extension/SonarLintEngineEnableLanguage.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/junit/jupiter/extension/SonarLintEngineEnableLanguage.java
new file mode 100644
index 0000000..c30fb27
--- /dev/null
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/junit/jupiter/extension/SonarLintEngineEnableLanguage.java
@@ -0,0 +1,37 @@
+/*
+ * sonarlint4netbeans: SonarLint integration for Apache Netbeans
+ * Copyright (C) 2023 Philippe FICHET.
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.github.philippefichet.sonarlint4netbeans.junit.jupiter.extension;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.sonarsource.sonarlint.core.commons.Language;
+
+/**
+ *
+ * @author FICHET Philippe <philippe.fichet@laposte.net>
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface SonarLintEngineEnableLanguage {
+
+ Language[] languages();
+}
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/junit/jupiter/extension/SonarLintLookupMockedExtension.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/junit/jupiter/extension/SonarLintLookupMockedExtension.java
index 81ad6bd..89fd410 100644
--- a/src/test/java/com/github/philippefichet/sonarlint4netbeans/junit/jupiter/extension/SonarLintLookupMockedExtension.java
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/junit/jupiter/extension/SonarLintLookupMockedExtension.java
@@ -20,8 +20,12 @@
package com.github.philippefichet.sonarlint4netbeans.junit.jupiter.extension;
import com.github.philippefichet.sonarlint4netbeans.Predicates;
+import com.github.philippefichet.sonarlint4netbeans.SonarLintEngine;
+import com.github.philippefichet.sonarlint4netbeans.SonarLintEngineImpl;
import com.github.philippefichet.sonarlint4netbeans.assertj.SonarLintArgumentMatchers;
+import com.github.philippefichet.sonarlint4netbeans.remote.SonarLintRemoteEngine;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -38,6 +42,7 @@
import org.openide.util.Lookup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonarsource.sonarlint.core.commons.Language;
/**
*
@@ -118,18 +123,22 @@ private void init()
});
}
+ mockLookupMethodInstance(lookupMethodInstance);
+ }
+
+ private void mockLookupMethodInstance(Map, Supplier>> lookupMethodInstance) {
if (!lookupMethodInstance.isEmpty()) {
Map, Object> instances = new HashMap<>();
lookupMethodInstance.forEach(
(Class> clazz, Supplier> supplier) -> {
- Mockito.when(mockedLookup.lookup(clazz))
+ Mockito.when(mockedLookup.lookup(clazz))
.thenAnswer(
(InvocationOnMock iom) -> {
if (logCall) {
LOG.debug("defaultLookup.lookup(Class>) for an specific instance called with \"{}\"", clazz);
}
return instances.computeIfAbsent(clazz, (Class> cls) -> supplier.get());
- });
+ });
}
);
}
@@ -137,6 +146,20 @@ private void init()
@Override
public void interceptTestMethod(Invocation invocation, ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable {
+ SonarLintEngineEnableLanguage annotation = invocationContext.getExecutable().getAnnotation(SonarLintEngineEnableLanguage.class);
+ Language[] languages = annotation == null ? Language.values() : annotation.languages();
+ LOG.info("Language enabled: \"{}\"", Arrays.toString(languages));
+ Map, Supplier>> lookupMethodInstanceEngines = new HashMap<>();
+ lookupMethodInstanceEngines.put(SonarLintEngine.class, () -> {
+ SonarLintEngineImpl engine = new SonarLintEngineImpl(languages);
+ engine.waitingInitialization();
+ return engine;
+ });
+ lookupMethodInstanceEngines.put(SonarLintRemoteEngine.class, () -> {
+ SonarLintRemoteEngine engine = new SonarLintRemoteEngine(languages);
+ return engine;
+ });
+ mockLookupMethodInstance(lookupMethodInstanceEngines);
executeInMockedLookup(() -> {
try {
InvocationInterceptor.super.interceptTestMethod(
diff --git a/src/test/java/com/github/philippefichet/sonarlint4netbeans/remote/SonarLintRemoteEngineTest.java b/src/test/java/com/github/philippefichet/sonarlint4netbeans/remote/SonarLintRemoteEngineTest.java
new file mode 100644
index 0000000..c7e77e7
--- /dev/null
+++ b/src/test/java/com/github/philippefichet/sonarlint4netbeans/remote/SonarLintRemoteEngineTest.java
@@ -0,0 +1,128 @@
+/*
+ * sonarlint4netbeans: SonarLint integration for Apache Netbeans
+ * Copyright (C) 2023 Philippe FICHET.
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.github.philippefichet.sonarlint4netbeans.remote;
+
+import com.github.philippefichet.sonarlint4netbeans.DefaultIssueTestImpl;
+import com.github.philippefichet.sonarlint4netbeans.ProjectMockedBuilder;
+import com.github.philippefichet.sonarlint4netbeans.SonarLintDataManager;
+import com.github.philippefichet.sonarlint4netbeans.SonarLintDataManagerMockedBuilder;
+import com.github.philippefichet.sonarlint4netbeans.SonarLintUtils;
+import com.github.philippefichet.sonarlint4netbeans.junit.jupiter.extension.SonarLintLookupMockedExtension;
+import com.github.philippefichet.sonarlint4netbeans.project.SonarLintProjectPreferenceScope;
+import com.github.philippefichet.sonarlint4netbeans.remote.configuration.SonarLintRemoteConnectionConfiguration;
+import com.github.philippefichet.sonarlint4netbeans.remote.configuration.SonarLintRemoteConnectionConfigurationManagement;
+import com.github.philippefichet.sonarlint4netbeans.remote.configuration.SonarLintRemoteProjectConfiguration;
+import com.github.philippefichet.sonarlint4netbeans.remote.synchronization.TaskWrapper;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.mockito.Mockito;
+import org.netbeans.api.project.Project;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Lookup;
+import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
+import org.sonarsource.sonarlint.core.commons.IssueSeverity;
+import org.sonarsource.sonarlint.core.commons.Language;
+import org.sonarsource.sonarlint.core.commons.RuleType;
+
+/**
+ *
+ * @author FICHET Philippe <philippe.fichet@laposte.net>
+ */
+@EnabledIfSystemProperty(
+ named = "sonarlint4netbeans.test.remote.project-maven1.token",
+ matches = "[a-f0-9]+",
+ disabledReason = "Disabled because require token to check remote issue on sample project"
+)
+public class SonarLintRemoteEngineTest {
+
+ private final Project sonarlint4netbeansSampleMavenProject = new ProjectMockedBuilder()
+ .projectDirectory(new File("./src/test/samples/sonarlint4netbeans-sample-mavenproject/branch-main"))
+ .build();
+
+ private final File sonarlint4netbeansSampleMavenProjectNewClass =
+ new File("./src/test/samples/sonarlint4netbeans-sample-mavenproject/branch-main/src/main/java/com/mycompany/mavenproject1/NewClass.java");
+
+ @RegisterExtension
+ SonarLintLookupMockedExtension sonarLintLookupMockedExtension = SonarLintLookupMockedExtension.builder()
+ .logCall()
+ .mockLookupMethodWith(
+ SonarLintDataManager.class,
+ new SonarLintDataManagerMockedBuilder()
+ .createPreferences(sonarlint4netbeansSampleMavenProject)
+ .preferencesScope(sonarlint4netbeansSampleMavenProject, SonarLintProjectPreferenceScope.REMOTE)
+ .addFileToProject(sonarlint4netbeansSampleMavenProject, sonarlint4netbeansSampleMavenProjectNewClass)
+ .build()
+ ).mockLookupMethodWith(Project.class, Mockito.mock(Project.class))
+ .mockLookupMethodWith(SonarLintRemoteConnectionConfigurationManagement.class, Mockito.mock(SonarLintRemoteConnectionConfigurationManagement.class))
+ .build();
+
+ @Test
+ public void remote() throws InterruptedException, IOException {
+ SonarLintRemoteConnectionConfigurationManagement sonarLintRemoteConnectionConfigurationManagement = Lookup.getDefault().lookup(SonarLintRemoteConnectionConfigurationManagement.class);
+ String connectionId = "testing-connection-id-sonarcloud";
+ String projectKey = "philippefichet_sonarlint4netbeans-sample-mavenproject";
+ String branchName = "master";
+ String baseURL = "https://sonarcloud.io";
+ boolean isSonarCloud = true;
+ String organization = "philippefichet";
+ String login = System.getProperty("sonarlint4netbeans.test.remote.project-maven1.token");
+ SonarLintRemoteConnectionConfiguration sonarLintRemoteConnectionConfiguration = new SonarLintRemoteConnectionConfiguration(
+ connectionId,
+ baseURL,
+ isSonarCloud
+ );
+ Mockito.when(sonarLintRemoteConnectionConfigurationManagement.getAuthTokenFromConnectionId(connectionId))
+ .thenReturn(Optional.of(login));
+ Mockito.when(sonarLintRemoteConnectionConfigurationManagement.getSonarLintConnectionConfigurationFromConnectionId(connectionId))
+ .thenReturn(Optional.of(sonarLintRemoteConnectionConfiguration));
+
+ SonarLintRemoteEngine remoteEngine = new SonarLintRemoteEngine(new Language[] {Language.JAVA});
+ SonarLintRemoteProjectConfiguration sonarLintRemoteProjectConfiguration = new SonarLintRemoteProjectConfiguration(
+ sonarlint4netbeansSampleMavenProject,
+ connectionId,
+ projectKey,
+ organization,
+ branchName
+ );
+ SonarLintRemoteProjectConfiguration.save(sonarlint4netbeansSampleMavenProject, connectionId, projectKey, organization);
+ TaskWrapper sync = remoteEngine.launchResyncTask(
+ sonarLintRemoteProjectConfiguration
+ );
+ sync.getTask().waitFinished(30_000);
+ List issues = SonarLintUtils.analyze(FileUtil.toFileObject(sonarlint4netbeansSampleMavenProjectNewClass), null);
+ Assertions.assertThat(issues)
+ .extracting(DefaultIssueTestImpl::toTuple)
+ .containsAnyOf(
+ new DefaultIssueTestImpl.Builder()
+ .severity(IssueSeverity.MAJOR)
+ .type(RuleType.CODE_SMELL)
+ .ruleKey("java:S2629")
+ .startLine(80)
+ .endLine(80)
+ .buildTuple()
+ );
+ }
+}
diff --git a/src/test/resources/logging.properties b/src/test/resources/logging.properties
index cf8ee15..7099a1a 100644
--- a/src/test/resources/logging.properties
+++ b/src/test/resources/logging.properties
@@ -1,9 +1,9 @@
handlers=java.util.logging.ConsoleHandler
.level=INFO
-java.util.logging.ConsoleHandler.level=FINEST
+java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
# String.format(format, date, source, logger, level, message, thrown);
# https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html
# %[argument_index$][flags][width][.precision]conversion
java.util.logging.SimpleFormatter.format=| %1$tc | %2$s | %3$s | %4$5s | %5$s |%n
-com.github.philippefichet.sonarlint4netbeans.level=FINEST
+com.github.philippefichet.sonarlint4netbeans.level=INFO
diff --git a/src/test/samples/sonarlint4netbeans-sample-mavenproject/branch-main/src/main/java/com/mycompany/mavenproject1/NewClass.java b/src/test/samples/sonarlint4netbeans-sample-mavenproject/branch-main/src/main/java/com/mycompany/mavenproject1/NewClass.java
new file mode 100644
index 0000000..28777b6
--- /dev/null
+++ b/src/test/samples/sonarlint4netbeans-sample-mavenproject/branch-main/src/main/java/com/mycompany/mavenproject1/NewClass.java
@@ -0,0 +1,83 @@
+/*
+ * sonarlint4netbeans-sample-mavenproject: Sample for SonarLint integration for Apache Netbeans
+ * Copyright (C) 2023 Philippe FICHET.
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.mycompany.mavenproject1;
+
+import java.nio.file.Path;
+
+public class NewClass {
+ private static String resource;
+ public static final String const_convition_violation = "TEST";
+
+ /**
+ *
+ * @deprecated
+ */
+ @Deprecated
+ public void deprecatedMethod() {}
+
+ public void MethodName_Convention_Violation() {}
+
+
+ // FIXME test
+ public static String getInstance() {
+ if (resource == null) {
+ synchronized (NewClass.class) {
+ if (resource == null)
+ resource = "";
+ }
+ }
+ return resource;
+ }
+
+ public static void lambdaTest()
+ {
+ String t = "toto";
+ Runnable r = () -> {
+ for (int i = 0; i < 10; i++) {
+ System.out.println(t.trim());
+ }
+ };
+ new Thread(r).start();
+ }
+
+ public static void tooManyParameter(int param1, int param2, int param3, String param4, long param5, int param6, int param7, int param8, String param9) {
+ System.out.println("test");
+ }
+
+ /**
+ * Use "sonar.java.source=8" property to detected this issue
+ */
+ public static void checkS3725WithExtraProperties() {
+ Path myPath = null;
+ if(java.nio.file.Files.exists(myPath)) { // Noncompliant
+ // do something
+ }
+ }
+
+ /**
+ * Use "sonar.java.libraries=${projectDir}/target/lib/*.jar" and
+ * java:S2629 must be enabled and slf4j-api-1.7.36 copied in target/lib
+ * to show an issue
+ * Or cloud analyse
+ */
+ public static void checkJavaS2629WithExtraPropertiesAndProjectDir(String arg1) {
+ org.slf4j.LoggerFactory.getLogger("Testing").debug("message: " + arg1);
+ }
+}