static void addToArray(List<Pair<String, Integer>> list, String name, int value) { // check if we already have that name (at a lower level) for (Pair<String, Integer> pair : list) { if (name.equals(pair.getFirst())) { return; } } list.add(Pair.of(name, Integer.valueOf(value))); }
static void addToArray(List<Pair<String, Integer>> list, String name, int value) { // check if we already have that name (at a lower level) for (Pair<String, Integer> pair : list) { if (name.equals(pair.getFirst())) { assert false; return; } } list.add(Pair.of(name, value)); }
static void addToArray(List<Pair<String, Integer>> list, String name, int value) { // check if we already have that name (at a lower level) for (Pair<String, Integer> pair : list) { if (name.equals(pair.getFirst())) { assert false; return; } } list.add(Pair.of(name, value)); }
/** * Create a map for this build from anonymized ID back to project name. * * Used for the debugging and profiling json output only. */ Map<Long, Pair<String, Map<Long,String>>> createDeanonymizer() { return mProjects.asMap().entrySet().stream() .collect(Collectors.toMap( entry -> entry.getValue().mId, entry -> Pair.of( entry.getKey(), HashBiMap.create(entry.getValue().mVariantIds.asMap()).inverse()))); }
synchronized void invalidClassReference(String from, String to) { if (from.contains(".")) { from = ByteCodeUtils.getClassName(from); } if (mWarningsEmitted.contains(Pair.of(from, to))) { return; } for (FilterSpecification dontWarnSpec : mDontWarnSpecs) { if (dontWarnSpec.matches(from) || dontWarnSpec.matches(to)) { return; } } mWarningsEmitted.add(Pair.of(from, to)); mLogger.warn("{} references unknown class: {}", from, to); }
synchronized void invalidMemberReference(String from, String to) { if (mWarningsEmitted.contains(Pair.of(from, to))) { return; } String fromClassName; if (from.contains(".")) { fromClassName = ByteCodeUtils.getClassName(from); } else { fromClassName = from; } String toClassName = ByteCodeUtils.getClassName(to); for (FilterSpecification dontWarnSpec : mDontWarnSpecs) { if (dontWarnSpec.matches(fromClassName) || dontWarnSpec.matches(toClassName)) { return; } } mWarningsEmitted.add(Pair.of(from, to)); mLogger.warn("{} references unknown class member: {}", from, to); }
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { String layout = element.getAttribute(ATTR_LAYOUT); if (layout.startsWith(LAYOUT_RESOURCE_PREFIX)) { // Ignore @android:layout/ layouts layout = layout.substring(LAYOUT_RESOURCE_PREFIX.length()); Node parent = element.getParentNode(); if (parent.getNodeType() == Node.ELEMENT_NODE) { String tag = parent.getNodeName(); if (tag.indexOf('.') == -1 && !tag.equals(VIEW_MERGE)) { if (!context.getProject().getReportIssues()) { // If this is a library project not being analyzed, ignore it return; } if (mIncludes == null) { mIncludes = new HashMap<String, List<Pair<File, String>>>(); } List<Pair<File, String>> includes = mIncludes.get(layout); if (includes == null) { includes = new ArrayList<Pair<File, String>>(); mIncludes.put(layout, includes); } includes.add(Pair.of(context.file, tag)); } } } }
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { String layout = element.getAttribute(ATTR_LAYOUT); if (layout.startsWith(LAYOUT_RESOURCE_PREFIX)) { // Ignore @android:layout/ layouts layout = layout.substring(LAYOUT_RESOURCE_PREFIX.length()); Node parent = element.getParentNode(); if (parent.getNodeType() == Node.ELEMENT_NODE) { String tag = parent.getNodeName(); if (tag.indexOf('.') == -1 && !tag.equals(VIEW_MERGE)) { if (!context.getProject().getReportIssues()) { // If this is a library project not being analyzed, ignore it return; } if (mIncludes == null) { mIncludes = new HashMap<>(); } List<Pair<File, String>> includes = mIncludes.get(layout); if (includes == null) { includes = new ArrayList<>(); mIncludes.put(layout, includes); } includes.add(Pair.of(context.file, tag)); } } } }
/** Run lint with the given registry and return the resulting warnings */ @NonNull public Pair<List<Warning>,LintBaseline> run(@NonNull IssueRegistry registry) throws IOException { int exitCode = run(registry, Collections.emptyList()); if (exitCode == LintCliFlags.ERRNO_CREATED_BASELINE) { throw new GradleException("Aborting build since new baseline file was created"); } return Pair.of(warnings, driver.getBaseline()); }
/** * Add one library file manifest, will be added last in the list of library files which will * make the parameter the lowest priority library manifest file. * @param file the library manifest file to add. * @param name the library name. * @return itself. */ @NonNull public Invoker addLibraryManifest(@NonNull String name, @NonNull File file) { if (mMergeType == MergeType.LIBRARY) { throw new IllegalStateException( "Cannot add library dependencies manifests when creating a library"); } mLibraryFilesBuilder.add(Pair.of(name, file)); return thisAsT(); }
/** * recursively calculate the list of libraries to merge the manifests files from. * @param libraries the dependencies * @param manifestFiles list of files and names identifiers for the libraries' manifest files. */ private static void collectLibraries(List<? extends ManifestDependency> libraries, ImmutableList.Builder<Pair<String, File>> manifestFiles) { for (ManifestDependency library : libraries) { manifestFiles.add(Pair.of(library.getName(), library.getManifest())); List<? extends ManifestDependency> manifestDependencies = library .getManifestDependencies(); if (!manifestDependencies.isEmpty()) { collectLibraries(manifestDependencies, manifestFiles); } } }
@Override public void afterCheckProject(@NonNull Context context) { if (mFormatStrings != null) { boolean checkCount = context.isEnabled(ARG_COUNT); boolean checkValid = context.isEnabled(INVALID); boolean checkTypes = context.isEnabled(ARG_TYPES); // Ensure that all the format strings are consistent with respect to each other; // e.g. they all have the same number of arguments, they all use all the // arguments, and they all use the same types for all the numbered arguments for (Map.Entry<String, List<Pair<Handle, String>>> entry : mFormatStrings.entrySet()) { String name = entry.getKey(); List<Pair<Handle, String>> list = entry.getValue(); // Check argument counts if (checkCount) { Handle notFormatted = mNotFormatStrings.get(name); if (notFormatted != null) { list = ImmutableList.<Pair<Handle, String>>builder() .add(Pair.of(notFormatted, name)).addAll(list).build(); } checkArity(context, name, list); } // Check argument types (and also make sure that the formatting strings are valid) if (checkValid || checkTypes) { checkTypes(context, checkValid, checkTypes, name, list); } } } }
/** * Calls {@link URL#openConnection()} to actually perform a download. * <p> * Isolated so that it can be overridden by unit tests. */ @VisibleForTesting(visibility=Visibility.PRIVATE) @NonNull protected Pair<InputStream, URLConnection> openUrl( @NonNull String url, boolean needsMarkResetSupport, @NonNull ITaskMonitor monitor, @Nullable Header[] headers) throws IOException { URLConnection connection = new URL(url).openConnection(mSettings.getProxy()); if (headers != null) { for (Header header : headers) { connection.setRequestProperty(header.getName(), header.getValue()); } } connection.connect(); InputStream is = connection.getInputStream(); if (needsMarkResetSupport) { is = ensureMarkReset(is); } return Pair.of(is, connection); }
/** * Sets manifest providers for this merging activity. * @param providers the list of manifest providers. * @return itself. */ @NonNull public Invoker addManifestProviders(@NonNull Iterable<? extends ManifestProvider> providers) { for (ManifestProvider provider : providers) { mLibraryFilesBuilder.add(Pair.of(provider.getName(), provider.getManifest())); } return thisAsT(); }
/** * Parses an XML node to process the {@code <layoutlib>} element. * <p/> * The layoutlib element is new in the XSD rev 4, so we need to cope with it missing in earlier * XMLs. */ LayoutlibVersionMixin(Node pkgNode) { int api = LAYOUTLIB_API_NOT_SPECIFIED; int rev = LAYOUTLIB_REV_NOT_SPECIFIED; Node layoutlibNode = RemotePackageParserUtils .findChildElement(pkgNode, RepoConstants.NODE_LAYOUT_LIB); if (layoutlibNode != null) { api = RemotePackageParserUtils.getXmlInt(layoutlibNode, RepoConstants.NODE_API, 0); rev = RemotePackageParserUtils.getXmlInt(layoutlibNode, RepoConstants.NODE_REVISION, 0); } mLayoutlibVersion = Pair.of(api, rev); }
@Override public void visitDocument(@NonNull XmlContext context, @NonNull Document document) { Element root = document.getDocumentElement(); if (root != null) { if (context.getPhase() == 1) { // Map from ids to types Map<String,String> fileMap = Maps.newHashMapWithExpectedSize(10); addIds(root, fileMap); getFileMapList(context).add(Pair.of(context.file, fileMap)); } else { String name = LintUtils.getLayoutName(context.file); Map<String, List<Location>> map = mLocations.get(name); if (map != null) { lookupLocations(context, root, map); } } } }
@Override public void visitDocument(@NonNull XmlContext context, @NonNull Document document) { if (!context.getProject().getReportIssues()) { return; } Element root = document.getDocumentElement(); if (root != null) { if (context.getPhase() == 1) { // Map from ids to types Map<String,String> fileMap = Maps.newHashMapWithExpectedSize(10); addIds(root, fileMap); getFileMapList(context).add(Pair.of(context.file, fileMap)); } else { String name = LintUtils.getLayoutName(context.file); Map<String, List<Location>> map = mLocations.get(name); if (map != null) { lookupLocations(context, root, map); } } } }
mPending = new ArrayList<Pair<String,Handle>>(); mPending.add(Pair.of(layout, handle));
private static Pair<Dependency, DependencyNode> createRenderscriptSupport( @NonNull Pair<File, String> pair) { Dependency dependency = new JavaDependency( pair.getFirst(), new MavenCoordinatesImpl("com.android.support", "renderscript", pair.getSecond()), "renderscript-" + pair.getSecond(), null /*projectPath*/); return Pair.of( dependency, new DependencyNode(dependency.getAddress(), JAVA, ImmutableList.of(), null)); }
private static Pair<Dependency, DependencyNode> handleRenderscriptSupport( @NonNull VariantConfiguration variantConfiguration, @NonNull AndroidBuilder androidBuilder) { if (variantConfiguration.getRenderscriptSupportModeEnabled()) { File supportJar = androidBuilder.getRenderScriptSupportJar(); if (supportJar != null) { return sRSCache.get(Pair.of( supportJar, androidBuilder.getTargetInfo().getBuildTools().getRevision().toString())); } } return null; } }