#!/usr/bin/env bash

echo """
This file is intended only as a reference or starting-point for extension developers.
It is not supported by Apache Geode in any way.
This is merely the path one developer took in creating an early iteration of Geodes configuration classes.

Our ultimate goal is to not require an XSD at all and to not use XML as a data container.
For those developers coming from this now-discouraged cache.xml configuration style, however,
  this script can assist in generating configuration container classes consistent with the schemas.
"""

printf "Press ENTER to generate classes using xjc..."
read
echo

geodeRoot=$(git rev-parse --show-toplevel)

generate-core () {
  projectDir="${geodeRoot}/geode-core"

  sourceXsd="${projectDir}/src/main/resources/META-INF/schemas/geode.apache.org/schema/cache/configurationService.xsd"
  classPath="${projectDir}/src/main/java"
  jaxBindings="${projectDir}//src/main/resources/META-INF/schemas/geode.apache.org/schema/cache/bindings.xjb"

  outputDir="${projectDir}/build/generated-src/main/"
  outputPackage="org.apache.geode.cache.configuration"
  outputEpisode="${projectDir}/../etc/geode-core.episode"

  mkdir -p ${outputDir}
  xjc -extension -p ${outputPackage} -d ${outputDir} -episode ${outputEpisode} -no-header -b ${jaxBindings} -classpath ${classPath} -contentForWildcard -npa ${sourceXsd}
}

generate-connectors () {
  projectDir="${geodeRoot}/geode-connectors"

  sourceXsd="${projectDir}/src/main/resources/META-INF/schemas/geode.apache.org/schema/jdbc/jdbc-1.0.xsd"
  jaxBindings="${projectDir}/src/main/resources/META-INF/schemas/geode.apache.org/schema/jdbc/bindings.xjb"
  classPath="${projectDir}/../geode-core/src/main/java"
  coreEpisode="${projectDir}/../etc/geode-core.episode"

  outputDir="${projectDir}/build/generated-src/main/"
  outputPackage="org.apache.geode.cache.configuration"
  outputEpisode="${projectDir}/../etc/geode-connectors.episode"

  mkdir -p ${outputDir}
  xjc -extension -p ${outputPackage} -d ${outputDir} -episode ${outputEpisode} -no-header -b ${jaxBindings} -classpath ${classPath} -contentForWildcard -npa ${sourceXsd}
}

generate-lucene () {
  projectDir="${geodeRoot}/geode-lucene"

  sourceXsd="${projectDir}/src/main/resources/META-INF/schemas/geode.apache.org/schema/lucene/lucene-1.0.xsd"
  jaxBindings="${projectDir}/src/main/resources/META-INF/schemas/geode.apache.org/schema/lucene/bindings.xjb"
  classPath="${projectDir}/../geode-core/src/main/java"
  coreEpisode="${projectDir}/../etc/geode-core.episode"

  outputDir="${projectDir}/build/generated-src/main/"
  outputPackage="org.apache.geode.cache.configuration"
  outputEpisode="${projectDir}/../etc/geode-lucene.episode"

  mkdir -p ${outputDir}
  xjc -extension -p ${outputPackage} -d ${outputDir} -episode ${outputEpisode} -no-header -b ${coreEpisode} -b ${jaxBindings} -classpath ${classPath} -contentForWildcard -npa ${sourceXsd}
}

generate-core
generate-connectors
generate-lucene
