Search in sources :

Example 41 with Matcher

use of java.util.regex.Matcher in project jetty.project by eclipse.

the class JavaVersion method parsePreJDK9.

private static JavaVersion parsePreJDK9(String version) {
    Matcher matcher = PRE_JDK9.matcher(version);
    if (!matcher.matches())
        throw new IllegalArgumentException("Invalid Java version " + version);
    int major = 1;
    int minor = Integer.parseInt(matcher.group(1));
    String microGroup = matcher.group(3);
    int micro = microGroup == null || microGroup.isEmpty() ? 0 : Integer.parseInt(microGroup);
    String updateGroup = matcher.group(5);
    int update = updateGroup == null || updateGroup.isEmpty() ? 0 : Integer.parseInt(updateGroup);
    String suffix = matcher.group(6);
    return new JavaVersion(version, minor, major, minor, micro, update, suffix);
}
Also used : Matcher(java.util.regex.Matcher)

Example 42 with Matcher

use of java.util.regex.Matcher in project jetty.project by eclipse.

the class Module method process.

public void process(BaseHome basehome) throws FileNotFoundException, IOException {
    Pattern section = Pattern.compile("\\s*\\[([^]]*)\\]\\s*");
    if (!FS.canReadFile(_path)) {
        StartLog.debug("Skipping read of missing file: %s", basehome.toShortForm(_path));
        return;
    }
    try (BufferedReader buf = Files.newBufferedReader(_path, StandardCharsets.UTF_8)) {
        String sectionType = "";
        String line;
        while ((line = buf.readLine()) != null) {
            line = line.trim();
            Matcher sectionMatcher = section.matcher(line);
            if (sectionMatcher.matches()) {
                sectionType = sectionMatcher.group(1).trim().toUpperCase(Locale.ENGLISH);
            } else {
                // blank lines and comments are valid for ini-template section
                if ((line.length() == 0) || line.startsWith("#")) {
                    // for the [ini-template] section
                    if ("INI-TEMPLATE".equals(sectionType)) {
                        _iniTemplate.add(line);
                    }
                } else {
                    switch(sectionType) {
                        case "":
                            // ignore (this would be entries before first section)
                            break;
                        case "DESCRIPTION":
                            _description.add(line);
                            break;
                        case "DEPEND":
                        case "DEPENDS":
                            _depends.add(line);
                            break;
                        case "FILE":
                        case "FILES":
                            _files.add(line);
                            break;
                        case "TAG":
                        case "TAGS":
                            _tags.add(line);
                            break;
                        // old name introduced in 9.2.x
                        case "DEFAULTS":
                        case // new name for 9.3+
                        "INI":
                            _defaultConfig.add(line);
                            break;
                        case "INI-TEMPLATE":
                            _iniTemplate.add(line);
                            break;
                        case "LIB":
                        case "LIBS":
                            _libs.add(line);
                            break;
                        case "LICENSE":
                        case "LICENSES":
                        case "LICENCE":
                        case "LICENCES":
                            _license.add(line);
                            break;
                        case "NAME":
                            StartLog.warn("Deprecated [name] used in %s", basehome.toShortForm(_path));
                            _provides.add(line);
                            break;
                        case "PROVIDE":
                        case "PROVIDES":
                            _provides.add(line);
                            break;
                        case "OPTIONAL":
                            _optional.add(line);
                            break;
                        case "EXEC":
                            _jvmArgs.add(line);
                            break;
                        case "VERSION":
                            if (version != null) {
                                throw new IOException("[version] already specified");
                            }
                            version = new Version(line);
                            break;
                        case "XML":
                            _xmls.add(line);
                            break;
                        default:
                            throw new IOException("Unrecognized module section: [" + sectionType + "]");
                    }
                }
            }
        }
    }
    if (version == null) {
        version = new Version(VERSION_UNSPECIFIED);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 43 with Matcher

use of java.util.regex.Matcher in project jetty.project by eclipse.

the class FruitDecoder method willDecode.

@Override
public boolean willDecode(String s) {
    if (s == null) {
        return false;
    }
    Pattern pat = Pattern.compile("([^|]*)|([^|]*)");
    Matcher mat = pat.matcher(s);
    return (mat.find());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 44 with Matcher

use of java.util.regex.Matcher in project jetty.project by eclipse.

the class BadDualDecoder method willDecode.

@Override
public boolean willDecode(String s) {
    if (s == null) {
        return false;
    }
    Pattern pat = Pattern.compile("([^|]*)|([^|]*)");
    Matcher mat = pat.matcher(s);
    return (mat.find());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 45 with Matcher

use of java.util.regex.Matcher in project jetty.project by eclipse.

the class BadDualDecoder method decode.

@Override
public Fruit decode(String s) throws DecodeException {
    Pattern pat = Pattern.compile("([^|]*)|([^|]*)");
    Matcher mat = pat.matcher(s);
    if (!mat.find()) {
        throw new DecodeException(s, "Unable to find Fruit reference encoded in text message");
    }
    Fruit fruit = new Fruit();
    fruit.name = mat.group(1);
    fruit.color = mat.group(2);
    return fruit;
}
Also used : Pattern(java.util.regex.Pattern) Fruit(org.eclipse.jetty.websocket.jsr356.samples.Fruit) Matcher(java.util.regex.Matcher) DecodeException(javax.websocket.DecodeException)

Aggregations

Matcher (java.util.regex.Matcher)12640 Pattern (java.util.regex.Pattern)5059 ArrayList (java.util.ArrayList)1525 IOException (java.io.IOException)913 HashMap (java.util.HashMap)575 File (java.io.File)490 Test (org.junit.Test)448 BufferedReader (java.io.BufferedReader)433 Map (java.util.Map)369 List (java.util.List)292 InputStreamReader (java.io.InputStreamReader)268 HashSet (java.util.HashSet)237 MalformedURLException (java.net.MalformedURLException)164 URL (java.net.URL)157 Date (java.util.Date)153 InputStream (java.io.InputStream)148 Field (java.lang.reflect.Field)130 ParseException (java.text.ParseException)130 PatternSyntaxException (java.util.regex.PatternSyntaxException)128 LinkedHashMap (java.util.LinkedHashMap)122