diff --git a/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/process/BWDesignUtilityExecutorMojo.java b/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/process/BWDesignUtilityExecutorMojo.java index 8a47184b..bbc72672 100644 --- a/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/process/BWDesignUtilityExecutorMojo.java +++ b/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/process/BWDesignUtilityExecutorMojo.java @@ -1,19 +1,6 @@ package com.tibco.bw.maven.plugin.process; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.lang.StringUtils; +import com.tibco.bw.maven.plugin.utils.BWProjectUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -23,6 +10,13 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + @Mojo(name = "bwdesignUtility") public class BWDesignUtilityExecutorMojo extends AbstractMojo{ @@ -70,16 +64,19 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoFailureException("Value for BW Home is empty"); } - binDir = tibcoHome.concat(bwHome).concat("//bin"); + binDir = tibcoHome.concat(bwHome).concat(File.separator).concat("bin"); executorHome = binDir; if(null != commandName && commandName.equals("validate")){ + importWorkspace(); validateBWProject(); } else if(null != commandName && commandName.equals("gen_diagrams")) { + importWorkspace(); generateProcessDiagram(); } else { + importWorkspace(); validateBWProject(); generateProcessDiagram(); } @@ -92,43 +89,41 @@ else if(null != commandName && commandName.equals("gen_diagrams")) private void generateProcessDiagram() throws MojoExecutionException { List params = new ArrayList<>(); params = createUtilityArgument(params); + params.add("diagram:gen_diagrams"); + params.add(project.getName()); + if(null != diagramLoc && !diagramLoc.isEmpty()){ + params.add(diagramLoc); + } + try { ProcessBuilder builder = new ProcessBuilder( params); - builder.directory( new File( executorHome ) ); - final Process process = builder.start(); + builder.directory( new File( executorHome ) ); + // redirect error stream to /dev/null + if(BWProjectUtils.OS.WINDOWS.equals(BWProjectUtils.getOS())) { + builder.redirectError(new File("NUL")); + } else { + builder.redirectError(new File("/dev/null")); + } + final Process process = builder.start(); logger.info("---------------------Generating Process diagram-----------------------"); - - BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(process.getOutputStream())); - if(null != diagramLoc && !diagramLoc.isEmpty()){ - writer.write("diagram:gen_diagrams "+project.getName()+" "+diagramLoc); - } - else{ - writer.write("diagram:gen_diagrams "+project.getName()); - } - writer.close(); - - BufferedReader reader = new BufferedReader(new InputStreamReader( - process.getInputStream())); - String line; - while ((line = reader.readLine()) != null) { - System.out.println(line); - } - reader.close(); - + logger.debug("Launching bwdesign utility with params: " + params); + + printProcessOutput(process); + } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException( e.getMessage(), e); } - - } private List createUtilityArgument(List params) { - String utilityName = executorHome.concat("//bwdesign.exe"); + String utilityName = executorHome.concat(File.separator).concat("bwdesign.exe"); + if(BWProjectUtils.OS.UNIX.equals(BWProjectUtils.getOS())) { + utilityName = executorHome.concat(File.separator).concat("bwdesign"); + } String workSpaceLocation = project.getBasedir().getParent(); params.add(utilityName); params.add("-data"); @@ -138,36 +133,81 @@ private List createUtilityArgument(List params) { private void validateBWProject() throws MojoExecutionException{ - Process validateProcess = null; - List validateParam = new ArrayList<>(); - validateParam = createUtilityArgument(validateParam); + List params = new ArrayList<>(); + params = createUtilityArgument(params); + params.add("validate"); + params.add(projectList()); + try { - ProcessBuilder validateBuilder = new ProcessBuilder( validateParam); - validateBuilder.directory( new File( executorHome ) ); + ProcessBuilder builder = new ProcessBuilder( params); + builder.directory( new File( executorHome ) ); + // redirect error stream to /dev/null + if(BWProjectUtils.OS.WINDOWS.equals(BWProjectUtils.getOS())) { + builder.redirectError(new File("NUL")); + } else { + builder.redirectError(new File("/dev/null")); + } logger.info("---------------------Validating BW Project-----------------------"); - validateProcess = validateBuilder.start(); - String applicationName = project.getName(); - String moduleName = applicationName.replace(".application", ""); - - BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(validateProcess.getOutputStream())); - writer.write("validate "+moduleName+","+applicationName); - writer.close(); - - BufferedReader reader = new BufferedReader(new InputStreamReader( - validateProcess.getInputStream())); - String line; - while ((line = reader.readLine()) != null) { - System.out.println(line); - } + logger.debug("Launching bwdesign utility with params: " + params); + final Process process = builder.start(); + + printProcessOutput(process); } catch (IOException e) { e.printStackTrace(); throw new MojoExecutionException( e.getMessage(), e); } - - - } - + + /* + Should run import task before validate and diagram:gen_diagrams if you don't run mvn into existing eclipse workspace + */ + private void importWorkspace() throws MojoExecutionException { + List params = new ArrayList<>(); + params = createUtilityArgument(params); + params.add("import"); + params.add(project.getBasedir().getParent()); + + try { + ProcessBuilder builder = new ProcessBuilder( params); + builder.directory( new File( executorHome ) ); + // redirect error stream to /dev/null + if(BWProjectUtils.OS.WINDOWS.equals(BWProjectUtils.getOS())) { + builder.redirectError(new File("NUL")); + } else { + builder.redirectError(new File("/dev/null")); + } + final Process process = builder.start(); + logger.info("-----------------Import Projects to Workspaces-------------------"); + logger.debug("Launching bwdesign utility with params: " + params); + + printProcessOutput(process); + + } catch (Exception e) { + e.printStackTrace(); + throw new MojoExecutionException( e.getMessage(), e); + } + + + } + + private String projectList() { + List projectList = new ArrayList(); + for (MavenProject mvnProject: session.getProjects()) { + projectList.add(mvnProject.getName()); + } + return String.join(",", projectList); + } + + private void printProcessOutput(Process process) throws IOException { + BufferedReader reader= null; + String line = null; + + reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + while ((line = reader.readLine()) != null) { + System.err.println(line); + } + + reader.close(); + } } diff --git a/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/test/setuplocal/EngineRunner.java b/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/test/setuplocal/EngineRunner.java index c4aabab6..5191dd3b 100644 --- a/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/test/setuplocal/EngineRunner.java +++ b/Source/bw6-maven-plugin/src/main/java/com/tibco/bw/maven/plugin/test/setuplocal/EngineRunner.java @@ -27,10 +27,8 @@ public void run() throws Exception BWTestConfig.INSTANCE.getLogger().info( "" ); BWTestConfig.INSTANCE.setEngineProcess(process); - final StringBuilder sb = new StringBuilder(); - - Runnable input = getInputRunnable(process, sb); - Runnable error = getErrorRunnable(process, sb); + Runnable input = getInputRunnable(process); + Runnable error = getErrorRunnable(process); Thread inputThread = new Thread( input ); Thread errorThread = new Thread( error ); @@ -39,7 +37,7 @@ public void run() throws Exception TimerTask task = new TimerTask() { public void run() { - System.out.print( "." ); + //BWTestConfig.INSTANCE.getLogger().info( "." ); } }; Timer timer = new Timer("Timer"); @@ -62,7 +60,7 @@ public void run() { - private Runnable getErrorRunnable(final Process process, final StringBuilder sb) { + private Runnable getErrorRunnable(final Process process) { Runnable error = new Runnable() { public void run() { try { @@ -72,18 +70,17 @@ public void run() { String line; while((line = br.readLine()) != null) { - //System.out.println( line); - sb.append( line ); + BWTestConfig.INSTANCE.getLogger().error(line); } } catch(Exception e) { - //logger.error ( e.getMessage() , e); + BWTestConfig.INSTANCE.getLogger().error(e); } } }; return error; } - private Runnable getInputRunnable(final Process process, final StringBuilder sb){ + private Runnable getInputRunnable(final Process process){ Runnable input = new Runnable() { public void run() { try { @@ -92,13 +89,18 @@ public void run() { BufferedReader br = new BufferedReader(isr); String line; while((line = br.readLine()) != null) { - System.out.println(line); - if( line.contains( "Started BW Application") ) + BWTestConfig.INSTANCE.getLogger().info(line); + //TIBCO-THOR-FRWK-300006: Started BW Application + if( line.contains( "TIBCO-THOR-FRWK-300006") ) + { + latch.countDown(); + } + //TIBCO-THOR-FRWK-300019: BW Application is impaired + if( line.contains( "TIBCO-THOR-FRWK-300019") ) { + isEngineStarted.set(false); latch.countDown(); } - - sb.append( line ); } if(latch.getCount()>0){ isEngineStarted.set(false); @@ -106,7 +108,7 @@ public void run() { } } catch(Exception e) { - e.printStackTrace(); + BWTestConfig.INSTANCE.getLogger().error(e); } } };