Skip to content

Commit 92e8c1d

Browse files
committed
Merge branch 'master' into multiple-scm-instatination-fix
Conflicts: src/main/java/hudson/plugins/perforce/PerforceSCM.java Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
2 parents 0235070 + 02d2fcf commit 92e8c1d

File tree

14 files changed

+323
-138
lines changed

14 files changed

+323
-138
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<artifactId>perforce</artifactId>
1212
<name>Perforce Plugin</name>
1313
<packaging>hpi</packaging>
14-
<version>1.3.25-SNAPSHOT</version>
14+
<version>1.3.27-SNAPSHOT</version>
1515
<url>http://wiki.jenkins-ci.org/display/JENKINS/Perforce+Plugin</url>
1616

1717
<developers>

src/main/java/com/tek42/perforce/parse/AbstractPerforceTemplate.java

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
import com.tek42.perforce.PerforceException;
4545
import com.tek42.perforce.process.Executor;
4646
import hudson.plugins.perforce.PerforceSCM;
47+
import hudson.plugins.perforce.utils.TimedStreamCloser;
4748
import java.io.InputStream;
49+
import java.util.concurrent.TimeoutException;
50+
import java.util.logging.Level;
4851
import org.slf4j.LoggerFactory;
4952
import org.apache.commons.lang.time.StopWatch;
5053

@@ -330,61 +333,31 @@ protected StringBuilder getPerforceResponse(String origcmd[], ResponseFilter fil
330333
String line = null;
331334
totalLength = 0;
332335
lines = new ArrayList<String>(1024);
333-
336+
TimedStreamCloser timedStreamCloser=null;
334337
try
335338
{
336339
PerforceSCM.PerforceSCMDescriptor scmDescr = PerforceSCM.getInstance();
337-
340+
p4.getWriter().close();
341+
int timeout = -1;
338342
if(scmDescr.hasP4ReadlineTimeout()) { // Implementation with timeout
339-
StopWatch stopWatch = new StopWatch();
340-
int timeout = scmDescr.getP4ReadLineTimeout() * 1000;
341-
stopWatch.start();
342-
343-
try {
344-
while (reader.ready() || p4.isAlive()) {
345-
if (reader.ready()) {
346-
stopWatch.reset();
347-
stopWatch.start();
348-
line = reader.readLine();
349-
if (line == null) {
350-
break;
351-
}
352-
353-
//FIXME: Remove code duplication
354-
// only check for errors if we have not found one already
355-
if (mesgIndex == -1)
356-
mesgIndex = checkAuthnErrors(line);
357-
if(filter.reject(line)) continue;
358-
lines.add(line);
359-
totalLength += line.length();
360-
count++;
361-
}
362-
else {
363-
if (stopWatch.getTime() > timeout) {
364-
throw new PerforceException("Timeout. Haven't received new line from external executor after "
365-
+scmDescr.getP4ReadLineTimeout()+" seconds. ");
366-
}
367-
368-
// Sleep for check period
369-
Thread.sleep(P4_EXECUTOR_CHECK_PERIOD);
370-
}
371-
}
372-
} catch(InterruptedException ex) {
373-
throw new PerforceException("Interrupted", ex);
374-
}
375-
376-
} else { // legacy behavior
377-
p4.getWriter().close();
378-
while((line = reader.readLine()) != null) {
379-
// only check for errors if we have not found one already
380-
if (mesgIndex == -1)
381-
mesgIndex = checkAuthnErrors(line);
382-
if(filter.reject(line)) continue;
383-
lines.add(line);
384-
totalLength += line.length();
385-
count++;
386-
}
387-
}
343+
timeout = scmDescr.getP4ReadLineTimeout();
344+
}
345+
timedStreamCloser = new TimedStreamCloser(p4.getInputStream(), timeout);
346+
timedStreamCloser.start();
347+
348+
while((line = reader.readLine()) != null) {
349+
timedStreamCloser.reset();
350+
// only check for errors if we have not found one already
351+
if (mesgIndex == -1)
352+
mesgIndex = checkAuthnErrors(line);
353+
if(filter.reject(line)) continue;
354+
lines.add(line);
355+
totalLength += line.length();
356+
count++;
357+
}
358+
if(timedStreamCloser.timedOut()) {
359+
throw new PerforceException("Perforce operation timed out after " + timeout + " seconds.");
360+
}
388361
}
389362
catch(IOException ioe)
390363
{
@@ -399,6 +372,7 @@ protected StringBuilder getPerforceResponse(String origcmd[], ResponseFilter fil
399372
getLogger().warn(sw.toString());
400373
}
401374
finally{
375+
if(timedStreamCloser!=null) timedStreamCloser.interrupt();
402376
try{
403377
p4.getWriter().close();
404378
} catch (IOException e) {

src/main/java/com/tek42/perforce/process/CmdLineExecutor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class CmdLineExecutor implements Executor {
4848
List<String> args;
4949
BufferedWriter writer;
5050
BufferedReader reader;
51+
InputStream input;
52+
OutputStream output;
5153
private final Logger logger = LoggerFactory.getLogger("perforce");
5254

5355
/**
@@ -83,6 +85,8 @@ public void exec(String[] args) throws PerforceException {
8385
builder.redirectErrorStream(true);
8486
try {
8587
currentProcess = builder.start();
88+
input = currentProcess.getInputStream();
89+
output = currentProcess.getOutputStream();
8690
reader = new BufferedReader(new InputStreamReader(currentProcess.getInputStream()));
8791
writer = new BufferedWriter(new OutputStreamWriter(currentProcess.getOutputStream()));
8892

@@ -157,11 +161,11 @@ public boolean isAlive() {
157161
}
158162

159163
public OutputStream getOutputStream() {
160-
throw new UnsupportedOperationException("Not supported yet.");
164+
return output;
161165
}
162166

163167
public InputStream getInputStream() {
164-
throw new UnsupportedOperationException("Not supported yet.");
168+
return input;
165169
}
166170

167171
}

src/main/java/hudson/plugins/perforce/HudsonP4DefaultExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ public BufferedWriter getWriter() {
119119
}
120120
return writer;
121121
}
122-
122+
123123
public BufferedReader getReader() {
124124
if(reader==null){
125125
reader = new BufferedReader(new InputStreamReader(input));
126126
}
127127
return reader;
128128
}
129-
129+
130130
private void closeBuffers(){
131131
try {
132132
input.close();

src/main/java/hudson/plugins/perforce/PerforceChangeLogSet.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Collections;
1414
import java.util.Iterator;
1515
import java.util.List;
16+
import org.apache.commons.lang.StringEscapeUtils;
1617
import org.kohsuke.stapler.framework.io.WriterOutputStream;
1718

1819
/**
@@ -69,27 +70,27 @@ public static void saveToChangeLog(OutputStream outputStream, List<Changelist> c
6970
for (Changelist change : changes) {
7071
stream.println("\t<entry>");
7172
stream.println("\t\t<changenumber>" + change.getChangeNumber() + "</changenumber>");
72-
stream.println("\t\t<date>" + Util.xmlEscape(PerforceChangeLogParser.javaDateToStringDate(change.getDate())) + "</date>");
73-
stream.println("\t\t<description>" + Util.xmlEscape(change.getDescription()) + "</description>");
74-
stream.println("\t\t<user>" + Util.xmlEscape(change.getUser()) + "</user>");
75-
stream.println("\t\t<workspace>" + Util.xmlEscape(change.getWorkspace()) + "</workspace>");
73+
stream.println("\t\t<date>" + StringEscapeUtils.escapeXml(PerforceChangeLogParser.javaDateToStringDate(change.getDate())) + "</date>");
74+
stream.println("\t\t<description>" + StringEscapeUtils.escapeXml(change.getDescription()) + "</description>");
75+
stream.println("\t\t<user>" + StringEscapeUtils.escapeXml(change.getUser()) + "</user>");
76+
stream.println("\t\t<workspace>" + StringEscapeUtils.escapeXml(change.getWorkspace()) + "</workspace>");
7677
stream.println("\t\t<files>");
7778
for (Changelist.FileEntry entry : change.getFiles()) {
7879
stream.println("\t\t\t<file>");
79-
stream.println("\t\t\t\t<name>" + Util.xmlEscape(entry.getFilename()) + "</name>");
80-
stream.println("\t\t\t\t<workspacePath>" + Util.xmlEscape(entry.getWorkspacePath()) + "</workspacePath>");
81-
stream.println("\t\t\t\t<rev>" + Util.xmlEscape(entry.getRevision()) + "</rev>");
82-
stream.println("\t\t\t\t<changenumber>" + Util.xmlEscape(entry.getChangenumber()) + "</changenumber>");
80+
stream.println("\t\t\t\t<name>" + StringEscapeUtils.escapeXml(entry.getFilename()) + "</name>");
81+
stream.println("\t\t\t\t<workspacePath>" + StringEscapeUtils.escapeXml(entry.getWorkspacePath()) + "</workspacePath>");
82+
stream.println("\t\t\t\t<rev>" + StringEscapeUtils.escapeXml(entry.getRevision()) + "</rev>");
83+
stream.println("\t\t\t\t<changenumber>" + StringEscapeUtils.escapeXml(entry.getChangenumber()) + "</changenumber>");
8384
stream.println("\t\t\t\t<action>" + entry.getAction() + "</action>");
8485
stream.println("\t\t\t</file>");
8586
}
8687
stream.println("\t\t</files>");
8788
stream.println("\t\t<jobs>");
8889
for (Changelist.JobEntry entry : change.getJobs()) {
8990
stream.println("\t\t\t<job>");
90-
stream.println("\t\t\t\t<name>" + Util.xmlEscape(entry.getJob()) + "</name>");
91-
stream.println("\t\t\t\t<description>" + Util.xmlEscape(entry.getDescription()) + "</description>");
92-
stream.println("\t\t\t\t<status>" + Util.xmlEscape(entry.getStatus()) + "</status>");
91+
stream.println("\t\t\t\t<name>" + StringEscapeUtils.escapeXml(entry.getJob()) + "</name>");
92+
stream.println("\t\t\t\t<description>" + StringEscapeUtils.escapeXml(entry.getDescription()) + "</description>");
93+
stream.println("\t\t\t\t<status>" + StringEscapeUtils.escapeXml(entry.getStatus()) + "</status>");
9394
stream.println("\t\t\t</job>");
9495
}
9596
stream.println("\t\t</jobs>");

0 commit comments

Comments
 (0)