Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed May 1, 2024
1 parent b13780d commit 620c360
Show file tree
Hide file tree
Showing 239 changed files with 11,777 additions and 316 deletions.
24 changes: 2 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
# Toolbox
# MDK

The Toolbox project started with manifold aims:
* replace `MIMA CLI`, provide drop-in replacement, but also continue improving it.
* provide replacement for `maven-dependency-plugin`, offering similar (sub)set of Mojos
* showcase how MIMA helps to write reusable Resolver code that runs in Maven (as Mojos) but also outside of Maven as well
* was birthplace of Resolver 2.x `ScopeManager` (that is now part of Resolver 2.x, while Resolver 1.x circumvention is present in Toolbox that supports Maven 3.6+), fixing MNG-8041

Structure of the project:
* Module "shared" is a reusable library module, that depends on MIMA `Context` only (and Resolver APIs), and implements all the logic.
* Module "toolbox" is a Maven Plugin and a CLI at the same time, that exposes Toolbox operations as Mojos and commands. Each Mojo comes in two
"flavors": without prefix (i.e. "tree"), that requires project, and uses `MavenProject` to get the data for requests, and "gav-"
prefixed ones (i.e. "gav-tree"), that do not require project, and is able to target any existing Artifact out there.

To use it as Maven plugin, introspect available Mojos and parameters:
```
$ mvn eu.maveniverse.maven.plugins:toolbox:help -Ddetail
```
Or, to use it as CLI:
```
$ jbang toolbox@maveniverse
```
or you can download the CLI JAR from Maven Central and run it directly.
See https://en.wikipedia.org/wiki/MDK
83 changes: 0 additions & 83 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,94 +22,11 @@
<name>${project.groupId}:${project.artifactId}</name>

<dependencies>
<!-- MIMA + Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima</groupId>
<artifactId>context</artifactId>
</dependency>

<!-- Maven -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>

<!-- Resolver -->
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<scope>provided</scope>
</dependency>

<!-- Search -->
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>search-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>search-backend-remoterepository</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>search-backend-smo</artifactId>
</dependency>

<!-- Commons Compress (unpack) -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima.runtime</groupId>
<artifactId>standalone-static-uber</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.maven.plugins.deploy.spi;

import java.util.Map;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.deployment.DeploymentException;

/**
* Deployer SPI
*
* @since 3.2.0
*/
public interface DeployerSPI {
void deploy(RepositorySystemSession session, DeployRequest deployRequest, Map<String, Object> parameters)
throws DeploymentException;
}
65 changes: 14 additions & 51 deletions kurt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,28 @@
<name>${project.groupId}:${project.artifactId}</name>

<dependencies>
<!-- MIMA + Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima</groupId>
<artifactId>context</artifactId>
</dependency>

<!-- Maven -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<scope>provided</scope>
<groupId>eu.maveniverse.maven.mdk</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<version>0.9.0.M2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>

<!-- Resolver -->
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
Expand All @@ -69,47 +54,25 @@
<artifactId>maven-resolver-util</artifactId>
<scope>provided</scope>
</dependency>

<!-- Search -->
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>search-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>search-backend-remoterepository</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>search-backend-smo</artifactId>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<scope>provided</scope>
</dependency>

<!-- Commons Compress (unpack) -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima.runtime</groupId>
<artifactId>standalone-static-uber</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
109 changes: 109 additions & 0 deletions kurt/src/main/java/eu/maveniverse/maven/mdk/kurt/KurtDeployerSPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package eu.maveniverse.maven.mdk.kurt;

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.apache.maven.plugins.deploy.spi.DeployerSPI;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.deployment.DeploymentException;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.sisu.Priority;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Kurt deployer SPI
*/
@Singleton
@Named("kurt")
@Priority(10)
public class KurtDeployerSPI extends AbstractMavenLifecycleParticipant implements DeployerSPI {
private final Logger log = LoggerFactory.getLogger(getClass());

private final RepositorySystem repositorySystem;

private final List<DeployRequest> deployAtEndRequests = Collections.synchronizedList(new ArrayList<>());

@Inject
public KurtDeployerSPI(RepositorySystem repositorySystem) {
this.repositorySystem = requireNonNull(repositorySystem);
}

@Override
public void deploy(RepositorySystemSession session, DeployRequest deployRequest, Map<String, Object> parameters)
throws DeploymentException {
deployAtEndRequests.add(deployRequest);
}

@Override
public void afterSessionEnd(MavenSession session) throws MavenExecutionException {
boolean errors = !session.getResult().getExceptions().isEmpty();

if (!deployAtEndRequests.isEmpty()) {

log.info("");
log.info("------------------------------------------------------------------------");

if (errors) {
log.info("-- Not performing deploy at end due to errors --");
} else {
log.info("-- Performing deploy at end --");
log.info("------------------------------------------------------------------------");

synchronized (deployAtEndRequests) {
HashMap<RemoteRepository, DeployRequest> batched = new HashMap<>();
for (DeployRequest deployRequest : deployAtEndRequests) {
if (!batched.containsKey(deployRequest.getRepository())) {
batched.put(deployRequest.getRepository(), deployRequest);
} else {
DeployRequest dr = batched.get(deployRequest.getRepository());
deployRequest.getArtifacts().forEach(dr::addArtifact);
deployRequest.getMetadata().forEach(dr::addMetadata);
}
}
try {
for (DeployRequest dr : batched.values()) {
repositorySystem.deploy(session.getRepositorySession(), dr);
}
} catch (DeploymentException e) {
log.error(e.getMessage(), e);
throw new MavenExecutionException(e.getMessage(), e);
}
deployAtEndRequests.clear();
}
}

log.info("------------------------------------------------------------------------");
}
}
}
12 changes: 12 additions & 0 deletions kurt/src/main/resources/META-INF/maven/extension.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension>
<exportedPackages>
<exportedPackage>org.apache.maven.plugins.deploy.spi</exportedPackage>
<exportedPackage>eu.maveniverse.maven.mdk.kurt</exportedPackage>
</exportedPackages>

<exportedArtifacts>
<exportedArtifact>eu.maveniverse.maven.mdk:api</exportedArtifact>
<exportedArtifact>eu.maveniverse.maven.mdk:kurt</exportedArtifact>
</exportedArtifacts>
</extension>
Loading

0 comments on commit 620c360

Please sign in to comment.