FrontendUtils { public static String getStatsAssetsByChunkName(VaadinService service) throws IOException { DeploymentConfiguration config = service.getDeploymentConfiguration(); if (!config.isProductionMode() && config.enableDevServer()) { DevModeHandler handler = DevModeHandler.getDevModeHandler(); HttpURLConnection assetsConnection = handler .prepareConnection("/assetsByChunkName", "GET"); if (assetsConnection .getResponseCode() != HttpURLConnection.HTTP_OK) { throw new WebpackConnectionException(String.format( NO_CONNECTION, "getting assets by chunk name.")); } return streamToString(assetsConnection.getInputStream()); } InputStream resourceAsStream; if (config.isStatsExternal()) { resourceAsStream = getStatsFromExternalUrl( config.getExternalStatsUrl(), service.getContext()); } else { resourceAsStream = getStatsFromClassPath(service); } if (resourceAsStream == null) { return null; } try (Scanner scan = new Scanner(resourceAsStream, StandardCharsets.UTF_8.name())) { StringBuilder assets = new StringBuilder(); assets.append("{"); scanToAssetChunkStart(scan, assets); while (scan.hasNextLine()) { String line = scan.nextLine().trim(); if ("}".equals(line) || "},".equals(line)) { return assets.append("}").toString(); } else if (line.endsWith("}") || line.endsWith("},")) { return assets .append(line.substring(0, line.indexOf('}')).trim()) .append("}").toString(); } else if (line.contains("{")) { break; } assets.append(line); } getLogger() .error("Could not parse assetsByChunkName from stats.json"); } return null; } private  FrontendUtils(); static String getOsName(); static boolean isWindows(); static String streamToString(InputStream inputStream); static ProcessBuilder createProcessBuilder(List<String> command); static String getStatsContent(VaadinService service); static String getIndexHtmlContent(VaadinService service); static String getStatsHash(VaadinService service); static String getStatsAssetsByChunkName(VaadinService service); static String getProjectFrontendDir(
            DeploymentConfiguration configuration); static boolean isWebpackConfigFile(File file); static String getUnixRelativePath(Path source, Path target); static String getUnixPath(Path source); static FallbackChunk readFallbackChunk(JsonObject object); static FrontendVersion parseFrontendVersion(String versionString); static File getVaadinHomeDirectory(); static String commandToString(String baseDir, List<String> command); @SuppressWarnings("squid:S106") static void console(String format, Object message); static final String PROJECT_BASEDIR; static final String DEFAULT_NODE_DIR; static final String NODE_MODULES; static final String FRONTEND; static final String DEFAULT_FRONTEND_DIR; static final String WEBPACK_CONFIG; static final String WEBPACK_GENERATED; static final String TARGET; static final String FLOW_NPM_PACKAGE_NAME; static final String FORM_NPM_PACKAGE_NAME; static final String DEFAULT_FLOW_RESOURCES_FOLDER; @Deprecated
    static final String DEAULT_FLOW_RESOURCES_FOLDER; static final String DEFAULT_GENERATED_DIR; static final String IMPORTS_NAME; static final String IMPORTS_D_TS_NAME; static final String INDEX_HTML; static final String INDEX_TS; static final String INDEX_JS; static final String DEFAULT_CONNECT_JAVA_SOURCE_FOLDER; static final String DEFAULT_CONNECT_APPLICATION_PROPERTIES; static final String DEFAULT_CONNECT_OPENAPI_JSON_FILE; static final String DEFAULT_CONNECT_GENERATED_TS_DIR; static final String FALLBACK_IMPORTS_NAME; static final String PARAM_GENERATED_DIR; static final String PARAM_FRONTEND_DIR; static final String PARAM_IGNORE_VERSION_CHECKS; static final String WEBPACK_PREFIX_ALIAS; static final String TOKEN_FILE; static final String CHUNKS; static final String FALLBACK; static final String EXPORT_CHUNK; static final String CSS_IMPORTS; static final String JS_MODULES; static final String PARAM_TOKEN_FILE; static final String INSTALL_NODE_LOCALLY; static final String DISABLE_CHECK; static final String YELLOW; static final String RED; static final String GREEN; static final String BRIGHT_BLUE; }
@Test public void assetsByChunkIsCorrectlyParsedFromStats() throws IOException { VaadinService service = setupStatsAssetMocks("ValidStats.json"); String statsAssetsByChunkName = FrontendUtils .getStatsAssetsByChunkName(service); Assert.assertEquals( "{\"bundle\": \"build/vaadin-bundle-1111.cache.js\",\"export\": \"build/vaadin-export-2222.cache.js\"}", statsAssetsByChunkName); }
@Test public void formattingError_assetsByChunkIsCorrectlyParsedFromStats() throws IOException { VaadinService service = setupStatsAssetMocks("MissFormatStats.json"); String statsAssetsByChunkName = FrontendUtils .getStatsAssetsByChunkName(service); Assert.assertEquals( "{\"bundle\": \"build/vaadin-bundle-1111.cache.js\"}", statsAssetsByChunkName); }
@Test public void noStatsFile_assetsByChunkReturnsNull() throws IOException { VaadinService service = getServiceWithResource(null); String statsAssetsByChunkName = FrontendUtils .getStatsAssetsByChunkName(service); Assert.assertNull(statsAssetsByChunkName); }
@Test public void faultyStatsFileReturnsNull() throws IOException { VaadinService service = setupStatsAssetMocks("InvalidStats.json"); String statsAssetsByChunkName = FrontendUtils .getStatsAssetsByChunkName(service); Assert.assertNull(statsAssetsByChunkName); }