<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you 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 REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
 -->
<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>com.adobe.aem</groupId>
    <artifactId>parent-oss</artifactId>
    <version>1</version>
    <relativePath>../parent-oss/pom.xml</relativePath>
  </parent>

  <artifactId>aemanalyser-cli</artifactId>
  <version>0.1.2</version>
  <packaging>jar</packaging>

  <name>AEM Analyser CLI</name>
  <description>AEM Analyser Command-line tool</description>

  <scm>
    <connection>scm:git:git@github.com:adobe/aemanalyser-maven-plugin.git</connection>
    <developerConnection>scm:git:git@github.com:adobe/aemanalyser-maven-plugin.git</developerConnection>
    <url>https://github.com/adobe/aemanalyser-maven-plugin/tree/main/aemanalyser-cli</url>
    <tag>aemanalyser-cli-0.1.2</tag>
  </scm>
  
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <phase>generate-resources</phase>
            <goals>
              <goal>copy-dependencies</goal>
              <goal>build-classpath</goal>
            </goals>
            <configuration>
              <includeArtifactIds>
                aemanalyser-core,
                geronimo-json_1.1_spec,
                johnzon-core,
                org.apache.felix.cm.json,
                org.apache.felix.configadmin.plugin.interpolation,
                org.apache.felix.converter,
                org.apache.sling.feature,
                org.apache.sling.feature.analyser,
                org.apache.sling.feature.extension.apiregions,
                org.osgi.service.cm,
                org.osgi.framework,
                org.osgi.resource,
                org.osgi.util.function,
                picocli,
                slf4j-api,
                slf4j-simple
              </includeArtifactIds>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>              

              <!-- These properties are for build-classpath. It creates a classpath for the copied
                   dependencies and puts it in the ${distro.classpath} property. The jar Class-Path
                   uses spaces as separators. Unfortunately <pathSeparator> configuration property
                   does not work with a space as value, so the pathSeparator is set to a character
                   here and this is then replaced later using the regex-property plugin. -->
              <prefix>lib</prefix>
              <outputProperty>distro.classpath</outputProperty>
              <pathSeparator>:</pathSeparator>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <goals>
              <goal>regex-property</goal>
            </goals>
            <configuration>
              <!-- Here the value of property for the jar the Class-Path is replaced to have a space
                   as separator. Unfortunately <replacement> does not work if a single space if specified
                   so this uses the surrounding .jar and lib to provide some content. -->
              <name>distro.classpath.replaced</name>
              <value>${distro.classpath}</value>
              <regex>[.]jar[:]lib</regex>
              <replacement>.jar lib</replacement>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.adobe.aem.analyser.cli.Main</mainClass>
            </manifest>
            <manifestEntries>
              <!-- Include the computed classpath with all copied dependencies in the jar here -->
              <Class-Path>${distro.classpath.replaced}</Class-Path>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals><goal>single</goal></goals>
            <configuration>
              <descriptors>
                <descriptor>src/main/assembly/zip-assembly.xml</descriptor>
              </descriptors>              
            </configuration>
          </execution>
        </executions>
      </plugin>    
    </plugins>
  </build>
  
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>aemanalyser-core</artifactId>
      <version>1.0.2</version>
    </dependency>

    <!-- 
     Interpolation
     -->    
    <dependency>
      <groupId>org.apache.felix</groupId>
      <artifactId>org.apache.felix.configadmin.plugin.interpolation</artifactId>
      <version>1.2.0</version>
    </dependency>
    <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>org.osgi.service.cm</artifactId>
       <version>1.6.0</version>
    </dependency>

    <!--
     | CLI
    -->
    <dependency>
      <groupId>info.picocli</groupId>
      <artifactId>picocli</artifactId>
      <version>4.6.1</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.26</version>
    </dependency>

    <!-- Test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
