Skip to content

Commit

Permalink
Fix import on directory
Browse files Browse the repository at this point in the history
Earler https://rbcommons.com/s/twitter/r/4386 removed the usage of `com.twitter.intellij.pants.util.PantsUtil#convertToTargetSpecs` which implicitly convert an empty target spec (in the case where user chooses a directory instead of a specifc target) to `<selected folder>::`. This RB makes the directory case explicit as one of the GUI options.

Other fix:
* Target in GUI will show up correctly as `a/b/c::` instead of `Optional[a/b/c::]`

Testing Done:
https://travis-ci.org/pantsbuild/intellij-pants-plugin/builds/176898711

Reviewed at https://rbcommons.com/s/twitter/r/4389/
  • Loading branch information
wisechengyi committed Nov 18, 2016
1 parent 9c2d3e1 commit 5a89552
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions common/com/twitter/intellij/pants/util/PantsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ public static <K, V> Map<K, V> filterByValue(Map<K, V> map, Condition<V> conditi
return result;
}

public static Optional<String> getRelativeProjectPath(@NotNull File projectFile) {
final Optional<File> buildRoot = findBuildRoot(projectFile);
public static Optional<String> getRelativeProjectPath(@NotNull String projectFile) {
final Optional<File> buildRoot = findBuildRoot(new File(projectFile));
return buildRoot.flatMap(file -> getRelativeProjectPath(file, projectFile));
}

Expand Down Expand Up @@ -861,7 +861,7 @@ public static List<String> convertToTargetSpecs(String importPath, List<String>
File importPathFile = new File(importPath);
final String projectDir =
isBUILDFileName(importPathFile.getName()) ? importPathFile.getParent() : importPathFile.getPath();
final Optional<String> relativeProjectDir = getRelativeProjectPath(new File(projectDir));
final Optional<String> relativeProjectDir = getRelativeProjectPath(projectDir);
// If relativeProjectDir is null, that means the projectDir is already relative.
String relativePath = relativeProjectDir.orElse(projectDir);
if (targetNames.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.intellij.util.ui.StatusText;
import com.intellij.util.ui.UIUtil;
import com.twitter.intellij.pants.PantsBundle;
import com.twitter.intellij.pants.PantsException;
import com.twitter.intellij.pants.util.PantsUtil;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -97,7 +98,12 @@ public void onProjectPathChanged(@NotNull final String projectPath) {

if (file.isDirectory()) {
myTargetSpecs.setEnabled(false);
myTargetSpecs.setEmptyText(PantsUtil.getRelativeProjectPath(new File(file.getPath())) + "/::");
String text = PantsUtil.getRelativeProjectPath(file.getPath())
.orElseThrow(() -> new PantsException(String.format(
"Fail to find relative path from %s to build root.", file.getPath()
))) + "/::";
myTargetSpecs.setEmptyText(text);
myTargetSpecs.addItem(text, text, true);

myWithDependeesCheckBox.setSelected(false);
myWithDependeesCheckBox.setEnabled(true);
Expand Down

0 comments on commit 5a89552

Please sign in to comment.