com.github.ferstl.maven.pomenforcers.PedanticDependencyOrderEnforcer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pedantic-pom-enforcers Show documentation
Show all versions of pedantic-pom-enforcers Show documentation
The Pedantic POM Enforcers consist of serveral Maven enforcer rules that help you keep your
project setup consistent and organized.
/*
* 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 org.apache.maven.model.Dependency;
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 dependencies section 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>
* <dependencyOrder implementation="com.github.ferstl.maven.pomenforcers.PedanticDependencyOrderEnforcer">
* <!-- 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>
* </dependencyOrder>
* </rules>
*
*
* @id {@link PedanticEnforcerRule#DEPENDENCY_ORDER}
*/
public class PedanticDependencyOrderEnforcer extends AbstractPedanticDependencyOrderEnforcer {
@Override
protected void accept(PedanticEnforcerVisitor visitor) {
visitor.visit(this);
}
@Override
protected PedanticEnforcerRule getDescription() {
return PedanticEnforcerRule.DEPENDENCY_ORDER;
}
@Override
protected Collection getDeclaredDependencies() {
return getProjectModel().getDependencies();
}
@Override
protected Collection getMavenDependencies(MavenProject project) {
return project.getDependencies();
}
@Override
protected void reportError(ErrorReport report, Collection sortedDependencies) {
report.addLine("Your dependencies have to be sorted this way:")
.addLine(toList(sortedDependencies));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy