// Path: src/main/java/com/github/ferstl/maven/pomenforcers/model/PluginModel.java
// public class PluginModel extends ArtifactModel {
// 
//   @XmlElementWrapper(name = "configuration", namespace = "http://maven.apache.org/POM/4.0.0")
//   @XmlAnyElement
//   private List<Element> configItems;
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   private DependenciesModel dependencies;
// 
//   PluginModel() {
//   }
// 
//   public PluginModel(String groupId, String artifactId, String version) {
//     super(groupId, artifactId, version);
//   }
// 
//   public boolean isConfigured() {
//     return this.configItems != null && !this.configItems.isEmpty();
//   }
// 
//   public List<DependencyModel> getDependencies() {
//     return this.dependencies != null ? this.dependencies.getDependencies() : Collections.emptyList();
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (obj == this) {
//       return true;
//     }
//     if (!(obj instanceof PluginModel)) {
//       return false;
//     }
// 
//     PluginModel other = (PluginModel) obj;
//     return super.equals(other)
//         // TODO: Element implementations may not implement equals()!!
//         && Objects.equals(this.configItems, other.configItems)
//         && Objects.equals(this.dependencies, other.dependencies);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(super.hashCode(), this.configItems, this.dependencies);
//   }
// }
// 
// Path: src/main/java/com/github/ferstl/maven/pomenforcers/util/EnforcerRuleUtils.java
// public static String evaluateProperties(String input, EnforcerRuleHelper helper) {
//   if (!Strings.isNullOrEmpty(input)) {
//     Matcher matcher = PROPERTY_PATTERN.matcher(input);
//     StringBuffer substituted = new StringBuffer();
//     while (matcher.find()) {
//       String property = matcher.group();
//       matcher.appendReplacement(substituted, evaluateStringProperty(property, helper));
//     }
//     matcher.appendTail(substituted);
//     return substituted.toString();
//   }
//   return input;
// }


import java.util.Objects;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.apache.maven.model.Plugin;
import com.github.ferstl.maven.pomenforcers.model.PluginModel;
import static com.github.ferstl.maven.pomenforcers.util.EnforcerRuleUtils.evaluateProperties;
import static com.google.common.base.Strings.isNullOrEmpty;
/*
 * 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.model.functions;


/**
 * Matches Maven {@link Plugin} objects with {@link PluginModel} objects.
 */
public class PluginMatcher extends AbstractOneToOneMatcher<Plugin, PluginModel> {

  private static final String DEFAULT_GROUP_ID = "org.apache.maven.plugins";

  public PluginMatcher(EnforcerRuleHelper helper) {
    super(helper);
  }

  @Override
  protected PluginModel transform(Plugin mavenPlugin) {
    return new PluginModel(mavenPlugin.getGroupId(), mavenPlugin.getArtifactId(), mavenPlugin.getVersion());
  }

  @Override
  protected boolean matches(PluginModel supersetItem, PluginModel subsetItem) {
    String groupId = getGroupId(subsetItem);
// Path: src/main/java/com/github/ferstl/maven/pomenforcers/model/PluginModel.java
// public class PluginModel extends ArtifactModel {
// 
//   @XmlElementWrapper(name = "configuration", namespace = "http://maven.apache.org/POM/4.0.0")
//   @XmlAnyElement
//   private List<Element> configItems;
// 
//   @XmlElement(namespace = "http://maven.apache.org/POM/4.0.0")
//   private DependenciesModel dependencies;
// 
//   PluginModel() {
//   }
// 
//   public PluginModel(String groupId, String artifactId, String version) {
//     super(groupId, artifactId, version);
//   }
// 
//   public boolean isConfigured() {
//     return this.configItems != null && !this.configItems.isEmpty();
//   }
// 
//   public List<DependencyModel> getDependencies() {
//     return this.dependencies != null ? this.dependencies.getDependencies() : Collections.emptyList();
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (obj == this) {
//       return true;
//     }
//     if (!(obj instanceof PluginModel)) {
//       return false;
//     }
// 
//     PluginModel other = (PluginModel) obj;
//     return super.equals(other)
//         // TODO: Element implementations may not implement equals()!!
//         && Objects.equals(this.configItems, other.configItems)
//         && Objects.equals(this.dependencies, other.dependencies);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(super.hashCode(), this.configItems, this.dependencies);
//   }
// }
// 
// Path: src/main/java/com/github/ferstl/maven/pomenforcers/util/EnforcerRuleUtils.java
// public static String evaluateProperties(String input, EnforcerRuleHelper helper) {
//   if (!Strings.isNullOrEmpty(input)) {
//     Matcher matcher = PROPERTY_PATTERN.matcher(input);
//     StringBuffer substituted = new StringBuffer();
//     while (matcher.find()) {
//       String property = matcher.group();
//       matcher.appendReplacement(substituted, evaluateStringProperty(property, helper));
//     }
//     matcher.appendTail(substituted);
//     return substituted.toString();
//   }
//   return input;
// }


// Path: src/main/java/com/github/ferstl/maven/pomenforcers/model/functions/PluginMatcher.java
import java.util.Objects;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.apache.maven.model.Plugin;
import com.github.ferstl.maven.pomenforcers.model.PluginModel;
import static com.github.ferstl.maven.pomenforcers.util.EnforcerRuleUtils.evaluateProperties;
import static com.google.common.base.Strings.isNullOrEmpty;

/*
 * 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.model.functions;


/**
 * Matches Maven {@link Plugin} objects with {@link PluginModel} objects.
 */
public class PluginMatcher extends AbstractOneToOneMatcher<Plugin, PluginModel> {

  private static final String DEFAULT_GROUP_ID = "org.apache.maven.plugins";

  public PluginMatcher(EnforcerRuleHelper helper) {
    super(helper);
  }

  @Override
  protected PluginModel transform(Plugin mavenPlugin) {
    return new PluginModel(mavenPlugin.getGroupId(), mavenPlugin.getArtifactId(), mavenPlugin.getVersion());
  }

  @Override
  protected boolean matches(PluginModel supersetItem, PluginModel subsetItem) {
    String groupId = getGroupId(subsetItem);
    String artifactId = evaluateProperties(subsetItem.getArtifactId(), getHelper());