Search in sources :

Example 1 with FileTextLineFilter

use of org.dbflute.helper.filesystem.FileTextLineFilter in project dbflute-core by dbflute.

the class DfRefreshMan method detectEclipseProjectName.

protected String detectEclipseProjectName() {
    // e.g.
    // PROJECT_ROOT
    // |-dbflute_maihamadb
    // |-mydbflute
    // |-...
    // |-.project
    final File projectFile = new File("../.project");
    if (!projectFile.exists()) {
        return null;
    }
    final Set<String> resultSet = new HashSet<String>();
    try {
        new FileTextIO().encodeAsUTF8().readFilteringLine(new FileInputStream(projectFile), new FileTextLineFilter() {

            boolean _found = false;

            public String filter(String line) {
                if (_found || !line.contains("<name>")) {
                    return null;
                }
                ScopeInfo scopeInfo = Srl.extractScopeFirst(line, "<name>", "</name>");
                if (scopeInfo == null) {
                    // basically no way, just in case
                    return null;
                }
                final String content = scopeInfo.getContent().trim();
                resultSet.add(content);
                _found = true;
                return null;
            }
        });
    } catch (FileNotFoundException ignored) {
        // no way because of already checked, just in case
        return null;
    }
    if (resultSet.isEmpty()) {
        _log.info("*The .project file exists but not found project name: " + projectFile);
        return null;
    }
    return resultSet.iterator().next();
}
Also used : FileTextIO(org.dbflute.helper.filesystem.FileTextIO) FileNotFoundException(java.io.FileNotFoundException) FileTextLineFilter(org.dbflute.helper.filesystem.FileTextLineFilter) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 2 with FileTextLineFilter

use of org.dbflute.helper.filesystem.FileTextLineFilter in project dbflute-core by dbflute.

the class DfUpgradeTask method doReplaceVersionScript.

protected void doReplaceVersionScript(final String upgradeVersion, FileTextIO textIO, String scriptPath, final String versionKeyword) {
    final File versionScript = new File(scriptPath);
    if (versionScript.exists()) {
        // basically true (just in case)
        _log.info("...Replacing version script: " + scriptPath);
        textIO.rewriteFilteringLine(scriptPath, new FileTextLineFilter() {

            public String filter(String line) {
                return filterVersionLine(upgradeVersion, line, versionKeyword);
            }
        });
    }
}
Also used : FileTextLineFilter(org.dbflute.helper.filesystem.FileTextLineFilter) File(java.io.File)

Aggregations

File (java.io.File)2 FileTextLineFilter (org.dbflute.helper.filesystem.FileTextLineFilter)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1 FileTextIO (org.dbflute.helper.filesystem.FileTextIO)1 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)1