001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.runtime.about; 021 022import java.io.IOException; 023import java.io.InputStream; 024import java.util.List; 025import java.util.MissingResourceException; 026import java.util.Properties; 027import java.util.ResourceBundle; 028 029import org.apache.isis.core.commons.exceptions.IsisException; 030 031public class AboutIsis { 032 private static String applicationCopyrightNotice; 033 private static String applicationName; 034 private static String applicationVersion; 035 private static String frameworkName; 036 private static String frameworkVersion; 037 private static String logo; 038 private static String frameworkCopyright; 039 private static String frameworkCompileDate; 040 private static List<ComponentDetails> componentDetails; 041 042 static { 043 try { 044 final ResourceBundle bundle = ResourceBundle.getBundle("isis-version"); 045 logo = bundle.getString("framework.logo"); 046 frameworkVersion = bundle.getString("framework.version"); 047 frameworkName = bundle.getString("framework.name"); 048 frameworkCopyright = bundle.getString("framework.copyright"); 049 frameworkCompileDate = bundle.getString("framework.compile.date"); 050 } catch (final MissingResourceException ex) { 051 logo = "splash-logo"; 052 frameworkVersion = "${project.version}-r${buildNumber}"; 053 frameworkCopyright = "Copyright (c) 2010~2013 Apache Software Foundation"; 054 frameworkName = "${project.parent.name}"; 055 } 056 057 // NOT in use yet: frameworkVersion = findVersion(); 058 } 059 060 public static String findVersion() { 061 try { 062 final String moduleId = "org.apache.isis.plugins:dndviewer"; 063 final String module = moduleId.replace(":", "/"); 064 final InputStream resourceAsStream = AboutIsis.class.getClassLoader().getResourceAsStream("META-INF/maven/" + module + "/pom.properties"); 065 if (resourceAsStream == null) { 066 return "no version"; 067 } 068 final Properties p = new Properties(); 069 p.load(resourceAsStream); 070 final String version = p.getProperty("version"); 071 return version; 072 } catch (final IOException e) { 073 throw new IsisException(e); 074 } 075 076 } 077 078 public static String getApplicationCopyrightNotice() { 079 return applicationCopyrightNotice; 080 } 081 082 public static String getApplicationName() { 083 return applicationName; 084 } 085 086 public static String getApplicationVersion() { 087 return applicationVersion; 088 } 089 090 public static String getFrameworkCopyrightNotice() { 091 return select(frameworkCopyright, "Copyright Apache Software Foundation"); 092 } 093 094 public static String getFrameworkCompileDate() { 095 return frameworkCompileDate; 096 } 097 098 public static String getFrameworkName() { 099 return select(frameworkName, "Apache Isis"); 100 } 101 102 public static String getImageName() { 103 return select(logo, "splash-logo"); 104 } 105 106 public static String getFrameworkVersion() { 107 final String version = "Version " + select(frameworkVersion, "unreleased"); 108 /* 109 * NOT in use yet: for (ComponentDetails details : componentDetails) { 110 * version += "\n" + details.getName() + " " + details.getModule() + " " 111 * + details.getVersion(); } 112 */ 113 return version; 114 } 115 116 public static void main(final String[] args) { 117 System.out.println(getFrameworkName() + ", " + getFrameworkVersion()); 118 System.out.println(getFrameworkCopyrightNotice()); 119 } 120 121 private static String select(final String value, final String defaultValue) { 122 return value == null || value.startsWith("${") ? defaultValue : value; 123 } 124 125 public static void setApplicationCopyrightNotice(final String applicationCopyrightNotice) { 126 AboutIsis.applicationCopyrightNotice = applicationCopyrightNotice; 127 } 128 129 public static void setApplicationName(final String applicationName) { 130 AboutIsis.applicationName = applicationName; 131 } 132 133 public static void setApplicationVersion(final String applicationVersion) { 134 AboutIsis.applicationVersion = applicationVersion; 135 } 136 137 public static void setComponentDetails(final List<ComponentDetails> componentDetails) { 138 AboutIsis.componentDetails = componentDetails; 139 } 140 141}