@Test public void testExtractVersionFromPackageJson() { Log log = mock(Log.class); File coffeescript = new File("target/test-classes/package-json/coffeescript"); String version = NPM.getVersionFromNPM(coffeescript, log); assertThat(version).isEqualTo("1.7.1"); File less = new File("target/test-classes/package-json/less"); version = NPM.getVersionFromNPM(less, log); assertThat(version).isEqualTo("1.5.0"); File doesNotExist = new File("target/test-classes/package-json/nope"); version = NPM.getVersionFromNPM(doesNotExist, log); assertThat(version).isEqualTo("0.0.0"); }
public static String getVersionFromNPM(File npmDirectory, Log log) { File packageFile = new File(npmDirectory, PACKAGE_JSON); if (!packageFile.isFile()) { return "0.0.0"; } FileReader reader = null; try { reader = new FileReader(packageFile); JSONObject json = (JSONObject) JSONValue.parseWithException(reader); return (String) json.get("version"); } catch (IOException | ParseException e) { log.error("Cannot extract version from " + packageFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(reader); } return null; }
NPM { public static String getVersionFromNPM(File npmDirectory, Log log) { File packageFile = new File(npmDirectory, PACKAGE_JSON); if (!packageFile.isFile()) { return "0.0.0"; } FileReader reader = null; try { reader = new FileReader(packageFile); JSONObject json = (JSONObject) JSONValue.parseWithException(reader); return (String) json.get("version"); } catch (IOException | ParseException e) { log.error("Cannot extract version from " + packageFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(reader); } return null; } }
NPM { public static String getVersionFromNPM(File npmDirectory, Log log) { File packageFile = new File(npmDirectory, PACKAGE_JSON); if (!packageFile.isFile()) { return "0.0.0"; } FileReader reader = null; try { reader = new FileReader(packageFile); JSONObject json = (JSONObject) JSONValue.parseWithException(reader); return (String) json.get("version"); } catch (IOException | ParseException e) { log.error("Cannot extract version from " + packageFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(reader); } return null; } private  NPM(Log log, NodeManager manager, String name, String version, String... args); }
NPM { public static String getVersionFromNPM(File npmDirectory, Log log) { File packageFile = new File(npmDirectory, PACKAGE_JSON); if (!packageFile.isFile()) { return "0.0.0"; } FileReader reader = null; try { reader = new FileReader(packageFile); JSONObject json = (JSONObject) JSONValue.parseWithException(reader); return (String) json.get("version"); } catch (IOException | ParseException e) { log.error("Cannot extract version from " + packageFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(reader); } return null; } private  NPM(Log log, NodeManager manager, String name, String version, String... args); NPM handleQuoting(); int execute(String binary, String... args); int execute(File binary, String... args); String getLastErrorStream(); String getLastOutputStream(); File findExecutable(String binary); static String getVersionFromNPM(File npmDirectory, Log log); static NPM npm(AbstractWisdomMojo mojo, String name, String version, String... args); static void configureRegistry(NodeManager node, Log log, String npmRegistryUrl); @Override boolean equals(Object o); @Override int hashCode(); void registerOutputStream(boolean register); }
NPM { public static String getVersionFromNPM(File npmDirectory, Log log) { File packageFile = new File(npmDirectory, PACKAGE_JSON); if (!packageFile.isFile()) { return "0.0.0"; } FileReader reader = null; try { reader = new FileReader(packageFile); JSONObject json = (JSONObject) JSONValue.parseWithException(reader); return (String) json.get("version"); } catch (IOException | ParseException e) { log.error("Cannot extract version from " + packageFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(reader); } return null; } private  NPM(Log log, NodeManager manager, String name, String version, String... args); NPM handleQuoting(); int execute(String binary, String... args); int execute(File binary, String... args); String getLastErrorStream(); String getLastOutputStream(); File findExecutable(String binary); static String getVersionFromNPM(File npmDirectory, Log log); static NPM npm(AbstractWisdomMojo mojo, String name, String version, String... args); static void configureRegistry(NodeManager node, Log log, String npmRegistryUrl); @Override boolean equals(Object o); @Override int hashCode(); void registerOutputStream(boolean register); static final String PACKAGE_JSON; }