From d81f82b23ff05de09375c9a8b78a84e61d4b376b Mon Sep 17 00:00:00 2001 From: Tomasz Pasternak Date: Tue, 10 Dec 2019 17:28:29 +0100 Subject: [PATCH] Save incremental import depth setting Before this commit, IntelliJ plugin was asking for incremental import depth each time, even when doing refresh. The depth value was not saved anywhere. Now, the incremental import depth parameter is saved alongside other settings, and may be configured in the same place as others. --- .../pants/model/PantsExecutionOptions.java | 3 +- .../twitter/intellij/pants/PantsManager.java | 2 +- .../impl/PantsProjectComponentImpl.java | 6 +-- .../service/PantsCompileOptionsExecutor.java | 20 +++++-- .../pants/service/project/PantsResolver.java | 2 +- .../project/PantsSystemProjectResolver.java | 9 ++-- .../resolver/PantsCreateModulesExtension.java | 26 +-------- .../settings/PantsExecutionSettings.java | 10 ++-- .../pants/settings/PantsProjectSettings.java | 28 +++++++--- .../settings/PantsProjectSettingsControl.java | 47 ++++++++++++++-- .../pants/settings/PantsSettings.java | 13 +++-- .../PantsIntegrationTestCase.java | 5 ++ .../pants/integration/NoopCompileTest.java | 54 +++++++++---------- .../pants/integration/OSSPantsImportTest.java | 48 +++++++++++++++++ .../OSSProjectInfoResolveTest.java | 6 ++- .../PantsCompileOptionsExecutorTest.java | 3 +- .../integration/ScalaWelcomeProjectData.java | 12 +++++ 17 files changed, 203 insertions(+), 91 deletions(-) create mode 100644 tests/com/twitter/intellij/pants/integration/OSSPantsImportTest.java create mode 100644 tests/com/twitter/intellij/pants/integration/ScalaWelcomeProjectData.java diff --git a/common/com/twitter/intellij/pants/model/PantsExecutionOptions.java b/common/com/twitter/intellij/pants/model/PantsExecutionOptions.java index 2b478d2ed..e61f5518a 100644 --- a/common/com/twitter/intellij/pants/model/PantsExecutionOptions.java +++ b/common/com/twitter/intellij/pants/model/PantsExecutionOptions.java @@ -6,12 +6,13 @@ import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Optional; public interface PantsExecutionOptions { @NotNull List getSelectedTargetSpecs(); - boolean isEnableIncrementalImport(); + Optional incrementalImportDepth(); boolean isImportSourceDepsAsJars(); } diff --git a/src/com/twitter/intellij/pants/PantsManager.java b/src/com/twitter/intellij/pants/PantsManager.java index 309ff8c44..a9ab0c905 100644 --- a/src/com/twitter/intellij/pants/PantsManager.java +++ b/src/com/twitter/intellij/pants/PantsManager.java @@ -133,7 +133,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 ); } diff --git a/src/com/twitter/intellij/pants/components/impl/PantsProjectComponentImpl.java b/src/com/twitter/intellij/pants/components/impl/PantsProjectComponentImpl.java index b63951f14..ab75ad9f5 100644 --- a/src/com/twitter/intellij/pants/components/impl/PantsProjectComponentImpl.java +++ b/src/com/twitter/intellij/pants/components/impl/PantsProjectComponentImpl.java @@ -135,8 +135,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 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")); @@ -150,7 +150,7 @@ private void convertToPantsProject() { final boolean useIntellijCompiler = false; final PantsProjectSettings pantsProjectSettings = new PantsProjectSettings( - targetSpecs, new ArrayList<>(), projectPath, loadLibsAndSources, enableIncrementalImport, useIdeaProjectJdk, enableExportDepAsJar, useIntellijCompiler); + targetSpecs, new ArrayList<>(), projectPath, loadLibsAndSources, enableIncrementalImport.isPresent(), enableIncrementalImport.orElse(0), useIdeaProjectJdk, enableExportDepAsJar, useIntellijCompiler); /** * Following procedures in {@link com.intellij.openapi.externalSystem.util.ExternalSystemUtil#refreshProjects}: diff --git a/src/com/twitter/intellij/pants/service/PantsCompileOptionsExecutor.java b/src/com/twitter/intellij/pants/service/PantsCompileOptionsExecutor.java index 1c74cd883..9b9f5776c 100644 --- a/src/com/twitter/intellij/pants/service/PantsCompileOptionsExecutor.java +++ b/src/com/twitter/intellij/pants/service/PantsCompileOptionsExecutor.java @@ -44,6 +44,7 @@ public class PantsCompileOptionsExecutor { private final PantsCompileOptions myOptions; private final File myBuildRoot; private final boolean myResolveSourcesAndDocsForJars; + private final Optional 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,7 +74,8 @@ public static PantsCompileOptionsExecutor createMock() { return new PantsCompileOptionsExecutor( new File("/"), new MyPantsCompileOptions("", PantsExecutionSettings.createDefault()), - true + true, + Optional.of(1) ) { }; } @@ -80,17 +83,24 @@ public static PantsCompileOptionsExecutor createMock() { private PantsCompileOptionsExecutor( @NotNull File buildRoot, @NotNull PantsCompileOptions compilerOptions, - boolean resolveSourcesAndDocsForJars + boolean resolveSourcesAndDocsForJars, + @NotNull Optional incrementalImportDepth ) { myBuildRoot = buildRoot; myOptions = compilerOptions; myResolveSourcesAndDocsForJars = resolveSourcesAndDocsForJars; + myIncrementalImportDepth = incrementalImportDepth; } public String getProjectRelativePath() { return PantsUtil.getRelativeProjectPath(getBuildRoot(), getProjectPath()).get(); } + @NotNull + public Optional getIncrementalImportDepth() { + return myIncrementalImportDepth; + } + @NotNull public File getBuildRoot() { return myBuildRoot; @@ -280,8 +290,8 @@ public List getSelectedTargetSpecs() { return myExecutionOptions.getSelectedTargetSpecs(); } - public boolean isEnableIncrementalImport() { - return myExecutionOptions.isEnableIncrementalImport(); + public Optional incrementalImportDepth() { + return myExecutionOptions.incrementalImportDepth(); } @Override diff --git a/src/com/twitter/intellij/pants/service/project/PantsResolver.java b/src/com/twitter/intellij/pants/service/project/PantsResolver.java index 8fd4dc801..42d87aaac 100644 --- a/src/com/twitter/intellij/pants/service/project/PantsResolver.java +++ b/src/com/twitter/intellij/pants/service/project/PantsResolver.java @@ -115,7 +115,7 @@ public void addInfoTo(@NotNull DataNode projectInfoDataNode) { private Optional constructBuildGraph(@NotNull DataNode projectInfoDataNode) { Optional buildGraph; - if (myExecutor.getOptions().isEnableIncrementalImport()) { + if (myExecutor.getOptions().incrementalImportDepth().isPresent()) { Optional pantsExecutable = PantsUtil.findPantsExecutable(projectInfoDataNode.getData().getLinkedExternalProjectPath()); SimpleExportResult result = SimpleExportResult.getExportResult(pantsExecutable.get().getPath()); if (PantsUtil.versionCompare(result.getVersion(), "1.0.9") < 0) { diff --git a/src/com/twitter/intellij/pants/service/project/PantsSystemProjectResolver.java b/src/com/twitter/intellij/pants/service/project/PantsSystemProjectResolver.java index 9b5fbf4f1..1168a68e5 100644 --- a/src/com/twitter/intellij/pants/service/project/PantsSystemProjectResolver.java +++ b/src/com/twitter/intellij/pants/service/project/PantsSystemProjectResolver.java @@ -82,8 +82,11 @@ public DataNode resolveProjectInfo( final PantsCompileOptionsExecutor executor = PantsCompileOptionsExecutor.create(projectPath, settings); task2executor.put(id, executor); + + Optional incrementalImportDepth = settings.incrementalImportDepth(); + final DataNode projectDataNode = - resolveProjectInfoImpl(id, executor, listener, isPreviewMode, settings.isEnableIncrementalImport()); + resolveProjectInfoImpl(id, executor, listener, isPreviewMode, settings.incrementalImportDepth()); // We do not want to repeatedly force switching to 'Project Files Tree' view if // user decides to use import dep as jar and wants to use the more focused 'Project' view. if (!settings.isImportSourceDepsAsJars()) { @@ -149,7 +152,7 @@ private DataNode resolveProjectInfoImpl( @NotNull final PantsCompileOptionsExecutor executor, @NotNull ExternalSystemTaskNotificationListener listener, boolean isPreviewMode, - boolean isEnableIncrementalImport + Optional isEnableIncrementalImport ) throws ExternalSystemException, IllegalArgumentException, IllegalStateException { // todo(fkorotkov): add ability to choose a name for a project final ProjectData projectData = new ProjectData( @@ -175,7 +178,7 @@ private DataNode resolveProjectInfoImpl( .ifPresent(sdk -> projectDataNode.createChild(PantsConstants.SDK_KEY, sdk)); if (!isPreviewMode) { - PantsExternalMetricsListenerManager.getInstance().logIsIncrementalImport(isEnableIncrementalImport); + PantsExternalMetricsListenerManager.getInstance().logIsIncrementalImport(isEnableIncrementalImport.isPresent()); resolveUsingPantsGoal(id, executor, listener, projectDataNode); if (!containsContentRoot(projectDataNode, executor.getProjectDir())) { diff --git a/src/com/twitter/intellij/pants/service/project/resolver/PantsCreateModulesExtension.java b/src/com/twitter/intellij/pants/service/project/resolver/PantsCreateModulesExtension.java index 05066716d..0fd186368 100644 --- a/src/com/twitter/intellij/pants/service/project/resolver/PantsCreateModulesExtension.java +++ b/src/com/twitter/intellij/pants/service/project/resolver/PantsCreateModulesExtension.java @@ -52,7 +52,7 @@ public void resolve( Set 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 createModuleData( @NotNull DataNode projectInfoDataNode, diff --git a/src/com/twitter/intellij/pants/settings/PantsExecutionSettings.java b/src/com/twitter/intellij/pants/settings/PantsExecutionSettings.java index dbe1d6b60..ebc67b4d7 100644 --- a/src/com/twitter/intellij/pants/settings/PantsExecutionSettings.java +++ b/src/com/twitter/intellij/pants/settings/PantsExecutionSettings.java @@ -10,19 +10,21 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; public class PantsExecutionSettings extends ExternalSystemExecutionSettings implements PantsExecutionOptions { private final boolean myLibsWithSourcesAndDocs; private final boolean myUseIdeaProjectJdk; - private final boolean myEnableIncrementalImport; private final boolean myUseIntellijCompiler; + private final Optional myEnableIncrementalImport; + private final boolean myImportSourceDepsAsJars; private final List myTargetSpecs; private static final List 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 DEFAULT_ENABLE_INCREMENTAL_IMPORT = Optional.empty(); private static final boolean DEFAULT_IMPORT_SOURCE_DEPS_AS_JARS = false; private static final boolean DEFAULT_USE_INTELLIJ_COMPILER = false; @@ -48,7 +50,7 @@ public PantsExecutionSettings( boolean libsWithSourcesAndDocs, boolean useIdeaProjectJdk, boolean importSourceDepsAsJars, - boolean enableIncrementalImport, + Optional enableIncrementalImport, boolean useIntellijCompiler ) { myTargetSpecs = targetSpecs; @@ -72,7 +74,7 @@ public boolean isUseIdeaProjectJdk() { return myUseIdeaProjectJdk; } - public boolean isEnableIncrementalImport() { + public Optional incrementalImportDepth() { return myEnableIncrementalImport; } diff --git a/src/com/twitter/intellij/pants/settings/PantsProjectSettings.java b/src/com/twitter/intellij/pants/settings/PantsProjectSettings.java index ca1311611..550da233a 100644 --- a/src/com/twitter/intellij/pants/settings/PantsProjectSettings.java +++ b/src/com/twitter/intellij/pants/settings/PantsProjectSettings.java @@ -10,16 +10,28 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; public class PantsProjectSettings extends ExternalProjectSettings implements PantsCompileOptions { private List mySelectedTargetSpecs = new ArrayList<>(); private List 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 @@ -36,6 +48,7 @@ public PantsProjectSettings( String externalProjectPath, boolean libsWithSources, boolean isEnableIncrementalImport, + int incrementalImportDepth, boolean isUseIdeaProjectJdk, boolean isImportSourceDepsAsJars, boolean isUseIntellijCompiler @@ -44,7 +57,8 @@ public PantsProjectSettings( mySelectedTargetSpecs = selectedTargetSpecs; myAllAvailableTargetSpecs = allAvailableTargetSpecs; this.libsWithSources = libsWithSources; - enableIncrementalImport = isEnableIncrementalImport; + incrementalImportEnabled = isEnableIncrementalImport; + this.incrementalImportDepth = incrementalImportDepth; useIdeaProjectJdk = isUseIdeaProjectJdk; importSourceDepsAsJars = isImportSourceDepsAsJars; useIdeaProjectJdk = isUseIntellijCompiler; @@ -65,8 +79,9 @@ public boolean equals(Object obj) { PantsProjectSettings other = (PantsProjectSettings) obj; return 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); @@ -87,7 +102,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; @@ -117,8 +133,8 @@ public void setSelectedTargetSpecs(List selectedTargetSpecs) { } @Override - public boolean isEnableIncrementalImport() { - return this.enableIncrementalImport; + public Optional incrementalImportDepth() { + return incrementalImportEnabled ? Optional.of(incrementalImportDepth) : Optional.empty(); } @Override diff --git a/src/com/twitter/intellij/pants/settings/PantsProjectSettingsControl.java b/src/com/twitter/intellij/pants/settings/PantsProjectSettingsControl.java index b8568cf2a..d07057b3a 100644 --- a/src/com/twitter/intellij/pants/settings/PantsProjectSettingsControl.java +++ b/src/com/twitter/intellij/pants/settings/PantsProjectSettingsControl.java @@ -33,6 +33,12 @@ import javax.swing.JCheckBox; import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; + +import java.awt.FlowLayout; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -51,15 +57,31 @@ private enum ProjectPathFileType { isBUILDFile } + private JSpinner newImportDepthSpinner(){ + JSpinner spinner = new JSpinner(); + spinner.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1)); + return spinner; + } + + private JBCheckBox newEnableIcrementalImportCheckbox(){ + JBCheckBox checkbox = new JBCheckBox(PantsBundle.message("pants.settings.text.with.incremental.import")); + checkbox.addActionListener(evt -> { + myImportDepthSpinner.setValue(((JBCheckBox) evt.getSource()).isSelected() ? mySettings.incrementalImportDepth : 0); + myImportDepthSpinner.setEnabled(((JBCheckBox) evt.getSource()).isSelected()); + }); + return checkbox; + } + @VisibleForTesting protected CheckBoxList myTargetSpecsBox = new CheckBoxList<>(); private JBCheckBox myLibsWithSourcesCheckBox = new JBCheckBox(PantsBundle.message("pants.settings.text.with.sources.and.docs")); - private JBCheckBox myEnableIncrementalImportCheckBox = new JBCheckBox(PantsBundle.message("pants.settings.text.with.incremental.import")); + private JSpinner myImportDepthSpinner = newImportDepthSpinner(); + private JBCheckBox myEnableIncrementalImportCheckBox = newEnableIcrementalImportCheckbox(); private JBCheckBox myUseIdeaProjectJdkCheckBox = new JBCheckBox(PantsBundle.message("pants.settings.text.with.jdk.enforcement")); private JBCheckBox myImportSourceDepsAsJarsCheckBox = new JBCheckBox(PantsBundle.message("pants.settings.text.import.deps.as.jars")); private JBCheckBox myUseIntellijCompilerCheckBox = new JBCheckBox(PantsBundle.message("pants.settings.text.use.intellij.compiler")); - + private JPanel myImportDepthPanel = importDepthPanel(myImportDepthSpinner); @VisibleForTesting protected Set errors = new HashSet<>(); @@ -73,11 +95,22 @@ public PantsProjectSettingsControl(@NotNull PantsProjectSettings settings) { mySettings = settings; } + private static JPanel importDepthPanel(JSpinner importDepthSpinner) { + JPanel importDepthPanel = new JPanel(); + importDepthPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT); + importDepthPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); + importDepthPanel.add(new JLabel("Import depth: ")); + importDepthPanel.add(importDepthSpinner); + return importDepthPanel; + + } + @Override protected void fillExtraControls(@NotNull PaintAwarePanel content, int indentLevel) { myLibsWithSourcesCheckBox.setSelected(mySettings.libsWithSources); - myEnableIncrementalImportCheckBox.setSelected(mySettings.enableIncrementalImport); + myEnableIncrementalImportCheckBox.setSelected(mySettings.incrementalImportEnabled); + myImportDepthSpinner.setValue(mySettings.incrementalImportDepth); myUseIdeaProjectJdkCheckBox.setSelected(mySettings.useIdeaProjectJdk); myImportSourceDepsAsJarsCheckBox.setSelected(mySettings.importSourceDepsAsJars); myUseIntellijCompilerCheckBox.setSelected(mySettings.useIntellijCompiler); @@ -91,9 +124,12 @@ public void run() { myTargetSpecsBox.setItems( mySettings.getAllAvailableTargetSpecs(), x->x); mySettings.getSelectedTargetSpecs().forEach(spec -> myTargetSpecsBox.setItemSelected(spec, true)); + + List boxes = ContainerUtil.newArrayList( myLibsWithSourcesCheckBox, myEnableIncrementalImportCheckBox, + myImportDepthPanel, myUseIdeaProjectJdkCheckBox, myImportSourceDepsAsJarsCheckBox, myUseIntellijCompilerCheckBox, @@ -131,6 +167,7 @@ protected boolean isExtraSettingModified() { getInitialSettings().getExternalProjectPath(), myLibsWithSourcesCheckBox.isSelected(), myEnableIncrementalImportCheckBox.isSelected(), + (Integer)(myImportDepthSpinner.getValue()), myUseIdeaProjectJdkCheckBox.isSelected(), myImportSourceDepsAsJarsCheckBox.isSelected(), myUseIntellijCompilerCheckBox.isSelected() @@ -155,7 +192,6 @@ public void onProjectPathChanged(@NotNull final String projectPath) { return; } lastPath = projectPath; - myTargetSpecsBox.clear(); errors.clear(); @@ -229,7 +265,8 @@ protected void applyExtraSettings(@NotNull PantsProjectSettings settings) { settings.setSelectedTargetSpecs(getSelectedTargetSpecsFromBoxes()); settings.setAllAvailableTargetSpecs(getAllTargetSpecsFromBoxes()); settings.libsWithSources = myLibsWithSourcesCheckBox.isSelected(); - settings.enableIncrementalImport = myEnableIncrementalImportCheckBox.isSelected(); + settings.incrementalImportEnabled = myEnableIncrementalImportCheckBox.isSelected(); + settings.incrementalImportDepth = (Integer) (myImportDepthSpinner.getValue()); settings.useIdeaProjectJdk = myUseIdeaProjectJdkCheckBox.isSelected(); settings.importSourceDepsAsJars = myImportSourceDepsAsJarsCheckBox.isSelected(); settings.useIntellijCompiler = myUseIntellijCompilerCheckBox.isSelected(); diff --git a/src/com/twitter/intellij/pants/settings/PantsSettings.java b/src/com/twitter/intellij/pants/settings/PantsSettings.java index 1a92e7607..df1f8e7d8 100644 --- a/src/com/twitter/intellij/pants/settings/PantsSettings.java +++ b/src/com/twitter/intellij/pants/settings/PantsSettings.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Objects; +import java.util.Optional; import java.util.Set; @State( @@ -73,15 +74,19 @@ public boolean isUseIdeaProjectJdk() { } public boolean isEnableIncrementalImport() { - return getLinkedProjectsSettings().stream().anyMatch(PantsProjectSettings::isEnableIncrementalImport); + return getLinkedProjectsSettings().stream().anyMatch(x -> x.incrementalImportDepth().isPresent()); } + public boolean isUseIntellijCompiler() { return getLinkedProjectsSettings().stream().anyMatch(s -> s.useIntellijCompiler); } - - public void setEnableIncrementalImport(boolean enableIncrementalImport) { - getLinkedProjectsSettings().forEach(s -> s.enableIncrementalImport = enableIncrementalImport); + public void setEnableIncrementalImport(Optional incrementalImportDepth) { + getLinkedProjectsSettings().forEach(s -> + { + s.incrementalImportEnabled = incrementalImportDepth.isPresent(); + s.incrementalImportDepth = incrementalImportDepth.orElse(0); + }); } public int getResolverVersion() { diff --git a/testFramework/com/twitter/intellij/pants/testFramework/PantsIntegrationTestCase.java b/testFramework/com/twitter/intellij/pants/testFramework/PantsIntegrationTestCase.java index 335645eb9..11a60c695 100644 --- a/testFramework/com/twitter/intellij/pants/testFramework/PantsIntegrationTestCase.java +++ b/testFramework/com/twitter/intellij/pants/testFramework/PantsIntegrationTestCase.java @@ -98,6 +98,11 @@ public abstract class PantsIntegrationTestCase extends ExternalSystemImportingTestCase { private final boolean readOnly; + + public void setProjectSettings(PantsProjectSettings projectSettings) { + myProjectSettings = projectSettings; + } + private PantsProjectSettings myProjectSettings; private String myRelativeProjectPath = null; private CompilerTester myCompilerTester; diff --git a/tests/com/twitter/intellij/pants/integration/NoopCompileTest.java b/tests/com/twitter/intellij/pants/integration/NoopCompileTest.java index f39e1720d..f5a87a72e 100644 --- a/tests/com/twitter/intellij/pants/integration/NoopCompileTest.java +++ b/tests/com/twitter/intellij/pants/integration/NoopCompileTest.java @@ -14,29 +14,22 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; +import java.util.Optional; public class NoopCompileTest extends OSSPantsIntegrationTest { - private static class ScalaProjectData { - static final String path = "examples/tests/scala/org/pantsbuild/example/hello/welcome"; - static final String HELLO_SRC_JAVA_MODULE = "examples_src_java_org_pantsbuild_example_hello_greet_greet"; - static final String HELLO_SRC_SCALA_MODULE = "examples_src_scala_org_pantsbuild_example_hello_welcome_welcome"; - static final String HELLO_TEST_MODULE = "examples_tests_scala_org_pantsbuild_example_hello_welcome_welcome"; - static final String HELLO_RESOURCES_MODULE = "examples_src_resources_org_pantsbuild_example_hello_hello"; - } - @Override public void setUp() throws Exception { super.setUp(); } private void importScalaHello() { - doImport(ScalaProjectData.path); + doImport(ScalaWelcomeProjectData.path); assertFirstSourcePartyModules( - ScalaProjectData.HELLO_RESOURCES_MODULE, - ScalaProjectData.HELLO_SRC_JAVA_MODULE, - ScalaProjectData.HELLO_SRC_SCALA_MODULE, - ScalaProjectData.HELLO_TEST_MODULE + ScalaWelcomeProjectData.HELLO_RESOURCES_MODULE, + ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE, + ScalaWelcomeProjectData.HELLO_SRC_SCALA_MODULE, + ScalaWelcomeProjectData.HELLO_TEST_MODULE ); } @@ -140,13 +133,13 @@ public void testAddThenDeleteFileInProjectShouldOp() throws Throwable { public void testCompileDifferentModule() throws Throwable { importScalaHello(); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); - assertPantsCompileNoop(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileNoop(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); // Compile a different module, should not noop. - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_SCALA_MODULE)); - assertPantsCompileNoop(pantsCompileModule(ScalaProjectData.HELLO_SRC_SCALA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_SCALA_MODULE)); + assertPantsCompileNoop(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_SCALA_MODULE)); // Switch back should compile again. - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); } public void testCompileProjectSettings() throws Throwable { @@ -154,11 +147,11 @@ public void testCompileProjectSettings() throws Throwable { PantsSettings settings = PantsSettings.getInstance(myProject); settings.setUseIdeaProjectJdk(false); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); - assertPantsCompileNoop(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileNoop(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); settings.setUseIdeaProjectJdk(true); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); } public void testCompileIncrementalImports() throws Throwable { @@ -166,27 +159,28 @@ public void testCompileIncrementalImports() throws Throwable { // If a project uses incremental imports, then noop should never happen. PantsSettings settings = PantsSettings.getInstance(myProject); - settings.setEnableIncrementalImport(true); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + settings.setEnableIncrementalImport(Optional.of(1)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); } + public void testShouldCompileAfterCleanAll() throws Throwable { importScalaHello(); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); - assertPantsCompileNoop(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileNoop(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); cmd("./pants", "clean-all"); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); } public void testShouldCompileAfterOutOfBandPantsCLI() throws Throwable { importScalaHello(); - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); - assertPantsCompileNoop(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileNoop(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); cmd("./pants", "export-classpath", "--manifest-jar-only", "examples/tests/java/org/pantsbuild/example/hello/greet"); // Recompile because the sha of manifest.jar will change. - assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaProjectData.HELLO_SRC_JAVA_MODULE)); + assertPantsCompileExecutesAndSucceeds(pantsCompileModule(ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE)); } } diff --git a/tests/com/twitter/intellij/pants/integration/OSSPantsImportTest.java b/tests/com/twitter/intellij/pants/integration/OSSPantsImportTest.java new file mode 100644 index 000000000..e615859d4 --- /dev/null +++ b/tests/com/twitter/intellij/pants/integration/OSSPantsImportTest.java @@ -0,0 +1,48 @@ +// Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). +// Licensed under the Apache License, Version 2.0 (see LICENSE). + +package com.twitter.intellij.pants.integration; + +import com.twitter.intellij.pants.settings.PantsProjectSettings; +import com.twitter.intellij.pants.testFramework.OSSPantsIntegrationTest; + +public class OSSPantsImportTest extends OSSPantsIntegrationTest { + public void testIncrementalImportsDeep() { + PantsProjectSettings settings = new PantsProjectSettings(); + settings.incrementalImportDepth = 100; + settings.incrementalImportEnabled = true; + setProjectSettings(settings); + doImport(ScalaWelcomeProjectData.path); + assertFirstSourcePartyModules( + ScalaWelcomeProjectData.HELLO_RESOURCES_MODULE, + ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE, + ScalaWelcomeProjectData.HELLO_SRC_SCALA_MODULE, + ScalaWelcomeProjectData.HELLO_TEST_MODULE + ); + } + + public void testNoIncrementalImportsDeep() { + PantsProjectSettings settings = new PantsProjectSettings(); + settings.incrementalImportEnabled = false; + setProjectSettings(settings); + doImport(ScalaWelcomeProjectData.path); + assertFirstSourcePartyModules( + ScalaWelcomeProjectData.HELLO_RESOURCES_MODULE, + ScalaWelcomeProjectData.HELLO_SRC_JAVA_MODULE, + ScalaWelcomeProjectData.HELLO_SRC_SCALA_MODULE, + ScalaWelcomeProjectData.HELLO_TEST_MODULE + ); + } + + public void testIncrementalImportsShallow() { + PantsProjectSettings settings = new PantsProjectSettings(); + settings.incrementalImportDepth = 1; + settings.incrementalImportEnabled = true; + setProjectSettings(settings); + doImport(ScalaWelcomeProjectData.path); + assertFirstSourcePartyModules( + ScalaWelcomeProjectData.HELLO_SRC_SCALA_MODULE, + ScalaWelcomeProjectData.HELLO_TEST_MODULE + ); + } +} diff --git a/tests/com/twitter/intellij/pants/integration/OSSProjectInfoResolveTest.java b/tests/com/twitter/intellij/pants/integration/OSSProjectInfoResolveTest.java index 9509d4049..d6e23613e 100644 --- a/tests/com/twitter/intellij/pants/integration/OSSProjectInfoResolveTest.java +++ b/tests/com/twitter/intellij/pants/integration/OSSProjectInfoResolveTest.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; public class OSSProjectInfoResolveTest extends OSSPantsIntegrationTest { private static Consumer STRING_CONSUMER = new Consumer() { @@ -36,14 +37,15 @@ private ProjectInfo resolveProjectInfo(@NotNull String targetSpec) { final boolean libsWithSourcesAndDocs = true; final boolean useIdeaProjectJdk = false; final boolean isExportDepAsJar = false; - final boolean isEnableIncrementalImport = false; + final Optional incrementalImportDepth = Optional.empty(); final boolean isUseIntelliJCompiler = false; + PantsExecutionSettings settings = new PantsExecutionSettings( Collections.singletonList(targetSpec), libsWithSourcesAndDocs, useIdeaProjectJdk, isExportDepAsJar, - isEnableIncrementalImport, + incrementalImportDepth, isUseIntelliJCompiler ); diff --git a/tests/com/twitter/intellij/pants/integration/PantsCompileOptionsExecutorTest.java b/tests/com/twitter/intellij/pants/integration/PantsCompileOptionsExecutorTest.java index 051a9b8d6..9d088d4c3 100644 --- a/tests/com/twitter/intellij/pants/integration/PantsCompileOptionsExecutorTest.java +++ b/tests/com/twitter/intellij/pants/integration/PantsCompileOptionsExecutorTest.java @@ -9,6 +9,7 @@ import java.io.File; import java.util.Collections; +import java.util.Optional; public class PantsCompileOptionsExecutorTest extends OSSPantsIntegrationTest { @@ -21,7 +22,7 @@ public void testProjectName() throws Throwable { false, // include libs and sources. does not matter here false, // use idea project jdk. does not matter here. false, // pants qexport dep as jar - false, // incremental imports. does not matter here. + Optional.empty(), // incremental imports. does not matter here. false // use intellij compiler ); diff --git a/tests/com/twitter/intellij/pants/integration/ScalaWelcomeProjectData.java b/tests/com/twitter/intellij/pants/integration/ScalaWelcomeProjectData.java new file mode 100644 index 000000000..3ff609aa1 --- /dev/null +++ b/tests/com/twitter/intellij/pants/integration/ScalaWelcomeProjectData.java @@ -0,0 +1,12 @@ +// Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). +// Licensed under the Apache License, Version 2.0 (see LICENSE). + +package com.twitter.intellij.pants.integration; + +public class ScalaWelcomeProjectData { + static final String path = "examples/tests/scala/org/pantsbuild/example/hello/welcome"; + static final String HELLO_SRC_JAVA_MODULE = "examples_src_java_org_pantsbuild_example_hello_greet_greet"; + static final String HELLO_SRC_SCALA_MODULE = "examples_src_scala_org_pantsbuild_example_hello_welcome_welcome"; + static final String HELLO_TEST_MODULE = "examples_tests_scala_org_pantsbuild_example_hello_welcome_welcome"; + static final String HELLO_RESOURCES_MODULE = "examples_src_resources_org_pantsbuild_example_hello_hello"; +} \ No newline at end of file