From f28ab021d2289e28939a68dd940c9bb0d6b5b63f Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 24 Oct 2022 16:44:25 +1000 Subject: [PATCH 01/42] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 45cf75b..607ce59 100644 --- a/pom.xml +++ b/pom.xml @@ -21,13 +21,13 @@ See the Apache License Version 2.0 for the specific language governing permissio plexus-build-api - 1.0.0 + 1.0.1-SNAPSHOT scm:git:https://github.com/codehaus-plexus/plexus-build-api.git scm:git:https://github.com/codehaus-plexus/plexus-build-api.git https://github.com/codehaus-plexus/plexus-build-api - plexus-build-api-1.0.0 + HEAD From 1647a5e025fde94b3182d5bcb083c6a58269b542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 5 Nov 2022 05:34:36 +0100 Subject: [PATCH 02/42] Store Objects in the DefaultContext in a map (#50) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix https://github.com/codehaus-plexus/plexus-build-api/issues/48 Co-authored-by: Christoph Läubrich --- .../plexus/build/DefaultBuildContext.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java index 049ae0e..f83c6ba 100644 --- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java @@ -21,6 +21,8 @@ import java.io.OutputStream; import java.nio.file.Files; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.Scanner; @@ -28,19 +30,24 @@ import org.slf4j.LoggerFactory; /** - * Filesystem based non-incremental build context implementation which behaves as if all files - * were just created. More specifically, + * Filesystem based non-incremental build context implementation which behaves + * as if all files were just created. More specifically, * - * hasDelta returns true for all paths - * newScanner returns Scanner that scans all files under provided basedir - * newDeletedScanner always returns empty scanner. - * isIncremental returns false - * getValue always returns null + *
    + *
  1. hasDelta returns true for all paths
  2. + *
  3. newScanner returns Scanner that scans all files under provided + * basedir
  4. + *
  5. newDeletedScanner always returns empty scanner
  6. + *
  7. isIncremental returns false
  8. + *
  9. getValue always returns the last set value in this session and only + * stores to memory
  10. + *
*/ @Named("default") @Singleton public class DefaultBuildContext implements BuildContext { + private final Map contextMap = new ConcurrentHashMap<>(); private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class); /** {@inheritDoc} */ public boolean hasDelta(String relpath) { @@ -105,11 +112,12 @@ public boolean isIncremental() { /** {@inheritDoc} */ public Object getValue(String key) { - return null; + return contextMap.get(key); } /** {@inheritDoc} */ public void setValue(String key, Object value) { + contextMap.put(key, value); } private String getMessage(File file, int line, int column, String message) { From 46ce8d1caaf1734f8518a900481afbda49b3aef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 5 Nov 2022 07:25:51 +0100 Subject: [PATCH 03/42] Remove ThreadBuildContext (#51) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix https://github.com/codehaus-plexus/plexus-build-api/issues/45 Co-authored-by: Christoph Läubrich --- .../plexus/build/ThreadBuildContext.java | 158 ------------------ 1 file changed, 158 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/build/ThreadBuildContext.java diff --git a/src/main/java/org/codehaus/plexus/build/ThreadBuildContext.java b/src/main/java/org/codehaus/plexus/build/ThreadBuildContext.java deleted file mode 100644 index 24a92cc..0000000 --- a/src/main/java/org/codehaus/plexus/build/ThreadBuildContext.java +++ /dev/null @@ -1,158 +0,0 @@ -/* -Copyright (c) 2008 Sonatype, Inc. All rights reserved. - -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. -You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. -*/ - -package org.codehaus.plexus.build; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -import org.codehaus.plexus.util.Scanner; - -/** - * BuildContext implementation that delegates actual work to thread-local - * build context set using {@link #setThreadBuildContext(BuildContext)}. - * {@link DefaultBuildContext} is used if no thread local build context was set. - * - * Note that plexus component metadata is not generated for this implementation. - * Apparently, older version of plexus used by maven-filtering and likely - * other projects, does not honour "default" role-hint. - * - * @author slachiewicz - * @version $Id: $Id - * @since 0.0.8 - */ -public class ThreadBuildContext implements BuildContext { - - private static final ThreadLocal threadContext = new ThreadLocal(){ - @Override - protected BuildContext initialValue() { - return defaultContext; - } - }; - - private static final DefaultBuildContext defaultContext = new DefaultBuildContext(); - - /** - *

getContext.

- * - * @return a {@link BuildContext} object. - */ - public static BuildContext getContext() { - return threadContext.get(); - } - - /** - *

setThreadBuildContext.

- * - * @param context a {@link BuildContext} object. - */ - public static void setThreadBuildContext(BuildContext context) { - threadContext.set(context); - } - - /** {@inheritDoc} */ - public boolean hasDelta(String relPath) { - return getContext().hasDelta(relPath); - } - - /** - *

hasDelta.

- * - * @param file a {@link java.io.File} object. - * @return a boolean. - */ - public boolean hasDelta(File file) { - return getContext().hasDelta(file); - } - - /** - *

hasDelta.

- * - * @param relPaths a {@link java.util.List} object. - * @return a boolean. - */ - public boolean hasDelta(List relPaths) { - return getContext().hasDelta(relPaths); - } - - /** {@inheritDoc} */ - public Scanner newDeleteScanner(File basedir) { - return getContext().newDeleteScanner(basedir); - } - - /** {@inheritDoc} */ - public OutputStream newFileOutputStream(File file) throws IOException { - return getContext().newFileOutputStream(file); - } - - /** {@inheritDoc} */ - public Scanner newScanner(File basedir) { - return getContext().newScanner(basedir); - } - - /** {@inheritDoc} */ - public Scanner newScanner(File basedir, boolean ignoreDelta) { - return getContext().newScanner(basedir, ignoreDelta); - } - - /** {@inheritDoc} */ - public void refresh(File file) { - getContext().refresh(file); - } - - /** {@inheritDoc} */ - public Object getValue(String key) { - return getContext().getValue(key); - } - - /** - *

isIncremental.

- * - * @return a boolean. - */ - public boolean isIncremental() { - return getContext().isIncremental(); - } - - /** {@inheritDoc} */ - public void setValue(String key, Object value) { - getContext().setValue(key, value); - } - - /** {@inheritDoc} */ - public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { - getContext().addMessage(file, line, column, message, severity, cause); - } - - /** {@inheritDoc} */ - public void removeMessages(File file) { - getContext().removeMessages(file); - } - - /** {@inheritDoc} */ - public void addWarning(File file, int line, int column, String message, Throwable cause) { - addMessage(file, line, column, message, SEVERITY_WARNING, cause); - } - - /** {@inheritDoc} */ - public void addError(File file, int line, int column, String message, Throwable cause) { - addMessage(file, line, column, message, SEVERITY_ERROR, cause); - } - - /** {@inheritDoc} */ - public boolean isUptodate(File target, File source) { - return getContext().isUptodate(target, source); - } -} From dd472d2eee4b41605a874f87078e5097e3879fb7 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Wed, 9 Nov 2022 17:51:30 +0100 Subject: [PATCH 04/42] ignore Eclipse metadata --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1ebf457..37eebec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ target/ *.iml .idea/ +.classpath +.project +.settings/ \ No newline at end of file From 985c3609a6429e0a59ffa0554b9b9bdae19b19cb Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 14 Nov 2022 16:34:43 +0100 Subject: [PATCH 05/42] Add README and LICENSE (#53) --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 27 ++++++++ 2 files changed, 228 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e1ce3c --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +Plexus Build API +======================= + +[![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/codehaus-plexus/plexus-classworlds.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) + +This API allows IDEs to integrate with Maven deeper than it would be possible by just using regular Maven/Mojo API. + +It supports + +- incremental builds e.g. allows to query which files have been touched since last build +- fine-grained error/info markers (referring to specific files in particular line numbers) +- notifications about updated files + + +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. + +### M2Eclipse + +[M2Eclipse](https://www.eclipse.org/m2e/) is using this API for supporting both incremental builds and fully integrated error markers in Eclipse. They maintain information for Mojo developers at [Making Maven Plugins Compatible](https://www.eclipse.org/m2e/documentation/m2e-making-maven-plugins-compat.html). +Currently only versions up to 0.0.7 (with old Maven coordinates `org.sonatype.plexus:plexus-build-api`) are supported, this limitation is tracked in [Issue 944](https://github.com/eclipse-m2e/m2e-core/issues/944). From 5f84e0a828a7c5a22d2d15a0c6eaeb89dd82040d Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 5 Dec 2022 10:13:21 +0100 Subject: [PATCH 06/42] Add history section --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5e1ce3c..6af0dde 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,8 @@ The default implementation shipping with this artifact is supposed to impose min [M2Eclipse](https://www.eclipse.org/m2e/) is using this API for supporting both incremental builds and fully integrated error markers in Eclipse. They maintain information for Mojo developers at [Making Maven Plugins Compatible](https://www.eclipse.org/m2e/documentation/m2e-making-maven-plugins-compat.html). Currently only versions up to 0.0.7 (with old Maven coordinates `org.sonatype.plexus:plexus-build-api`) are supported, this limitation is tracked in [Issue 944](https://github.com/eclipse-m2e/m2e-core/issues/944). + +History +----- + +The project was relocated from . Also its Maven coordinates changed from `org.sonatype.plexus:plexus-build-api` to `org.codehaus.plexus:plexus-build-api`, the API is still the same, though. From 4ea7e85ebe7cd43d89b21bcf771460eb57051169 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Mar 2023 02:58:59 +0000 Subject: [PATCH 07/42] Bump plexus-utils from 3.5.0 to 3.5.1 Bumps [plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.5.0 to 3.5.1. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.5.0...plexus-utils-3.5.1) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 607ce59..53b717f 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus-utils - 3.5.0 + 3.5.1 javax.inject From c072534bce42430b3ea2225aee06fb2eef5480e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Mar 2023 02:58:22 +0000 Subject: [PATCH 08/42] Bump maven-surefire-plugin from 2.22.2 to 3.0.0 Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 2.22.2 to 3.0.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-2.22.2...surefire-3.0.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53b717f..020ea47 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.0.0 true From 628b04e653caf1b0e494b0904d7630b8b8a1e559 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 May 2023 02:58:55 +0000 Subject: [PATCH 09/42] Bump maven-surefire-plugin from 3.0.0 to 3.1.0 Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.0.0 to 3.1.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.0.0...surefire-3.1.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 020ea47..2dbb706 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.apache.maven.plugins maven-surefire-plugin - 3.0.0 + 3.1.0 true From e67ab9f9f70b2a5d4ff08a7f77bf7065ba4b2266 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 May 2023 15:16:36 +0200 Subject: [PATCH 10/42] Reuse plexus-pom action for CI (#65) --- .github/workflows/maven.yml | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fab1345..09feae4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,25 +16,16 @@ # under the License. name: GitHub CI -on: - push: - pull_request: -jobs: +on: [push, pull_request] +jobs: build: name: Build it uses: codehaus-plexus/.github/.github/workflows/maven.yml@master - with: - jdk-fast-fail-build: '11' - jdk-matrix: '["11", "17", "18", "19-ea"]' - jdk-distribution-matrix: '["zulu", "temurin", "microsoft", "liberica","corretto"]' - os-matrix: '["ubuntu-latest","windows-latest", "macOS-latest"]' - matrix-exclude: '[ - { "jdk": "18", "distribution": "microsoft" }, - { "jdk": "19-ea", "distribution": "corretto" }, - { "jdk": "19-ea", "distribution": "liberica" }, - { "jdk": "19-ea", "distribution": "microsoft" }, - { "jdk": "19-ea", "distribution": "temurin" } - ]' - maven_args: 'install javadoc:javadoc -e -B -V -fae -Pno-tests-if-not-on-osx' + + deploy: + name: Deploy + needs: build + uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master + secrets: inherit From 7a142c992ef9339d6f4661bbdd3d846064bef37d Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 May 2023 16:48:13 +0200 Subject: [PATCH 11/42] Use a CachingOutputStream when using the build context (#64) The CachingOutputStream provides a write cache so that the target file is only modified if there's a content change. If the data written exactly maps the existing content of the file, the file will not be modified at all. --- .../java/org/codehaus/plexus/build/DefaultBuildContext.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java index f83c6ba..5b8c66c 100644 --- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java @@ -26,6 +26,7 @@ import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.Scanner; +import org.codehaus.plexus.util.io.CachingOutputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,7 +77,7 @@ public boolean hasDelta(List relpaths) { /** {@inheritDoc} */ public OutputStream newFileOutputStream(File file) throws IOException { - return Files.newOutputStream(file.toPath()); + return new CachingOutputStream(file.toPath()); } /** {@inheritDoc} */ From a37511693428c8e80ddeb92a7b812696da90e3e3 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 May 2023 17:35:08 +0200 Subject: [PATCH 12/42] Switch to plexus-pom 13 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2dbb706..69effd8 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 10 + 13 plexus-build-api From 9bcb1c14e1451a7c3b161f0c779b5815dce226ce Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 May 2023 17:35:40 +0200 Subject: [PATCH 13/42] Reformat using spotless --- pom.xml | 24 +- .../codehaus/plexus/build/BuildContext.java | 437 +++++++++--------- .../plexus/build/DefaultBuildContext.java | 229 ++++----- .../codehaus/plexus/build/EmptyScanner.java | 152 +++--- .../build/test/TestFullBuildContext.java | 26 +- .../test/TestIncrementalBuildContext.java | 282 ++++++----- 6 files changed, 567 insertions(+), 583 deletions(-) diff --git a/pom.xml b/pom.xml index 69effd8..a589c79 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,4 @@ + - 4.0.0 @@ -26,10 +26,10 @@ See the Apache License Version 2.0 for the specific language governing permissio scm:git:https://github.com/codehaus-plexus/plexus-build-api.git scm:git:https://github.com/codehaus-plexus/plexus-build-api.git - https://github.com/codehaus-plexus/plexus-build-api HEAD + https://github.com/codehaus-plexus/plexus-build-api - + org.codehaus.plexus @@ -51,8 +51,8 @@ See the Apache License Version 2.0 for the specific language governing permissio - src/main/resources true + src/main/resources @@ -61,14 +61,14 @@ See the Apache License Version 2.0 for the specific language governing permissio sisu-maven-plugin 0.3.5 - - index-project - - main-index - test-index - - - + + index-project + + main-index + test-index + + + org.apache.maven.plugins diff --git a/src/main/java/org/codehaus/plexus/build/BuildContext.java b/src/main/java/org/codehaus/plexus/build/BuildContext.java index 48fee34..e13b37d 100644 --- a/src/main/java/org/codehaus/plexus/build/BuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/BuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ package org.codehaus.plexus.build; @@ -19,223 +19,222 @@ import org.codehaus.plexus.util.Scanner; - // TODO should it be BuildWorkspace or something like that? /** *

BuildContext interface.

*/ public interface BuildContext { - /** Constant SEVERITY_WARNING=1 */ - int SEVERITY_WARNING = 1; - - /** Constant SEVERITY_ERROR=2 */ - int SEVERITY_ERROR = 2; - - // TODO should we add File getBasedir()? - - /** - * Returns true if file or folder identified by relpath has - * changed since last build. - * - * @param relpath is path relative to build context basedir - * @return a boolean. - */ - boolean hasDelta(String relpath); - - /** - * Returns true if the file has changed since last build or is not - * under basedir. - * - * @since 0.0.5 - * @param file a {@link java.io.File} object. - * @return a boolean. - */ - boolean hasDelta(File file); - - /** - * Returns true if any file or folder identified by relpaths has - * changed since last build. - * - * @param relpaths paths relative to build context basedir - * @return a boolean. - */ - boolean hasDelta(List relpaths); - - /** - * Indicates that the file or folder content has been modified during the build. - * - * @see #newFileOutputStream(File) - * @param file a {@link java.io.File} object. - */ - void refresh(File file); - - /** - * Returns new OutputStream that writes to the file. - * - * Files changed using OutputStream returned by this method do not need to be - * explicitly refreshed using {@link #refresh(File)}. - * - * As an optional optimisation, OutputStreams created by incremental build - * context will attempt to avoid writing to the file if file content - * has not changed. - * - * @param file a {@link java.io.File} object. - * @return a {@link java.io.OutputStream} object. - * @throws java.io.IOException if any. - */ - OutputStream newFileOutputStream(File file) throws IOException; - - /** - * Convenience method, fully equal to newScanner(basedir, false) - * - * @param basedir a {@link java.io.File} object. - * @return a {@link org.codehaus.plexus.util.Scanner} object. - */ - Scanner newScanner(File basedir); - - /** - * Returned Scanner scans basedir for files and directories - * deleted since last build. Returns empty Scanner if basedir - * is not under this build context basedir. - * - * @param basedir a {@link java.io.File} object. - * @return a {@link org.codehaus.plexus.util.Scanner} object. - */ - Scanner newDeleteScanner(File basedir); - - /** - * Returned Scanner scans files and folders under basedir. - * - * If this is an incremental build context and ignoreDelta - * is false, the scanner will only "see" files and folders with - * content changes since last build. - * - * If ignoreDelta is true, the scanner will "see" all - * files and folders. - * - * Please beware that ignoreDelta=false does NOT work reliably for operations - * that copy resources from source to target locations. Returned Scanner - * only scans changed source resources and it does not consider changed or deleted - * target resources. This results in missing or stale target resources. - * Starting with 0.5.0, recommended way to process resources is to use - * #newScanner(basedir,true) to locate all source resources and {@link #isUptodate(File, File)} - * to optimized processing of uptodate target resources. - * - * Returns empty Scanner if basedir is not under this build context basedir. - * - * https://issues.apache.org/jira/browse/MSHARED-125 - * - * @param basedir a {@link java.io.File} object. - * @param ignoreDelta a boolean. - * @return a {@link org.codehaus.plexus.util.Scanner} object. - */ - Scanner newScanner(File basedir, boolean ignoreDelta); - - /** - * Returns true if this build context is incremental. - * - * Scanners created by {@link #newScanner(File)} of an incremental build context - * will ignore files and folders that were not changed since last build. - * Additionally, {@link #newDeleteScanner(File)} will scan files and directories - * deleted since last build. - * - * @return a boolean. - */ - boolean isIncremental(); - - /** - * Associate specified key with specified value - * in the build context. - * - * Primary (and the only) purpose of this method is to allow preservation of - * state needed for proper incremental behaviour between consecutive executions - * of the same mojo needed to. - * - * For example, maven-plugin-plugin:descriptor mojo - * can store collection of extracted MojoDescritpor during first invocation. Then - * on each consecutive execution maven-plugin-plugin:descriptor will only need - * to extract MojoDescriptors for changed files. - * - * @see #getValue(String) - * @param key a {@link java.lang.String} object. - * @param value a {@link java.lang.Object} object. - */ - void setValue(String key, Object value); - - /** - * Returns value associated with key during previous mojo execution. - * - * This method always returns null for non-incremental builds - * (i.e., {@link #isIncremental()} returns false) and mojos are - * expected to fall back to full, non-incremental behaviour. - * - * @see #setValue(String, Object) - * @see #isIncremental() - * @param key a {@link java.lang.String} object. - * @return a {@link java.lang.Object} object. - */ - Object getValue(String key); - - /** - *

addWarning.

- * - * @deprecated Use addMessage with severity=SEVERITY_ERROR instead - * @since 0.0.5 - * @param file a {@link java.io.File} object. - * @param line a int. - * @param column a int. - * @param message a {@link java.lang.String} object. - * @param cause a {@link java.lang.Throwable} object. - */ - void addWarning(File file, int line, int column, String message, Throwable cause); - - /** - *

addError.

- * - * @deprecated Use addMessage with severity=SEVERITY_WARNING instead - * @since 0.0.5 - * @param file a {@link java.io.File} object. - * @param line a int. - * @param column a int. - * @param message a {@link java.lang.String} object. - * @param cause a {@link java.lang.Throwable} object. - */ - void addError(File file, int line, int column, String message, Throwable cause); - - /** - * Adds a message to the build context. The message is associated with a file and a location inside that file. - * - * @param file The file or folder with which the message is associated. Should not be null and it is recommended to be - * an absolute path. - * @param line The line number inside the file. Use 1 (not 0) for the first line. Use 0 for unknown/unspecified. - * @param column The column number inside the file. Use 1 (not 0) for the first column. Use 0 for unknown/unspecified. - * @param severity The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR. - * @param cause A Throwable object associated with the message. Can be null. - * @since 0.0.7 - * @param message a {@link java.lang.String} object. - */ - void addMessage(File file, int line, int column, String message, int severity, Throwable cause); - - /** - * Removes all messages associated with a file or folder during a previous build. It does not affect the messages - * added during the current build. - * - * @since 0.0.7 - * @param file a {@link java.io.File} object. - */ - void removeMessages(File file); - - /** - * Returns true, if the target file exists and is uptodate compared to the source file. - * - * More specifically, this method returns true when both target and source files exist, - * do not have changes since last incremental build and the target file was last modified - * later than the source file. Returns false in all other cases. - * - * @since 0.0.5 - * @param target a {@link java.io.File} object. - * @param source a {@link java.io.File} object. - * @return a boolean. - */ - boolean isUptodate(File target, File source); + /** Constant SEVERITY_WARNING=1 */ + int SEVERITY_WARNING = 1; + + /** Constant SEVERITY_ERROR=2 */ + int SEVERITY_ERROR = 2; + + // TODO should we add File getBasedir()? + + /** + * Returns true if file or folder identified by relpath has + * changed since last build. + * + * @param relpath is path relative to build context basedir + * @return a boolean. + */ + boolean hasDelta(String relpath); + + /** + * Returns true if the file has changed since last build or is not + * under basedir. + * + * @since 0.0.5 + * @param file a {@link java.io.File} object. + * @return a boolean. + */ + boolean hasDelta(File file); + + /** + * Returns true if any file or folder identified by relpaths has + * changed since last build. + * + * @param relpaths paths relative to build context basedir + * @return a boolean. + */ + boolean hasDelta(List relpaths); + + /** + * Indicates that the file or folder content has been modified during the build. + * + * @see #newFileOutputStream(File) + * @param file a {@link java.io.File} object. + */ + void refresh(File file); + + /** + * Returns new OutputStream that writes to the file. + * + * Files changed using OutputStream returned by this method do not need to be + * explicitly refreshed using {@link #refresh(File)}. + * + * As an optional optimisation, OutputStreams created by incremental build + * context will attempt to avoid writing to the file if file content + * has not changed. + * + * @param file a {@link java.io.File} object. + * @return a {@link java.io.OutputStream} object. + * @throws java.io.IOException if any. + */ + OutputStream newFileOutputStream(File file) throws IOException; + + /** + * Convenience method, fully equal to newScanner(basedir, false) + * + * @param basedir a {@link java.io.File} object. + * @return a {@link org.codehaus.plexus.util.Scanner} object. + */ + Scanner newScanner(File basedir); + + /** + * Returned Scanner scans basedir for files and directories + * deleted since last build. Returns empty Scanner if basedir + * is not under this build context basedir. + * + * @param basedir a {@link java.io.File} object. + * @return a {@link org.codehaus.plexus.util.Scanner} object. + */ + Scanner newDeleteScanner(File basedir); + + /** + * Returned Scanner scans files and folders under basedir. + * + * If this is an incremental build context and ignoreDelta + * is false, the scanner will only "see" files and folders with + * content changes since last build. + * + * If ignoreDelta is true, the scanner will "see" all + * files and folders. + * + * Please beware that ignoreDelta=false does NOT work reliably for operations + * that copy resources from source to target locations. Returned Scanner + * only scans changed source resources and it does not consider changed or deleted + * target resources. This results in missing or stale target resources. + * Starting with 0.5.0, recommended way to process resources is to use + * #newScanner(basedir,true) to locate all source resources and {@link #isUptodate(File, File)} + * to optimized processing of uptodate target resources. + * + * Returns empty Scanner if basedir is not under this build context basedir. + * + * https://issues.apache.org/jira/browse/MSHARED-125 + * + * @param basedir a {@link java.io.File} object. + * @param ignoreDelta a boolean. + * @return a {@link org.codehaus.plexus.util.Scanner} object. + */ + Scanner newScanner(File basedir, boolean ignoreDelta); + + /** + * Returns true if this build context is incremental. + * + * Scanners created by {@link #newScanner(File)} of an incremental build context + * will ignore files and folders that were not changed since last build. + * Additionally, {@link #newDeleteScanner(File)} will scan files and directories + * deleted since last build. + * + * @return a boolean. + */ + boolean isIncremental(); + + /** + * Associate specified key with specified value + * in the build context. + * + * Primary (and the only) purpose of this method is to allow preservation of + * state needed for proper incremental behaviour between consecutive executions + * of the same mojo needed to. + * + * For example, maven-plugin-plugin:descriptor mojo + * can store collection of extracted MojoDescritpor during first invocation. Then + * on each consecutive execution maven-plugin-plugin:descriptor will only need + * to extract MojoDescriptors for changed files. + * + * @see #getValue(String) + * @param key a {@link java.lang.String} object. + * @param value a {@link java.lang.Object} object. + */ + void setValue(String key, Object value); + + /** + * Returns value associated with key during previous mojo execution. + * + * This method always returns null for non-incremental builds + * (i.e., {@link #isIncremental()} returns false) and mojos are + * expected to fall back to full, non-incremental behaviour. + * + * @see #setValue(String, Object) + * @see #isIncremental() + * @param key a {@link java.lang.String} object. + * @return a {@link java.lang.Object} object. + */ + Object getValue(String key); + + /** + *

addWarning.

+ * + * @deprecated Use addMessage with severity=SEVERITY_ERROR instead + * @since 0.0.5 + * @param file a {@link java.io.File} object. + * @param line a int. + * @param column a int. + * @param message a {@link java.lang.String} object. + * @param cause a {@link java.lang.Throwable} object. + */ + void addWarning(File file, int line, int column, String message, Throwable cause); + + /** + *

addError.

+ * + * @deprecated Use addMessage with severity=SEVERITY_WARNING instead + * @since 0.0.5 + * @param file a {@link java.io.File} object. + * @param line a int. + * @param column a int. + * @param message a {@link java.lang.String} object. + * @param cause a {@link java.lang.Throwable} object. + */ + void addError(File file, int line, int column, String message, Throwable cause); + + /** + * Adds a message to the build context. The message is associated with a file and a location inside that file. + * + * @param file The file or folder with which the message is associated. Should not be null and it is recommended to be + * an absolute path. + * @param line The line number inside the file. Use 1 (not 0) for the first line. Use 0 for unknown/unspecified. + * @param column The column number inside the file. Use 1 (not 0) for the first column. Use 0 for unknown/unspecified. + * @param severity The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR. + * @param cause A Throwable object associated with the message. Can be null. + * @since 0.0.7 + * @param message a {@link java.lang.String} object. + */ + void addMessage(File file, int line, int column, String message, int severity, Throwable cause); + + /** + * Removes all messages associated with a file or folder during a previous build. It does not affect the messages + * added during the current build. + * + * @since 0.0.7 + * @param file a {@link java.io.File} object. + */ + void removeMessages(File file); + + /** + * Returns true, if the target file exists and is uptodate compared to the source file. + * + * More specifically, this method returns true when both target and source files exist, + * do not have changes since last incremental build and the target file was last modified + * later than the source file. Returns false in all other cases. + * + * @since 0.0.5 + * @param target a {@link java.io.File} object. + * @param source a {@link java.io.File} object. + * @return a boolean. + */ + boolean isUptodate(File target, File source); } diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java index 5b8c66c..3e02ed6 100644 --- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -19,7 +19,6 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.nio.file.Files; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -49,112 +48,114 @@ public class DefaultBuildContext implements BuildContext { private final Map contextMap = new ConcurrentHashMap<>(); - private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class); - /** {@inheritDoc} */ - public boolean hasDelta(String relpath) { - return true; - } - - /** - *

hasDelta.

- * - * @param file a {@link java.io.File} object. - * @return a boolean. - */ - public boolean hasDelta(File file) { - return true; - } - - /** - *

hasDelta.

- * - * @param relpaths a {@link java.util.List} object. - * @return a boolean. - */ - public boolean hasDelta(List relpaths) { - return true; - } - - /** {@inheritDoc} */ - public OutputStream newFileOutputStream(File file) throws IOException { - return new CachingOutputStream(file.toPath()); - } - - /** {@inheritDoc} */ - public Scanner newScanner(File basedir) { - DirectoryScanner ds = new DirectoryScanner(); - ds.setBasedir(basedir); - return ds; - } - - /** {@inheritDoc} */ - public void refresh(File file) { - // do nothing - } - - /** {@inheritDoc} */ - public Scanner newDeleteScanner(File basedir) { - return new EmptyScanner(basedir); - } - - /** {@inheritDoc} */ - public Scanner newScanner(File basedir, boolean ignoreDelta) { - return newScanner(basedir); - } - - /** - *

isIncremental.

- * - * @return a boolean. - */ - public boolean isIncremental() { - return false; - } - - /** {@inheritDoc} */ - public Object getValue(String key) { - return contextMap.get(key); - } - - /** {@inheritDoc} */ - public void setValue(String key, Object value) { - contextMap.put(key, value); - } - - private String getMessage(File file, int line, int column, String message) { - return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message; - } - - /** {@inheritDoc} */ - public void addError(File file, int line, int column, String message, Throwable cause) { - addMessage(file, line, column, message, SEVERITY_ERROR, cause); - } - - /** {@inheritDoc} */ - public void addWarning(File file, int line, int column, String message, Throwable cause) { - addMessage(file, line, column, message, SEVERITY_WARNING, cause); - } - - /** {@inheritDoc} */ - public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { - switch(severity) { - case BuildContext.SEVERITY_ERROR: - logger.error(getMessage(file, line, column, message), cause); - return; - case BuildContext.SEVERITY_WARNING: - logger.warn(getMessage(file, line, column, message), cause); - return; - } - throw new IllegalArgumentException("severity=" + severity); - } - - /** {@inheritDoc} */ - public void removeMessages(File file) { - } - - /** {@inheritDoc} */ - public boolean isUptodate(File target, File source) { - return target != null && target.exists() && source != null && source.exists() - && target.lastModified() > source.lastModified(); - } + private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class); + /** {@inheritDoc} */ + public boolean hasDelta(String relpath) { + return true; + } + + /** + *

hasDelta.

+ * + * @param file a {@link java.io.File} object. + * @return a boolean. + */ + public boolean hasDelta(File file) { + return true; + } + + /** + *

hasDelta.

+ * + * @param relpaths a {@link java.util.List} object. + * @return a boolean. + */ + public boolean hasDelta(List relpaths) { + return true; + } + + /** {@inheritDoc} */ + public OutputStream newFileOutputStream(File file) throws IOException { + return new CachingOutputStream(file.toPath()); + } + + /** {@inheritDoc} */ + public Scanner newScanner(File basedir) { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(basedir); + return ds; + } + + /** {@inheritDoc} */ + public void refresh(File file) { + // do nothing + } + + /** {@inheritDoc} */ + public Scanner newDeleteScanner(File basedir) { + return new EmptyScanner(basedir); + } + + /** {@inheritDoc} */ + public Scanner newScanner(File basedir, boolean ignoreDelta) { + return newScanner(basedir); + } + + /** + *

isIncremental.

+ * + * @return a boolean. + */ + public boolean isIncremental() { + return false; + } + + /** {@inheritDoc} */ + public Object getValue(String key) { + return contextMap.get(key); + } + + /** {@inheritDoc} */ + public void setValue(String key, Object value) { + contextMap.put(key, value); + } + + private String getMessage(File file, int line, int column, String message) { + return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message; + } + + /** {@inheritDoc} */ + public void addError(File file, int line, int column, String message, Throwable cause) { + addMessage(file, line, column, message, SEVERITY_ERROR, cause); + } + + /** {@inheritDoc} */ + public void addWarning(File file, int line, int column, String message, Throwable cause) { + addMessage(file, line, column, message, SEVERITY_WARNING, cause); + } + + /** {@inheritDoc} */ + public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { + switch (severity) { + case BuildContext.SEVERITY_ERROR: + logger.error(getMessage(file, line, column, message), cause); + return; + case BuildContext.SEVERITY_WARNING: + logger.warn(getMessage(file, line, column, message), cause); + return; + } + throw new IllegalArgumentException("severity=" + severity); + } + + /** {@inheritDoc} */ + public void removeMessages(File file) {} + + /** {@inheritDoc} */ + public boolean isUptodate(File target, File source) { + return target != null + && target.exists() + && source != null + && source.exists() + && target.lastModified() > source.lastModified(); + } } diff --git a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java b/src/main/java/org/codehaus/plexus/build/EmptyScanner.java index 106b9d9..99cd8a6 100644 --- a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java +++ b/src/main/java/org/codehaus/plexus/build/EmptyScanner.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -22,80 +22,72 @@ * Scanner implementation never finds any files/directories. */ public class EmptyScanner implements Scanner { - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - private final File basedir; - - /** - *

Constructor for EmptyScanner.

- * - * @param basedir a {@link java.io.File} object. - */ - public EmptyScanner(File basedir) { - this.basedir = basedir; - } - - /** - *

addDefaultExcludes.

- */ - public void addDefaultExcludes() { - } - - /** - *

getIncludedDirectories.

- * - * @return an array of {@link java.lang.String} objects. - */ - public String[] getIncludedDirectories() { - return EMPTY_STRING_ARRAY; - } - - /** - *

getIncludedFiles.

- * - * @return an array of {@link java.lang.String} objects. - */ - public String[] getIncludedFiles() { - return EMPTY_STRING_ARRAY; - } - - /** - *

scan.

- */ - public void scan() { - } - - /** - *

setExcludes.

- * - * @param excludes an array of {@link java.lang.String} objects. - */ - public void setExcludes(String[] excludes) { - } - - /** - *

setIncludes.

- * - * @param includes an array of {@link java.lang.String} objects. - */ - public void setIncludes(String[] includes) { - } - - /** - *

Getter for the field basedir.

- * - * @return a {@link java.io.File} object. - */ - public File getBasedir() { - return basedir; - } - - /** {@inheritDoc} */ - @Override - public void setFilenameComparator( Comparator comparator ) - { - - } + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + + private final File basedir; + + /** + *

Constructor for EmptyScanner.

+ * + * @param basedir a {@link java.io.File} object. + */ + public EmptyScanner(File basedir) { + this.basedir = basedir; + } + + /** + *

addDefaultExcludes.

+ */ + public void addDefaultExcludes() {} + + /** + *

getIncludedDirectories.

+ * + * @return an array of {@link java.lang.String} objects. + */ + public String[] getIncludedDirectories() { + return EMPTY_STRING_ARRAY; + } + + /** + *

getIncludedFiles.

+ * + * @return an array of {@link java.lang.String} objects. + */ + public String[] getIncludedFiles() { + return EMPTY_STRING_ARRAY; + } + + /** + *

scan.

+ */ + public void scan() {} + + /** + *

setExcludes.

+ * + * @param excludes an array of {@link java.lang.String} objects. + */ + public void setExcludes(String[] excludes) {} + + /** + *

setIncludes.

+ * + * @param includes an array of {@link java.lang.String} objects. + */ + public void setIncludes(String[] includes) {} + + /** + *

Getter for the field basedir.

+ * + * @return a {@link java.io.File} object. + */ + public File getBasedir() { + return basedir; + } + + /** {@inheritDoc} */ + @Override + public void setFilenameComparator(Comparator comparator) {} } diff --git a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java b/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java index be30fe9..2533138 100644 --- a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java +++ b/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -17,17 +17,15 @@ import org.codehaus.plexus.build.DefaultBuildContext; - public class TestFullBuildContext extends DefaultBuildContext { - private final Map context; - - public TestFullBuildContext(Map context) { - this.context = context; - } + private final Map context; - public void setValue(String key, Object value) { - context.put(key, value); - } + public TestFullBuildContext(Map context) { + this.context = context; + } + public void setValue(String key, Object value) { + context.put(key, value); + } } diff --git a/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java b/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java index 2779d31..3dedd24 100644 --- a/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java +++ b/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -31,175 +31,169 @@ public class TestIncrementalBuildContext implements BuildContext { - private final File basedir; + private final File basedir; - private final Set refresh = new HashSet<>(); + private final Set refresh = new HashSet<>(); - private static final class TestScanner implements Scanner { - private final File basedir; - private final Set files; + private static final class TestScanner implements Scanner { + private final File basedir; + private final Set files; - private TestScanner(File basedir, Set files) { - this.basedir = basedir; - this.files = files; - } + private TestScanner(File basedir, Set files) { + this.basedir = basedir; + this.files = files; + } + + public void addDefaultExcludes() {} + + public String[] getIncludedDirectories() { + return new String[0]; + } + + public String[] getIncludedFiles() { + return (String[]) files.toArray(new String[0]); + } + + public void scan() {} + + public void setExcludes(String[] excludes) {} - public void addDefaultExcludes() { + public void setIncludes(String[] includes) {} + + public File getBasedir() { + return basedir; + } + + @Override + public void setFilenameComparator(Comparator filenameComparator) {} } - public String[] getIncludedDirectories() { - return new String[0]; + private final Set changedFiles; + + private final Set deletedFiles; + + private final Map context; + + private final List warnings; + + private final List errors; + + public TestIncrementalBuildContext(File basedir, Set changedFiles, Map context) { + this(basedir, changedFiles, new HashSet(), context); } - public String[] getIncludedFiles() { - return (String[]) files.toArray(new String[0]); + public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context) { + this(basedir, changedFiles, deletedFiles, context, new ArrayList(), new ArrayList()); } - public void scan() { + public TestIncrementalBuildContext( + File basedir, Set changedFiles, Set deletedFiles, Map context, List warnings, List errors) { + this.basedir = basedir; + this.changedFiles = changedFiles; + this.deletedFiles = deletedFiles; + this.context = context; + this.warnings = warnings; + this.errors = errors; } - public void setExcludes(String[] excludes) { + public boolean hasDelta(String relpath) { + String basepath = basedir.getAbsolutePath(); + + if (relpath.startsWith(basepath)) { + relpath = relpath.substring(basepath.length() + 1); + } + + return changedFiles.contains(relpath) || deletedFiles.contains(relpath); } - public void setIncludes(String[] includes) { + public boolean hasDelta(List relpaths) { + for (Iterator i = relpaths.iterator(); i.hasNext(); ) { + String relpath = i.next(); + if (hasDelta(relpath)) { + return true; + } + } + return false; } - public File getBasedir() { - return basedir; + public boolean hasDelta(File file) { + String relpath = getRelpath(file); + return relpath == null || hasDelta(relpath); } - @Override - public void setFilenameComparator( Comparator filenameComparator ) - { + private String getRelpath(File file) { + try { + String path = file.getCanonicalPath(); + String basepath = basedir.getCanonicalPath(); + if (path.startsWith(basepath) && !path.equals(basepath)) { + return path.substring(basepath.length()); + } else { + return null; + } + } catch (IOException e) { + // this is a test implementation, we can be little loose here + throw new IllegalArgumentException(e); + } + } + public boolean isIncremental() { + return true; } - } - private final Set changedFiles; + public Scanner newDeleteScanner(File basedir) { + return new TestScanner(basedir, deletedFiles); + } - private final Set deletedFiles; + public OutputStream newFileOutputStream(File file) throws IOException { + refresh(file); + return new FileOutputStream(file); + } - private final Map context; + public Scanner newScanner(final File basedir) { + return new TestScanner(basedir, changedFiles); + } - private final List warnings; - - private final List errors; + public Scanner newScanner(File basedir, boolean ignoreDelta) { + if (ignoreDelta) { + DirectoryScanner directoryScanner = new DirectoryScanner(); + directoryScanner.setBasedir(basedir); + return directoryScanner; + } - public TestIncrementalBuildContext(File basedir, Set changedFiles, Map context) { - this(basedir, changedFiles, new HashSet(), context); - } + return newScanner(basedir); + } - public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context) { - this(basedir, changedFiles, deletedFiles, context, new ArrayList(), new ArrayList()); - } + public void refresh(File file) { + refresh.add(file.getAbsoluteFile()); + } - public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context, List warnings, List errors) { - this.basedir = basedir; - this.changedFiles = changedFiles; - this.deletedFiles = deletedFiles; - this.context = context; - this.warnings = warnings; - this.errors = errors; - } + public Object getValue(String key) { + return context.get(key); + } - public boolean hasDelta(String relpath) { - String basepath = basedir.getAbsolutePath(); + public void setValue(String key, Object value) { + context.put(key, value); + } - if (relpath.startsWith(basepath)) { - relpath = relpath.substring(basepath.length() + 1); + public Set getRefreshFiles() { + return refresh; } - return changedFiles.contains(relpath) || deletedFiles.contains(relpath); - } + public void addError(File file, int line, int column, String message, Throwable cause) {} - public boolean hasDelta(List relpaths) { - for(Iterator i = relpaths.iterator(); i.hasNext();) { - String relpath = i.next(); - if(hasDelta(relpath)) { - return true; - } - } - return false; - } - - public boolean hasDelta(File file) { - String relpath = getRelpath(file); - return relpath == null || hasDelta(relpath); - } - - private String getRelpath(File file) { - try { - String path = file.getCanonicalPath(); - String basepath = basedir.getCanonicalPath(); - if (path.startsWith(basepath) && !path.equals(basepath)) { - return path.substring(basepath.length()); - } else { - return null; - } - } catch (IOException e) { - // this is a test implementation, we can be little loose here - throw new IllegalArgumentException(e); - } - } - -public boolean isIncremental() { - return true; - } - - public Scanner newDeleteScanner(File basedir) { - return new TestScanner(basedir, deletedFiles); - } - - public OutputStream newFileOutputStream(File file) throws IOException { - refresh(file); - return new FileOutputStream(file); - } - - public Scanner newScanner(final File basedir) { - return new TestScanner(basedir, changedFiles); - } - - public Scanner newScanner(File basedir, boolean ignoreDelta) { - if(ignoreDelta) { - DirectoryScanner directoryScanner = new DirectoryScanner(); - directoryScanner.setBasedir(basedir); - return directoryScanner; - } - - return newScanner(basedir); - } - - public void refresh(File file) { - refresh.add(file.getAbsoluteFile()); - } - - public Object getValue(String key) { - return context.get(key); - } - - public void setValue(String key, Object value) { - context.put(key, value); - } - - public Set getRefreshFiles() { - return refresh; - } - - public void addError(File file, int line, int column, String message, Throwable cause) { - } - - public void addWarning(File file, int line, int column, String message, Throwable cause) { - } - - public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { - } - - public void removeMessages(File file) { - } - - public boolean isUptodate(File target, File source) { - return target != null && target.exists() && !hasDelta(target) - && source != null && source.exists() && !hasDelta(source) - && target.lastModified() > source.lastModified(); - } + public void addWarning(File file, int line, int column, String message, Throwable cause) {} + + public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {} + + public void removeMessages(File file) {} + + public boolean isUptodate(File target, File source) { + return target != null + && target.exists() + && !hasDelta(target) + && source != null + && source.exists() + && !hasDelta(source) + && target.lastModified() > source.lastModified(); + } } From 5fa1c0d8d659e5e2b9cb00876725b8c5296ab240 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 May 2023 02:58:22 +0000 Subject: [PATCH 14/42] Bump plexus-utils from 3.5.1 to 4.0.0 Bumps [plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.5.1 to 4.0.0. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.5.1...plexus-utils-4.0.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a589c79..0708eb4 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus-utils - 3.5.1 + 4.0.0 javax.inject From 8ba5a8996ce7e175b8b47f62b8d738b46ba0c0cd Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 23 May 2023 11:01:36 +0200 Subject: [PATCH 15/42] Bump sisu-maven-plugin from 0.3.5 to 0.9.0.M2 (#69) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0708eb4..e413bd1 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.eclipse.sisu sisu-maven-plugin - 0.3.5 + 0.9.0.M2 index-project From 71764df18cb22fa8c25a485b61e7ae65e3ff55e6 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 23 May 2023 13:33:38 +0200 Subject: [PATCH 16/42] [maven-release-plugin] prepare release plexus-build-api-1.1.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e413bd1..f27527f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,12 @@ See the Apache License Version 2.0 for the specific language governing permissio plexus-build-api - 1.0.1-SNAPSHOT + 1.1.0 scm:git:https://github.com/codehaus-plexus/plexus-build-api.git scm:git:https://github.com/codehaus-plexus/plexus-build-api.git - HEAD + plexus-build-api-1.1.0 https://github.com/codehaus-plexus/plexus-build-api From 3c13cdbceb5df0be8b70456de6d1a1d7524fa639 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 23 May 2023 13:33:41 +0200 Subject: [PATCH 17/42] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f27527f..c73eb8c 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,12 @@ See the Apache License Version 2.0 for the specific language governing permissio plexus-build-api - 1.1.0 + 1.1.1-SNAPSHOT scm:git:https://github.com/codehaus-plexus/plexus-build-api.git scm:git:https://github.com/codehaus-plexus/plexus-build-api.git - plexus-build-api-1.1.0 + HEAD https://github.com/codehaus-plexus/plexus-build-api From 0ead77374f6fdef1b6acf6785e8b98d8be6ecf1f Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 23 May 2023 13:52:47 +0200 Subject: [PATCH 18/42] Update SCM information and site publishing --- pom.xml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c73eb8c..3ee6dca 100644 --- a/pom.xml +++ b/pom.xml @@ -25,9 +25,9 @@ See the Apache License Version 2.0 for the specific language governing permissio scm:git:https://github.com/codehaus-plexus/plexus-build-api.git - scm:git:https://github.com/codehaus-plexus/plexus-build-api.git - HEAD - https://github.com/codehaus-plexus/plexus-build-api + ${project.scm.connection} + master + https://github.com/codehaus-plexus/plexus-build-api/tree/master @@ -97,6 +97,24 @@ See the Apache License Version 2.0 for the specific language governing permissio + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${project.reporting.outputDirectory} + + + + + scm-publish + + + publish-scm + + site-deploy + + + From 9a9fb61e210a3dc788fe64252a33d03d7b61c0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 2 Jun 2023 08:39:34 +0200 Subject: [PATCH 19/42] Let the DefaultBuildContext delegate to the legacy build-api Currently there is a problem that if a maven-plugin wants to upgrade to the newer API artifact it looses backward-compatibility to older implementors of the API instantly. This changes the DefaultBuildContext in a way that allows it to behave backward-compatible in this case: 1) it gets injected the old implementation 2) it delegates all relevant calls to the legacy 3) it contains a feature-switch that is able to detect if the default-legacy-api is used and therefore we can exchange behavior with a new default or need to still to delegate to a custom implementation. --- pom.xml | 24 +++ .../plexus/build/DefaultBuildContext.java | 96 ++++++--- .../codehaus/plexus/build/EmptyScanner.java | 93 -------- .../build/test/TestFullBuildContext.java | 31 --- .../test/TestIncrementalBuildContext.java | 199 ------------------ 5 files changed, 89 insertions(+), 354 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/build/EmptyScanner.java delete mode 100644 src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java delete mode 100644 src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java diff --git a/pom.xml b/pom.xml index 3ee6dca..d8f3457 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,30 @@ See the Apache License Version 2.0 for the specific language governing permissio slf4j-api 1.7.36 + + + org.sonatype.plexus + plexus-build-api + 0.0.7 + + + * + * + + + + + org.eclipse.sisu + org.eclipse.sisu.plexus + 0.9.0.M2 + + + * + * + + + +
diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java index 3e02ed6..7fb0da6 100644 --- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java @@ -13,6 +13,7 @@ package org.codehaus.plexus.build; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -23,7 +24,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.Scanner; import org.codehaus.plexus.util.io.CachingOutputStream; import org.slf4j.Logger; @@ -47,11 +48,28 @@ @Singleton public class DefaultBuildContext implements BuildContext { - private final Map contextMap = new ConcurrentHashMap<>(); private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class); + // the legacy API requires the AbstractLogEnabled we just have it here to get + // compile errors in case it is missing from the classpath! + @SuppressWarnings("unused") + private static final AbstractLogEnabled DUMMY = null; + + private final Map contextMap = new ConcurrentHashMap<>(); + private org.sonatype.plexus.build.incremental.BuildContext legacy; + + /** + * @param legacy the legacy API we delegate to by default, this allow us to + * support "older" plugins and implementors of the API while still + * having a way to move forward! + */ + @Inject + public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy) { + this.legacy = legacy; + } + /** {@inheritDoc} */ public boolean hasDelta(String relpath) { - return true; + return legacy.hasDelta(relpath); } /** @@ -61,7 +79,7 @@ public boolean hasDelta(String relpath) { * @return a boolean. */ public boolean hasDelta(File file) { - return true; + return legacy.hasDelta(file); } /** @@ -71,34 +89,44 @@ public boolean hasDelta(File file) { * @return a boolean. */ public boolean hasDelta(List relpaths) { - return true; + return legacy.hasDelta(relpaths); } /** {@inheritDoc} */ public OutputStream newFileOutputStream(File file) throws IOException { - return new CachingOutputStream(file.toPath()); + if (isDefaultImplementation()) { + return new CachingOutputStream(file.toPath()); + } + return legacy.newFileOutputStream(file); + } + + /** + * @return true if the legacy is the default implementation and we + * can safely override/change behavior here, or false if a + * custom implementation is used and full delegation is required. + */ + private boolean isDefaultImplementation() { + return legacy.getClass().equals(org.sonatype.plexus.build.incremental.DefaultBuildContext.class); } /** {@inheritDoc} */ public Scanner newScanner(File basedir) { - DirectoryScanner ds = new DirectoryScanner(); - ds.setBasedir(basedir); - return ds; + return legacy.newScanner(basedir); } /** {@inheritDoc} */ public void refresh(File file) { - // do nothing + legacy.refresh(file); } /** {@inheritDoc} */ public Scanner newDeleteScanner(File basedir) { - return new EmptyScanner(basedir); + return legacy.newDeleteScanner(basedir); } /** {@inheritDoc} */ public Scanner newScanner(File basedir, boolean ignoreDelta) { - return newScanner(basedir); + return legacy.newScanner(basedir, ignoreDelta); } /** @@ -107,7 +135,7 @@ public Scanner newScanner(File basedir, boolean ignoreDelta) { * @return a boolean. */ public boolean isIncremental() { - return false; + return legacy.isIncremental(); } /** {@inheritDoc} */ @@ -120,10 +148,6 @@ public void setValue(String key, Object value) { contextMap.put(key, value); } - private String getMessage(File file, int line, int column, String message) { - return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message; - } - /** {@inheritDoc} */ public void addError(File file, int line, int column, String message, Throwable cause) { addMessage(file, line, column, message, SEVERITY_ERROR, cause); @@ -134,28 +158,38 @@ public void addWarning(File file, int line, int column, String message, Throwabl addMessage(file, line, column, message, SEVERITY_WARNING, cause); } + private String getMessage(File file, int line, int column, String message) { + return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message; + } + /** {@inheritDoc} */ public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { - switch (severity) { - case BuildContext.SEVERITY_ERROR: - logger.error(getMessage(file, line, column, message), cause); - return; - case BuildContext.SEVERITY_WARNING: - logger.warn(getMessage(file, line, column, message), cause); - return; + if (isDefaultImplementation()) { + switch (severity) { + case BuildContext.SEVERITY_ERROR: + logger.error(getMessage(file, line, column, message), cause); + return; + case BuildContext.SEVERITY_WARNING: + logger.warn(getMessage(file, line, column, message), cause); + return; + default: + logger.debug(getMessage(file, line, column, message), cause); + return; + } } - throw new IllegalArgumentException("severity=" + severity); + legacy.addMessage(file, line, column, message, severity, cause); } /** {@inheritDoc} */ - public void removeMessages(File file) {} + public void removeMessages(File file) { + if (isDefaultImplementation()) { + return; + } + legacy.removeMessages(file); + } /** {@inheritDoc} */ public boolean isUptodate(File target, File source) { - return target != null - && target.exists() - && source != null - && source.exists() - && target.lastModified() > source.lastModified(); + return legacy.isUptodate(target, source); } } diff --git a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java b/src/main/java/org/codehaus/plexus/build/EmptyScanner.java deleted file mode 100644 index 99cd8a6..0000000 --- a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright (c) 2008 Sonatype, Inc. All rights reserved. - -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. -You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. -*/ - -package org.codehaus.plexus.build; - -import java.io.File; -import java.util.Comparator; - -import org.codehaus.plexus.util.Scanner; - -/** - * Scanner implementation never finds any files/directories. - */ -public class EmptyScanner implements Scanner { - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - private final File basedir; - - /** - *

Constructor for EmptyScanner.

- * - * @param basedir a {@link java.io.File} object. - */ - public EmptyScanner(File basedir) { - this.basedir = basedir; - } - - /** - *

addDefaultExcludes.

- */ - public void addDefaultExcludes() {} - - /** - *

getIncludedDirectories.

- * - * @return an array of {@link java.lang.String} objects. - */ - public String[] getIncludedDirectories() { - return EMPTY_STRING_ARRAY; - } - - /** - *

getIncludedFiles.

- * - * @return an array of {@link java.lang.String} objects. - */ - public String[] getIncludedFiles() { - return EMPTY_STRING_ARRAY; - } - - /** - *

scan.

- */ - public void scan() {} - - /** - *

setExcludes.

- * - * @param excludes an array of {@link java.lang.String} objects. - */ - public void setExcludes(String[] excludes) {} - - /** - *

setIncludes.

- * - * @param includes an array of {@link java.lang.String} objects. - */ - public void setIncludes(String[] includes) {} - - /** - *

Getter for the field basedir.

- * - * @return a {@link java.io.File} object. - */ - public File getBasedir() { - return basedir; - } - - /** {@inheritDoc} */ - @Override - public void setFilenameComparator(Comparator comparator) {} -} diff --git a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java b/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java deleted file mode 100644 index 2533138..0000000 --- a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) 2008 Sonatype, Inc. All rights reserved. - -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. -You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. -*/ - -package org.codehaus.plexus.build.test; - -import java.util.Map; - -import org.codehaus.plexus.build.DefaultBuildContext; - -public class TestFullBuildContext extends DefaultBuildContext { - - private final Map context; - - public TestFullBuildContext(Map context) { - this.context = context; - } - - public void setValue(String key, Object value) { - context.put(key, value); - } -} diff --git a/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java b/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java deleted file mode 100644 index 3dedd24..0000000 --- a/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java +++ /dev/null @@ -1,199 +0,0 @@ -/* -Copyright (c) 2008 Sonatype, Inc. All rights reserved. - -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. -You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. -*/ - -package org.codehaus.plexus.build.test; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.codehaus.plexus.build.BuildContext; -import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.Scanner; - -public class TestIncrementalBuildContext implements BuildContext { - - private final File basedir; - - private final Set refresh = new HashSet<>(); - - private static final class TestScanner implements Scanner { - private final File basedir; - private final Set files; - - private TestScanner(File basedir, Set files) { - this.basedir = basedir; - this.files = files; - } - - public void addDefaultExcludes() {} - - public String[] getIncludedDirectories() { - return new String[0]; - } - - public String[] getIncludedFiles() { - return (String[]) files.toArray(new String[0]); - } - - public void scan() {} - - public void setExcludes(String[] excludes) {} - - public void setIncludes(String[] includes) {} - - public File getBasedir() { - return basedir; - } - - @Override - public void setFilenameComparator(Comparator filenameComparator) {} - } - - private final Set changedFiles; - - private final Set deletedFiles; - - private final Map context; - - private final List warnings; - - private final List errors; - - public TestIncrementalBuildContext(File basedir, Set changedFiles, Map context) { - this(basedir, changedFiles, new HashSet(), context); - } - - public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context) { - this(basedir, changedFiles, deletedFiles, context, new ArrayList(), new ArrayList()); - } - - public TestIncrementalBuildContext( - File basedir, Set changedFiles, Set deletedFiles, Map context, List warnings, List errors) { - this.basedir = basedir; - this.changedFiles = changedFiles; - this.deletedFiles = deletedFiles; - this.context = context; - this.warnings = warnings; - this.errors = errors; - } - - public boolean hasDelta(String relpath) { - String basepath = basedir.getAbsolutePath(); - - if (relpath.startsWith(basepath)) { - relpath = relpath.substring(basepath.length() + 1); - } - - return changedFiles.contains(relpath) || deletedFiles.contains(relpath); - } - - public boolean hasDelta(List relpaths) { - for (Iterator i = relpaths.iterator(); i.hasNext(); ) { - String relpath = i.next(); - if (hasDelta(relpath)) { - return true; - } - } - return false; - } - - public boolean hasDelta(File file) { - String relpath = getRelpath(file); - return relpath == null || hasDelta(relpath); - } - - private String getRelpath(File file) { - try { - String path = file.getCanonicalPath(); - String basepath = basedir.getCanonicalPath(); - if (path.startsWith(basepath) && !path.equals(basepath)) { - return path.substring(basepath.length()); - } else { - return null; - } - } catch (IOException e) { - // this is a test implementation, we can be little loose here - throw new IllegalArgumentException(e); - } - } - - public boolean isIncremental() { - return true; - } - - public Scanner newDeleteScanner(File basedir) { - return new TestScanner(basedir, deletedFiles); - } - - public OutputStream newFileOutputStream(File file) throws IOException { - refresh(file); - return new FileOutputStream(file); - } - - public Scanner newScanner(final File basedir) { - return new TestScanner(basedir, changedFiles); - } - - public Scanner newScanner(File basedir, boolean ignoreDelta) { - if (ignoreDelta) { - DirectoryScanner directoryScanner = new DirectoryScanner(); - directoryScanner.setBasedir(basedir); - return directoryScanner; - } - - return newScanner(basedir); - } - - public void refresh(File file) { - refresh.add(file.getAbsoluteFile()); - } - - public Object getValue(String key) { - return context.get(key); - } - - public void setValue(String key, Object value) { - context.put(key, value); - } - - public Set getRefreshFiles() { - return refresh; - } - - public void addError(File file, int line, int column, String message, Throwable cause) {} - - public void addWarning(File file, int line, int column, String message, Throwable cause) {} - - public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {} - - public void removeMessages(File file) {} - - public boolean isUptodate(File target, File source) { - return target != null - && target.exists() - && !hasDelta(target) - && source != null - && source.exists() - && !hasDelta(source) - && target.lastModified() > source.lastModified(); - } -} From 903ed6c3e9dc767da4f9ac6cf5a22f0324400bbf Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 2 Jun 2023 10:03:14 +0200 Subject: [PATCH 20/42] [maven-release-plugin] prepare release plexus-build-api-1.2.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d8f3457..34360b9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,12 @@ See the Apache License Version 2.0 for the specific language governing permissio plexus-build-api - 1.1.1-SNAPSHOT + 1.2.0 scm:git:https://github.com/codehaus-plexus/plexus-build-api.git ${project.scm.connection} - master + plexus-build-api-1.2.0 https://github.com/codehaus-plexus/plexus-build-api/tree/master From db22fbfbd98a8ae30c05fcc619cc74f0ee25279e Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 2 Jun 2023 10:03:17 +0200 Subject: [PATCH 21/42] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 34360b9..9ab69bb 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,12 @@ See the Apache License Version 2.0 for the specific language governing permissio plexus-build-api - 1.2.0 + 1.2.1-SNAPSHOT scm:git:https://github.com/codehaus-plexus/plexus-build-api.git ${project.scm.connection} - plexus-build-api-1.2.0 + master https://github.com/codehaus-plexus/plexus-build-api/tree/master From 3d46b7a8c6cce2ac900f41910161fd2d8c7e0045 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Jun 2023 02:58:08 +0000 Subject: [PATCH 22/42] Bump maven-surefire-plugin from 3.1.0 to 3.1.2 Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.0 to 3.1.2. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.0...surefire-3.1.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9ab69bb..0d4c7b7 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.apache.maven.plugins maven-surefire-plugin - 3.1.0 + 3.1.2 true From 2098dfd2633ff450714b114717d35de7f3ffa0a4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 02:52:46 +0000 Subject: [PATCH 23/42] Bump org.codehaus.plexus:plexus from 13 to 14 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 13 to 14. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0d4c7b7..c2b9e39 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 13 + 14 plexus-build-api From 62478dbf48bf812963818ad946ff9491f9cc655a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 02:32:52 +0000 Subject: [PATCH 24/42] Bump org.codehaus.plexus:plexus from 14 to 15 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 14 to 15. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c2b9e39..aff7274 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 14 + 15 plexus-build-api From d7055dc45530a679b8f1ff62c0aa5562101d40a7 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Wed, 4 Oct 2023 18:57:40 +0200 Subject: [PATCH 25/42] Cleanup after pom update --- pom.xml | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index aff7274..83c4112 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ See the Apache License Version 2.0 for the specific language governing permissio slf4j-api 1.7.36 - + org.sonatype.plexus plexus-build-api @@ -83,29 +83,10 @@ See the Apache License Version 2.0 for the specific language governing permissio org.eclipse.sisu sisu-maven-plugin - 0.9.0.M2 - - - index-project - - main-index - test-index - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - org.apache.maven.plugins maven-surefire-plugin - 3.1.2 true From 959ebc999e23a0474dff4f72e5cf8ced6df4fce3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Dec 2023 02:36:30 +0000 Subject: [PATCH 26/42] Bump org.codehaus.plexus:plexus from 15 to 16 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 15 to 16. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 83c4112..6ecef5d 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 15 + 16 plexus-build-api From 48fe7eab8d45fd96264f043d4963c6613075ef99 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 02:52:03 +0000 Subject: [PATCH 27/42] Bump release-drafter/release-drafter from 5 to 6 Bumps [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) from 5 to 6. - [Release notes](https://github.com/release-drafter/release-drafter/releases) - [Commits](https://github.com/release-drafter/release-drafter/compare/v5...v6) --- updated-dependencies: - dependency-name: release-drafter/release-drafter dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 4000f8c..4c09c8a 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,6 +7,6 @@ jobs: update_release_draft: runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v5 + - uses: release-drafter/release-drafter@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c1ea4cf8780d234949254475c1feae7a14418ed6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 02:23:20 +0000 Subject: [PATCH 28/42] Bump org.codehaus.plexus:plexus from 16 to 17 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 16 to 17. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6ecef5d..02114dc 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 16 + 17 plexus-build-api From 178a7588ce24e5712b99d72d862ca49605207da4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 02:31:24 +0000 Subject: [PATCH 29/42] Bump org.codehaus.plexus:plexus-utils from 4.0.0 to 4.0.1 Bumps [org.codehaus.plexus:plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-4.0.0...plexus-utils-4.0.1) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 02114dc..d623c70 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus-utils - 4.0.0 + 4.0.1 javax.inject From a6af31164f4732fd1216c049e94c9d6829b6b447 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 May 2024 22:22:29 +0200 Subject: [PATCH 30/42] Bump org.codehaus.plexus:plexus from 17 to 18 (#82) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d623c70..4b90986 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 17 + 18 plexus-build-api From 1d79201aed2fa2d9ef102d8c0e18a7000cc2b140 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 02:02:51 +0000 Subject: [PATCH 31/42] Bump org.eclipse.sisu:org.eclipse.sisu.plexus from 0.9.0.M2 to 0.9.0.M3 Bumps [org.eclipse.sisu:org.eclipse.sisu.plexus](https://github.com/eclipse/sisu.inject) from 0.9.0.M2 to 0.9.0.M3. - [Release notes](https://github.com/eclipse/sisu.inject/releases) - [Changelog](https://github.com/eclipse-sisu/sisu-project/blob/main/RELEASE.md) - [Commits](https://github.com/eclipse/sisu.inject/compare/milestones/0.9.0.M2...milestones/0.9.0.M3) --- updated-dependencies: - dependency-name: org.eclipse.sisu:org.eclipse.sisu.plexus dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4b90986..0d45c93 100644 --- a/pom.xml +++ b/pom.xml @@ -61,7 +61,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.eclipse.sisu org.eclipse.sisu.plexus - 0.9.0.M2 + 0.9.0.M3 * From 745367c774c2d77f9c858e701cec39bd1d5ce02c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 02:41:01 +0000 Subject: [PATCH 32/42] Bump org.codehaus.plexus:plexus-utils from 4.0.1 to 4.0.2 Bumps [org.codehaus.plexus:plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 4.0.1 to 4.0.2. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-4.0.1...plexus-utils-4.0.2) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0d45c93..bb66ecc 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus-utils - 4.0.1 + 4.0.2 javax.inject From 827c422448580fdb8bad178c5d90e00790113dda Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2024 02:08:02 +0000 Subject: [PATCH 33/42] Bump org.codehaus.plexus:plexus from 18 to 19 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 18 to 19. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bb66ecc..94fb9a8 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 18 + 19 plexus-build-api From 747f1d5b4ac601bb448626d983adfa5c51d79dce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2025 02:15:02 +0000 Subject: [PATCH 34/42] Bump org.codehaus.plexus:plexus from 19 to 20 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 19 to 20. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 94fb9a8..f332246 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 19 + 20 plexus-build-api From b4dbb226b5db365aa13c5aeaf4890ed2d29e6345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 22 Feb 2025 05:39:53 +0100 Subject: [PATCH 35/42] Add a connect API for inter-process-communication between maven and IDE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently an IDE launching an external maven process is rather blind, it can only see if the process exit with success and maybe read the standard stream. A much more feature rich experience could been offered if the launching process can gather some information about the run, e.g. what process is currently executed, what mojo and if it failed. Also currently features of the build context can only be implemented if running inside the IDE process what has several implications. This now adds a connect API that allows an IDE to supply an extension to the maven process (e.g. via maven.ext.class.path) and set a system property (plexus.build.ipc.port) to communicate with the running maven process. Signed-off-by: Christoph Läubrich --- README.md | 14 +- pom.xml | 6 + .../plexus/build/DefaultBuildContext.java | 14 +- .../plexus/build/connect/BuildConnection.java | 50 ++++ .../plexus/build/connect/Configuration.java | 51 ++++ .../plexus/build/connect/SessionListener.java | 65 ++++ .../build/connect/TcpBuildConnection.java | 281 ++++++++++++++++++ .../build/connect/messages/Message.java | 226 ++++++++++++++ .../connect/messages/ProjectsReadMessage.java | 63 ++++ .../connect/messages/RefreshMessage.java | 47 +++ .../connect/messages/SessionMessage.java | 90 ++++++ .../resources/META-INF/maven/extension.xml | 11 + 12 files changed, 910 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/Configuration.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/SessionListener.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/Message.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/RefreshMessage.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java create mode 100644 src/main/resources/META-INF/maven/extension.xml diff --git a/README.md b/README.md index 6af0dde..1789d9f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ Plexus Build API -======================= +================ [![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/codehaus-plexus/plexus-classworlds.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) @@ -13,9 +13,8 @@ It supports - fine-grained error/info markers (referring to specific files in particular line numbers) - notifications about updated files - Current Implementations ------ +----------------------- ### Default Implementation @@ -27,6 +26,13 @@ The default implementation shipping with this artifact is supposed to impose min Currently only versions up to 0.0.7 (with old Maven coordinates `org.sonatype.plexus:plexus-build-api`) are supported, this limitation is tracked in [Issue 944](https://github.com/eclipse-m2e/m2e-core/issues/944). History ------ +------- The project was relocated from . Also its Maven coordinates changed from `org.sonatype.plexus:plexus-build-api` to `org.codehaus.plexus:plexus-build-api`, the API is still the same, though. + +## Provided APIs + +### IDE connection to 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. diff --git a/pom.xml b/pom.xml index f332246..15a4f4c 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,12 @@ See the Apache License Version 2.0 for the specific language governing permissio + + org.apache.maven + maven-core + 3.9.9 + provided + diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java index 7fb0da6..797079e 100644 --- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.codehaus.plexus.build.connect.BuildConnection; +import org.codehaus.plexus.build.connect.messages.RefreshMessage; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.Scanner; import org.codehaus.plexus.util.io.CachingOutputStream; @@ -56,15 +58,18 @@ public class DefaultBuildContext implements BuildContext { private final Map contextMap = new ConcurrentHashMap<>(); private org.sonatype.plexus.build.incremental.BuildContext legacy; + private BuildConnection connection; /** - * @param legacy the legacy API we delegate to by default, this allow us to - * support "older" plugins and implementors of the API while still - * having a way to move forward! + * @param legacy the legacy API we delegate to by default, this allow us to + * support "older" plugins and implementors of the API while + * still having a way to move forward! + * @param connection the connection we use to forward refresh events */ @Inject - public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy) { + public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy, BuildConnection connection) { this.legacy = legacy; + this.connection = connection; } /** {@inheritDoc} */ @@ -117,6 +122,7 @@ public Scanner newScanner(File basedir) { /** {@inheritDoc} */ public void refresh(File file) { legacy.refresh(file); + connection.send(new RefreshMessage(file.toPath())); } /** {@inheritDoc} */ diff --git a/src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java b/src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java new file mode 100644 index 0000000..f2b83df --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java @@ -0,0 +1,50 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect; + +import org.codehaus.plexus.build.connect.messages.Message; + +/** + * A {@link BuildConnection} allow communication between a an IDE and a maven + * build to observe the state of the build and act on certain events. This is + * usually not used directly by mojos but invoked internally by other APIs. + */ +public interface BuildConnection { + + /** + * Send a message and returns the reply from the other endpoint, should only be + * called from a maven thread! + * + * @param message the message to send + * @return the reply message or null if this connection is not + * enabled and the message was discarded. + */ + Message send(Message message); + + /** + * This method allows code to perform an eager check if a buildconnection is + * present to send messages. This can be used to guard operations to prevent + * allocate resources or objects if the message will be dropped. + * + * @return true if the connection can be used to send messages or + * if they will be discarded + */ + boolean isEnabled(); + + /** + * Obtains the current configuration, can only be called from a maven thread + * + * @return the active configuration + */ + Configuration getConfiguration(); +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/Configuration.java b/src/main/java/org/codehaus/plexus/build/connect/Configuration.java new file mode 100644 index 0000000..c467b36 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/Configuration.java @@ -0,0 +1,51 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect; + +import org.codehaus.plexus.build.connect.messages.Message; +import org.codehaus.plexus.build.connect.messages.ProjectsReadMessage; + +/** + * Provides access to the configuration provided by the server + */ +public interface Configuration { + + /** + * If this property is set to true in reply to a session start, a + * {@link ProjectsReadMessage} will be send to the endpoint containing all + * projects with their effective model + */ + public static final String CONFIG_SEND_AFTER_PROJECTS_READ = "afterProjectsRead"; + + /** + * @return true if {@link #CONFIG_SEND_AFTER_PROJECTS_READ} is + * provided + */ + public boolean isSendProjects(); + + /** + * Creates a Configuration from a message + * + * @param message + * @return the configuration backed by the message payload + */ + public static Configuration of(Message message) { + return new Configuration() { + + @Override + public boolean isSendProjects() { + return message.getBooleanProperty(CONFIG_SEND_AFTER_PROJECTS_READ, false); + } + }; + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/SessionListener.java b/src/main/java/org/codehaus/plexus/build/connect/SessionListener.java new file mode 100644 index 0000000..c8cea4c --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/SessionListener.java @@ -0,0 +1,65 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.AbstractMavenLifecycleParticipant; +import org.apache.maven.MavenExecutionException; +import org.apache.maven.execution.MavenSession; +import org.codehaus.plexus.build.connect.messages.Message; +import org.codehaus.plexus.build.connect.messages.ProjectsReadMessage; +import org.codehaus.plexus.build.connect.messages.SessionMessage; + +/** + * Listen to session events and send them to the connection + */ +@Named +@Singleton +public class SessionListener extends AbstractMavenLifecycleParticipant { + + @Inject + private BuildConnection connection; + + private boolean sendProjects; + private boolean started; + + @Override + public void afterSessionStart(MavenSession session) throws MavenExecutionException { + started = true; + Message reply = connection.send(new SessionMessage(session, true)); + if (reply != null) { + sendProjects = Configuration.of(reply).isSendProjects(); + } + } + + @Override + public void afterProjectsRead(MavenSession session) throws MavenExecutionException { + if (connection.isEnabled()) { + if (!started) { + afterSessionStart(session); + } + if (sendProjects) { + connection.send(new ProjectsReadMessage(session.getAllProjects())); + } + } + } + + @Override + public void afterSessionEnd(MavenSession session) throws MavenExecutionException { + connection.send(new SessionMessage(session, false)); + started = false; + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java b/src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java new file mode 100644 index 0000000..b9b1a95 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java @@ -0,0 +1,281 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.Closeable; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.BiConsumer; +import java.util.function.Function; + +import org.apache.maven.plugin.LegacySupport; +import org.codehaus.plexus.build.connect.messages.Message; +import org.codehaus.plexus.build.connect.messages.SessionMessage; + +/** + * Default implementation using the system property + * plexus.build.ipc.port to communicate with an endpoint to + * exchange messages + */ +@Named("default") +@Singleton +public class TcpBuildConnection implements BuildConnection { + private static final String PLEXUS_BUILD_IPC_PORT = "plexus.build.ipc.port"; + + private static final int PORT = Integer.getInteger(PLEXUS_BUILD_IPC_PORT, 0); + + @Inject + private LegacySupport support; + + private Map configMap = new ConcurrentHashMap<>(); + + private final ThreadLocal connections = + ThreadLocal.withInitial(() -> new TcpClientConnection()); + + @Override + public boolean isEnabled() { + return PORT > 0; + } + + @Override + public Message send(Message message) { + if (isEnabled()) { + String sessionId; + boolean sessionStart; + if (message instanceof SessionMessage) { + sessionId = message.getSessionId(); + sessionStart = ((SessionMessage) message).isSessionStart(); + } else { + sessionId = getThreadSessionId(); + sessionStart = false; + } + byte[] messageBytes = message.serialize(sessionId); + byte[] replyBytes = connections.get().send(messageBytes); + if (replyBytes.length > 0) { + Message reply = Message.decode(replyBytes); + if (reply != null && sessionStart) { + configMap.put(sessionId, Configuration.of(reply)); + } + return reply; + } + } + return null; + } + + private String getThreadSessionId() { + // We must use LegacySupport here to get the currents threads session (what + // might be cloned) + return SessionMessage.getId(support.getSession()); + } + + @Override + public Configuration getConfiguration() { + String id = getThreadSessionId(); + if (id == null) { + throw new IllegalStateException("No session attached to current thread!"); + } + Configuration configuration = configMap.get(id); + if (configuration == null) { + throw new IllegalStateException("No configuration active for session " + id + "!"); + } + return configuration; + } + + /** + * Creates a new server that will receive messages from a remote endpoint and + * inform the consumer + * + * @param consumer the consumer of messages, might be called by different + * threads, if the consumer throws an exception while handling a + * message it will maybe no longer receive some messages. The + * returned map is used as a payload for the reply to the + * server, if null is returned a simple + * acknowledgement without any payload will be send to the + * endpoint. If the consumer performs blocking operations the + * further execution of the maven process might be halted + * depending on the message type, if that is not desired work + * should be offloaded by the consumer to a different thread. + * @return a {@link ServerConnection} that can be used to shutdown the server + * and get properties that needs to be passed to the maven process + * @throws IOException if no local socket can be opened + */ + public static ServerConnection createServer(Function> consumer) throws IOException { + return new ServerConnection(new ServerSocket(0), consumer); + } + + /** + * Represents a server connection that must be created to communicate with the + * maven process using the {@link TcpBuildConnection} + */ + public static final class ServerConnection implements AutoCloseable { + + private ServerSocket socket; + private ExecutorService executor = Executors.newCachedThreadPool(); + private List connections = new ArrayList<>(); + + ServerConnection(ServerSocket socket, Function> consumer) { + this.socket = socket; + executor.execute(() -> { + while (!Thread.currentThread().isInterrupted()) { + try { + TcpServerConnection connection = new TcpServerConnection(socket.accept(), consumer); + connections.add(connection); + executor.execute(connection); + } catch (IOException e) { + return; + } + } + }); + } + + @Override + public void close() { + executor.shutdownNow(); + for (TcpServerConnection connection : connections) { + connection.close(); + } + try { + socket.close(); + } catch (IOException e) { + } + } + + /** + * Given a consumer publishes required properties for a process to launch + * + * @param consumer the consumer for system properties + */ + public void setupProcess(BiConsumer consumer) { + // currently only one but might become more later (e.g. timeout, reconnects, + // ...) + consumer.accept(PLEXUS_BUILD_IPC_PORT, Integer.toString(socket.getLocalPort())); + } + } + + private static final class TcpServerConnection implements Runnable, Closeable { + + private Socket socket; + private Function> consumer; + private DataInputStream in; + private DataOutputStream out; + private AtomicBoolean closed = new AtomicBoolean(); + + public TcpServerConnection(Socket socket, Function> consumer) throws IOException { + this.socket = socket; + this.consumer = consumer; + in = new DataInputStream(socket.getInputStream()); + out = new DataOutputStream(socket.getOutputStream()); + } + + @Override + public void run() { + try { + while (!closed.get() && !Thread.currentThread().isInterrupted()) { + try { + int length = in.readInt(); + if (length == 0) { + return; + } + byte[] bytes = new byte[length]; + in.readFully(bytes); + Message message = Message.decode(bytes); + Map payload = consumer.apply(message); + Message reply = Message.replyTo(message, payload); + byte[] responseBytes = reply.serialize(); + synchronized (out) { + out.writeInt(responseBytes.length); + out.write(responseBytes); + out.flush(); + } + } catch (Exception e) { + return; + } + } + } finally { + close(); + } + } + + @Override + public void close() { + if (closed.compareAndSet(false, true)) { + try { + synchronized (out) { + out.writeInt(0); + out.flush(); + } + } catch (IOException e) { + } + try { + socket.close(); + } catch (IOException e) { + } + } + } + } + + private static final class TcpClientConnection { + + private Socket socket; + private boolean closed; + private DataInputStream in; + private DataOutputStream out; + + public byte[] send(byte[] messageBytes) { + if (!closed) { + try { + if (socket == null) { + socket = new Socket("localhost", PORT); + in = new DataInputStream(socket.getInputStream()); + out = new DataOutputStream(socket.getOutputStream()); + } + out.writeInt(messageBytes.length); + out.write(messageBytes); + out.flush(); + int length = in.readInt(); + if (length == 0) { + socket.close(); + closed = true; + } else { + byte[] bytes = new byte[length]; + in.readFully(bytes); + return bytes; + } + } catch (IOException e) { + closed = true; + if (socket != null) { + try { + socket.close(); + } catch (IOException e1) { + } + } + } + } + return new byte[0]; + } + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java b/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java new file mode 100644 index 0000000..af47e5d --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java @@ -0,0 +1,226 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; + +/** + * A message exchanged between two endpoints, usually an IDE and a maven build + */ +public class Message { + private static final ThreadLocal ID = new ThreadLocal() { + private final AtomicLong generator = new AtomicLong(); + + @Override + protected Long initialValue() { + return generator.getAndIncrement(); + } + }; + private final long threadId; + private final Map properties; + private final String sessionId; + + Message(Map payload) { + this(null, ID.get(), payload); + } + + Message(String sessionId, long threadId, Map payload) { + this.sessionId = sessionId; + this.properties = Objects.requireNonNull(payload); + this.threadId = threadId; + } + + /** + * Get a String property from the payload + * + * @param key the key to fetch + * @return the value + */ + public String getProperty(String key) { + return properties.get(key); + } + + /** + * Get a String property from the payload + * + * @param key the key to fetch + * @param defaultValue default value to use when no value is present + * @return the value + */ + public String getProperty(String key, String defaultValue) { + return properties.getOrDefault(key, defaultValue); + } + + /** + * Get a boolean property from the payload + * + * @param key the key to fetch + * @return the value + */ + public boolean getBooleanProperty(String key) { + return Boolean.parseBoolean(properties.get(key)); + } + + /** + * Get a boolean property from the payload + * + * @param key the key to fetch + * @param defaultValue the value to use if not value is present + * @return the value + */ + public boolean getBooleanProperty(String key, boolean defaultValue) { + String property = getProperty(key); + if (property == null) { + return defaultValue; + } + return Boolean.parseBoolean(property); + } + + /** + * @return the remote session id for this message, only valid for messages not + * created locally + */ + public String getSessionId() { + if (sessionId == null) { + throw new IllegalStateException("can not be called on a local message!"); + } + return sessionId; + } + + /** + * @return the bytes using the message session id + */ + public byte[] serialize() { + return serialize(getSessionId()); + } + + @Override + public String toString() { + return getClass().getSimpleName() + " [" + sessionId + "][" + threadId + "] " + properties; + } + + /** + * Creates bytes for this message using the session id + * + * @param sessionId + * @return the bytes using the supplied message id + */ + public byte[] serialize(String sessionId) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(stream); + try { + writeString(sessionId, out); + out.writeLong(threadId); + writeString(getClass().getSimpleName(), out); + if (properties.isEmpty()) { + out.writeInt(0); + } else { + Set> set = properties.entrySet(); + out.writeInt(set.size()); + for (Entry entry : set) { + writeString(entry.getKey(), out); + writeString(entry.getValue(), out); + } + } + } catch (IOException e) { + // should never happen, but if it happens something is wrong! + throw new RuntimeException("Internal Error: Write data failed", e); + } + return stream.toByteArray(); + } + + /** + * Creates a reply to a message using the thread id and session id from the + * original but with the provided payload + * + * @param message the reply message to inherit from + * @param payload the new payload + * @return the message + */ + public static Message replyTo(Message message, Map payload) { + if (payload == null) { + payload = Collections.emptyMap(); + } + return new Message(message.sessionId, message.threadId, payload); + } + + /** + * Decodes a message from its bytes + * + * @param bytes the bytes to decode + * @return the message or null if decoding failed + */ + public static Message decode(byte[] bytes) { + ByteArrayInputStream stream = new ByteArrayInputStream(bytes); + DataInputStream in = new DataInputStream(stream); + try { + String sessionId = readString(in); + long threadId = in.readLong(); + String messageType = readString(in); + int size = in.readInt(); + Map payload = new LinkedHashMap<>(size); + for (int i = 0; i < size; i++) { + payload.put(readString(in), readString(in)); + } + if ("SessionMessage".equals(messageType)) { + return new SessionMessage(sessionId, threadId, payload); + } + if ("ProjectsReadMessage".equals(messageType)) { + return new ProjectsReadMessage(sessionId, threadId, payload); + } + if ("RefreshMessage".equals(messageType)) { + return new RefreshMessage(sessionId, threadId, payload); + } + return new Message(sessionId, threadId, payload); + } catch (IOException e) { + // should never happen, but if it happens something is wrong! + System.err.println("Internal Error: Message decoding failed: " + e); + } + return null; + } + + private static String readString(DataInputStream in) throws IOException { + int length = in.readInt(); + if (length < 0) { + return null; + } + if (length == 0) { + return ""; + } + byte[] bs = new byte[length]; + in.readFully(bs); + return new String(bs, StandardCharsets.UTF_8); + } + + private static void writeString(String string, DataOutputStream stream) throws IOException { + if (string == null) { + stream.writeInt(-1); + } else { + byte[] bytes = string.getBytes(StandardCharsets.UTF_8); + stream.writeInt(bytes.length); + stream.write(bytes); + } + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java new file mode 100644 index 0000000..91825ef --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java @@ -0,0 +1,63 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.DefaultModelWriter; +import org.apache.maven.project.MavenProject; + +/** + * Message send to inform about reactor project in the build and their effective + * model + */ +public class ProjectsReadMessage extends Message { + + private static final DefaultModelWriter MODEL_WRITER = new DefaultModelWriter(); + + ProjectsReadMessage(String sessionId, long threadId, Map payload) { + super(sessionId, threadId, payload); + } + + /** + * @param projects the projects to send + */ + public ProjectsReadMessage(Collection projects) { + super(buildMap(projects)); + } + + private static Map buildMap(Collection projects) { + Map map = new HashMap<>(); + for (MavenProject project : projects) { + String key = project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion(); + map.put(key, getEffectiveModel(project)); + } + return map; + } + + private static String getEffectiveModel(MavenProject project) { + Model model = project.getModel(); + StringWriter writer = new StringWriter(); + try { + MODEL_WRITER.write(writer, null, model); + } catch (IOException e) { + } + String string = writer.toString(); + return string; + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/RefreshMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/RefreshMessage.java new file mode 100644 index 0000000..a473a02 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/RefreshMessage.java @@ -0,0 +1,47 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.io.File; +import java.nio.file.Path; +import java.util.Collections; +import java.util.Map; + +/** + * A message that indicates a path should be refreshed (e.g. because new files + * are placed in a generated folder) + */ +public class RefreshMessage extends Message { + + private static final String PATH_KEY = "path"; + + /** + * Create a new message to refresh a path + * + * @param path the path to refresh + */ + public RefreshMessage(Path path) { + super(Collections.singletonMap(PATH_KEY, path.toFile().getAbsolutePath())); + } + + /** + * @return the path to refresh + */ + public Path getPath() { + return new File(getProperty(PATH_KEY)).toPath(); + } + + RefreshMessage(String sessionId, long threadId, Map payload) { + super(sessionId, threadId, payload); + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java new file mode 100644 index 0000000..f88d906 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java @@ -0,0 +1,90 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.WeakHashMap; + +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; + +/** + * Event that is received / send when a session starts/end + */ +public class SessionMessage extends Message { + + private static final String SESSION_EXECUTION_ROOT_DIRECTORY = "sessionExecutionRootDirectory"; + private static final String SESSION_START = "sessionStart"; + private static final String SESSION_ID = "sessionId"; + private static final Map ID_MAP = new WeakHashMap<>(); + + /** + * Creates a new session message + * + * @param session the session to use + * @param start true if it is a start of the session or + * false if it is the end of a session + */ + public SessionMessage(MavenSession session, boolean start) { + super(buildMap(session, start)); + } + + SessionMessage(String sessionId, long threadId, Map payload) { + super(sessionId, threadId, payload); + } + + public String getSessionId() { + return getProperty(SESSION_ID); + } + + /** + * @return true if this is a session start event + */ + public boolean isSessionStart() { + return getBooleanProperty(SESSION_START); + } + + /** + * @return the value of the ExecutionRootDirectory of this session + */ + public String getExecutionRootDirectory() { + return getProperty(SESSION_EXECUTION_ROOT_DIRECTORY); + } + + /** + * Returns the unique ID for a session + * + * @param session the session to get an Id for + * @return the id of the session or the name of the current thread if the + * session is null + */ + public static synchronized String getId(MavenSession session) { + if (session == null) { + return Thread.currentThread().getName(); + } + // we can't use the session itself as a key, because sessions might be cloned, + // but the execution request should (hopefully) stay constant... + return ID_MAP.computeIfAbsent( + session.getRequest(), x -> UUID.randomUUID().toString()); + } + + private static Map buildMap(MavenSession session, boolean start) { + Map map = new HashMap<>(2); + map.put(SESSION_ID, getId(session)); + map.put(SESSION_START, Boolean.toString(start)); + map.put(SESSION_EXECUTION_ROOT_DIRECTORY, session.getExecutionRootDirectory()); + return map; + } +} diff --git a/src/main/resources/META-INF/maven/extension.xml b/src/main/resources/META-INF/maven/extension.xml new file mode 100644 index 0000000..181a211 --- /dev/null +++ b/src/main/resources/META-INF/maven/extension.xml @@ -0,0 +1,11 @@ + + + + + org.codehaus.plexus.build + + + + org.codehaus.plexus:plexus-build-api + + From 490f7017a924bef847a4de54c168318d6e810035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 22 Feb 2025 15:30:30 +0100 Subject: [PATCH 36/42] Use EventSpy to handle execution of events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we use an AbstractMavenLifecycleParticipant but this only offers limited number of events, an EventSpy is much more flexible and offers much more insights. This now replaces the SessionListener with an EventSpy and also adds support for project execution events. Alongside with that the configuration is now local to the EventListener and no longer part of the connection implementation. Signed-off-by: Christoph Läubrich --- .../plexus/build/DefaultBuildContext.java | 19 ++- .../plexus/build/connect/BuildConnection.java | 13 +- .../plexus/build/connect/Configuration.java | 11 +- .../plexus/build/connect/EventListener.java | 100 ++++++++++++ .../plexus/build/connect/SessionListener.java | 65 -------- .../build/connect/TcpBuildConnection.java | 50 ++---- .../build/connect/messages/InitMessage.java | 34 +++++ .../build/connect/messages/Message.java | 18 ++- .../connect/messages/ProjectMessage.java | 122 +++++++++++++++ .../connect/messages/ProjectsMessage.java | 143 ++++++++++++++++++ .../connect/messages/ProjectsReadMessage.java | 63 -------- .../connect/messages/SessionMessage.java | 27 ---- 12 files changed, 447 insertions(+), 218 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/build/connect/EventListener.java delete mode 100644 src/main/java/org/codehaus/plexus/build/connect/SessionListener.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsMessage.java delete mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java index 797079e..2b34e71 100644 --- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.apache.maven.plugin.LegacySupport; import org.codehaus.plexus.build.connect.BuildConnection; import org.codehaus.plexus.build.connect.messages.RefreshMessage; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -59,17 +60,23 @@ public class DefaultBuildContext implements BuildContext { private final Map contextMap = new ConcurrentHashMap<>(); private org.sonatype.plexus.build.incremental.BuildContext legacy; private BuildConnection connection; + private LegacySupport legacySupport; /** - * @param legacy the legacy API we delegate to by default, this allow us to - * support "older" plugins and implementors of the API while - * still having a way to move forward! - * @param connection the connection we use to forward refresh events + * @param legacy the legacy API we delegate to by default, this allow us + * to support "older" plugins and implementors of the API + * while still having a way to move forward! + * @param connection the connection we use to forward refresh events + * @param legacySupport legacy support to get the current session */ @Inject - public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy, BuildConnection connection) { + public DefaultBuildContext( + org.sonatype.plexus.build.incremental.BuildContext legacy, + BuildConnection connection, + LegacySupport legacySupport) { this.legacy = legacy; this.connection = connection; + this.legacySupport = legacySupport; } /** {@inheritDoc} */ @@ -122,7 +129,7 @@ public Scanner newScanner(File basedir) { /** {@inheritDoc} */ public void refresh(File file) { legacy.refresh(file); - connection.send(new RefreshMessage(file.toPath())); + connection.send(new RefreshMessage(file.toPath()), legacySupport.getSession()); } /** {@inheritDoc} */ diff --git a/src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java b/src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java index f2b83df..921115e 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java +++ b/src/main/java/org/codehaus/plexus/build/connect/BuildConnection.java @@ -12,6 +12,7 @@ */ package org.codehaus.plexus.build.connect; +import org.apache.maven.execution.MavenSession; import org.codehaus.plexus.build.connect.messages.Message; /** @@ -25,11 +26,12 @@ public interface BuildConnection { * Send a message and returns the reply from the other endpoint, should only be * called from a maven thread! * - * @param message the message to send + * @param message the message to send + * @param mavenSession the maven session to reference * @return the reply message or null if this connection is not * enabled and the message was discarded. */ - Message send(Message message); + Message send(Message message, MavenSession mavenSession); /** * This method allows code to perform an eager check if a buildconnection is @@ -40,11 +42,4 @@ public interface BuildConnection { * if they will be discarded */ boolean isEnabled(); - - /** - * Obtains the current configuration, can only be called from a maven thread - * - * @return the active configuration - */ - Configuration getConfiguration(); } diff --git a/src/main/java/org/codehaus/plexus/build/connect/Configuration.java b/src/main/java/org/codehaus/plexus/build/connect/Configuration.java index c467b36..2444145 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/Configuration.java +++ b/src/main/java/org/codehaus/plexus/build/connect/Configuration.java @@ -13,7 +13,6 @@ package org.codehaus.plexus.build.connect; import org.codehaus.plexus.build.connect.messages.Message; -import org.codehaus.plexus.build.connect.messages.ProjectsReadMessage; /** * Provides access to the configuration provided by the server @@ -21,14 +20,12 @@ public interface Configuration { /** - * If this property is set to true in reply to a session start, a - * {@link ProjectsReadMessage} will be send to the endpoint containing all - * projects with their effective model + * If this property is set to true in reply to a InitMessage */ - public static final String CONFIG_SEND_AFTER_PROJECTS_READ = "afterProjectsRead"; + public static final String CONFIG_SEND_PROJECTS = "sendProjectInfos"; /** - * @return true if {@link #CONFIG_SEND_AFTER_PROJECTS_READ} is + * @return true if {@link #CONFIG_SEND_PROJECTS} is * provided */ public boolean isSendProjects(); @@ -44,7 +41,7 @@ public static Configuration of(Message message) { @Override public boolean isSendProjects() { - return message.getBooleanProperty(CONFIG_SEND_AFTER_PROJECTS_READ, false); + return message.getBooleanProperty(CONFIG_SEND_PROJECTS, false); } }; } diff --git a/src/main/java/org/codehaus/plexus/build/connect/EventListener.java b/src/main/java/org/codehaus/plexus/build/connect/EventListener.java new file mode 100644 index 0000000..5806c08 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/EventListener.java @@ -0,0 +1,100 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect; + +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.eventspy.EventSpy; +import org.apache.maven.execution.ExecutionEvent; +import org.apache.maven.execution.ExecutionEvent.Type; +import org.apache.maven.execution.MavenSession; +import org.codehaus.plexus.build.connect.messages.InitMessage; +import org.codehaus.plexus.build.connect.messages.Message; +import org.codehaus.plexus.build.connect.messages.ProjectMessage; +import org.codehaus.plexus.build.connect.messages.ProjectsMessage; +import org.codehaus.plexus.build.connect.messages.SessionMessage; + +/** + * Listen to all maven events and forward them to the endpoint + */ +@Named +@Singleton +public class EventListener implements EventSpy { + + private BuildConnection connection; + private Configuration configuration; + + /** + * Creates endpoint for the given connection + * + * @param connection injected + */ + @Inject + public EventListener(BuildConnection connection) { + this.connection = connection; + } + + @Override + public void init(Context context) throws Exception { + Map data = new LinkedHashMap<>(); + context.getData().forEach((k, v) -> { + data.put(k, String.valueOf(v)); + }); + Message message = connection.send(new InitMessage(data), null); + if (message != null) { + configuration = Configuration.of(message); + } + } + + @Override + public void onEvent(Object event) throws Exception { + if (configuration == null) { + return; + } + if (event instanceof ExecutionEvent) { + handleExecutionEvent((ExecutionEvent) event); + } + } + + private void handleExecutionEvent(ExecutionEvent executionEvent) { + MavenSession session = executionEvent.getSession(); + Type type = executionEvent.getType(); + switch (type) { + case SessionStarted: + connection.send(new SessionMessage(session, true), session); + if (configuration.isSendProjects()) { + connection.send(new ProjectsMessage(session.getProjects()), session); + } + break; + case SessionEnded: + connection.send(new SessionMessage(session, false), session); + break; + case ProjectStarted: + case ProjectFailed: + case ProjectSkipped: + case ProjectSucceeded: + connection.send(new ProjectMessage(executionEvent.getProject(), type), session); + break; + default: + break; + } + } + + @Override + public void close() throws Exception {} +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/SessionListener.java b/src/main/java/org/codehaus/plexus/build/connect/SessionListener.java deleted file mode 100644 index c8cea4c..0000000 --- a/src/main/java/org/codehaus/plexus/build/connect/SessionListener.java +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright (c) 2025 Christoph Läubrich All rights reserved. - -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. -You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. -*/ -package org.codehaus.plexus.build.connect; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.AbstractMavenLifecycleParticipant; -import org.apache.maven.MavenExecutionException; -import org.apache.maven.execution.MavenSession; -import org.codehaus.plexus.build.connect.messages.Message; -import org.codehaus.plexus.build.connect.messages.ProjectsReadMessage; -import org.codehaus.plexus.build.connect.messages.SessionMessage; - -/** - * Listen to session events and send them to the connection - */ -@Named -@Singleton -public class SessionListener extends AbstractMavenLifecycleParticipant { - - @Inject - private BuildConnection connection; - - private boolean sendProjects; - private boolean started; - - @Override - public void afterSessionStart(MavenSession session) throws MavenExecutionException { - started = true; - Message reply = connection.send(new SessionMessage(session, true)); - if (reply != null) { - sendProjects = Configuration.of(reply).isSendProjects(); - } - } - - @Override - public void afterProjectsRead(MavenSession session) throws MavenExecutionException { - if (connection.isEnabled()) { - if (!started) { - afterSessionStart(session); - } - if (sendProjects) { - connection.send(new ProjectsReadMessage(session.getAllProjects())); - } - } - } - - @Override - public void afterSessionEnd(MavenSession session) throws MavenExecutionException { - connection.send(new SessionMessage(session, false)); - started = false; - } -} diff --git a/src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java b/src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java index b9b1a95..339487e 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java +++ b/src/main/java/org/codehaus/plexus/build/connect/TcpBuildConnection.java @@ -12,7 +12,6 @@ */ package org.codehaus.plexus.build.connect; -import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -25,16 +24,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import java.util.UUID; +import java.util.WeakHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiConsumer; import java.util.function.Function; -import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.execution.MavenSession; import org.codehaus.plexus.build.connect.messages.Message; -import org.codehaus.plexus.build.connect.messages.SessionMessage; /** * Default implementation using the system property @@ -48,10 +47,7 @@ public class TcpBuildConnection implements BuildConnection { private static final int PORT = Integer.getInteger(PLEXUS_BUILD_IPC_PORT, 0); - @Inject - private LegacySupport support; - - private Map configMap = new ConcurrentHashMap<>(); + private final Map sessionMap = new WeakHashMap<>(); private final ThreadLocal connections = ThreadLocal.withInitial(() -> new TcpClientConnection()); @@ -62,47 +58,23 @@ public boolean isEnabled() { } @Override - public Message send(Message message) { + public Message send(Message message, MavenSession mavenSession) { if (isEnabled()) { - String sessionId; - boolean sessionStart; - if (message instanceof SessionMessage) { - sessionId = message.getSessionId(); - sessionStart = ((SessionMessage) message).isSessionStart(); - } else { - sessionId = getThreadSessionId(); - sessionStart = false; - } + String sessionId = getId(mavenSession); byte[] messageBytes = message.serialize(sessionId); byte[] replyBytes = connections.get().send(messageBytes); if (replyBytes.length > 0) { - Message reply = Message.decode(replyBytes); - if (reply != null && sessionStart) { - configMap.put(sessionId, Configuration.of(reply)); - } - return reply; + return Message.decode(replyBytes); } } return null; } - private String getThreadSessionId() { - // We must use LegacySupport here to get the currents threads session (what - // might be cloned) - return SessionMessage.getId(support.getSession()); - } - - @Override - public Configuration getConfiguration() { - String id = getThreadSessionId(); - if (id == null) { - throw new IllegalStateException("No session attached to current thread!"); - } - Configuration configuration = configMap.get(id); - if (configuration == null) { - throw new IllegalStateException("No configuration active for session " + id + "!"); + private synchronized String getId(MavenSession session) { + if (session == null) { + return Thread.currentThread().getName(); } - return configuration; + return sessionMap.computeIfAbsent(session, x -> UUID.randomUUID().toString()); } /** diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java new file mode 100644 index 0000000..7239b92 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java @@ -0,0 +1,34 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.util.Map; + +/** + * Message send to init the inital communication with the endpoints + */ +public class InitMessage extends Message { + + /** + * Creates a message with inital information about the running maven system + * + * @param settings the context settings to send to the endpoint + */ + public InitMessage(Map settings) { + super(settings); + } + + InitMessage(String sessionId, long threadId, Map payload) { + super(sessionId, threadId, payload); + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java b/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java index af47e5d..4400f22 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java @@ -25,6 +25,7 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Stream; /** * A message exchanged between two endpoints, usually an IDE and a maven build @@ -52,6 +53,13 @@ protected Long initialValue() { this.threadId = threadId; } + /** + * @return the keys stored in this message + */ + public Stream keys() { + return properties.keySet().stream(); + } + /** * Get a String property from the payload * @@ -187,12 +195,18 @@ public static Message decode(byte[] bytes) { if ("SessionMessage".equals(messageType)) { return new SessionMessage(sessionId, threadId, payload); } - if ("ProjectsReadMessage".equals(messageType)) { - return new ProjectsReadMessage(sessionId, threadId, payload); + if ("ProjectsMessage".equals(messageType)) { + return new ProjectsMessage(sessionId, threadId, payload); } if ("RefreshMessage".equals(messageType)) { return new RefreshMessage(sessionId, threadId, payload); } + if ("InitMessage".equals(messageType)) { + return new InitMessage(sessionId, threadId, payload); + } + if ("ProjectMessage".equals(messageType)) { + return new ProjectMessage(sessionId, threadId, payload); + } return new Message(sessionId, threadId, payload); } catch (IOException e) { // should never happen, but if it happens something is wrong! diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java new file mode 100644 index 0000000..68a30fd --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java @@ -0,0 +1,122 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.io.File; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.apache.maven.execution.ExecutionEvent.Type; +import org.apache.maven.project.MavenProject; + +/** + * Send to inform about project changes + */ +public class ProjectMessage extends Message { + + private static final String BASE_DIR = "baseDir"; + private static final String VERSION = "version"; + private static final String ARTIFACT_ID = "artifactId"; + private static final String GROUP_ID = "groupId"; + private static final String EVENT_TYPE = "eventType"; + + ProjectMessage(String sessionId, long threadId, Map payload) { + super(sessionId, threadId, payload); + } + + /** + * Constructs a new event based on project and type + * + * @param mavenProject + * @param eventtype + */ + public ProjectMessage(MavenProject mavenProject, Type eventtype) { + super(toMap(mavenProject, eventtype)); + } + + /** + * @return the group id of the project + */ + public String getGroupId() { + return getProperty(GROUP_ID); + } + + /** + * @return the artifact id of the project + */ + public String getArtifactId() { + return getProperty(ARTIFACT_ID); + } + + /** + * @return the version of the project + */ + public String getVersion() { + return getProperty(ARTIFACT_ID); + } + + /** + * @return the basedir of the project + */ + public Path getBaseDir() { + return new File(getProperty(BASE_DIR)).toPath(); + } + + /** + * @return the type of the event + */ + public EventType getType() { + try { + return EventType.valueOf(getProperty(EVENT_TYPE)); + } catch (RuntimeException e) { + return EventType.Unknown; + } + } + + private static Map toMap(MavenProject mavenProject, Type eventtype) { + Map map = new HashMap<>(); + map.put(EVENT_TYPE, eventtype.name()); + map.put(GROUP_ID, mavenProject.getGroupId()); + map.put(ARTIFACT_ID, mavenProject.getArtifactId()); + map.put(VERSION, mavenProject.getVersion()); + map.put(BASE_DIR, mavenProject.getBasedir().getAbsolutePath()); + return map; + } + + /** + * Describe the type of the event + */ + public enum EventType { + /** + * The project was started + */ + ProjectStarted, + /** + * The project failed + */ + ProjectFailed, + /** + * The project was skipped + */ + ProjectSkipped, + /** + * the project succeed + */ + ProjectSucceeded, + /** + * the type of event is unknown + */ + Unknown; + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsMessage.java new file mode 100644 index 0000000..93bfa5a --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsMessage.java @@ -0,0 +1,143 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.file.Path; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Stream; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.DefaultModelWriter; +import org.apache.maven.project.MavenProject; + +/** + * Message send to inform about reactor project in the build and their effective + * model + */ +public class ProjectsMessage extends Message { + + private static final DefaultModelWriter MODEL_WRITER = new DefaultModelWriter(); + + ProjectsMessage(String sessionId, long threadId, Map payload) { + super(sessionId, threadId, payload); + } + + /** + * @param projects the projects to send + */ + public ProjectsMessage(Collection projects) { + super(buildMap(projects)); + } + + /** + * @return a stream of project infos + */ + public Stream projects() { + return keys().map(key -> { + String[] gav = key.split("\t"); + if (gav.length == 5 && "p".equals(gav[0])) { + ProjectInfo pi = new ProjectInfo() { + + @Override + public String getGroupId() { + return gav[1]; + } + + @Override + public String getArtifactId() { + return gav[2]; + } + + @Override + public String getVersion() { + return gav[3]; + } + + @Override + public String getModel() { + return getProperty(key); + } + + @Override + public Path getBaseDir() { + return new File(gav[4]).toPath(); + } + }; + return pi; + } + return null; + }) + .filter(Objects::nonNull); + } + + private static Map buildMap(Collection projects) { + Map map = new HashMap<>(); + for (MavenProject project : projects) { + String key = String.format( + "p\t%s\t%s\t%s\t%s", + project.getGroupId(), + project.getArtifactId(), + project.getVersion(), + project.getBasedir().getAbsolutePath()); + map.put(key, getEffectiveModel(project)); + } + return map; + } + + private static String getEffectiveModel(MavenProject project) { + Model model = project.getModel(); + StringWriter writer = new StringWriter(); + try { + MODEL_WRITER.write(writer, null, model); + } catch (IOException e) { + } + String string = writer.toString(); + return string; + } + + /** + * Holds basic project info + */ + public static interface ProjectInfo { + /** + * @return the group id of the reactor project + */ + String getGroupId(); + + /** + * @return the artifact id of the reactor project + */ + String getArtifactId(); + + /** + * @return the version of the reactor project + */ + String getVersion(); + + /** + * @return the effective model of the project + */ + String getModel(); + + /** + * @return the basedir of the project + */ + Path getBaseDir(); + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java deleted file mode 100644 index 91825ef..0000000 --- a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectsReadMessage.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -Copyright (c) 2025 Christoph Läubrich All rights reserved. - -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. -You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. -*/ -package org.codehaus.plexus.build.connect.messages; - -import java.io.IOException; -import java.io.StringWriter; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.maven.model.Model; -import org.apache.maven.model.io.DefaultModelWriter; -import org.apache.maven.project.MavenProject; - -/** - * Message send to inform about reactor project in the build and their effective - * model - */ -public class ProjectsReadMessage extends Message { - - private static final DefaultModelWriter MODEL_WRITER = new DefaultModelWriter(); - - ProjectsReadMessage(String sessionId, long threadId, Map payload) { - super(sessionId, threadId, payload); - } - - /** - * @param projects the projects to send - */ - public ProjectsReadMessage(Collection projects) { - super(buildMap(projects)); - } - - private static Map buildMap(Collection projects) { - Map map = new HashMap<>(); - for (MavenProject project : projects) { - String key = project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion(); - map.put(key, getEffectiveModel(project)); - } - return map; - } - - private static String getEffectiveModel(MavenProject project) { - Model model = project.getModel(); - StringWriter writer = new StringWriter(); - try { - MODEL_WRITER.write(writer, null, model); - } catch (IOException e) { - } - String string = writer.toString(); - return string; - } -} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java index f88d906..2f9e0a6 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/SessionMessage.java @@ -14,10 +14,7 @@ import java.util.HashMap; import java.util.Map; -import java.util.UUID; -import java.util.WeakHashMap; -import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; /** @@ -27,8 +24,6 @@ public class SessionMessage extends Message { private static final String SESSION_EXECUTION_ROOT_DIRECTORY = "sessionExecutionRootDirectory"; private static final String SESSION_START = "sessionStart"; - private static final String SESSION_ID = "sessionId"; - private static final Map ID_MAP = new WeakHashMap<>(); /** * Creates a new session message @@ -45,10 +40,6 @@ public SessionMessage(MavenSession session, boolean start) { super(sessionId, threadId, payload); } - public String getSessionId() { - return getProperty(SESSION_ID); - } - /** * @return true if this is a session start event */ @@ -63,26 +54,8 @@ public String getExecutionRootDirectory() { return getProperty(SESSION_EXECUTION_ROOT_DIRECTORY); } - /** - * Returns the unique ID for a session - * - * @param session the session to get an Id for - * @return the id of the session or the name of the current thread if the - * session is null - */ - public static synchronized String getId(MavenSession session) { - if (session == null) { - return Thread.currentThread().getName(); - } - // we can't use the session itself as a key, because sessions might be cloned, - // but the execution request should (hopefully) stay constant... - return ID_MAP.computeIfAbsent( - session.getRequest(), x -> UUID.randomUUID().toString()); - } - private static Map buildMap(MavenSession session, boolean start) { Map map = new HashMap<>(2); - map.put(SESSION_ID, getId(session)); map.put(SESSION_START, Boolean.toString(start)); map.put(SESSION_EXECUTION_ROOT_DIRECTORY, session.getExecutionRootDirectory()); return map; From 65e754432286f8cd6394868647e22f49eb7bd2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 22 Feb 2025 17:04:51 +0100 Subject: [PATCH 37/42] Add support for sending mojo execution events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- .../plexus/build/connect/EventListener.java | 24 +-- .../build/connect/messages/InitMessage.java | 26 +++- .../build/connect/messages/Message.java | 25 ++++ .../build/connect/messages/MojoMessage.java | 138 ++++++++++++++++++ .../connect/messages/ProjectMessage.java | 2 +- 5 files changed, 199 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/build/connect/messages/MojoMessage.java diff --git a/src/main/java/org/codehaus/plexus/build/connect/EventListener.java b/src/main/java/org/codehaus/plexus/build/connect/EventListener.java index 5806c08..1eb5e8d 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/EventListener.java +++ b/src/main/java/org/codehaus/plexus/build/connect/EventListener.java @@ -12,9 +12,6 @@ */ package org.codehaus.plexus.build.connect; -import java.util.LinkedHashMap; -import java.util.Map; - import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -25,6 +22,7 @@ import org.apache.maven.execution.MavenSession; import org.codehaus.plexus.build.connect.messages.InitMessage; import org.codehaus.plexus.build.connect.messages.Message; +import org.codehaus.plexus.build.connect.messages.MojoMessage; import org.codehaus.plexus.build.connect.messages.ProjectMessage; import org.codehaus.plexus.build.connect.messages.ProjectsMessage; import org.codehaus.plexus.build.connect.messages.SessionMessage; @@ -51,11 +49,7 @@ public EventListener(BuildConnection connection) { @Override public void init(Context context) throws Exception { - Map data = new LinkedHashMap<>(); - context.getData().forEach((k, v) -> { - data.put(k, String.valueOf(v)); - }); - Message message = connection.send(new InitMessage(data), null); + Message message = connection.send(new InitMessage(context), null); if (message != null) { configuration = Configuration.of(message); } @@ -71,9 +65,9 @@ public void onEvent(Object event) throws Exception { } } - private void handleExecutionEvent(ExecutionEvent executionEvent) { - MavenSession session = executionEvent.getSession(); - Type type = executionEvent.getType(); + private void handleExecutionEvent(ExecutionEvent event) { + MavenSession session = event.getSession(); + Type type = event.getType(); switch (type) { case SessionStarted: connection.send(new SessionMessage(session, true), session); @@ -88,7 +82,13 @@ private void handleExecutionEvent(ExecutionEvent executionEvent) { case ProjectFailed: case ProjectSkipped: case ProjectSucceeded: - connection.send(new ProjectMessage(executionEvent.getProject(), type), session); + connection.send(new ProjectMessage(event.getProject(), type), session); + break; + case MojoStarted: + case MojoFailed: + case MojoSkipped: + case MojoSucceeded: + connection.send(new MojoMessage(event.getMojoExecution(), type), session); break; default: break; diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java index 7239b92..e8cabcb 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/InitMessage.java @@ -12,7 +12,11 @@ */ package org.codehaus.plexus.build.connect.messages; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Properties; + +import org.apache.maven.eventspy.EventSpy.Context; /** * Message send to init the inital communication with the endpoints @@ -22,10 +26,26 @@ public class InitMessage extends Message { /** * Creates a message with inital information about the running maven system * - * @param settings the context settings to send to the endpoint + * @param context the context settings to send to the endpoint */ - public InitMessage(Map settings) { - super(settings); + public InitMessage(Context context) { + super(toMap(context)); + } + + private static Map toMap(Context context) { + Map data = new LinkedHashMap<>(); + context.getData().forEach((k, v) -> { + if (v instanceof String) { + data.put(k, (String) v); + } + if (v instanceof Properties) { + Properties properties = (Properties) v; + for (String p : properties.stringPropertyNames()) { + data.put(k + "." + p, properties.getProperty(p)); + } + } + }); + return data; } InitMessage(String sessionId, long threadId, Map payload) { diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java b/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java index 4400f22..ddc1430 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/Message.java @@ -207,6 +207,9 @@ public static Message decode(byte[] bytes) { if ("ProjectMessage".equals(messageType)) { return new ProjectMessage(sessionId, threadId, payload); } + if ("MojoMessage".equals(messageType)) { + return new MojoMessage(sessionId, threadId, payload); + } return new Message(sessionId, threadId, payload); } catch (IOException e) { // should never happen, but if it happens something is wrong! @@ -237,4 +240,26 @@ private static void writeString(String string, DataOutputStream stream) throws I stream.write(bytes); } } + + @Override + public int hashCode() { + return Objects.hash(properties, sessionId, threadId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Message other = (Message) obj; + return Objects.equals(properties, other.properties) + && Objects.equals(sessionId, other.sessionId) + && threadId == other.threadId; + } } diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/MojoMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/MojoMessage.java new file mode 100644 index 0000000..e1beb34 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/MojoMessage.java @@ -0,0 +1,138 @@ +/* +Copyright (c) 2025 Christoph Läubrich All rights reserved. + +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. +You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. +*/ +package org.codehaus.plexus.build.connect.messages; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.maven.execution.ExecutionEvent.Type; +import org.apache.maven.plugin.MojoExecution; + +/** + * Mesaage generated when a mojo is executed + */ +public class MojoMessage extends Message { + + private static final String GOAL = "goal"; + private static final String LIFECYCLE_PHASE = "lifecyclePhase"; + private static final String EXECUTION_ID = "executionId"; + private static final String VERSION = "version"; + private static final String ARTIFACT_ID = "artifactId"; + private static final String GROUP_ID = "groupId"; + private static final String EVENT_TYPE = "eventType"; + + MojoMessage(String sessionId, long threadId, Map payload) { + super(sessionId, threadId, payload); + } + + /** + * Creates a Mojo message from execution and type + * + * @param mojoExecution + * @param type + */ + public MojoMessage(MojoExecution mojoExecution, Type type) { + super(toMap(mojoExecution, type)); + } + + /** + * @return the group id + */ + public String getGroupId() { + return getProperty(GROUP_ID); + } + + /** + * @return the artifact id + */ + public String getArtifactId() { + return getProperty(ARTIFACT_ID); + } + + /** + * @return the version + */ + public String getVersion() { + return getProperty(VERSION); + } + + /** + * @return the execution id + */ + public String getExecutionId() { + return getProperty(EXECUTION_ID); + } + + /** + * @return the lifecycle phase + */ + public String getLifecyclePhase() { + return getProperty(LIFECYCLE_PHASE); + } + + /** + * @return the lifecycle phase + */ + public String getGoal() { + return getProperty(GOAL); + } + + /** + * @return the type of event + */ + public EventType getType() { + try { + return EventType.valueOf(getProperty(EVENT_TYPE)); + } catch (RuntimeException e) { + return EventType.Unknown; + } + } + + private static Map toMap(MojoExecution mojoExecution, Type type) { + Map map = new HashMap<>(); + map.put(EVENT_TYPE, type.name()); + map.put(GROUP_ID, mojoExecution.getGroupId()); + map.put(ARTIFACT_ID, mojoExecution.getArtifactId()); + map.put(VERSION, mojoExecution.getVersion()); + map.put(EXECUTION_ID, mojoExecution.getExecutionId()); + map.put(LIFECYCLE_PHASE, mojoExecution.getLifecyclePhase()); + map.put(GOAL, mojoExecution.getGoal()); + return map; + } + + /** + * create the event type + */ + public static enum EventType { + /** + * the mojo was started + */ + MojoStarted, + /** + * The mojo failed + */ + MojoFailed, + /** + * The mojo was skipped + */ + MojoSkipped, + /** + * The mojo succeed + */ + MojoSucceeded, + /** + * the type is unknown + */ + Unknown; + } +} diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java index 68a30fd..3180263 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java @@ -97,7 +97,7 @@ private static Map toMap(MavenProject mavenProject, Type eventty /** * Describe the type of the event */ - public enum EventType { + public static enum EventType { /** * The project was started */ From 5ed541d86bb7d7ca6ddb997d8c4524d20a35fbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 22 Feb 2025 17:47:09 +0100 Subject: [PATCH 38/42] Fix Artifact id returned instead of project version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- .../codehaus/plexus/build/connect/messages/ProjectMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java index 3180263..0ec2ef1 100644 --- a/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java +++ b/src/main/java/org/codehaus/plexus/build/connect/messages/ProjectMessage.java @@ -63,7 +63,7 @@ public String getArtifactId() { * @return the version of the project */ public String getVersion() { - return getProperty(ARTIFACT_ID); + return getProperty(VERSION); } /** From bd53adab977f51b13f50eb98d7f6e54aa60b9e59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 May 2025 02:29:07 +0000 Subject: [PATCH 39/42] Bump org.codehaus.plexus:plexus from 20 to 21 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 20 to 21. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-version: '21' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 15a4f4c..92e9222 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 20 + 21 plexus-build-api From 9780eec14d02a8c23f9aa0d79039adf542906d9f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 02:21:28 +0000 Subject: [PATCH 40/42] Bump org.eclipse.sisu:org.eclipse.sisu.plexus from 0.9.0.M3 to 0.9.0.M4 Bumps [org.eclipse.sisu:org.eclipse.sisu.plexus](https://github.com/eclipse-sisu/sisu-project) from 0.9.0.M3 to 0.9.0.M4. - [Release notes](https://github.com/eclipse-sisu/sisu-project/releases) - [Changelog](https://github.com/eclipse-sisu/sisu-project/blob/main/RELEASE.md) - [Commits](https://github.com/eclipse-sisu/sisu-project/compare/milestones/0.9.0.M3...milestones/0.9.0.M4) --- updated-dependencies: - dependency-name: org.eclipse.sisu:org.eclipse.sisu.plexus dependency-version: 0.9.0.M4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 92e9222..d866d5d 100644 --- a/pom.xml +++ b/pom.xml @@ -61,7 +61,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.eclipse.sisu org.eclipse.sisu.plexus - 0.9.0.M3 + 0.9.0.M4 * From 4615b9b75f12326193a1717559f545252f06181a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 02:28:29 +0000 Subject: [PATCH 41/42] Bump org.codehaus.plexus:plexus from 21 to 22 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 21 to 22. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-version: '22' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d866d5d..26d9825 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.codehaus.plexus plexus - 21 + 22 plexus-build-api From 1367b498a5bf1a7b98de5cd34d7bbee4d48397ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Jun 2025 02:07:17 +0000 Subject: [PATCH 42/42] Bump org.apache.maven:maven-core from 3.9.9 to 3.9.10 Bumps org.apache.maven:maven-core from 3.9.9 to 3.9.10. --- updated-dependencies: - dependency-name: org.apache.maven:maven-core dependency-version: 3.9.10 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 26d9825..d6fad88 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ See the Apache License Version 2.0 for the specific language governing permissio org.apache.maven maven-core - 3.9.9 + 3.9.10 provided