Class ProjectsUtil


  • public class ProjectsUtil
    extends Object
    A class that provides utility methods related to blocks projects.
    • Method Detail

      • fetchProjectsWithBlocks

        public static String fetchProjectsWithBlocks()
        Returns the names and last modified time of existing blocks projects that have a blocks file.
      • escapeSingleQuotes

        public static String escapeSingleQuotes​(String s)
      • escapeDoubleQuotes

        public static String escapeDoubleQuotes​(String s)
      • fetchProjectsForOfflineBlocksEditor

        public static void fetchProjectsForOfflineBlocksEditor​(List<com.google.blocks.ftcrobotcontroller.util.OfflineBlocksProject> offlineBlocksProjects)
                                                        throws IOException
        Collects information about the existing blocks projects, for the offline blocks editor.
        Throws:
        IOException
      • fetchProjects

        public static void fetchProjects​(List<com.google.blocks.ftcrobotcontroller.util.BlocksProject> blocksProjects)
                                  throws IOException
        Collects information about the existing blocks projects.
        Throws:
        IOException
      • fetchEnabledProjectsWithJavaScript

        public static List<org.firstinspires.ftc.robotcore.internal.opmode.OpModeMeta> fetchEnabledProjectsWithJavaScript()
        Returns the OpModeMeta for existing blocks projects that have a JavaScript file and are enabled.
      • isValidProjectName

        public static boolean isValidProjectName​(String projectName)
        Returns true if the given project name is not null and contains only valid characters. This function does not check whether the project exists.
      • fetchBlkFileContent

        public static String fetchBlkFileContent​(String projectName)
                                          throws IOException
        Returns the content of the blocks file with the given project name. The returned content may include extra XML after the blocks XML.
        Parameters:
        projectName - the name of the project
        Throws:
        IOException
      • fetchJsFileContent

        public static String fetchJsFileContent​(String projectName)
                                         throws IOException
        Returns the content of the JavaScript file with the given project name.
        Parameters:
        projectName - the name of the project
        Throws:
        IOException
      • newProject

        public static String newProject​(String projectName,
                                        String sampleName)
                                 throws IOException
        Returns the content of the blocks file for a new project. Note that this method does not save the project. It just creates the content.
        Parameters:
        projectName - the name of the project
        sampleName - the name of the sample to copy.
        Returns:
        the content of the blocks file
        Throws:
        IOException
      • saveProject

        public static void saveProject​(String projectName,
                                       String blkFileContent,
                                       String jsFileContent)
                                throws IOException
        Save the blocks file and JavaScript file with the given project name.
        Parameters:
        projectName - the name of the project
        blkFileContent - the content to write to the blocks file.
        jsFileContent - the content to write to the JavaScript file.
        Throws:
        IOException
      • renameProject

        public static void renameProject​(String oldProjectName,
                                         String newProjectName)
                                  throws IOException
        Renames the blocks file and JavaScript file with the given project name.
        Parameters:
        oldProjectName - the old name of the project
        newProjectName - the new name of the project
        Throws:
        IOException
      • copyProject

        public static void copyProject​(String oldProjectName,
                                       String newProjectName)
                                throws IOException
        Copies the blocks file and JavaScript file with the given project name.
        Parameters:
        oldProjectName - the old name of the project
        newProjectName - the new name of the project
        Throws:
        IOException
      • enableProject

        public static void enableProject​(String projectName,
                                         boolean enable)
                                  throws IOException
        Enables (or disables) the project with the given name.
        Parameters:
        projectName - the name of the project
        enable - whether to enable (or disable) the project
        Throws:
        IOException
      • deleteProjects

        public static Boolean deleteProjects​(String[] projectNames)
        Delete the blocks and JavaScript files for the given project names.
        Parameters:
        projectNames - the names of the projects to delete
      • getBlocksJavaClassName

        public static String getBlocksJavaClassName​(String projectName)
      • saveBlocksJava

        public static void saveBlocksJava​(String relativeFileName,
                                          String javaContent)
                                   throws IOException
        Save the Java generated from blocks.
        Parameters:
        relativeFileName - the name of the file
        javaContent - the content to write to the Java file.
        Throws:
        IOException