<commit_before>/**
 * Copyright (C) 2011, 2012 camunda services GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.camunda.fox.platform.deployer;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import org.activiti.engine.impl.interceptor.CommandExecutor;

import com.camunda.fox.platform.deployer.impl.ActivateDeploymentCmd;
import com.camunda.fox.platform.deployer.impl.DeployIfChangedCmd;
import com.camunda.fox.platform.deployer.impl.UndeployCmd;

/**
 * Server-independent Deployment / Redeployment Strategy
 * <p>
 * Each deploymentJob (representing a '.jar', or '.bar'),  is identified by its full 
 * path relative to the deploy folder of the server. Using this path as a name, a deployment 
 * is created in activiti. 
 * <br />
 * Upon reception of a deployment job, we check, for each process, whether processes with the same key(id) 
 * are already deployed. <br />
 *   If true, we check whether they are from the same deployment-unit. <br />
 *     If not, the deployment fails.<br />
 *     If true, we check whether the process has changed. <br />
 *       If the process has changed, we create a new activiti deployment, for all the processes in the job.<br />
 *       Otherwise, we set the classloader passed-in by the deployment job for the existing activiti deployment.<br />
 *   If the deployment job contains at least one process the key of which is not yet present in the activiti-db, a new deployment for all the processes is created.<br />
 * </p> 
 * 
 * @author <NAME>
 */
public abstract class AbstractActivitiDeployer {

  private static Logger log = Logger.getLogger(AbstractActivitiDeployer.class.getName());
  
  // /////////////////////////////////////////// Configuration

  public final static Set<String> DEPLOYABLE_RESOURCE_SUFFIXES;
  static {
    DEPLOYABLE_RESOURCE_SUFFIXES = new HashSet<String>();
    DEPLOYABLE_RESOURCE_SUFFIXES.add(".bpmn20.xml");
    // DEPLOYABLE_RESOURCE_SUFFIXES.add(".form"); NOT SUPPORTED FOR NOW
  }

  public String getJarExtension() {
    return ".bar";
  }

  // NOTE: these are provided for subclasses but not actually used here:
  protected String processArchiveMarkerFile = "META-INF/processes.xml";
  protected Set<String> deployableResourceSuffixes = DEPLOYABLE_RESOURCE_SUFFIXES;
  
  protected final Set<String> activeDeploymentIds = new HashSet<String>();
  
  /////////////////////////////////////////// Deployment methods
  
  /**
   * Ceate a new deployment if at least one of the resources have changed.
   * 
   * @param name the name for the deployment
   * @param resources a list of resources
   * @param classLoader the classloader for this deployment
   * @param activeDeployments 
   * 
   */
  public String deploy(String name, Map<String, byte[]> resources, ClassLoader classLoader ) {
    log.fine("===================================================================");
    try {
      CommandExecutor commandExecutor = getCommandExecutor();
      if (commandExecutor == null) {
        log.warning("Found process(es) but not performing deployment, commandExecutor is null. Is the activiti-service.jar deployed?");
        return null;
      } else {
        String deploymentId = getCommandExecutor().execute(new DeployIfChangedCmd(name, resources, classLoader, new HashSet<String>(activeDeploymentIds)));
        
        getCommandExecutor().execute(new ActivateDeploymentCmd(deploymentId, classLoader));
        
        activeDeploymentIds.add(deploymentId);
        return deploymentId;
      }
     
    } finally {
      log.fine("===================================================================");
    }
  }
  
  /**
   * Undeploy a deployment. 
   * 
   * @param name the name of the deployment
   * 
   */
  public String unDeploy(String name, boolean delete) {
    log.fine("===================================================================");
    try {
      CommandExecutor commandExecutor = getCommandExecutor();
      if (commandExecutor == null) {
        log.warning("Not performing undeployment, command executor is null.");
        return null;
      } else {
        String deploymentId = commandExecutor.execute(new UndeployCmd(name, delete));
        activeDeploymentIds.remove(deploymentId);
        return deploymentId;        
      }
    } finally {
      log.fine("===================================================================");
    }
  }
  

  /////////////////////////////////////////// Getters / Setters

  protected abstract CommandExecutor getCommandExecutor();

  public Set<String> getDeployableResourceSuffixes() {
    return deployableResourceSuffixes;
  }

  public String getProcessArchiveMarkerFile() {
    return processArchiveMarkerFile;
  }

  public void setProcessArchiveMarkerFile(String processArchiveMarkerFile) {
    this.processArchiveMarkerFile = processArchiveMarkerFile;
  }

  public void setDeployableResourceSuffixes(Set<String> deployableResourceSuffixes) {
    this.deployableResourceSuffixes = deployableResourceSuffixes;
  }

}<commit_msg>Removed dead code (deployable file extensions should be obtained from BpmnDeployer)<commit_after>/**
 * Copyright (C) 2011, 2012 camunda services GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.camunda.fox.platform.deployer;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import org.activiti.engine.impl.interceptor.CommandExecutor;

import com.camunda.fox.platform.deployer.impl.ActivateDeploymentCmd;
import com.camunda.fox.platform.deployer.impl.DeployIfChangedCmd;
import com.camunda.fox.platform.deployer.impl.UndeployCmd;

/**
 * Server-independent Deployment / Redeployment Strategy
 * <p>
 * Each deploymentJob (representing a '.jar', or '.bar'),  is identified by its full 
 * path relative to the deploy folder of the server. Using this path as a name, a deployment 
 * is created in activiti. 
 * <br />
 * Upon reception of a deployment job, we check, for each process, whether processes with the same key(id) 
 * are already deployed. <br />
 *   If true, we check whether they are from the same deployment-unit. <br />
 *     If not, the deployment fails.<br />
 *     If true, we check whether the process has changed. <br />
 *       If the process has changed, we create a new activiti deployment, for all the processes in the job.<br />
 *       Otherwise, we set the classloader passed-in by the deployment job for the existing activiti deployment.<br />
 *   If the deployment job contains at least one process the key of which is not yet present in the activiti-db, a new deployment for all the processes is created.<br />
 * </p> 
 * 
 * @author <NAME>
 */
public abstract class AbstractActivitiDeployer {

  private static Logger log = Logger.getLogger(AbstractActivitiDeployer.class.getName());
  
  // /////////////////////////////////////////// Configuration

  protected final Set<String> activeDeploymentIds = new HashSet<String>();
  
  /////////////////////////////////////////// Deployment methods
  
  /**
   * Ceate a new deployment if at least one of the resources have changed.
   * 
   * @param name the name for the deployment
   * @param resources a list of resources
   * @param classLoader the classloader for this deployment
   * @param activeDeployments 
   * 
   */
  public String deploy(String name, Map<String, byte[]> resources, ClassLoader classLoader ) {
    log.fine("===================================================================");
    try {
      CommandExecutor commandExecutor = getCommandExecutor();
      if (commandExecutor == null) {
        log.warning("Found process(es) but not performing deployment, commandExecutor is null. Is the activiti-service.jar deployed?");
        return null;
      } else {
        String deploymentId = getCommandExecutor().execute(new DeployIfChangedCmd(name, resources, classLoader, new HashSet<String>(activeDeploymentIds)));
        
        getCommandExecutor().execute(new ActivateDeploymentCmd(deploymentId, classLoader));
        
        activeDeploymentIds.add(deploymentId);
        return deploymentId;
      }
     
    } finally {
      log.fine("===================================================================");
    }
  }
  
  /**
   * Undeploy a deployment. 
   * 
   * @param name the name of the deployment
   * 
   */
  public String unDeploy(String name, boolean delete) {
    log.fine("===================================================================");
    try {
      CommandExecutor commandExecutor = getCommandExecutor();
      if (commandExecutor == null) {
        log.warning("Not performing undeployment, command executor is null.");
        return null;
      } else {
        String deploymentId = commandExecutor.execute(new UndeployCmd(name, delete));
        activeDeploymentIds.remove(deploymentId);
        return deploymentId;        
      }
    } finally {
      log.fine("===================================================================");
    }
  }
  

  /////////////////////////////////////////// Getters / Setters

  protected abstract CommandExecutor getCommandExecutor();

}
{'fraction_non_alphanumeric': 0.15922006662747404, 'fraction_numerical': 0.0025475210660395845, 'mean_word_length': 3.2760787599497276, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7396345', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2544, 'n_words': 887}