本文整理汇总了Java中hudson.plugins.git.util.Build类的典型用法代码示例。如果您正苦于以下问题:Java Build类的具体用法?Java Build怎么用?Java Build使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Build类属于hudson.plugins.git.util包,在下文中一共展示了Build类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBuildData
import hudson.plugins.git.util.Build; //导入依赖的package包/类
private BuildData createBuildData(String sha) {
BuildData buildData = mock(BuildData.class);
Revision revision = mock(Revision.class);
when(revision.getSha1String()).thenReturn(sha);
when(buildData.getLastBuiltRevision()).thenReturn(revision);
Build gitBuild = mock(Build.class);
when(gitBuild.getMarked()).thenReturn(revision);
when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
when(gitBuild.getRevision()).thenReturn(revision);
when(gitBuild.isFor(sha)).thenReturn(true);
buildData.lastBuild = gitBuild;
return buildData;
}
示例2: hasBeenBuilt
import hudson.plugins.git.util.Build; //导入依赖的package包/类
private boolean hasBeenBuilt(BuildData data, ObjectId sha1, String branch) {
try {
for(Map.Entry<String, Build> buildByBranchName : data.buildsByBranchName.entrySet()) {
String branchName = buildByBranchName.getKey();
if (branchName == null) {
branchName = "";
}
Build build = buildByBranchName.getValue();
if(branchName.equals(branch) && (build.revision.getSha1().equals(sha1) || build.marked.getSha1().equals(sha1)))
return true;
}
return false;
}
catch(Exception ex) {
return false;
}
}
示例3: mockBuild
import hudson.plugins.git.util.Build; //导入依赖的package包/类
private AbstractBuild mockBuild(String gitLabConnection, Result result, String... remoteUrls) {
AbstractBuild build = mock(AbstractBuild.class);
List<BuildData> buildDatas = new ArrayList<>();
BuildData buildData = mock(BuildData.class);
Revision revision = mock(Revision.class);
when(revision.getSha1String()).thenReturn(SHA1);
when(buildData.getLastBuiltRevision()).thenReturn(revision);
when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
Build gitBuild = mock(Build.class);
when(gitBuild.getMarked()).thenReturn(revision);
when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
buildDatas.add(buildData);
when(build.getActions(BuildData.class)).thenReturn(buildDatas);
when(build.getAction(BuildData.class)).thenReturn(buildData);
when(build.getResult()).thenReturn(result);
when(build.getUrl()).thenReturn(BUILD_URL);
AbstractProject<?, ?> project = mock(AbstractProject.class);
when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
when(build.getProject()).thenReturn(project);
EnvVars environment = mock(EnvVars.class);
when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return (String) invocation.getArguments()[0];
}
});
try {
when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
return build;
}
示例4: testShouldBeCommited
import hudson.plugins.git.util.Build; //导入依赖的package包/类
@Test
public void testShouldBeCommited() throws Exception {
DummySCM scm = new DummySCM(null);
FreeStyleBuild build = mock(FreeStyleBuild.class);
when(build.getResult()).thenReturn(Result.SUCCESS);
Launcher launcher = mock(Launcher.class);
BuildData gitBuildData = mock(BuildData.class);
Build lastBuild = mock(Build.class);
Revision rev = mock(Revision.class);
Branch gitBranchData = mock(Branch.class);
gitBuildData.lastBuild = lastBuild;
lastBuild.revision = rev;
when(build.getAction(BuildData.class)).thenReturn(gitBuildData);
List<Branch> branches = new ArrayList<>();
branches.add(gitBranchData);
when(gitBuildData.lastBuild.revision.getBranches()).thenReturn(branches);
when(gitBranchData.getName()).thenReturn("origin/ready/f1");
OutputStream out = new ByteArrayOutputStream();
BuildListener listener = new StreamBuildListener(out);
assertFalse(scm.isCommited());
scm.handlePostBuild(build, launcher, listener);
assertTrue(scm.isCommited());
}
示例5: retrieveGitlabProjectIds
import hudson.plugins.git.util.Build; //导入依赖的package包/类
private static List<GitLabBranchBuild> retrieveGitlabProjectIds(Run<?, ?> build, EnvVars environment) {
LOGGER.log(Level.INFO, "Retrieving gitlab project ids");
final List<GitLabBranchBuild> result = new ArrayList<>();
GitLabWebHookCause gitlabCause = build.getCause(GitLabWebHookCause.class);
if (gitlabCause != null) {
return Collections.singletonList(new GitLabBranchBuild(
gitlabCause.getData().getSourceProjectId().toString(), gitlabCause.getData().getLastCommit()));
}
// Check upstream causes for GitLabWebHookCause
List<GitLabBranchBuild> builds = findBuildsFromUpstreamCauses(build.getCauses());
if (!builds.isEmpty()) {
return builds;
}
final GitLabClient gitLabClient = getClient(build);
if (gitLabClient == null) {
LOGGER.log(Level.WARNING, "No gitlab client found.");
return result;
}
final List<BuildData> buildDatas = build.getActions(BuildData.class);
if (CollectionUtils.isEmpty(buildDatas)) {
LOGGER.log(Level.INFO, "Build does not contain build data.");
return result;
}
if (buildDatas.size() == 1) {
addGitLabBranchBuild(result, getBuildRevision(build), buildDatas.get(0).getRemoteUrls(), environment, gitLabClient);
} else {
final SCMRevisionAction scmRevisionAction = build.getAction(SCMRevisionAction.class);
if (scmRevisionAction == null) {
LOGGER.log(Level.INFO, "Build does not contain SCM revision action.");
return result;
}
final SCMRevision scmRevision = scmRevisionAction.getRevision();
String scmRevisionHash = null;
if (scmRevision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
scmRevisionHash = ((AbstractGitSCMSource.SCMRevisionImpl) scmRevision).getHash();
}
for (final BuildData buildData : buildDatas) {
for (final Entry<String, Build> buildByBranchName : buildData.getBuildsByBranchName().entrySet()) {
if (buildByBranchName.getValue().getSHA1().equals(ObjectId.fromString(scmRevisionHash))) {
addGitLabBranchBuild(result, scmRevisionHash, buildData.getRemoteUrls(), environment, gitLabClient);
}
}
}
}
return result;
}
示例6: mockBuildWithLibrary
import hudson.plugins.git.util.Build; //导入依赖的package包/类
private AbstractBuild mockBuildWithLibrary(String gitLabConnection, Result result, String... remoteUrls) {
AbstractBuild build = mock(AbstractBuild.class);
List<BuildData> buildDatas = new ArrayList<>();
BuildData buildData = mock(BuildData.class);
SCMRevisionAction scmRevisionAction = mock(SCMRevisionAction.class);
AbstractGitSCMSource.SCMRevisionImpl revisionImpl = mock(AbstractGitSCMSource.SCMRevisionImpl.class);
when(build.getAction(SCMRevisionAction.class)).thenReturn(scmRevisionAction);
when(scmRevisionAction.getRevision()).thenReturn(revisionImpl);
when(revisionImpl.getHash()).thenReturn(SHA1);
Revision revision = mock(Revision.class);
when(revision.getSha1String()).thenReturn(SHA1);
when(buildData.getLastBuiltRevision()).thenReturn(revision);
when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
Build gitBuild = mock(Build.class);
when(gitBuild.getMarked()).thenReturn(revision);
when(gitBuild.getSHA1()).thenReturn(ObjectId.fromString(SHA1));
when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
Map<String, Build> buildsByBranchName = new HashMap<>();
buildsByBranchName.put("develop", gitBuild);
when(buildData.getBuildsByBranchName()).thenReturn(buildsByBranchName);
buildDatas.add(buildData);
//Second build data (@librabry)
BuildData buildDataLib = mock(BuildData.class);
Revision revisionLib = mock(Revision.class);
when(revisionLib.getSha1String()).thenReturn("SHALIB");
when(buildDataLib.getLastBuiltRevision()).thenReturn(revisionLib);
Build gitBuildLib = mock(Build.class);
when(gitBuildLib.getMarked()).thenReturn(revisionLib);
when(buildDataLib.getLastBuild(any(ObjectId.class))).thenReturn(gitBuildLib);
buildDatas.add(buildDataLib);
when(build.getActions(BuildData.class)).thenReturn(buildDatas);
when(build.getResult()).thenReturn(result);
when(build.getUrl()).thenReturn(BUILD_URL);
AbstractProject<?, ?> project = mock(AbstractProject.class);
when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
when(build.getProject()).thenReturn(project);
EnvVars environment = mock(EnvVars.class);
when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return (String) invocation.getArguments()[0];
}
});
try {
when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
return build;
}