Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run bwdesignUtility task on Windows and Linux #477

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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{

Expand Down Expand Up @@ -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();
}
Expand All @@ -92,43 +89,41 @@ else if(null != commandName && commandName.equals("gen_diagrams"))
private void generateProcessDiagram() throws MojoExecutionException {
List<String> 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<String> createUtilityArgument(List<String> 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");
Expand All @@ -138,36 +133,81 @@ private List<String> createUtilityArgument(List<String> params) {


private void validateBWProject() throws MojoExecutionException{
Process validateProcess = null;
List<String> validateParam = new ArrayList<>();
validateParam = createUtilityArgument(validateParam);
List<String> 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<String> 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<String> projectList = new ArrayList<String>();
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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");
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -92,21 +89,26 @@ 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);
latch.countDown();
}

} catch(Exception e) {
e.printStackTrace();
BWTestConfig.INSTANCE.getLogger().error(e);
}
}
};
Expand Down