Skip to content
Permalink
Browse files

Add job parameter to dynamically list available CVS symbolic names fo…

…r a module

[FIXED JENKINS-9311] Support CVS tags as job params
  • Loading branch information...
mc1arke committed Sep 10, 2012
1 parent b188365 commit 50165bf777a14f60be12f25d0a4928daa8269ea0
@@ -25,7 +25,9 @@

import hudson.scm.CVSChangeLogSet.CVSChangeLog;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Used to store a list of changes and a list of files parsed from the output of
@@ -37,12 +39,22 @@

private final List<CVSChangeLog> changes;
private final List<CvsFile> files;
private transient Set<String> tagNames = new HashSet<String>();
private transient Set<String> branchNames = new HashSet<String>();


public CvsChangeSet(final List<CvsFile> files,
final List<CVSChangeLog> changes) {
this.files = files;
this.changes = changes;
}

public CvsChangeSet(final List<CvsFile> files, final List<CVSChangeLog> changes, final Set<String> branchNames,
final Set<String> tagNames) {
this(files, changes);
this.branchNames = branchNames;
this.tagNames = tagNames;
}

public List<CVSChangeLog> getChanges() {
return changes;
@@ -51,42 +63,36 @@ public CvsChangeSet(final List<CvsFile> files,
public List<CvsFile> getFiles() {
return files;
}

public Set<String> getTagNames(){
return tagNames;
}

public Set<String> getBranchNames() {
return branchNames;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((changes == null) ? 0 : changes.hashCode());
result = prime * result + ((files == null) ? 0 : files.hashCode());
return result;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

CvsChangeSet that = (CvsChangeSet) o;

if (branchNames != null ? !branchNames.equals(that.branchNames) : that.branchNames != null) return false;
if (changes != null ? !changes.equals(that.changes) : that.changes != null) return false;
if (files != null ? !files.equals(that.files) : that.files != null) return false;
if (tagNames != null ? !tagNames.equals(that.tagNames) : that.tagNames != null) return false;

return true;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
CvsChangeSet other = (CvsChangeSet) obj;
if (changes == null) {
if (other.changes != null) {
return false;
}
} else if (!changes.equals(other.changes)) {
return false;
}
if (files == null) {
if (other.files != null) {
return false;
}
} else if (!files.equals(other.files)) {
return false;
}
return true;
public int hashCode() {
int result = changes != null ? changes.hashCode() : 0;
result = 31 * result + (files != null ? files.hashCode() : 0);
result = 31 * result + (tagNames != null ? tagNames.hashCode() : 0);
result = 31 * result + (branchNames != null ? branchNames.hashCode() : 0);
return result;
}
}
@@ -9,6 +9,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -52,6 +54,8 @@ public CvsChangeSet mapCvsLog(final String cvsRoot, final CvsRepositoryLocation
CVSChangeLogSet.File file = null;
CVSChangeLog change = null;
final Map<String,String> branches = new HashMap<String,String>();
final Set<String> tagNames = new TreeSet<String>();
final Set<String> branchNames = new TreeSet<String>();
final BufferedReader reader = new BufferedReader(read());
Status status = Status.FILE_NAME;
String line;
@@ -71,7 +75,7 @@ public CvsChangeSet mapCvsLog(final String cvsRoot, final CvsRepositoryLocation
//we don't break here because we now want to continue parsing 'line'.
//we should be safe having prePrevious line skipped since we know it contained ====
case FILE_BRANCH_NAMES:
status = parseBranchNames(line, status, branches);
status = parseBranchNames(line, status, branches, branchNames, tagNames);
break;

case FILE_VERSION:
@@ -105,7 +109,7 @@ public CvsChangeSet mapCvsLog(final String cvsRoot, final CvsRepositoryLocation
}
reader.close();
dispose();
return new CvsChangeSet(new ArrayList<CvsFile>(files.values()), changes);
return new CvsChangeSet(new ArrayList<CvsFile>(files.values()), changes, branchNames, tagNames);

}

@@ -147,9 +151,12 @@ private Status parseFileName(final String line, final CVSChangeLogSet.File file,
* @param line the current CVS Rlog line to parse
* @param currentStatus the current processing status
* @param branches the list of branch names to add the parsed branch to.
* @param branchNames the set of tags names parsed from any files in the module being parsed.
* @param tagNames the set of tags names parsed from any files in the module being parsed.
* @return the type to parse the next line as, either the currentStatus or FILE_VERSION
*/
private Status parseBranchNames(final String line, final Status currentStatus, final Map<String, String> branches) {
private Status parseBranchNames(final String line, final Status currentStatus, final Map<String, String> branches,
final Set<String> branchNames, final Set<String> tagNames) {

if (line.startsWith("keyword substitution:")) {
//we've passed the branch/tag list, move onto the next content type
@@ -169,18 +176,21 @@ else if (!line.startsWith("\t")) {
}

// get the name of the branch/tag from the current line
final String name = trimmedLine.substring(0, colonLocation);
final String name = trimmedLine.substring(0, colonLocation).trim();

// check the format of the associated file version. Branch versions are
// n.n.0.n, tags do not have the second last section as 0. Tags cannot have
// changelog entries so can safely be skipped
final Matcher versionMatcher = DOT_PATTERN.matcher(trimmedLine.substring(colonLocation + 2));

if(!versionMatcher.matches()) {
// doesn't match branch format (see above), so skip it
// doesn't match branch format (see above), so suspect it's a tag. Collect is and keep it for now
tagNames.add(name);
return currentStatus;
}

branchNames.add(name);

// add the branch to to the list, skipping the second last item in the group
// since it's 0 and isn't used in the changelog file versions
branches.put(versionMatcher.group(1) +versionMatcher.group(3) + '.', name);

0 comments on commit 50165bf

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