Skip to content

Commit

Permalink
[JENKINS-41165] Fix for Ignore Parent (#39)
Browse files Browse the repository at this point in the history
Fixing Ignore Parent
  • Loading branch information
Casz committed Jan 19, 2017
1 parent 4291e73 commit 0efd396
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
Expand Up @@ -178,7 +178,13 @@ public boolean checkForChanges(String promoteDepot, String promoteStream, int pr
}
} else if (promoteDepot.equals(getDepot()) && !scm.isIgnoreStreamParent()) {

String localStream = scm.getPollingStream(job, listener);
String localStream;
try {
localStream = scm.getPollingStream(job, listener);
} catch (IllegalArgumentException ex) {
listener.getLogger().println(ex.getMessage());
return false;
}

if (streams == null) {
listener.fatalError("streams EMPTY");
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/hudson/plugins/accurev/AccurevSCM.java
Expand Up @@ -469,15 +469,22 @@ public boolean hasStringVariableReference(final String str) {
return StringUtils.isNotEmpty(str) && str.startsWith("$");
}

public String getPollingStream(Job<?, ?> project, TaskListener listener) {
/**
*
* @param project Running build
* @param listener Listener that it runs the build on
* @return Stream name tries to expand Variable reference to a String
* @throws IllegalArgumentException Thrown when Variable reference is not supported or cannot expand
*/
public String getPollingStream(Job<?, ?> project, TaskListener listener) throws IllegalArgumentException {
String parsedLocalStream;
if (hasStringVariableReference(getStream())) {
if (hasStringVariableReference(stream)) {
ParametersDefinitionProperty paramDefProp = project
.getProperty(ParametersDefinitionProperty.class);

if (paramDefProp == null) {
throw new IllegalArgumentException(
"Polling is not supported when stream name has a variable reference '" + getStream() + "'.");
"Polling is not supported when stream name has a variable reference '" + stream + "'.");
}

Map<String, String> keyValues = new TreeMap<>();
Expand All @@ -495,14 +502,14 @@ public String getPollingStream(Job<?, ?> project, TaskListener listener) {

final EnvVars environment = new EnvVars(keyValues);
parsedLocalStream = environment.expand(getStream());
listener.getLogger().println("... expanded '" + getStream() + "' to '" + parsedLocalStream + "'.");
listener.getLogger().println("... expanded '" + stream + "' to '" + parsedLocalStream + "'.");
} else {
parsedLocalStream = getStream();
parsedLocalStream = stream;
}

if (hasStringVariableReference(parsedLocalStream)) {
throw new IllegalArgumentException(
"Polling is not supported when stream name has a variable reference '" + getStream() + "'.");
"Failed to expand variable reference '" + stream + "'.");
}
return parsedLocalStream;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/hudson/plugins/accurev/CheckForChanges.java
Expand Up @@ -9,7 +9,6 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hudson/plugins/accurev/cmd/ShowStreams.java
Expand Up @@ -16,6 +16,7 @@
import org.apache.commons.lang.StringUtils;
import org.xmlpull.v1.XmlPullParserFactory;

import javax.annotation.CheckForNull;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -28,6 +29,7 @@
public class ShowStreams extends Command {
private static final Logger logger = Logger.getLogger(ShowStreams.class.getName());

@CheckForNull
public static Map<String, AccurevStream> getStreams(//
final AccurevSCM scm, //
final String nameOfStreamRequired, //
Expand Down
Expand Up @@ -184,9 +184,16 @@ private boolean captureChangeLog(Run<?, ?> build, File changelogFile, Map<String
localStream, changelogFile, logger, scm, webURL);
}

return getChangesFromStreams(startTime, stream, changelogFile, webURL) ||
ChangeLogCmd.captureChangelog(server, accurevEnv, accurevWorkingSpace, listener, launcher,
startDateOfPopulate, startTime.getTime(), localStream, changelogFile, logger, scm, webURL);
// Too confusing reading it
// This check is for whether to catch changes for one or multiple streams
// ALso if it should ignore changes on Parent
// Doing too much in too few lines to make it apparant
// High potential for simple rewrite!
if (!getChangesFromStreams(startTime, stream, changelogFile, webURL)) {
return ChangeLogCmd.captureChangelog(server, accurevEnv, accurevWorkingSpace, listener, launcher, startDateOfPopulate,
startTime.getTime(), localStream, changelogFile, logger, scm, webURL);
}
return true;
}

protected String getChangeLogStream() {
Expand Down
Expand Up @@ -68,12 +68,16 @@ protected PollingResult checkForChanges(Job<?, ?> project) throws IOException, I
listener.getLogger().println(ex.getMessage());
return PollingResult.NO_CHANGES;
}
final Map<String, AccurevStream> streams = scm.isIgnoreStreamParent() ? null : ShowStreams.getStreams(scm, localStream, server,
final Map<String, AccurevStream> streams = ShowStreams.getStreams(scm, localStream, server,
accurevEnv, jenkinsWorkspace, listener, launcher);
AccurevStream stream = streams == null ? null : streams.get(localStream);
if (streams == null) {
listener.getLogger().println("Could not retrieve any Streams from Accurev, please check credentials");
return PollingResult.NO_CHANGES;
}
AccurevStream stream = streams.get(localStream);

if (stream == null) {
listener.getLogger().println("Stream not found or Accurev login failed.");
listener.getLogger().println("Tried to find '" + localStream + "' Stream, could not found it.");
return PollingResult.NO_CHANGES;
}
// There may be changes in a parent stream that we need to factor in.
Expand All @@ -83,7 +87,7 @@ protected PollingResult checkForChanges(Job<?, ?> project) throws IOException, I
return PollingResult.BUILD_NOW;
}
stream = stream.getParent();
} while (stream != null && stream.isReceivingChangesFromParent());
} while (stream != null && stream.isReceivingChangesFromParent() && !scm.isIgnoreStreamParent());
return PollingResult.NO_CHANGES;

}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public String getRefTree() {
}

@Override
protected PollingResult checkForChanges(Job<?, ?> project) throws IOException, InterruptedException {
protected PollingResult checkForChanges(Job<?, ?> project) throws IOException, InterruptedException, IllegalArgumentException {
localStream = scm.getPollingStream(project, listener);
return super.checkForChanges(project);
}
Expand Down Expand Up @@ -71,6 +71,9 @@ protected Relocation checkForRelocation() throws IOException, InterruptedExcepti
} else {
Map<String, AccurevStream> workspaceBasis = ShowStreams.getStreams(scm, workspaceBasisStream, server, accurevEnv, jenkinsWorkspace, listener,
launcher);
if (workspaceBasis == null) {
throw new IllegalArgumentException("Could not determine the workspace basis stream");
}
workspaceStream.setParent(workspaceBasis.get(workspaceBasisStream));
}
} else {
Expand Down

0 comments on commit 0efd396

Please sign in to comment.