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

Revert "Save incremental import depth setting (#479)" #503

Merged
merged 1 commit into from
Mar 12, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;

public interface PantsExecutionOptions {

@NotNull
List<String> getSelectedTargetSpecs();

Optional<Integer> incrementalImportDepth();
boolean isEnableIncrementalImport();
boolean isImportSourceDepsAsJars();
}
2 changes: 1 addition & 1 deletion src/com/twitter/intellij/pants/PantsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private PantsExecutionSettings getExecutionsSettingsFromPath(@NotNull Project id
pantsProjectSettings.libsWithSources,
pantsProjectSettings.useIdeaProjectJdk,
pantsProjectSettings.importSourceDepsAsJars,
pantsProjectSettings.incrementalImportEnabled ? Optional.of(pantsProjectSettings.incrementalImportDepth) : Optional.empty(),
pantsProjectSettings.enableIncrementalImport,
pantsProjectSettings.useIntellijCompiler
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ private void convertToPantsProject() {
}
// TODO: This is actually an integer value: if we replaced the incremental import
// checkbox with an integer optional, we could propagate this value through.
final Optional<Integer> enableIncrementalImport =
Optional.ofNullable(PropertiesComponent.getInstance(myProject).getValue("incremental_import")).map(Integer::parseInt);
final boolean enableIncrementalImport =
PropertiesComponent.getInstance(myProject).getValue("incremental_import") != null;

final boolean enableExportDepAsJar =
Boolean.parseBoolean(Optional.ofNullable(PropertiesComponent.getInstance(myProject).getValue("dep_as_jar")).orElse("false"));
Expand All @@ -154,7 +154,7 @@ private void convertToPantsProject() {
final boolean useIntellijCompiler = false;
final PantsProjectSettings pantsProjectSettings =
new PantsProjectSettings(
targetSpecs, targetSpecs, projectPath, loadLibsAndSources, enableIncrementalImport.isPresent(), enableIncrementalImport.orElse(0), useIdeaProjectJdk, enableExportDepAsJar, useIntellijCompiler);
targetSpecs, targetSpecs, projectPath, loadLibsAndSources, enableIncrementalImport, useIdeaProjectJdk, enableExportDepAsJar, useIntellijCompiler);

/**
* Following procedures in {@link com.intellij.openapi.externalSystem.util.ExternalSystemUtil#refreshProjects}:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class PantsCompileOptionsExecutor {
private final PantsCompileOptions myOptions;
private final File myBuildRoot;
private final boolean myResolveSourcesAndDocsForJars;
private final Optional<Integer> myIncrementalImportDepth;

@NotNull
public static PantsCompileOptionsExecutor create(
Expand All @@ -63,8 +62,7 @@ public static PantsCompileOptionsExecutor create(
return new PantsCompileOptionsExecutor(
buildRoot.get(),
options,
executionOptions.isLibsWithSourcesAndDocs(),
executionOptions.incrementalImportDepth()
executionOptions.isLibsWithSourcesAndDocs()
);
}

Expand All @@ -74,33 +72,25 @@ public static PantsCompileOptionsExecutor createMock() {
return new PantsCompileOptionsExecutor(
new File("/"),
new MyPantsCompileOptions("", PantsExecutionSettings.createDefault()),
true,
Optional.of(1)
true
) {
};
}

private PantsCompileOptionsExecutor(
@NotNull File buildRoot,
@NotNull PantsCompileOptions compilerOptions,
boolean resolveSourcesAndDocsForJars,
@NotNull Optional<Integer> incrementalImportDepth
boolean resolveSourcesAndDocsForJars
) {
myBuildRoot = buildRoot;
myOptions = compilerOptions;
myResolveSourcesAndDocsForJars = resolveSourcesAndDocsForJars;
myIncrementalImportDepth = incrementalImportDepth;
}

public String getProjectRelativePath() {
return PantsUtil.getRelativeProjectPath(getBuildRoot(), getProjectPath()).get();
}

@NotNull
public Optional<Integer> getIncrementalImportDepth() {
return myIncrementalImportDepth;
}

@NotNull
public File getBuildRoot() {
return myBuildRoot;
Expand Down Expand Up @@ -295,8 +285,8 @@ public List<String> getSelectedTargetSpecs() {
return myExecutionOptions.getSelectedTargetSpecs();
}

public Optional<Integer> incrementalImportDepth() {
return myExecutionOptions.incrementalImportDepth();
public boolean isEnableIncrementalImport() {
return myExecutionOptions.isEnableIncrementalImport();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void addInfoTo(@NotNull DataNode<ProjectData> projectInfoDataNode) {

private Optional<BuildGraph> constructBuildGraph(@NotNull DataNode<ProjectData> projectInfoDataNode) {
Optional<BuildGraph> buildGraph;
if (myExecutor.getOptions().incrementalImportDepth().isPresent()) {
if (myExecutor.getOptions().isEnableIncrementalImport()) {
Optional<VirtualFile> pantsExecutable = PantsUtil.findPantsExecutable(projectInfoDataNode.getData().getLinkedExternalProjectPath());
SimpleExportResult result = SimpleExportResult.getExportResult(pantsExecutable.get().getPath());
if (PantsUtil.versionCompare(result.getVersion(), "1.0.9") < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static void clearPantsModules(@NotNull Project project, String projectPa
{
Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
if (Objects.equals(module.getOptionValue(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH), Paths.get(projectPath).normalize().toString())) {
if (Objects.equals(module.getOptionValue(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH), projectPath)) {
ModuleManager.getInstance(project).disposeModule(module);
}
}
Expand All @@ -103,9 +103,6 @@ public DataNode<ProjectData> resolveProjectInfo(
checkForDifferentPantsExecutables(id, projectPath);
final PantsCompileOptionsExecutor executor = PantsCompileOptionsExecutor.create(projectPath, settings);
task2executor.put(id, executor);

Optional<Integer> incrementalImportDepth = settings.incrementalImportDepth();

final DataNode<ProjectData> projectDataNode =
resolveProjectInfoImpl(id, executor, listener, settings, isPreviewMode);
// We do not want to repeatedly force switching to 'Project Files Tree' view if
Expand Down Expand Up @@ -204,7 +201,7 @@ private DataNode<ProjectData> resolveProjectInfoImpl(
.ifPresent(sdk -> projectDataNode.createChild(PantsConstants.SDK_KEY, sdk));

if (!isPreviewMode) {
PantsExternalMetricsListenerManager.getInstance().logIsIncrementalImport(settings.incrementalImportDepth().isPresent());
PantsExternalMetricsListenerManager.getInstance().logIsIncrementalImport(settings.isEnableIncrementalImport());
resolveUsingPantsGoal(id, executor, listener, projectDataNode);

if (!containsContentRoot(projectDataNode, executor.getProjectDir())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.jetbrains.annotations.Nullable;
import com.google.gson.Gson;

import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;

Expand Down Expand Up @@ -50,7 +49,7 @@ public void importData(
module.setOption(PantsConstants.PANTS_LIBRARY_EXCLUDES_KEY, PantsUtil.dehydrateTargetAddresses(metadata.getLibraryExcludes()));
module.setOption(PantsConstants.PANTS_TARGET_ADDRESSES_KEY, PantsUtil.dehydrateTargetAddresses(metadata.getTargetAddresses()));
module.setOption(PantsConstants.PANTS_TARGET_ADDRESS_INFOS_KEY, gson.toJson(metadata.getTargetAddressInfoSet()));
module.setOption(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH, Paths.get(projectData.getLinkedExternalProjectPath()).normalize().toString());
module.setOption(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH, projectData.getLinkedExternalProjectPath());
ExternalSystemModulePropertyManager.getInstance(module).setExternalModuleType(PantsConstants.PANTS_TARGET_MODULE_TYPE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void resolve(
Set<TargetInfo> targetInfoWithinLevel = null;
if (buildGraph.isPresent()) {
final int maxDepth = buildGraph.get().getMaxDepth();
depthToInclude = executor.getIncrementalImportDepth().orElse(null);
getDepthToImportFromUser(maxDepth);
if (depthToInclude == null) {
throw new PantsException("Task cancelled");
}
Expand Down Expand Up @@ -90,6 +90,30 @@ public void resolve(
}
}

private void getDepthToImportFromUser(final int maxDepth) {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
String result = Messages.showInputDialog(
String.format(
"Enter the depth of transitive dependencies to import min: 0, max: %s.\n" +
"0: root level.\n" +
"1: up to direct dependency.\n" +
"%s: entire build graph", maxDepth, maxDepth
),
"Incremental Import",
PantsIcons.Icon, //icon
String.valueOf(maxDepth), //initial number
null //validator per keystroke, not necessary in this case.
);
depthToInclude = result == null ? null : Integer.valueOf(result);
if (depthToInclude == null || depthToInclude < 0 || depthToInclude > maxDepth) {
throw new PantsException("Invalid input");
}
}
}, ModalityState.NON_MODAL);
}

@NotNull
private DataNode<ModuleData> createModuleData(
@NotNull DataNode<ProjectData> projectInfoDataNode,
Expand Down
22 changes: 10 additions & 12 deletions src/com/twitter/intellij/pants/settings/PantsExecutionSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.twitter.intellij.pants.settings;

import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.twitter.intellij.pants.model.PantsExecutionOptions;
import org.jetbrains.annotations.NotNull;

Expand All @@ -17,17 +16,16 @@ public class PantsExecutionSettings extends ExternalSystemExecutionSettings impl
private final String myName;
private final boolean myLibsWithSourcesAndDocs;
private final boolean myUseIdeaProjectJdk;
private final boolean myEnableIncrementalImport;
private final boolean myUseIntellijCompiler;
private final Optional<Integer> myIncrementalImportDepth;

private final boolean myImportSourceDepsAsJars;
private final List<String> myTargetSpecs;

private static final String DEFAULT_PROJECT_NAME = null;
private static final List<String> DEFAULT_TARGET_SPECS = Collections.emptyList();
private static final boolean DEFAULT_WITH_SOURCES_AND_DOCS = true;
private static final boolean DEFAULT_USE_IDEA_PROJECT_SDK = false;
private static final Optional<Integer> DEFAULT_INCREMENTAL_IMPORT = Optional.empty();
private static final boolean DEFAULT_ENABLE_INCREMENTAL_IMPORT = false;
private static final boolean DEFAULT_IMPORT_SOURCE_DEPS_AS_JARS = false;
private static final boolean DEFAULT_USE_INTELLIJ_COMPILER = false;

Expand All @@ -38,7 +36,7 @@ public static PantsExecutionSettings createDefault() {
DEFAULT_WITH_SOURCES_AND_DOCS,
DEFAULT_USE_IDEA_PROJECT_SDK,
DEFAULT_IMPORT_SOURCE_DEPS_AS_JARS,
DEFAULT_INCREMENTAL_IMPORT,
DEFAULT_ENABLE_INCREMENTAL_IMPORT,
DEFAULT_USE_INTELLIJ_COMPILER
);
}
Expand All @@ -49,15 +47,15 @@ public PantsExecutionSettings(
boolean libsWithSourcesAndDocs,
boolean useIdeaProjectJdk,
boolean importSourceDepsAsJars,
Optional<Integer> enableIncrementalImport,
boolean enableIncrementalImport,
boolean useIntellijCompiler
){
myName = name;
myTargetSpecs = targetSpecs;
myLibsWithSourcesAndDocs = libsWithSourcesAndDocs;
myUseIdeaProjectJdk = useIdeaProjectJdk;
myImportSourceDepsAsJars = importSourceDepsAsJars;
myIncrementalImportDepth = enableIncrementalImport;
myEnableIncrementalImport = enableIncrementalImport;
myUseIntellijCompiler = useIntellijCompiler;
}

Expand All @@ -72,7 +70,7 @@ public PantsExecutionSettings(
boolean libsWithSourcesAndDocs,
boolean useIdeaProjectJdk,
boolean importSourceDepsAsJars,
Optional<Integer> enableIncrementalImport,
boolean enableIncrementalImport,
boolean useIntellijCompiler
) {
this(DEFAULT_PROJECT_NAME, targetSpecs, libsWithSourcesAndDocs, useIdeaProjectJdk, importSourceDepsAsJars, enableIncrementalImport, useIntellijCompiler);
Expand All @@ -96,8 +94,8 @@ public boolean isUseIdeaProjectJdk() {
return myUseIdeaProjectJdk;
}

public Optional<Integer> incrementalImportDepth() {
return myIncrementalImportDepth;
public boolean isEnableIncrementalImport() {
return myEnableIncrementalImport;
}

@Override
Expand All @@ -113,7 +111,7 @@ public boolean equals(Object o) {

PantsExecutionSettings settings = (PantsExecutionSettings) o;
return Objects.equals(myUseIdeaProjectJdk, settings.myUseIdeaProjectJdk) &&
Objects.equals(myIncrementalImportDepth, settings.myIncrementalImportDepth) &&
Objects.equals(myEnableIncrementalImport, settings.myEnableIncrementalImport) &&
Objects.equals(myUseIntellijCompiler, settings.myUseIntellijCompiler) &&
Objects.equals(myLibsWithSourcesAndDocs, settings.myLibsWithSourcesAndDocs) &&
Objects.equals(myTargetSpecs, settings.myTargetSpecs);
Expand All @@ -125,7 +123,7 @@ public int hashCode() {
myTargetSpecs,
myLibsWithSourcesAndDocs,
myUseIdeaProjectJdk,
myIncrementalImportDepth,
myEnableIncrementalImport,
myUseIntellijCompiler
);
}
Expand Down
28 changes: 6 additions & 22 deletions src/com/twitter/intellij/pants/settings/PantsProjectSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,17 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class PantsProjectSettings extends ExternalProjectSettings implements PantsCompileOptions {
private String projectName;
private List<String> mySelectedTargetSpecs = new ArrayList<>();
private List<String> myAllAvailableTargetSpecs = new ArrayList<>();
public boolean libsWithSources;
public boolean incrementalImportEnabled;

public boolean isIncrementalImportEnabled() {
return incrementalImportEnabled;
}

public int getIncrementalImportDepth() {
return incrementalImportDepth;
}

public int incrementalImportDepth;
public boolean enableIncrementalImport;
public boolean useIdeaProjectJdk;
public boolean importSourceDepsAsJars;
public boolean useIntellijCompiler;


/**
* @param allAvailableTargetSpecs targets explicted listed from `pants idea-plugin` goal.
* @param selectedTargetSpecs targets selected by the user to import
Expand All @@ -50,7 +38,6 @@ public PantsProjectSettings(
String externalProjectPath,
boolean libsWithSources,
boolean isEnableIncrementalImport,
int incrementalImportDepth,
boolean isUseIdeaProjectJdk,
boolean isImportSourceDepsAsJars,
boolean isUseIntellijCompiler
Expand All @@ -59,8 +46,7 @@ public PantsProjectSettings(
mySelectedTargetSpecs = selectedTargetSpecs;
myAllAvailableTargetSpecs = allAvailableTargetSpecs;
this.libsWithSources = libsWithSources;
incrementalImportEnabled = isEnableIncrementalImport;
this.incrementalImportDepth = incrementalImportDepth;
enableIncrementalImport = isEnableIncrementalImport;
useIdeaProjectJdk = isUseIdeaProjectJdk;
importSourceDepsAsJars = isImportSourceDepsAsJars;
useIdeaProjectJdk = isUseIntellijCompiler;
Expand All @@ -82,9 +68,8 @@ public boolean equals(Object obj) {
return Objects.equals(projectName, other.projectName)
&& Objects.equals(libsWithSources, other.libsWithSources)
&& Objects.equals(myAllAvailableTargetSpecs, other.myAllAvailableTargetSpecs)
&& Objects.equals(enableIncrementalImport, other.enableIncrementalImport)
&& Objects.equals(mySelectedTargetSpecs, other.mySelectedTargetSpecs)
&& Objects.equals(incrementalImportEnabled, other.incrementalImportEnabled)
&& Objects.equals(incrementalImportDepth, other.incrementalImportDepth)
&& Objects.equals(useIdeaProjectJdk, other.useIdeaProjectJdk)
&& Objects.equals(importSourceDepsAsJars, other.importSourceDepsAsJars)
&& Objects.equals(useIntellijCompiler, other.useIntellijCompiler);
Expand All @@ -106,8 +91,7 @@ protected void copyTo(@NotNull ExternalProjectSettings receiver) {
((PantsProjectSettings) receiver).setSelectedTargetSpecs(getSelectedTargetSpecs());
((PantsProjectSettings) receiver).setAllAvailableTargetSpecs(getAllAvailableTargetSpecs());
((PantsProjectSettings) receiver).libsWithSources = libsWithSources;
((PantsProjectSettings) receiver).incrementalImportDepth = incrementalImportDepth;
((PantsProjectSettings) receiver).incrementalImportEnabled = incrementalImportEnabled;
((PantsProjectSettings) receiver).enableIncrementalImport = enableIncrementalImport;
((PantsProjectSettings) receiver).useIdeaProjectJdk = useIdeaProjectJdk;
((PantsProjectSettings) receiver).importSourceDepsAsJars = importSourceDepsAsJars;
((PantsProjectSettings) receiver).useIntellijCompiler = useIntellijCompiler;
Expand Down Expand Up @@ -137,8 +121,8 @@ public void setSelectedTargetSpecs(List<String> selectedTargetSpecs) {
}

@Override
public Optional<Integer> incrementalImportDepth() {
return incrementalImportEnabled ? Optional.of(incrementalImportDepth) : Optional.empty();
public boolean isEnableIncrementalImport() {
return this.enableIncrementalImport;
}

@Override
Expand Down
Loading