// Path: src/main/java/io/apigee/buildTools/enterprise4g/utils/ConfigTokens.java
// public class Policy {
// 
// 	@Key
// 	public String name;
// 	@Key
// 	public List<Token> tokens;
// 	public String getName() {
// 		return name;
// 	}
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 	public List<Token> getTokens() {
// 		return tokens;
// 	}
// 	public void setTokens(List<Token> tokens) {
// 		this.tokens = tokens;
// 	}
// }


import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.apigee.buildTools.enterprise4g.utils.ConfigTokens.Policy;
import java.io.File;
import java.util.List;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
            // sets the description to whatever is in the <proxyname>.xml file
            node.setTextContent(expression.evaluate(xmlDoc));
        } else {
            // if Description is empty, then it reverts back to appending the username, git hash, etc
            node.setTextContent(getComment(fileList.get(0)));
        }

        DOMSource source = new DOMSource(xmlDoc);
        StreamResult result = new StreamResult(fileList.get(0));
        //Fix for https://github.com/apigee/apigee-deploy-maven-plugin/issues/66
        result.setSystemId(fileList.get(0).getAbsolutePath());
        transformer.transform(source, result);

    }

    public static Document replaceTokens(Document doc, Policy configTokens)
            throws XPathExpressionException, TransformerConfigurationException {

        Logger logger = LogManager.getLogger(PackageConfigurer.class);

        javax.xml.xpath.XPathFactory factory = javax.xml.xpath.XPathFactory
                .newInstance();
        javax.xml.xpath.XPath xpath = factory.newXPath();

        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String json = gson.toJson(configTokens);
        logger.info(
                "============= to apply the following config tokens ================\n{}",
                json);

// Path: src/main/java/io/apigee/buildTools/enterprise4g/utils/ConfigTokens.java
// public class Policy {
// 
// 	@Key
// 	public String name;
// 	@Key
// 	public List<Token> tokens;
// 	public String getName() {
// 		return name;
// 	}
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 	public List<Token> getTokens() {
// 		return tokens;
// 	}
// 	public void setTokens(List<Token> tokens) {
// 		this.tokens = tokens;
// 	}
// }


// Path: src/main/java/io/apigee/buildTools/enterprise4g/utils/PackageConfigurer.java
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.apigee.buildTools.enterprise4g.utils.ConfigTokens.Policy;
import java.io.File;
import java.util.List;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

            // sets the description to whatever is in the <proxyname>.xml file
            node.setTextContent(expression.evaluate(xmlDoc));
        } else {
            // if Description is empty, then it reverts back to appending the username, git hash, etc
            node.setTextContent(getComment(fileList.get(0)));
        }

        DOMSource source = new DOMSource(xmlDoc);
        StreamResult result = new StreamResult(fileList.get(0));
        //Fix for https://github.com/apigee/apigee-deploy-maven-plugin/issues/66
        result.setSystemId(fileList.get(0).getAbsolutePath());
        transformer.transform(source, result);

    }

    public static Document replaceTokens(Document doc, Policy configTokens)
            throws XPathExpressionException, TransformerConfigurationException {

        Logger logger = LogManager.getLogger(PackageConfigurer.class);

        javax.xml.xpath.XPathFactory factory = javax.xml.xpath.XPathFactory
                .newInstance();
        javax.xml.xpath.XPath xpath = factory.newXPath();

        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String json = gson.toJson(configTokens);
        logger.info(
                "============= to apply the following config tokens ================\n{}",
                json);

        try {