Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed 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.tapestry5;
Utility methods related to managing framework version numbers.
public class VersionUtils
{

    
Reads a version number from a properties file on the classpath. These files are generally created by Maven. For example, tapestry-core's properties file is META-INF/maven/org.apache.tapestry/tapestry-core/pom.properties. The Maven generated properties files include the artifact id and group id as well as the version.

The resource is located using the Thread's context class loader.

Parameters:
resourcePath the complete path to the resource, including a leading slash.
Returns:
the version number read from the properties file, or "UNKNOWN" if the version number is not present or the file can not be opened
    public static String readVersionNumber(String resourcePath)
    {
        String result = "UNKNOWN";
                resourcePath);
        if (stream != null)
        {
            Properties properties = new Properties();
            try
            {
                stream = new BufferedInputStream(stream);
                properties.load(stream);
            }
            catch (IOException ex)
            {
                // Just ignore it.
            }
            String version = properties.getProperty("version");
            // Since the file, if it exists, is created by Maven and will have the key, I can't see
            // how version would EVER be null, unless there's a problem reading the properties.
            if (version != nullresult = version;
        }
        return result;
    }
New to GrepCode? Check out our FAQ X