提交 f6ce0b4d 编写于 作者: K kohsuke

added code to display changelogs in module builds.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2023 71c3de6d-444a-0410-be80-ed276b4c234a
上级 32e35723
package hudson.maven;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
/**
* {@link ChangeLogSet} implementation used for {@link MavenBuild}.
*
* @author Kohsuke Kawaguchi
*/
public class FilteredChangeLogSet extends ChangeLogSet<Entry> {
private final List<Entry> master = new ArrayList<Entry>();
public final ChangeLogSet<? extends Entry> core;
/*package*/ FilteredChangeLogSet(MavenBuild build) {
super(build);
MavenModule mod = build.getParent();
// modules that are under 'mod'. lazily computed
List<MavenModule> subsidiaries = null;
MavenModuleSetBuild parentBuild = build.getParentBuild();
if(parentBuild==null) {
core = ChangeLogSet.createEmpty(build);
return;
}
core = parentBuild.getChangeSet();
for (Entry e : core) {
boolean belongs = false;
for (String path : e.getAffectedPaths()) {
if(path.startsWith(mod.getRelativePath())) {
belongs = true;
break;
}
}
if(belongs) {
// make sure at least one change belongs to this module proper,
// and not its subsidiary module
if(subsidiaries==null) {
subsidiaries = new ArrayList<MavenModule>();
for (MavenModule mm : mod.getParent().getModules()) {
if(mm!=mod && mm.getRelativePath().startsWith(mod.getRelativePath()))
subsidiaries.add(mm);
}
}
belongs = false;
for (String path : e.getAffectedPaths()) {
if(!belongsToSubsidiary(subsidiaries, path)) {
belongs = true;
break;
}
}
if(belongs)
master.add(e);
}
}
}
private boolean belongsToSubsidiary(List<MavenModule> subsidiaries, String path) {
for (MavenModule sub : subsidiaries)
if(path.startsWith(sub.getRelativePath()))
return true;
return false;
}
public Iterator<Entry> iterator() {
return master.iterator();
}
public boolean isEmptySet() {
return master.isEmpty();
}
}
......@@ -7,12 +7,13 @@ import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.DependencyGraph;
import hudson.model.Fingerprint.RangeSet;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.model.Run;
import hudson.remoting.Channel;
import hudson.remoting.VirtualChannel;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.util.IOException2;
import org.apache.maven.BuildFailureException;
import org.apache.maven.embedder.MavenEmbedderException;
......@@ -53,6 +54,30 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
super(project, buildDir);
}
/**
* Gets the {@link MavenModuleSetBuild} that has the same build number.
*
* @return
* null if no such build exists, which happens when the module build
* is manually triggered.
*/
public MavenModuleSetBuild getParentBuild() {
return getParent().getParent().getBuildByNumber(getNumber());
}
@Override
public ChangeLogSet<? extends Entry> getChangeSet() {
return new FilteredChangeLogSet(this);
}
/**
* We always get the changeset from {@link MavenModuleSetBuild}.
*/
@Override
public boolean hasChangeSetComputed() {
return true;
}
@Override
public void run() {
run(new RunnerImpl());
......
......@@ -40,12 +40,6 @@ public final class MavenModule extends AbstractProject<MavenModule,MavenBuild> i
private transient ModuleName moduleName;
/**
* Relative path to this module's root directory
* from {@link MavenModuleSet#getWorkspace()}.
*
* The path separator is normalized to '/'.
*/
private String relativePath;
/**
......@@ -86,6 +80,16 @@ public final class MavenModule extends AbstractProject<MavenModule,MavenBuild> i
dependencies = Collections.emptySet();
}
/**
* Relative path to this module's root directory
* from {@link MavenModuleSet#getWorkspace()}.
*
* The path separator is normalized to '/'.
*/
public String getRelativePath() {
return relativePath;
}
@Override
public FilePath getWorkspace() {
return getParent().getWorkspace().child(relativePath);
......
......@@ -12,6 +12,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
import java.util.AbstractList;
/**
* {@link ChangeLogSet} for CVS.
......@@ -140,6 +142,18 @@ public final class CVSChangeLogSet extends ChangeLogSet<CVSChangeLog> {
return author;
}
public Collection<String> getAffectedPaths() {
return new AbstractList<String>() {
public String get(int index) {
return files.get(index).getName();
}
public int size() {
return files.size();
}
};
}
public void setUser(String author) {
this.author = User.get(author);
}
......
package hudson.scm;
import hudson.model.User;
import hudson.model.AbstractBuild;
import hudson.MarkupText;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.User;
import java.util.Collection;
import java.util.Collections;
/**
......@@ -71,6 +72,18 @@ public abstract class ChangeLogSet<T extends ChangeLogSet.Entry> implements Iter
*/
public abstract User getAuthor();
/**
* Returns a set of paths in the workspace that was
* affected by this change.
*
* <p>
* Contains string like 'foo/bar/zot'. No leading/trailing '/',
* and separator must be normalized to '/'.
*
* @return never null.
*/
public abstract Collection<String> getAffectedPaths();
/**
* Gets the text fully marked up by {@link ChangeLogAnnotator}.
*/
......
......@@ -10,6 +10,8 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.AbstractList;
/**
* {@link ChangeLogSet} for Subversion.
......@@ -72,6 +74,17 @@ public final class SubversionChangeLogSet extends ChangeLogSet<LogEntry> {
return author;
}
public Collection<String> getAffectedPaths() {
return new AbstractList<String>() {
public String get(int index) {
return paths.get(index).value;
}
public int size() {
return paths.size();
}
};
}
public void setUser(String author) {
this.author = User.get(author);
}
......
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<st:include from="${it.core}" page="digest.jelly" />
</j:jelly>
\ No newline at end of file
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<st:include from="${it.core}" page="index.jelly" />
</j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册