private Optional<Artifact> xctestIpa() { FileProvider fileProvider = ruleContext.getPrerequisite("xctest_app", Mode.TARGET, FileProvider.class); if (fileProvider == null) { return Optional.absent(); } List<Artifact> files = Artifact.filterFiles(fileProvider.getFilesToBuild(), FileType.of(".ipa")); if (files.size() == 0) { return Optional.absent(); } else if (files.size() == 1) { return Optional.of(Iterables.getOnlyElement(files)); } else { throw new IllegalStateException("Expected 0 or 1 files in xctest_app, got: " + files); } }
/** * Retrieves the resource {@link Artifact} and resource root {@link PathFragment}. * * @param targets {@link FileProvider}s for a given set of resource. * @return The Builder. */ public LocalResourceContainer.Builder withResources(Iterable<FileProvider> targets) { PathFragment lastResourceDir = null; Artifact lastFile = null; for (FileProvider target : targets) { for (Artifact file : target.getFilesToBuild()) { PathFragment packageFragment = file.getArtifactOwner().getLabel().getPackageIdentifier().getSourceRoot(); PathFragment packageRelativePath = file.getRootRelativePath().relativeTo(packageFragment); PathFragment resourceDir = findResourceDir(file); if (resourceDir == null) { ruleContext.attributeError( ResourceType.RESOURCES.getAttribute(), String.format(INCORRECT_RESOURCE_LAYOUT_MESSAGE, file.getRootRelativePath())); return this; } if (lastResourceDir == null || resourceDir.equals(lastResourceDir)) { resourceRoots.add( trimTail(file.getExecPath(), makeRelativeTo(resourceDir, packageRelativePath))); } else { ruleContext.attributeError( ResourceType.RESOURCES.getAttribute(), String.format( "'%s' (generated by '%s') is not in the same directory '%s' (derived from %s)." + " All resources must share a common directory.", file.getRootRelativePath(), file.getArtifactOwner().getLabel(), lastResourceDir, lastFile.getRootRelativePath())); return this; } resources.add(file); lastFile = file; lastResourceDir = resourceDir; } } return this; }