Skip to content

Commit 3e551d9

Browse files
committed
feat: add rc-upload enhance version
Signed-off-by: sebastien.heurtematte <sebastien.heurtematte@eclipse-foundation.org>
1 parent 49c9735 commit 3e551d9

File tree

4 files changed

+211
-59
lines changed

4 files changed

+211
-59
lines changed

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ Maven plugin for Sonatype Central Portal API ([API Doc](https://central.sonatype
1313
- [Features](#features)
1414
- [Plugin Parameters](#plugin-parameters)
1515
- [Plugin Goals](#plugin-goals)
16+
- [Publishing Mode Examples](#publishing-mode-examples)
1617
- [Creating an Artifact Bundle for Upload](#creating-an-artifact-bundle-for-upload)
1718
- [Bundle Structure Example](#bundle-structure-example)
1819
- [Requirements](#requirements)
20+
- [Deployment States](#deployment-states)
1921
- [Authenticate](#authenticate)
2022
- [Github Integration Example](#github-integration-example)
2123
- [Build project](#build-project)
@@ -53,10 +55,11 @@ Maven plugin for Sonatype Central Portal API ([API Doc](https://central.sonatype
5355
| central.dryRun | If true, only simulate the release/drop (no action performed) | false | true |
5456
| central.artifactFile | Path to the artifact file to upload (zip file containing Maven artifacts) | | /path/to/bundle.zip |
5557
| central.bundleName | Custom name for the upload bundle (defaults to artifact filename without extension) | | my-custom-bundle |
56-
| central.publishingType | Publishing type for uploads (USER_MANAGED or AUTOMATIC) | USER_MANAGED | AUTOMATIC |
58+
| central.automaticPublishing | Whether to automatically publish after validation (true=AUTOMATIC, false=USER_MANAGED) | false | true |
5759
| central.maxWaitTime | Maximum wait time in seconds for validation to complete | 300 | 600 |
5860
| central.maxWaitTimePublishing | Maximum wait time in seconds for publishing to complete | 600 | 900 |
5961
| central.pollInterval | Polling interval in seconds when checking deployment status | 5 | 10 |
62+
| central.waitForCompletion | If true, wait for complete publishing process. If false, return after validation/publishing starts | false | true |
6063

6164
You can provide your Bearer token either via the command line or securely via your Maven `settings.xml` file.
6265

@@ -65,11 +68,27 @@ You can provide your Bearer token either via the command line or securely via yo
6568
| Goal/Function | Description | Main Parameters | Example Command |
6669
| ------------- | -------------------------------------------------------------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
6770
| rc-status | List publication status for a component | namespace, name, version, bearerToken | mvn central-staging-plugins:rc-status -Dcentral.namespace=org.eclipse.cbi -Dcentral.name=org.eclipse.cbi.tycho.example-parent -Dcentral.version=1.0.0 |
68-
| rc-upload | Upload artifact bundle to Central Portal with validation waiting | artifactFile, bundleName, publishingType, bearerToken | mvn central-staging-plugins:rc-upload -Dcentral.artifactFile=/path/to/bundle.zip -Dcentral.publishingType=USER_MANAGED |
71+
| rc-upload | Upload artifact bundle to Central Portal with validation waiting | artifactFile, bundleName, automaticPublishing, waitForCompletion, bearerToken | mvn central-staging-plugins:rc-upload -Dcentral.artifactFile=/path/to/bundle.zip -Dcentral.automaticPublishing=false -Dcentral.waitForCompletion=true |
6972
| rc-publish | Publish a deployment (publish if validated, supports dry run) | deploymentId (optional), bearerToken, dryRun | mvn central-staging-plugins:rc-publish -Dcentral.deploymentId=xxxxx-xxxxx-xxxx-xxx-xxxxxxx -Dcentral.dryRun=true |
7073
| rc-drop | Drop (delete) a deployment (supports dry run) | deploymentId, bearerToken, dryRun | mvn central-staging-plugins:rc-drop -Dcentral.deploymentId=xxxxx-xxxxx-xxxx-xxx-xxxxxxx -Dcentral.dryRun=true |
7174
| rc-list | List all deployments for a namespace, with state, date, and errors per component | namespace, bearerToken | mvn central-staging-plugins:rc-list -Dcentral.namespace=org.eclipse.cbi |
7275

76+
### Publishing Mode Examples
77+
78+
The `automaticPublishing` parameter controls the publishing behavior:
79+
80+
**Manual Publishing (default)**: Upload, validate, and wait for manual approval
81+
```bash
82+
mvn central-staging-plugins:rc-upload -Dcentral.artifactFile=/path/to/bundle.zip
83+
# or explicitly
84+
mvn central-staging-plugins:rc-upload -Dcentral.artifactFile=/path/to/bundle.zip -Dcentral.automaticPublishing=false
85+
```
86+
87+
**Automatic Publishing**: Upload, validate, and automatically publish to Maven Central
88+
```bash
89+
mvn central-staging-plugins:rc-upload -Dcentral.artifactFile=/path/to/bundle.zip -Dcentral.automaticPublishing=true -Dcentral.waitForCompletion=true
90+
```
91+
7392
## Creating an Artifact Bundle for Upload
7493

7594
The `rc-upload` goal requires a bundle file (zip archive) that follows the [Maven Repository Layout](https://maven.apache.org/repository/layout.html). The bundle must contain your artifacts with all required files: JAR, POM, sources, javadoc, and their corresponding signatures and checksums.
@@ -80,7 +99,7 @@ See doc: https://central.sonatype.org/publish/publish-portal-upload/
8099

81100
For a project with namespace `com.sonatype.central.example`, component `example_java_project`, and version `0.1.0`:
82101

83-
```
102+
```shell
84103
bundle.zip
85104
└── com/
86105
└── sonatype/
@@ -120,6 +139,16 @@ bundle.zip
120139
- **Multiple components**: A single bundle can contain multiple components
121140
- **Layout**: Must follow Maven Repository Layout with proper directory structure
122141

142+
### Deployment States
143+
144+
The deployment state can have the following values:
145+
146+
- **PENDING**: A deployment is uploaded and waiting for processing by the validation service
147+
- **VALIDATING**: A deployment is being processed by the validation service
148+
- **VALIDATED**: A deployment has passed validation and is waiting on a user to manually publish via the Central Portal UI
149+
- **PUBLISHING**: A deployment has been either automatically or manually published and is being uploaded to Maven Central
150+
- **PUBLISHED**: A deployment has successfully been uploaded to Maven Central
151+
- **FAILED**: A deployment has encountered an error (additional context will be present in an errors field)
123152

124153
## Authenticate
125154

@@ -208,8 +237,8 @@ mvn clean package
208237

209238
## License
210239

211-
Eclipse Public License v. 2.0 ([LICENSE](LICENSE))
240+
Eclipse Public License v.2.0 ([LICENSE](LICENSE))
212241

213242
## Contributing
214243

215-
Contributions are welcome! Please submit issues and pull requests via GitHub.
244+
Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to contribute to this project.

src/main/java/org/eclipse/cbi/central/DeploymentConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public final class DeploymentConstants {
4545
*/
4646
public static final String PUBLISHED_STATE = "PUBLISHED";
4747

48+
/**
49+
* Deployment state: The deployment is being uploaded to Maven Central.
50+
*/
51+
public static final String PUBLISHING_STATE = "PUBLISHING";
52+
4853
/**
4954
* Field name for deployment ID in API responses.
5055
*/

src/main/java/org/eclipse/cbi/central/plugin/RcPublishMojo.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,28 @@ public void execute() throws MojoFailureException {
6262
Map<String, Object> status = client.getDeploymentStatus(effectiveDeploymentId);
6363
Object state = status.get(DeploymentConstants.DEPLOYMENT_STATE);
6464
getLog().info("Current deployment state: " + state);
65-
if (isValidatedState(state)) {
66-
getLog().info("Deployment is VALIDATED.");
65+
if (isPublishableState(state)) {
66+
if (DeploymentConstants.VALIDATED_STATE.equals(state.toString())) {
67+
getLog().info("Deployment is VALIDATED.");
68+
} else if (DeploymentConstants.PUBLISHING_STATE.equals(state.toString())) {
69+
getLog().info("Deployment is already PUBLISHING.");
70+
}
6771
if (dryRun) {
6872
getLog().info("[DRY RUN] Would publish deployment: " + effectiveDeploymentId);
6973
} else {
70-
getLog().info("Publishing deployment...");
71-
Map<String, Object> result = client.publishDeployment(effectiveDeploymentId);
72-
getLog().info("Publish result: " + result);
74+
if (DeploymentConstants.PUBLISHING_STATE.equals(state.toString())) {
75+
getLog().info("Deployment is already being published, no action needed.");
76+
} else {
77+
getLog().info("Publishing deployment...");
78+
Map<String, Object> result = client.publishDeployment(effectiveDeploymentId);
79+
getLog().info("Publish result: " + result);
80+
}
7381
}
7482
} else {
75-
getLog().warn("DeploymentId " + effectiveDeploymentId + " is not in VALIDATED state. Current state: "
83+
getLog().warn("DeploymentId " + effectiveDeploymentId + " is not in a publishable state (VALIDATED or PUBLISHING). Current state: "
7684
+ state);
7785
throw new IllegalArgumentException("DeploymentId " + effectiveDeploymentId
78-
+ " is not in VALIDATED state. Current state: " + state);
86+
+ " is not in a publishable state (VALIDATED or PUBLISHING). Current state: " + state);
7987
}
8088
} catch (Exception e) {
8189
getLog().error("Failed to publish deployment", e);
@@ -97,7 +105,7 @@ private String findLatestValidatedDeploymentId(String groupId, String artifactId
97105
for (Object depObj : deployments) {
98106
if (depObj instanceof Map<?, ?> dep) {
99107
Object depState = dep.get(DeploymentConstants.DEPLOYMENT_STATE);
100-
if (!isValidatedState(depState))
108+
if (!DeploymentConstants.VALIDATED_STATE.equals(depState.toString()))
101109
continue;
102110
Object componentsObj = dep.get(DeploymentConstants.DEPLOYED_COMPONENT_VERSIONS);
103111
if (componentsObj instanceof java.util.List<?> components) {
@@ -120,9 +128,11 @@ private String findLatestValidatedDeploymentId(String groupId, String artifactId
120128
}
121129

122130
/**
123-
* Checks if the deployment state is VALIDATED.
131+
* Checks if the deployment state is publishable (VALIDATED or already PUBLISHING).
124132
*/
125-
private boolean isValidatedState(Object stateObj) {
126-
return stateObj != null && DeploymentConstants.VALIDATED_STATE.equals(stateObj.toString());
133+
private boolean isPublishableState(Object stateObj) {
134+
return stateObj != null &&
135+
(DeploymentConstants.VALIDATED_STATE.equals(stateObj.toString()) ||
136+
DeploymentConstants.PUBLISHING_STATE.equals(stateObj.toString()));
127137
}
128138
}

0 commit comments

Comments
 (0)