@Override
 public void generateApplicationSkeleton(String applicationId, String workingDirectory)
     throws AppFactoryException {
   boolean isSuccess =
       ProjectUtils.generateProjectArchetype(
           applicationId,
           workingDirectory,
           ProjectUtils.getArchetypeRequest(applicationId, getProperty(MAVEN_ARCHETYPE_REQUEST)));
   if (isSuccess) {
     String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
     File archetypeDir =
         new File(
             CarbonUtils.getTmpDir()
                 + File.separator
                 + tenantDomain
                 + File.separator
                 + applicationId
                 + File.separator
                 + AppFactoryConstants.MAVEN_ARCHETYPE_DIR);
     initialDeployArtifactGeneration(applicationId, workingDirectory, archetypeDir);
     ProjectUtils.configureFinalName(archetypeDir.getAbsolutePath());
     ProjectUtils.copyArchetypeToTrunk(archetypeDir.getAbsolutePath(), workingDirectory);
     boolean deleteResult = FileUtils.deleteQuietly(archetypeDir);
     if (!deleteResult) {
       log.warn("Error while deleting the archetype directory");
     }
   }
 }
  @Override
  public void generateApplicationSkeleton(String applicationID, String workingDirectory)
      throws AppFactoryException {

    try {
      String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
      String applicationExtenstion =
          ProjectUtils.getApplicationExtenstion(applicationID, tenantDomain);
      String uploadedFileName =
          applicationID
              + "-1.0.0."
              + applicationExtenstion
              + AppFactoryConstants.UPPLOADABLE_SUFFIX;
      copyUploadedAppToLocation(uploadedFileName, workingDirectory);

      if (log.isDebugEnabled()) {
        log.debug(
            "Application skeleton creation hanlded for Uploaded application type with application key -"
                + applicationID);
      }
    } catch (IOException e) {
      log.error(e);
      throw new AppFactoryException("Error when generating uploaded application skeleton", e);
    }
  }
 @Override
 public void generateDeployableFile(
     String rootPath, String applicationId, String version, String stage)
     throws AppFactoryException {
   String applicationExtenstion =
       ProjectUtils.getApplicationExtenstion(
           applicationId, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
   String artifactFileName =
       applicationId
           + AppFactoryConstants.APPFACTORY_ARTIFACT_NAME_VERSION_SEPERATOR
           + version
           + AppFactoryConstants.FILENAME_EXTENSION_SEPERATOR
           + applicationExtenstion;
   String uploadedAppSrcFile =
       rootPath
           + File.separator
           + AppFactoryConstants.AF_GIT_TMP_FOLDER
           + File.separator
           + artifactFileName;
   String uploadedApptmpFolder =
       rootPath + File.separator + AppFactoryConstants.DEPLOYABLE_ARTIFACT_FOLDER;
   try {
     FileUtils.copyFileToDirectory(new File(uploadedAppSrcFile), new File(uploadedApptmpFolder));
   } catch (IOException e) {
     String errMsg = "Error when copying folder from src to artifact tmp : " + e.getMessage();
     log.error(errMsg, e);
     throw new AppFactoryException(errMsg, e);
   }
 }
 @Override
 public List<File> getPreVersionDeleteableFiles(
     String applicationID, String targetVersion, String currentVersion, String workingDir)
     throws AppFactoryException {
   String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
   String applicationExtension;
   applicationExtension = ProjectUtils.getApplicationExtenstion(applicationID, tenantDomain);
   List<File> deletableFiles = new ArrayList<File>();
   deletableFiles.add(
       new File(
           CarbonUtils.getTmpDir()
               + File.separator
               + AppFactoryConstants.REPOSITORY_BRANCH
               + File.separator
               + applicationID
               + File.separator
               + targetVersion
               + File.separator
               + applicationID
               + AppFactoryConstants.MINUS
               + AppFactoryConstants.INITIAL_UPLOADED_APP_VERSION
               + AppFactoryConstants.DOT_SEPERATOR
               + applicationExtension));
   return deletableFiles;
 }
 /** {@inheritDoc} */
 @Override
 public File retrieveArtifact(
     String applicationId, String version, String revision, String buildId, String tenantDomain)
     throws AppFactoryException {
   File targetDir = null;
   List<File> artifactFiles = null;
   File workDir = new File(getStoragePathForArtifact(applicationId, version, buildId));
   String applicationType = ProjectUtils.getApplicationType(applicationId, tenantDomain);
   String[] fileExtension = {applicationType};
   artifactFiles = (List<File>) FileUtils.listFiles(workDir, fileExtension, false);
   targetDir = artifactFiles.get(0);
   return targetDir;
 }
 /**
  * Generate the initial artifact by running maven assembly plugin on pre installed artifacts in
  * archetype
  *
  * @param applicationId application id
  * @param workingDirectory current working directory. this is where we do all application related
  *     file operations
  * @param archetypeDir location of the archetypes generated
  * @throws AppFactoryException
  */
 protected void initialDeployArtifactGeneration(
     String applicationId, String workingDirectory, File archetypeDir) throws AppFactoryException {
   List<String> goals = new ArrayList<String>();
   goals.add(AppFactoryConstants.MVN_GOAL_CLEAN);
   goals.add(AppFactoryConstants.MVN_GOAL_INSTALL);
   goals.add(AppFactoryConstants.MVN_GOAL_ASSEMBLY);
   File projectDir = new File(archetypeDir.getAbsolutePath() + File.separator + applicationId);
   File initialArtifact =
       new File(
           archetypeDir.getAbsolutePath()
               + File.separator
               + applicationId
               + AppFactoryConstants.AF_ARCHETYPE_INITIAL_ARTIFACT_LOCATION);
   boolean isInitialArtifactGenerationSuccess =
       ProjectUtils.initialDeployArtifactGeneration(
           applicationId, projectDir, initialArtifact, new File(workingDirectory), goals);
   if (isInitialArtifactGenerationSuccess) {
     try {
       File initialArtifactSource =
           new File(
               projectDir
                   + File.separator
                   + AppFactoryConstants.AF_ARCHETYPE_INITIAL_ARTIFACT_SOURCE_LOCATION);
       FileUtils.deleteDirectory(initialArtifactSource);
       File assemblyFile =
           new File(
               projectDir
                   + File.separator
                   + AppFactoryConstants.AF_ARCHETYPE_INITIAL_ARTIFACT_ASSEMBLY_XML_LOCATION);
       FileUtils.forceDelete(assemblyFile);
       File assemblyDescriptorFile =
           new File(
               projectDir
                   + File.separator
                   + AppFactoryConstants.AF_ARCHETYPE_INITIAL_ARTIFACT_BIN_XML_LOCATION);
       FileUtils.forceDelete(assemblyDescriptorFile);
     } catch (IOException e) {
       String msg = "Error occurred while deleting files used in deploy artifact generation";
       log.error(msg, e);
       throw new AppFactoryException(msg, e);
     }
   }
 }