You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/17 12:50:39 UTC
[21/50] [abbrv] incubator-taverna-osgi git commit: Removed dead code
Removed dead code
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/d8ab2401
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/d8ab2401
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/d8ab2401
Branch: refs/heads/master
Commit: d8ab24017fa187988ceba8a074f5956f5fc2afa3
Parents: 11552bc
Author: Christian-B <br...@cs.man.ac.uk>
Authored: Tue Jul 1 15:59:48 2014 +0100
Committer: Christian-B <br...@cs.man.ac.uk>
Committed: Tue Jul 1 15:59:48 2014 +0100
----------------------------------------------------------------------
.../impl/ApplicationConfigurationImpl.java | 266 -------------------
.../impl/ApplicationUserHome.java | 224 ----------------
.../impl/Log4JConfiguration.java | 161 -----------
3 files changed, 651 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d8ab2401/taverna-app-configuration-impl/impl/ApplicationConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/taverna-app-configuration-impl/impl/ApplicationConfigurationImpl.java b/taverna-app-configuration-impl/impl/ApplicationConfigurationImpl.java
deleted file mode 100644
index 7e9078e..0000000
--- a/taverna-app-configuration-impl/impl/ApplicationConfigurationImpl.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2007 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package uk.org.taverna.configuration.app.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.UUID;
-
-import org.apache.log4j.Logger;
-
-import uk.org.taverna.configuration.app.ApplicationConfiguration;
-
-/**
- * Represent the application config as it has been specified in {@value #PROPERTIES}. This
- * configuration specifies the application's name and title, etc.
- * <p>
- * An application would typically provide the {@value #PROPERTIES} file on the classpath under a
- * <code>conf</code> directory, or in a <code>conf</code> directory in the application's
- * distribution directory.
- *
- * @author Stian Soiland-Reyes
- * @author David Withers
- */
-public class ApplicationConfigurationImpl implements ApplicationConfiguration {
-
- private static final Logger logger = Logger.getLogger(ApplicationConfigurationImpl.class);
-
- private static final String UNKNOWN_APPLICATION = "unknownApplication-"
- + UUID.randomUUID().toString();
-
- public static final String PREFIX = "taverna.app.";
- public static final String APP_NAME = PREFIX + "name";
- public static final String APP_TITLE = PREFIX + "title";
- public static final String APP_HOME = PREFIX + "home";
- public static final String APP_STARTUP = PREFIX + "startup";
-
- public static final String PROPERTIES = PREFIX + "properties";
-
- private Properties properties;
-
- private File startupDir;
- private File homeDir;
-
- public ApplicationConfigurationImpl() {
- }
-
- @Override
- public String getName() {
- String name = (String) getProperties().get(APP_NAME);
- if (name == null) {
- logger.error("ApplicationConfig could not determine application name, using "
- + UNKNOWN_APPLICATION);
- return UNKNOWN_APPLICATION;
- }
- return name;
- }
-
- @Override
- public String getTitle() {
- String title = (String) getProperties().get(APP_TITLE);
- if (title == null) {
- return getName();
- }
- return title;
- }
-
- @Override
- public File getStartupDir() {
- if (startupDir == null) {
- String startupDirName = System.getProperty(APP_STARTUP);
- if (startupDirName != null) {
- startupDir = new File(startupDirName).getAbsoluteFile();
- }
- }
- return startupDir;
- }
-
- @Override
- public synchronized File getApplicationHomeDir() {
- if (homeDir == null) {
- if (getName().equals(ApplicationConfigurationImpl.UNKNOWN_APPLICATION)) {
- try {
- // Make a temporary home directory as a backup
- homeDir = File.createTempFile(getName(), "home");
- homeDir.delete();
- homeDir.mkdirs();
- } catch (IOException e) {
- throw new IllegalStateException("Can't create temporary application home", e);
- }
- logger.warn("Could not determine application's user home,"
- + " using temporary dir " + homeDir);
- } else {
- homeDir = new ApplicationUserHome(getName()).getAppUserHome();
- }
- if (homeDir == null || !homeDir.isDirectory()) {
- throw new IllegalStateException("Could not create application home directory "
- + homeDir);
- }
- }
- return homeDir;
- }
-
- @Override
- public File getPluginsDir() {
- File pluginsDir = new File(getApplicationHomeDir(), PLUGINS_DIR);
- pluginsDir.mkdirs();
- if (!pluginsDir.isDirectory()) {
- throw new IllegalStateException("Could not create plugins directory " + pluginsDir);
- }
- return pluginsDir;
- }
-
- @Override
- public File getDefaultPluginsDir() {
- File defaultPluginsDir = new File(getStartupDir(), PLUGINS_DIR);
- if (!defaultPluginsDir.isDirectory()) {
- throw new IllegalStateException("Could not find default plugins directory "
- + defaultPluginsDir);
- }
- return defaultPluginsDir;
- }
-
- @Override
- public File getLogFile() {
- return new File(getLogDir(), getName() + ".log");
- }
-
- @Override
- public File getLogDir() {
- File logDir = new File(getApplicationHomeDir(), "logs");
- logDir.mkdirs();
- if (!logDir.isDirectory()) {
- throw new IllegalStateException("Could not create log directory " + logDir);
- }
- return logDir;
- }
-
- @Override
- public synchronized Properties getProperties() {
- if (properties == null) {
- properties = loadProperties(PROPERTIES);
- // Fill in overrides from system properties
- for (Entry<Object, Object> property : System.getProperties().entrySet()) {
- String key = (String) property.getKey();
- if (key.startsWith(PREFIX)) {
- properties.put(key, property.getValue());
- }
- }
- }
- return properties;
- }
-
- private void findInClassLoader(List<URI> configs, ClassLoader classLoader, String resourcePath) {
- Enumeration<URL> resources;
- try {
- resources = classLoader.getResources(resourcePath);
- } catch (IOException ex) {
- System.err.println("Error looking for " + resourcePath + " in " + classLoader);
- ex.printStackTrace();
- return;
- }
- while (resources.hasMoreElements()) {
- URL configURL = resources.nextElement();
- try {
- configs.add(configURL.toURI());
- } catch (URISyntaxException ex) {
- throw new RuntimeException("Invalid URL from getResource(): " + configURL, ex);
- }
- }
- }
-
- /**
- * Attempt to load application properties from propertyFileName.
- * <p>
- * Will attempt to load a property file from the locations below. The first non-empty properties
- * successfully loaded will be returned.
- * <ol>
- * <li>$startup/conf/$resourceName</li>
- * <li>$startup/$resourceName</li>
- * <li>$contextClassPath/conf/$resourceName</li>
- * <li>$contextClassPath/$resourceName</li>
- * <li>$classpath/conf/$resourceName</li>
- * <li>$classpath/$resourceName</li>
- * </ol>
- * <p>
- * Where <code>$startup</code> is this application's startup directory as determined by
- * {@link #getStartupDir()}, and <code>$contextClassPath</code> means a search using
- * {@link ClassLoader#getResources(String)} from the classloader returned by
- * {@link Thread#getContextClassLoader()} and then again <code>$classpath</code> for the
- * classloader of {@link #getClass()} of this instance.
- * </p>
- * <p>
- * If none of these sources could find a non-empty property file, a warning is logged, and an
- * empty {@link Properties} instance is returned.
- *
- * @param resourceName
- * Relative filename of property file
- *
- * @return Loaded or empty {@link Properties} instance.
- */
- protected Properties loadProperties(String resourceName) {
- // Ordered list of config locations to attempt to load
- // properties from
- List<URI> configs = new ArrayList<URI>();
-
- File startupDir = getStartupDir();
- if (startupDir != null) {
- configs.add(startupDir.toURI().resolve(CONF_DIR).resolve(resourceName));
- configs.add(startupDir.toURI().resolve(resourceName));
- }
-
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- findInClassLoader(configs, contextClassLoader, CONF_DIR + resourceName);
- findInClassLoader(configs, contextClassLoader, resourceName);
-
- findInClassLoader(configs, getClass().getClassLoader(), CONF_DIR + resourceName);
- findInClassLoader(configs, getClass().getClassLoader(), resourceName);
-
- Properties loadedProps = new Properties();
- for (URI config : configs) {
- try {
- InputStream inputStream = config.toURL().openStream();
- loadedProps.load(inputStream);
- } catch (MalformedURLException ex) {
- throw new RuntimeException("Invalid URL from URI: " + config, ex);
- } catch (IOException ex) {
- continue; // Probably not found/access denied
- }
- if (!loadedProps.isEmpty()) {
- logger.debug("Loaded " + resourceName + " from " + config);
- return loadedProps;
- }
- }
- logger.debug("Could not find application properties file " + resourceName);
- return loadedProps;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d8ab2401/taverna-app-configuration-impl/impl/ApplicationUserHome.java
----------------------------------------------------------------------
diff --git a/taverna-app-configuration-impl/impl/ApplicationUserHome.java b/taverna-app-configuration-impl/impl/ApplicationUserHome.java
deleted file mode 100644
index 896294d..0000000
--- a/taverna-app-configuration-impl/impl/ApplicationUserHome.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2007 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package uk.org.taverna.configuration.app.impl;
-
-import java.io.File;
-
-import org.apache.log4j.Logger;
-
-/**
- * Find and create an application's user directory according to operating system
- * standards.
- * <p>
- * For example for the application "MyApp" this class will be able to find
- * <code>$HOME/.myapp</code> on Linux or
- * <code>C:\Document and settings\MyUsername\Application Data\MyApplication</code>
- * on Windows XP.
- *
- * @author Stian Soiland-Reyes
- * @author Stuart Owen
- *
- */
-public class ApplicationUserHome {
-
- private final String defaultApplicationHome;
-
- private final String applicationName;
-
- private File homeDir;
-
- private static Logger logger = Logger.getLogger(ApplicationUserHome.class);
-
- /**
- * Initialise with the name of the application.
- *
- * @param applicationName
- * This name will be used as a template for creating the
- * application home directory (but might be transcribed, for
- * instance to lowercase). It is generally recommended, but not
- * required - that this name does not contain spaces or any
- * special international/Unicode characters.
- */
- public ApplicationUserHome(String applicationName) {
- this(applicationName, null);
- }
-
- /**
- * Initialise with the name of the application and a default application
- * home.
- *
- * @param applicationName
- * This name will be used as a template for creating the
- * application home directory (but might be transcribed, for
- * instance to lowercase). It is generally recommended, but not
- * required - that this name does not contain spaces or any
- * special international/Unicode characters.
- * @param defaultApplicationHome
- * The full path to the default home directory. If this string is
- * not <code>null</code>, then a {@link File} based on this
- * directory will always be returned by
- * {@link #getDefaultApplicationHome()} - otherwise the normal
- * operating system logic is used to determine the application's
- * home directory.
- */
- public ApplicationUserHome(String applicationName,
- String defaultApplicationHome) {
- this.applicationName = applicationName;
- this.defaultApplicationHome = defaultApplicationHome;
- }
-
- /**
- * Find (and if necessary create) the user's application directory,
- * according to operating system standards. The resolved directory is then
- * returned as a {@link File} object.
- * <p>
- * The application's name as defined by {@link #getApplicationName()} is
- * used as a basis for naming the directory of the application's user
- * directory, but the directory name might for instance be transformed to
- * lowercase.
- * <p>
- * If {@link #getDefaultApplicationHome()} returns a non-null value, the
- * directory specified by that path will be used instead of the operation
- * system specific directory. The directory will be created if needed.
- * <p>
- * If any exception occurs (such as out of diskspace), <code>null</code>
- * will be returned.
- *
- * <p>
- * On Windows XP, this will typically be something like:
- *
- * <pre>
- * C:\Document and settings\MyUsername\Application Data\MyApplication
- * </pre>
- *
- * and on Windows Vista it would be something like:
- *
- * <pre>
- * C:\Users\MyUsername\Application Data\MyApplication
- * </pre>
- *
- * while on Mac OS X it will be something like:
- *
- * <pre>
- * /Users/MyUsername/Library/Application Support/MyApplication
- * </pre>
- *
- * All other OS'es are assumed to be UNIX-alike, returning something like:
- *
- * <pre>
- * /user/myusername/.myapplication
- * </pre>
- *
- * <p>
- * If the directory does not already exist, it will be created.
- * </p>
- *
- * @return An {@link File} referring to an existing directory for
- * user-specific configuration etc. for the given application.
- */
- public synchronized File getAppUserHome() {
- if (homeDir != null) {
- return homeDir;
- }
- File appHome;
- String applicationHome = getDefaultApplicationHome();
- if (applicationHome != null) {
- appHome = new File(applicationHome);
- } else {
- if (getApplicationName() == null) {
- logger.warn("Unknown application name");
- return null;
- }
- File home = new File(System.getProperty("user.home"));
- if (!home.isDirectory()) {
- logger.error("User home not a valid directory: " + home);
- return null;
- }
- String os = System.getProperty("os.name");
- // logger.debug("OS is " + os);
- if (os.equals("Mac OS X")) {
- File libDir = new File(home, "Library/Application Support");
- libDir.mkdirs();
- appHome = new File(libDir, getApplicationName());
- } else if (os.startsWith("Windows")) {
- String APPDATA = System.getenv("APPDATA");
- File appData = null;
- if (APPDATA != null) {
- appData = new File(APPDATA);
- }
- if (appData != null && appData.isDirectory()) {
- appHome = new File(appData, getApplicationName());
- } else {
- logger.warn("Could not find %APPDATA%: " + APPDATA);
- appHome = new File(home, getApplicationName());
- }
- } else {
- // We'll assume UNIX style is OK
- appHome = new File(home, "."
- + getApplicationName().toLowerCase());
- }
- }
- if (!appHome.exists()) {
- if (appHome.mkdir()) {
- logger.info("Created " + appHome);
- } else {
- logger.error("Could not create " + appHome);
- return null;
- }
- }
- if (!appHome.isDirectory()) {
- logger.error("User home not a valid directory: " + appHome);
- return null;
- }
- this.homeDir = appHome.getAbsoluteFile();
- return this.homeDir;
- }
-
- /**
- * The application's name. This name will be used as a template for creating
- * the application home directory (but might be transcribed, for instance to
- * lowercase). It is generally recommended, but not required - that this
- * name does not contain spaces or any special international/Unicode
- * characters.
- *
- * @return The application's name.
- *
- */
- public String getApplicationName() {
- return applicationName;
- }
-
- /**
- * The full path to the default home directory. If this string is not
- * <code>null</code>, then a {@link File} based on this directory will
- * always be returned by {@link #getDefaultApplicationHome()} - otherwise
- * the normal operating system logic is used to determine the application's
- * home directory.
- *
- * @return The full path to the application's home directory, or
- * <code>null</code> if the operation system specific logic is to
- * be used.
- */
- public String getDefaultApplicationHome() {
- return defaultApplicationHome;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d8ab2401/taverna-app-configuration-impl/impl/Log4JConfiguration.java
----------------------------------------------------------------------
diff --git a/taverna-app-configuration-impl/impl/Log4JConfiguration.java b/taverna-app-configuration-impl/impl/Log4JConfiguration.java
deleted file mode 100644
index cdd2c2c..0000000
--- a/taverna-app-configuration-impl/impl/Log4JConfiguration.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2007 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package uk.org.taverna.configuration.app.impl;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.PropertyConfigurator;
-import org.apache.log4j.RollingFileAppender;
-
-import uk.org.taverna.configuration.app.ApplicationConfiguration;
-
-public class Log4JConfiguration {
- public final static String LOG4J_PROPERTIES = "log4j.properties";
-
- private static boolean log4jConfigured = false;
-
- private ApplicationConfiguration applicationConfiguration;
-
- private Properties properties ;
-
- protected Log4JConfiguration() {
- prepareLog4J();
- }
-
- public void prepareLog4J() {
- if (!log4jConfigured) {
- Properties log4jProperties = getLogProperties();
- if (log4jProperties != null && ! log4jProperties.isEmpty()) {
- LogManager.resetConfiguration();
- PropertyConfigurator.configure(log4jProperties);
- }
-
- String logFilePath = applicationConfiguration.getLogFile().getAbsolutePath();
- PatternLayout layout = new PatternLayout("%-5p %d{ISO8601} (%c:%L) - %m%n");
-
- // Add file appender
- RollingFileAppender appender;
- try {
- appender = new RollingFileAppender(layout, logFilePath);
- appender.setMaxFileSize("1MB");
- appender.setEncoding("UTF-8");
- appender.setMaxBackupIndex(4);
- // Let root logger decide level
- appender.setThreshold(Level.ALL);
- LogManager.getRootLogger().addAppender(appender);
- } catch (IOException e) {
- System.err.println("Could not log to " + logFilePath);
- }
-
- log4jConfigured = true;
- }
- }
-
- /**
- * Initialises and provides access to the list of Properties.
- * @return
- */
- public Properties getLogProperties() {
- if (properties == null) {
- InputStream is = getLogPropertiesInputStream();
- if (is != null) {
- try {
- properties = new Properties();
- properties.load(is);
-// properties.putAll(System.getProperties());
- } catch (IOException e) {
- errorLog("An error occurred trying to load the " + LOG4J_PROPERTIES + " file",e);
- }
- }
- }
- return properties;
- }
-
- /**
- * Return an input stream to the configuration file, or null if it can't be found
- * @return
- */
- private InputStream getLogPropertiesInputStream() {
- InputStream result = null;
- File propertiesFile = getLogPropertiesFile();
- if (propertiesFile!=null) {
- try {
- result=new FileInputStream(propertiesFile);
- } catch (FileNotFoundException e) {
- errorLog("Unable to find "+LOG4J_PROPERTIES,e);
- }
- }
- else {
- errorLog("Unable to determine file for "+LOG4J_PROPERTIES,null);
- }
- return result;
- }
-
- /**
- * Returns a File object to the configuration file or null if it cannot be found.
- *
- * @return
- */
- private File getLogPropertiesFile() {
- File home = applicationConfiguration.getApplicationHomeDir();
- File startup = applicationConfiguration.getStartupDir();
- File result=null;
- if (home!=null) {
- File file = new File(new File(home, ApplicationConfiguration.CONF_DIR), LOG4J_PROPERTIES);
- if (file.exists()) {
- result=file;
- }
- }
- if (result==null && startup!=null) {
- File file = new File(new File(startup, ApplicationConfiguration.CONF_DIR), LOG4J_PROPERTIES);
- if (file.exists()) {
- result=file;
- }
- }
- return result;
- }
-
- private void errorLog(String message, Throwable exception) {
- System.out.println(message);
- if (exception!=null) {
- exception.printStackTrace();
- }
-
- }
-
- /**
- * Sets the applicationConfiguration.
- *
- * @param applicationConfiguration the new value of applicationConfiguration
- */
- public void setApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
- this.applicationConfiguration = applicationConfiguration;
- }
-
-}