public Mary4To5VoiceConverter(List<VoiceComponentDescription> voiceDescriptions, File voiceZip) {
   voiceDescription = null;
   mary4Zip = voiceZip;
   for (VoiceComponentDescription d : voiceDescriptions) {
     if (d.getPackageFilename().equals(mary4Zip.getName())) {
       voiceDescription = d;
       break;
     }
   }
   if (voiceDescription == null) {
     throw new IllegalArgumentException(
         "No matching voice description for file " + mary4Zip.getName());
   }
   if (!MaryUtils.isLog4jConfigured()) {
     BasicConfigurator.configure();
   }
   logger = Logger.getLogger(this.getClass());
   logger.info(
       voiceDescription.getName()
           + " "
           + voiceDescription.getVersion()
           + " ("
           + voiceDescription.getLocale()
           + " "
           + voiceDescription.getGender()
           + ")");
 }
 private void updateVoiceDescription(File rootDir, File packageFile)
     throws MalformedURLException, ParserConfigurationException, MaryConfigurationException,
         IOException {
   logger.debug("writing new voice description...");
   voiceDescription.setVersion(Version.specificationVersion());
   voiceDescription.setDependsVersion(Version.specificationVersion());
   voiceDescription.setPackageFilename(packageFile.getName());
   voiceDescription.setPackageMD5Sum(computeMD5(packageFile));
   voiceDescription.setPackageSize((int) packageFile.length());
   voiceDescription.removeAllLocations();
   voiceDescription.addLocation(
       URI.create("http://mary.dfki.de/download/" + Version.specificationVersion() + "/").toURL());
   Document doc = voiceDescription.createComponentXML();
   File newVoiceDescriptionFile = new File(rootDir, getFilenamePrefix() + "-component.xml");
   DomUtils.document2File(doc, newVoiceDescriptionFile);
   logger.debug("... created " + newVoiceDescriptionFile.getPath());
 }
 private String getFilenamePrefix() {
   return "voice-" + voiceDescription.getName() + "-" + Version.specificationVersion();
 }
 private String getVoiceNameFromVoiceDescription() {
   return voiceDescription.getName();
 }
 private void addNewProps() {
   config.setProperty("locale", voiceDescription.getLocale().toString());
 }
  private void convert() throws Exception {
    logger.info("converting...");
    File rootDir = mary4Zip.getParentFile();
    extractedDir =
        new File(rootDir, voiceDescription.getName() + "-" + voiceDescription.getVersion());
    logger.debug("... extracting archive to " + extractedDir.getPath());
    if (extractedDir.exists()) {
      logger.debug("Folder " + extractedDir.getPath() + " exists, trying to delete...");
      extractedDir.delete();
    }
    FileUtils.unzipArchive(mary4Zip, extractedDir);

    loadConfig(findConfigFile());

    compileDir =
        new File(
            rootDir, voiceDescription.getName() + "-" + Version.specificationVersion() + "-maven");

    domain = config.getProperty(getPropertyPrefix() + "domain");
    samplingRate = Integer.parseInt(config.getProperty(getPropertyPrefix() + "samplingRate"));

    filesForResources = getFilesForResources();
    filesForFilesystem = getFilesForFilesystem();
    Map<String, String> extraVariablesToSubstitute = null;

    compiler =
        new VoiceCompiler.MavenVoiceCompiler(
            compileDir,
            getVoiceName(),
            Version.specificationVersion(),
            voiceDescription.getLocale(),
            voiceDescription.getGender(),
            domain,
            samplingRate,
            isUnitSelectionVoice(),
            filesForResources,
            filesForFilesystem,
            extraVariablesToSubstitute);

    logger.debug("Creating directories");
    compiler.createDirectories();

    logger.debug("Copying template files");
    compiler.copyTemplateFiles();

    updateConfig(compiler.getPackageName());
    saveConfig(compiler.getConfigFile());

    logger.debug("Copying voice files");
    compiler.copyVoiceFiles();

    if (!isUnitSelectionVoice()) {
      logger.debug("Converting HMM PDF files from Mary 4.0 to Mary 5.0 format");
      convertMary4ToMary5HmmPdfFiles(compiler.getMainResourcesDir());
    }

    logger.debug("Compiling with Maven");
    compiler.compileWithMaven();

    String convertedZipFilename = getFilenamePrefix() + ".zip";
    File convertedZipFile = new File(compileDir + "/target/" + convertedZipFilename);
    if (!convertedZipFile.exists()) {
      throw new IOException(
          "Maven should have created file "
              + convertedZipFile.getAbsolutePath()
              + " but file does not exist.");
    }

    updateVoiceDescription(rootDir, convertedZipFile);

    File finalZipFile = new File(rootDir, convertedZipFilename);
    if (finalZipFile.exists()) {
      finalZipFile.delete();
    }
    boolean success = convertedZipFile.renameTo(finalZipFile);
    if (!success) {
      throw new IOException(
          "Failure trying to move "
              + convertedZipFile.getAbsolutePath()
              + " to "
              + finalZipFile.getAbsolutePath());
    }
  }