All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ferstl.maven.pomenforcers.PedanticDependencyManagementOrderEnforcer Maven / Gradle / Ivy

Go to download

The Pedantic POM Enforcers consist of serveral Maven enforcer rules that help you keep your project setup consistent and organized.

There is a newer version: 2.2.0
Show newest version
/*
 * Copyright (c) 2013 by Stefan Ferstl 
 *
 * 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.
 */
package com.github.ferstl.maven.pomenforcers;

import java.util.Collection;
import java.util.Collections;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.project.MavenProject;

import com.github.ferstl.maven.pomenforcers.model.DependencyModel;

import static com.github.ferstl.maven.pomenforcers.ErrorReport.toList;


/**
 * This enforcer makes sure that all artifacts in your dependency management are
 * ordered. The ordering can be defined by any combination of scope,
 * groupId and artifactId. Each of these attributes
 * may be given a priority.
 *
 * 
 * ### Example
 *     <rules>
 *       <dependencyManagementOrder implementation="com.github.ferstl.maven.pomenforcers.PedanticDependencyManagementOrderEnforcer">
 *         <!-- order by scope, groupId and artifactId (default) -->
 *         <orderBy>scope,groupId,artifactId</orderBy>
 *         <!-- runtime scope should occur before provided scope -->
 *         <scopePriorities>compile,runtime,provided</scopePriorities>
 *         <!-- all group IDs starting with com.myproject and com.mylibs should occur first -->
 *         <groupIdPriorities>com.myproject,com.mylibs</groupIdPriorities>
 *         <!-- all artifact IDs starting with commons- and utils- should occur first -->
 *         <artifactIdPriorities>commons-,utils-</artifactIdPriorities>
 *       </dependencyManagementOrder>
 *     </rules>
 * 
* * @id {@link PedanticEnforcerRule#DEPENDENCY_MANAGEMENT_ORDER} */ public class PedanticDependencyManagementOrderEnforcer extends AbstractPedanticDependencyOrderEnforcer { @Override protected PedanticEnforcerRule getDescription() { return PedanticEnforcerRule.DEPENDENCY_MANAGEMENT_ORDER; } @Override protected void accept(PedanticEnforcerVisitor visitor) { visitor.visit(this); } @Override protected Collection getDeclaredDependencies() { return getProjectModel().getManagedDependencies(); } @Override protected Collection getMavenDependencies(MavenProject project) { DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { return dependencyManagement.getDependencies(); } else { return Collections.emptyList(); } } @Override protected void reportError(ErrorReport report, Collection sortedDependencies) { report.addLine("Your dependency management has to be ordered this way:") .addLine(toList(sortedDependencies)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy