diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..d48ea5b --- /dev/null +++ b/AGENTS.md @@ -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. + diff --git a/README.md b/README.md index 4509abf..c0f32fa 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 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.