Search in sources :

Example 1 with ReplaceTokens

use of org.apache.tools.ant.filters.ReplaceTokens in project eclipse.pde by eclipse-pde.

the class Utils method transferAndReplace.

/**
 * Transfer the contents of resource into the destination IFile. During the
 * transfer, replace all instances of "@replaceTag@" with "replaceString"
 *
 * @param resource
 *            - input URL
 * @param destination
 *            - IFile destination
 * @param replacements
 *            - map of tokens and values to replaces, file should contain
 *            "@replaceTag@"
 * @throws IOException
 * @throws CoreException
 */
public static void transferAndReplace(URL resource, IFile destination, Map<String, String> replacements) throws IOException, CoreException {
    Reader reader = new InputStreamReader(new BufferedInputStream(resource.openStream()));
    final ReplaceTokens replaces = new ReplaceTokens(reader);
    for (String replaceTag : replacements.keySet()) {
        String replaceString = replacements.get(replaceTag);
        ReplaceTokens.Token token = new ReplaceTokens.Token();
        token.setKey(replaceTag);
        token.setValue(replaceString);
        replaces.addConfiguredToken(token);
    }
    try (ReaderInputStream inputStream = new ReaderInputStream(replaces)) {
        destination.create(inputStream, true, null);
    }
}
Also used : ReaderInputStream(org.apache.tools.ant.util.ReaderInputStream) ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens)

Example 2 with ReplaceTokens

use of org.apache.tools.ant.filters.ReplaceTokens in project cargo by codehaus-cargo.

the class Jo1xStandaloneLocalConfiguration method createWebappToken.

/**
 * Create {@link ReplaceTokens} for the deployed webapps.
 *
 * @return tokens
 * @throws MalformedURLException if the document base cannot be determined
 */
private ReplaceTokens createWebappToken() throws MalformedURLException {
    ReplaceTokens.Token tokenWebApps = new ReplaceTokens.Token();
    tokenWebApps.setKey(TOKEN_KEY_WEBAPP);
    StringBuilder keyWebApps = new StringBuilder();
    for (Deployable deployable : getDeployables()) {
        if (deployable.getType() == DeployableType.WAR) {
            WAR war = (WAR) deployable;
            // This is what we need to generate:
            // <hostname>.webapp.<webapp-name>.mapping=...
            // <hostname>.webapp.<webapp-name>.docbase=...
            final String webappName = war.getContext().replace('.', '_').replace('=', '_');
            String mapping = war.getContext();
            if (mapping == null) {
                mapping = "";
            } else if ("/".equals(mapping)) {
                mapping = "";
            } else if (!mapping.startsWith("/") && !mapping.isEmpty()) {
                mapping = "/" + mapping;
            }
            String docbase = getFileHandler().getURL(war.getFile());
            if (war.isExpanded()) {
                docbase += "/";
            }
            keyWebApps.append("# CARGO! Context: " + war.getContext() + " File: " + war.getFile() + LINE_SEPARATOR);
            keyWebApps.append("host.webapp." + webappName + ".mapping=" + mapping + LINE_SEPARATOR);
            keyWebApps.append("host.webapp." + webappName + ".docbase=" + docbase + LINE_SEPARATOR);
            keyWebApps.append(LINE_SEPARATOR);
        }
    }
    // the Ant filtering code fails.
    if (keyWebApps.length() == 0) {
        keyWebApps.append(" ");
    }
    tokenWebApps.setValue(keyWebApps.toString());
    ReplaceTokens replaceWebApps = new ReplaceTokens();
    replaceWebApps.addConfiguredToken(tokenWebApps);
    return replaceWebApps;
}
Also used : Deployable(org.codehaus.cargo.container.deployable.Deployable) WAR(org.codehaus.cargo.container.deployable.WAR) ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens)

Example 3 with ReplaceTokens

use of org.apache.tools.ant.filters.ReplaceTokens in project cargo by codehaus-cargo.

the class Jo1xStandaloneLocalConfiguration method createWarDirToken.

/**
 * Creates tokens for the hotdeployment war dir.
 *
 * @return wardir token
 */
private ReplaceTokens createWarDirToken() {
    ReplaceTokens.Token tokenWarDir = new ReplaceTokens.Token();
    tokenWarDir.setKey(TOKEN_KEY_WAR_DIR);
    tokenWarDir.setValue(new File(getHome(), "webapp/host").toString());
    ReplaceTokens replaceWarDir = new ReplaceTokens();
    replaceWarDir.addConfiguredToken(tokenWarDir);
    return replaceWarDir;
}
Also used : ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens) File(java.io.File)

Example 4 with ReplaceTokens

use of org.apache.tools.ant.filters.ReplaceTokens in project cargo by codehaus-cargo.

the class Jo1xStandaloneLocalConfiguration method createLogLevelToken.

/**
 * Creates tokens for the loglevel.
 *
 * @return loglevel token
 */
private ReplaceTokens createLogLevelToken() {
    ReplaceTokens.Token tokenLogLevel = new ReplaceTokens.Token();
    tokenLogLevel.setKey(TOKEN_KEY_LOGLEVEL);
    String logLevel = getPropertyValue(GeneralPropertySet.LOGGING);
    String joLogLevel;
    if (LoggingLevel.LOW.equalsLevel(logLevel)) {
        joLogLevel = "1";
    } else if (LoggingLevel.HIGH.equalsLevel(logLevel)) {
        joLogLevel = "5";
    } else {
        joLogLevel = "2";
    }
    tokenLogLevel.setValue(joLogLevel);
    ReplaceTokens replacePort = new ReplaceTokens();
    replacePort.addConfiguredToken(tokenLogLevel);
    return replacePort;
}
Also used : ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens)

Example 5 with ReplaceTokens

use of org.apache.tools.ant.filters.ReplaceTokens in project cargo by codehaus-cargo.

the class JRun4xFilterChain method init.

/**
 * Initializes the {@link ReplaceTokens}s used in this {@link FilterChain}.
 */
private void init() {
    ReplaceTokens jrunTokens = new ReplaceTokens();
    jrunTokens.addConfiguredToken(createServerNameToken());
    jrunTokens.addConfiguredToken(createPortToken());
    jrunTokens.addConfiguredToken(createLoggingToken());
    jrunTokens.addConfiguredToken(createUserToken());
    jrunTokens.addConfiguredToken(createRmiPortToken());
    this.addReplaceTokens(jrunTokens);
    this.addReplaceTokens(createJvmConfigTokens());
}
Also used : ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens)

Aggregations

ReplaceTokens (org.apache.tools.ant.filters.ReplaceTokens)11 File (java.io.File)2 Deployable (org.codehaus.cargo.container.deployable.Deployable)2 WAR (org.codehaus.cargo.container.deployable.WAR)2 Token (org.apache.tools.ant.filters.ReplaceTokens.Token)1 FilterChain (org.apache.tools.ant.types.FilterChain)1 ReaderInputStream (org.apache.tools.ant.util.ReaderInputStream)1 EAR (org.codehaus.cargo.container.deployable.EAR)1