Package com.vaadin.copilot
Class ProjectManager
java.lang.Object
com.vaadin.copilot.ProjectManager
Handles reading and writing files in the project
-
Constructor Summary
ConstructorsConstructorDescriptionProjectManager
(ApplicationConfiguration applicationConfiguration) Creates a new project manager -
Method Summary
Modifier and TypeMethodDescriptiongetFileForClass
(Class<?> cls) Returns the Java file for the given class.getFileForClass
(String cls) Returns the Java file for the given class.Tries to find a common package prefix for all Flow views in the project.Returns the frontend folder.The folder where Hilla views should be created for the file system router to pick them up.Returns the java resource folder.Returns the Java source folder.getProjectRelativeName
(File projectFile) Returns the name of the file, relative to the project root.Returns the project root folder.static String
getRelativeName
(File projectFile, File folder) Returns the name of the file, relative to the given folder.getSourceFile
(ComponentTracker.Location location) Returns the Java file for the given component location.Gets current theme folderGets current theme namemakeAbsolute
(String projectRelativeFilename) makeRelative
(String filename) sanitizeFilename
(String name) Makes a string safe to use as a file namevoid
Writes the given content to the given file inside the project.void
Writes the given content to the given file inside the project.writeFileBase64
(String filename, String undoLabel, String base64Content, boolean renameIfExists)
-
Constructor Details
-
ProjectManager
Creates a new project manager- Parameters:
applicationConfiguration
- the application configuration- Throws:
IOException
- if the project folder cannot be resolved
-
-
Method Details
-
readFile
- Throws:
IOException
-
readFile
- Throws:
IOException
-
readLines
- Throws:
IOException
-
writeFile
Writes the given content to the given file inside the project.If the filename is absolute, it is used as is. Otherwise, it is resolved relative to the project root.
If the file is outside the project, an exception is thrown
- Parameters:
filename
- the filename to write to, absolute or relative to the project rootundoLabel
- the undo label for the changecontent
- the content to write- Throws:
IOException
- if the file cannot be written
-
writeFile
Writes the given content to the given file inside the project.If the filename is absolute, it is used as is. Otherwise, it is resolved relative to the project root.
If the file is outside the project, an exception is thrown
- Parameters:
file
- the filename to write to, absolute or relative to the project rootundoLabel
- the undo label for the changecontent
- the content to write- Throws:
IOException
- if the file cannot be written
-
writeFileBase64
public File writeFileBase64(String filename, String undoLabel, String base64Content, boolean renameIfExists) throws IOException - Throws:
IOException
-
makeAbsolute
- Throws:
IOException
-
makeRelative
- Throws:
IOException
-
getProjectRelativeName
Returns the name of the file, relative to the project root.- Parameters:
projectFile
- the file- Returns:
- the relative name of the file
-
getRelativeName
Returns the name of the file, relative to the given folder.- Parameters:
projectFile
- the filefolder
- the folder to make relative to- Returns:
- the relative name of the file
-
getFileForClass
Returns the Java file for the given class.- Parameters:
cls
- the class- Returns:
- the file for the class
-
getFileForClass
Returns the Java file for the given class.- Parameters:
cls
- the class- Returns:
- the file for the class
-
getSourceFile
Returns the Java file for the given component location.- Parameters:
location
- the component location- Returns:
- the file for the class where the component is used
-
getJavaSourceFolder
Returns the Java source folder.- Returns:
- the Java source folder
-
getProjectRoot
Returns the project root folder.- Returns:
- the project root folder
-
getFrontendFolder
Returns the frontend folder.- Returns:
- the frontend folder
-
getJavaResourceFolder
Returns the java resource folder.- Returns:
- the java resource folder.
-
getThemeName
Gets current theme name- Returns:
- optional theme name
-
getThemeFolder
Gets current theme folder- Returns:
- optional theme folder
-
sanitizeFilename
Makes a string safe to use as a file name- Parameters:
name
- the string to process- Returns:
- the sanitized string
-
getHillaViewsFolder
The folder where Hilla views should be created for the file system router to pick them up.- Returns:
- the folder where Hilla views should be created
-
getFlowViewsPackage
Tries to find a common package prefix for all Flow views in the project.If all views are in the same package, that package is returned. If views are in different packages, the common prefix is returned. If no common prefix is found, the main package is returned.
- Returns:
- a suitable package to place a new Flow view in
-