// Path: src/main/java/com/github/ferstl/maven/pomenforcers/model/DependencyModel.java
// @XmlRootElement(name = "dependency")
// public class DependencyModel extends ArtifactModel {
// 
//   private static final Joiner TO_STRING_JOINER = Joiner.on(":").skipNulls();
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   @XmlJavaTypeAdapter(value = DependencyScopeAdapter.class)
//   private DependencyScope scope;
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   private String classifier;
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   private String type;
// 
//   @XmlElementWrapper(namespace = "http://maven.apache.org/POM/4.0.0")
//   @XmlElement(name = "exclusion", namespace = "http://maven.apache.org/POM/4.0.0")
//   private List<ArtifactModel> exclusions;
// 
//   // Constructor used by JAXB
//   DependencyModel() {
//   }
// 
//   public DependencyModel(
//       String groupId, String artifactId, String version, String scope, String classifier, String type) {
// 
//     super(groupId, artifactId, version);
//     this.scope = scope != null ? DependencyScope.getByScopeName(scope) : null;
//     this.classifier = classifier;
//     this.type = type;
//   }
// 
//   public DependencyScope getScope() {
//     return this.scope != null ? this.scope : DependencyScope.COMPILE;
//   }
// 
//   public String getClassifier() {
//     return this.classifier;
//   }
// 
//   public String getType() {
//     return this.type != null ? this.type : "jar";
//   }
// 
//   public List<ArtifactModel> getExclusions() {
//     return this.exclusions != null ? this.exclusions : Collections.emptyList();
//   }
// 
//   @Override
//   public String toString() {
//     return TO_STRING_JOINER.join(
//         super.toString(),
//         getType(),
//         getScope().getScopeName(),
//         this.classifier);
//   }
// 
//   // Note that this equals() implementation breaks the symmetry contract!
//   @Override
//   public boolean equals(Object obj) {
//     if (this == obj) {
//       return true;
//     }
//     if (!(obj instanceof DependencyModel)) {
//       return false;
//     }
// 
//     DependencyModel other = (DependencyModel) obj;
//     return super.equals(other)
//         && equal(this.classifier, other.classifier)
//         && equal(this.type, other.type)
//         && equal(this.scope, other.scope)
//         && equal(this.exclusions, other.exclusions);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(super.hashCode(), this.classifier, this.type, this.scope);
//   }
// 
// }


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;
/*
 * Copyright (c) 2012 - 2020 the original author or authors.
 *
 * 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;





/**
 * This enforcer makes sure that all artifacts in your dependency management are
 * ordered. The ordering can be defined by any combination of <code>scope</code>,
 * <code>groupId</code> and <code>artifactId</code>. Each of these attributes
 * may be given a priority.
 *
 * <pre>
 * ### Example
 *     &lt;rules&gt;
 *       &lt;dependencyManagementOrder implementation=&quot;com.github.ferstl.maven.pomenforcers.PedanticDependencyManagementOrderEnforcer&quot;&gt;
 *         &lt;!-- order by scope, groupId and artifactId (default) --&gt;
 *         &lt;orderBy&gt;scope,groupId,artifactId&lt;/orderBy&gt;
 *         &lt;!-- runtime scope should occur before provided scope --&gt;
 *         &lt;scopePriorities&gt;compile,runtime,provided&lt;/scopePriorities&gt;
 *         &lt;!-- all group IDs starting with com.myproject and com.mylibs should occur first --&gt;
 *         &lt;groupIdPriorities&gt;com.myproject,com.mylibs&lt;/groupIdPriorities&gt;
 *         &lt;!-- all artifact IDs starting with commons- and utils- should occur first --&gt;
 *         &lt;artifactIdPriorities&gt;commons-,utils-&lt;/artifactIdPriorities&gt;
 *       &lt;/dependencyManagementOrder&gt;
 *     &lt;/rules&gt;
 * </pre>
 *
 * @id {@link PedanticEnforcerRule#DEPENDENCY_MANAGEMENT_ORDER}
 * @since 1.0.0
 */
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<DependencyModel> getDeclaredDependencies() {
    return getProjectModel().getManagedDependencies();
  }

  @Override
  protected Collection<Dependency> getMavenDependencies(MavenProject project) {
    DependencyManagement dependencyManagement = project.getDependencyManagement();
    if (dependencyManagement != null) {
      return dependencyManagement.getDependencies();
    } else {
      return Collections.emptyList();
    }
  }

  @Override
// Path: src/main/java/com/github/ferstl/maven/pomenforcers/model/DependencyModel.java
// @XmlRootElement(name = "dependency")
// public class DependencyModel extends ArtifactModel {
// 
//   private static final Joiner TO_STRING_JOINER = Joiner.on(":").skipNulls();
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   @XmlJavaTypeAdapter(value = DependencyScopeAdapter.class)
//   private DependencyScope scope;
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   private String classifier;
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   private String type;
// 
//   @XmlElementWrapper(namespace = "http://maven.apache.org/POM/4.0.0")
//   @XmlElement(name = "exclusion", namespace = "http://maven.apache.org/POM/4.0.0")
//   private List<ArtifactModel> exclusions;
// 
//   // Constructor used by JAXB
//   DependencyModel() {
//   }
// 
//   public DependencyModel(
//       String groupId, String artifactId, String version, String scope, String classifier, String type) {
// 
//     super(groupId, artifactId, version);
//     this.scope = scope != null ? DependencyScope.getByScopeName(scope) : null;
//     this.classifier = classifier;
//     this.type = type;
//   }
// 
//   public DependencyScope getScope() {
//     return this.scope != null ? this.scope : DependencyScope.COMPILE;
//   }
// 
//   public String getClassifier() {
//     return this.classifier;
//   }
// 
//   public String getType() {
//     return this.type != null ? this.type : "jar";
//   }
// 
//   public List<ArtifactModel> getExclusions() {
//     return this.exclusions != null ? this.exclusions : Collections.emptyList();
//   }
// 
//   @Override
//   public String toString() {
//     return TO_STRING_JOINER.join(
//         super.toString(),
//         getType(),
//         getScope().getScopeName(),
//         this.classifier);
//   }
// 
//   // Note that this equals() implementation breaks the symmetry contract!
//   @Override
//   public boolean equals(Object obj) {
//     if (this == obj) {
//       return true;
//     }
//     if (!(obj instanceof DependencyModel)) {
//       return false;
//     }
// 
//     DependencyModel other = (DependencyModel) obj;
//     return super.equals(other)
//         && equal(this.classifier, other.classifier)
//         && equal(this.type, other.type)
//         && equal(this.scope, other.scope)
//         && equal(this.exclusions, other.exclusions);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(super.hashCode(), this.classifier, this.type, this.scope);
//   }
// 
// }


// Path: src/main/java/com/github/ferstl/maven/pomenforcers/PedanticDependencyManagementOrderEnforcer.java
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;

/*
 * Copyright (c) 2012 - 2020 the original author or authors.
 *
 * 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;





/**
 * This enforcer makes sure that all artifacts in your dependency management are
 * ordered. The ordering can be defined by any combination of <code>scope</code>,
 * <code>groupId</code> and <code>artifactId</code>. Each of these attributes
 * may be given a priority.
 *
 * <pre>
 * ### Example
 *     &lt;rules&gt;
 *       &lt;dependencyManagementOrder implementation=&quot;com.github.ferstl.maven.pomenforcers.PedanticDependencyManagementOrderEnforcer&quot;&gt;
 *         &lt;!-- order by scope, groupId and artifactId (default) --&gt;
 *         &lt;orderBy&gt;scope,groupId,artifactId&lt;/orderBy&gt;
 *         &lt;!-- runtime scope should occur before provided scope --&gt;
 *         &lt;scopePriorities&gt;compile,runtime,provided&lt;/scopePriorities&gt;
 *         &lt;!-- all group IDs starting with com.myproject and com.mylibs should occur first --&gt;
 *         &lt;groupIdPriorities&gt;com.myproject,com.mylibs&lt;/groupIdPriorities&gt;
 *         &lt;!-- all artifact IDs starting with commons- and utils- should occur first --&gt;
 *         &lt;artifactIdPriorities&gt;commons-,utils-&lt;/artifactIdPriorities&gt;
 *       &lt;/dependencyManagementOrder&gt;
 *     &lt;/rules&gt;
 * </pre>
 *
 * @id {@link PedanticEnforcerRule#DEPENDENCY_MANAGEMENT_ORDER}
 * @since 1.0.0
 */
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<DependencyModel> getDeclaredDependencies() {
    return getProjectModel().getManagedDependencies();
  }

  @Override
  protected Collection<Dependency> getMavenDependencies(MavenProject project) {
    DependencyManagement dependencyManagement = project.getDependencyManagement();
    if (dependencyManagement != null) {
      return dependencyManagement.getDependencies();
    } else {
      return Collections.emptyList();
    }
  }

  @Override
  protected void reportError(ErrorReport report, Collection<DependencyModel> resolvedDependencies, Collection<DependencyModel> sortedDependencies) {