Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 21, 2024
1 parent 84e5684 commit a5aea01
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin;

import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name = "classpath", threadSafe = true)
public class ClasspathMojo extends ProjectMojoSupport {
/**
* The resolution scope to display, accepted values are "runtime", "compile", "test", etc.
*/
@Parameter(property = "scope", defaultValue = "runtime", required = true)
private String scope;

@Override
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
toolboxCommando.classpath(ResolutionScope.parse(scope), projectAsResolutionRoot(), output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
public class DumpMojo extends ProjectMojoSupport {
@Override
protected void doExecute(ToolboxCommando toolboxCommando) {
toolboxCommando.dump(verbose, output);
toolboxCommando.dump(logger.isDebugEnabled(), output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.aether.artifact.ArtifactTypeRegistry;
import org.eclipse.aether.artifact.DefaultArtifact;
Expand All @@ -35,12 +34,8 @@
*/
public abstract class ProjectMojoSupport extends AbstractMojo {
protected final Logger logger = LoggerFactory.getLogger(getClass());

protected final Output output = new Slf4jOutput(logger);

@Parameter(property = "verbose", defaultValue = "false", required = true)
protected boolean verbose;

@Component
private MavenProject mavenProject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public class TreeMojo extends ProjectMojoSupport {
@Parameter(property = "scope", defaultValue = "runtime", required = true)
private String scope;

/**
* Set it {@code true} for verbose tree.
*/
@Parameter(property = "verboseTree", defaultValue = "false", required = true)
private boolean verboseTree;

@Override
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
toolboxCommando.tree(ResolutionScope.parse(scope), projectAsResolutionRoot(), verbose, output);
toolboxCommando.tree(ResolutionScope.parse(scope), projectAsResolutionRoot(), verboseTree, output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin.gav;

import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.aether.resolution.ArtifactDescriptorException;

@Mojo(name = "gav-classpath", requiresProject = false, threadSafe = true)
public class GavClasspathMojo extends GavMojoSupport {
/**
* The artifact coordinates in the format {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}
* to display tree for.
*/
@Parameter(property = "gav", required = true)
private String gav;

/**
* The resolution scope to display, accepted values are "runtime", "compile", "test", etc.
*/
@Parameter(property = "scope", defaultValue = "runtime", required = true)
private String scope;

/**
* Apply BOMs, if needed.
*/
@Parameter(property = "boms", defaultValue = "")
private java.util.List<String> boms;

@Override
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
try {
toolboxCommando.classpath(ResolutionScope.parse(scope), toolboxCommando.loadGav(gav, boms), output);
} catch (RuntimeException e) {
throw new MojoExecutionException(e);
} catch (ArtifactDescriptorException e) {
throw new MojoFailureException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin.gav;

import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.apache.maven.plugins.annotations.Mojo;

@Mojo(name = "gav-dump", requiresProject = false, threadSafe = true)
public class GavDumpMojo extends GavMojoSupport {
@Override
protected void doExecute(ToolboxCommando toolboxCommando) {
toolboxCommando.dump(logger.isDebugEnabled(), output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin.gav;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.mima.context.ContextOverrides;
import eu.maveniverse.maven.mima.context.Runtime;
import eu.maveniverse.maven.mima.context.Runtimes;
import eu.maveniverse.maven.toolbox.shared.Output;
import eu.maveniverse.maven.toolbox.shared.Slf4jOutput;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class GavMojoSupport extends AbstractMojo {
protected final Logger logger = LoggerFactory.getLogger(getClass());
protected final Output output = new Slf4jOutput(logger);

@Parameter(property = "verbose", defaultValue = "false", required = true)
protected boolean verbose;

@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
Runtime runtime = Runtimes.INSTANCE.getRuntime();
try (Context context = runtime.create(ContextOverrides.create().build())) {
doExecute(ToolboxCommando.create(runtime, context));
}
}

protected abstract void doExecute(ToolboxCommando toolboxCommando)
throws MojoExecutionException, MojoFailureException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,18 @@
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin;
package eu.maveniverse.maven.toolbox.plugin.gav;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.mima.context.ContextOverrides;
import eu.maveniverse.maven.mima.context.Runtime;
import eu.maveniverse.maven.mima.context.Runtimes;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.Slf4jOutput;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.aether.resolution.ArtifactDescriptorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Mojo(name = "gav-tree", requiresProject = false, threadSafe = true)
public class GavTreeMojo extends AbstractMojo {
private final Logger logger = LoggerFactory.getLogger(getClass());

public class GavTreeMojo extends GavMojoSupport {
/**
* The artifact coordinates in the format {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}
* to display tree for.
Expand All @@ -43,8 +33,8 @@ public class GavTreeMojo extends AbstractMojo {
/**
* Set it {@code true} for verbose tree.
*/
@Parameter(property = "verbose", defaultValue = "false", required = true)
private boolean verbose;
@Parameter(property = "verboseTree", defaultValue = "false", required = true)
private boolean verboseTree;

/**
* Apply BOMs, if needed.
Expand All @@ -53,12 +43,9 @@ public class GavTreeMojo extends AbstractMojo {
private java.util.List<String> boms;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Runtime runtime = Runtimes.INSTANCE.getRuntime();
try (Context context = runtime.create(ContextOverrides.create().build())) {
ToolboxCommando toolboxCommando = ToolboxCommando.create(runtime, context);
toolboxCommando.tree(
ResolutionScope.parse(scope), toolboxCommando.loadGav(gav, boms), verbose, new Slf4jOutput(logger));
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
try {
toolboxCommando.tree(ResolutionScope.parse(scope), toolboxCommando.loadGav(gav, boms), verboseTree, output);
} catch (RuntimeException e) {
throw new MojoExecutionException(e);
} catch (ArtifactDescriptorException e) {
Expand Down

0 comments on commit a5aea01

Please sign in to comment.