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
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
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
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
FRONTEND
Default folder used for source and generated folders.
static String
IMPORTS_NAME
Name of the file that contains application imports, javascript, theme and style annotations.
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
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
.
-
Method Summary
All Methods Modifier and Type Method and Description static ProcessBuilder
createProcessBuilder(List<String> command)
Creates a process builder for the given list of program and arguments.
static List<String>
getBowerExecutable(String baseDir)
Locate
bower
executable.static String
getNodeExecutable(String baseDir)
Locate
node
executable.static List<String>
getNpmExecutable(String baseDir)
Locate
npm
executable.static String
getOsName()
Get the Operating System name from the
os.name
system property.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 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 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.
static void
validateNodeAndNpmVersion(String baseDir)
Validate that the found node and npm versions are new enough.
-
-
-
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:
-
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:
-
TARGET
public static final String TARGET
Default target folder for the java project.
See Also:
-
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:
-
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:
-
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:
-
-
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
-
getNodeExecutable
public static String getNodeExecutable(String baseDir)
Locate
node
executable.Parameters:
baseDir
- project root folder.Returns:
the full path to the executable
-
getNpmExecutable
public static List<String> getNpmExecutable(String baseDir)
Locate
npm
executable.Parameters:
baseDir
- project root folder.Returns:
the list of all commands in sequence that need to be executed to have npm running
-
getBowerExecutable
public static List<String> getBowerExecutable(String baseDir)
Locate
bower
executable.An empty list is returned if bower is not found
Parameters:
baseDir
- project root folder.Returns:
the list of all commands in sequence that need to be executed to have bower running, an empty list if bower is not found
-
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.
-
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
Throws:
IOException
- if an I/O error occurs while creating the input stream.
-
validateNodeAndNpmVersion
public static void validateNodeAndNpmVersion(String baseDir)
Validate that the found node and npm versions are new enough. Throws an exception with a descriptive message if a version is too old.
Parameters:
baseDir
- project root folder.
-
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
-
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
-
-