Пример #1
0
  /**
   * Constructs the feature configuration from a {@code CToolchain} protocol buffer.
   *
   * @param toolchain the toolchain configuration as specified by the user.
   * @throws InvalidConfigurationException if the configuration has logical errors.
   */
  CcToolchainFeatures(CToolchain toolchain) throws InvalidConfigurationException {
    // Build up the feature graph.
    // First, we build up the map of name -> features in one pass, so that earlier features can
    // reference later features in their configuration.
    ImmutableList.Builder<Feature> features = ImmutableList.builder();
    HashMap<String, Feature> featuresByName = new HashMap<>();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      Feature feature = new Feature(toolchainFeature);
      features.add(feature);
      if (featuresByName.put(feature.getName(), feature) != null) {
        throw new InvalidConfigurationException(
            "Invalid toolchain configuration: feature '"
                + feature.getName()
                + "' was specified multiple times.");
      }
    }
    this.features = features.build();
    this.featuresByName = ImmutableMap.copyOf(featuresByName);

    // Next, we build up all forward references for 'implies' and 'requires' edges.
    ImmutableMultimap.Builder<Feature, Feature> implies = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, ImmutableSet<Feature>> requires =
        ImmutableMultimap.builder();
    // We also store the reverse 'implied by' and 'required by' edges during this pass.
    ImmutableMultimap.Builder<Feature, Feature> impliedBy = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, Feature> requiredBy = ImmutableMultimap.builder();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      String name = toolchainFeature.getName();
      Feature feature = featuresByName.get(name);
      for (CToolchain.FeatureSet requiredFeatures : toolchainFeature.getRequiresList()) {
        ImmutableSet.Builder<Feature> allOf = ImmutableSet.builder();
        for (String requiredName : requiredFeatures.getFeatureList()) {
          Feature required = getFeatureOrFail(requiredName, name);
          allOf.add(required);
          requiredBy.put(required, feature);
        }
        requires.put(feature, allOf.build());
      }
      for (String impliedName : toolchainFeature.getImpliesList()) {
        Feature implied = getFeatureOrFail(impliedName, name);
        impliedBy.put(implied, feature);
        implies.put(feature, implied);
      }
    }
    this.implies = implies.build();
    this.requires = requires.build();
    this.impliedBy = impliedBy.build();
    this.requiredBy = requiredBy.build();
  }
 public IfThenElseGenericFeature(
     BooleanFeature<T> condition, Feature<T, Y> thenFeature, Feature<T, Y> elseFeature) {
   super();
   this.condition = condition;
   this.thenFeature = thenFeature;
   this.elseFeature = elseFeature;
   this.setName(
       "IfThenElse("
           + condition.getName()
           + ","
           + thenFeature.getName()
           + ","
           + elseFeature.getName()
           + ")");
 }
Пример #3
0
    public static void printNeighbors(ArrayList neighbors) {
        int i = 0;
        for(Neighbor neighbor : neighbors) {
            Instance instance = neighbor.getInstance();

            System.out.println("\nNeighbor " + (i + 1) + ", distance: " + neighbor.getDistance());
            i++;
            for(Feature f : instance.getAttributes()) {
                System.out.print(f.getName() + ": ");
                if(f instanceof Category) {
                    System.out.println(((Category)f).getCategory().toString());
                }
                else if(f instanceof Distance) {
                    System.out.println(((Distance)f).getDistance().toString());
                }
                else if (f instanceof Expiration) {
                    System.out.println(((Expiration)f).getExpiry().toString());
                }
                else if (f instanceof Handset) {
                    System.out.print(((Handset)f).getOs().toString() + ", ");
                    System.out.println(((Handset)f).getDevice().toString());
                }
                else if (f instanceof Offer) {
                    System.out.println(((Offer)f).getOfferType().toString());
                }
                else if (f instanceof WSAction) {
                    System.out.println(((WSAction)f).getAction().toString());
                }
            }
        }
    }
Пример #4
0
 public Feature getFeature(final String feature) {
   for (Feature f : features) {
     if (f.getName().equals(feature)) {
       return f;
     }
   }
   throw new NoSuchObjectException("No such Feature in project[" + feature + "]:" + feature);
 }
Пример #5
0
 @VisibleForTesting
 Collection<String> getFeatureNames() {
   Collection<String> featureNames = new HashSet<>();
   for (Feature feature : features) {
     featureNames.add(feature.getName());
   }
   return featureNames;
 }
Пример #6
0
 private FeatureConfiguration(ImmutableList<Feature> enabledFeatures) {
   this.enabledFeatures = enabledFeatures;
   ImmutableSet.Builder<String> builder = ImmutableSet.builder();
   for (Feature feature : enabledFeatures) {
     builder.add(feature.getName());
   }
   this.enabledFeatureNames = builder.build();
 }
 private String getTypeOfResponseVariable(String responseVariable, List<Feature> features) {
   String type = null;
   for (Feature feature : features) {
     if (feature.getName().equals(responseVariable)) {
       type = feature.getType();
     }
   }
   return type;
 }
Пример #8
0
  @Override
  public List<Frame> execute(List<CVParticle> input) throws Exception {
    Frame frame = null;
    List<Feature> features = new ArrayList<Feature>();
    for (CVParticle particle : input) {
      if (particle instanceof Feature) {
        features.add((Feature) particle);
      } else if (particle instanceof Frame && frame == null) {
        frame = (Frame) particle;
      }
    }
    if (frame == null)
      frame =
          new Frame(
              input.get(0).getStreamId(),
              input.get(0).getSequenceNr(),
              Frame.NO_IMAGE,
              (byte[]) null,
              0L,
              new Rectangle());

    // merge new features with already existing features in the Frame
    f1:
    for (Feature newF : features) {
      for (Feature oldF : frame.getFeatures()) {
        if (newF.getName().equals(oldF.getName())) {
          oldF.getSparseDescriptors().addAll(newF.getSparseDescriptors());
          continue f1;
        }
      }
      frame.getFeatures().add(newF);
    }
    List<Frame> result = new ArrayList<Frame>();
    result.add(frame);
    return result;
  }
    private void beginScenario(DescribedStatement scenario) {
      if (testResult == null) {
        String testClass =
            String.format("%s %s", currentFeature.getKeyword(), currentFeature.getName());
        String testName = String.format("%s %s", scenario.getKeyword(), scenario.getName());
        testResult = new Bundle(resultTemplate);
        testResult.putString(REPORT_KEY_NAME_CLASS, testClass);
        testResult.putString(REPORT_KEY_NAME_TEST, testName);
        testResult.putInt(REPORT_KEY_NUM_CURRENT, ++scenarioCounter);

        testResult.putString(
            Instrumentation.REPORT_KEY_STREAMRESULT, String.format("\n%s:", testClass));

        sendStatus(REPORT_VALUE_RESULT_START, testResult);
        resultCode = 0;
      }
    }
Пример #10
0
 public static void printClassificationInstance(Instance classificationInstance) {
     for(Feature f : classificationInstance.getAttributes()) {
         System.out.print(f.getName() + ": ");
         if(f instanceof Category) {
             System.out.println(((Category)f).getCategory().toString());
         }
         else if(f instanceof Distance) {
             System.out.println(((Distance)f).getDistance().toString());
         }
         else if (f instanceof Expiration) {
             System.out.println(((Expiration)f).getExpiry().toString());
         }
         else if (f instanceof Handset) {
             System.out.print(((Handset)f).getOs().toString() + ", ");
             System.out.println(((Handset)f).getDevice().toString());
         }
         else if (f instanceof Offer) {
             System.out.println(((Offer)f).getOfferType().toString());
         }
         else if (f instanceof WSAction) {
             System.out.println(((WSAction)f).getAction().toString());
         }
     }
 }
  /** @param featuresXml */
  private void generate(FeaturesXml featuresXml) throws Exception {
    // Add the repositories
    if (this.repositories != null) {
      for (String repo : repositories) {
        featuresXml.addRepository(repo);
      }
    }

    // Collect all dependencies (bundle candidates)
    ScopeArtifactFilter filter = new ScopeArtifactFilter(DefaultArtifact.SCOPE_RUNTIME);
    DependencyNode dependencyGraph = dependencyGraphBuilder.buildDependencyGraph(project, filter);
    CollectingDependencyNodeVisitor collectingVizzy = new CollectingDependencyNodeVisitor();
    dependencyGraph.accept(collectingVizzy);
    List<DependencyNode> nodes = collectingVizzy.getNodes();

    // Iterate all features
    for (Feature feature : features) {
      getLog().info("Generating feature '" + feature.getName() + "'"); // $NON-NLS-1$ //$NON-NLS-2$
      // Create the feature
      featuresXml.addFeature(feature.getName(), feature.getVersion(), feature.getComment());
      // Add any feature dependencies
      List<Feature> onFeatures = feature.getDependsOnFeatures();
      if (onFeatures != null && !onFeatures.isEmpty()) {
        for (Feature onFeature : onFeatures) {
          getLog()
              .info(
                  "   Depends on feature: "
                      + onFeature.getName()
                      + "/"
                      + onFeature.getVersion()); // $NON-NLS-1$ //$NON-NLS-2$
          featuresXml.addFeatureDependency(
              feature.getName(), feature.getVersion(), onFeature.getName(), onFeature.getVersion());
        }
      }
      // Add any included or non-excluded bundles (from artifact
      // dependency graph)
      PatternIncludesArtifactFilter includesFilter =
          new PatternIncludesArtifactFilter(feature.getIncludes());
      PatternExcludesArtifactFilter excludesFilter =
          new PatternExcludesArtifactFilter(feature.getExcludes());
      String startLevel = feature.getStartLevel();
      for (DependencyNode dependencyNode : nodes) {
        if (isSelf(dependencyNode)) continue;
        Artifact artifact = dependencyNode.getArtifact();
        // If no includes, assume everything
        boolean includeBundle = feature.getIncludes() == null || feature.getIncludes().isEmpty();
        if (includeBundle) {
          getLog()
              .debug(
                  "   Artifact "
                      + artifact
                      + " matches default [all] filter (including)."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (includesFilter.include(artifact)) {
          getLog()
              .debug(
                  "   Artifact "
                      + artifact
                      + " matched include filter (including)."); //$NON-NLS-1$ //$NON-NLS-2$
          includeBundle = true;
        }
        // Excludes must be explicit.
        if (!excludesFilter.include(artifact)) {
          getLog()
              .debug(
                  "   Artifact "
                      + artifact
                      + " matched exclude filter (excluding)."); //$NON-NLS-1$ //$NON-NLS-2$
          includeBundle = false;
        }

        if (includeBundle) {
          featuresXml.addBundle(
              feature.getName(),
              feature.getVersion(),
              formatArtifactAsBundle(artifact),
              startLevel);
        }
      }

      // Add additional explicit bundles specified in the config
      List<String> bundles = feature.getBundles();
      if (bundles != null && !bundles.isEmpty()) {
        for (String bundle : bundles) {
          getLog().debug("   Adding explicit bundle: " + bundle); // $NON-NLS-1$
          featuresXml.addBundle(feature.getName(), feature.getVersion(), bundle, startLevel);
        }
      }

      // Add config files if any are specified in the pom
      List<ConfigFile> configFiles = feature.getConfigFiles();
      if (configFiles != null && !configFiles.isEmpty()) {
        for (ConfigFile configFile : configFiles) {
          getLog().debug("   Adding config file: " + configFile.getValue()); // $NON-NLS-1$
          featuresXml.addConfigFile(
              feature.getName(),
              feature.getVersion(),
              configFile.getFinalName(),
              configFile.getValue());
        }
      }
    }
  }