mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
Doc cleanup
This commit is contained in:
parent
3acebe4d40
commit
b372f34863
@ -4,24 +4,31 @@ title: Project Structure
|
||||
|
||||
<!--TODO split into parts accordingly to the table of contents-->
|
||||
|
||||
This topic considers the concept of projects based on *IntelliJ Platform* and related subjects, such as _modules_, _facets_, _libraries_, _SDK_. The project structure and Java classes you can use to manage projects and modules have been considered.
|
||||
This topic considers the concept of projects based on the IntelliJ Platform and related subjects, such as _modules_, _facets_, _libraries_, and _SDK_.
|
||||
The project structure and Java classes available to manage projects and modules are discussed.
|
||||
|
||||
## Project and its components
|
||||
* bullet list
|
||||
{:toc}
|
||||
|
||||
This section briefly discusses the IDEA project structure, project components and related terms. For more information about projects and their components, refer to [Project](https://www.jetbrains.com/help/idea/about-projects.html), [Module](https://www.jetbrains.com/help/idea/configuring-projects.html#working-with-modules), [Library](https://www.jetbrains.com/help/idea/working-with-libraries.html), [Facet](https://www.jetbrains.com/help/idea/adding-support-for-frameworks-and-technologies.html#facets) in the *IntelliJ IDEA* Web Help.
|
||||
## Project and Its Components
|
||||
This section briefly discusses the IDEA project structure, project components and related terms.
|
||||
For more information about projects and their components, refer to [Project](https://www.jetbrains.com/help/idea/about-projects.html), [Module](https://www.jetbrains.com/help/idea/creating-and-managing-modules.html), [Library](https://www.jetbrains.com/help/idea/working-with-libraries.html), [Facet](https://www.jetbrains.com/help/idea/adding-support-for-frameworks-and-technologies.html#facets) in the IntelliJ IDEA Web Help.
|
||||
|
||||
### Project
|
||||
|
||||
In the *IntelliJ Platform*, a _project_ encapsulates all your source code, libraries, and build instructions into a single organizational unit. Everything you do using the *IntelliJ Platform SDK* is done within the context of a project. A project defines collections referred to as _modules_ and _libraries_. Depending on the logical and functional requirements for the project, you can create a _single-module_ or a _multi-module_ project.
|
||||
In the IntelliJ Platform, a _project_ encapsulates all of a project's source code, libraries, and build instructions into a single organizational unit.
|
||||
Everything done using the IntelliJ Platform SDK is done within the context of a project.
|
||||
A project defines collections referred to as _modules_ and _libraries_.
|
||||
Depending on the logical and functional requirements for the project, you can create a _single-module_ or a _multi-module_ project.
|
||||
|
||||
### Module
|
||||
|
||||
A _module_ is a discrete unit of functionality that can be run, tested, and debugged independently. Modules include such things as source code, build scripts, unit tests, deployment descriptors, etc. In a project, each module can use a specific SDK or inherit the SDK defined at the project level (see the [SDK](/reference_guide/project_model/sdk.md) section below in this document). A module can depend on other modules of the project.
|
||||
A _module_ is a discrete unit of functionality that can be run, tested, and debugged independently.
|
||||
Modules include such things as source code, build scripts, unit tests, deployment descriptors, etc.
|
||||
In a project, each module can use a specific SDK or inherit the SDK defined at the project level (see the [SDK](#sdk) section below in this document).
|
||||
A module can depend on other modules of the project.
|
||||
|
||||
### Library
|
||||
|
||||
A _library_ is an archive of compiled code (such as JAR files) that your modules depend on. The *IntelliJ Platform* supports three types of libraries:
|
||||
|
||||
A _library_ is an archive of compiled code (such as JAR files) on which modules depend.
|
||||
The IntelliJ Platform supports three types of libraries:
|
||||
* **Module Library**: the library classes are visible only in this module and the library information is recorded in the module's `.iml` file.
|
||||
* **Project Library**: the library classes are visible within the project and the library information is recorded in the project's `.ipr` file or in `.idea/libraries`.
|
||||
* **Global Library**: the library information is recorded in the `applicationLibraries.xml` file in the `~/.IntelliJIdea/config/options` directory. Global libraries are similar to project libraries, but are visible for different projects.
|
||||
@ -29,25 +36,26 @@ A _library_ is an archive of compiled code (such as JAR files) that your modules
|
||||
For more information about libraries, refer to [Library](https://www.jetbrains.com/help/idea/working-with-libraries.html).
|
||||
|
||||
### SDK
|
||||
|
||||
Every project uses a Software Development Kit (_SDK_). For Java projects, SDK is referred to as JDK (Java Development Kit).
|
||||
|
||||
The SDK determines which API library is used to build the project. If your project is multi-module, the project SDK is common for all modules within the project by default.
|
||||
The SDK determines which API library is used to build the project.
|
||||
If a project is multi-module, the project SDK is common for all modules within the project by default.
|
||||
Optionally, a project can configure an individual SDK for each module.
|
||||
|
||||
Optionally, you can configure an individual SDK for each module.
|
||||
|
||||
For more information about SDKs, see [Working with SDKs](https://www.jetbrains.com/help/idea/working-with-sdks.html) in the *IntelliJ IDEA* Web Help.
|
||||
For more information about SDKs, see [Working with SDKs](https://www.jetbrains.com/help/idea/working-with-sdks.html) in the IntelliJ IDEA Web Help.
|
||||
|
||||
### Facet
|
||||
A _facet_ represents a certain configuration, specific for a particular framework/technology associated with a module.
|
||||
A module can have multiple facets.
|
||||
E.g. Spring specific configuration is stored in a Spring facet.
|
||||
|
||||
A _facet_ represents a certain configuration, specific for a particular framework/technology associated with a module. A module can have multiple facets. E.g. Spring specific configuration is stored in a Spring facet.
|
||||
|
||||
Facets are documented under [Facet](https://www.jetbrains.com/help/idea/adding-support-for-frameworks-and-technologies.html#facets) and [Language and Framework Specific Guidelines](https://www.jetbrains.com/help/idea/language-and-framework-specific-guidelines.html) in the *IntelliJ IDEA* Web Help.
|
||||
Facets are documented under [Facet](https://www.jetbrains.com/help/idea/adding-support-for-frameworks-and-technologies.html#facets) and [Language and Framework Specific Guidelines](https://www.jetbrains.com/help/idea/language-and-framework-specific-guidelines.html) in the IntelliJ IDEA Web Help.
|
||||
|
||||
## Additional Information
|
||||
For more information on each of these entities, see:
|
||||
|
||||
- [Project](/reference_guide/project_model/project.md)
|
||||
- [Module](/reference_guide/project_model/module.md)
|
||||
- [SDK](/reference_guide/project_model/sdk.md)
|
||||
- [Library](/reference_guide/project_model/facet.md)
|
||||
- [Library](/reference_guide/project_model/library.md)
|
||||
- [External system integration](/reference_guide/frameworks_and_external_apis/external_system_integration.md) (for projects imported from Gradle or similar build systems)
|
||||
|
@ -2,7 +2,7 @@
|
||||
title: Library
|
||||
---
|
||||
|
||||
A library is an archive of compiled code (such as JAR files) that your modules depend on.
|
||||
A library is an archive of compiled code (such as JAR files) that modules depend on.
|
||||
|
||||
The IntelliJ Platform supports three types of libraries:
|
||||
* **Module Library**: the library classes are visible only in this module and the library information is recorded in the module `.iml` file.
|
||||
@ -14,16 +14,14 @@ For more information about libraries, refer to
|
||||
|
||||
A particular type of programmatically defined libraries is [Predefined Libraries](#predefined-libraries).
|
||||
|
||||
* bullet list
|
||||
{:toc}
|
||||
|
||||
## Accessing Libraries and Jars
|
||||
Package [libraries](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/libraries) provides functionality for working with project libraries and jars.
|
||||
|
||||
Package
|
||||
[libraries](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/libraries)
|
||||
provides functionality for working with project libraries and jars.
|
||||
|
||||
### How do I get a list of libraries a module depends on?
|
||||
|
||||
### Getting a List of Libraries a Module Depends On
|
||||
To get the list of libraries that a module depends on, use `OrderEnumerator.forEachLibrary` as follows.
|
||||
|
||||
```java
|
||||
final List<String> libraryNames = new ArrayList<String>();
|
||||
ModuleRootManager.getInstance(module).orderEntries().forEachLibrary(library -> {
|
||||
@ -35,11 +33,10 @@ Messages.showInfoMessage(StringUtil.join(libraryNames, "\n"), "Libraries in Modu
|
||||
|
||||
This sample code outputs a list of libraries that the given module depends on.
|
||||
|
||||
### How do I get a list of all libraries?
|
||||
|
||||
### Getting a List of All Libraries
|
||||
To manage the lists of application and project libraries, use [`LibraryTable`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/libraries/LibraryTable.java).
|
||||
The list of application-level library tables is accessed by calling `LibraryTablesRegistrar.getInstance().getLibraryTable()`,
|
||||
whereas the list of project-level library tables is accessed through `LibraryTablesRegistrar.getInstance().getLibraryTable(Project)`.
|
||||
whereas the list of project-level library tables is accessed through `LibraryTablesRegistrar.getInstance().getLibraryTable()`.
|
||||
Once you have a `LibraryTable`, you can get the libraries in it by calling `LibraryTable.getLibraries()`.
|
||||
|
||||
To get the list of all module libraries defined in a given module, use the following API:
|
||||
@ -47,10 +44,9 @@ To get the list of all module libraries defined in a given module, use the follo
|
||||
OrderEntryUtil.getModuleLibraries(ModuleRootManager.getInstance(module));
|
||||
```
|
||||
|
||||
### How do I get the library content?
|
||||
|
||||
[`Library`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/libraries/Library.java) provides the `getUrls()` method you can use to get a list of source roots and classes the library includes. To clarify, consider the following code snippet:
|
||||
|
||||
### Getting the Library Content
|
||||
[`Library`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/libraries/Library.java) provides the `getUrls()` method you can use to get a list of source roots and classes the library includes.
|
||||
To clarify, consider the following code snippet:
|
||||
```java
|
||||
StringBuilder roots = new StringBuilder("The " + lib.getName() + " library includes:\n");
|
||||
roots.append("Sources:\n");
|
||||
@ -64,10 +60,8 @@ for (String each : lib.getUrls(OrderRootType.CLASSES)) {
|
||||
Messages.showInfoMessage(roots.toString(), "Library Info");
|
||||
```
|
||||
|
||||
### How do I create a library?
|
||||
|
||||
To create a library, you need to perform the following steps:
|
||||
|
||||
### Creating a Library
|
||||
To create a library, perform the following steps:
|
||||
* Get a [write action](../../basics/architectural_overview/general_threading_rules.md#readwrite-lock)
|
||||
* Obtain the library table to which you want to add the library. Use one of the following, depending on the library level:
|
||||
* `LibraryTablesRegistrar.getInstance().getLibraryTable()`
|
||||
@ -77,49 +71,39 @@ To create a library, you need to perform the following steps:
|
||||
* Add contents to the library (see below)
|
||||
* For a module-level library, commit the modifiable model returned by `ModuleRootManager.getInstance(module).getModifiableModel()`.
|
||||
|
||||
For module-level libraries, you can also use simplified APIs in the [`ModuleRootModificationUtil`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ModuleRootModificationUtil.java)
|
||||
class to add a library with a single API call. You can find an example of using these APIs in the [sample plugin](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/com/intellij/tutorials/project/model/ModificationAction.java).
|
||||
|
||||
### How do I add contents to a library or modify it?
|
||||
|
||||
To add or change the roots of a library, you need to perform the following steps:
|
||||
For module-level libraries, you can also use simplified APIs in the [`ModuleRootModificationUtil`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ModuleRootModificationUtil.java) class to add a library with a single API call.
|
||||
You can find an example of using these APIs in the [project_model](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/main/java/org/intellij/sdk/project/model/ModificationAction.java) code sample.
|
||||
|
||||
### Adding Contents or Modifying a Library
|
||||
To add or change the roots of a library, you need to perform the following steps:
|
||||
* Get a [write action](../../basics/architectural_overview/general_threading_rules.md#readwrite-lock)
|
||||
* Get a **modifiable model** for the library, using `Library.getModifiableModel()`
|
||||
* Use methods such as `Library.ModifiableModel.addRoot()` to perform the necessary changes
|
||||
* Commit the model using `Library.ModifiableModel.commit()`.
|
||||
|
||||
### How do I add a library dependency to a module?
|
||||
|
||||
### Adding a Library Dependency to a Module
|
||||
Use `ModuleRootModificationUtil.addDependency(module, library)` from under a write action.
|
||||
|
||||
### Checking Belonging to a Library
|
||||
|
||||
The [`ProjectFileIndex`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java) interface implements a number of methods you can use to check whether the specified file belongs to the project library classes or library sources.
|
||||
You can use the following methods:
|
||||
|
||||
* To check if a specified virtual file is a compiled class file use
|
||||
|
||||
```java
|
||||
ProjectFileIndex.isLibraryClassFile(virtualFile)
|
||||
ProjectFileIndex.isLibraryClassFile(virtualFile)
|
||||
```
|
||||
* To check if a specified virtual file or directory belongs to library classes use
|
||||
|
||||
```java
|
||||
ProjectFileIndex.isInLibraryClasses(virtualFileorDirectory)
|
||||
ProjectFileIndex.isInLibraryClasses(virtualFileorDirectory)
|
||||
```
|
||||
* To check if the specified virtual file or directory belongs to library sources use
|
||||
|
||||
```java
|
||||
ProjectFileIndex.isInLibrarySource(virtualFileorDirectory)
|
||||
ProjectFileIndex.isInLibrarySource(virtualFileorDirectory)
|
||||
```
|
||||
|
||||
See the following [code sample](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectFileIndexSampleAction.java)
|
||||
to see how the method mentioned above can be applied.
|
||||
See the [project_model](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/main/java/org/intellij/sdk/project/model/ProjectFileIndexSampleAction.java) to see how the method mentioned above can be applied.
|
||||
|
||||
|
||||
More details on libraries can be found in this
|
||||
[code sample](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/com/intellij/tutorials/project/model/LibrariesAction.java)
|
||||
More details on libraries can be found in the [plugin_model](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/main/java/org/intellij/sdk/project/model/LibrariesAction.java) code sample.
|
||||
|
||||
## Predefined Libraries
|
||||
EP: `com.intellij.additionalLibraryRootsProvider`
|
||||
|
@ -2,50 +2,55 @@
|
||||
title: Project
|
||||
---
|
||||
|
||||
In the *IntelliJ Platform*, a project encapsulates all your source code, libraries, build instructions into a single organizational unit. Everything you do in the IDE is done within the context of a project. A project defines some collections referred to as modules and libraries. Depending on the logical and functional requirements for the project, you can create a single-module or a multi-module project.
|
||||
In the *IntelliJ Platform*, a project encapsulates all the source code, libraries, and build instructions into a single organizational unit.
|
||||
Everything done in the IDE is accomplished within the context of a project.
|
||||
A project defines some collections referred to as modules and libraries.
|
||||
Depending on the logical and functional requirements for the project, a single-module or a multi-module project is possible.
|
||||
|
||||
## Working with projects
|
||||
## Working with Projects
|
||||
|
||||
The *IntelliJ Platform* stores the project configuration data in XML files. The list of those files depends on the chosen [project](https://www.jetbrains.com/help/idea/about-projects.html) format.
|
||||
The *IntelliJ Platform* stores the project configuration data in XML files.
|
||||
The list of those files depends on the chosen [project](https://www.jetbrains.com/help/idea/about-projects.html) format.
|
||||
|
||||
For file-based format projects (legacy), the information core to the project itself (e.g. location of the component modules, compiler settings, etc.) is stored in the `%project_name%.ipr` file. The information about modules the project includes is stored in `%module_name%.iml` files. Module files are created for each module.
|
||||
For file-based format projects (legacy), the information core to the project itself (e.g., location of the component modules, compiler settings, etc.) is stored in the `%project_name%.ipr` file.
|
||||
The information about modules the project includes is stored in `%module_name%.iml` files.
|
||||
Module files are created for each module.
|
||||
|
||||
For directory-based format projects, the project and workspace settings are stored in a number of XML files under the `%project_home_directory%/.idea` directory. Each XML file is responsible for its own set of settings and can be recognized by its name: `projectCodeStyle.xml`, `encodings.xml`, `vcs.xml` etc. As for the file-based format projects, `.iml` files describe modules.
|
||||
For directory-based format projects, the project and workspace settings are stored in a number of XML files under the `%project_home_directory%/.idea` directory.
|
||||
Each XML file is responsible for its own set of settings and can be recognized by its name: `projectCodeStyle.xml`, `encodings.xml`, `vcs.xml` etc.
|
||||
As for the file-based format projects, `.iml` files describe modules.
|
||||
|
||||
Note that you don't need to access project files directly to load or save settings. See [Persisting State of Components](../../basics/persisting_state_of_components.md) for more information.
|
||||
|
||||
To work with projects and project files, you can use the following classes and interfaces:
|
||||
Note that direct access to project files isn't required to load or save settings.
|
||||
See [Persisting State of Components](../../basics/persisting_state_of_components.md) for more information.
|
||||
|
||||
To work with projects and project files, use the following classes and interfaces:
|
||||
* [`Project`](upsource:///platform/core-api/src/com/intellij/openapi/project/Project.java)
|
||||
* [`ProjectRootManager`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ProjectRootManager.java)
|
||||
* [`ProjectManager`](upsource:///platform/projectModel-api/src/com/intellij/openapi/project/ProjectManager.java)
|
||||
* [`ProjectFileIndex`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java)
|
||||
|
||||
Other classes for working with the project model are located in the [projectModel-api.openapi](upsource:///platform/projectModel-api/src/com/intellij/openapi) package. Basic API classes and interfaces for the concepts of [project](upsource:///platform/core-api/src/com/intellij/openapi/project/Project.java), [module](upsource:///platform/core-api/src/com/intellij/openapi/module/Module.java), [application](upsource:///platform/core-api/src/com/intellij/openapi/application/Application.java) and [component](upsource:///platform/core-api/src/com/intellij/openapi/components/ProjectComponent.java) are placed in the [core-api.openapi](upsource:///platform/core-api/src/com/intellij/openapi) package.
|
||||
|
||||
### How do I get a list of source roots for all modules in my project?
|
||||
Other classes for working with the project model are located in the [projectModel-api.openapi](upsource:///platform/projectModel-api/src/com/intellij/openapi) package.
|
||||
Basic API classes and interfaces for the concepts of [project](upsource:///platform/core-api/src/com/intellij/openapi/project/Project.java), [module](upsource:///platform/core-api/src/com/intellij/openapi/module/Module.java), [application](upsource:///platform/core-api/src/com/intellij/openapi/application/Application.java) and [component](upsource:///platform/core-api/src/com/intellij/openapi/components/ProjectComponent.java) are placed in the [core-api.openapi](upsource:///platform/core-api/src/com/intellij/openapi) package.
|
||||
|
||||
### Getting a List of Source Roots for All Modules in a Project
|
||||
Use the `ProjectRootManager.getContentSourceRoots()` method. To clarify this, consider the following code snippet:
|
||||
|
||||
```java
|
||||
String projectName = project.getName();
|
||||
VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentSourceRoots();
|
||||
String sourceRootsList = Arrays.stream(vFiles).map(VirtualFile::getUrl).collect(Collectors.joining("\n"));
|
||||
|
||||
Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, "Project Properties");
|
||||
```
|
||||
|
||||
### Checking if a file belongs to a project
|
||||
|
||||
### Checking if a File Belongs to a Project
|
||||
Use [`ProjectFileIndex`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java) to get this information:
|
||||
```java
|
||||
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
```
|
||||
|
||||
### How do I get the content or source root to which the specified file or directory belongs?
|
||||
|
||||
Use the `ProjectFileIndex.getContentRootForFile()` and `ProjectFileIndex.getSourceRootForFile()` methods. For example:
|
||||
|
||||
### Getting the Content or Source Root to Which the a File or Directory Belongs
|
||||
Use the `ProjectFileIndex.getContentRootForFile()` and `ProjectFileIndex.getSourceRootForFile()` methods.
|
||||
For example:
|
||||
```java
|
||||
VirtualFile moduleContentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFileOrDirectory);
|
||||
VirtualFile moduleSourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virtualFileOrDirectory);
|
||||
@ -53,36 +58,25 @@ VirtualFile moduleSourceRoot = ProjectRootManager.getInstance(project).getFileIn
|
||||
|
||||
Note that this method returns `null` if the file or directory does not belong to any source root of modules in the project.
|
||||
|
||||
### How do I check whether a file or directory is related to the project libraries?
|
||||
### Checking Whether a File or Directory Is Related to the Project Libraries
|
||||
The [`ProjectFileIndex`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java) interface implements a number of methods you can use to check whether the specified file belongs to the project library classes or library sources:
|
||||
* `isLibraryClassFile()`: Returns `true` if the specified `virtualFile` is a compiled class file.
|
||||
* `isInLibraryClasses()`: Returns `true` if the specified `virtualFileorDirectory` belongs to library classes.
|
||||
* `isInLibrarySource()`: Returns `true` if the specified `virtualFileorDirectory` belongs to library sources.
|
||||
|
||||
The `ProjectFileIndex` interface implements a number of methods you can use to check whether the specified file belongs to the project library classes or library sources:
|
||||
* `isLibraryClassFile(virtualFile)`: Returns `true` if the specified `virtualFile` is a compiled class file.
|
||||
* `isInLibraryClasses(virtualFileorDirectory)`: Returns `true` if the specified `virtualFileorDirectory` belongs to library classes.
|
||||
* `isInLibrarySource(virtualFileorDirectory)`: Returns `true` if the specified `virtualFileorDirectory` belongs to library sources.
|
||||
|
||||
### How do I get the project SDK?
|
||||
|
||||
* To get the project-level SDK: `Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();`
|
||||
* To get the project-level SDK name: `String projectSdkName = ProjectRootManager.getInstance(project).getProjectSdkName();`
|
||||
|
||||
### How do I set the project SDK?
|
||||
|
||||
* To set the project-level SDK: `ProjectRootManager.getInstance(project).setProjectSdk(Sdk jdk);`
|
||||
* To set the project-level SDK name: `ProjectRootManager.getInstance(project).setProjectSdkName(String name);`
|
||||
|
||||
Note that by default, the project modules use the project SDK. Optionally, you can configure an individual SDK for each module. See [SDK](sdk.md) for more details.
|
||||
|
||||
## Changing the project structure
|
||||
### Getting the Project SDK
|
||||
Note that by default, the project modules use the project SDK.
|
||||
Optionally, you can configure an individual SDK for each module.
|
||||
See [SDK](sdk.md) for more details.
|
||||
|
||||
## Changing the Project Structure
|
||||
Utility classes used for modifying the project structure can be found in the package [projectModel-impl.openapi](upsource:///platform/projectModel-impl/src/com/intellij/openapi). Its [roots](upsource:///platform/projectModel-impl/src/com/intellij/openapi/roots/) subpackage contains instances and utilities intended for work with project and module source roots, including [`ModuleRootModificationUtil`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ModuleRootModificationUtil.java) and [`ProjectRootUtil`](upsource:///platform/projectModel-impl/src/com/intellij/openapi/projectRoots/impl/ProjectRootUtil.java). Project structure
|
||||
changes need to be performed in a [write action](/basics/architectural_overview/general_threading_rules.md#readwrite-lock).
|
||||
|
||||
Refer to the [basic example](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/com/intellij/tutorials/project/model/ModificationAction.java) of on-the-fly project structure modification to learn how it can be implemented.
|
||||
Refer to the [`project_model`](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/main/java/org/intellij/sdk/project/model/ModificationAction.java) code sample to learn how project structure modification can be implemented.
|
||||
|
||||
## Receiving notifications about project structure changes
|
||||
|
||||
To receive notifications about changes in project structure (modules or libraries being added or removed, module dependencies being changed, and so on),
|
||||
use the [message bus](/reference_guide/messaging_infrastructure.md) and the `ProjectTopics.PROJECT_ROOTS` topic:
|
||||
## Receiving Notifications about Project Structure Changes
|
||||
To receive notifications about changes in project structure (modules or libraries being added or removed, module dependencies being changed, and so on), use the [message bus](/reference_guide/messaging_infrastructure.md) and the `ProjectTopics.PROJECT_ROOTS` topic:
|
||||
|
||||
```java
|
||||
project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
|
||||
@ -92,6 +86,4 @@ project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new Mod
|
||||
});
|
||||
```
|
||||
|
||||
The event only notifies you that something has changed; if you need to know in detail what changes have occurred, you
|
||||
need to keep a copy of the state of the project structure model which is relevant for you, and to compare it with the
|
||||
current state after the change.
|
||||
The event only notifies that something has changed; if more details are needed about what changes have occurred, keep a copy of the state of the project structure model which is relevant, and to compare it with the state after the change.
|
||||
|
@ -2,17 +2,21 @@
|
||||
title: SDK
|
||||
---
|
||||
|
||||
Every project uses a Software Development Kit (SDK). For Java projects, the SDK is referred to as the JDK (Java Development Kit). The SDK determines which API library is used to build the project. If your project is multi-module, the project SDK by default is common for all modules within the project. Optionally, you can configure individual SDKs for each module. For more information about SDKs, see [SDK](https://www.jetbrains.com/help/idea/working-with-sdks.html) in the IntelliJ IDEA Web Help.
|
||||
Every project uses a Software Development Kit (SDK).
|
||||
For Java projects, the SDK is referred to as the JDK (Java Development Kit).
|
||||
The SDK determines which API library is used to build the project.
|
||||
If a project is multi-module, the project SDK by default is common for all modules within the project.
|
||||
Optionally, individual SDKs for each module can be configured.
|
||||
For more information about SDKs, see [SDK](https://www.jetbrains.com/help/idea/working-with-sdks.html) in the IntelliJ IDEA Web Help.
|
||||
|
||||
## Getting project SDK information
|
||||
|
||||
Main information about the project SDK can be accessed via [`ProjectRootManager`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ProjectRootManager.java) like the following example shows
|
||||
## Getting Project SDK Information
|
||||
The information about the project SDK is accessed via [`ProjectRootManager`](upsource:///platform/projectModel-api/src/com/intellij/openapi/roots/ProjectRootManager.java) like the following example shows
|
||||
|
||||
```java
|
||||
Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
|
||||
```
|
||||
|
||||
## Getting and setting project SDK attributes
|
||||
## Getting and Setting Project SDK Attributes
|
||||
|
||||
* To get the project level SDK
|
||||
|
||||
@ -38,11 +42,11 @@ Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
|
||||
ProjectRootManager.getInstance(project).setProjectSdkName(String name);
|
||||
```
|
||||
|
||||
See the following [code sample](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectSdkAction.java) to get more familiar with SDK manipulation tool set.
|
||||
See the [project_model](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/project_model/src/main/java/org/intellij/sdk/project/model/ProjectSdkAction.java) code sample to get more familiar with SDK manipulation toolset.
|
||||
|
||||
## Working with your own SDK
|
||||
## Working with a Custom SDK
|
||||
|
||||
To create your own SDK, provide a class extending [`SdkType`](upsource:///platform/lang-api/src/com/intellij/openapi/projectRoots/SdkType.java), leave `saveAdditionalData()` blank, and register it in the `com.intellij.sdkType` extension point.
|
||||
To create a custom SDK, provide a class extending [`SdkType`](upsource:///platform/lang-api/src/com/intellij/openapi/projectRoots/SdkType.java), leave `saveAdditionalData()` blank, and register it in the `com.intellij.sdkType` extension point.
|
||||
|
||||
To make SDK settings persistent, override `setupSdkPaths()` and save settings by `modificator.commitChanges()`:
|
||||
|
||||
@ -56,11 +60,11 @@ public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) {
|
||||
}
|
||||
```
|
||||
|
||||
To let user select an SDK, see [`ProjectJdksEditor`](upsource:///java/idea-ui/src/com/intellij/openapi/projectRoots/ui/ProjectJdksEditor.java).
|
||||
To let a user select an SDK, see [`ProjectJdksEditor`](upsource:///java/idea-ui/src/com/intellij/openapi/projectRoots/ui/ProjectJdksEditor.java).
|
||||
|
||||
However, it is not recommended to use "SDK" in non-IntelliJ IDEA IDEs. Although "SDK" is available in most JetBrains products, `ProjectJdksEditor` is specific to Java, making the operation around "SDK" difficult.
|
||||
The most recommended way of managing your "SDK" settings is to create a [`CustomStepProjectGenerator`](upsource:///platform/lang-impl/src/com/intellij/ide/util/projectWizard/CustomStepProjectGenerator.java)
|
||||
The recommended way of managing "SDK" settings is to create a [`CustomStepProjectGenerator`](upsource:///platform/lang-impl/src/com/intellij/ide/util/projectWizard/CustomStepProjectGenerator.java)
|
||||
implementation and save settings in a [`PersistentStateComponent`](/basics/persisting_state_of_components.md).
|
||||
|
||||
## Assisting in setting up SDK
|
||||
Register your implementation of [`ProjectSdkSetupValidator`](upsource:///platform/lang-impl/src/com/intellij/codeInsight/daemon/ProjectSdkSetupValidator.java) in extension point `com.intellij.projectSdkSetupValidator` to provide quick fix.
|
||||
## Assisting in Setting Up an SDK
|
||||
Register the implementation of [`ProjectSdkSetupValidator`](upsource:///platform/lang-impl/src/com/intellij/codeInsight/daemon/ProjectSdkSetupValidator.java) in extension point `com.intellij.projectSdkSetupValidator` to provide quick fix.
|
Loading…
x
Reference in New Issue
Block a user