Skip to content

Commit

Permalink
SLE-986: Update SLCORE
Browse files Browse the repository at this point in the history
Adjust based on the changes coming from SLCORE and remove dead code.
  • Loading branch information
thahnen committed Dec 3, 2024
1 parent b66356b commit 7b74655
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.GetSharedConnectedModeConfigFileParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.GetSharedConnectedModeConfigFileResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.branch.DidVcsRepositoryChangeParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.branch.GetMatchedSonarProjectBranchParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.branch.GetMatchedSonarProjectBranchResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.config.DidChangeCredentialsParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.projects.GetAllProjectsParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.projects.SonarProjectDto;
Expand Down Expand Up @@ -328,14 +326,6 @@ public void didVcsRepositoryChange(ISonarLintProject project) {
.didVcsRepositoryChange(new DidVcsRepositoryChangeParams(ConfigScopeSynchronizer.getConfigScopeId(project)));
}

public GetMatchedSonarProjectBranchResponse getMatchedSonarProjectBranch(ISonarLintProject project)
throws InterruptedException, ExecutionException {
return getBackend()
.getSonarProjectBranchService()
.getMatchedSonarProjectBranch(new GetMatchedSonarProjectBranchParams(ConfigScopeSynchronizer.getConfigScopeId(project)))
.get();
}

public void credentialsChanged(ConnectionFacade connection) {
getBackend().getConnectionService().didChangeCredentials(new DidChangeCredentialsParams(connection.getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonarlint.eclipse.ui.internal.job;

import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -32,16 +31,12 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.sonarlint.eclipse.core.SonarLintLogger;
import org.sonarlint.eclipse.core.documentation.SonarLintDocumentation;
import org.sonarlint.eclipse.core.internal.backend.ConfigScopeSynchronizer;
import org.sonarlint.eclipse.core.internal.backend.SonarLintBackendService;
import org.sonarlint.eclipse.core.internal.jobs.AnalysisReadyStatusCache;
import org.sonarlint.eclipse.core.internal.vcs.VcsService;
import org.sonarlint.eclipse.core.resource.ISonarLintFile;
import org.sonarlint.eclipse.core.resource.ISonarLintProject;
import org.sonarlint.eclipse.ui.internal.SonarLintUiPlugin;
import org.sonarlint.eclipse.ui.internal.dialog.AwaitProjectConnectionReadyDialog;
import org.sonarlint.eclipse.ui.internal.util.BrowserUtils;
import org.sonarlint.eclipse.ui.internal.util.MessageDialogUtils;

/**
Expand All @@ -55,15 +50,12 @@ public abstract class AbstractOpenInEclipseJob extends Job {

protected final ISonarLintProject project;
private final boolean skipAnalysisReadyCheck;
private final boolean skipBranchCheck;

protected AbstractOpenInEclipseJob(String name, ISonarLintProject project, boolean skipAnalysisReadyCheck,
boolean skipBranchCheck) {
protected AbstractOpenInEclipseJob(String name, ISonarLintProject project, boolean skipAnalysisReadyCheck) {
super(name);

this.project = project;
this.skipAnalysisReadyCheck = skipAnalysisReadyCheck;
this.skipBranchCheck = skipBranchCheck;
}

@Override
Expand Down Expand Up @@ -116,15 +108,6 @@ protected IStatus run(IProgressMonitor monitor) {
return Status.CANCEL_STATUS;
}
file = fileOpt.get();

/**
* Due to the Git logic moving slowly to SLCORE to be IDE-independant, this check might already been done on
* their side based on the feature using this logic. On the long run this is going to be removed as the branch
* check will be done completely on SLCORE side for every feature.
*/
if (!skipBranchCheck && !tryMatchBranches()) {
return Status.CANCEL_STATUS;
}
}

try {
Expand Down Expand Up @@ -158,48 +141,6 @@ private Optional<ISonarLintFile> tryGetLocalFile() {
return fileOpt;
}

/**
* Branch check: Local and remote information should match (if no local branch found, at least try your best).
*
* As mentioned above, this might not be needed by every feature building on-top of this class and will eventually
* be removed. That is also the reason for the constructor flag!
*/
private boolean tryMatchBranches() {
var branch = getBranch();
if (branch == null) {
return false;
}

// In case SLCORE is not yet ready for the SonarProjectBranchService, we also check via this plug-ins VcsService
// using the JGit dependency coming bundled from SLCORE. This should yield a result when actually in a Git
// repository but if not, it is no problem as it is only used in case of the Open in IDE with automatic Connected
// Mode setup.
Optional<String> localBranch = Optional.empty();
try {
var response = SonarLintBackendService.get().getMatchedSonarProjectBranch(project);
localBranch = Optional.ofNullable(response.getMatchedSonarProjectBranch());
} catch (InterruptedException | ExecutionException err) {
SonarLintLogger.get().debug("Cannot get matched branch from backend, trying local VCS service", err);
}
if (localBranch.isEmpty()) {
localBranch = VcsService.getCachedSonarProjectBranch(project);
}

if (localBranch.isEmpty()) {
// This error message may be misleading to COBOL / ABAP developers but that is okay for now :>
MessageDialogUtils.branchNotAvailable("The local branch of the project '" + project.getName()
+ "' could not be determined. SonarLint now can only try to find the matching local issue!");
} else if (!branch.equals(localBranch.get())) {
MessageDialogUtils.branchMismatch("The local branch '" + localBranch.get() + "' of the project '"
+ project.getName() + "' does not match the remote branch '" + branch + "'. "
+ "Please checkout the correct branch and invoke the requested action once again!");
BrowserUtils.openExternalBrowser(SonarLintDocumentation.BRANCH_AWARENESS, Display.getDefault());
return false;
}

return true;
}

/**
* The actual feature specific logic after everything is set up accordingly and the base checks are done.
*
Expand All @@ -210,13 +151,4 @@ private boolean tryMatchBranches() {

/** As we work per "ISonarLintFile" we want to get the IDE (project relative) path from a file on the server */
abstract String getIdeFilePath();

/**
* This is needed to get the branch from the specific feature information, shouldn't be overwritten by sub-classes
* that have "skipBranchCheck" set to "true"!
*/
@Nullable
protected String getBranch() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class OpenFixSuggestionInEclipseJob extends AbstractOpenInEclipseJob {
private final FixSuggestionDto fixSuggestion;

public OpenFixSuggestionInEclipseJob(FixSuggestionDto fixSuggestion, ISonarLintProject project) {
super("Open fix suggestion in IDE", project, true, true);
super("Open fix suggestion in IDE", project, true);

this.fixSuggestion = fixSuggestion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class OpenIssueInEclipseJob extends AbstractOpenInEclipseJob {
private final boolean askedForPreferenceChangeAlready;

public OpenIssueInEclipseJob(OpenIssueContext context) {
super(context.getName(), context.getProject(), false, false);
super(context.getName(), context.getProject(), false);

this.name = context.getName();
this.issueDetails = context.getIssueDetails();
Expand All @@ -80,11 +80,6 @@ protected String getIdeFilePath() {
return issueDetails.getIdeFilePath().toString();
}

@Override
protected String getBranch() {
return issueDetails.getBranch();
}

/** Handle normal issues: They can be present as On-the-fly / Report markers */
private IStatus handleNormalIssue() throws CoreException {
// Check with possible On-The-Fly markers of that file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,10 @@ public static void dialogCancelled(String message) {
showError("Dialog cancelled", message);
}

public static void branchMismatch(String message) {
showError("Branch does not match", message);
}

public static void openInEclipseFailed(String message) {
showError("Open in Eclipse failed", message);
}

public static void branchNotAvailable(String message) {
Display.getDefault().syncExec(() -> MessageDialog.openInformation(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Branch not matchable", message));
}

/** For the "Open in IDE" feature we want to display a yes/no question for the user to answer */
public static void openInIdeQuestion(String message, Runnable yesHandler) {
Display.getDefault().asyncExec(() -> {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<tycho.version>4.0.8</tycho.version>

<!-- Sloop embedded CLI version for fragment projects -->
<sloop.version>10.11.0.79652</sloop.version>
<sloop.version>10.11.0.79687</sloop.version>

<!-- SonarQube analysis -->
<sonar.java.source>11</sonar.java.source>
Expand Down
2 changes: 1 addition & 1 deletion target-platforms/commons-build.target
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<dependency>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-java-client-osgi</artifactId>
<version>10.11.0.79652</version>
<version>10.11.0.79687</version>
<type>jar</type>
</dependency>
</dependencies>
Expand Down

0 comments on commit 7b74655

Please sign in to comment.