package org.apache.maven.yml2prop;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.StringUtils;
import org.yaml.snakeyaml.Yaml;

@Mojo(name = "run")
public class Yml2Prop extends AbstractMojo {

   @Parameter(alias = "sourceYaml", required = true)
   private String sourceYaml;

   @Parameter(alias = "entries", required = true)
   private String[] entryNames;

   @Parameter(alias = "destProp", defaultValue = "${basedir}/src/main/resources/application.properties")
   private String destProp;

   @SuppressWarnings("unchecked")
   public void execute() throws MojoExecutionException, MojoFailureException {
      try {
         Yaml yaml = new Yaml();
         Map<String, Object> map = (Map<String, Object>) yaml.load(new FileInputStream(new File(sourceYaml)));
         Properties properties = new Properties();
         for (String entryName : entryNames) {
            if (StringUtils.isEmpty(entryName)) {
               continue;
            }
            Map<String, Object> entry = (Map<String, Object>) map.get(entryName);
            getLog()
                  .info(String.format("Found entry[%s] we do merge them now, please wait for a min......", entryName));
            iterateAndProcess(properties, entry, "");
         }
         properties.store(new FileOutputStream(new File(destProp)), "Generated by Yml2Prop plugin.");
      }
      catch (FileNotFoundException e) {
         getLog().error(String.format("File %s not found", sourceYaml));
         throw new MojoExecutionException(String.format("File %s not found", sourceYaml), e);
      }
      catch (IOException e) {
         getLog().error(String.format("File %s can not be written", destProp));
         throw new MojoExecutionException(String.format("File %s can not be written", sourceYaml), e);
      }
   }

   @SuppressWarnings("unchecked")
   private void iterateAndProcess(Properties properties, Map<String, Object> ymlEntry, String rootKey) {
      for (String key : ymlEntry.keySet()) {
         Object value = ymlEntry.get(key);
         if (value instanceof String || value instanceof List) {
            properties.setProperty(rootKey.length() == 0 ? key : rootKey + "." + key, value.toString());
         }
         else if (value instanceof Map) {
            iterateAndProcess(properties, (Map<String, Object>) value, rootKey.length() == 0 ? key : rootKey + "."
                  + key);
         }
      }
   }
}

@@ -2582,37 +2582,44 @@
 roperty(
-rootKey.length() == 0
+StringUtils.isEmpty(rootKey)
  ? key :
@@ -2787,29 +2787,36 @@
 ue, 
-rootKey.length() == 0
+StringUtils.isEmpty(rootKey)
  ? k

Use StringUtils.empty