/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.tool.enforcer;

import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;

/**
 * Performs checks on the version specified for dependencies in pom.xml files. For example if we're in XWiki Rendering
 * and there's a dependency on some XWiki Commons module we might want to ensure that it uses a variable (such as
 * {@code ${commons.version}}) and not {@code ${project.version}}. To achieve this you would use:
 *
 * <pre>
 * <code>
 *   &lt;rules&gt;
 *     &lt;validateDependencyVersion implementation="org.xwiki.tool.enforcer.BannedDependencyType"&gt;
 *       &lt;versionCheck&gt;
 *         &lt;projectPackaging&gt;jar&lt;/projectPackaging&gt;
 *         &lt;dependencyType&gt;xar&lt;/dependencyType&gt;
 *       &lt;/versionCheck&gt;
 *     &lt;/validateDependencyVersion&gt;
 *   &lt;/rules&gt;
 * </code>
 * </pre>
 *
 * @version $Id$
 * @since 14.5RC1
 * @since 14.4.3
 * @since 13.10.8
 */
public class BannedDependencyType extends AbstractPomCheck
{
    /**
     * The packaging of the project to check.
     */
    private String projectPackaging;

    private String dependencyType;

    @Override
    public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException
    {
        Model model = getModel(helper);

        if (this.projectPackaging == null || model.getPackaging().equals(projectPackaging)) {
            for (Dependency dependency : model.getDependencies()) {
                if (isRuntime(dependency) && getType(dependency).equals(this.dependencyType)) {
                    StringBuilder builder = new StringBuilder("Found dependency with banned type [");
                    builder.append(this.dependencyType);
                    builder.append("]");
                    if (this.projectPackaging != null) {
                        builder.append(" for a project with packaging [");
                        builder.append(this.projectPackaging);
                        builder.append("]");
                    }
                    builder.append(": ");
                    builder.append(dependency);
                    throw new EnforcerRuleException(builder.toString());
                }
            }
        }
    }

    private boolean isRuntime(Dependency dependency)
    {
        return dependency.getScope() == null || dependency.getScope().equals("runtime");
    }

    private String getType(Dependency dependency)
    {
        return dependency.getType() != null ? dependency.getType() : "jar";
    }
}

@@ -1158,23 +1158,20 @@
  on the 
-version
+type
  specifi
@@ -1225,214 +1225,136 @@
 le i
-f we're in XWiki Rendering%0A * and there's a dependency on some XWiki Commons module we might want to ensure that it uses a variable (such as%0A * %7B@code $%7Bcommons.version%7D%7D) and not %7B@code $%7Bproject.ver
+n XWiki Standard we want to%0A * prevent extension with package %7B@code jar%7D and %7B@code webjar%7D to depend on %7B@code xar%7D exten
 sion
-%7D%7D
+s
 . To
@@ -1366,16 +1366,19 @@
 eve this
+%0A *
  you wou
@@ -1542,37 +1542,270 @@
     &lt;
-versionCheck
+projectPackaging&gt;jar&lt;/projectPackaging&gt;%0A *       &lt;dependencyType&gt;xar&lt;/dependencyType&gt;%0A *     &lt;/validateDependencyVersion&gt;%0A *     &lt;validateDependencyVersion implementation=%22org.xwiki.tool.enforcer.BannedDependencyType%22
 &gt;%0A *
-  
        &
@@ -1819,32 +1819,35 @@
 ectPackaging&gt;
+web
 jar&lt;/projectP
@@ -1857,26 +1857,24 @@
 aging&gt;%0A *
-  
        &lt;d
@@ -1921,39 +1921,8 @@
 gt;%0A
- *       &lt;/versionCheck&gt;%0A
  *  

Introduce an enforcer to forbidd specific type of dependencies * update javadoc