public void requirements() {
    MarketDataFeed marketDataFeed = MarketDataFeed.of("MarketDataVendor");
    MarketDataMappings marketDataMappings =
        DefaultMarketDataMappings.builder()
            .mappings(ImmutableMap.of(TestKey.class, new TestMapping("foo")))
            .marketDataFeed(marketDataFeed)
            .build();
    CalculationTask task =
        new CalculationTask(
            new TestTarget(), 0, 0, new TestFunction(), marketDataMappings, ReportingRules.empty());
    MarketDataRequirements requirements = task.requirements();
    Set<? extends MarketDataId<?>> nonObservables = requirements.getNonObservables();
    ImmutableSet<? extends ObservableId> observables = requirements.getObservables();
    ImmutableSet<ObservableId> timeSeries = requirements.getTimeSeries();

    MarketDataId<?> timeSeriesId = TestObservableKey.of("3").toMarketDataId(marketDataFeed);
    assertThat(timeSeries).hasSize(1);
    assertThat(timeSeries.iterator().next()).isEqualTo(timeSeriesId);

    MarketDataId<?> nonObservableId = TestId.of("1");
    assertThat(nonObservables).hasSize(1);
    assertThat(nonObservables.iterator().next()).isEqualTo(nonObservableId);

    MarketDataId<?> observableId = TestObservableKey.of("2").toMarketDataId(marketDataFeed);
    assertThat(observables).hasSize(1);
    assertThat(observables.iterator().next()).isEqualTo(observableId);
  }
  @Test
  public void shouldBePossibleToCreateStateSet() {
    ImmutableSet<AddressState> addresses = createAddressSet(addresses()).asStateSet();

    Iterator<AddressState> iterator = addresses.iterator();
    assertThat(iterator.next().city, equalTo("Uppsala"));
    assertThat(iterator.next().city, equalTo("Stockholm"));
  }
  @Test
  public void shouldBePossibleToCreateSet() {
    ImmutableSet<Address> addresses = createAddressSet(addresses()).asAddressSet();

    Iterator<Address> iterator = addresses.iterator();
    assertThat(iterator.next().isFromUppsala(), is(true));
    assertThat(iterator.next().isFromUppsala(), is(false));
  }
Exemple #4
0
 /**
  * @param path The {@link Path} to test.
  * @return true if {@code path} is a temporary or backup file.
  */
 private boolean isTempFile(Path path) {
   final String fileName = path.getFileName().toString();
   Predicate<Pattern> patternMatches =
       new Predicate<Pattern>() {
         @Override
         public boolean apply(Pattern pattern) {
           return pattern.matcher(fileName).matches();
         }
       };
   return Iterators.any(tempFilePatterns.iterator(), patternMatches);
 }
    /**
     * Walks the trie of paths attempting to merge all of the children of the current path into
     * itself. As soon as this fails we know we can't merge the parent path with the current path
     * either.
     *
     * @param currentPath current path
     * @return Optional.of(a successfully merged folder) or absent if merging did not succeed.
     */
    private Optional<IjFolder> walk(Path currentPath) {
      ImmutableList<Optional<IjFolder>> children =
          FluentIterable.from(tree.getOutgoingNodesFor(currentPath))
              .transform(
                  new Function<Path, Optional<IjFolder>>() {
                    @Override
                    public Optional<IjFolder> apply(Path input) {
                      return walk(input);
                    }
                  })
              .toList();

      boolean anyAbsent =
          FluentIterable.from(children).anyMatch(Predicates.equalTo(Optional.<IjFolder>absent()));
      if (anyAbsent) {
        // Signal that no further merging should be done.
        return Optional.absent();
      }

      ImmutableSet<IjFolder> presentChildren =
          FluentIterable.from(children)
              .transform(
                  new Function<Optional<IjFolder>, IjFolder>() {
                    @Override
                    public IjFolder apply(Optional<IjFolder> input) {
                      return input.get();
                    }
                  })
              .toSet();
      IjFolder currentFolder = mergePathsMap.get(currentPath);
      if (presentChildren.isEmpty()) {
        return Optional.of(Preconditions.checkNotNull(currentFolder));
      }

      final IjFolder myFolder;
      if (currentFolder != null) {
        myFolder = currentFolder;
      } else {
        IjFolder aChild = presentChildren.iterator().next();
        myFolder = aChild.createCopyWith(currentPath);
      }
      boolean allChildrenCanBeMerged =
          FluentIterable.from(presentChildren)
              .allMatch(
                  new Predicate<IjFolder>() {
                    @Override
                    public boolean apply(IjFolder input) {
                      return canMerge(myFolder, input, packagePathCache);
                    }
                  });
      if (!allChildrenCanBeMerged) {
        return Optional.absent();
      }
      IjFolder mergedFolder = myFolder;
      for (IjFolder presentChild : presentChildren) {
        mergePathsMap.remove(presentChild.getPath());
        mergedFolder = presentChild.merge(mergedFolder);
      }
      mergePathsMap.put(mergedFolder.getPath(), mergedFolder);

      return Optional.of(mergedFolder);
    }
Exemple #6
0
  @Override
  @SuppressWarnings("PMD.PrematureDeclaration")
  int runCommandWithOptionsInternal(BuildCommandOptions options) throws IOException {
    // Set the logger level based on the verbosity option.
    Verbosity verbosity = console.getVerbosity();
    Logging.setLoggingLevelForVerbosity(verbosity);

    // Create artifact cache to initialize Cassandra connection, if appropriate.
    ArtifactCache artifactCache = getArtifactCache();

    try {
      buildTargets = getBuildTargets(options.getArgumentsFormattedAsBuildTargets());
    } catch (NoSuchBuildTargetException e) {
      console.printBuildFailureWithoutStacktrace(e);
      return 1;
    }

    if (buildTargets.isEmpty()) {
      console.printBuildFailure("Must specify at least one build target.");

      // If there are aliases defined in .buckconfig, suggest that the user
      // build one of them. We show the user only the first 10 aliases.
      ImmutableSet<String> aliases = options.getBuckConfig().getAliases();
      if (!aliases.isEmpty()) {
        console
            .getStdErr()
            .println(
                String.format(
                    "Try building one of the following targets:\n%s",
                    Joiner.on(' ').join(Iterators.limit(aliases.iterator(), 10))));
      }
      return 1;
    }

    getBuckEventBus().post(BuildEvent.started(buildTargets));

    // Parse the build files to create a DependencyGraph.
    DependencyGraph dependencyGraph;
    try {
      dependencyGraph =
          getParser()
              .parseBuildFilesForTargets(
                  buildTargets, options.getDefaultIncludes(), getBuckEventBus());
    } catch (BuildTargetException | BuildFileParseException e) {
      console.printBuildFailureWithoutStacktrace(e);
      return 1;
    }

    // Create and execute the build.
    build =
        options.createBuild(
            options.getBuckConfig(),
            dependencyGraph,
            getProjectFilesystem(),
            getAndroidDirectoryResolver(),
            artifactCache,
            console,
            getBuckEventBus(),
            Optional.<TargetDevice>absent(),
            getCommandRunnerParams().getPlatform());
    int exitCode = 0;
    try {
      exitCode = executeBuildAndPrintAnyFailuresToConsole(build, console);
    } finally {
      // Shutdown the Executor Service once the build completes.
      // Note: we need to use shutdown() instead of shutdownNow() to ensure that tasks submitted to
      // the Execution Service are completed.
      build.getStepRunner().getListeningExecutorService().shutdown();
    }

    getBuckEventBus().post(BuildEvent.finished(buildTargets, exitCode));

    if (exitCode != 0) {
      return exitCode;
    }

    return 0;
  }
 @Override
 public Iterator<NodeComparison> iterator() {
   return nodeComparisons.iterator();
 }
Exemple #8
0
  AppleBundle(
      BuildRuleParams params,
      SourcePathResolver resolver,
      Either<AppleBundleExtension, String> extension,
      SourcePath infoPlist,
      Map<String, String> infoPlistSubstitutions,
      Optional<BuildRule> binary,
      AppleBundleDestinations destinations,
      Set<SourcePath> resourceDirs,
      Set<SourcePath> resourceFiles,
      Set<SourcePath> dirsContainingResourceDirs,
      ImmutableSet<SourcePath> extensionBundlePaths,
      Optional<ImmutableSet<SourcePath>> resourceVariantFiles,
      Tool ibtool,
      Tool dsymutil,
      Tool strip,
      Optional<AppleAssetCatalog> assetCatalog,
      Set<BuildTarget> tests,
      AppleSdk sdk,
      ImmutableSet<CodeSignIdentity> allValidCodeSignIdentities,
      Optional<SourcePath> provisioningProfileSearchPath) {
    super(params, resolver);
    this.extension =
        extension.isLeft() ? extension.getLeft().toFileExtension() : extension.getRight();
    this.infoPlist = infoPlist;
    this.infoPlistSubstitutions = ImmutableMap.copyOf(infoPlistSubstitutions);
    this.binary = binary;
    this.destinations = destinations;
    this.resourceDirs = resourceDirs;
    this.resourceFiles = resourceFiles;
    this.dirsContainingResourceDirs = dirsContainingResourceDirs;
    this.extensionBundlePaths = extensionBundlePaths;
    this.resourceVariantFiles = resourceVariantFiles;
    this.ibtool = ibtool;
    this.dsymutil = dsymutil;
    this.strip = strip;
    this.assetCatalog = assetCatalog;
    this.binaryName = getBinaryName(getBuildTarget());
    this.bundleRoot = getBundleRoot(getBuildTarget(), this.extension);
    this.binaryPath = this.destinations.getExecutablesPath().resolve(this.binaryName);
    this.tests = ImmutableSortedSet.copyOf(tests);
    this.platformName = sdk.getApplePlatform().getName();
    this.sdkName = sdk.getName();

    // We need to resolve the possible set of profiles and code sign identity at construction time
    // because they form part of the rule key.
    if (binary.isPresent() && ApplePlatform.needsCodeSign(this.platformName)) {
      final Path searchPath;
      if (provisioningProfileSearchPath.isPresent()) {
        searchPath = resolver.getResolvedPath(provisioningProfileSearchPath.get());
      } else {
        searchPath =
            Paths.get(
                System.getProperty("user.home") + "/Library/MobileDevice/Provisioning Profiles");
      }

      Optional<ImmutableSet<ProvisioningProfileMetadata>> provisioningProfiles;
      try {
        provisioningProfiles =
            Optional.of(ProvisioningProfileCopyStep.findProfilesInPath(searchPath));
      } catch (InterruptedException e) {
        // We get here if the user pressed Ctrl-C during the profile discovery step.
        // In this case, we'll fail anyway since the set of profiles will be empty.
        provisioningProfiles = Optional.of(ImmutableSet.<ProvisioningProfileMetadata>of());
      }
      this.provisioningProfiles = provisioningProfiles;

      Optional<CodeSignIdentity> foundIdentity = Optional.absent();
      Optional<String> customIdentity =
          InfoPlistSubstitution.getVariableExpansionForPlatform(
              CODE_SIGN_IDENTITY, this.platformName, this.infoPlistSubstitutions);
      if (customIdentity.isPresent()) {
        LOG.debug("Bundle specifies custom code signing identity: " + customIdentity.get());
        if (CodeSignIdentity.isHash(customIdentity.get())) {
          for (CodeSignIdentity identity : allValidCodeSignIdentities) {
            if (identity.getHash().equals(customIdentity.get())) {
              foundIdentity = Optional.of(identity);
              break;
            }
          }
        } else {
          for (CodeSignIdentity identity : allValidCodeSignIdentities) {
            if (identity.getFullName().startsWith(customIdentity.get())) {
              foundIdentity = Optional.of(identity);
              break;
            }
          }
        }
      } else if (!allValidCodeSignIdentities.isEmpty()) {
        LOG.debug("Using default code signing identity");
        Iterator<CodeSignIdentity> it = allValidCodeSignIdentities.iterator();
        foundIdentity = Optional.of(it.next());
      }
      if (!foundIdentity.isPresent()) {
        throw new HumanReadableException(
            "The platform "
                + platformName
                + " for this target "
                + "requires code signing but couldn't find a compatible code signing identity to use.");
      }
      LOG.debug("Code signing identity is " + foundIdentity.toString());
      this.codeSignIdentity = foundIdentity;
    } else {
      this.provisioningProfiles = Optional.absent();
      this.codeSignIdentity = Optional.absent();
    }
  }