Skip to content

Commit

Permalink
chore: remove obsolete references to seed node
Browse files Browse the repository at this point in the history
  • Loading branch information
JChrist committed Jan 16, 2025
1 parent 54612ea commit a5e3f04
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ video
*.iml
target/
macos-sdk-11.3/
META-INF/jrad/
**/META-INF/jrad/**
artifacts/
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pluginUntilBuild=

# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
platformType = IC
# cannot use 2024.3.1 (or 2024.3.1.1) https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1838
platformVersion = 2024.3
#platformVersion = LATEST-EAP-SNAPSHOT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.intellij.openapi.project.Project;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import network.radicle.jetbrains.radiclejetbrainsplugin.config.RadicleProjectSettingsHandler;
import network.radicle.jetbrains.radiclejetbrainsplugin.services.RadicleCliService;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -74,9 +73,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}

public void openInBrowser(Project project, GitRepository repo, String fileToOpen, BrowserLauncher browserLauncher) {
var radicleSettingsHandler = new RadicleProjectSettingsHandler(project);
var nodeUrl = radicleSettingsHandler.loadSettings().getSeedNode().url
.replace("http://", "").replace("https://", "");
var cli = project.getService(RadicleCliService.class);
var nodeUrl = cli.getWebUrl();
if (Strings.isNullOrEmpty(nodeUrl)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package network.radicle.jetbrains.radiclejetbrainsplugin.config;

import network.radicle.jetbrains.radiclejetbrainsplugin.models.SeedNode;

public class RadicleProjectSettings {
private String radHome;

Check warning on line 4 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/config/RadicleProjectSettings.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `radHome` may be 'final'
private String path;

Check warning on line 5 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/config/RadicleProjectSettings.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `path` may be 'final'
private SeedNode seedNode;

public RadicleProjectSettings(String radHome, String path, SeedNode seedNode) {
public RadicleProjectSettings(String radHome, String path) {
this.radHome = radHome;
this.path = path;
this.seedNode = seedNode;
}

public String getRadHome() {
Expand All @@ -21,16 +17,11 @@ public String getPath() {
return path;
}

public SeedNode getSeedNode() {
return seedNode;
}

@Override
public String toString() {
return "RadicleProjectSettings{" +
"radHome='" + radHome + '\'' +
"path='" + path + '\'' +
"seedNode='" + seedNode + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
import com.intellij.ide.passwordSafe.PasswordSafe;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.project.Project;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.SeedNode;

public class RadicleProjectSettingsHandler {
public static final String RAD_SETTINGS_PREFIX = RadicleProjectSettingsHandler.class.getPackageName();
public static final String RAD_HOME_KEY = RAD_SETTINGS_PREFIX + ".radHome";
public static final String PATH_KEY = RAD_SETTINGS_PREFIX + ".path";
public static final String RAD_SEED_KEY = RAD_SETTINGS_PREFIX + ".radSeedKey";
public static final String DEFAULT_SEED_NODES = "http://localhost:8080";
private final Project project;

public RadicleProjectSettingsHandler(Project project) {
this.project = project;
saveDefaultSeedNodes();
}

public Project getProject() {
Expand All @@ -39,16 +35,7 @@ public String getPassword(String key) {
}

public boolean isSettingsEmpty() {
return Strings.isNullOrEmpty(getPath()) || Strings.isNullOrEmpty(getRadHome()) ||
Strings.isNullOrEmpty(getSeedNode().url);
}

private SeedNode getSeedNode() {
var seed = getApplicationProperties().getValue(RAD_SEED_KEY);
if (Strings.isNullOrEmpty(seed)) {
return new SeedNode("");
}
return new SeedNode(seed);
return Strings.isNullOrEmpty(getPath()) || Strings.isNullOrEmpty(getRadHome());
}

public void saveRadHome(String radHome) {
Expand All @@ -59,23 +46,12 @@ public void savePath(String path) {
getApplicationProperties().setValue(PATH_KEY, path);
}

public void saveSeedNode(String seedNode) {
getApplicationProperties().setValue(RAD_SEED_KEY, Strings.nullToEmpty(seedNode));
}

public void savePassphrase(String key, String passphrase) {
storeCredentials(key, passphrase);
}

private void saveDefaultSeedNodes() {
var loadedSeedNode = getSeedNode();
if (Strings.isNullOrEmpty(loadedSeedNode.url)) {
saveSeedNode(DEFAULT_SEED_NODES);
}
}

public RadicleProjectSettings loadSettings() {
return new RadicleProjectSettings(getRadHome(), getPath(), getSeedNode());
return new RadicleProjectSettings(getRadHome(), getPath());
}

private PropertiesComponent getApplicationProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ protected void init() {
super.init();
setOKActionEnabled(false);
setTitle(RadicleBundle.message("shareProject"));
var settings = radicleProjectSettingsHandler.loadSettings();
var seedNode = settings.getSeedNode();
var textFieldListener = new TextFieldListener();
nameField.getDocument().addDocumentListener(textFieldListener);
branchField.getDocument().addDocumentListener(textFieldListener);
Expand All @@ -115,7 +113,7 @@ protected void init() {
for (var vi : Visibility.values()) {
visibilitySelect.addItem(vi);
}
seedNodeSelect.addItem(seedNode.url);
//seedNodeSelect.addItem(seedNode.url);
for (var repo : repos) {
projectSelect.addItem(repo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class RadIssue {
public GitRepository repo;
public Project project;
public String projectId;
public SeedNode seedNode;

public RadIssue() {
// for json
Expand All @@ -61,7 +60,6 @@ public RadIssue(RadIssue other) {
this.repo = other.repo;
this.project = other.project;
this.projectId = other.projectId;
this.seedNode = other.seedNode;
}

public RadDiscussion findDiscussion(String commentId) {
Expand All @@ -70,7 +68,7 @@ public RadDiscussion findDiscussion(String commentId) {

@JsonIgnore
public String getDescription() {
return discussion == null || discussion.isEmpty() ? "" : discussion.get(0).body;
return discussion == null || discussion.isEmpty() ? "" : discussion.getFirst().body;
}

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
public class RadPatch {
private static final Logger logger = LoggerFactory.getLogger(RadPatch.class);

public SeedNode seedNode;
public GitRepository repo;
public Project project;
public RadProject radProject;
Expand Down Expand Up @@ -69,7 +68,6 @@ public RadPatch(
}

public RadPatch(RadPatch other) {
this.seedNode = other.seedNode;
this.repo = other.repo;
this.project = other.project;
this.radProject = other.radProject;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.util.ui.EDT;

Check warning on line 11 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/services/RadicleCliService.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.util.ui.EDT;`
import git4idea.GitVcs;
import git4idea.commands.Git;
import git4idea.repo.GitRemote;
Expand All @@ -30,7 +31,6 @@
import network.radicle.jetbrains.radiclejetbrainsplugin.models.RadIssue;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.RadPatch;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.RadProject;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.SeedNode;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -182,7 +182,6 @@ public RadPatch getPatch(GitRepository repo, String projectId, String patchId) {
patch.project = repo.getProject();
patch.repo = repo;
patch.self = self;
patch.seedNode = getSeedNode();
patch.radProject = getRadRepo(repo);
return patch;
}
Expand Down Expand Up @@ -401,12 +400,6 @@ public Map<String, String> getEmbeds(String repoId, List<String> oids) {
}
}

protected SeedNode getSeedNode() {
var sh = new RadicleProjectSettingsHandler(project);
var settings = sh.loadSettings();
return settings.getSeedNode();
}

public Project getProject() {
return project;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.google.common.base.Strings;
import com.intellij.execution.util.ExecUtil;
import com.intellij.execution.wsl.WSLDistribution;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.ui.EDT;
import jnr.ffi.LibraryLoader;
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadAction;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.Embed;
Expand Down Expand Up @@ -103,6 +105,13 @@ public String getAlias(String nid) {
if (aliases.containsKey(nid)) {
return aliases.get(nid);
}
if (EDT.isCurrentThreadEdt()) {
final var resolveNid = nid;
ApplicationManager.getApplication().executeOnPooledThread(() -> {
getAlias(resolveNid);
});
return null;
}
var jrad = checkGetJRad();
if (jrad == null) {
return null;
Expand All @@ -124,9 +133,16 @@ public Map<String, String> getAlias(List<String> nids) {
if (missing.isEmpty()) {
return result;
}
if (EDT.isCurrentThreadEdt()) {
final var resolveNids = nids;
ApplicationManager.getApplication().executeOnPooledThread(() -> {
getAlias(resolveNids);
});
return result;
}
var jrad = checkGetJRad();
if (jrad == null) {
return null;
return result;
}
try {
var json = RadicleCliService.MAPPER.writeValueAsString(Map.of("ids", missing));
Expand Down Expand Up @@ -345,9 +361,7 @@ public void load() {
var libName = System.mapLibraryName("jrad");
libFile = createTempFileFromJar(libName);
jRad = LibraryLoader.create(JRad.class)
.search(Paths.get("./jrad/target/release").toAbsolutePath().normalize().toString())
.search(Paths.get("./jrad/target/debug").toAbsolutePath().normalize().toString())
.search(libFile == null ? "." : libFile.toAbsolutePath().getParent().toString())
.search(libFile.toAbsolutePath().getParent().toString())
.failImmediately()
.load("jrad");
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadTrack;
import network.radicle.jetbrains.radiclejetbrainsplugin.commands.RadicleScriptCommandFactory;
import network.radicle.jetbrains.radiclejetbrainsplugin.config.RadicleProjectSettingsHandler;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.RadDetails;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.RadPatch;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -55,7 +54,6 @@ public class RadicleProjectService {
private static final Logger logger = Logger.getInstance(RadicleProjectService.class);
private static final int TIMEOUT = 60_000;
protected final RadicleProjectSettingsHandler projectSettingsHandler;
protected RadDetails radDetails;
protected String wslDistro;
protected Project project;

Expand All @@ -69,14 +67,6 @@ public RadicleProjectService(RadicleProjectSettingsHandler radicleProjectSetting
this.projectSettingsHandler = radicleProjectSettingsHandler;
}

public void setRadDetails(RadDetails details) {
this.radDetails = details;
}

public RadDetails getRadDetails() {
return this.radDetails;
}

public String detectRadPath() {
ProcessOutput output = radPath();
if (!RadAction.isSuccess(output)) {
Expand Down Expand Up @@ -221,11 +211,6 @@ public ProcessOutput createPatch(GitRepository repo, String title, String descri
return executeCommandFromFile("git", repo, params);
}

public ProcessOutput patchCache(GitRepository repo) {
var params = List.of("patch", "cache");
return executeCommandFromFile(repo, params);
}

public ProcessOutput clone(String urn, String directory, String radPath, String radHome) {
if (!Strings.isNullOrEmpty(radPath) && !Strings.isNullOrEmpty(radHome)) {
return executeCommand(radPath, radHome, directory, List.of("clone", urn, "--no-confirm"), null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package network.radicle.jetbrains.radiclejetbrainsplugin.toolwindow;

import com.google.common.base.Strings;
import com.intellij.collaboration.ui.codereview.list.search.ReviewListSearchValue;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
Expand Down Expand Up @@ -108,11 +107,6 @@ public void updateListPanel() {
if (searchVm != null) {
searchVm.setCountDown(countDown);
}
var settings = radicleProjectSettingsHandler.loadSettings();
var seedNode = settings.getSeedNode();
if (seedNode == null || Strings.isNullOrEmpty(seedNode.url)) {
return;
}
var gitRepoManager = GitRepositoryManager.getInstance(project);
var repos = gitRepoManager.getRepositories();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadClone;
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadSelf;
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadSync;
import network.radicle.jetbrains.radiclejetbrainsplugin.config.RadicleProjectSettingsHandler;
import network.radicle.jetbrains.radiclejetbrainsplugin.listeners.RadicleManagerListener;
import network.radicle.jetbrains.radiclejetbrainsplugin.models.RadDetails;
import org.junit.Test;
Expand Down Expand Up @@ -204,10 +203,7 @@ public void radOpenInBrowser() throws InterruptedException {
ArgumentCaptor<URI> urlCaptor = ArgumentCaptor.forClass(URI.class);
verify(browserUtilMock).browse(urlCaptor.capture());
String url = String.valueOf(urlCaptor.getValue());
var settings = new RadicleProjectSettingsHandler(getProject());
var seedNodeUrl = settings.loadSettings().getSeedNode().url;
var host = seedNodeUrl.replace("http://", "").replace("https://", "");
var expected = RadicleOpenInBrowserAction.UI_URL + host + "/rad:123/tree" + fileToOpen;
var expected = RadicleOpenInBrowserAction.UI_URL + radCli.getWebUrl() + "/rad:123/tree" + fileToOpen;
assertThat(url).isEqualTo(expected);
}

Expand Down
Loading

0 comments on commit a5e3f04

Please sign in to comment.