brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geomacy <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #740: New versioning rules prep
Date Tue, 27 Jun 2017 16:06:35 GMT
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/740#discussion_r124314422
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
---
    @@ -0,0 +1,188 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.text;
    +
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import com.google.common.base.Preconditions;
    +
    +/** Utilities for parsing and working with versions following the recommended Brooklyn
scheme,
    + * following <code>major.minor.patch-qualifier</code> syntax,
    + * with support for mapping to OSGi. 
    + * <p>
    + * See tests for examples, {@link VersionComparator} for more notes, and its tests for
more examples.
    + */
    +public class BrooklynVersionSyntax {
    +
    +    private static final String USABLE_REGEX = "[^:\\s/\\\\]+";
    +
    +    private final static String OSGI_TOKEN_CHARS = "A-Za-z0-9_-";
    +    private final static String OSGI_TOKEN_REGEX = "[" + OSGI_TOKEN_CHARS + "]+";
    +    private final static String NUMBER = "[0-9]+";
    +    private final static String QUALIFIER = OSGI_TOKEN_REGEX;
    +    
    +    public final static String VALID_OSGI_VERSION_REGEX = 
    +        NUMBER + 
    +            "(" + "\\." + NUMBER +  
    +                "(" + "\\." + NUMBER +  
    +                    "(" + "\\." + QUALIFIER +  
    +                    ")?" +
    +                ")?" +
    +            ")?";
    +    
    +    public final static String GOOD_BROOKLYN_VERSION_REGEX = 
    +        NUMBER + 
    +            "(" + "\\." + NUMBER +  
    +                "(" + "\\." + NUMBER +  
    +                    "(" + "-" + QUALIFIER +  
    +                    ")?" +
    +                ")?" +
    +            ")?";
    +    
    +    private static boolean isUsable(String candidate) {
    +        return candidate!=null && candidate.matches(USABLE_REGEX);
    +    }
    +    
    +    /** 
    +     * For versions we currently work with any non-empty string that does not contain
a ':' or whitespace.
    +     * However we discourage things that are not OSGi versions; see {@link #isValidOsgiVersion(String)}.

    +     * In some places (eg bundles) the use of OSGi version syntax may be enforced.  
    +     */
    +    public static boolean isUsableVersion(String candidate) {
    +        return isUsable(candidate);
    +    }
    +    
    +    /** True if the argument matches the Brooklyn version syntax, 
    +     * <code>MAJOR.MINOR.POINT-QUALIFIER</code> or part thereof (not ending
in a period though),
    +     * where the first three are whole numbers and the final piece is any valid OSGi
token
    +     * (something satisfying {@link #isGoodTypeName(String)} with no periods).
    +     * See also {@link #isValidOsgiVersion(String)} and note this _requires_ a different
separator to OSGi.
    +     */
    +    public static boolean isGoodBrooklynVersion(String candidate) {
    +        return candidate!=null && candidate.matches(GOOD_BROOKLYN_VERSION_REGEX);
    +    }
    +    
    +    /** True if the argument matches the OSGi version spec, of the form 
    +     * <code>MAJOR.MINOR.POINT.QUALIFIER</code> or part thereof (not ending
in a period though),
    +     * where the first three are whole numbers and the final piece is any valid OSGi
token
    +     * (something satisfying {@link #isGoodTypeName(String)} with no periods).
    +     * See also {@link #isGoodVersion(String)}.
    --- End diff --
    
    `isGoodVersion` no longer exists


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message