@Override protected Warning createWarning(final Matcher matcher) { String message = matcher.group(5); if (message.matches("^-\\[.*\\].*$")) { return FALSE_POSITIVE; } String filename = matcher.group(1); int lineNumber = getLineNumber(matcher.group(2)); int column = getLineNumber(matcher.group(3)); String type = matcher.group(4); String category = matcher.group(6); Priority priority; if (type.contains("error")) { priority = Priority.HIGH; } else { priority = Priority.NORMAL; } Warning warning; if (category == null) { warning = createWarning(filename, lineNumber, message, priority); } else { warning = createWarning(filename, lineNumber, category, message, priority); } warning.setColumnPosition(column); return warning; }
Event toPoint(MetricInfo info) { Event p = new Event(); String metricName = Utils.smoothText.apply(info.metric); p.values = ImmutableMap.of(metricName, (Object) info.value); Warning warning = warnings.get(info.metric); p.tags = Maps.newLinkedHashMap(); // We need the order! p.tags.put("service", info.service.replace("/", ":")); // Transform into real service name. p.tags.put("host", info.host); for (Map.Entry<String, String> e : userMap.entrySet()) { String user = e.getKey(); String dim = e.getValue(); if ("user1".equals(user)) { p.tags.put(dim, info.user1); } else if ("user2".equals(user)) { p.tags.put(dim, info.user2); } else if ("user3".equals(user)) { p.tags.put(dim, info.user3); } else if ("user4".equals(user)) { p.tags.put(dim, info.user4); } } if (warning != null) { warning.checkAlarm(info, p.tags); } return p; }
private Warning createWarning( final int id, final String fileName, final int line, final int column) { Warning warning = new Warning(Priority.HIGH, String.valueOf(id), line, line, "category", "type"); warning.setFileName(fileName); warning.setColumnPosition(column, column); return warning; }
@Override protected Warning createWarning(final Matcher matcher) { String message = matcher.group(4); String category = classifyIfEmpty("", message); Warning warning = createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, message); warning.setColumnPosition(getLineNumber(matcher.group(3))); return warning; }
private CompilerOptions createCompilerOptions() { CompilerOptions options = new CompilerOptions(); this.compilationLevel.setOptionsForCompilationLevel(options); if (this.debugOptions) { this.compilationLevel.setDebugOptionsForCompilationLevel(options); } options.prettyPrint = this.prettyPrint; options.printInputDelimiter = this.printInputDelimiter; options.generateExports = this.generateExports; options.setLanguageIn(this.languageIn); options.setOutputCharset(this.outputEncoding); this.warningLevel.setOptionsForWarningLevel(options); options.setManageClosureDependencies(manageDependencies); convertEntryPointParameters(options); options.setTrustedStrings(true); if (replaceProperties) { convertPropertiesMap(options); } convertDefineParameters(options); for (Warning warning : warnings) { CheckLevel level = warning.getLevel(); String groupName = warning.getGroup(); DiagnosticGroup group = new DiagnosticGroups().forName(groupName); if (group == null) { throw new BuildException("Unrecognized 'warning' option value (" + groupName + ")"); } options.setWarningLevel(group, level); } if (!Strings.isNullOrEmpty(sourceMapFormat)) { options.sourceMapFormat = Format.valueOf(sourceMapFormat); } if (sourceMapOutputFile != null) { File parentFile = sourceMapOutputFile.getParentFile(); if (parentFile.mkdirs()) { log("Created missing parent directory " + parentFile, Project.MSG_DEBUG); } options.sourceMapOutputPath = parentFile.getAbsolutePath(); } return options; }
public boolean hasWarning() { try { return Warning.valueOf(name()) != null; } catch (Exception e) { return false; } }
/** * Verifies that the message contains escaped XML characters. * * @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-17287">Issue 17287</a> */ @Test public void issue17287() { Warning warning = new Warning( Priority.HIGH, "dereferencing pointer '<anonymous>' does break strict-aliasing rules", 0, 0, "category", "type"); assertEquals( "Wrong message escaping", "dereferencing pointer '<anonymous>' does break strict-aliasing rules", warning.getMessage()); }
/** When the system starts up, run the tests. */ @Override public void contextInitialized(ServletContextEvent sce) { ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); configProps = ConfigurationProperties.getBean(ctx); /* * If OpenSocial is not configured in runtime.properties, skip the tests. */ if (!configurationPresent()) { ss.info(this, "The OpenSocial connection is not configured."); return; } /* * Run all of the non-threaded tests. If any fail, skip the threaded * tests. */ checkDatabaseTables(); checkShindigConfigFile(); checkTokenKeyFile(); checkTokenServiceInfo(); if (!warnings.isEmpty()) { for (Warning w : warnings) { w.warn(ss); } return; } /* * Run the threaded tests. */ ss.info(this, "Starting threads for OpenSocial smoke tests"); new ShindigTestThread(this, ss, shindigBaseUrl).start(); new TokenServiceTestThread(this, ss, tokenServiceHost, tokenServicePort).start(); }
// NOT CALLED WHEN SYMBOL == NULL public String getType() { if (jjtGetNumChildren() == 0) { return VariableStore.getType(symbol); } else { String type = null; for (int i = 0; i < jjtGetNumChildren(); i++) { String typeChild = children[i].getType(); if (type != null && typeChild != null && !type.equals(typeChild)) { // Geracao de Warning Warning.push("Variables with different types"); } if (type == null && typeChild != null) type = typeChild; } return type; } }
public String getWarning() { return Warning.valueOf(name()).w; }
/** * Detects the package name for the specified warning. * * @param warning the warning */ private void detectPackageName(final Warning warning) { if (!warning.hasPackageName()) { warning.setPackageName(PackageDetectors.detectPackageName(warning.getFileName())); } }
public void test() throws Exception { File file = new File(getTargetDir(), "report"); try { LintCliClient client = new LintCliClient() { @Override String getRevision() { return "unittest"; // Hardcode version to keep unit test output stable } }; //noinspection ResultOfMethodCallIgnored file.getParentFile().mkdirs(); XmlReporter reporter = new XmlReporter(client, file); Project project = Project.create(client, new File("/foo/bar/Foo"), new File("/foo/bar/Foo")); Warning warning1 = new Warning( ManifestDetector.USES_SDK, "<uses-sdk> tag should specify a target API level (the highest verified " + "version; when running on later versions, compatibility behaviors may " + "be enabled) with android:targetSdkVersion=\"?\"", Severity.WARNING, project, null); warning1.line = 6; warning1.file = new File("/foo/bar/Foo/AndroidManifest.xml"); warning1.errorLine = " <uses-sdk android:minSdkVersion=\"8\" />\n ^\n"; warning1.path = "AndroidManifest.xml"; warning1.location = Location.create( warning1.file, new DefaultPosition(6, 4, 198), new DefaultPosition(6, 42, 236)); Warning warning2 = new Warning( HardcodedValuesDetector.ISSUE, "[I18N] Hardcoded string \"Fooo\", should use @string resource", Severity.WARNING, project, null); warning2.line = 11; warning2.file = new File("/foo/bar/Foo/res/layout/main.xml"); warning2.errorLine = " android:text=\"Fooo\" />\n" + " ~~~~~~~~~~~~~~~~~~~\n"; warning2.path = "res/layout/main.xml"; warning2.location = Location.create( warning2.file, new DefaultPosition(11, 8, 377), new DefaultPosition(11, 27, 396)); List<Warning> warnings = new ArrayList<Warning>(); warnings.add(warning1); warnings.add(warning2); reporter.write(0, 2, warnings); String report = Files.toString(file, Charsets.UTF_8); assertEquals( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<issues format=\"4\" by=\"lint unittest\">\n" + "\n" + " <issue\n" + " id=\"UsesMinSdkAttributes\"\n" + " severity=\"Warning\"\n" + " message=\"<uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion="?"\"\n" + " category=\"Correctness\"\n" + " priority=\"9\"\n" + " summary=\"Checks that the minimum SDK and target SDK attributes are defined\"\n" + " explanation=\"The manifest should contain a `<uses-sdk>` element which defines the minimum API Level required for the application to run, as well as the target version (the highest API level you have tested the version for.)\"\n" + " url=\"http://developer.android.com/guide/topics/manifest/uses-sdk-element.html\"\n" + " urls=\"http://developer.android.com/guide/topics/manifest/uses-sdk-element.html\"\n" + " errorLine1=\" <uses-sdk android:minSdkVersion="8" />\"\n" + " errorLine2=\" ^\">\n" + " <location\n" + " file=\"AndroidManifest.xml\"\n" + " line=\"7\"\n" + " column=\"5\"/>\n" + " </issue>\n" + "\n" + " <issue\n" + " id=\"HardcodedText\"\n" + " severity=\"Warning\"\n" + " message=\"[I18N] Hardcoded string "Fooo", should use @string resource\"\n" + " category=\"Internationalization\"\n" + " priority=\"5\"\n" + " summary=\"Looks for hardcoded text attributes which should be converted to resource lookup\"\n" + " explanation=\"Hardcoding text attributes directly in layout files is bad for several reasons:\n" + "\n" + "* When creating configuration variations (for example for landscape or portrait)you have to repeat the actual text (and keep it up to date when making changes)\n" + "\n" + "* The application cannot be translated to other languages by just adding new translations for existing string resources.\n" + "\n" + "In Android Studio and Eclipse there are quickfixes to automatically extract this hardcoded string into a resource lookup.\"\n" + " errorLine1=\" android:text="Fooo" />\"\n" + " errorLine2=\" ~~~~~~~~~~~~~~~~~~~\">\n" + " <location\n" + " file=\"res/layout/main.xml\"\n" + " line=\"12\"\n" + " column=\"9\"/>\n" + " </issue>\n" + "\n" + "</issues>\n", report); // Make sure the XML is valid Document document = new PositionXmlParser().parse(report); assertNotNull(document); assertEquals(2, document.getElementsByTagName("issue").getLength()); } finally { //noinspection ResultOfMethodCallIgnored file.delete(); } }
public void testNonPrintableChars() throws Exception { // See https://code.google.com/p/android/issues/detail?id=56205 File file = new File(getTargetDir(), "report"); try { LintCliClient client = new LintCliClient() { @Override String getRevision() { return "unittest"; // Hardcode version to keep unit test output stable } }; //noinspection ResultOfMethodCallIgnored file.getParentFile().mkdirs(); XmlReporter reporter = new XmlReporter(client, file); Project project = Project.create(client, new File("/foo/bar/Foo"), new File("/foo/bar/Foo")); Warning warning1 = new Warning( TypographyDetector.FRACTIONS, String.format( "Use fraction character %1$c (%2$s) instead of %3$s ?", '\u00BC', "¼", "1/4"), Severity.WARNING, project, null); warning1.line = 592; warning1.file = new File("/foo/bar/Foo/AndroidManifest.xml"); warning1.errorLine = " <string name=\"user_registration_name3_3\">Register 3/3</string>\n" + " ^"; warning1.path = "res/values-en/common_strings.xml"; warning1.location = Location.create(warning1.file, new DefaultPosition(592, 46, -1), null); List<Warning> warnings = new ArrayList<Warning>(); warnings.add(warning1); reporter.write(0, 2, warnings); String report = Files.toString(file, Charsets.UTF_8); assertEquals( "" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<issues format=\"4\" by=\"lint unittest\">\n" + "\n" + " <issue\n" + " id=\"TypographyFractions\"\n" + " severity=\"Warning\"\n" + " message=\"Use fraction character ¼ (&#188;) instead of 1/4 ?\"\n" + " category=\"Usability:Typography\"\n" + " priority=\"5\"\n" + " summary=\"Looks for fraction strings which can be replaced with a fraction character\"\n" + " explanation=\"You can replace certain strings, such as 1/2, and 1/4, with dedicated characters for these, such as ½ (&#189;) and ¼ (&#188;). This can help make the text more readable.\"\n" + " url=\"http://en.wikipedia.org/wiki/Number_Forms\"\n" + " urls=\"http://en.wikipedia.org/wiki/Number_Forms\">\n" + " <location\n" + " file=\"AndroidManifest.xml\"\n" + " line=\"593\"\n" + " column=\"47\"/>\n" + " </issue>\n" + "\n" + "</issues>\n", report); // Make sure the XML is valid Document document = new PositionXmlParser().parse(report); assertNotNull(document); assertEquals(1, document.getElementsByTagName("issue").getLength()); String explanation = ((Element) document.getElementsByTagName("issue").item(0)).getAttribute("explanation"); assertEquals( TypographyDetector.FRACTIONS.getExplanation(Issue.OutputFormat.RAW), explanation); } finally { //noinspection ResultOfMethodCallIgnored file.delete(); } }