/**
   * Generates the metadata filter file
   *
   * @param config the metadata configuration
   * @param file the output filter file
   */
  protected void generateMetadataFilter(MetadataConfig config, File file) throws IOException {
    FileWriter writer = new FileWriter(file);

    for (Map.Entry<String, String> property : config.toProperties().entrySet()) {
      writer.write(property.getKey() + "=" + property.getValue() + "\n");
    }

    writer.close();

    getLog().info("Generated " + file.getPath());
  }
  /**
   * Executes the generate goal
   *
   * @throws org.apache.maven.plugin.MojoExecutionException if an error occurs
   */
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (!metadataDirectory.exists() || !metadataDirectory.isDirectory()) {
      throw new MojoFailureException(
          "Metadata configuration directory "
              + metadataDirectory
              + " doesn't exist or is not a directory");
    }

    try {
      // Instantiate some required DOM tools
      DocumentBuilder documentBuilder = XmlUtils.createBuilder();

      // Load provided distribution configuration
      MetadataConfig distroConfig =
          MetadataConfig.loadFromDirectory(metadataDirectory, documentBuilder, getLog());

      generateMetadataSource(distroConfig, outputDirectory, outputPackage);

      generateMetadataFilter(distroConfig, outputFilterFile);
    } catch (Exception ex) {
      throw new MojoExecutionException("Unexpected error", ex);
    }
  }
 /**
  * Renders metadata references as constant classes organized by type
  *
  * @param sb the string builder
  * @param config the metadata configuration
  * @return the code
  */
 protected void renderReferencesAsClasses(StringBuilder sb, MetadataConfig config) {
   for (String type : config.getSupportedTypes()) {
     renderTypeReferencesAsClass(sb, type, config.getReferencesByType(type));
   }
 }