com.vaadin.flow.server.frontend.
Class FrontendUtils
- java.lang.Object
-
- com.vaadin.flow.server.frontend.FrontendUtils
-
public class FrontendUtils extends Object
A class for static methods and definitions that might be used in different locations.
Since:
2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
FrontendUtils.UnknownVersionException
Thrown when detecting the version of a tool fails.
-
Field Summary
Fields Modifier and Type Field and Description static String
BRIGHT_BLUE
static String
CHUNKS
A key in a Json object for chunks list.
static String
CSS_IMPORTS
A key in a Json object for css imports data.
static String
DEAULT_FLOW_RESOURCES_FOLDER
Deprecated.
This is deprecated due to a typo. Use DEFAULT_FLOW_RESOURCES_FOLDER instead.static String
DEFAULT_CONNECT_APPLICATION_PROPERTIES
Default application properties file path in Connect project.
static String
DEFAULT_CONNECT_GENERATED_TS_DIR
Default generated path for generated TS files.
static String
DEFAULT_CONNECT_JAVA_SOURCE_FOLDER
Default Java source folder for OpenAPI generator.
static String
DEFAULT_CONNECT_OPENAPI_JSON_FILE
Default generated path for OpenAPI spec file.
static String
DEFAULT_FLOW_RESOURCES_FOLDER
Default folder for copying front-end resources present in the classpath jars.
static String
DEFAULT_FRONTEND_DIR
Path of the folder containing application frontend source files, it needs to be relative to the
DEFAULT_NODE_DIR
By default it is/frontend
in the project folder.static String
DEFAULT_GENERATED_DIR
Default folder name for flow generated stuff relative to the
TARGET
.static String
DEFAULT_NODE_DIR
Default folder for the node related content.
static String
DISABLE_CHECK
static String
EXPORT_CHUNK
The entry-point key used for the exported bundle.
static String
FALLBACK
A key in a Json object for fallback chunk.
static String
FALLBACK_IMPORTS_NAME
Name of the file that contains all application imports, javascript, theme and style annotations which are not discovered by the current scanning strategy (but they are in the project classpath).
static String
FLOW_NPM_PACKAGE_NAME
The NPM package name that will be used for the javascript files present in jar resources that will to be copied to the npm folder so as they are accessible to webpack.
static String
FORM_NPM_PACKAGE_NAME
The NPM package name that will be used for the javascript files present in jar resources that will to be copied to the npm folder so as they are accessible to webpack.
static String
FRONTEND
Default folder used for source and generated folders.
static String
GREEN
static String
IMPORTS_D_TS_NAME
The TypeScript definitions for the
IMPORTS_NAME
file.static String
IMPORTS_NAME
Name of the file that contains application imports, javascript, theme and style annotations.
static String
INDEX_HTML
File name of the index.html in client side.
static String
INDEX_JS
File name of the index.js in client side.
static String
INDEX_TS
File name of the index.ts in client side.
static String
INSTALL_NODE_LOCALLY
static String
JS_MODULES
A key in a Json object for js modules data.
static String
NODE_MODULES
Location for the installed node packages.
static String
PARAM_FRONTEND_DIR
A parameter for overriding the
DEFAULT_FRONTEND_DIR
folder.static String
PARAM_GENERATED_DIR
A parameter for overriding the
DEFAULT_GENERATED_DIR
folder.static String
PARAM_IGNORE_VERSION_CHECKS
Set to
true
to ignore node/npm tool version checks.static String
PARAM_TOKEN_FILE
A parameter informing about the location of the
TOKEN_FILE
.static String
PROJECT_BASEDIR
static String
RED
static String
TARGET
Default target folder for the java project.
static String
TOKEN_FILE
File used to enable npm mode.
static String
WEBPACK_CONFIG
The name of the webpack configuration file.
static String
WEBPACK_GENERATED
The name of the webpack generated configuration file.
static String
WEBPACK_PREFIX_ALIAS
A special prefix used by webpack to map imports placed in the
DEFAULT_FRONTEND_DIR
.static String
YELLOW
-
Method Summary
All Methods Modifier and Type Method and Description static String
commandToString(String baseDir, List<String> command)
Pretty prints a command line order.
static void
console(String format, Object message)
Intentionally send to console instead to log, useful when executing external processes.
static ProcessBuilder
createProcessBuilder(List<String> command)
Creates a process builder for the given list of program and arguments.
static String
getIndexHtmlContent(VaadinService service)
Gets the content of the
frontend/index.html
file which is served by webpack-dev-server in dev-mode and read from classpath in production mode.static String
getOsName()
Get the Operating System name from the
os.name
system property.static String
getProjectFrontendDir(DeploymentConfiguration configuration)
Get directory where project's frontend files are located.
static String
getStatsAssetsByChunkName(VaadinService service)
Load the asset chunks from stats.json.
static String
getStatsContent(VaadinService service)
Gets the content of the
stats.json
file produced by webpack.static String
getStatsHash(VaadinService service)
Get the latest has for the stats file in development mode.
static String
getUnixPath(Path source)
Get path as a String in Unix form.
static String
getUnixRelativePath(Path source, Path target)
Get relative path from a source path to a target path in Unix form.
static File
getVaadinHomeDirectory()
Gets vaadin home directory (
".vaadin"
folder in the user home dir).protected static FrontendVersion
getVersion(String tool, List<String> versionCommand)
static boolean
isWebpackConfigFile(File file)
Checks whether the
file
is a webpack configuration file with the expected content (includes a configuration generated by Flow).static boolean
isWindows()
Check if the current os is Windows.
static FrontendVersion
parseFrontendVersion(String versionString)
Parse the version number of node/npm from version output string.
static FallbackChunk
readFallbackChunk(elemental.json.JsonObject object)
Read fallback chunk data from a json object.
static String
streamToString(InputStream inputStream)
Read a stream and copy the content in a String.
-
-
-
Field Detail
-
PROJECT_BASEDIR
public static final String PROJECT_BASEDIR
See Also:
-
DEFAULT_NODE_DIR
public static final String DEFAULT_NODE_DIR
Default folder for the node related content. It's the base directory for
Constants.PACKAGE_JSON
,WEBPACK_CONFIG
,NODE_MODULES
. By default it's the project root folder.See Also:
-
NODE_MODULES
public static final String NODE_MODULES
Location for the installed node packages. This folder is always considered by node, even though we define extra folders with the
NODE_PATH
.See Also:
-
FRONTEND
public static final String FRONTEND
Default folder used for source and generated folders.
See Also:
-
DEFAULT_FRONTEND_DIR
public static final String DEFAULT_FRONTEND_DIR
Path of the folder containing application frontend source files, it needs to be relative to the
DEFAULT_NODE_DIR
By default it is/frontend
in the project folder.See Also:
-
WEBPACK_CONFIG
public static final String WEBPACK_CONFIG
The name of the webpack configuration file.
See Also:
-
WEBPACK_GENERATED
public static final String WEBPACK_GENERATED
The name of the webpack generated configuration file.
See Also:
-
TARGET
public static final String TARGET
Default target folder for the java project.
See Also:
-
FLOW_NPM_PACKAGE_NAME
public static final String FLOW_NPM_PACKAGE_NAME
The NPM package name that will be used for the javascript files present in jar resources that will to be copied to the npm folder so as they are accessible to webpack.
See Also:
-
FORM_NPM_PACKAGE_NAME
public static final String FORM_NPM_PACKAGE_NAME
The NPM package name that will be used for the javascript files present in jar resources that will to be copied to the npm folder so as they are accessible to webpack.
See Also:
-
DEFAULT_FLOW_RESOURCES_FOLDER
public static final String DEFAULT_FLOW_RESOURCES_FOLDER
Default folder for copying front-end resources present in the classpath jars.
See Also:
-
DEAULT_FLOW_RESOURCES_FOLDER
@Deprecated public static final String DEAULT_FLOW_RESOURCES_FOLDER
Deprecated. This is deprecated due to a typo. Use DEFAULT_FLOW_RESOURCES_FOLDER instead.
Default folder for copying front-end resources present in the classpath jars.
-
DEFAULT_GENERATED_DIR
public static final String DEFAULT_GENERATED_DIR
Default folder name for flow generated stuff relative to the
TARGET
.See Also:
-
IMPORTS_NAME
public static final String IMPORTS_NAME
Name of the file that contains application imports, javascript, theme and style annotations. It is also the entry-point for webpack. It is always generated in the
DEFAULT_GENERATED_DIR
folder.See Also:
-
IMPORTS_D_TS_NAME
public static final String IMPORTS_D_TS_NAME
The TypeScript definitions for the
IMPORTS_NAME
file.See Also:
-
INDEX_HTML
public static final String INDEX_HTML
File name of the index.html in client side.
See Also:
-
INDEX_TS
public static final String INDEX_TS
File name of the index.ts in client side.
See Also:
-
INDEX_JS
public static final String INDEX_JS
File name of the index.js in client side.
See Also:
-
DEFAULT_CONNECT_JAVA_SOURCE_FOLDER
public static final String DEFAULT_CONNECT_JAVA_SOURCE_FOLDER
Default Java source folder for OpenAPI generator.
See Also:
-
DEFAULT_CONNECT_APPLICATION_PROPERTIES
public static final String DEFAULT_CONNECT_APPLICATION_PROPERTIES
Default application properties file path in Connect project.
See Also:
-
DEFAULT_CONNECT_OPENAPI_JSON_FILE
public static final String DEFAULT_CONNECT_OPENAPI_JSON_FILE
Default generated path for OpenAPI spec file.
See Also:
-
DEFAULT_CONNECT_GENERATED_TS_DIR
public static final String DEFAULT_CONNECT_GENERATED_TS_DIR
Default generated path for generated TS files.
See Also:
-
FALLBACK_IMPORTS_NAME
public static final String FALLBACK_IMPORTS_NAME
Name of the file that contains all application imports, javascript, theme and style annotations which are not discovered by the current scanning strategy (but they are in the project classpath). This file is dynamically imported by the
IMPORTS_NAME
file. It is always generated in theDEFAULT_GENERATED_DIR
folder.See Also:
-
PARAM_GENERATED_DIR
public static final String PARAM_GENERATED_DIR
A parameter for overriding the
DEFAULT_GENERATED_DIR
folder.See Also:
-
PARAM_FRONTEND_DIR
public static final String PARAM_FRONTEND_DIR
A parameter for overriding the
DEFAULT_FRONTEND_DIR
folder.See Also:
-
PARAM_IGNORE_VERSION_CHECKS
public static final String PARAM_IGNORE_VERSION_CHECKS
Set to
true
to ignore node/npm tool version checks.See Also:
-
WEBPACK_PREFIX_ALIAS
public static final String WEBPACK_PREFIX_ALIAS
A special prefix used by webpack to map imports placed in the
DEFAULT_FRONTEND_DIR
. e.g.import 'Frontend/foo.js';
references the filefrontend/foo.js
.See Also:
-
TOKEN_FILE
public static final String TOKEN_FILE
File used to enable npm mode.
See Also:
-
CHUNKS
public static final String CHUNKS
A key in a Json object for chunks list.
See Also:
-
FALLBACK
public static final String FALLBACK
A key in a Json object for fallback chunk.
See Also:
-
EXPORT_CHUNK
public static final String EXPORT_CHUNK
The entry-point key used for the exported bundle.
See Also:
-
CSS_IMPORTS
public static final String CSS_IMPORTS
A key in a Json object for css imports data.
See Also:
-
JS_MODULES
public static final String JS_MODULES
A key in a Json object for js modules data.
See Also:
-
PARAM_TOKEN_FILE
public static final String PARAM_TOKEN_FILE
A parameter informing about the location of the
TOKEN_FILE
.See Also:
-
INSTALL_NODE_LOCALLY
public static final String INSTALL_NODE_LOCALLY
See Also:
-
DISABLE_CHECK
public static final String DISABLE_CHECK
See Also:
-
YELLOW
public static final String YELLOW
See Also:
-
RED
public static final String RED
See Also:
-
GREEN
public static final String GREEN
See Also:
-
BRIGHT_BLUE
public static final String BRIGHT_BLUE
See Also:
-
-
Method Detail
-
getOsName
public static String getOsName()
Get the Operating System name from the
os.name
system property.Returns:
operating system name
-
isWindows
public static boolean isWindows()
Check if the current os is Windows.
Returns:
true if windows
-
streamToString
public static String streamToString(InputStream inputStream)
Read a stream and copy the content in a String.
Parameters:
inputStream
- the input streamReturns:
the string
-
createProcessBuilder
public static ProcessBuilder createProcessBuilder(List<String> command)
Creates a process builder for the given list of program and arguments. If the program is defined as an absolute path, then the directory that contains the program is also appended to PATH so that the it can locate related tools.
Parameters:
command
- a list with the program and argumentsReturns:
a configured process builder
-
getStatsContent
public static String getStatsContent(VaadinService service) throws IOException
Gets the content of the
stats.json
file produced by webpack.Parameters:
service
- the vaadin service.Returns:
the content of the file as a string, null if not found.
Throws:
IOException
- on error reading stats file.
-
getIndexHtmlContent
public static String getIndexHtmlContent(VaadinService service) throws IOException
Gets the content of the
frontend/index.html
file which is served by webpack-dev-server in dev-mode and read from classpath in production mode. NOTE: In dev mode, the file content file is fetched via webpack http request. So that we don't need to have a separate index.html's content watcher, auto-reloading will work automatically, like other files managed by webpack in `frontend/` folder.Parameters:
service
- the vaadin serviceReturns:
the content of the index html file as a string, null if not found.
Throws:
IOException
- on error when reading file
-
getStatsHash
public static String getStatsHash(VaadinService service) throws IOException
Get the latest has for the stats file in development mode. This is requested from the webpack-dev-server.
In production mode and disabled dev server mode an empty string is returned.
Parameters:
service
- the Vaadin service.Returns:
hash string for the stats.json file, empty string if none found
Throws:
IOException
- if an I/O error occurs while creating the input stream.
-
getStatsAssetsByChunkName
public static String getStatsAssetsByChunkName(VaadinService service) throws IOException
Load the asset chunks from stats.json. We will only read the file until we have reached the assetsByChunkName json and return that as a json object string.
Parameters:
service
- the Vaadin service.Returns:
json for assetsByChunkName object in stats.json or
null
if stats.json not found or content not found.Throws:
IOException
- if an I/O error occurs while creating the input stream.
-
getProjectFrontendDir
public static String getProjectFrontendDir(DeploymentConfiguration configuration)
Get directory where project's frontend files are located.
Parameters:
configuration
- the current deployment configurationReturns:
DEFAULT_FRONTEND_DIR
or value ofPARAM_FRONTEND_DIR
if it is set.
-
isWebpackConfigFile
public static boolean isWebpackConfigFile(File file) throws IOException
Checks whether the
file
is a webpack configuration file with the expected content (includes a configuration generated by Flow).Parameters:
file
- a file to checkReturns:
true
iff the file exists and includes a generated configurationThrows:
IOException
- if an I/O error occurs while reading the file
-
getUnixRelativePath
public static String getUnixRelativePath(Path source, Path target)
Get relative path from a source path to a target path in Unix form. All the Windows' path separator will be replaced.
Parameters:
source
- the source pathtarget
- the target pathReturns:
unix relative path from source to target
-
getUnixPath
public static String getUnixPath(Path source)
Get path as a String in Unix form.
Parameters:
source
- path to getReturns:
path as a String in Unix form.
-
readFallbackChunk
public static FallbackChunk readFallbackChunk(elemental.json.JsonObject object)
Read fallback chunk data from a json object.
Parameters:
object
- json object to read fallback chunk dataReturns:
a fallback chunk data
-
getVersion
protected static FrontendVersion getVersion(String tool, List<String> versionCommand) throws FrontendUtils.UnknownVersionException
-
parseFrontendVersion
public static FrontendVersion parseFrontendVersion(String versionString) throws IOException
Parse the version number of node/npm from version output string.
Parameters:
versionString
- string containing version output, typically produced bytool --version
Returns:
FrontendVersion of versionString
Throws:
IOException
- if parsing fails
-
getVaadinHomeDirectory
public static File getVaadinHomeDirectory()
Gets vaadin home directory (
".vaadin"
folder in the user home dir).The directory is created if it's doesn't exist.
Returns:
a vaadin home directory
-
commandToString
public static String commandToString(String baseDir, List<String> command)
Pretty prints a command line order. It split in lines adapting to 80 columns, and allowing copy and paste in console. It also removes the current directory to avoid security issues in log files.
Parameters:
baseDir
- the current directorycommand
- the command and it's argumentsReturns:
the string for printing in logs
-
-