Class Maven
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
This is the IntelliJ port of the NetBeans Maven toolkit. It uses
MavenProjectsManager to enumerate imported Maven projects and their resolved
dependencies, and MavenRunner to execute goals against a project's live
configuration. Goal execution is asynchronous in the platform; this toolkit awaits
completion on a latch so the model receives a definitive result. Build output streams to
the IDE's Maven Run console (the platform does not expose it as a return value here).
- Author:
- anahata
-
Field Summary
Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class ToolContext
toolkit -
Constructor Summary
ConstructorsConstructorDescriptionMaven()Constructs the Maven toolkit (instantiated reflectively via its public no-arg constructor). -
Method Summary
Modifier and TypeMethodDescriptionAdds a dependency to a project'spom.xmland triggers a Maven reimport.getDependencies(String projectPath) Lists the resolved dependencies of the Maven project at the given path, grouped by scope.Lists every imported Maven project across all open IntelliJ projects.Gets a list of system instruction strings provided by this context provider.private Object[]resolveMavenContext(String projectPath) Resolves[IntelliJ Project, MavenProject]for a directory or pom path.private org.jetbrains.idea.maven.project.MavenProjectresolveMavenProject(String projectPath) Resolves theMavenProjectfor a directory or pom path.Executes Maven goals against the project at the given path and awaits completion.searchMavenIndex(String query, Integer maxResults) Searches the configured Maven repository index for artifacts matching a query.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, initialize, isEffectivelyProviding, postActivate, rebindMethods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, addAttachment, error, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, isProviding, populateMessage, setParentProvider, setProviding
-
Constructor Details
-
Maven
public Maven()Constructs the Maven toolkit (instantiated reflectively via its public no-arg constructor).
-
-
Method Details
-
getSystemInstructions
Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.Notes that projects must be imported as Maven projects and that goal output appears in the IDE Maven console.
- Returns:
- A list of system instruction strings.
- Throws:
Exception- if an error occurs during instruction generation.
-
getMavenProjects
Lists every imported Maven project across all open IntelliJ projects.- Returns:
- a Markdown listing of Maven coordinates, packaging and directory.
-
getDependencies
Lists the resolved dependencies of the Maven project at the given path, grouped by scope.- Parameters:
projectPath- the absolute path of the project directory or itspom.xml.- Returns:
- a Markdown listing of resolved dependencies.
- Throws:
AgiToolException- if the path is not a recognized (imported) Maven project.
-
runGoals
public String runGoals(String projectPath, List<String> goals, List<String> profiles) throws AgiToolException Executes Maven goals against the project at the given path and awaits completion.The goals run through the platform
MavenRunner; this call blocks (off the EDT) until the build finishes or a generous timeout elapses. Console output is shown in the IDE's Maven Run tool window.- Parameters:
projectPath- the absolute path of the project directory or itspom.xml.goals- the Maven goals to run (e.g.clean,install).profiles- the profiles to activate, ornull/empty for none.- Returns:
- a completion summary.
- Throws:
AgiToolException- if the project cannot be resolved or the build is interrupted.
-
searchMavenIndex
Searches the configured Maven repository index for artifacts matching a query.Uses
MavenArtifactSearcheragainst the index of the first open project. Results depend on the repository index having been built/downloaded by the IDE; an empty result usually means the index is not yet available.- Parameters:
query- the search query (matched against groupId/artifactId).maxResults- the maximum number of results, ornullfor 50.- Returns:
- a Markdown listing of matching
groupId:artifactId:versioncoordinates. - Throws:
AgiToolException- if no project is open.
-
addDependency
public String addDependency(String projectPath, String groupId, String artifactId, String version, String scope) throws AgiToolException Adds a dependency to a project'spom.xmland triggers a Maven reimport.The dependency element is spliced into the existing
<dependencies>block (or a new block is created before</project>) via a single undoable document edit, the file is saved, andMavenProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles()refreshes the project model so the new artifact is resolved onto the classpath.- Parameters:
projectPath- the absolute path of the project directory or itspom.xml.groupId- the dependency groupId.artifactId- the dependency artifactId.version- the dependency version.scope- the Maven scope (e.g.compile,test), ornullfor default.- Returns:
- a confirmation message.
- Throws:
AgiToolException- if the pom cannot be resolved or edited.
-
resolveMavenProject
private org.jetbrains.idea.maven.project.MavenProject resolveMavenProject(String projectPath) throws AgiToolException Resolves theMavenProjectfor a directory or pom path.- Parameters:
projectPath- the absolute project directory or pom path.- Returns:
- the resolved Maven project.
- Throws:
AgiToolException- if it is not a recognized imported Maven project.
-
resolveMavenContext
Resolves[IntelliJ Project, MavenProject]for a directory or pom path.- Parameters:
projectPath- the absolute project directory or pom path.- Returns:
- a two-element array of the host IntelliJ project and the Maven project.
- Throws:
AgiToolException- if the pom cannot be found or is not an imported Maven project.
-

