示例#1
0
  @Command("new-enum-type")
  public void newEnumType(
      @PipeIn final InputStream in,
      @Option(
              required = false,
              help = "the package in which to build this Class",
              description = "source package",
              type = PromptType.JAVA_PACKAGE,
              name = "package")
          final String pckg,
      @Option(
              required = false,
              help = "the class definition: surround with quotes",
              description = "class definition")
          final String... def)
      throws FileNotFoundException {

    JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

    JavaEnum je = null;
    if (def != null) {
      String classDef = Strings.join(Arrays.asList(def), " ");
      je = JavaParser.parse(JavaEnum.class, classDef);
    } else if (in != null) {
      je = JavaParser.parse(JavaEnum.class, in);
    } else {
      throw new RuntimeException("arguments required");
    }

    if (pckg != null) {
      je.setPackage(pckg);
    }

    if (!je.hasSyntaxErrors()) {
      java.saveEnumTypeSource(je);
    } else {
      writer.println(ShellColor.RED, "Syntax Errors:");
      for (SyntaxError error : je.getSyntaxErrors()) {
        writer.println(error.toString());
      }
      writer.println();

      if (prompt.promptBoolean("Your class has syntax errors, create anyway?", true)) {
        java.saveEnumTypeSource(je);
      }
    }

    pickUp.fire(new PickupResource(java.getEnumTypeResource(je)));
  }
示例#2
0
  @Command(value = "setup", help = "Setup validation for this project")
  public void setup(
      @Option(name = "provider", defaultValue = "HIBERNATE_VALIDATOR", required = true)
          final BVProvider providerType,
      @Option(name = "messageInterpolator", type = PromptType.JAVA_CLASS)
          final String messageInterpolator,
      @Option(name = "traversableResolver", type = PromptType.JAVA_CLASS)
          final String traversableResolver,
      @Option(name = "constraintValidatorFactory", type = PromptType.JAVA_CLASS)
          final String constraintValidatorFactory) {
    // instantiates the validation provider specified by the user
    final ValidationProvider provider = providerType.getValidationProvider(beanManager);

    if (!project.hasFacet(ValidationFacet.class)) {
      request.fire(new InstallFacets(ValidationFacet.class));
    }

    installDependencies(provider.getDependencies());

    if (!provider.getAdditionalDependencies().isEmpty()) {
      if (prompt.promptBoolean(
          "Would you install " + providerType.getName() + " additional dependencies?", false)) {
        installDependencies(provider.getAdditionalDependencies());
      }
    }

    if (provider.getDefaultDescriptor() != null) {
      final ValidationDescriptor providerDescriptor = provider.getDefaultDescriptor();
      final ValidationDescriptor descriptor =
          Descriptors.create(ValidationDescriptor.class)
              .setDefaultProvider(providerDescriptor.getDefaultProvider())
              .setMessageInterpolator(
                  messageInterpolator == null
                      ? providerDescriptor.getMessageInterpolator()
                      : messageInterpolator)
              .setTraversableResolver(
                  traversableResolver == null
                      ? providerDescriptor.getTraversableResolver()
                      : traversableResolver)
              .setConstraintValidatorFactory(
                  constraintValidatorFactory == null
                      ? providerDescriptor.getConstraintValidatorFactory()
                      : constraintValidatorFactory);

      project.getFacet(ValidationFacet.class).saveConfig(descriptor);
    }
  }