test_class.declarator: tmpFolder= new TemporaryFolder()
test_class.modifier: @Rule
    public
test_class.original_string: @Rule
    public TemporaryFolder tmpFolder= new TemporaryFolder();
test_class.type: TemporaryFolder
test_class.var_name: tmpFolder
test_class.file: kilt-core/src/test/java/de/poiu/kilt/importexport/XlsImExporterTest.java
test_class.identifier: XlsImExporterTest
test_case.body: @Test
    public void testImportXls_MissingKeys_Delete() throws IOException, URISyntaxException {
  
      // - preparation
  
      final Path propertiesRootDirectory= this.tmpFolder.getRoot().toPath();
      final Set<File> resourceBundleFiles= ImmutableSet.of(
        copyResourceToTmp("i18n/messages.properties"),
        copyResourceToTmp("i18n/messages_de.properties"));
  
      final FileMatcher fileMatcher= this.createFileMatcher(propertiesRootDirectory, resourceBundleFiles);
  
      final File xlsFile= new File(Resources.getResource("i18n_line_deleted.xlsx").toURI());
  
      // - test
  
      XlsImExporter.importXls(fileMatcher, xlsFile, UTF_8, MissingKeyAction.DELETE);
  
      // - verification
  
      final Path[] writtenResourceBundleFiles = Files.list(propertiesRootDirectory.resolve("i18n")).toArray(Path[]::new);
      assertThat(writtenResourceBundleFiles).containsOnly(
        propertiesRootDirectory.resolve("i18n/messages.properties"),
        propertiesRootDirectory.resolve("i18n/messages_de.properties")
      );
      assertThat(propertiesRootDirectory.resolve("i18n").resolve("messages.properties").toFile())
        .hasContent(""
          + "cancel = Cancel\n"
          + "\n");
      assertThat(propertiesRootDirectory.resolve("i18n").resolve("messages_de.properties").toFile())
        .hasContent(""
          + "cancel = Abbrechen\n"
          + "\n");
    }
test_case.class_method_signature: XlsImExporterTest.testImportXls_MissingKeys_Delete()
test_case.full_signature: @Test public void testImportXls_MissingKeys_Delete()
test_case.identifier: testImportXls_MissingKeys_Delete
test_case.invocations: toPath getRoot of copyResourceToTmp copyResourceToTmp createFileMatcher toURI getResource importXls toArray list resolve containsOnly assertThat resolve resolve hasContent assertThat toFile resolve resolve hasContent assertThat toFile resolve resolve
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testImportXls_MissingKeys_Delete()
focal_class.declarator: LOGGER= LogManager.getLogger()
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER= LogManager.getLogger();
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.file: kilt-core/src/main/java/de/poiu/kilt/importexport/XlsImExporter.java
focal_class.identifier: XlsImExporter
focal_class.class_method_signature: XlsImExporter.importXls(final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)
focal_class.full_signature: public static void importXls(final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)
focal_class.identifier: importXls
focal_class.modifiers: public static
focal_class.parameters: (final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)
focal_class.return: void
focal_class.signature: void importXls(final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)
focal_class.class_method_signature: XlsImExporter.exportXls(final FileMatcher fileMatcher,
                                 final Charset propertyFileEncoding,
                                 final File xlsFile)
focal_class.full_signature: public static void exportXls(final FileMatcher fileMatcher,
                                 final Charset propertyFileEncoding,
                                 final File xlsFile)
focal_class.identifier: exportXls
focal_class.modifiers: public static
focal_class.parameters: (final FileMatcher fileMatcher,
                                 final Charset propertyFileEncoding,
                                 final File xlsFile)
focal_class.return: void
focal_class.signature: void exportXls(final FileMatcher fileMatcher,
                                 final Charset propertyFileEncoding,
                                 final File xlsFile)
focal_class.class_method_signature: XlsImExporter.getFileForBundle(final File propertiesRootDirectory, final String bundleBasename, final Language language)
focal_class.full_signature: private static File getFileForBundle(final File propertiesRootDirectory, final String bundleBasename, final Language language)
focal_class.identifier: getFileForBundle
focal_class.modifiers: private static
focal_class.parameters: (final File propertiesRootDirectory, final String bundleBasename, final Language language)
focal_class.return: File
focal_class.signature: File getFileForBundle(final File propertiesRootDirectory, final String bundleBasename, final Language language)
focal_method.body: public static void importXls(final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction) {
      Require.nonNull(fileMatcher);
      Require.nonNull(xlsFile);
  
      final ApronOptions apronOptions= ApronOptions.create()
        .with(propertyFileEncoding != null ? propertyFileEncoding : UTF_8)
        .with(missingKeyAction);
  
      // read XLS file
      final XlsFile xlsFileObject= new XlsFile(xlsFile);
      final Map<I18nBundleKey, Collection<Translation>> content= xlsFileObject.getContent();
  
      // stores the mapping of resource bundle basenames and languages to the corresponding property files
      final Map<String, Map<Language, RememberingPropertyFile>> bundleFileMapping= new LinkedHashMap<>();
  
      // FIXME: Sort by bundleBasename and language? In that case we only have to have 1 property file open at a time
      content.entrySet().forEach((entry) -> {
        final I18nBundleKey bundleKey= entry.getKey();
        final String bundleBasename= bundleKey.getBundleBaseName();
        final String propertyKey= bundleKey.getKey();
        final Collection<Translation> translations= entry.getValue();
  
        // for each bundle…
        for (final Translation translation : translations) {
          if (!bundleFileMapping.containsKey(bundleBasename)) {
            bundleFileMapping.put(bundleBasename, new LinkedHashMap<>());
          }
  
          if (!bundleFileMapping.get(bundleBasename).containsKey(translation.getLang())) {
            final File fileForBundle= getFileForBundle(fileMatcher.getRoot().toFile(), bundleBasename, translation.getLang());
  
            if (!fileMatcher.matches(fileForBundle.toPath())) {
              LOGGER.log(Level.DEBUG, "Skipping import to file {} since it does not match inclusion pattern", fileForBundle);
              continue;
            }
  
            final PropertyFile propertyFile= new PropertyFile();
            bundleFileMapping.get(bundleBasename).put(translation.getLang(), new RememberingPropertyFile(fileForBundle, propertyFile));
          }
  
          final RememberingPropertyFile rpf= bundleFileMapping.get(bundleBasename).get(translation.getLang());
          // only write empty values if the key already exists in in the PropertyFile
          if ((translation.getValue() != null && !translation.getValue().isEmpty())
            || rpf.propertyFile.containsKey(propertyKey)) {
            rpf.propertyFile.setValue(propertyKey, translation.getValue());
          }
        }
      });
  
      //now write the property files back to disk
      bundleFileMapping.values().forEach((Map<Language, RememberingPropertyFile> langPropMap) -> {
        langPropMap.values().forEach((RememberingPropertyFile rpf) -> {
          // only write files if they have some content (avoid creating unwanted empty files for unsupported locales)
          if (rpf.propertyFile.propertiesSize()> 0) {
            rpf.propertyFile.saveTo(rpf.actualFile, apronOptions);
          }
        });
      });
    }
focal_method.class_method_signature: XlsImExporter.importXls(final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)
focal_method.full_signature: public static void importXls(final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)
focal_method.identifier: importXls
focal_method.invocations: nonNull nonNull with with create getContent forEach entrySet getKey getBundleBaseName getKey getValue containsKey put containsKey get getLang getFileForBundle toFile getRoot getLang matches toPath log put get getLang get get getLang getValue isEmpty getValue containsKey setValue getValue forEach values forEach values propertiesSize saveTo
focal_method.modifiers: public static
focal_method.parameters: (final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)
focal_method.return: void
focal_method.signature: void importXls(final FileMatcher fileMatcher,
                                 final File xlsFile,
                                 final Charset propertyFileEncoding,
                                 final MissingKeyAction missingKeyAction)