001/**
002 *
003 * Copyright 2020-2024 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack;
018
019import java.io.InputStream;
020import java.net.MalformedURLException;
021import java.net.URI;
022import java.net.URL;
023import java.util.logging.Logger;
024
025import org.jivesoftware.smack.util.FileUtils;
026
027public class Smack {
028
029    private static final Logger LOGGER = Logger.getLogger(Smack.class.getName());
030
031    private static final String SMACK_ORG = "org.jivesoftware";
032
033    public static final String SMACK_PACKAGE = SMACK_ORG + ".smack";
034
035    public static final URL BUG_REPORT_URL;
036
037    static {
038        try {
039            BUG_REPORT_URL = URI.create("https://discourse.igniterealtime.org/c/smack/smack-support/9").toURL();
040        } catch (MalformedURLException e) {
041            throw new ExceptionInInitializerError(e);
042        }
043    }
044
045    /**
046     * Returns the Smack version information, e.g."1.3.0".
047     *
048     * @return the Smack version information.
049     */
050    public static String getVersion() {
051        return SmackInitialization.SMACK_VERSION;
052    }
053
054    private static final String NOTICE_RESOURCE = SMACK_PACKAGE + "/NOTICE";
055
056    /**
057     * Get the stream of the NOTICE file of Smack.
058     * <p>
059     * This license of Smack requires that the contents of this NOTICE text file are shown "…within a display generated by
060     * the Derivative Works, if and wherever such third-party notices normally appear.".
061     * </p>
062     *
063     * @return the stream of the NOTICE file of Smack.
064     * @since 4.4.0
065     */
066    public static InputStream getNoticeStream() {
067        InputStream res = FileUtils.getInputStreamForClasspathFile(NOTICE_RESOURCE);
068        assert res != null;
069        return res;
070    }
071
072    public static void ensureInitialized() {
073        if (SmackConfiguration.isSmackInitialized()) {
074            return;
075        }
076
077        String version = getVersion();
078        LOGGER.finest("Smack " + version + " has been initialized");
079    }
080}