示例#1
0
 @Override
 public void visit(TextNode node) {
   if (this.pages < 2 && StringUtils.isEmptyOrNull(this.title)) {
     this.title = node.getText();
   }
   super.visit(node);
 }
 /**
  * Clones secured git remote repository to the file system.
  *
  * @param gitDirectory where the remote repository will be cloned
  * @param repositoryURI repository's URI example: https://qwerty.com/xyz/abc.git
  * @param username the username used for authentication
  * @param password the password used for authentication
  * @throws InvalidRemoteException
  * @throws TransportException
  * @throws GitAPIException
  */
 public static void cloneRepository(
     File gitDirectory, String repositoryURI, String username, String password)
     throws InvalidRemoteException, TransportException, GitAPIException {
   try {
     CloneCommand cloneCommand = Git.cloneRepository();
     cloneCommand.setURI(repositoryURI);
     if (!StringUtils.isEmptyOrNull(username) && !StringUtils.isEmptyOrNull(password)) {
       cloneCommand.setCredentialsProvider(
           new UsernamePasswordCredentialsProvider(username, password));
     }
     cloneCommand.setRemote(Constants.DEFAULT_REMOTE_NAME);
     cloneCommand.setDirectory(gitDirectory);
     cloneCommand.call();
   } catch (NullPointerException e) {
     throw new TransportException(INVALID_USERNAME_AND_PASSWORD);
   }
 }
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces("text/plain")
  public String deploy(
      DeployRequest req,
      @HeaderParam("Authorization") @DefaultValue("no token") String auth,
      @Context ServletContext context)
      throws Exception {
    if (!this.isAuth(auth)) {
      throw new Exception("Unauthorized!");
    }

    String contextRoot = req.getContextRoot();
    String artifact = req.getArtifact();

    if (StringUtils.isEmptyOrNull(req.getRepo()) || StringUtils.isEmptyOrNull(req.getDomain())) {
      return "Error: missing repo and/or domain.";
    }

    if (StringUtils.isEmptyOrNull(contextRoot)) {
      contextRoot = "/";
    }

    if (StringUtils.isEmptyOrNull(artifact)) {
      artifact = "com.meltmedia.cadmium:cadmium-war:war:" + version;
    }

    if (StringUtils.isEmptyOrNull(req.getConfigRepo())) {
      req.setConfigRepo(req.getRepo());
    }

    if (StringUtils.isEmptyOrNull(req.getConfigBranch())) {
      req.setConfigBranch("master");
    }

    if (StringUtils.isEmptyOrNull(req.getBranch())) {
      req.setBranch("master");
    }

    ChannelMember coordinator = membershipTracker.getCoordinator();
    com.meltmedia.cadmium.deployer.DeployRequest mRequest =
        new com.meltmedia.cadmium.deployer.DeployRequest();
    mRequest.setBranch(req.getBranch());
    mRequest.setRepo(req.getRepo());
    mRequest.setConfigBranch(req.getConfigBranch());
    mRequest.setConfigRepo(req.getConfigRepo());
    mRequest.setDomain(req.getDomain());
    mRequest.setContext(contextRoot);
    mRequest.setSecure(!req.isDisableSecurity());
    mRequest.setArtifact(artifact);
    Message<com.meltmedia.cadmium.deployer.DeployRequest> msg =
        new Message<com.meltmedia.cadmium.deployer.DeployRequest>(
            DeployCommandAction.DEPLOY_ACTION, mRequest);
    response.reset(coordinator);
    sender.sendMessage(msg, coordinator);

    int timeout = 4800;
    while (timeout-- > 0) {
      Thread.sleep(500l);
      Message<DeployResponse> returnMsg = response.getResponse(coordinator);
      if (returnMsg != null) {
        if (returnMsg.getBody().getError() != null) {
          throw new Exception(returnMsg.getBody().getError());
        }
        return returnMsg.getBody().getWarName();
      }
    }

    return "ok";
  }