OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 151
Line 48... Line 48...
48
        }
48
        }
49
        return res;
49
        return res;
50
    }
50
    }
51
 
51
 
52
    // match placeholder $Rev$ fixed length $Rev:: $ and of course with value $Rev: 12 $
52
    // match placeholder $Rev$ fixed length $Rev:: $ and of course with value $Rev: 12 $
-
 
53
    // don't require to match to the end to allow callers to only know the start of the substitute
-
 
54
    // and to not bother with the pattern
53
    private static final Pattern KEYWORD_PATTERN = Pattern.compile("^\\$\\p{Alpha}+:{0,2}\\p{Blank}*(.*?)\\p{Blank}*\\$$");
55
    private static final Pattern KEYWORD_PATTERN = Pattern.compile("^\\$\\p{Alpha}+:{0,2}\\p{Blank}*(.*?)\\p{Blank}*\\$");
54
 
56
 
55
    /**
57
    /**
56
     * Return the value of the svn keyword. E.g. use with
58
     * Return the value of the subversion keyword. E.g. use with
57
     * <code>private static final String REV = getKeywordValue("$Rev$")</code> (don't forget to
59
     * <code>private static final String REV = getKeywordValue("$Rev$")</code> (don't forget to
58
     * <code>svn propset svn:keywords</code>).
60
     * <code>svn propset svn:keywords</code>).
59
     * 
61
     * 
60
     * @param substitute the svn substitute, e.g. "$Rev: 12 $".
62
     * @param substitute the svn substitute, trailing characters not part of the keyword will be
-
 
63
     *        ignored, e.g. "$Rev: 12 $ other chars".
61
     * @return the value, empty string if none, e.g. "12".
64
     * @return the value, empty string if none, e.g. "12".
62
     * @throws IllegalArgumentException if substitute is not valid.
65
     * @throws IllegalArgumentException if substitute is not valid.
63
     */
66
     */
64
    public static String getKeywordValue(String substitute) throws IllegalArgumentException {
67
    public static String getKeywordValue(String substitute) throws IllegalArgumentException {
65
        final Matcher matcher = KEYWORD_PATTERN.matcher(substitute);
68
        final Matcher matcher = KEYWORD_PATTERN.matcher(substitute);
66
        if (!matcher.matches())
69
        if (!matcher.find())
67
            throw new IllegalArgumentException("SVN format not recognized");
70
            throw new IllegalArgumentException("SVN format not recognized");
68
 
71
 
69
        return matcher.group(1);
72
        return matcher.group(1);
70
    }
73
    }
71
}
74
}