new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/BuildApplication.java
public static Path buildApplication(Path appSrcPath, Map<String, String> antParams,
                                      String antTargets, String archiveDistDir, String namespace) {
    final LoggingFacade logger = getLogger();
    setImage(namespace);

    // Path of temp location for application source directory
    Path tempAppPath = Paths.get(WORK_DIR, "j2eeapplications", appSrcPath.getFileName().toString());
    // directory to copy archives built
    Path destArchiveBaseDir = Paths.get(WORK_DIR, appSrcPath.getFileName().toString());
    Path destDir = null;

    assertDoesNotThrow(() -> {
      // recreate WORK_DIR/j2eeapplications/<application_directory_name>
      logger.info("Deleting and recreating {0}", tempAppPath);
      Files.createDirectories(tempAppPath);
      deleteDirectory(tempAppPath.toFile());
      Files.createDirectories(tempAppPath);

      Files.createDirectories(destArchiveBaseDir);
      deleteDirectory(destArchiveBaseDir.toFile());
      Files.createDirectories(destArchiveBaseDir);

      // copy the application source to WORK_DIR/j2eeapplications/<application_directory_name> for zipping
      logger.info("Copying {0} to {1}", appSrcPath, tempAppPath);
      copyDirectory(appSrcPath.toFile(), tempAppPath.toFile());
    });

    // zip up the application source to be copied to pod for building
    Path zipFile = Paths.get(FileUtils.createZipFile(tempAppPath));


    // add ant properties as env variable in pod
    V1Container buildContainer = new V1Container();

    // set ZIP_FILE location as env variable in pod
    buildContainer.addEnvItem(new V1EnvVar()
        .name("ZIP_FILE")
        .value(zipFile.getFileName().toString()));

    // set ant parameteres as env variable in pod
    if (antParams != null) {
      StringBuilder params = new StringBuilder();
      antParams.entrySet().forEach((parameter) -> {
        params.append("-D").append(parameter.getKey()).append("=").append(parameter.getValue()).append(" ");
      });
      buildContainer = buildContainer
          .addEnvItem(new V1EnvVar().name("sysprops").value(params.toString()));
    }

    // set add targets in env variable "targets"
    if (antTargets != null) {
      buildContainer = buildContainer
          .addEnvItem(new V1EnvVar().name("targets").value(antTargets));
    }

    //setup temporary WebLogic pod to build application
    V1Pod webLogicPod = setupWebLogicPod(namespace, buildContainer);

    try {
      //copy the zip file to /u01 location inside pod
      Kubernetes.copyFileToPod(namespace, webLogicPod.getMetadata().getName(),
          null, zipFile, Paths.get("/u01", zipFile.getFileName().toString()));
    } catch (ApiException | IOException  ioex) {
      logger.info(ioex.getMessage());
    }
    try {
      //copy the build script to /u01 location inside pod
      Kubernetes.copyFileToPod(namespace, webLogicPod.getMetadata().getName(),
          null, BUILD_SCRIPT_SOURCE_PATH, Paths.get("/u01", BUILD_SCRIPT));
    } catch (ApiException | IOException  ioex) {
      logger.info(ioex.getMessage());
    }
    try {
      //Kubernetes.exec(webLogicPod, new String[]{"/bin/sh", "/u01/" + BUILD_SCRIPT});
      ExecResult exec = Exec.exec(webLogicPod, null, false, "/bin/sh", "/u01/" + BUILD_SCRIPT);
      assertEquals(0, exec.exitValue());
      if (exec.stdout() != null) {
        logger.info(exec.stdout());
      }
      if (exec.stderr() != null) {
        logger.info(exec.stderr());
      }
      Kubernetes.copyDirectoryFromPod(webLogicPod,
          Paths.get(APPLICATIONS_PATH, archiveDistDir).toString(), destArchiveBaseDir);
    } catch (ApiException | IOException | InterruptedException ioex) {
      logger.info(ioex.getMessage());
    }

    return destDir = Paths.get(destArchiveBaseDir.toString(), "u01/application", archiveDistDir);
  }
/**
   * Build application.
   *
   * <p>The appSrcPath, your application source directory is zipped up and copied to a WebLogic server pod for building.
   * If your archives are placed under &lt application_source &gt /build after building, use <b>build</b> as the
   * archiveDistDir param value. This method copies the folder <b>archiveDistDir</b> to local file system and absolute
   * path of the <b>archiveDistDir</b> directory is returned by this method.
   * <p> Example Usage: </p>

   * <pre>{@literal
   *     HashMap <String,String> antParams = new HashMap<>();
   *     antParams.put("key","value");
   *
   *     Path archivesDir = BuildApplication.buildApplication(
   *         "/scratch/speriyat/weblogic-kubernetes-operator/new-integration-tests/src/test/resources/apps/clusterview",
   *         antParams,
   *         "clean build all" // these targets must be supported by your build file
   *         "build" // the directory your build system creates
   *         "ns-abcd" // your domain or operator namespace, so that the pods are cleaned up after test is done
   *     );
   *     }
   * The returned archivesDir location will be -
   * WORK_DIR/<b>your_application_name</b>/u01/application/<b>archiveDistDir</b>
   * All your built archives will be under the above directory
   * Example: /tmp/it-results/clusterview/u01/application/dist/clusterview.war
   * </pre>
   * </p>
   *
   * @param appSrcPath path of the application source folder
   * @param antParams ant parameters
   * @param antTargets ant targets to call
   * @param archiveDistDir location of the archive built inside source directory
   * @param namespace name of the namespace to create the pod in
   * @return Path path of the archive built
   */
Build application.
The appSrcPath, your application source directory is zipped up and copied to a WebLogic server pod for building.
If your archives are placed under < application_source > /build after building, use build as the
archiveDistDir param value. This method copies the folder archiveDistDir to local file system and absolute
path of the archiveDistDir directory is returned by this method.
 Example Usage: 

{@literal
HashMap  antParams = new HashMap<>();
antParams.put("key","value").




Build application . The appSrcPath your application source directory is zipped up and copied to a WebLogic server pod for building . If your archives are placed under < application_source > / build after building use build as the archiveDistDir param value . This method copies the folder archiveDistDir to local file system and absolute path of the archiveDistDir directory is returned by this method . Example Usage : { @literal HashMap antParams = new HashMap< > () ; antParams . put ( " key " " value " ) .
public static Path buildApplication(Path appSrcPath, Map<String, String> antParams,
                                      String antTargets, String archiveDistDir, String namespace) {
    final LoggingFacade logger = getLogger();
    setImage(namespace);
    Path tempAppPath = Paths.get(WORK_DIR, "j2eeapplications", appSrcPath.getFileName().toString());
    Path destArchiveBaseDir = Paths.get(WORK_DIR, appSrcPath.getFileName().toString());
    Path destDir = null;
    assertDoesNotThrow(() -> {
      logger.info("Deleting and recreating {0}", tempAppPath);
      Files.createDirectories(tempAppPath);
      deleteDirectory(tempAppPath.toFile());
      Files.createDirectories(tempAppPath);
      Files.createDirectories(destArchiveBaseDir);
      deleteDirectory(destArchiveBaseDir.toFile());
      Files.createDirectories(destArchiveBaseDir);
      logger.info("Copying {0} to {1}", appSrcPath, tempAppPath);
      copyDirectory(appSrcPath.toFile(), tempAppPath.toFile());
    });
    Path zipFile = Paths.get(FileUtils.createZipFile(tempAppPath));
    V1Container buildContainer = new V1Container();
    buildContainer.addEnvItem(new V1EnvVar()
        .name("ZIP_FILE")
        .value(zipFile.getFileName().toString()));
    if (antParams != null) {
      StringBuilder params = new StringBuilder();
      antParams.entrySet().forEach((parameter) -> {
        params.append("-D").append(parameter.getKey()).append("=").append(parameter.getValue()).append(" ");
      });
      buildContainer = buildContainer
          .addEnvItem(new V1EnvVar().name("sysprops").value(params.toString()));
    }
    if (antTargets != null) {
      buildContainer = buildContainer
          .addEnvItem(new V1EnvVar().name("targets").value(antTargets));
    }
    V1Pod webLogicPod = setupWebLogicPod(namespace, buildContainer);
    try {
      Kubernetes.copyFileToPod(namespace, webLogicPod.getMetadata().getName(),
          null, zipFile, Paths.get("/u01", zipFile.getFileName().toString()));
    } catch (ApiException | IOException  ioex) {
      logger.info(ioex.getMessage());
    }
    try {
      Kubernetes.copyFileToPod(namespace, webLogicPod.getMetadata().getName(),
          null, BUILD_SCRIPT_SOURCE_PATH, Paths.get("/u01", BUILD_SCRIPT));
    } catch (ApiException | IOException  ioex) {
      logger.info(ioex.getMessage());
    }
    try {
      ExecResult exec = Exec.exec(webLogicPod, null, false, "/bin/sh", "/u01/" + BUILD_SCRIPT);
      assertEquals(0, exec.exitValue());
      if (exec.stdout() != null) {
        logger.info(exec.stdout());
      }
      if (exec.stderr() != null) {
        logger.info(exec.stderr());
      }
      Kubernetes.copyDirectoryFromPod(webLogicPod,
          Paths.get(APPLICATIONS_PATH, archiveDistDir).toString(), destArchiveBaseDir);
    } catch (ApiException | IOException | InterruptedException ioex) {
      logger.info(ioex.getMessage());
    }
    return destDir = Paths.get(destArchiveBaseDir.toString(), "u01/application", archiveDistDir);
  }
public static Path buildApplication ( Path appSrcPath , Map < String , String > antParams , String antTargets , String archiveDistDir , String namespace ) { final LoggingFacade logger = getLogger ( ) ; setImage ( namespace ) ; Path tempAppPath = Paths . get ( WORK_DIR , "j2eeapplications" , appSrcPath . getFileName ( ) . toString ( ) ) ; Path destArchiveBaseDir = Paths . get ( WORK_DIR , appSrcPath . getFileName ( ) . toString ( ) ) ; Path destDir = null ; assertDoesNotThrow ( ( ) -> { logger . info ( "Deleting and recreating {0}" , tempAppPath ) ; Files . createDirectories ( tempAppPath ) ; deleteDirectory ( tempAppPath . toFile ( ) ) ; Files . createDirectories ( tempAppPath ) ; Files . createDirectories ( destArchiveBaseDir ) ; deleteDirectory ( destArchiveBaseDir . toFile ( ) ) ; Files . createDirectories ( destArchiveBaseDir ) ; logger . info ( "Copying {0} to {1}" , appSrcPath , tempAppPath ) ; copyDirectory ( appSrcPath . toFile ( ) , tempAppPath . toFile ( ) ) ; } ) ; Path zipFile = Paths . get ( FileUtils . createZipFile ( tempAppPath ) ) ; V1Container buildContainer = new V1Container ( ) ; buildContainer . addEnvItem ( new V1EnvVar ( ) . name ( "ZIP_FILE" ) . value ( zipFile . getFileName ( ) . toString ( ) ) ) ; if ( antParams != null ) { StringBuilder params = new StringBuilder ( ) ; antParams . entrySet ( ) . forEach ( ( parameter ) -> { params . append ( "-D" ) . append ( parameter . getKey ( ) ) . append ( "=" ) . append ( parameter . getValue ( ) ) . append ( " " ) ; } ) ; buildContainer = buildContainer . addEnvItem ( new V1EnvVar ( ) . name ( "sysprops" ) . value ( params . toString ( ) ) ) ; } if ( antTargets != null ) { buildContainer = buildContainer . addEnvItem ( new V1EnvVar ( ) . name ( "targets" ) . value ( antTargets ) ) ; } V1Pod webLogicPod = setupWebLogicPod ( namespace , buildContainer ) ; try { Kubernetes . copyFileToPod ( namespace , webLogicPod . getMetadata ( ) . getName ( ) , null , zipFile , Paths . get ( "/u01" , zipFile . getFileName ( ) . toString ( ) ) ) ; } catch ( ApiException | IOException ioex ) { logger . info ( ioex . getMessage ( ) ) ; } try { Kubernetes . copyFileToPod ( namespace , webLogicPod . getMetadata ( ) . getName ( ) , null , BUILD_SCRIPT_SOURCE_PATH , Paths . get ( "/u01" , BUILD_SCRIPT ) ) ; } catch ( ApiException | IOException ioex ) { logger . info ( ioex . getMessage ( ) ) ; } try { ExecResult exec = Exec . exec ( webLogicPod , null , false , "/bin/sh" , "/u01/" + BUILD_SCRIPT ) ; assertEquals ( 0 , exec . exitValue ( ) ) ; if ( exec . stdout ( ) != null ) { logger . info ( exec . stdout ( ) ) ; } if ( exec . stderr ( ) != null ) { logger . info ( exec . stderr ( ) ) ; } Kubernetes . copyDirectoryFromPod ( webLogicPod , Paths . get ( APPLICATIONS_PATH , archiveDistDir ) . toString ( ) , destArchiveBaseDir ) ; } catch ( ApiException | IOException | InterruptedException ioex ) { logger . info ( ioex . getMessage ( ) ) ; } return destDir = Paths . get ( destArchiveBaseDir . toString ( ) , "u01/application" , archiveDistDir ) ; }
Build application.
Build application .
// Path of temp location for application source directory // directory to copy archives built // recreate WORK_DIR/j2eeapplications/<application_directory_name> // copy the application source to WORK_DIR/j2eeapplications/<application_directory_name> for zipping // zip up the application source to be copied to pod for building // add ant properties as env variable in pod // set ZIP_FILE location as env variable in pod // set ant parameteres as env variable in pod // set add targets in env variable "targets" //setup temporary WebLogic pod to build application //copy the zip file to /u01 location inside pod //copy the build script to /u01 location inside pod //Kubernetes.exec(webLogicPod, new String[]{"/bin/sh", "/u01/" + BUILD_SCRIPT});