Skip to content

Commit

Permalink
catkin_tools profiles are now loaded from .catkin_tools (#56)
Browse files Browse the repository at this point in the history
also, package autocompletion in allow/deny lists no longer include rosdep keys, which are precompiled anyways

Signed-off-by: Noam Dori <TheNODO55@gmail.com>
  • Loading branch information
Noam-Dori committed Jun 8, 2021
1 parent 7983aed commit 5c98059
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 9 deletions.
102 changes: 102 additions & 0 deletions src/main/java/ros/integrate/buildtool/ROSProfileLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package ros.integrate.buildtool;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.VirtualFileSystem;
import org.jetbrains.annotations.NotNull;
import org.yaml.snakeyaml.Yaml;
import ros.integrate.settings.ROSSettings;
import ros.integrate.ui.PathListUtil;

import java.io.IOException;
import java.util.*;

public class ROSProfileLoader {
private static final Logger LOG = Logger.getInstance("#ros.integrate.buildtool.ROSProfileLoader");
private final ROSSettings settings;
private static final VirtualFileSystem FILE_SYSTEM = VirtualFileManager.getInstance()
.getFileSystem(LocalFileSystem.PROTOCOL);

public ROSProfileLoader(Project project) {
this.settings = ROSSettings.getInstance(project);
}

public List<ROSProfile> load(@NotNull ROSBuildTool buildTool) {
if (settings.getWorkspacePath().isEmpty()) {
return Collections.emptyList();
}
switch (buildTool) {
case COLCON:
return loadColcon();
case CATKIN_MAKE:
return loadCatkinMake();
case CATKIN_TOOLS:
return loadCatkinTools();
}
return Collections.emptyList();
}

@NotNull
private List<ROSProfile> loadColcon() {
return Collections.emptyList();
}

@NotNull
private List<ROSProfile> loadCatkinMake() {
return Collections.emptyList();
}


@NotNull
private List<ROSProfile> loadCatkinTools() {
VirtualFile profilesDir = FILE_SYSTEM.findFileByPath(settings.getWorkspacePath() + "/.catkin_tools/profiles");
if (profilesDir == null) {
return Collections.emptyList();
}
List<ROSProfile> ret = new ArrayList<>();
for (VirtualFile profileDir : profilesDir.getChildren()) {
Yaml config = new Yaml();
VirtualFile configFile = Optional.ofNullable(profileDir.findChild("config.yaml"))
.orElseGet(() -> profileDir.findChild("build.yaml"));
if (configFile == null) {
continue;
}
try {
Map<String, Object> data = config.load(configFile.getInputStream());
ROSProfile profile = new ROSProfile();
profile.setGuiBuildtool(ROSBuildTool.CATKIN_TOOLS);
profile.setGuiName(profileDir.getName());
profile.setInstall((Boolean) data.getOrDefault("install", true));
profile.setIsolation(true);
profile.setMakeArgs(serialize(data, "make_args", ' '));
profile.setCmakeArgs(serialize(data, "cmake_args", ' '));
profile.setBuildtoolArgs(serialize(data, "catkin_make_args", ' '));
profile.setDenyList(serialize(data, "blacklist", ','));
profile.setAllowList(serialize(data, "whitelist", ','));
profile.setBuildDir(extendPath(data, "build_space", "build"));
profile.setDevelDir(extendPath(data, "devel_space", "devel"));
profile.setSourceDir(extendPath(data, "source_space", "src"));
profile.setInstallDir(extendPath(data, "install_space", "install"));
profile.save();
ret.add(profile);
} catch (IOException e) {
LOG.error(String.format("Read of file [%s] failed with exception", configFile.getPath()), e);
}
}
return ret;
}

@SuppressWarnings("unchecked")
private String serialize(@NotNull Map<String, Object> data, String lookupKey, char delimiter) {
return PathListUtil.serializePathList((List<String>)
data.getOrDefault(lookupKey, Collections.emptyList()), delimiter);
}

private String extendPath(@NotNull Map<String, Object> data, String lookupKey, String def) {
String raw = (String) data.getOrDefault(lookupKey, def);
return raw.startsWith("/") ? raw : settings.getWorkspacePath() + "/" + raw;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

import javax.swing.*;
import java.awt.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.*;

/**
* the user interface that allows the user to add,get, or modify the project's ROS buildtool configurations,
Expand Down Expand Up @@ -131,6 +128,8 @@ public JComponent createComponent() {
formToSelect.getPanel().setVisible(true);
});

profileList.setValues(new ArrayList<>(data.loadProfiles()));

return ret;
}

Expand Down
27 changes: 26 additions & 1 deletion src/main/java/ros/integrate/buildtool/ROSProfiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

/**
Expand All @@ -16,8 +17,9 @@
* and the IDE will hold information missing from those files in a separate, persistent database.
* @author Noam Dori
*/
// TODO: 5/4/2021 implement away the mock stuff
public class ROSProfiles {
private final Project project;

/**
* a shortcut to get the ROS profiles database
* @param project the project from which to get the profiles DB
Expand All @@ -27,6 +29,10 @@ public static ROSProfiles getInstance(@NotNull Project project) {
return project.getService(ROSProfiles.class);
}

private ROSProfiles(Project project) {
this.project = project;
}

/**
* The database. It is important to note that the identifiers are not persistent in any capacity.
* Reloading this database will load new identifiers, so no point in storing them.
Expand Down Expand Up @@ -66,4 +72,23 @@ public Integer requestId() {
profiles.put(nextId, new ROSProfile());
return nextId++;
}

/**
* loads all profiles onto this database
* @return the key list of all profiles loaded in.
* @apiNote this is a heavy operation as it does a lot of reading. Use sparingly.
* this also wipes any existing data.
*/
public Set<Integer> loadProfiles() {
profiles.clear();
nextId = 0;
ROSProfileLoader profileLoader = new ROSProfileLoader(project);
for (ROSBuildTool buildTool: ROSBuildTool.values()) {
profileLoader.load(buildTool).forEach(profile -> {
profiles.put(nextId, profile);
nextId++;
});
}
return profiles.keySet();
}
}
3 changes: 0 additions & 3 deletions src/main/java/ros/integrate/buildtool/ui/ROSProfileForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.jetbrains.annotations.Nullable;
import ros.integrate.buildtool.ROSBuildTool;
import ros.integrate.buildtool.ROSProfile;
import ros.integrate.pkg.ROSDepKeyCache;
import ros.integrate.pkg.ROSPackageManager;
import ros.integrate.ui.HistoryKey;
import ros.integrate.ui.PathListTextField;
Expand Down Expand Up @@ -69,8 +68,6 @@ public ROSProfileForm(@NotNull Project project) {

project.getService(ROSPackageManager.class).getAllPackages()
.forEach(pkg -> packages.put(pkg.getName(), pkg.getIcon(0)));
project.getService(ROSDepKeyCache.class).getAllKeys()
.forEach(pkg -> packages.put(pkg.getName(), pkg.getIcon(0)));
TextFieldWithAutoCompletionListProvider<String> provider =
new TextFieldWithAutoCompletionListProvider<String>(packages.keySet()){
@NotNull
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ros/integrate/ui/PathListUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static String serializePathList(@NotNull List<String> pathList) {
* @param delimiter the delimiter to use between the paths
* @return a string containing all paths
*/
static String serializePathList(@NotNull List<String> pathList, char delimiter) {
public static String serializePathList(@NotNull List<String> pathList, char delimiter) {
return pathList.stream().filter(path -> !path.isEmpty()).collect(Collectors.joining(String.valueOf(delimiter)));
}
}

0 comments on commit 5c98059

Please sign in to comment.