IntelliJ Plug-in for Pants Build
Java Python Shell Scala HTML
Clone or download
wisechengyi Adopt unique module path to avoid module creation lockup (#359)
### Problem

The stacktrace shows my earlier suspicion before on module create lock between projects: if target X is in both project A and B, then both projects will create module X whose module definition file isn't unique at this point, causing a dead lock.

```
	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl$$Lambda$1909/170935657.run(Unknown Source)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1010)
	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl.applyProjectSdk(PantsProjectComponentImpl.java:216)
	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl.access$1300(PantsProjectComponentImpl.java:48)
	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl$1$1.moduleAdded(PantsProjectComponentImpl.java:158)
	at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:117)
	at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:426)
	at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:387)
	at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:376)
	at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:364)
	at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:357)
	at com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:43)
	at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:208)
	at com.sun.proxy.$Proxy135.moduleAdded(Unknown Source)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.fireModuleAdded(ModuleManagerImpl.java:386)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.lambda$commitModel$5(ModuleManagerImpl.java:1012)
	at com.intellij.openapi.module.impl.ModuleManagerImpl$$Lambda$1905/1492672951.run(Unknown Source)
	at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.makeRootsChange(ProjectRootManagerImpl.java:330)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.commitModel(ModuleManagerImpl.java:966)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.access$1500(ModuleManagerImpl.java:64)
	at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.commitWithRunnable(ModuleManagerImpl.java:874)
	at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.access$1200(ModuleManagerImpl.java:640)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.commitModelWithRunnable(ModuleManagerImpl.java:631)
	at com.intellij.openapi.roots.impl.ModifiableModelCommitter.multiCommit(ModifiableModelCommitter.java:50)
	at com.intellij.openapi.roots.impl.ModifiableModelCommitter.multiCommit(ModifiableModelCommitter.java:39)
```

### Solution

Assign a unique parent directory for modules at each import. The implementation uses a hash from the timestamp.

### Result

Verified multiple imports of the same target do not cause a lockup.
Latest commit 448182b Jun 30, 2018
Permalink
Failed to load latest commit information.
.idea Upgrade to 2018.1 compatibility (#335) Mar 13, 2018
3rdparty/intellij Upgrade to 2018.1 compatibility (#335) Mar 13, 2018
common Restrict BUILD file change popup to Pants project (#358) Jun 28, 2018
images Remove IntelliJ compiler option, isolate strategy checking, and expor… Feb 11, 2016
jps-plugin Add usage extension points (#238) Jan 4, 2017
resources Prepare 1.9.2 release (#356) Jun 28, 2018
scripts Bump IJ to 2018.1.5 and plugins (#357) Jun 25, 2018
src Adopt unique module path to avoid module creation lockup (#359) Jun 30, 2018
testData Exclude jars imported into the project for IntelliJ Junit/Scala runner ( Feb 28, 2018
testFramework Make scala plugin an optional dependency (#352) Jun 6, 2018
tests Make scala plugin an optional dependency (#352) Jun 6, 2018
.gitignore Add test to import whole repo; include buildroot name into project na… Sep 13, 2016
.travis.yml Bump IJ to 2018.1.5 and plugins (#357) Jun 25, 2018
BUILD.tools Update to 2017.3 (#319) Dec 6, 2017
CONTRIBUTING.md Set up more of the module classpath in the project (#345) Apr 25, 2018
CONTRIBUTORS.md updating contributors file Jun 30, 2016
LICENSE add LICENSE, CONTRIBUTORS.md to root, add license to java,scala,prope… Oct 31, 2014
README.md Readme/Contributing guideline update (#222) Dec 2, 2016
intellij-pants-plugin.iml Tweak module dependency scope (#346) Apr 26, 2018
pants Upgrade test target to be 2017.1.2 (#292) May 8, 2017
pants-beta-updates.xml Disabled beta build Oct 8, 2015
pants.ini Update to 2017.3 (#319) Dec 6, 2017

README.md

intellij-pants-plugin

  • The intellij-pants-plugin supports importing, compiling and testing Pants projects.
  • Scala and Java projects are fully supported. Python projects are supported on a best effort basis.
  • As of 12/2/2016, latest version of the plugin supports IntelliJ IDEA 2016.3 and up for both Community Edition and Ultimate Edition.
  • As of 12/2/2016, the plugin supports 1.1.x, 1.2.x, and current master of Pants.

User documentation

Installing the Plugin

Please use Plugins tab: (Main menu: Settings | Plugins) to install the plugin. Find Pants Support plugin. Install and Restart IntelliJ.

Minimum set of plugins is required to enable Pants Support features

  • Gradle
  • Groovy
  • Java Bytecode Decompiler
  • JUnit
  • Python Community Edition (if you are importing python projects)
  • Scala

Importing an entire project directory

  • Use Main menu: File -> New -> Project From Existing Sources
  • Select project directory Import project from directory
  • Choose "Pants" on the next screen
  • Make sure the check box "All Targets in the directory" is enabled and proceed with the wizard

Importing targets from a BUILD File

  • Use Main menu: File -> New -> Project From Existing Sources
  • Select a Build File from within the project Import project from BUILD file
  • Check the targets you want to Import and proceed with the wizard. (Please wait for the targets to show up) Choose Targets

Importing targets from a script

  • Use Main menu: File -> New -> Project From Existing Sources
  • Select an executable that will use export goal to produce a desirable project structure. See an integration test as an example.

Importing multiple BUILD files/directories

  • Import the first directory/BUILD file
  • Use File -> New -> Module From Existing Sources to import next directories/BUILD files

Once you import the project using above steps, you will see the "Project View" with multiple modules configured.

Invoking Pants within IntelliJ

The plugin can invoke any Pants commands via Pants Tasks.

  • To configure a Pants Task simply create a new Pants Run Configuration Creating of a new Pants Run Configuration
  • Choose a target to run a task for Choosing a target Configured target
  • Fill the rest of options for the task. Note there is a task for each Pants goal. Configure Pants Task
  • Run the Task Configured Pants Task
  • To debug a task simply press Debug button next to Run button.
  • Note: you can create a task for any goal Bundle Task

Predefined Pants Tasks for test targets

The plugin can also generate test configurations.

For example if a test class is opened then with a right click it's easy to create a task to run and debug Run Configuration Producer Preconfigured Run Configuration

With a right click in Project View it's easy to create a test task to run all tests for a target Run Configuration Producer

Compilation

  • Pants' compile goal (Default) The plugin will use pants compile <list of targets> to compile your project once a Make or PantsCompile command is invoked. Compilation via compile goal

Compilation options can be configured in Preferences -> Build, Execution, Deployment -> Compiler -> Pants: Compilation Options

Plugin Features.

  • Project File Tree View. The plugin configures modules per pants build target. Due to multiple modules, the default "Project View" is not very user friendly. The Plugin provides a custom view "Project Files Tree View". This view adheres to your repository file hierarchy. You can switch to this view as follows: Project Files Tree View "Project Files Tree View" also provides an ability to filter out files that weren't loaded during project generation. Show Only Loaded Files
  • Project Regeneration using IntelliJ Action. If you add a dependency to your project, you can re-resolve project using IntelliJ Action in background. Use Main Menu: Help -> Find Action or Short hand Cmd+Shift+A and select Action "Refresh all External Projects" Remember to check "Include non-menu actions" Refresh Project
  • Running tests within IntelliJ You can right click on tests and run tests.

Report Bugs

If you encounter a bug, please check for existing issues or file a new one on the project page.