Class ProjectsUtil
- java.lang.Object
-
- com.google.blocks.ftcrobotcontroller.util.ProjectsUtil
-
public class ProjectsUtil extends Object
A class that provides utility methods related to blocks projects.
-
-
Field Summary
Fields Modifier and Type Field Description static String
TAG
static String
VALID_PROJECT_REGEX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyProject(String oldProjectName, String newProjectName)
Copies the blocks file and JavaScript file with the given project name.static Boolean
deleteProjects(String[] projectNames)
Delete the blocks and JavaScript files for the given project names.static void
enableProject(String projectName, boolean enable)
Enables (or disables) the project with the given name.static String
escapeDoubleQuotes(String s)
static String
escapeSingleQuotes(String s)
static String
fetchBlkFileContent(String projectName)
Returns the content of the blocks file with the given project name.static List<org.firstinspires.ftc.robotcore.internal.opmode.OpModeMeta>
fetchEnabledProjectsWithJavaScript()
Returns theOpModeMeta
for existing blocks projects that have a JavaScript file and are enabled.static String
fetchJsFileContent(String projectName)
Returns the content of the JavaScript file with the given project name.static void
fetchProjects(List<com.google.blocks.ftcrobotcontroller.util.BlocksProject> blocksProjects)
Collects information about the existing blocks projects.static void
fetchProjectsForOfflineBlocksEditor(List<com.google.blocks.ftcrobotcontroller.util.OfflineBlocksProject> offlineBlocksProjects)
Collects information about the existing blocks projects, for the offline blocks editor.static String
fetchProjectsWithBlocks()
Returns the names and last modified time of existing blocks projects that have a blocks file.static String
fetchSampleNames()
Returns the names of blocks samplesstatic String
getBlocksJavaClassName(String projectName)
static boolean
isValidProjectName(String projectName)
Returns true if the given project name is not null and contains only valid characters.static String
newProject(String projectName, String sampleName)
Returns the content of the blocks file for a new project.static void
renameProject(String oldProjectName, String newProjectName)
Renames the blocks file and JavaScript file with the given project name.static void
saveBlocksJava(String relativeFileName, String javaContent)
Save the Java generated from blocks.static void
saveProject(String projectName, String blkFileContent, String jsFileContent)
Save the blocks file and JavaScript file with the given project name.
-
-
-
Field Detail
-
TAG
public static final String TAG
- See Also:
- Constant Field Values
-
VALID_PROJECT_REGEX
public static final String VALID_PROJECT_REGEX
- See Also:
- Constant Field Values
-
-
Method Detail
-
fetchProjectsWithBlocks
public static String fetchProjectsWithBlocks()
Returns the names and last modified time of existing blocks projects that have a blocks file.
-
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
-
fetchSampleNames
public static String fetchSampleNames() throws IOException
Returns the names of blocks samples- Throws:
IOException
-
fetchEnabledProjectsWithJavaScript
public static List<org.firstinspires.ftc.robotcore.internal.opmode.OpModeMeta> fetchEnabledProjectsWithJavaScript()
Returns theOpModeMeta
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 projectsampleName
- 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 projectblkFileContent
- 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 projectnewProjectName
- 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 projectnewProjectName
- 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 projectenable
- 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
-
saveBlocksJava
public static void saveBlocksJava(String relativeFileName, String javaContent) throws IOException
Save the Java generated from blocks.- Parameters:
relativeFileName
- the name of the filejavaContent
- the content to write to the Java file.- Throws:
IOException
-
-