List of usage examples for org.apache.commons.io FileUtils toFile
public static File toFile(URL url)
URL
to a File
. From source file:org.sonar.squidbridge.metrics.ResourceParser.java
private static SourceFile scanFile(String filePath, boolean ignoreHeaderComments, SquidAstVisitor<Grammar>... visitors) { AstScanner<Grammar> scanner = ignoreHeaderComments ? MiniCAstScanner.createIgnoreHeaderComments(visitors) : MiniCAstScanner.create(visitors); File file = FileUtils.toFile(ResourceParser.class.getResource(filePath)); if (file == null || !file.exists()) { throw new IllegalArgumentException("The file located under \"" + filePath + "\" was not found."); }/*from www . j a v a 2 s .c o m*/ scanner.scanFile(file); assertThat(scanner.getIndex().search(new QueryByType(SourceFile.class)).size()).isEqualTo(1); return (SourceFile) scanner.getIndex().search(new QueryByType(SourceFile.class)).iterator().next(); }
From source file:org.sonar.updatecenter.deprecated.UpdateCenter.java
private JSONArray resolvePlugins() throws Exception { List<String> plugins = FileUtils.readLines(FileUtils.toFile(getClass().getResource("/plugins.txt"))); String pluginInfoWidgetTemplate = FileUtils .readFileToString(FileUtils.toFile(getClass().getResource("/plugin-info-widget-template.html"))); if (outputDirectory != null) { FileUtils.copyURLToFile(getClass().getResource("/style.css"), new File(outputDirectory, "plugins/style.css")); }//from w w w . j a v a2 s. co m JSONArray json = new JSONArray(); for (String plugin : plugins) { if (plugin.startsWith("#")) { // Skip comments continue; } History<Plugin> history = resolvePluginHistory(plugin); if (history.latest() == null) { System.out.println("WTF? " + plugin); continue; } json.add(history.latest().toJsonObject()); Plugin latest = history.latest(); if (outputDirectory != null) { String pluginInfoWidget = StringUtils.replaceEach(pluginInfoWidgetTemplate, new String[] { "%name%", "%version%", "%date%", "%downloadUrl%", "%sonarVersion%", "%issueTracker%", "%sources%", "%license%", "%developers%" }, new String[] { latest.getName(), latest.getVersion(), latest.getReleaseDate(), latest.getDownloadUrl(), latest.getRequiredSonarVersion(), formatLink(latest.getIssueTracker()), formatLink(latest.getSources()), latest.getLicense() == null ? "Unknown" : latest.getLicense(), formatDevelopers(latest.getDevelopers()) }); FileUtils.writeStringToFile(new File(outputDirectory, "plugins/" + latest.getKey() + ".html"), pluginInfoWidget, "UTF-8"); } // TODO use logger System.out.println( latest.getName() + " : " + history.getAllVersions() + ", latest " + latest.getVersion()); } return json; }
From source file:org.sonar.updatecenter.mojo.GenerateHtmlHeadersMojoTest.java
private File resource(String filename) { return FileUtils .toFile(getClass().getResource("/org/sonar/updatecenter/mojo/GenerateMojoTest/" + filename)); }
From source file:org.sonar.updatecenter.mojo.GenerateMetadataMojoTest.java
private File resource(String filename) { return FileUtils.toFile(url(filename)); }
From source file:org.sonar.updatecenter.mojo.PluginHeadersTest.java
private File getExpectedFile(String fileName) { return FileUtils .toFile(getClass().getResource("/org/sonar/updatecenter/mojo/PluginHeadersTest/" + fileName)); }
From source file:org.sonarqube.cppcheck.CppcheckXmlParserTest.java
@Test public void test2() { File file = FileUtils.toFile(getClass().getResource("/cppcheck2.xml")); Collection<CppcheckXmlParser.Message> messages = CppcheckXmlParser.parse(file); assertThat(messages.size()).isEqualTo(9); CppcheckXmlParser.Message message = messages.iterator().next(); assertThat(message.getId()).isEqualTo("autoVariables"); assertThat(message.getMsg()).isEqualTo("Assigning address of local auto-variable to a function parameter."); assertThat(message.getVerbose()).startsWith("Dangerous assignment"); assertThat(message.getSeverity()).isEqualTo("error"); assertThat(message.getLine()).isEqualTo("4"); assertThat(message.getFilename()).isEqualTo("src/autoVariables/bad.c"); }
From source file:org.sonarqube.cppcheck.CppcheckXmlParserTest.java
@Test public void test3() { File file = FileUtils.toFile(getClass().getResource("/no-location.xml")); Collection<CppcheckXmlParser.Message> messages = CppcheckXmlParser.parse(file); CppcheckXmlParser.Message message = Iterables.getOnlyElement(messages); assertThat(message.getMsg()).isNotNull(); assertThat(message.getLine()).isNull(); assertThat(message.getFilename()).isNull(); }
From source file:org.sonarsource.sonarlint.core.plugin.DefaultPluginJarExploderTest.java
File getFileFromCache(String filename) throws IOException { File src = FileUtils.toFile(getClass().getResource("/" + filename)); File destFile = new File(new File(userHome, "" + filename.hashCode()), filename); FileUtils.copyFile(src, destFile);//from w w w .ja va2 s. c o m return destFile; }
From source file:org.sonarsource.sonarlint.core.plugin.PluginInfoTest.java
@Test public void create_from_file() { File checkstyleJar = FileUtils.toFile(getClass().getResource("/sonar-checkstyle-plugin-2.8.jar")); PluginInfo checkstyleInfo = PluginInfo.create(checkstyleJar); assertThat(checkstyleInfo.getName()).isEqualTo("Checkstyle"); assertThat(checkstyleInfo.getMinimalSqVersion()).isEqualTo(Version.create("2.8")); }
From source file:org.sonarsource.sonarlint.core.plugin.PluginJarExploderTest.java
private File getFile(String filename) { return FileUtils.toFile(getClass().getResource("/" + filename)); }