<?xml version="1.0" encoding="UTF-8"?>

<!--
 * 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.xwiki.commons</groupId>
    <artifactId>xwiki-commons-legacy-component</artifactId>
    <version>8.1</version>
  </parent>
  <artifactId>xwiki-commons-legacy-component-default</artifactId>
  <name>XWiki Commons - Legacy - Component - Default Implementation</name>
  <packaging>jar</packaging>
  <description>Legacy module for xwiki-commons-component-default</description>
  <properties>
    <!-- The features provided by this module so that it's found when resolving extension -->
    <xwiki.extension.features>org.xwiki.commons:xwiki-commons-component-default</xwiki.extension.features>
  </properties>
  <dependencies>
    <!-- We need this dependency so that the wrapped module is built before this one -->
    <dependency>
      <groupId>org.xwiki.commons</groupId>
      <artifactId>xwiki-commons-component-default</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
      <exclusions>
        <!-- Exclude to avoid false positives from Revapi. It seems that sometimes (the conditions are unknown) the
             xwiki-commons-component-api JAR would appear before the xwiki-commons-legacy-component-api JAR when Revapi
             executes, thus leading to an error such as:

               java.class.noLongerImplementsInterface: class org.xwiki.component.embed.EmbeddableComponentManager: Class
               no longer implements interface 'org.xwiki.component.manager.CompatibilityComponentManager'.

             Note that for this case EmbeddableComponentManager (located in xwiki-commons-legacy-component-default)
             extends ComponentManager which extends CompatibilityComponentManager in xwiki-commons-legacy-component-api.
        -->
        <exclusion>
          <groupId>org.xwiki.commons</groupId>
          <artifactId>xwiki-commons-component-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.xwiki.commons</groupId>
      <artifactId>xwiki-commons-legacy-component-api</artifactId>
      <version>${project.version}</version>
      <exclusions>
        <!-- [Revapi bug] Revapi seems to follow all transitive dependencies, even those with scope "provided"
             so we force the exclude that should be useless from Maven point of view -->
        <exclusion>
          <groupId>org.xwiki.commons</groupId>
          <artifactId>xwiki-commons-component-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <!-- Getting the transitive dependencies of xwiki-commons-component-api since we exclude it above -->
    <dependency>
      <groupId>org.xwiki.commons</groupId>
      <artifactId>xwiki-commons-component-api</artifactId>
      <version>${project.version}</version>
      <type>pom</type>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>org.xwiki.commons</groupId>
      <artifactId>xwiki-commons-tool-test-simple</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <!-- Apply Compatibility Aspects -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>backward-compatibility-aspects</id>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <weaveDependencies>
            <weaveDependency>
              <groupId>org.xwiki.commons</groupId>
              <artifactId>xwiki-commons-component-default</artifactId>
            </weaveDependency>
          </weaveDependencies>
        </configuration>
      </plugin>
      <!-- Exclude AspectJ's builddef.lst file form the generated JAR since it's not useful there. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>**/builddef.lst</exclude>
          </excludes>
        </configuration>
      </plugin>
      <!-- We need to merge the content of the files that have the same names in the JAR we're aspectifying and
           in this module -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-classes</phase>
            <configuration>
              <target>
                <concat destfile="${project.build.directory}/classes/META-INF/services/org.xwiki.component.annotation.ComponentDependencyFactory" append="true">
                  <filelist dir="${basedir}/src/main/resources/META-INF/services" files="org.xwiki.component.annotation.ComponentDependencyFactory" />
                </concat>
                <concat destfile="${project.build.directory}/classes/META-INF/services/org.xwiki.component.embed.LifecycleHandler" append="true">
                  <filelist dir="${basedir}/src/main/resources/META-INF/services" files="org.xwiki.component.embed.LifecycleHandler" />
                </concat>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- Make sure we run the tests only with the aspectified JARs since otherwise components will be registered
           twice for example. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <classpathDependencyExcludes>
            <classpathDependencyExcludes>org.xwiki.commons:xwiki-commons-component-api</classpathDependencyExcludes>
            <classpathDependencyExcludes>org.xwiki.commons:xwiki-commons-component-default</classpathDependencyExcludes>
          </classpathDependencyExcludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
