Class MavenProperties

java.lang.Object
java.util.AbstractMap<String,String>
org.apache.maven.cling.props.MavenProperties
All Implemented Interfaces:
Map<String,String>

public class MavenProperties extends AbstractMap<String,String>
Enhancement of the standard Properties managing the maintain of comments, etc.
  • Constructor Details Link icon

    • MavenProperties Link icon

      public MavenProperties()
    • MavenProperties Link icon

      public MavenProperties(Path location) throws IOException
      Throws:
      IOException
    • MavenProperties Link icon

      public MavenProperties(Path location, Function<String,String> callback) throws IOException
      Throws:
      IOException
    • MavenProperties Link icon

      public MavenProperties(boolean substitute)
    • MavenProperties Link icon

      public MavenProperties(Path location, boolean substitute)
  • Method Details Link icon

    • load Link icon

      public void load(Path location) throws IOException
      Throws:
      IOException
    • load Link icon

      public void load(URL location) throws IOException
      Throws:
      IOException
    • load Link icon

      public void load(InputStream is) throws IOException
      Throws:
      IOException
    • load Link icon

      public void load(Reader reader) throws IOException
      Throws:
      IOException
    • save Link icon

      public void save() throws IOException
      Throws:
      IOException
    • save Link icon

      public void save(Path location) throws IOException
      Throws:
      IOException
    • save Link icon

      public void save(OutputStream os) throws IOException
      Throws:
      IOException
    • save Link icon

      public void save(Writer writer) throws IOException
      Throws:
      IOException
    • store Link icon

      public void store(OutputStream os, String comment) throws IOException
      Store a properties into a output stream, preserving comments, special character, etc. This method is mainly to be compatible with the java.util.Properties class.
      Parameters:
      os - an output stream.
      comment - this parameter is ignored as this Properties
      Throws:
      IOException - If storing fails
    • getProperty Link icon

      public String getProperty(String key)
      Searches for the property with the specified key in this property list.
      Parameters:
      key - the property key.
      Returns:
      the value in this property list with the specified key value.
    • getProperty Link icon

      public String getProperty(String key, String defaultValue)
      Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.
      Parameters:
      key - the property key.
      defaultValue - a default value.
      Returns:
      The property value of the default value
    • entrySet Link icon

      public Set<Map.Entry<String,String>> entrySet()
      Specified by:
      entrySet in interface Map<String,String>
      Specified by:
      entrySet in class AbstractMap<String,String>
    • propertyNames Link icon

      public Enumeration<?> propertyNames()
      Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.
      Returns:
      an enumeration of all the keys in this property list, including the keys in the default property list.
    • setProperty Link icon

      public Object setProperty(String key, String value)
      Calls the map method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the map call to put.
      Parameters:
      key - the key to be placed into this property list.
      value - the value corresponding to the key.
      Returns:
      the previous value of the specified key in this property list, or null if it did not have one.
    • put Link icon

      public String put(String key, String value)
      Specified by:
      put in interface Map<String,String>
      Overrides:
      put in class AbstractMap<String,String>
    • put Link icon

      public String put(String key, List<String> commentLines, List<String> valueLines)
    • put Link icon

      public String put(String key, List<String> commentLines, String value)
    • put Link icon

      public String put(String key, String comment, String value)
    • update Link icon

      public boolean update(Map<String,String> props)
    • update Link icon

      public boolean update(MavenProperties properties)
    • getRaw Link icon

      public List<String> getRaw(String key)
    • getComments Link icon

      public List<String> getComments(String key)
    • remove Link icon

      public String remove(Object key)
      Specified by:
      remove in interface Map<String,String>
      Overrides:
      remove in class AbstractMap<String,String>
    • clear Link icon

      public void clear()
      Specified by:
      clear in interface Map<String,String>
      Overrides:
      clear in class AbstractMap<String,String>
    • getHeader Link icon

      public List<String> getHeader()
      Return the comment header.
      Returns:
      the comment header
    • setHeader Link icon

      public void setHeader(List<String> header)
      Set the comment header.
      Parameters:
      header - the header to use
    • getFooter Link icon

      public List<String> getFooter()
      Return the comment footer.
      Returns:
      the comment footer
    • setFooter Link icon

      public void setFooter(List<String> footer)
      Set the comment footer.
      Parameters:
      footer - the footer to use
    • loadLayout Link icon

      protected void loadLayout(Reader in, boolean maybeTyped) throws IOException
      Reads a properties file and stores its internal structure. The found properties will be added to the associated configuration object.
      Parameters:
      in - the reader to the properties file
      Throws:
      IOException - if an error occurs
    • substitute Link icon

      public void substitute()
    • substitute Link icon

      public void substitute(Function<String,String> callback)
    • saveLayout Link icon

      protected void saveLayout(Writer out, boolean typed) throws IOException
      Writes the properties file to the given writer, preserving as much of its structure as possible.
      Parameters:
      out - the writer
      Throws:
      IOException - if an error occurs
    • unescapeJava Link icon

      protected static String unescapeJava(String str)

      Unescapes any Java literals found in the String to a Writer.

      This is a slightly modified version of the StringEscapeUtils.unescapeJava() function in commons-lang that doesn't drop escaped separators (i.e '\,').
      Parameters:
      str - the String to unescape, may be null
      Returns:
      the processed string
      Throws:
      IllegalArgumentException - if the Writer is null
    • escapeJava Link icon

      protected static String escapeJava(String str)

      Escapes the characters in a String using Java String rules.

      Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

      So a tab becomes the characters '\\' and 't'.

      The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

      Example:

       input string: He didn't say, "Stop!"
       output string: He didn't say, \"Stop!\"
       
      Parameters:
      str - String to escape values in, may be null
      Returns:
      String with escaped values, null if null string input
    • hex Link icon

      protected static String hex(char ch)

      Returns an upper case hexadecimal String for the given character.

      Parameters:
      ch - The character to convert.
      Returns:
      An upper case hexadecimal String
    • contains Link icon

      public static boolean contains(char[] array, char valueToFind)

      Checks if the value is in the given array.

      The method returns false if a null array is passed in.

      Parameters:
      array - the array to search through
      valueToFind - the value to find
      Returns:
      true if the array contains the object