Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix on GUI import #244

Merged
merged 4 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions common/com/twitter/intellij/pants/util/PantsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.intellij.execution.CommonProgramRunConfigurationParameters;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.process.CapturingProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessOutput;
Expand Down Expand Up @@ -71,7 +69,6 @@
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.impl.sdk.JpsSdkImpl;
import org.jetbrains.jps.model.library.sdk.JpsSdkReference;
import org.jetbrains.plugins.scala.testingSupport.test.AbstractTestRunConfiguration;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -172,7 +169,7 @@ public static boolean isBUILDFileName(@NotNull String name) {
*/
public static boolean isPantsProjectFile(VirtualFile file) {
if (file.isDirectory()) {
return findPantsExecutable(file) != null;
return findPantsExecutable(file).isPresent();
}
return isBUILDFileName(file.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.twitter.intellij.pants.settings;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.externalSystem.service.settings.AbstractExternalProjectSettingsControl;
import com.intellij.openapi.externalSystem.service.settings.ExternalSystemSettingsControlCustomizer;
import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil;
Expand All @@ -23,25 +22,28 @@
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;

import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

public class PantsProjectSettingsControl extends AbstractExternalProjectSettingsControl<PantsProjectSettings> {
private static final Logger LOG = Logger.getInstance(PantsProjectSettingsControl.class);
private final boolean myShowAdvancedSettings;

private CheckBoxList<String> myTargetSpecs;
private JBCheckBox myWithDependeesCheckBox;
private JBCheckBox myLibsWithSourcesCheckBox;
private JBCheckBox myEnableIncrementalImport;

private Set<String> errors = new HashSet<>();

public PantsProjectSettingsControl(@NotNull PantsProjectSettings settings, boolean showAdvancedSettings) {
super(null, settings, new ExternalSystemSettingsControlCustomizer(true, true));
myShowAdvancedSettings = showAdvancedSettings;
Expand Down Expand Up @@ -88,21 +90,25 @@ protected void resetExtraSettings(boolean isDefaultModuleCreation) {

public void onProjectPathChanged(@NotNull final String projectPath) {
myTargetSpecs.clear();
errors.clear();
final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(projectPath));
if (file == null || !PantsUtil.isPantsProjectFile(file)) {
myTargetSpecs.setEnabled(true);
LOG.warn("Bad project path: " + projectPath);
errors.add(String.format("Pants project not found given project path: %s", projectPath));
return;
}

if (file.isDirectory()) {
myTargetSpecs.setEnabled(false);
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);
Optional<String> relativeProjectPath = PantsUtil.getRelativeProjectPath(file.getPath());
if (!relativeProjectPath.isPresent()) {
errors.add(String.format("Fail to find relative path from %s to build root.", file.getPath()));
return;
}
String spec = relativeProjectPath.get() + "/::";

myTargetSpecs.setEmptyText(spec);
myTargetSpecs.addItem(spec, spec, true);

myWithDependeesCheckBox.setSelected(false);
myWithDependeesCheckBox.setEnabled(true);
Expand Down Expand Up @@ -181,6 +187,11 @@ public boolean validate(@NotNull PantsProjectSettings settings) throws Configura
if (PantsUtil.isBUILDFileName(file.getName()) && myTargetSpecs.getSelectedIndices().length == 0) {
throw new ConfigurationException(PantsBundle.message("pants.error.no.targets.are.selected"));
}
if (!errors.isEmpty()) {
String errorMessage = String.join("\n", errors);
errors.clear();
throw new ConfigurationException(errorMessage);
}
return true;
}
}
17 changes: 17 additions & 0 deletions tests/com/twitter/intellij/pants/util/PantsUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package com.twitter.intellij.pants.util;

import com.intellij.openapi.vfs.LocalFileSystem;
import com.twitter.intellij.pants.testFramework.OSSPantsIntegrationTest;

public class PantsUtilTest extends OSSPantsIntegrationTest {

public void testIsPantsProjectFile() {
// Current project path should be under a Pants repo.
assertTrue(PantsUtil.isPantsProjectFile(LocalFileSystem.getInstance().findFileByPath(getProjectPath())));
// File system root should not.
assertFalse(PantsUtil.isPantsProjectFile(LocalFileSystem.getInstance().findFileByPath("/")));
}
}