Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Agent guide for plexus-build-api

`org.codehaus.plexus:plexus-build-api` lets Maven plugins report file changes, messages and
progress to whatever runs the build: IDEs use it for incremental builds (which files were touched),
markers pointing at a file and line, and notifications about updated files. The project has no
`src/site` pages; the site is generated from the POM and the Javadoc, and the README is the user
guide.

## Build and test

- CI calls the shared `codehaus-plexus/.github` `maven.yml@master` workflow, which runs
`mvn verify javadoc:javadoc` on JDK 8, 21 and 25 and on Linux, Windows and macOS. A push to
master also deploys a snapshot.
- Main code must use the Java 8 API (`javaVersion` 8 from the `plexus` parent).
- Unit tests use JUnit 5.
- `sisu-maven-plugin` builds the component index, and the JAR sets
`Automatic-Module-Name: org.codehaus.plexus.build`; keep that name stable.
- Run `mvn spotless:apply` on JDK 17 to 21 before pushing; it also formats Markdown.

## Documentation updates

A change that users or contributors can notice ships with the documentation it affects, in the
same pull request. A refactor with no visible effect needs none.

- Public API added or changed in `BuildContext`, `Messages` or `Progress`: its Javadoc, and the
matching section of `README.md`, including the example code.
- The Java requirement, or how to build and release: `README.md`.
- A new convention, build gate or test fixture: this file.

61 changes: 52 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Plexus Build API
================

[![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/codehaus-plexus/plexus-build-api.svg?label=License)](http://www.apache.org/licenses/)
[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-build-api.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.plexus/plexus-build-api)
![Build Status](https://github.com/codehaus-plexus/plexus-build-api/actions/workflows/maven.yml/badge.svg)
[![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/codehaus-plexus/plexus-build-api.svg?label=License)](https://www.apache.org/licenses/LICENSE-2.0)
[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-build-api.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/org.codehaus.plexus/plexus-build-api)
[![Build Status](https://github.com/codehaus-plexus/plexus-build-api/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/codehaus-plexus/plexus-build-api/actions/workflows/maven.yml?query=branch%3Amaster)

This API allows IDEs to integrate with Maven deeper than it would be possible by just using regular Maven/Mojo API.
This API lets IDEs integrate with Maven more deeply than the regular Maven plugin API allows. It requires
Java 8 or later. The [site](https://codehaus-plexus.github.io/plexus-build-api/) has the Javadoc,
and contributor notes are in [AGENTS.md](AGENTS.md).

It supports

Expand All @@ -18,7 +20,7 @@ Current Implementations

### Default Implementation

The default implementation shipping with this artifact is supposed to impose minimal overhead. It doesn't support incremental build and acts directly on the file system. Errors and warning are just logged through SLF4J.
The default implementation shipping with this artifact is supposed to impose minimal overhead. It doesn't support incremental build and acts directly on the file system. Errors and warnings are just logged through SLF4J.

### M2Eclipse

Expand Down Expand Up @@ -71,12 +73,53 @@ public void execute() {
}
```

### BuildContext

`BuildContext` is the original API: it tells a mojo which files changed since the last build, and writes
output files so that an IDE learns about them.

```java
@Inject
private BuildContext buildContext;

public void execute() throws IOException {
if (buildContext.hasDelta(sourceFile)) {
try (OutputStream out = buildContext.newFileOutputStream(targetFile)) {
// write the generated file
}
}

// state kept between two executions of the same mojo in an incremental build
List<String> previous = buildContext.getValue("extracted");
buildContext.setValue("extracted", current);
}
```

`getValue` returns `null` when the build is not incremental, and its return type is inferred from the
assignment target: a stored value of another type fails with a `ClassCastException` at the call site.

### Progress

The API allows a mojo to report progress in a way that is suitable to be shown as a progressbar as well as check if the user wants the mojo to gracefully abort its current operation.
This can be useful for example when processing some files in a loop so the user can directly see the amount of progress and possibly ask to abort if it takes to long.
This can be useful for example when processing some files in a loop so the user can directly see the amount of progress and possibly ask to abort if it takes too long.

```java
@Inject
private Progress progress;

public void execute() {
progress.startTask("Processing files", files.size());
for (File file : files) {
if (progress.isCancelRequested()) {
return;
}
// process the file
progress.worked(1);
}
}
```

### IDE connection to maven process
### IDE connection to the Maven process

This API is usually not used by mojos but for IDE integration, if enabled as a maven-core extension plexus-build-api supply a way to communicate with the running maven build and get events.
The default implementation open a tcp connections to a port specified by the system property `plexus.build.ipc.port` using key/value encoded message format. If no such value is given all messages are silently discarded.
This API is usually not used by mojos but for IDE integration: if enabled as a Maven core extension, plexus-build-api supplies a way to communicate with the running Maven build and get events.
The default implementation opens a TCP connection to a port specified by the system property `plexus.build.ipc.port` using key/value encoded message format. If no such value is given all messages are silently discarded.
Loading