Class NatureHelper


  • public class NatureHelper
    extends java.lang.Object
    The NatureHelper supports querying and modifying Eclipse nature-like elements without having an Eclipse running.
    Author:
    Niko Nowatzki, Holger Eichelberger
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  NatureHelper.ProjectHandler
      Implements core functionality accessing the project file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static javax.xml.parsers.DocumentBuilderFactory dbFactory  
      static java.lang.String FILE_NAME  
    • Constructor Summary

      Constructors 
      Constructor Description
      NatureHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addNature​(java.io.File project, java.lang.String nature)
      Adds a nature.
      private static boolean checkNature​(org.w3c.dom.Node node, java.lang.String nature)
      Checks whether the text content of the given node matches the given nature.
      private static boolean containsNature​(org.w3c.dom.NodeList nodes, java.lang.String nature)
      Check whether the given nature is represented by at least one node in nodes.
      static boolean hasNature​(java.io.File project, java.lang.String... natures)
      Returns whether at least one of the given natures are attached to project.
      private static boolean hasNature​(NatureHelper.ProjectHandler handler, java.lang.String... natures)
      Returns whether at least one of the given natures are attached to the project represented by handler.
      private static void removeElements​(org.w3c.dom.Node parent, java.lang.String nature)
      Removes all elements with a given nature (as content).
      static void removeNature​(java.io.File project, java.lang.String nature)
      Remove a nature.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • dbFactory

        private static javax.xml.parsers.DocumentBuilderFactory dbFactory
    • Constructor Detail

      • NatureHelper

        public NatureHelper()
    • Method Detail

      • hasNature

        public static boolean hasNature​(java.io.File project,
                                        java.lang.String... natures)
                                 throws java.io.IOException
        Returns whether at least one of the given natures are attached to project.
        Parameters:
        project - the folder representing the "Eclipse" project
        natures - natures which should be included in file.
        Returns:
        true if the nature is attached to project, false else
        Throws:
        java.io.IOException - if reading or writing the project file fails
      • hasNature

        private static boolean hasNature​(NatureHelper.ProjectHandler handler,
                                         java.lang.String... natures)
        Returns whether at least one of the given natures are attached to the project represented by handler.
        Parameters:
        handler - the hendler representing the project
        natures - natures which should be included in file.
        Returns:
        true if the nature is attached to project, false else
      • checkNature

        private static boolean checkNature​(org.w3c.dom.Node node,
                                           java.lang.String nature)
        Checks whether the text content of the given node matches the given nature.
        Parameters:
        node - the node to be checked
        nature - the nature to be considered
        Returns:
        true if the nature is represented by node, false else
      • containsNature

        private static boolean containsNature​(org.w3c.dom.NodeList nodes,
                                              java.lang.String nature)
        Check whether the given nature is represented by at least one node in nodes.
        Parameters:
        nodes - list of nodes to be considered
        nature - the nature to search for
        Returns:
        true if the nature is represented by at least one node in nodes, false else
      • addNature

        public static void addNature​(java.io.File project,
                                     java.lang.String nature)
                              throws java.io.IOException
        Adds a nature.
        Parameters:
        project - the folder representing the "Eclipse" project
        nature - String which should be removed.
        Throws:
        java.io.IOException - if reading or writing the project file fails
      • removeNature

        public static void removeNature​(java.io.File project,
                                        java.lang.String nature)
                                 throws java.io.IOException
        Remove a nature.
        Parameters:
        project - the folder representing the "Eclipse" project
        nature - String which should be removed.
        Throws:
        java.io.IOException - if reading or writing the project file fails
      • removeElements

        private static void removeElements​(org.w3c.dom.Node parent,
                                           java.lang.String nature)
        Removes all elements with a given nature (as content).
        Parameters:
        parent - the parent node to start at
        nature - the nature as content to be removed