<?xml version="1.0"?>

<project name="license-gen" default="generateLicense" basedir="." xmlns:artifact="urn:maven-artifact-ant">
  
  <target name="generateLicense">
           
    <echo>ant.version: ${ant.version}</echo>
       
    <property name="rhq.version" value="1.3.0-SNAPSHOT" />
    <echo>rhq.version: ${rhq.version}</echo>
    <echo/>    
        
    <property name="default.rhq.license.name" value="RHQ User" />
    <property name="default.rhq.license.email" value="sales@jboss.com" />
    <property name="default.rhq.license.phone" value="888-555-1212" />
    <property name="default.rhq.license.max-platforms" value="*" />
    <property name="default.rhq.license.ip-addresses" value="*" />
    <property name="default.rhq.license.plugins" value="*" />
    <property name="default.rhq.license.support-level" value="3" />
  
    <property name="localRepository" location="${user.home}/.m2/repository" />
    <!--<echo>localRepository: ${localRepository}</echo>-->
    
    <property name="alt.localRepository" location="C:/.m2-repo" />
    <!--<echo>alt.localRepository: ${alt.localRepository}</echo>-->
  
    <tstamp>
      <format property="default.rhq.license.expire-date" pattern="yyyy-MM-dd" offset="1" unit="month" />
    </tstamp>
  
    <echo>Please enter the following license parameters (hit Enter to accept defaults)...</echo>
    
    <input message="Name [${default.rhq.license.name}]:" addproperty="rhq.license.name" defaultvalue="${default.rhq.license.name}" />
    <input message="Email address [${default.rhq.license.email}]:" addproperty="rhq.license.email" defaultvalue="${default.rhq.license.email}" />
    <input message="Phone number [${default.rhq.license.phone}]:" addproperty="rhq.license.phone" defaultvalue="${default.rhq.license.phone}" />
    <input message="Expiration date (yyyy-MM-dd) (*=never) [${default.rhq.license.expire-date}]:" addproperty="rhq.license.expire-date" defaultvalue="${default.rhq.license.expire-date}" />
    <input message="Maximum platforms (*=unlimited) [${default.rhq.license.max-platforms}]:" addproperty="rhq.license.max-platforms" defaultvalue="${default.rhq.license.max-platforms}" />
    <input message="Allowed IP addresses (*=any) [${default.rhq.license.ip-addresses}]:" addproperty="rhq.license.ip-addresses" defaultvalue="${default.rhq.license.ip-addresses}" />
    <input message="Allowed plugins (*=any) [${default.rhq.license.plugins}]:" addproperty="rhq.license.plugins" defaultvalue="${default.rhq.license.plugins}" />
    <input message="Support level (1-3) [${default.rhq.license.support-level}]:" addproperty="rhq.license.support-level" defaultvalue="${default.rhq.license.support-level}" />

    <echo>Generating license...</echo>
                              
    <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant">
      <classpath>
        <pathelement location="${localRepository}/org/apache/maven/maven-artifact-ant/2.0.4/maven-artifact-ant-2.0.4.jar" />
        <pathelement location="${alt.localRepository}/org/apache/maven/maven-artifact-ant/2.0.4/maven-artifact-ant-2.0.4.jar" />
      </classpath>
    </typedef>

    <artifact:dependencies pathId="license-generator.classpath">
      <dependency groupId="org.rhq" artifactId="rhq-enterprise-server-license-gen" version="${rhq.version}"/>
    </artifact:dependencies>
    
    <mkdir dir="target" />
    <property name="license.file" value="target${file.separator}rhq-license.xml" />
    
    <java classname="org.rhq.enterprise.server.license.LicenseGenerator" classpathref="license-generator.classpath" output="${license.file}" logError="true">
      <arg value="${rhq.license.name}" />
      <arg value="${rhq.license.email}" />
      <arg value="${rhq.license.phone}" />
      <arg value="${rhq.license.expire-date}" />
      <arg value="${rhq.license.max-platforms}" />
      <arg value="${rhq.license.ip-addresses}" />
      <arg value="${rhq.license.plugins}" />
      <arg value="${rhq.license.support-level}" />
    </java>
    
    <echo>Done. License file written to ${license.file}</echo>
    
  </target>
  
</project>