|
Java example source code file (Version.java)
The Version.java Java example source code
/*
* Copyright 2013 The Netty Project
*
* The Netty Project 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 io.netty.util;
import io.netty.util.internal.PlatformDependent;
import java.io.InputStream;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
/**
* Retrieves the version information of available Netty artifacts.
* <p>
* This class retrieves the version information from {@code META-INF/io.netty.versions.properties}, which is
* generated in build time. Note that it may not be possible to retrieve the information completely, depending on
* your environment, such as the specified {@link ClassLoader}, the current {@link SecurityManager}.
* </p>
*/
public final class Version {
private static final String PROP_VERSION = ".version";
private static final String PROP_BUILD_DATE = ".buildDate";
private static final String PROP_COMMIT_DATE = ".commitDate";
private static final String PROP_SHORT_COMMIT_HASH = ".shortCommitHash";
private static final String PROP_LONG_COMMIT_HASH = ".longCommitHash";
private static final String PROP_REPO_STATUS = ".repoStatus";
/**
* Retrieves the version information of Netty artifacts using the current
* {@linkplain Thread#getContextClassLoader() context class loader}.
*
* @return A {@link Map} whose keys are Maven artifact IDs and whose values are {@link Version}s
*/
public static Map<String, Version> identify() {
return identify(null);
}
/**
* Retrieves the version information of Netty artifacts using the specified {@link ClassLoader}.
*
* @return A {@link Map} whose keys are Maven artifact IDs and whose values are {@link Version}s
*/
public static Map<String, Version> identify(ClassLoader classLoader) {
if (classLoader == null) {
classLoader = PlatformDependent.getContextClassLoader();
}
// Collect all properties.
Properties props = new Properties();
try {
Enumeration<URL> resources = classLoader.getResources("META-INF/io.netty.versions.properties");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
InputStream in = url.openStream();
try {
props.load(in);
} finally {
try {
in.close();
} catch (Exception ignore) {
// Ignore.
}
}
}
} catch (Exception ignore) {
// Not critical. Just ignore.
}
// Collect all artifactIds.
Set<String> artifactIds = new HashSet
Other Java examples (source code examples)Here is a short list of links related to this Java Version.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.