hudson.Util.replaceMacro()方法的使用及代码示例

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

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

Util.replaceMacro介绍

[英]Replaces the occurrence of '$key' by resolver.get('key').

Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.)
[中]替换冲突解决程序出现的“$key”。获取('key')。
与shell不同,未定义的变量保持原样(这种行为与Ant相同)

代码示例

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

/**
 * Expands the variables in the given string by using environment variables represented in 'this'.
 */
public String expand(String s) {
  return Util.replaceMacro(s, this);
}

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

/**
 * Resolves environment variables against each other.
 */
public static void resolve(Map<String, String> env) {
  for (Map.Entry<String,String> entry: env.entrySet()) {
    entry.setValue(Util.replaceMacro(entry.getValue(), env));
  }
}

代码示例来源: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

/**
 * Performs a variable substitution to the given text and return it.
 */
public String substitute(AbstractBuild<?,?> build, String text) {
  return Util.replaceMacro(text,createVariableResolver(build));
}

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

private File getExeFile(String execName) {
  String m2Home = Util.replaceMacro(getHome(),EnvVars.masterEnvVars);
  if(Functions.isWindows()) {
    File exeFile = new File(m2Home, "bin/" + execName + ".bat");
    // since Maven 3.3 .bat files are replaced with .cmd
    if (!exeFile.exists()) {
      return new File(m2Home, "bin/" + execName + ".cmd");
    }
    return exeFile;
  } else {
    return new File(m2Home, "bin/" + execName);
  }
}

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

/**
 * Recursively expands the variables in text and attribute values and return the new DOM.
 *
 * The expansion uses {@link Util#replaceMacro(String, VariableResolver)}, so any unresolved
 * references will be left as-is.
 */
public XStreamDOM expandMacro(VariableResolver<String> vars) {
  String[] newAttributes = new String[attributes.length];
  for (int i=0; i<attributes.length; i+=2) {
    newAttributes[i+0] = attributes[i]; // name
    newAttributes[i+1] = Util.replaceMacro(attributes[i+1],vars);
  }
  List<XStreamDOM> newChildren = null;
  if (children!=null) {
    newChildren = new ArrayList<XStreamDOM>(children.size());
    for (XStreamDOM d : children)
      newChildren.add(d.expandMacro(vars));
  }
  return new XStreamDOM(tagName,newAttributes,newChildren,Util.replaceMacro(value,vars));
}

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

@Restricted(NoExternalUse.class)
public static String expandVariablesForDirectory(String base, String itemFullName, String itemRootDir) {
  return Util.replaceMacro(base, ImmutableMap.of(
      "JENKINS_HOME", Jenkins.getInstance().getRootDir().getPath(),
      "ITEM_ROOTDIR", itemRootDir,
      "ITEM_FULLNAME", itemFullName,   // legacy, deprecated
      "ITEM_FULL_NAME", itemFullName.replace(':','$'))); // safe, see JENKINS-12251
}

代码示例来源:origin: jenkinsci/gitlab-plugin

private static String replaceMacros(Run<?, ?> build, TaskListener listener, String inputString) {
  String returnString = inputString;
  if (build != null && inputString != null) {
    try {
      Map<String, String> messageEnvVars = getEnvVars(build, listener);
      returnString = Util.replaceMacro(inputString, messageEnvVars);
    } catch (Exception e) {
      listener.getLogger().printf("Couldn't replace macros in message: %s%n", e.getMessage());
      LOGGER.log(Level.WARNING, "Couldn't replace macros in message", e);
    }
  }
  return returnString;
}

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

/**
 * Adds key value pairs as "-Dkey=value -Dkey=value ..." by parsing a given string using {@link Properties} with masking.
 *
 * @param prefix
 *      The '-D' portion of the example. Defaults to -D if null.
 * @param properties
 *      The persisted form of {@link Properties}. For example, "abc=def\nghi=jkl". Can be null, in which
 *      case this method becomes no-op.
 * @param vr
 *      {@link VariableResolver} to resolve variables in properties string.
 * @param propsToMask
 *      Set containing key names to mark as masked in the argument list. Key
 *      names that do not exist in the set will be added unmasked.
 * @since 1.378
 */
public ArgumentListBuilder addKeyValuePairsFromPropertyString(String prefix, String properties, VariableResolver<String> vr, Set<String> propsToMask) throws IOException {
  if(properties==null)    return this;
  properties = Util.replaceMacro(properties, propertiesGeneratingResolver(vr));
  for (Entry<Object,Object> entry : Util.loadProperties(properties).entrySet()) {
    addKeyValuePair(prefix, (String)entry.getKey(), entry.getValue().toString(), (propsToMask == null) ? false : propsToMask.contains(entry.getKey()));
  }
  return this;
}

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

Util.replaceMacro(entry.getValue(), resolver);

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

@Override
public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) {
  if (StringUtils.isEmpty(path)) {
    return null;
  }
  try {
    EnvVars env = build.getEnvironment(listener);
    String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver());
    targetPath = env.expand(targetPath);
    if (IOUtils.isAbsolute(targetPath)) {
      return new FilePath(new File(targetPath));
    } else {
      FilePath mrSettings = build.getModuleRoot().child(targetPath);
      FilePath wsSettings = build.getWorkspace().child(targetPath);
      try {
        if (!wsSettings.exists() && mrSettings.exists()) {
          wsSettings = mrSettings;
        }
      } catch (Exception e) {
        throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote());
      }
      return wsSettings;
    }
  } catch (Exception e) {
    throw new IllegalStateException("failed to prepare settings.xml");
  }
}

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

@Override
public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) {
  if (StringUtils.isEmpty(path)) {
    return null;
  }
  try {
    EnvVars env = build.getEnvironment(listener);
    String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver());
    targetPath = env.expand(targetPath);
    if (IOUtils.isAbsolute(targetPath)) {
      return new FilePath(new File(targetPath));
    } else {
      FilePath mrSettings = build.getModuleRoot().child(targetPath);
      FilePath wsSettings = build.getWorkspace().child(targetPath);
      try {
        if (!wsSettings.exists() && mrSettings.exists()) {
          wsSettings = mrSettings;
        }
      } catch (Exception e) {
        throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote());
      }
      return wsSettings;
    }
  } catch (Exception e) {
    throw new IllegalStateException("failed to prepare global settings.xml");
  }
}

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

try (InputStream in = url.openStream()) {
  String literal = IOUtils.toString(in,"UTF-8");
  rsp.getWriter().println(Util.replaceMacro(literal, Collections.singletonMap("rootURL",req.getContextPath())));

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

String targets = Util.replaceMacro(this.targets,vr);
targets = env.expand(targets);
String pom = env.expand(this.pom);

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Expands the variables in the given string by using environment variables represented in 'this'.
 */
public String expand(String s) {
  return Util.replaceMacro(s, this);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Resolves environment variables against each other.
 */
public static void resolve(Map<String, String> env) {
  for (Map.Entry<String,String> entry: env.entrySet()) {
    entry.setValue(Util.replaceMacro(entry.getValue(), env));
  }
}

代码示例来源:origin: jenkinsci/ghprb-plugin

public static String replaceMacros(Run<?, ?> build, TaskListener listener, String inputString) {
  String returnString = inputString;
  if (build != null && inputString != null) {
    try {
      Map<String, String> messageEnvVars = getEnvVars(build, listener);
      returnString = Util.replaceMacro(inputString, messageEnvVars);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Couldn't replace macros in message: ", e);
    }
  }
  return returnString;
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Replaces the occurrence of '$key' by <tt>properties.get('key')</tt>.
 *
 * <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: org.jvnet.hudson.main/hudson-core

/**
 * Performs a variable subsitution to the given text and return it.
 */
public String substitute(AbstractBuild<?,?> build, String text) {
  return Util.replaceMacro(text,createVariableResolver(build));
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Restricted(NoExternalUse.class)
public static String expandVariablesForDirectory(String base, String itemFullName, String itemRootDir) {
  return Util.replaceMacro(base, ImmutableMap.of(
      "JENKINS_HOME", Jenkins.getInstance().getRootDir().getPath(),
      "ITEM_ROOTDIR", itemRootDir,
      "ITEM_FULLNAME", itemFullName,   // legacy, deprecated
      "ITEM_FULL_NAME", itemFullName.replace(':','$'))); // safe, see JENKINS-12251
}

相关文章

微信公众号

最新文章

更多