hudson.Util类的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(350)

本文整理了Java中hudson.Util类的一些代码示例,展示了Util类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util类的具体详情如下:
包路径:hudson.Util
类名称:Util

Util介绍

[英]Various utility methods that don't have more proper home.
[中]各种实用方法,没有更合适的家。

代码示例

代码示例来源:origin: jenkinsci/jenkins

  1. public FormValidation doCheckCustomWorkspace(@QueryParameter String customWorkspace){
  2. if(Util.fixEmptyAndTrim(customWorkspace)==null)
  3. return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty());
  4. else
  5. return FormValidation.ok();
  6. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Fails if a global view with the given name does not exist.
  3. */
  4. public FormValidation doViewExistsCheck(@QueryParameter String value) {
  5. checkPermission(View.CREATE);
  6. String view = Util.fixEmpty(value);
  7. if(view==null) return FormValidation.ok();
  8. if(Jenkins.getInstance().getView(view)!=null)
  9. return FormValidation.ok();
  10. else
  11. return FormValidation.error(Messages.ProxyView_NoSuchViewExists(value));
  12. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Convert null to "".
  3. */
  4. @Nonnull
  5. public static String fixNull(@CheckForNull String s) {
  6. return fixNull(s, "");
  7. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Computes the MD5 digest of a file.
  3. * @param file a file
  4. * @return a 32-character string
  5. * @throws IOException in case reading fails
  6. * @since 1.525
  7. */
  8. @Nonnull
  9. public static String getDigestOf(@Nonnull File file) throws IOException {
  10. // Note: getDigestOf() closes the input stream.
  11. return getDigestOf(Files.newInputStream(fileToPath(file)));
  12. }

代码示例来源:origin: jenkinsci/jenkins

  1. public WarningVersionRange(JSONObject o) {
  2. this.name = Util.fixEmpty(o.optString("name"));
  3. this.firstVersion = Util.intern(Util.fixEmpty(o.optString("firstVersion")));
  4. this.lastVersion = Util.intern(Util.fixEmpty(o.optString("lastVersion")));
  5. Pattern p;
  6. try {
  7. p = Pattern.compile(o.getString("pattern"));
  8. } catch (PatternSyntaxException ex) {
  9. LOGGER.log(Level.WARNING, "Failed to compile pattern '" + o.getString("pattern") + "', using '.*' instead", ex);
  10. p = Pattern.compile(".*");
  11. }
  12. this.pattern = p;
  13. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Performs syntactical check on the remote FS for agents.
  3. */
  4. public FormValidation doCheckRemoteFS(@QueryParameter String value) throws IOException, ServletException {
  5. if(Util.fixEmptyAndTrim(value)==null)
  6. return FormValidation.error(Messages.Slave_Remote_Director_Mandatory());
  7. if(value.startsWith("\\\\") || value.startsWith("/net/"))
  8. return FormValidation.warning(Messages.Slave_Network_Mounted_File_System_Warning());
  9. if (Util.isRelativePath(value)) {
  10. return FormValidation.warning(Messages.Slave_Remote_Relative_Path_Warning());
  11. }
  12. return FormValidation.ok();
  13. }

代码示例来源:origin: jenkinsci/jenkins

  1. public static @Nonnull FormValidation validateLabelExpression(String value, @CheckForNull AbstractProject<?, ?> project) {
  2. if (Util.fixEmpty(value)==null)
  3. return FormValidation.ok(); // nothing typed yet
  4. try {
  5. Label.parseExpression(value);
  6. } catch (ANTLRException e) {
  7. return FormValidation.error(e,
  8. Messages.AbstractProject_AssignedLabelString_InvalidBooleanExpression(e.getMessage()));
  9. Jenkins j = Jenkins.getInstance();
  10. Label l = j.getLabel(value);
  11. if (l.isEmpty()) {
  12. for (LabelAtom a : l.listAtoms()) {
  13. if (a.isEmpty()) {
  14. LabelAtom nearest = LabelAtom.findNearest(a.getName());
  15. return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch_DidYouMean(a.getName(),nearest.getDisplayName()));
  16. return FormValidation.warning(Messages.AbstractProject_AssignedLabelString_NoMatch());
  17. .getExtensionList(AbstractProject.LabelValidator.class)) {
  18. FormValidation result = v.check(project, l);
  19. if (!FormValidation.Kind.OK.equals(result.kind)) {
  20. return FormValidation.okWithMarkup(Messages.AbstractProject_LabelLink(
  21. j.getRootUrl(), Util.escape(l.getName()), l.getUrl(), l.getNodes().size(), l.getClouds().size())
  22. );

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Handles a fatal build problem (exception) that occurred during the build.
  3. */
  4. private void handleFatalBuildProblem(@Nonnull BuildListener listener, @Nonnull Throwable e) {
  5. if(listener!=null) {
  6. LOGGER.log(FINE, getDisplayName()+" failed to build",e);
  7. if(e instanceof IOException)
  8. Util.displayIOException((IOException)e,listener);
  9. Functions.printStackTrace(e, listener.fatalError(e.getMessage()));
  10. } else {
  11. LOGGER.log(SEVERE, getDisplayName()+" failed to build and we don't even have a listener",e);
  12. }
  13. }

代码示例来源:origin: jenkinsci/jenkins

  1. @Nonnull
  2. public static String getDigestOf(@Nonnull String text) {
  3. try {
  4. return getDigestOf(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
  5. } catch (IOException e) {
  6. throw new Error(e);
  7. }
  8. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Replaces the occurrence of '$key' by {@code properties.get('key')}.
  3. *
  4. * <p>
  5. * Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.)
  6. *
  7. */
  8. @Nullable
  9. public static String replaceMacro( @CheckForNull String s, @Nonnull Map<String,String> properties) {
  10. return replaceMacro(s,new VariableResolver.ByMap<String>(properties));
  11. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Gets the string that says how long the build took to run.
  3. */
  4. public @Nonnull String getDurationString() {
  5. if (hasntStartedYet()) {
  6. return Messages.Run_NotStartedYet();
  7. } else if (isBuilding()) {
  8. return Messages.Run_InProgressDuration(
  9. Util.getTimeSpanString(System.currentTimeMillis()-startTime));
  10. }
  11. return Util.getTimeSpanString(duration);
  12. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Get a human readable string representing strings like "xxx days ago",
  3. * which should be used to point to the occurrence of an event in the past.
  4. */
  5. @Nonnull
  6. public static String getPastTimeString(long duration) {
  7. return Messages.Util_pastTime(getTimeSpanString(duration));
  8. }

代码示例来源:origin: jenkinsci/jenkins

  1. public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int numExecutors,
  2. Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException {
  3. this.name = name;
  4. this.numExecutors = numExecutors;
  5. this.mode = mode;
  6. this.remoteFS = Util.fixNull(remoteFS).trim();
  7. this.label = Util.fixNull(labelString).trim();
  8. this.launcher = launcher;
  9. this.retentionStrategy = retentionStrategy;
  10. Slave node = (Slave) Jenkins.getInstance().getNode(name);
  11. throw new FormException(Messages.Slave_InvalidConfig_NoName(), null);
  12. throw new FormException(Messages.Slave_InvalidConfig_Executors(name), null);

代码示例来源:origin: jenkinsci/jenkins

  1. @Nonnull
  2. @Restricted(NoExternalUse.class)
  3. /*package*/ String getApiTokenInsecure() {
  4. if(apiToken == null){
  5. return Messages.ApiTokenProperty_NoLegacyToken();
  6. }
  7. String p = apiToken.getPlainText();
  8. if (p.equals(Util.getDigestOf(Jenkins.getInstance().getSecretKey()+":"+user.getId()))) {
  9. // if the current token is the initial value created by pre SECURITY-49 Jenkins, we can't use that.
  10. // force using the newer value
  11. apiToken = Secret.fromString(p=API_KEY_SEED.mac(user.getId()));
  12. }
  13. return Util.getDigestOf(p);
  14. }

代码示例来源:origin: jenkinsci/jenkins

  1. public FormValidation doCheckUpstreamProjects(@AncestorInPath Job project, @QueryParameter String value) {
  2. if (!project.hasPermission(Item.CONFIGURE)) {
  3. return FormValidation.ok();
  4. }
  5. StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),",");
  6. boolean hasProjects = false;
  7. while(tokens.hasMoreTokens()) {
  8. String projectName = tokens.nextToken().trim();
  9. if (StringUtils.isNotBlank(projectName)) {
  10. Job item = Jenkins.getInstance().getItem(projectName, project, Job.class);
  11. if (item == null) {
  12. Job nearest = Items.findNearest(Job.class, projectName, project.getParent());
  13. String alternative = nearest != null ? nearest.getRelativeNameFrom(project) : "?";
  14. return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoSuchProject(projectName, alternative));
  15. }
  16. hasProjects = true;
  17. }
  18. }
  19. if (!hasProjects) {
  20. return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoProjectSpecified());
  21. }
  22. return FormValidation.ok();
  23. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Makes sure that the given name is good as an agent name.
  3. */
  4. public FormValidation doCheckName(@QueryParameter String value) throws IOException, ServletException {
  5. Jenkins.getInstance().checkPermission(Computer.CREATE);
  6. if(Util.fixEmpty(value)==null)
  7. return FormValidation.ok();
  8. try {
  9. checkName(value);
  10. return FormValidation.ok();
  11. } catch (Failure e) {
  12. return FormValidation.error(e.getMessage());
  13. }
  14. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Checks if a top-level view with the given name exists.
  3. * @deprecated 1.512
  4. */
  5. @Deprecated
  6. public FormValidation doViewExistsCheck(@QueryParameter String value) {
  7. checkPermission(View.CREATE);
  8. String view = fixEmpty(value);
  9. if(view==null) return FormValidation.ok();
  10. if(getView(view)==null)
  11. return FormValidation.ok();
  12. else
  13. return FormValidation.error(Messages.Hudson_ViewAlreadyExists(view));
  14. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Makes sure that the given name is good as a job name.
  3. * For use from {@code newJob}.
  4. */
  5. @Restricted(DoNotUse.class) // called from newJob view
  6. public FormValidation doCheckJobName(@QueryParameter String value) {
  7. // this method can be used to check if a file exists anywhere in the file system,
  8. // so it should be protected.
  9. getOwner().checkPermission(Item.CREATE);
  10. if (Util.fixEmpty(value) == null) {
  11. return FormValidation.ok();
  12. }
  13. try {
  14. Jenkins.checkGoodName(value);
  15. value = value.trim(); // why trim *after* checkGoodName? not sure, but ItemGroupMixIn.createTopLevelItem does the same
  16. Jenkins.getInstance().getProjectNamingStrategy().checkName(value);
  17. } catch (Failure e) {
  18. return FormValidation.error(e.getMessage());
  19. }
  20. if (getOwner().getItemGroup().getItem(value) != null) {
  21. return FormValidation.error(Messages.Hudson_JobAlreadyExists(value));
  22. }
  23. // looks good
  24. return FormValidation.ok();
  25. }

代码示例来源:origin: jenkinsci/jenkins

  1. @RequirePOST
  2. public FormValidation doValidateProxy(
  3. @QueryParameter("testUrl") String testUrl, @QueryParameter("name") String name, @QueryParameter("port") int port,
  4. @QueryParameter("userName") String userName, @QueryParameter("password") String password,
  5. @QueryParameter("noProxyHost") String noProxyHost) {
  6. Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
  7. if (Util.fixEmptyAndTrim(testUrl) == null) {
  8. return FormValidation.error(Messages.ProxyConfiguration_TestUrlRequired());
  9. host = url.getHost();
  10. } catch (MalformedURLException e) {
  11. return FormValidation.error(Messages.ProxyConfiguration_MalformedTestUrl(testUrl));
  12. if (Util.fixEmptyAndTrim(name) != null && !isNoProxyHost(host, noProxyHost)) {
  13. client.getHostConfiguration().setProxy(name, port);
  14. Credentials credentials = createCredentials(userName, password);
  15. return FormValidation.error(Messages.ProxyConfiguration_FailedToConnect(testUrl, code));

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Performs syntax check.
  3. */
  4. public FormValidation doCheck(@QueryParameter String value) {
  5. try {
  6. String msg = CronTabList.create(fixNull(value)).checkSanity();
  7. if (msg != null)
  8. return FormValidation.warning(msg);
  9. return FormValidation.ok();
  10. } catch (ANTLRException e) {
  11. return FormValidation.error(e.getMessage());
  12. }
  13. }
  14. }

相关文章