Ejemplo n.º 1
0
  @Override
  public Result execute(UIExecutionContext context) {
    Project project = getSelectedProject(context.getUIContext());
    final DependencyFacet deps = project.getFacet(DependencyFacet.class);

    if (arguments.hasValue()) {
      int count = 0;
      for (Dependency gav : arguments.getValue()) {
        Dependency existingDep =
            deps.getEffectiveManagedDependency(DependencyBuilder.create(gav).setVersion(null));
        if (existingDep != null) {
          if (context
              .getPrompt()
              .promptBoolean(
                  String.format(
                      "Dependency [%s:%s] is currently managed. "
                          + "Reference the existing managed dependency [%s:%s:%s]?",
                      gav.getCoordinate().getArtifactId(),
                      gav.getCoordinate().getGroupId(),
                      existingDep.getCoordinate().getGroupId(),
                      existingDep.getCoordinate().getArtifactId(),
                      existingDep.getCoordinate().getVersion()))) {
            gav = DependencyBuilder.create(existingDep).setScopeType(gav.getScopeType());
          }
        }

        this.installer.install(project, gav);
        count++;
      }

      return Results.success(
          "Installed [" + count + "] dependenc" + (count == 1 ? "y" : "ies") + ".");
    }
    return Results.fail("No arguments specified.");
  }
Ejemplo n.º 2
0
  protected Result processDeployment(Project project, String path, Type type) {
    Result result;

    // The server must be running
    if (serverController.hasServer() && serverController.getServer().isRunning()) {
      final PackagingFacet packagingFacet = project.getFacet(PackagingFacet.class);

      // Can't deploy what doesn't exist
      if (!packagingFacet.getFinalArtifact().exists())
        throw new DeploymentFailureException(
            messages.getMessage("deployment.not.found", path, type));
      final File content;
      if (path == null) {
        content = new File(packagingFacet.getFinalArtifact().getFullyQualifiedName());
      } else if (path.startsWith("/")) {
        content = new File(path);
      } else {
        // TODO this might not work for EAR deployments
        content =
            new File(packagingFacet.getFinalArtifact().getParent().getFullyQualifiedName(), path);
      }
      try {
        final ModelControllerClient client = serverController.getClient();
        final Deployment deployment =
            StandaloneDeployment.create(client, content, null, type, null, null);
        deployment.execute();
        result = Results.success(messages.getMessage("deployment.successful", type));
      } catch (Exception e) {
        if (e.getCause() != null) {
          result =
              Results.fail(e.getLocalizedMessage() + ": " + e.getCause().getLocalizedMessage());
        } else {
          result = Results.fail(e.getLocalizedMessage());
        }
      }
    } else {
      result =
          Results.fail(
              messages.getMessage(
                  "server.not.running", configuration.getHostname(), configuration.getPort()));
    }

    return result;
  }
Ejemplo n.º 3
0
 @Override
 public Result execute(final UIExecutionContext context) throws Exception {
   applyUIValues(context.getUIContext());
   Project project = getSelectedProject(context);
   JPAFacet<?> facet = jpaVersion.getValue();
   if (facetFactory.install(project, facet)) {
     return Results.success();
   }
   return Results.fail("Could not install JPA.");
 }
Ejemplo n.º 4
0
 @Override
 public Result execute(final UIExecutionContext context) throws Exception {
   JavaEESpecFacet chosen = javaEEVersion.getValue();
   if (facetFactory.install(getSelectedProject(context.getUIContext()), chosen)) {
     // This facet may activate other facets, so better invalidate the cache
     projectFactory.invalidateCaches();
     return Results.success("JavaEE " + chosen.getSpecVersion() + " has been installed.");
   }
   return Results.fail("Could not install JavaEE " + chosen.getSpecVersion());
 }
Ejemplo n.º 5
0
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    String url = getJolokiaUrl();
    if (url == null) {
      return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first");
    }

    org.apache.camel.commands.RouteShowCommand command =
        new org.apache.camel.commands.RouteShowCommand(route.getValue(), name.getValue());
    command.execute(getController(), getOutput(context), getError(context));
    return Results.success();
  }
Ejemplo n.º 6
0
  @Override
  public Result start(UIContext context) {
    Result result = null;
    if ((serverController.hasServer() && serverController.getServer().isRunning())
        || false) // getState().isRunningState())
    {
      result = Results.fail(messages.getMessage("server.already.running"));
    } else {
      try {

        if (!serverController.hasServer()) createServer(context);

        Server<ModelControllerClient> server = serverController.getServer();

        // Start the server
        server.start();
        server.checkServerState();

        if (server.isRunning()) {
          result =
              Results.success(
                  messages.getMessage("server.start.success", configuration.getVersion()));
        } else {
          result =
              Results.fail(messages.getMessage("server.start.failed", configuration.getVersion()));
        }
      } catch (Exception e) {
        result =
            Results.fail(
                messages.getMessage(
                    "server.start.failed.exception",
                    configuration.getVersion(),
                    e.getLocalizedMessage()));
      }
      if (result instanceof Failed) {
        // closeConsoleOutput();
      }
    }
    return result;
  }
Ejemplo n.º 7
0
  @Override
  public Result shutdown(UIContext context) {
    try {
      if (!serverController.hasServer()) {
        createServer(context);
      }
      return serverController.shutdownServer();

    } catch (Exception e) {
      return Results.fail(e.getLocalizedMessage());
    } finally {
      serverController.closeClient();
    }
  }
Ejemplo n.º 8
0
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    Result result = Results.success("Project named '" + named.getValue() + "' has been created.");
    DirectoryResource directory = targetLocation.getValue();
    DirectoryResource targetDir = directory.getChildDirectory(named.getValue());

    if (targetDir.mkdirs() || overwrite.getValue()) {
      ProjectType value = type.getValue();

      Project project = null;
      if (value != null) {
        project =
            projectFactory.createProject(
                targetDir, buildSystem.getValue(), value.getRequiredFacets());
      } else {
        project = projectFactory.createProject(targetDir, buildSystem.getValue());
      }

      if (project != null) {
        UIContext uiContext = context.getUIContext();
        MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
        metadataFacet.setProjectName(named.getValue());
        metadataFacet.setProjectVersion(version.getValue());
        metadataFacet.setTopLevelPackage(topLevelPackage.getValue());

        if (finalName.hasValue()) {
          PackagingFacet packagingFacet = project.getFacet(PackagingFacet.class);
          packagingFacet.setFinalName(finalName.getValue());
        }

        uiContext.setSelection(project.getRoot());
        uiContext.getAttributeMap().put(Project.class, project);
      } else result = Results.fail("Could not create project of type: [" + value + "]");
    } else result = Results.fail("Could not create target location: " + targetDir);

    return result;
  }
Ejemplo n.º 9
0
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    JavaResource javaResource = targetClass.getValue();
    JavaClassSource targetClass = javaResource.getJavaType();
    GetSetMethodGenerator generator;
    if (builderPattern.getValue()) {
      generator = new BuilderGetSetMethodGenerator();
    } else {
      generator = new DefaultGetSetMethodGenerator();
    }
    List<PropertySource<JavaClassSource>> selectedProperties = new ArrayList<>();
    if (properties == null || properties.getValue() == null) {
      return Results.fail("No properties were selected");
    }
    for (String selectedProperty : properties.getValue()) {
      selectedProperties.add(targetClass.getProperty(selectedProperty));
    }

    for (PropertySource<JavaClassSource> property : selectedProperties) {
      MethodSource<JavaClassSource> accessor =
          targetClass.getMethod("get" + Strings.capitalize(property.getName()));
      if (accessor == null) {
        generator.createAccessor(property);
      } else {
        if (!generator.isCorrectAccessor(accessor, property)) {
          if (promptToFixMethod(context, accessor.getName(), property.getName())) {
            targetClass.removeMethod(accessor);
            generator.createMutator(property);
          }
        }
      }
      String mutatorMethodName = "set" + Strings.capitalize(property.getName());
      String mutatorMethodParameter = property.getType().getName();
      MethodSource<JavaClassSource> mutator =
          targetClass.getMethod(mutatorMethodName, mutatorMethodParameter);
      if (mutator == null) {
        generator.createMutator(property);
      } else {
        if (!generator.isCorrectMutator(mutator, property)) {
          if (promptToFixMethod(context, mutator.getName(), property.getName())) {
            targetClass.removeMethod(mutator);
            generator.createMutator(property);
          }
        }
      }
    }
    setCurrentWorkingResource(context, targetClass);
    return Results.success("Mutators and accessors were generated successfully");
  }
Ejemplo n.º 10
0
  @Override
  public Result execute(UIExecutionContext context) {
    final Result result;
    Project project = getSelectedProject(context.getUIContext());
    DependencyFacet deps = project.getFacet(DependencyFacet.class);

    String urlValue = url.getValue();
    DependencyRepository rep = deps.removeRepository(urlValue);
    if (rep != null) {
      result = Results.success("Removed repository [" + rep.getId() + "->" + rep.getUrl() + "]");
    } else {
      result = Results.fail("No repository with url [" + urlValue + "]");
    }
    return result;
  }
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    String url = getJolokiaUrl();
    if (url == null) {
      return Results.fail("Not connected to remote jolokia agent. Use camel-connect command first");
    }

    boolean val = "true".equals(verbose.getValue());

    org.apache.camel.commands.CatalogLanguageListCommand command =
        new org.apache.camel.commands.CatalogLanguageListCommand(val, label.getValue());
    command.execute(getController(), getOutput(context), getError(context));

    return Results.success();
  }
Ejemplo n.º 12
0
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    UIContext uiContext = context.getUIContext();
    JavaResource resource = (JavaResource) uiContext.getInitialSelection().get();
    String name = named.getValue();
    String fieldName = conversationFieldName.getValue();
    String beginName = beginMethodName.getValue();
    String endName = endMethodName.getValue();
    Boolean overwriteValue = overwrite.getValue();
    UIOutput output = uiContext.getProvider().getOutput();
    if (resource.exists()) {
      if (resource.getJavaSource().isClass()) {
        JavaClass javaClass = (JavaClass) resource.getJavaSource();

        if (javaClass.hasField(fieldName)
            && !javaClass.getField(fieldName).isType(Conversation.class)) {
          if (overwriteValue) {
            javaClass.removeField(javaClass.getField(fieldName));
          } else {
            return Results.fail("Field [" + fieldName + "] already exists.");
          }
        }
        if (javaClass.hasMethodSignature(beginName)
            && (javaClass.getMethod(beginName).getParameters().size() == 0)) {
          if (overwriteValue) {
            javaClass.removeMethod(javaClass.getMethod(beginName));
          } else {
            return Results.fail("Method [" + beginName + "] exists.");
          }
        }
        if (javaClass.hasMethodSignature(endName)
            && (javaClass.getMethod(endName).getParameters().size() == 0)) {
          if (overwriteValue) {
            javaClass.removeMethod(javaClass.getMethod(endName));
          } else {
            return Results.fail("Method [" + endName + "] exists.");
          }
        }

        javaClass
            .addField()
            .setPrivate()
            .setName(fieldName)
            .setType(Conversation.class)
            .addAnnotation(Inject.class);

        Method<JavaClass> beginMethod =
            javaClass.addMethod().setName(beginName).setReturnTypeVoid().setPublic();
        if (Strings.isNullOrEmpty(name)) {
          beginMethod.setBody(fieldName + ".begin();");
        } else {
          beginMethod.setBody(fieldName + ".begin(\"" + name + "\");");
        }

        if (timeout.getValue() != null) {
          beginMethod.setBody(
              beginMethod.getBody() + "\n" + fieldName + ".setTimeout(" + timeout + ");");
        }

        javaClass
            .addMethod()
            .setName(endName)
            .setReturnTypeVoid()
            .setPublic()
            .setBody(fieldName + ".end();");

        if (javaClass.hasSyntaxErrors()) {
          output.err().println("Modified Java class contains syntax errors:");
          for (SyntaxError error : javaClass.getSyntaxErrors()) {
            output.err().print(error.getDescription());
          }
        }

        resource.setContents(javaClass);
      } else {
        return Results.fail(
            "Must operate on a Java Class file, not an ["
                + resource.getJavaSource().getSourceType()
                + "]");
      }
    }
    return Results.success("Conversation block created");
  }