本文整理了Java中hudson.Util
类的一些代码示例,展示了Util
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util
类的具体详情如下:
包路径:hudson.Util
类名称:Util
[英]Various utility methods that don't have more proper home.
[中]各种实用方法,没有更合适的家。
代码示例来源:origin: jenkinsci/jenkins
public FormValidation doCheckCustomWorkspace(@QueryParameter String customWorkspace){
if(Util.fixEmptyAndTrim(customWorkspace)==null)
return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty());
else
return FormValidation.ok();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Fails if a global view with the given name does not exist.
*/
public FormValidation doViewExistsCheck(@QueryParameter String value) {
checkPermission(View.CREATE);
String view = Util.fixEmpty(value);
if(view==null) return FormValidation.ok();
if(Jenkins.getInstance().getView(view)!=null)
return FormValidation.ok();
else
return FormValidation.error(Messages.ProxyView_NoSuchViewExists(value));
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Convert null to "".
*/
@Nonnull
public static String fixNull(@CheckForNull String s) {
return fixNull(s, "");
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Computes the MD5 digest of a file.
* @param file a file
* @return a 32-character string
* @throws IOException in case reading fails
* @since 1.525
*/
@Nonnull
public static String getDigestOf(@Nonnull File file) throws IOException {
// Note: getDigestOf() closes the input stream.
return getDigestOf(Files.newInputStream(fileToPath(file)));
}
代码示例来源:origin: jenkinsci/jenkins
public WarningVersionRange(JSONObject o) {
this.name = Util.fixEmpty(o.optString("name"));
this.firstVersion = Util.intern(Util.fixEmpty(o.optString("firstVersion")));
this.lastVersion = Util.intern(Util.fixEmpty(o.optString("lastVersion")));
Pattern p;
try {
p = Pattern.compile(o.getString("pattern"));
} catch (PatternSyntaxException ex) {
LOGGER.log(Level.WARNING, "Failed to compile pattern '" + o.getString("pattern") + "', using '.*' instead", ex);
p = Pattern.compile(".*");
}
this.pattern = p;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Performs syntactical check on the remote FS for agents.
*/
public FormValidation doCheckRemoteFS(@QueryParameter String value) throws IOException, ServletException {
if(Util.fixEmptyAndTrim(value)==null)
return FormValidation.error(Messages.Slave_Remote_Director_Mandatory());
if(value.startsWith("\\\\") || value.startsWith("/net/"))
return FormValidation.warning(Messages.Slave_Network_Mounted_File_System_Warning());
if (Util.isRelativePath(value)) {
return FormValidation.warning(Messages.Slave_Remote_Relative_Path_Warning());
}
return FormValidation.ok();
}
代码示例来源:origin: jenkinsci/jenkins
public static @Nonnull FormValidation validateLabelExpression(String value, @CheckForNull AbstractProject<?, ?> project) {
if (Util.fixEmpty(value)==null)
return FormValidation.ok(); // nothing typed yet
try {
Label.parseExpression(value);
} catch (ANTLRException e) {
return FormValidation.error(e,
Messages.AbstractProject_AssignedLabelString_InvalidBooleanExpression(e.getMessage()));
Jenkins j = Jenkins.getInstance();
Label l = j.getLabel(value);
if (l.isEmpty()) {
for (LabelAtom a : l.listAtoms()) {
if (a.isEmpty()) {
LabelAtom nearest = LabelAtom.findNearest(a.getName());
return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch_DidYouMean(a.getName(),nearest.getDisplayName()));
return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch());
.getExtensionList(AbstractProject.LabelValidator.class)) {
FormValidation result = v.check(project, l);
if (!FormValidation.Kind.OK.equals(result.kind)) {
return FormValidation.okWithMarkup(Messages.AbstractProject_LabelLink(
j.getRootUrl(), Util.escape(l.getName()), l.getUrl(), l.getNodes().size(), l.getClouds().size())
);
代码示例来源:origin: jenkinsci/jenkins
/**
* Handles a fatal build problem (exception) that occurred during the build.
*/
private void handleFatalBuildProblem(@Nonnull BuildListener listener, @Nonnull Throwable e) {
if(listener!=null) {
LOGGER.log(FINE, getDisplayName()+" failed to build",e);
if(e instanceof IOException)
Util.displayIOException((IOException)e,listener);
Functions.printStackTrace(e, listener.fatalError(e.getMessage()));
} else {
LOGGER.log(SEVERE, getDisplayName()+" failed to build and we don't even have a listener",e);
}
}
代码示例来源:origin: jenkinsci/jenkins
@Nonnull
public static String getDigestOf(@Nonnull String text) {
try {
return getDigestOf(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
} catch (IOException e) {
throw new Error(e);
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Replaces the occurrence of '$key' by {@code properties.get('key')}.
*
* <p>
* Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.)
*
*/
@Nullable
public static String replaceMacro( @CheckForNull String s, @Nonnull Map<String,String> properties) {
return replaceMacro(s,new VariableResolver.ByMap<String>(properties));
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Gets the string that says how long the build took to run.
*/
public @Nonnull String getDurationString() {
if (hasntStartedYet()) {
return Messages.Run_NotStartedYet();
} else if (isBuilding()) {
return Messages.Run_InProgressDuration(
Util.getTimeSpanString(System.currentTimeMillis()-startTime));
}
return Util.getTimeSpanString(duration);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Get a human readable string representing strings like "xxx days ago",
* which should be used to point to the occurrence of an event in the past.
*/
@Nonnull
public static String getPastTimeString(long duration) {
return Messages.Util_pastTime(getTimeSpanString(duration));
}
代码示例来源:origin: jenkinsci/jenkins
public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int numExecutors,
Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException {
this.name = name;
this.numExecutors = numExecutors;
this.mode = mode;
this.remoteFS = Util.fixNull(remoteFS).trim();
this.label = Util.fixNull(labelString).trim();
this.launcher = launcher;
this.retentionStrategy = retentionStrategy;
Slave node = (Slave) Jenkins.getInstance().getNode(name);
throw new FormException(Messages.Slave_InvalidConfig_NoName(), null);
throw new FormException(Messages.Slave_InvalidConfig_Executors(name), null);
代码示例来源:origin: jenkinsci/jenkins
@Nonnull
@Restricted(NoExternalUse.class)
/*package*/ String getApiTokenInsecure() {
if(apiToken == null){
return Messages.ApiTokenProperty_NoLegacyToken();
}
String p = apiToken.getPlainText();
if (p.equals(Util.getDigestOf(Jenkins.getInstance().getSecretKey()+":"+user.getId()))) {
// if the current token is the initial value created by pre SECURITY-49 Jenkins, we can't use that.
// force using the newer value
apiToken = Secret.fromString(p=API_KEY_SEED.mac(user.getId()));
}
return Util.getDigestOf(p);
}
代码示例来源:origin: jenkinsci/jenkins
public FormValidation doCheckUpstreamProjects(@AncestorInPath Job project, @QueryParameter String value) {
if (!project.hasPermission(Item.CONFIGURE)) {
return FormValidation.ok();
}
StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),",");
boolean hasProjects = false;
while(tokens.hasMoreTokens()) {
String projectName = tokens.nextToken().trim();
if (StringUtils.isNotBlank(projectName)) {
Job item = Jenkins.getInstance().getItem(projectName, project, Job.class);
if (item == null) {
Job nearest = Items.findNearest(Job.class, projectName, project.getParent());
String alternative = nearest != null ? nearest.getRelativeNameFrom(project) : "?";
return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoSuchProject(projectName, alternative));
}
hasProjects = true;
}
}
if (!hasProjects) {
return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoProjectSpecified());
}
return FormValidation.ok();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Makes sure that the given name is good as an agent name.
*/
public FormValidation doCheckName(@QueryParameter String value) throws IOException, ServletException {
Jenkins.getInstance().checkPermission(Computer.CREATE);
if(Util.fixEmpty(value)==null)
return FormValidation.ok();
try {
checkName(value);
return FormValidation.ok();
} catch (Failure e) {
return FormValidation.error(e.getMessage());
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Checks if a top-level view with the given name exists.
* @deprecated 1.512
*/
@Deprecated
public FormValidation doViewExistsCheck(@QueryParameter String value) {
checkPermission(View.CREATE);
String view = fixEmpty(value);
if(view==null) return FormValidation.ok();
if(getView(view)==null)
return FormValidation.ok();
else
return FormValidation.error(Messages.Hudson_ViewAlreadyExists(view));
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Makes sure that the given name is good as a job name.
* For use from {@code newJob}.
*/
@Restricted(DoNotUse.class) // called from newJob view
public FormValidation doCheckJobName(@QueryParameter String value) {
// this method can be used to check if a file exists anywhere in the file system,
// so it should be protected.
getOwner().checkPermission(Item.CREATE);
if (Util.fixEmpty(value) == null) {
return FormValidation.ok();
}
try {
Jenkins.checkGoodName(value);
value = value.trim(); // why trim *after* checkGoodName? not sure, but ItemGroupMixIn.createTopLevelItem does the same
Jenkins.getInstance().getProjectNamingStrategy().checkName(value);
} catch (Failure e) {
return FormValidation.error(e.getMessage());
}
if (getOwner().getItemGroup().getItem(value) != null) {
return FormValidation.error(Messages.Hudson_JobAlreadyExists(value));
}
// looks good
return FormValidation.ok();
}
代码示例来源:origin: jenkinsci/jenkins
@RequirePOST
public FormValidation doValidateProxy(
@QueryParameter("testUrl") String testUrl, @QueryParameter("name") String name, @QueryParameter("port") int port,
@QueryParameter("userName") String userName, @QueryParameter("password") String password,
@QueryParameter("noProxyHost") String noProxyHost) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
if (Util.fixEmptyAndTrim(testUrl) == null) {
return FormValidation.error(Messages.ProxyConfiguration_TestUrlRequired());
host = url.getHost();
} catch (MalformedURLException e) {
return FormValidation.error(Messages.ProxyConfiguration_MalformedTestUrl(testUrl));
if (Util.fixEmptyAndTrim(name) != null && !isNoProxyHost(host, noProxyHost)) {
client.getHostConfiguration().setProxy(name, port);
Credentials credentials = createCredentials(userName, password);
return FormValidation.error(Messages.ProxyConfiguration_FailedToConnect(testUrl, code));
代码示例来源:origin: jenkinsci/jenkins
/**
* Performs syntax check.
*/
public FormValidation doCheck(@QueryParameter String value) {
try {
String msg = CronTabList.create(fixNull(value)).checkSanity();
if (msg != null)
return FormValidation.warning(msg);
return FormValidation.ok();
} catch (ANTLRException e) {
return FormValidation.error(e.getMessage());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!