Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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.help;

import javax.inject.Inject;

import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;

import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.ProjectBuilder;
import org.eclipse.aether.RepositorySystem;

/**
* Displays a list of artifact handlers that are defined in Maven.
*
* @since 3.5.2
*/
@Mojo(name = "list-dependency-types", requiresProject = false, aggregator = true)
public class ListDependencyTypesMojo extends AbstractHelpMojo {
/**
* The Maven default built-in lifecycles.
*/
private final Map<String, ArtifactHandler> artifactHandlers;

@Inject
public ListDependencyTypesMojo(
ProjectBuilder projectBuilder,
RepositorySystem repositorySystem,
Map<String, ArtifactHandler> artifactHandlers) {
super(projectBuilder, repositorySystem);
this.artifactHandlers = artifactHandlers;
}

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------

/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
StringBuilder descriptionBuffer = new StringBuilder();
for (Map.Entry<String, ArtifactHandler> handlerEntry : new TreeMap<>(artifactHandlers).entrySet()) {
if ("default".equals(handlerEntry.getKey())) {
continue;
}
descriptionBuffer.append(handlerEntry.getKey()).append(LS);
ArtifactHandler handler = handlerEntry.getValue();
descriptionBuffer
.append(" - Extension: ")
.append("*.")
.append(handler.getExtension())
.append(LS);
if (handler.getClassifier() != null && !handler.getClassifier().isEmpty()) {
descriptionBuffer
.append(" - Classifier: ")
.append(handler.getClassifier())
.append(LS);
}
if (handler.isAddedToClasspath()) {
descriptionBuffer.append(" - Added to Classpath").append(LS);
}
if (handler.isIncludesDependencies()) {
descriptionBuffer.append(" - Includes dependencies").append(LS);
}
descriptionBuffer.append(LS);
}
getLog().info(LS + "Maven Dependency Types defined:" + LS + LS + descriptionBuffer);
writeFile(output, descriptionBuffer);
} catch (IOException e) {
throw new MojoFailureException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.help;

import javax.inject.Inject;

import java.io.IOException;
import java.util.List;

import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.Lifecycle;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.ProjectBuilder;
import org.eclipse.aether.RepositorySystem;

/**
* Displays a list of lifecycle phases that are defined in Maven.
*
* @since 3.5.2
*/
@Mojo(name = "list-lifecycle-phases", requiresProject = false, aggregator = true)
public class ListLifecyclePhasesMojo extends AbstractHelpMojo {
/**
* The Maven default built-in lifecycles.
*/
private final DefaultLifecycles defaultLifecycles;

@Inject
public ListLifecyclePhasesMojo(
ProjectBuilder projectBuilder, RepositorySystem repositorySystem, DefaultLifecycles defaultLifecycles) {
super(projectBuilder, repositorySystem);
this.defaultLifecycles = defaultLifecycles;
}

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------

/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
StringBuilder descriptionBuffer = new StringBuilder();
List<Lifecycle> lifecycles = defaultLifecycles.getLifeCycles();
for (Lifecycle lifecycle : lifecycles) {
descriptionBuffer.append(lifecycle.getId()).append(LS);
lifecycle
.getPhases()
.forEach(p -> descriptionBuffer.append(" * ").append(p).append(LS));
descriptionBuffer.append(LS);
}
getLog().info(LS + "Maven lifecycles defined:" + LS + LS + descriptionBuffer);
writeFile(output, descriptionBuffer);
} catch (IOException e) {
throw new MojoFailureException(e);
}
}
}
123 changes: 123 additions & 0 deletions src/main/java/org/apache/maven/plugins/help/ListPackagingMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.help;

import javax.inject.Inject;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;

import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.mapping.Lifecycle;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.lifecycle.mapping.LifecycleMojo;
import org.apache.maven.lifecycle.mapping.LifecyclePhase;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.ProjectBuilder;
import org.eclipse.aether.RepositorySystem;

/**
* Displays a list of packaging that are defined in Maven.
*
* @since 3.5.2
*/
@Mojo(name = "list-packaging", requiresProject = false, aggregator = true)
public class ListPackagingMojo extends AbstractHelpMojo {
/**
* The Maven default built-in lifecycles.
*/
private final DefaultLifecycles defaultLifecycles;

/**
* The Maven default built-in lifecycles.
*/
private final Map<String, LifecycleMapping> lifecycleMapping;

@Inject
public ListPackagingMojo(
ProjectBuilder projectBuilder,
RepositorySystem repositorySystem,
DefaultLifecycles defaultLifecycles,
Map<String, LifecycleMapping> lifecycleMapping) {
super(projectBuilder, repositorySystem);
this.defaultLifecycles = defaultLifecycles;
this.lifecycleMapping = lifecycleMapping;
}

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------

/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
StringBuilder descriptionBuffer = new StringBuilder();
for (Map.Entry<String, LifecycleMapping> lifecycleMappingEntry :
new TreeMap<>(lifecycleMapping).entrySet()) {
LifecycleMapping lifecycleMapping = lifecycleMappingEntry.getValue();
for (Map.Entry<String, Lifecycle> phaseEntry :
lifecycleMapping.getLifecycles().entrySet()) {
Lifecycle mapping = phaseEntry.getValue();
descriptionBuffer
.append(lifecycleMappingEntry.getKey())
.append(" (lifecycle: ")
.append(mapping.getId())
.append(")")
.append(LS);
org.apache.maven.lifecycle.Lifecycle lifecycle = getLifecycle(mapping.getId());
for (String phase : lifecycle.getPhases()) {
LifecyclePhase lphase = mapping.getLifecyclePhases().get(phase);
if (lphase != null) {
descriptionBuffer.append(" - ").append(phase).append(LS);
for (LifecycleMojo mojo : lphase.getMojos()) {
descriptionBuffer
.append(" - ")
.append(mojo.getGoal())
.append(LS);
}
}
}
}
descriptionBuffer.append(LS);
}
getLog().info(LS + "Maven packaging defined:" + LS + LS + descriptionBuffer);
writeFile(output, descriptionBuffer);
} catch (IOException e) {
throw new MojoFailureException(e);
}
}

private org.apache.maven.lifecycle.Lifecycle getLifecycle(String name) {
return defaultLifecycles.getLifeCycles().stream()
.filter(l -> Objects.equals(name, l.getId()))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No such lifecycle"));
}
}