Skip to content
Permalink
Browse files

[JENKINS-18368] Trying to work around core bug by correcting the Unix…

… flag on the launcher when running polling.
  • Loading branch information...
jglick committed Jul 30, 2013
1 parent 962ba85 commit 549b3287db17d06f27d057c1f3681b1a98347ffa
@@ -27,6 +27,7 @@
import hudson.AbortException;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Proc;
import hudson.Util;
import hudson.model.BuildListener;
import hudson.model.TaskListener;
@@ -51,6 +52,8 @@
import hudson.plugins.clearcase.viewstorage.SpecificViewStorage;
import hudson.plugins.clearcase.viewstorage.ViewStorage;
import hudson.plugins.clearcase.viewstorage.ViewStorageFactory;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.scm.ChangeLogSet;
import hudson.scm.PollingResult;
import hudson.scm.PollingResult.Change;
@@ -63,6 +66,7 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.text.DecimalFormat;
import java.text.ParseException;
@@ -88,6 +92,9 @@
* have to implement the specific checkout and polling logic.
*/
public abstract class AbstractClearCaseScm extends SCM {

private static final Logger LOG = Logger.getLogger(AbstractClearCaseScm.class.getName());

public static abstract class AbstractClearCaseScmDescriptor<T extends AbstractClearCaseScm> extends SCMDescriptor<T> {

public AbstractClearCaseScmDescriptor(Class<? extends RepositoryBrowser> repositoryBrowser) {
@@ -699,8 +706,34 @@ private boolean saveChangeLog(AbstractBuild build, Launcher launcher, BuildListe
protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, Launcher launcher, FilePath workspace, TaskListener listener,
SCMRevisionState baseline) throws IOException, InterruptedException {
PrintStream logger = listener.getLogger();
logger.println("compareRemoteRevisionWith"); // TODO
Logger.getLogger(AbstractClearCaseScm.class.getName()).info("compareRemoteRevisionWith"); // TODO
boolean isUnix = workspace.act(new IsUnix());
boolean launcherIsUnix = launcher.isUnix();
LOG.log(Level.FINE, "original launcher.unix={0} vs. actual workspace.unix={1}", new Object[] {launcherIsUnix, isUnix});
if (launcherIsUnix != isUnix) {
class FixUnixLauncher extends Launcher {
final boolean isUnix;
final Launcher original;
FixUnixLauncher(boolean isUnix, Launcher original) {
super(original);
this.isUnix = isUnix;
this.original = original;
}
@Override public Proc launch(ProcStarter starter) throws IOException {
return original.launch(starter);
}
@Override public Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars) throws IOException, InterruptedException {
return original.launchChannel(cmd, out, workDir, envVars);
}
@Override public void kill(Map<String, String> modelEnvVars) throws IOException, InterruptedException {
original.kill(modelEnvVars);
}
@Override public boolean isUnix() {
return isUnix;
}
}
listener.getLogger().println("JENKINS-18368 workaround activated");
launcher = new FixUnixLauncher(isUnix, launcher);
}

// check if build is running
if (project.isBuilding() && !project.isConcurrentBuild()) {
@@ -741,7 +774,7 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
// path names to check (= load rules)
// first get load rules from last baseline (polling)
String[] pathNames = ccBaseline.getLoadRules();
logger.println("compareRemoteRevisionWith: loadRules=" + (pathNames == null ? null : Arrays.asList(pathNames)));
LOG.log(Level.FINE, "loadRules={0}", (pathNames == null ? null : Arrays.asList(pathNames)));
//logger.println("load rules from last baseline: " + pathNames.toString());
// if load rules are atomatically extracted or other rules are used or load rules from last baseline are empty -> use from load rules field or from other rules
if (extractLoadRules || useOtherLoadRulesForPolling || pathNames == null || pathNames.length == 0) {
@@ -764,6 +797,15 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
return new PollingResult(baseline, calcRevisionsFromPoll(build, launcher, listener), change);
}

// taken from FilePath
private static final class IsUnix implements Callable<Boolean,IOException> {
private static final long serialVersionUID = 1L;
IsUnix() {}
public Boolean call() throws IOException {
return File.pathSeparatorChar == ':';
}
}

private boolean isViewInvalid(AbstractBuild<?,?> build, VariableResolver<String> variableResolver, ClearToolLauncher clearToolLauncher, FilePath workspace, String viewTag) throws IOException, InterruptedException {
CheckoutAction checkoutAction = createCheckOutAction(variableResolver, clearToolLauncher, build);
return !checkoutAction.isViewValid(workspace, viewTag);
@@ -833,7 +875,7 @@ public boolean processWorkspaceBeforeDeletion(AbstractProject<?, ?> project, Fil
BuildVariableResolver buildVariableResolver = new BuildVariableResolver(latestBuildOnNode);
ct.rmviewtag(generateNormalizedViewName(buildVariableResolver));
} catch (Exception e) {
Logger.getLogger(AbstractClearCaseScm.class.getName()).log(Level.WARNING, "Failed to remove ClearCase view", e);
LOG.log(Level.WARNING, "Failed to remove ClearCase view", e);
}
return true;

@@ -957,7 +999,7 @@ protected void setExtendedViewPath(VariableResolver<String> variableResolver, Cl
action.setExtendedViewPath(pwv);
}
} catch (Exception e) {
Logger.getLogger(AbstractClearCaseScm.class.getName()).log(Level.WARNING, "Exception when running 'cleartool pwv'", e);
LOG.log(Level.WARNING, "Exception when running 'cleartool pwv'", e);
}
}
}
@@ -53,6 +53,7 @@
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -424,14 +425,11 @@ public Reader lshistory(String format, Date lastBuildDate, String viewPath, Stri
try {
launcher.run(cmd.toCommandArray(), null, baos, filePath, true);
} catch (IOException e) {
if (launcher.getListener() != null) {
e.printStackTrace(launcher.getListener().getLogger()); // TODO
}
LOGGER.log(Level.FINE, null, e);
// We don't care if Clearcase returns an error code, we will process it afterwards
}
if (launcher.getListener() != null) {
launcher.getListener().getLogger().println(cmd.toStringWithQuote()); // TODO
launcher.getListener().getLogger().println(baos); // TODO
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "cmd={0} output={1}", new Object[] {cmd.toStringWithQuote(), baos});
}
returnReader = new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
baos.close();
@@ -42,6 +42,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;

@@ -54,6 +55,8 @@
*/
public abstract class AbstractHistoryAction implements HistoryAction {

private static final Logger LOG = Logger.getLogger(AbstractHistoryAction.class.getName());

protected ClearTool cleartool;
private Filter filter;
protected String extendedViewPath;
@@ -75,17 +78,13 @@ public AbstractHistoryAction(ClearTool cleartool, boolean isDynamicView, Filter

protected List<HistoryEntry> filterEntries(List<HistoryEntry> entries) throws IOException, InterruptedException {
if (filter == null) {
if (cleartool.getLauncher() != null) {
cleartool.getLauncher().getListener().getLogger().println("filterEntries: no filter");
}
LOG.fine("no filter");
return entries;
}
List<HistoryEntry> filtered = new ArrayList<HistoryEntry>();
for (HistoryEntry entry : entries) {
boolean accepted = filter.accept(entry);
if (cleartool.getLauncher() != null) {
cleartool.getLauncher().getListener().getLogger().println("filterEntries: filter=" + filter + " entry=" + entry + " accepted=" + accepted);
}
LOG.log(Level.FINE, "filter={0} entry={1} accepted={2}", new Object[] {filter, entry, accepted});
if (accepted) {
filtered.add(entry);
}
@@ -131,9 +130,7 @@ public boolean hasChanges(Date time, String viewPath, String viewTag, String[] b
String[] viewPaths) throws IOException, InterruptedException {
List<HistoryEntry> historyEntries = runLsHistory(time, viewPath, viewTag, branchNames, viewPaths);
List<HistoryEntry> filtered = filterEntries(historyEntries);
if (cleartool.getLauncher() != null) {
cleartool.getLauncher().getListener().getLogger().println("runAndFilterLsHistory: @" + time + " historyEntries=" + historyEntries + " -> " + filtered);
}
LOG.log(Level.FINE, "@{0} historyEntries={1} -> {2}", new Object[] {time, historyEntries, filtered});
return filtered;
}

@@ -188,7 +185,7 @@ private void tryToAttachLineToPreviousEntry(HistoryEntry previousEntry, String l
if (previousEntry != null) {
previousEntry.appendComment(line).appendComment("\n");
} else {
Logger.getLogger(AbstractHistoryAction.class.getName()).warning(
LOG.warning(
"Got the comment : \"" + line + "\" but couldn't attach it to any entry");
}
}

0 comments on commit 549b328

Please sign in to comment.
You can’t perform that action at this time.