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

Save incremental import depth setting #479

Merged
merged 2 commits into from
Mar 10, 2020
Merged
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
@@ -6,12 +6,13 @@
import org.jetbrains.annotations.NotNull;

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

public interface PantsExecutionOptions {

@NotNull
List<String> getSelectedTargetSpecs();

boolean isEnableIncrementalImport();
Optional<Integer> incrementalImportDepth();
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
@@ -134,7 +134,7 @@ private PantsExecutionSettings getExecutionsSettingsFromPath(@NotNull Project id
pantsProjectSettings.libsWithSources,
pantsProjectSettings.useIdeaProjectJdk,
pantsProjectSettings.importSourceDepsAsJars,
pantsProjectSettings.enableIncrementalImport,
pantsProjectSettings.incrementalImportEnabled ? Optional.of(pantsProjectSettings.incrementalImportDepth) : Optional.empty(),
pantsProjectSettings.useIntellijCompiler
);
}
Original file line number Diff line number Diff line change
@@ -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 boolean enableIncrementalImport =
PropertiesComponent.getInstance(myProject).getValue("incremental_import") != null;
final Optional<Integer> enableIncrementalImport =
Optional.ofNullable(PropertiesComponent.getInstance(myProject).getValue("incremental_import")).map(Integer::parseInt);

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

/**
* Following procedures in {@link com.intellij.openapi.externalSystem.util.ExternalSystemUtil#refreshProjects}:
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ 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(
@@ -62,7 +63,8 @@ public static PantsCompileOptionsExecutor create(
return new PantsCompileOptionsExecutor(
buildRoot.get(),
options,
executionOptions.isLibsWithSourcesAndDocs()
executionOptions.isLibsWithSourcesAndDocs(),
executionOptions.incrementalImportDepth()
);
}

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

private PantsCompileOptionsExecutor(
@NotNull File buildRoot,
@NotNull PantsCompileOptions compilerOptions,
boolean resolveSourcesAndDocsForJars
boolean resolveSourcesAndDocsForJars,
@NotNull Optional<Integer> incrementalImportDepth
) {
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;
@@ -285,8 +295,8 @@ public List<String> getSelectedTargetSpecs() {
return myExecutionOptions.getSelectedTargetSpecs();
}

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

@Override
Original file line number Diff line number Diff line change
@@ -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().isEnableIncrementalImport()) {
if (myExecutor.getOptions().incrementalImportDepth().isPresent()) {
Optional<VirtualFile> pantsExecutable = PantsUtil.findPantsExecutable(projectInfoDataNode.getData().getLinkedExternalProjectPath());
SimpleExportResult result = SimpleExportResult.getExportResult(pantsExecutable.get().getPath());
if (PantsUtil.versionCompare(result.getVersion(), "1.0.9") < 0) {
Original file line number Diff line number Diff line change
@@ -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), projectPath)) {
if (Objects.equals(module.getOptionValue(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH), Paths.get(projectPath).normalize().toString())) {
ModuleManager.getInstance(project).disposeModule(module);
}
}
@@ -103,6 +103,9 @@ 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
@@ -201,7 +204,7 @@ private DataNode<ProjectData> resolveProjectInfoImpl(
.ifPresent(sdk -> projectDataNode.createChild(PantsConstants.SDK_KEY, sdk));

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

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

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

@@ -49,7 +50,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, projectData.getLinkedExternalProjectPath());
module.setOption(PantsConstants.PANTS_OPTION_LINKED_PROJECT_PATH, Paths.get(projectData.getLinkedExternalProjectPath()).normalize().toString());
ExternalSystemModulePropertyManager.getInstance(module).setExternalModuleType(PantsConstants.PANTS_TARGET_MODULE_TYPE);
}
}
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public void resolve(
Set<TargetInfo> targetInfoWithinLevel = null;
if (buildGraph.isPresent()) {
final int maxDepth = buildGraph.get().getMaxDepth();
getDepthToImportFromUser(maxDepth);
depthToInclude = executor.getIncrementalImportDepth().orElse(null);
if (depthToInclude == null) {
throw new PantsException("Task cancelled");
}
@@ -90,30 +90,6 @@ 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,
22 changes: 12 additions & 10 deletions src/com/twitter/intellij/pants/settings/PantsExecutionSettings.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
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;

@@ -16,16 +17,17 @@ 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 boolean DEFAULT_ENABLE_INCREMENTAL_IMPORT = false;
private static final Optional<Integer> DEFAULT_INCREMENTAL_IMPORT = Optional.empty();
private static final boolean DEFAULT_IMPORT_SOURCE_DEPS_AS_JARS = false;
private static final boolean DEFAULT_USE_INTELLIJ_COMPILER = false;

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

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

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

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

PantsExecutionSettings settings = (PantsExecutionSettings) o;
return Objects.equals(myUseIdeaProjectJdk, settings.myUseIdeaProjectJdk) &&
Objects.equals(myEnableIncrementalImport, settings.myEnableIncrementalImport) &&
Objects.equals(myIncrementalImportDepth, settings.myIncrementalImportDepth) &&
Objects.equals(myUseIntellijCompiler, settings.myUseIntellijCompiler) &&
Objects.equals(myLibsWithSourcesAndDocs, settings.myLibsWithSourcesAndDocs) &&
Objects.equals(myTargetSpecs, settings.myTargetSpecs);
@@ -123,7 +125,7 @@ public int hashCode() {
myTargetSpecs,
myLibsWithSourcesAndDocs,
myUseIdeaProjectJdk,
myEnableIncrementalImport,
myIncrementalImportDepth,
myUseIntellijCompiler
);
}
28 changes: 22 additions & 6 deletions src/com/twitter/intellij/pants/settings/PantsProjectSettings.java
Original file line number Diff line number Diff line change
@@ -11,17 +11,29 @@
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 enableIncrementalImport;
public boolean incrementalImportEnabled;

public boolean isIncrementalImportEnabled() {
return incrementalImportEnabled;
}

public int getIncrementalImportDepth() {
return incrementalImportDepth;
}

public int incrementalImportDepth;
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
@@ -38,6 +50,7 @@ public PantsProjectSettings(
String externalProjectPath,
boolean libsWithSources,
boolean isEnableIncrementalImport,
int incrementalImportDepth,
boolean isUseIdeaProjectJdk,
boolean isImportSourceDepsAsJars,
boolean isUseIntellijCompiler
@@ -46,7 +59,8 @@ public PantsProjectSettings(
mySelectedTargetSpecs = selectedTargetSpecs;
myAllAvailableTargetSpecs = allAvailableTargetSpecs;
this.libsWithSources = libsWithSources;
enableIncrementalImport = isEnableIncrementalImport;
incrementalImportEnabled = isEnableIncrementalImport;
this.incrementalImportDepth = incrementalImportDepth;
useIdeaProjectJdk = isUseIdeaProjectJdk;
importSourceDepsAsJars = isImportSourceDepsAsJars;
useIdeaProjectJdk = isUseIntellijCompiler;
@@ -68,8 +82,9 @@ 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);
@@ -91,7 +106,8 @@ protected void copyTo(@NotNull ExternalProjectSettings receiver) {
((PantsProjectSettings) receiver).setSelectedTargetSpecs(getSelectedTargetSpecs());
((PantsProjectSettings) receiver).setAllAvailableTargetSpecs(getAllAvailableTargetSpecs());
((PantsProjectSettings) receiver).libsWithSources = libsWithSources;
((PantsProjectSettings) receiver).enableIncrementalImport = enableIncrementalImport;
((PantsProjectSettings) receiver).incrementalImportDepth = incrementalImportDepth;
((PantsProjectSettings) receiver).incrementalImportEnabled = incrementalImportEnabled;
((PantsProjectSettings) receiver).useIdeaProjectJdk = useIdeaProjectJdk;
((PantsProjectSettings) receiver).importSourceDepsAsJars = importSourceDepsAsJars;
((PantsProjectSettings) receiver).useIntellijCompiler = useIntellijCompiler;
@@ -121,8 +137,8 @@ public void setSelectedTargetSpecs(List<String> selectedTargetSpecs) {
}

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

@Override
Loading