Package com.famaridon.maven.scoped.properties.exceptions

Examples of com.famaridon.maven.scoped.properties.exceptions.BuildPropertiesFilesException


    {
      jaxbContext = JAXBContext.newInstance(Wrapper.class, Property.class);
      unmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e)
    {
      throw new BuildPropertiesFilesException(e.getMessage(), e);
    }

    File[] propertiesXmlFiles = propertiesXmlFolder.listFiles((FileFilter) new SuffixFileFilter(".properties.xml"));
    Set<File> outputFileSet = new HashSet<>(propertiesXmlFiles.length);
    for (File propertiesXml : propertiesXmlFiles)
    {
      try (FileInputStream inputStream = new FileInputStream(propertiesXml);
         Reader reader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));)
      {
        Wrapper<Property> wrapper = (Wrapper<Property>) unmarshaller.unmarshal(propertiesXml);

        Properties properties = new Properties();
        for (Property property : wrapper.getItems())
        {
          String value = property.getValues().get(targetScope);
          if ( StringUtils.isEmpty(value) )
          {
            value = property.getDefaultValue();
          }
          properties.setProperty(property.getName(), value);
        }

        File outputFile = new File(outputFolder, FilenameUtils.getBaseName(propertiesXml.getName()));
        // never use a writer with stream unicode char is encoded.
        try (FileOutputStream outputStream = new FileOutputStream(outputFile))
        {
          properties.store(outputStream, "Maven plugin building file for scope : " + targetScope);
        } catch (IOException e)
        {
          throw new BuildPropertiesFilesException("can't write properties file", e);
        }

        outputFileSet.add(outputFile);

      } catch (JAXBException | IOException e)
      {
        throw new BuildPropertiesFilesException("can't read xml file : " + propertiesXml.getAbsolutePath(), e);
      }

    }
    return outputFileSet;
  }
View Full Code Here

TOP

Related Classes of com.famaridon.maven.scoped.properties.exceptions.BuildPropertiesFilesException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.