private File getTestDataRootDir() { CodeSource source = getClass().getProtectionDomain().getCodeSource(); if (source != null) { URL location = source.getLocation(); try { File classesDir = SdkUtils.urlToFile(location); return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile(); } catch (MalformedURLException e) { fail(e.getLocalizedMessage()); } } return null; }
/** * Returns true if the given file path points to an image file recognized by * Android. See http://developer.android.com/guide/appendix/media-formats.html * for details. * * @param path the filename to be tested * @return true if the file represents an image file */ public static boolean hasImageExtension(String path) { for (String ext: IMAGE_EXTENSIONS) { if (endsWithIgnoreCase(path, ext)) { return true; } } return false; }
for (File file : files) { String path = file.getPath(); boolean isXml = endsWithIgnoreCase(path, DOT_XML); || endsWith(path, DOT_PNG) //also true for endsWith(name, DOT_9PNG) || endsWith(path, DOT_JPG) || endsWith(path, DOT_GIF) || endsWith(path, DOT_JPEG))) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes( folderType); if (endsWithIgnoreCase(path, ".html") || endsWithIgnoreCase(path, ".htm")) { tokenizeHtml(from, Files.toString(file, UTF_8)); } else if (endsWithIgnoreCase(path, ".css")) { tokenizeCss(from, Files.toString(file, UTF_8)); } else if (endsWithIgnoreCase(path, ".js")) { tokenizeJs(from, Files.toString(file, UTF_8)); } else if (file.isFile() && !LintUtils.isBitmapFile(file)) {
public HtmlBuilder newlineIfNecessary() { if (!SdkUtils.endsWith(mStringBuilder, "<BR/>")) { mStringBuilder.append("<BR/>"); } return this; }
private void writeValue(OutputStreamWriter writer, String key, String value, boolean addComment) throws IOException { if (addComment) { String comment = COMMENT_MAP.get(key); if (comment != null) { writer.write(comment); } } writer.write(String.format("%s=%s\n", key, SdkUtils.escapePropertyValue(value))); }
String lineSeparator = SdkUtils.getLineSeparator(); if (s.endsWith(lineSeparator)) { end -= lineSeparator.length();
/** * Creates the path comment XML string. Note that it does not escape characters * such as & and <; those are expected to be escaped by the caller (for * example, handled by a call to {@link org.w3c.dom.Document#createComment(String)}) * * * @param file the file to create a path comment for * @param includePadding whether to include padding. The final comment recognized by * error recognizers expect padding between the {@code <!--} and * the start marker (From:); you can disable padding if the caller * already is in a context where the padding has been added. * @return the corresponding XML contents of the string */ public static String createPathComment(@NonNull File file, boolean includePadding) throws MalformedURLException { String url = fileToUrlString(file); int dashes = url.indexOf("--"); if (dashes != -1) { // Not allowed inside XML comments - for SGML compatibility. Sigh. url = url.replace("--", "%2D%2D"); } if (includePadding) { return ' ' + FILENAME_PREFIX + url + ' '; } else { return FILENAME_PREFIX + url; } }
/** * Returns the corresponding URL string for the given {@link File} * * @param file the file to look up the URL for * @return the corresponding URL * @throws MalformedURLException in very unexpected cases */ public static String fileToUrlString(@NonNull File file) throws MalformedURLException { String url = fileToUrl(file).toExternalForm(); // Use three slashes, which is the form most widely recognized by terminal emulators. if (!url.startsWith("file:///")) { url = url.replaceFirst("file:/", "file:///"); } return url; }
public ImageTestFile(@NonNull String to, int width, int height) { super(to, new BytecodeProducer()); if (SdkUtils.endsWithIgnoreCase(to, DOT_PNG)) { mFormat = "PNG"; } else if (SdkUtils.endsWithIgnoreCase(to, DOT_JPG) || SdkUtils.endsWithIgnoreCase(to, DOT_JPEG)) { mFormat = "JPG"; } else if (SdkUtils.endsWithIgnoreCase(to, DOT_GIF)) { mFormat = "GIF"; } mImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); }
/** * Returns true if the given sequence ends with the given suffix (case * sensitive). * * @param sequence the character sequence to be checked * @param suffix the suffix to look for * @return true if the given sequence ends with the given suffix */ public static boolean endsWith(@NonNull CharSequence sequence, @NonNull CharSequence suffix) { return endsWith(sequence, sequence.length(), suffix); }
public PropertyTestFile property(String key, String value) { String escapedValue = escapePropertyValue(value); stringBuilder.append(key).append('=').append(escapedValue).append('\n'); return this; }
private static String humanReadableMessage(@NonNull Message message) { StringBuilder errorStringBuilder = new StringBuilder(); List<SourceFilePosition> positions = message.getSourceFilePositions(); if (positions.size() != 1 || !SourceFilePosition.UNKNOWN.equals(Iterables.getOnlyElement(positions))) { errorStringBuilder.append(Joiner.on(' ').join(positions)); } if (errorStringBuilder.length() > 0) { errorStringBuilder.append(": "); } if (message.getToolName().isPresent()) { errorStringBuilder.append(message.getToolName().get()).append(": "); } errorStringBuilder.append(message.getText()); String rawMessage = message.getRawMessage(); if (!message.getText().equals(message.getRawMessage())) { String separator = SdkUtils.getLineSeparator(); errorStringBuilder.append("\n ") .append(rawMessage.replace(separator, separator + " ")); } return errorStringBuilder.toString(); }
return SdkUtils.fileToUrlString(file); } catch (MalformedURLException e) { return null;
String className = (String) object; URL url = SdkUtils.fileToUrl(file); ClassLoader loader = client.createUrlClassLoader(new URL[]{url}, JarFileIssueRegistry.class.getClassLoader());
/** * Returns true if the given file represents an XML file * * @param file the file to be checked * @return true if the given file is an xml file */ public static boolean isXmlFile(@NonNull File file) { return SdkUtils.endsWithIgnoreCase(file.getPath(), DOT_XML); }
/** * Returns the corresponding {@link File} for the given file:// url * * @param url the URL string, e.g. file://foo/bar * @return the corresponding {@link File} (which may or may not exist) * @throws MalformedURLException if the URL string is malformed or is not a file: URL */ @NonNull public static File urlToFile(@NonNull String url) throws MalformedURLException { return urlToFile(new URL(url)); }
List<File> files = new ArrayList<>(subset.size()); for (File file : subset) { if (SdkUtils.endsWith(file.getPath(), DOT_XML) && !file.getName().equals(ANDROID_MANIFEST_XML)) { files.add(file);
public PropertyTestFile dependsOn(String relative) { TestCase.assertTrue(relative.startsWith("../")); stringBuilder.append("android.library.reference.") .append(Integer.toString(nextLibraryIndex++)) .append("=").append(escapePropertyValue(relative)) .append('\n'); return this; }
/** * Returns the aapt output. * @param apkFile the apk file to call aapt on. * @return the output as a list of files. * @throws ProcessException */ @NonNull private List<String> getAaptOutput(@NonNull File apkFile) throws ProcessException { ProcessInfoBuilder builder = new ProcessInfoBuilder(); builder.setExecutable(mAaptFile); builder.addArgs("dump", "badging", apkFile.getPath()); CachedProcessOutputHandler processOutputHandler = new CachedProcessOutputHandler(); mProcessExecutor.execute( builder.createProcess(), processOutputHandler) .rethrowFailure().assertNormalExitValue(); BaseProcessOutputHandler.BaseProcessOutput output = processOutputHandler.getProcessOutput(); return Splitter.on(SdkUtils.getLineSeparator()).splitToList(output.getStandardOutputAsString()); } }
&& (stats.errorCount > 0 || stats.warningCount > 0)) { File index = new File(dir, INDEX_NAME); String url = SdkUtils.fileToUrlString(index.getAbsoluteFile()); System.out.println(String.format("Wrote overview index to %1$s", url));