package hudson.plugins.git;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Proc;
import hudson.FilePath.FileCallable;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Hudson;
import hudson.model.ParametersAction;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.browser.GitWeb;
import hudson.plugins.git.opt.PreBuildMergeOptions;
import hudson.plugins.git.util.*;
import hudson.remoting.VirtualChannel;
import hudson.scm.ChangeLogParser;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import hudson.util.FormFieldValidator;
import hudson.util.FormValidation;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.spearce.jgit.lib.ObjectId;
import org.spearce.jgit.lib.RepositoryConfig;
import org.spearce.jgit.transport.RefSpec;
import org.spearce.jgit.transport.RemoteConfig;
/**
* Git SCM.
*
* @author Nigel Magnay
*/
public class GitSCM extends SCM implements Serializable {
// old fields are left so that old config data can be read in, but
// they are deprecated. transient so that they won't show up in XML
// when writing back
@Deprecated transient String source;
@Deprecated transient String branch;
/**
* Store a config version so we're able to migrate config on various
* functionality upgrades.
*/
private Long configVersion;
/**
* All the remote repositories that we know about.
*/
private List<RemoteConfig> remoteRepositories;
/**
* All the branches that we wish to care about building.
*/
private List<BranchSpec> branches;
/**
* Options for merging before a build.
*/
private PreBuildMergeOptions mergeOptions;
private boolean doGenerateSubmoduleConfigurations;
private boolean clean;
private String choosingStrategy = DEFAULT;
public static final String DEFAULT = "Default";
public static final String GERRIT = "Gerrit";
private GitWeb browser;
private Collection<SubmoduleConfig> submoduleCfg;
public static final String GIT_BRANCH = "GIT_BRANCH";
public static final String GIT_COMMIT = "GIT_COMMIT";
public Collection<SubmoduleConfig> getSubmoduleCfg() {
return submoduleCfg;
}
public void setSubmoduleCfg(Collection<SubmoduleConfig> submoduleCfg) {
this.submoduleCfg = submoduleCfg;
}
@DataBoundConstructor
public GitSCM(
List<RemoteConfig> repositories,
List<BranchSpec> branches,
PreBuildMergeOptions mergeOptions,
boolean doGenerateSubmoduleConfigurations,
Collection<SubmoduleConfig> submoduleCfg,
boolean clean,
String choosingStrategy, GitWeb browser) {
// normalization
this.branches = branches;
this.remoteRepositories = repositories;
this.browser = browser;
this.mergeOptions = mergeOptions;
this.doGenerateSubmoduleConfigurations = doGenerateSubmoduleConfigurations;
this.submoduleCfg = submoduleCfg;
this.clean = clean;
this.choosingStrategy = choosingStrategy;
this.configVersion = 1L;
}
public Object readResolve() {
// Migrate data
// Default unspecified to v0
if( configVersion == null )
configVersion = 0L;
if(source!=null)
{
remoteRepositories = new ArrayList<RemoteConfig>();
branches = new ArrayList<BranchSpec>();
doGenerateSubmoduleConfigurations = false;
mergeOptions = new PreBuildMergeOptions();
remoteRepositories.add(newRemoteConfig("origin", source, new RefSpec("+refs/heads/*:refs/remotes/origin/*") ));
if( branch != null )
{
branches.add(new BranchSpec(branch));
}
else
{
branches.add(new BranchSpec("*/master"));
}
}
if( configVersion < 1 && branches != null )
{
// Migrate the branch specs from
// single * wildcard, to ** wildcard.
for( BranchSpec branchSpec : branches )
{
String name = branchSpec.getName();
name = name.replace("*", "**");
branchSpec.setName(name);
}
}
if( mergeOptions.doMerge() && mergeOptions.getMergeRemote() == null )
{
mergeOptions.setMergeRemote(remoteRepositories.get(0));
}
return this;
}
@Override
public GitWeb getBrowser() {
return browser;
}
public boolean getClean() {
return this.clean;
}
public String getChoosingStrategy() {
return choosingStrategy;
}
public List<RemoteConfig> getRepositories() {
// Handle null-value to ensure backwards-compatibility, ie project configuration missing the <repositories/> XML element
if (remoteRepositories == null)
return new ArrayList<RemoteConfig>();
return remoteRepositories;
}
private String getSingleBranch(AbstractBuild<?, ?> build) {
// if we have multiple branches skip to advanced usecase
if (getBranches().size() != 1 || getRepositories().size() != 1)
return null;
String branch = getBranches().get(0).getName();
String repository = getRepositories().get(0).getName();
// replace repository wildcard with repository name
if (branch.startsWith("*/"))
branch = repository + branch.substring(1);
// if the branch name contains more wildcards then the simple usecase
// does not apply and we need to skip to the advanced usecase
if (branch.contains("*"))
return null;
// substitute build parameters if available
ParametersAction parameters = build.getAction(ParametersAction.class);
if (parameters != null)
branch = parameters.substitute(build, branch);
return branch;
}
@Override
public boolean pollChanges(final AbstractProject project, Launcher launcher,
final FilePath workspace, final TaskListener listener)
throws IOException, InterruptedException
{
// Poll for changes. Are there any unbuilt revisions that Hudson ought to build ?
final String gitExe = getDescriptor().getGitExe();
listener.getLogger().println("Using strategy: " + choosingStrategy);
AbstractBuild lastBuild = (AbstractBuild)project.getLastBuild();
if( lastBuild != null )
{
listener.getLogger().println("[poll] Last Build : #" + lastBuild.getNumber() );
}
final BuildData buildData = getBuildData(lastBuild, false);
if( buildData != null && buildData.lastBuild != null)
{
listener.getLogger().println("[poll] Last Built Revision: " + buildData.lastBuild.revision );
}
final String singleBranch = getSingleBranch(lastBuild);
boolean pollChangesResult = workspace.act(new FileCallable<Boolean>() {
private static final long serialVersionUID = 1L;
public Boolean invoke(File localWorkspace, VirtualChannel channel) throws IOException {
EnvVars environment = new EnvVars(System.getenv());
IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener, environment);
IBuildChooser buildChooser = createBuildChooser(git, listener, buildData);
if (git.hasGitRepo()) {
// Repo is there - do a fetch
listener.getLogger().println("Fetching changes from the remote Git repositories");
// Fetch updates
for (RemoteConfig re
没有合适的资源?快使用搜索试试~ 我知道了~
Hudson-GIT-plugin:Hudson的Git插件
共64个文件
java:31个
html:10个
jelly:9个
需积分: 14 2 下载量 19 浏览量
2021-02-19
16:24:02
上传
评论
收藏 1.25MB ZIP 举报
温馨提示
Hudson-GIT-plugin:Hudson的Git插件
资源详情
资源评论
资源推荐
收起资源包目录
Hudson-GIT-plugin-master.zip (64个子文件)
Hudson-GIT-plugin-master
.gitignore 55B
src
main
resources
index.jelly 86B
hudson
plugins
git
GitPublisher
config.jelly 158B
GitChangeSetList
index.jelly 2KB
digest.jelly 1KB
util
BuildData
index.jelly 641B
summary.jelly 455B
browser
GitWeb
config.jelly 279B
GitSCM
global.jelly 458B
config.jelly 6KB
java
hudson
plugins
git
Revision.java 2KB
GitChangeLogParser.java 1KB
opt
PreBuildMergeOptions.java 860B
GitRepositoryBrowser.java 1KB
IndexEntry.java 874B
GitAPI.java 20KB
GitSCM.java 30KB
PluginImpl.java 164B
GitChangeSet.java 6KB
GitChangeSetList.java 933B
GitException.java 380B
util
IBuildChooser.java 2KB
Build.java 2KB
GitUtils.java 4KB
GerritBuildChooser.java 4KB
BuildData.java 3KB
BuildChooser.java 6KB
GitObject.java 643B
SubmoduleCombinator.java 8KB
SubmoduleConfig.java 1KB
GitPublisher.java 5KB
browser
GitWeb.java 3KB
Branch.java 592B
Tag.java 681B
BranchSpec.java 4KB
IGitAPI.java 2KB
webapp
icons
git-32x32.png 1KB
git-22x22.png 1KB
git-48x48.png 2KB
gitweb.html 117B
branch.html 164B
help.html 85B
merge.html 459B
clean.html 82B
help-gitExe.html 146B
choosingStrategy.html 152B
timebased.html 143B
extraRepo.html 223B
gitPublisher.html 85B
test
hudson
plugins
git
SubmoduleCombinatorTest.java 2KB
test
java
hudson
plugins
git
MockStaplerRequest.java 12KB
TestBranchSpec.java 2KB
GitChangeSetTest.java 4KB
GitSCMTest.java 10KB
dotm2_settings.xml 1004B
pom.xml 3KB
maven-repository
org
spearce
jgit
0.4-750e07d
jgit-0.4-750e07d.pom 8KB
jgit-0.4-750e07d.jar 654KB
0.4-47e4af3
jgit-0.4-47e4af3.jar 656KB
jgit-0.4-47e4af3.pom 8KB
jgit-patch
0001-asdf.patch 10KB
0002-Extend-unit-tests-for-Externalizable-items-so-that-e.patch 20KB
README 790B
SVN_USERS_PLEASE_READ_ME 365B
共 64 条
- 1
iwbunny
- 粉丝: 26
- 资源: 4673
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0