Java Path File Name nio inheritGwtModule(Path path, String inheritableModuleLogicalName)

Here you can find the source of inheritGwtModule(Path path, String inheritableModuleLogicalName)

Description

Inherit the specified module name in the provided GWT module descriptor.

License

Open Source License

Parameter

Parameter Description
path GWT module descriptor
inheritableModuleLogicalName logical name of the GWT module to inherit

Exception

Parameter Description

Declaration

public static void inheritGwtModule(Path path, String inheritableModuleLogicalName) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012-2015 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* w  w  w. j  a v a 2s  .  c  o  m*/
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;

import java.util.List;
import static java.nio.charset.StandardCharsets.UTF_8;

public class Main {
    /**
     * Inherit the specified module name in the provided GWT module descriptor.
     *
     * @param path
     *         GWT module descriptor
     * @param inheritableModuleLogicalName
     *         logical name of the GWT module to inherit
     * @throws java.io.IOException
     *         error occurred while reading or writing content of file
     */
    public static void inheritGwtModule(Path path, String inheritableModuleLogicalName) throws IOException {
        final String inheritsString = "    <inherits name='" + inheritableModuleLogicalName + "'/>";
        List<String> content = Files.readAllLines(path, UTF_8);
        // insert custom module as last 'inherits' entry
        int i = 0, lastInheritsLine = 0;
        for (String str : content) {
            i++;
            if (str.contains("<inherits")) {
                lastInheritsLine = i;
            }
        }
        content.add(lastInheritsLine, inheritsString);
        Files.write(path, content, UTF_8);
    }
}

Related

  1. getSimpleName(String path)
  2. getSolrCorePath(Path solrHome, String indexName)
  3. getSourceRoot(Path filePath, String pkgName)
  4. getTestDataPath(Class clazz, String name)
  5. getUniqueFileInDirectory(Path dir, String name)
  6. initializePath(String... envVarNames)
  7. isExecutableOnPath(String execName)
  8. isHiddenName(Path path)
  9. jobNameFromPath(Path path)