本文整理汇总了Java中hudson.util.VersionNumber类的典型用法代码示例。如果您正苦于以下问题:Java VersionNumber类的具体用法?Java VersionNumber怎么用?Java VersionNumber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VersionNumber类属于hudson.util包,在下文中一共展示了VersionNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPermissionWhenParameterizedForMatrixConfig
import hudson.util.VersionNumber; //导入依赖的package包/类
@LocalData
@Test
public void testPermissionWhenParameterizedForMatrixConfig() throws Exception {
// This test fails before Jenkins 1.406
if (new VersionNumber("1.406").isNewerThan(Hudson.getVersion())) return; // Skip
FreeStyleProject p = createProject("testMatrix/FOO=$FOO", null, "", "", false, false, false, true);
ParameterDefinition paramDef = new StringParameterDefinition("FOO", "FOO");
ParametersDefinitionProperty paramsDef = new ParametersDefinitionProperty(paramDef);
p.addProperty(paramsDef);
// Build step should succeed when this parameter expands to a job accessible to
// authenticated users, even when selecting a single matrix config, not the parent job:
FreeStyleBuild b = p.scheduleBuild2(0, new UserCause(),
new ParametersAction(new StringParameterValue("FOO", "foo"))).get();
assertFile(true, "foo.txt", b);
rule.assertBuildStatusSuccess(b);
}
示例2: testPermissionWhenParameterizedForMavenModule
import hudson.util.VersionNumber; //导入依赖的package包/类
@LocalData
@Test
public void testPermissionWhenParameterizedForMavenModule() throws Exception {
// This test fails before Jenkins 1.406
if (new VersionNumber("1.406").isNewerThan(Hudson.getVersion())) return; // Skip
MavenModuleSet mp = setupMavenJob();
mp.addProperty(new AuthorizationMatrixProperty(
Collections.singletonMap(Item.READ, Collections.singleton("authenticated"))));
rule.assertBuildStatusSuccess(mp.scheduleBuild2(0, new UserCause()).get());
FreeStyleProject p = createProject(mp.getName() + "/org.jvnet.hudson.main.test.multimod$FOO",
null, "", "", false, false, false, true);
ParameterDefinition paramDef = new StringParameterDefinition("FOO", "foo");
ParametersDefinitionProperty paramsDef = new ParametersDefinitionProperty(paramDef);
p.addProperty(paramsDef);
// Build step should succeed when this parameter expands to a job accessible to
// authenticated users, even when selecting a single maven module, not the parent job:
FreeStyleBuild b = p.scheduleBuild2(0, new UserCause(),
new ParametersAction(new StringParameterValue("FOO", "$moduleA"))).get();
String dir = "org.jvnet.hudson.main.test.multimod/";
assertFile(true, dir + "moduleA/1.0-SNAPSHOT/moduleA-1.0-SNAPSHOT.jar", b);
assertFile(true, dir + pomName("moduleA", "1.0-SNAPSHOT"), b);
assertFile(false, dir + "moduleB/1.0-SNAPSHOT/moduleB-1.0-SNAPSHOT.jar", b);
assertFile(false, dir + pomName("moduleB", "1.0-SNAPSHOT"), b);
rule.assertBuildStatusSuccess(b);
}
示例3: cd
import hudson.util.VersionNumber; //导入依赖的package包/类
@Issue("JENKINS-33510")
@Test public void cd() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
DockerTestUtil.assumeDocker(new VersionNumber("17.12"));
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" withDockerContainer('ubuntu') {\n" +
" sh 'mkdir subdir && echo somecontent > subdir/file'\n" +
" dir('subdir') {\n" +
" sh 'pwd; tr \"a-z\" \"A-Z\" < file'\n" +
" }\n" +
" }\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("SOMECONTENT", b);
}
});
}
示例4: suffersFromJENKINS24358
import hudson.util.VersionNumber; //导入依赖的package包/类
private static boolean suffersFromJENKINS24358() {
VersionNumber version = Jenkins.getVersion();
if (version == null) {
return false;
} else if (version.compareTo(/*JENKINS-19544*/new VersionNumber("1.557")) >=0 && version.compareTo(new VersionNumber(/*JENKINS-24358*/"1.578")) < 0) {
if (version.toString().startsWith("1.565.") && version.compareTo(new VersionNumber(/* predicting JENKINS-24358 to be backported here */"1.565.3")) >=0) {
return false;
} else {
return true;
}
} else if (version.toString().startsWith(/* JENKINS-19544 backported to 1.554.1 */"1.554.")) {
return true;
} else { // before regression or after fix
return false;
}
}
示例5: version
import hudson.util.VersionNumber; //导入依赖的package包/类
/**
* Get the docker version.
*
* @return The {@link VersionNumber} instance if the version string matches the expected format,
* otherwise {@code null}.
*/
public @CheckForNull VersionNumber version() throws IOException, InterruptedException {
LaunchResult result = launch(new EnvVars(), true, "-v");
if (result.getStatus() == 0) {
return parseVersionNumber(result.getOut());
} else {
return null;
}
}
示例6: parseVersionNumber
import hudson.util.VersionNumber; //导入依赖的package包/类
/**
* Parse a Docker version string (e.g. "Docker version 1.5.0, build a8a31ef").
* @param versionString The version string to parse.
* @return The {@link VersionNumber} instance if the version string matched the
* expected format, otherwise {@code null}.
*/
protected static VersionNumber parseVersionNumber(@Nonnull String versionString) {
Matcher matcher = pattern.matcher(versionString.trim());
if (matcher.matches()) {
String major = matcher.group(2);
String minor = matcher.group(3);
String maint = matcher.group(4);
return new VersionNumber(String.format("%s.%s.%s", major, minor, maint));
} else {
return null;
}
}
示例7: Decorator
import hudson.util.VersionNumber; //导入依赖的package包/类
Decorator(String container, EnvVars envHost, String ws, String toolName, VersionNumber dockerVersion) {
this.container = container;
this.envHost = Util.mapToEnv(envHost);
this.ws = ws;
this.toolName = toolName;
this.hasEnv = dockerVersion != null && dockerVersion.compareTo(new VersionNumber("1.13.0")) >= 0;
this.hasWorkdir = dockerVersion != null && dockerVersion.compareTo(new VersionNumber("17.12")) >= 0;
}
示例8: buildWithMultiStage
import hudson.util.VersionNumber; //导入依赖的package包/类
@Test public void buildWithMultiStage() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
assumeDocker(new VersionNumber("17.05"));
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" sh 'mkdir -p child'\n" +
" writeFile file: 'child/stuff1', text: 'hello'\n" +
" writeFile file: 'child/stuff2', text: 'world'\n" +
" writeFile file: 'child/stuff3', text: env.BUILD_NUMBER\n" +
" writeFile file: 'child/Dockerfile.other', " +
"text: '# This is a test.\\n" +
"\\n" +
"FROM hello-world AS one\\n" +
"ARG stuff4=4\\n" +
"ARG stuff5=5\\n" +
"COPY stuff1 /\\n" +
"FROM scratch\\n" +
"COPY --from=one /stuff1 /\\n" +
"COPY stuff2 /\\nCOPY stuff3 /\\n'\n" +
" def built = docker.build 'hello-world-stuff-arguments', '-f child/Dockerfile.other --build-arg stuff4=build4 --build-arg stuff5=build5 child'\n" +
" echo \"built ${built.id}\"\n" +
"}", true));
// Note the absence '--pull' in the above docker build ags as compared to other tests.
// This is due to a Docker bug: https://github.com/docker/for-mac/issues/1751
// It can be re-added when that is fixed
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
DockerClient client = new DockerClient(new Launcher.LocalLauncher(StreamTaskListener.NULL), null, null);
String descendantImageId1 = client.inspect(new EnvVars(), "hello-world-stuff-arguments", ".Id");
story.j.assertLogContains("built hello-world-stuff-arguments", b);
story.j.assertLogNotContains(" --no-cache ", b);
story.j.assertLogContains(descendantImageId1.replaceFirst("^sha256:", "").substring(0, 12), b);
story.j.assertLogContains(" --build-arg stuff4=build4 ", b);
story.j.assertLogContains(" --build-arg stuff5=build5 ", b);
}
});
}
示例9: assumeDocker
import hudson.util.VersionNumber; //导入依赖的package包/类
public static void assumeDocker(VersionNumber minimumVersion) throws Exception {
Launcher.LocalLauncher localLauncher = new Launcher.LocalLauncher(StreamTaskListener.NULL);
try {
Assume.assumeThat("Docker working", localLauncher.launch().cmds(DockerTool.getExecutable(null, null, null, null), "ps").start().joinWithTimeout(DockerClient.CLIENT_TIMEOUT, TimeUnit.SECONDS, localLauncher.getListener()), is(0));
} catch (IOException x) {
Assume.assumeNoException("have Docker installed", x);
}
DockerClient dockerClient = new DockerClient(localLauncher, null, null);
Assume.assumeFalse("Docker version not < " + minimumVersion.toString(), dockerClient.version().isOlderThan(minimumVersion));
}
示例10: test_valid_version
import hudson.util.VersionNumber; //导入依赖的package包/类
@Test
public void test_valid_version() {
VersionNumber dockerVersion = DockerClient.parseVersionNumber("Docker version 1.5.0, build a8a31ef");
Assert.assertFalse(dockerVersion.isOlderThan(new VersionNumber("1.1")));
Assert.assertFalse(dockerVersion.isOlderThan(new VersionNumber("1.5")));
Assert.assertTrue(dockerVersion.isOlderThan(new VersionNumber("1.10")));
}
示例11: parseVersion
import hudson.util.VersionNumber; //导入依赖的package包/类
private static VersionNumber parseVersion(String version) {
// any version that sorts before 17.05.0-ce
if (version.equals("latest")) return new VersionNumber("0");
final Matcher matcher = Pattern.compile("(\\d+\\.\\d+\\.\\d+).*").matcher(version);
if (matcher.matches()) return new VersionNumber(matcher.group(1));
throw new IllegalArgumentException("Failed to parse version " + version);
}
示例12: getBuildNumber
import hudson.util.VersionNumber; //导入依赖的package包/类
/**
* Retrieves the build number of this CloudTest server.
* Postcondition: The build number returned is never null.
*/
public VersionNumber getBuildNumber() throws IOException {
if (url == null) {
// User didn't enter a value in the Configure Jenkins page.
// Nothing we can do.
throw new IllegalStateException("No URL has been configured for this CloudTest server.");
}
GenericSelfClosingHttpClient client = createClient();
HttpGet get = new HttpGet(url);
String responseBody = client.sendRequest(get);
Document doc = Jsoup.parse(responseBody);
Elements elements = doc.select("meta[name=buildnumber]");
if (elements != null && elements.size() >= 1)
{
String buildNumber = elements.get(0).attr("content");
if (buildNumber != null)
{
return new VersionNumber(buildNumber);
}
}
throw new Error("failed to find build number");
}
示例13: isInstalled
import hudson.util.VersionNumber; //导入依赖的package包/类
public boolean isInstalled() {
if (installedVersion == null) {
return false;
}
try {
PluginWrapper pluginWrapper = Jenkins.getInstance().getPluginManager().getPlugin(getClass());
String targetVersion = getVersionString(pluginWrapper);
LOGGER.log(Level.FINE, "Installed version = {0}. Target version = {1}",
new Object[]{installedVersion, targetVersion});
return !new VersionNumber(installedVersion).isOlderThan(new VersionNumber(targetVersion));
} catch (Throwable t) {
// if in doubt, it's not installed
return false;
}
}
示例14: start
import hudson.util.VersionNumber; //导入依赖的package包/类
@Override public boolean start() throws Exception {
EnvVars envReduced = new EnvVars(env);
EnvVars envHost = computer.getEnvironment();
envReduced.entrySet().removeAll(envHost.entrySet());
// Remove PATH during cat.
envReduced.remove("PATH");
envReduced.remove("");
LOGGER.log(Level.FINE, "reduced environment: {0}", envReduced);
workspace.mkdirs(); // otherwise it may be owned by root when created for -v
String ws = workspace.getRemote();
toolName = step.toolName;
DockerClient dockerClient = new DockerClient(launcher, node, toolName);
VersionNumber dockerVersion = dockerClient.version();
if (dockerVersion != null) {
if (dockerVersion.isOlderThan(new VersionNumber("1.7"))) {
throw new AbortException("The docker version is less than v1.7. Pipeline functions requiring 'docker exec' (e.g. 'docker.inside') or SELinux labeling will not work.");
} else if (dockerVersion.isOlderThan(new VersionNumber("1.8"))) {
listener.error("The docker version is less than v1.8. Running a 'docker.inside' from inside a container will not work.");
}
} else {
listener.error("Failed to parse docker version. Please note there is a minimum docker version requirement of v1.7.");
}
FilePath tempDir = tempDir(workspace);
tempDir.mkdirs();
String tmp = tempDir.getRemote();
Map<String, String> volumes = new LinkedHashMap<String, String>();
Collection<String> volumesFromContainers = new LinkedHashSet<String>();
Optional<String> containerId = dockerClient.getContainerIdIfContainerized();
if (containerId.isPresent()) {
listener.getLogger().println(node.getDisplayName() + " seems to be running inside container " + containerId.get());
final Collection<String> mountedVolumes = dockerClient.getVolumes(env, containerId.get());
final String[] dirs = {ws, tmp};
for (String dir : dirs) {
// check if there is any volume which contains the directory
boolean found = false;
for (String vol : mountedVolumes) {
if (dir.startsWith(vol)) {
volumesFromContainers.add(containerId.get());
found = true;
break;
}
}
if (!found) {
listener.getLogger().println("but " + dir + " could not be found among " + mountedVolumes);
volumes.put(dir, dir);
}
}
} else {
listener.getLogger().println(node.getDisplayName() + " does not seem to be running inside a container");
volumes.put(ws, ws);
volumes.put(tmp, tmp);
}
container = dockerClient.run(env, step.image, step.args, ws, volumes, volumesFromContainers, envReduced, dockerClient.whoAmI(), /* expected to hang until killed */ "cat");
DockerFingerprints.addRunFacet(dockerClient.getContainerRecord(env, container), run);
ImageAction.add(step.image, run);
getContext().newBodyInvoker().
withContext(BodyInvoker.mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new Decorator(container, envHost, ws, toolName, dockerVersion))).
withCallback(new Callback(container, toolName)).
start();
return false;
}
示例15: isNewJenkins
import hudson.util.VersionNumber; //导入依赖的package包/类
public boolean isNewJenkins() {
final VersionNumber matrixBreakOutVersion = new VersionNumber("1.560");
return Jenkins.getVersion().isNewerThan(matrixBreakOutVersion);
}