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

    Copyright (C) 2015 Red Hat, Inc.

    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.

-->
<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>io.fabric8</groupId>
    <artifactId>kubernetes-client-project</artifactId>
    <version>7.9.0</version>
  </parent>

  <artifactId>kubernetes-model-generator</artifactId>
  <packaging>pom</packaging>
  <name>Fabric8 :: Kubernetes Model Parent</name>

  <modules>
    <module>openapi/maven-plugin</module>
    <module>openapi/validator</module>
    <module>kubernetes-model-common</module>
    <module>kubernetes-model-core</module>
    <module>kubernetes-model-gatewayapi</module>
    <module>kubernetes-model-rbac</module>
    <module>kubernetes-model-admissionregistration</module>
    <module>kubernetes-model-apiextensions</module>
    <module>kubernetes-model-apps</module>
    <module>kubernetes-model-autoscaling</module>
    <module>kubernetes-model-batch</module>
    <module>kubernetes-model-certificates</module>
    <module>kubernetes-model-coordination</module>
    <module>kubernetes-model-discovery</module>
    <module>kubernetes-model-events</module>
    <module>kubernetes-model-extensions</module>
    <module>kubernetes-model-flowcontrol</module>
    <module>kubernetes-model-networking</module>
    <module>kubernetes-model-node</module>
    <module>kubernetes-model-metrics</module>
    <module>kubernetes-model-policy</module>
    <module>kubernetes-model-resource</module>
    <module>kubernetes-model-scheduling</module>
    <module>kubernetes-model-storageclass</module>
    <module>kubernetes-model-kustomize</module>
    <module>openshift-model</module>
    <module>openshift-model-autoscaling</module>
    <module>openshift-model-config</module>
    <module>openshift-model-hive</module>
    <!-- DEPRECATED: This module is deprecated and will be removed in a future release -->
    <module>openshift-model-installer</module>
    <module>openshift-model-miscellaneous</module>
    <module>openshift-model-insights</module>
    <module>openshift-model-operator</module>
    <module>openshift-model-operatorhub</module>
    <module>openshift-model-machine</module>
    <module>openshift-model-monitoring</module>
    <module>openshift-model-console</module>
    <module>openshift-model-machineconfiguration</module>
    <module>openshift-model-tuned</module>
    <module>openshift-model-whereabouts</module>
    <module>openshift-model-storageversionmigrator</module>
  </modules>

  <properties>
    <!-- should we include the integration test in this build? -->
    <itest>true</itest>
    <skipTests>false</skipTests>
    <testExclusionPattern>**/*KubernetesTest.java</testExclusionPattern>
    <openapi.schema.kubernetes-latest>${project.parent.basedir}/openapi/schemas/kubernetes-1.37.0.json</openapi.schema.kubernetes-latest>
    <openapi.schema.openshift-generated>${project.parent.basedir}/openapi/schemas/openshift-generated.json</openapi.schema.openshift-generated>
    <openapi.schema.dev.knative>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/dev.knative.json</openapi.schema.dev.knative>
    <openapi.schema.dev.tekton>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/dev.tekton.json</openapi.schema.dev.tekton>
    <openapi.schema.io.cert-manager>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/io.cert-manager.json</openapi.schema.io.cert-manager>
    <openapi.schema.io.istio>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/io.istio.json</openapi.schema.io.istio>
    <openapi.schema.io.k8s.autoscaling>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/io.k8s.autoscaling.json</openapi.schema.io.k8s.autoscaling>
    <openapi.schema.io.k8s.storage.snapshot>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/io.k8s.storage.snapshot.json</openapi.schema.io.k8s.storage.snapshot>
    <openapi.schema.io.open-cluster-management>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/io.open-cluster-management.json</openapi.schema.io.open-cluster-management>
    <openapi.schema.org.chaos-mesh>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/org.chaos-mesh.json</openapi.schema.org.chaos-mesh>
    <openapi.schema.org.ovn>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/org.ovn.json</openapi.schema.org.ovn>
    <openapi.schema.sh.volcano>${project.basedir}/../../../kubernetes-model-generator/openapi/schemas/sh.volcano.json</openapi.schema.sh.volcano>
    <openapi.openshift-version>4.20</openapi.openshift-version>
    <openapi.storageversionmigrator-revision>5c8923c5ff96ceb4435f66b986b5aec2dd0cbc22</openapi.storageversionmigrator-revision>
    <openapi.whereabouts-revision>5bb9e1542cf987458db181bedee7c051a1538dc1</openapi.whereabouts-revision>
    <!-- Where sundrio APT writes the generated Builders/Fluents under -Pgenerate (see the 'generate'
         profile below): straight into the committed source root, so regenerating updates the files
         that are under version control. Every model module now has its Builders committed (#5622),
         so this is unconditional; it used to be an override in a file-gated profile. -->
    <sundrio.generatedBuildersDirectory>${basedir}/src/generated-builders/java</sundrio.generatedBuildersDirectory>
    <osgi.require-capability>
      osgi.extender;
      filter:="(osgi.extender=osgi.serviceloader.registrar)"
    </osgi.require-capability>
    <osgi.provide-capability>
      osgi.serviceloader;
      osgi.serviceloader=io.fabric8.kubernetes.api.model.KubernetesResource
    </osgi.provide-capability>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
    </dependency>

    <!-- CompileOnly (provided) dependencies -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>io.sundr</groupId>
      <artifactId>builder-annotations</artifactId>
      <scope>provided</scope>
    </dependency>
    <!-- Test dependencies -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>zjsonpatch</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>io.fabric8</groupId>
          <artifactId>openapi-model-generator-maven-plugin</artifactId>
          <version>${project.version}</version>
          <configuration>
            <settings>
              <outputDirectory>${project.basedir}</outputDirectory>
              <packageName>io.fabric8.kubernetes.api.model</packageName>
              <builderPackage>io.fabric8.kubernetes.api.builder</builderPackage>
              <addBuildableReferences>true</addBuildableReferences>
              <generateJavadoc>true</generateJavadoc>
              <packageMappings>
                <com.coreos.monitoring>io.fabric8.openshift.api.model.monitoring</com.coreos.monitoring>
                <com.github.openshift.custom-resource-status>io.fabric8.openshift.api.model.customresourcestatus</com.github.openshift.custom-resource-status>
                <com.github.tektoncd.pipeline>io.fabric8.tekton.pipeline</com.github.tektoncd.pipeline>
                <dev.knative>io.fabric8.knative</dev.knative>
                <dev.tekton>io.fabric8.tekton</dev.tekton>
                <io.cert-manager>io.fabric8.certmanager.api.model</io.cert-manager>
                <io.istio>io.fabric8.istio.api</io.istio>
                <io.k8s.api.core.v1>io.fabric8.kubernetes.api.model</io.k8s.api.core.v1>
                <io.k8s.apimachinery.pkg>io.fabric8.kubernetes.api.model</io.k8s.apimachinery.pkg>
                <io.k8s.apimachinery.pkg.apis.meta.v1>io.fabric8.kubernetes.api.model</io.k8s.apimachinery.pkg.apis.meta.v1>
                <io.k8s.apimachinery.pkg.runtime.schema>io.fabric8.kubernetes.api.model</io.k8s.apimachinery.pkg.runtime.schema>
                <io.k8s.api>io.fabric8.kubernetes.api.model</io.k8s.api>
                <io.k8s.api.apps.v1>io.fabric8.kubernetes.api.model.apps</io.k8s.api.apps.v1>
                <io.k8s.api.rbac.v1>io.fabric8.kubernetes.api.model.rbac</io.k8s.api.rbac.v1>
                <io.k8s.autoscaling>io.fabric8.autoscaling.api.model</io.k8s.autoscaling>
                <io.k8s.client-go.tools.clientcmd.api.v1>io.fabric8.kubernetes.api.model</io.k8s.client-go.tools.clientcmd.api.v1>
                <io.k8s.kube-aggregator.pkg.apis.apiregistration.v1>io.fabric8.kubernetes.api.model</io.k8s.kube-aggregator.pkg.apis.apiregistration.v1>
                <io.k8s.networking.gateway>io.fabric8.kubernetes.api.model.gatewayapi</io.k8s.networking.gateway>
                <io.k8s.sigs.cluster-api.api>io.fabric8.kubernetes.api.model.clusterapi</io.k8s.sigs.cluster-api.api>
                <io.k8s.storage.snapshot.v1>io.fabric8.volumesnapshot.api.model</io.k8s.storage.snapshot.v1>
                <io.open-cluster-management>io.fabric8.openclustermanagement.api.model</io.open-cluster-management>
                <io.openshift>io.fabric8.openshift.api.model</io.openshift>
                <io.openshift.apiserver>io.fabric8.openshift.api.model.miscellaneous.apiserver</io.openshift.apiserver>
                <io.openshift.apps.v1>io.fabric8.openshift.api.model</io.openshift.apps.v1>
                <io.openshift.authorization.v1>io.fabric8.openshift.api.model</io.openshift.authorization.v1>
                <io.openshift.build.v1>io.fabric8.openshift.api.model</io.openshift.build.v1>
                <io.openshift.cloudcredential>io.fabric8.openshift.api.model.miscellaneous.cloudcredential</io.openshift.cloudcredential>
                <io.openshift.helm>io.fabric8.openshift.api.model.miscellaneous.helm</io.openshift.helm>
                <io.openshift.image.v1>io.fabric8.openshift.api.model</io.openshift.image.v1>
                <io.openshift.install>io.fabric8.openshift.api.model.installer</io.openshift.install>
                <io.openshift.network>io.fabric8.openshift.api.model.miscellaneous.network</io.openshift.network>
                <io.openshift.oauth.v1>io.fabric8.openshift.api.model</io.openshift.oauth.v1>
                <io.openshift.project.v1>io.fabric8.openshift.api.model</io.openshift.project.v1>
                <io.openshift.quota.v1>io.fabric8.openshift.api.model</io.openshift.quota.v1>
                <io.openshift.route.v1>io.fabric8.openshift.api.model</io.openshift.route.v1>
                <io.openshift.security.v1>io.fabric8.openshift.api.model</io.openshift.security.v1>
                <io.openshift.template.v1>io.fabric8.openshift.api.model</io.openshift.template.v1>
                <io.openshift.user.v1>io.fabric8.openshift.api.model</io.openshift.user.v1>
                <io.x-k8s.cluster>io.fabric8.kubernetes.api.model.clusterapi</io.x-k8s.cluster>
                <org.chaos-mesh>io.fabric8.chaosmesh</org.chaos-mesh>
                <org.ovn.k8s>io.fabric8.kubernetes.api.model.ovn</org.ovn.k8s>
                <sh.volcano>io.fabric8.volcano.api.model</sh.volcano>
              </packageMappings>
            </settings>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>generate-model</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>build-helper-maven-plugin</artifactId>
          <executions>
            <execution>
              <phase>generate-sources</phase>
              <goals>
                <goal>add-source</goal>
              </goals>
              <configuration>
                <sources>
                  <source>${generate.targetDirectory}</source>
                </sources>
              </configuration>
            </execution>
            <execution>
              <id>add-generated-resources</id>
              <phase>generate-resources</phase>
              <goals>
                <goal>add-resource</goal>
              </goals>
              <configuration>
                <resources>
                  <resource>
                    <directory>${generate.targetResourcesDirectory}</directory>
                  </resource>
                </resources>
              </configuration>
            </execution>
            <execution>
              <id>attach-artifacts</id>
              <phase>package</phase>
              <goals>
                <goal>attach-artifact</goal>
              </goals>
              <configuration>
                <skipAttach>true</skipAttach>
                <artifacts>
                  <artifact>
                    <file>${project.build.outputDirectory}/schema/kube-schema.json</file>
                    <type>json</type>
                    <classifier>schema</classifier>
                  </artifact>
                </artifacts>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <index>true</index>
            <manifest>
              <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
            </manifest>
            <manifestEntries>
              <Implementation-URL>${project.url}</Implementation-URL>
              <Scm-Url>${project.scm.url}</Scm-Url>
              <Scm-Connection>${project.scm.connection}</Scm-Connection>
              <Scm-Revision>${buildNumber}</Scm-Revision>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
      <!-- Set properties containing the scm revision and build timestamp -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>${buildnumber.plugin.version}</version>
        <executions>
          <execution>
            <id>get-scm-revision</id>
            <phase>initialize</phase>
            <goals>
              <goal>create</goal>
            </goals>
            <configuration>
              <doCheck>false</doCheck>
              <doUpdate>false</doUpdate>
              <revisionOnScmFailure>UNKNOWN</revisionOnScmFailure>
              <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <configuration>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtension>zip</nonFilteredFileExtension>
            <nonFilteredFileExtension>gz</nonFilteredFileExtension>
            <nonFilteredFileExtension>jar</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <inherited>true</inherited>
        <configuration>
          <skipTests>${skipTests}</skipTests>
          <excludes>
            <exclude>${testExclusionPattern}</exclude>
          </excludes>
        </configuration>
      </plugin>
      <!-- ============================================================================================
           #5622 — committed sundrio Builders (default-build half)
           ============================================================================================
           sundrio's APT output (*Builder.java / *Fluent.java) is snapshotted into a committed source
           root, src/generated-builders/java, so the default build compiles it as plain source instead
           of re-running annotation processing every time (~4-5s/module faster). The POJOs it is
           generated from live alongside it in src/generated/java.

           This was a file-gated `committed-generated-builders` profile while the conversion was in
           progress, so that a module without committed Builders would not silently lose its public
           Builder/Fluent API. All 49 *model* modules under this parent are converted, so the gate is
           gone and the configuration is unconditional.

           SCOPE, because this parent is inherited more widely than the model modules: extensions/pom.xml
           parents off it too, so everything here also applies to openapi/maven-plugin, openapi/validator
           and the extensions/*/client, */tests and */examples modules (all except
           open-virtual-network's client and tests, which parent off the root pom directly). None of them
           declares @Buildable, so today they only lose an annotation-processing round that was already
           emitting nothing, and gain a source root that does not exist, which javac ignores.

           The consequence to know about: adding @Buildable to one of those modules will NOT produce a
           Builder any more, because sundrio is off the processor path there. That surfaces as a compile
           error the moment the Builder is referenced, and the fix is to put the type in a */model module
           (where Builders are committed) or to give that module its own empty
           <annotationProcessorPaths combine.self="override"/>. Re-gating this on file existence to keep
           sundrio available there would reintroduce exactly the per-module activation this replaced.

           Under -Pgenerate those modules also get an empty src/generated-builders/java, because
           maven-compiler-plugin creates its generatedSourcesDirectory; it is untracked and git does not
           record empty directories.

           Two mechanics worth stating so they are not broken by accident:
           - declaring build-helper here also activates the executions this pom manages for it
             (add-source src/generated/java, add-resource src/generated/resources, attach-artifact with
             skipAttach), in every descendant rather than only the converted modules. They are no-ops
             where those directories are absent, which is everywhere outside the model modules.
           - a child pom that declares its own <annotationProcessorPaths> would win over this one by
             inheritance and silently restore a lombok-only path under -Pgenerate. No module under this
             parent declares maven-compiler-plugin today; keep it that way. -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-generated-builders-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${basedir}/src/generated-builders/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <!-- Run Lombok only (it keeps equals/hashCode/toString on the POJOs) and leave sundrio APT
               off, so the committed Builders compile as plain source. Restricting the processor path
               to the lombok artifact is enough on its own: javac auto-discovers Lombok through its
               META-INF/services, and sundrio (builder-annotations) is simply not on the path, so it
               never runs. This deliberately avoids naming Lombok's internal processor classes, which
               are coupled to ${lombok.version}. The 'generate' profile below re-enables sundrio. -->
          <annotationProcessorPaths>
            <path>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok</artifactId>
              <version>${lombok.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!-- #5622 — regeneration half of the mechanism (activated by `mvn -Pgenerate`, e.g. via
         `make generate-model`); the default-build half is unconditional, in <build> above.

         The empty <annotationProcessorPaths> override is what re-enables sundrio: with no processor
         path, javac discovers BOTH Lombok and sundrio from the compile classpath, so sundrio resolves
         its referenced Builders from the dependency jars (no shadow copies). It must stay an override
         of the lombok-only path in <build>; profiles are injected into this pom's own model before
         inheritance is assembled, so descendants inherit an already-empty value and cannot reorder or
         lose it. If it ever stopped winning, sundrio would SILENTLY stop regenerating and
         `make generate-model` would just recompile the stale committed Builders — the
         generate-model.yml drift guard is the safety net that would catch that.

         Note this makes implicit classpath discovery the ONLY route by which sundrio ever runs. javac
         warns about it from JDK 21 and it is expected to be disabled by default eventually, at which
         point regeneration silently produces nothing rather than merely slowing down; the drift guard
         would again be what catches it. -->

    <profile>
      <id>generate</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <!-- maven-compiler-plugin wipes generatedSourcesDirectory before APT; pointing it at
                   the dedicated src/generated-builders/java (NOT src/generated/java) means the wipe
                   only clears the Builders, never the POJOs that are sundrio's input. -->
              <generatedSourcesDirectory>${sundrio.generatedBuildersDirectory}</generatedSourcesDirectory>
              <annotationProcessorPaths combine.self="override"/>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
