001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2016 005 * Space Science and Engineering Center (SSEC) 006 * University of Wisconsin - Madison 007 * 1225 W. Dayton Street, Madison, WI 53706, USA 008 * https://www.ssec.wisc.edu/mcidas 009 * 010 * All Rights Reserved 011 * 012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 013 * some McIDAS-V source code is based on IDV and VisAD source code. 014 * 015 * McIDAS-V is free software; you can redistribute it and/or modify 016 * it under the terms of the GNU Lesser Public License as published by 017 * the Free Software Foundation; either version 3 of the License, or 018 * (at your option) any later version. 019 * 020 * McIDAS-V is distributed in the hope that it will be useful, 021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 023 * GNU Lesser Public License for more details. 024 * 025 * You should have received a copy of the GNU Lesser Public License 026 * along with this program. If not, see http://www.gnu.org/licenses. 027 */ 028 029package edu.wisc.ssec.mcidasv; 030 031import java.io.File; 032 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036import ucar.unidata.idv.IntegratedDataViewer; 037import ucar.unidata.idv.PluginManager; 038import ucar.unidata.util.IOUtil; 039import ucar.unidata.util.LogUtil; 040import ucar.unidata.util.ResourceCollection; 041 042import edu.wisc.ssec.mcidasv.servermanager.LocalEntryEditor; 043 044/** 045 * McIDAS-V extension to the IDV's {@link PluginManager}. The chief difference 046 * is that all requests for plugins are redirected to SSEC rather than Unidata. 047 */ 048public class McvPluginManager extends PluginManager { 049 050 private static final Logger logger = LoggerFactory.getLogger(LocalEntryEditor.class); 051 052 public McvPluginManager(IntegratedDataViewer idv) { 053 super(idv); 054 } 055 056 @Override protected void loadPlugins() throws Exception { 057 ResourceCollection rc = getResourceManager().getResources( 058 getResourceManager().RSC_PLUGINS); 059 060 for (int i = 0; i < rc.size(); i++) { 061 String path = rc.get(i).toString(); 062 if (!rc.isWritable(i)) 063 continue; 064 065 logger.debug("loadPlugins: path={}", path); 066 File pluginDir = new File(path); 067 File[] plugins = pluginDir.listFiles(); 068 if (plugins == null) 069 continue; 070 071 for (File plugin : plugins) { 072 String current = plugin.getName(); 073 if (current.startsWith(".tmp.") || current.endsWith(".deletethis")) 074 continue; 075 076 if (current.startsWith("http%3A%2F%2Fwww.unidata")) { 077 String newName = "http%3A%2F%2Fwww.ssec.wisc.edu%2Fmcidas%2Fsoftware%2Fv%2Fresources%2Fplugins%2F"+IOUtil.getFileTail(decode(current)); 078 logger.debug(" current={}", current); 079 logger.debug(" newName={}\n",newName); 080 File checkExisting = new File(plugin.getParent(), newName); 081 if (checkExisting.exists()) 082 logger.debug(" newName already exists..."); 083 else 084 logger.debug(" rename plugin..."); 085 } 086 } 087 } 088 super.loadPlugins(); 089 } 090 091 /** 092 * McIDAS-V overrides {@link PluginManager#removePlugin(File)} so that the 093 * user is given an update on their plugin situation. 094 */ 095 @Override public void removePlugin(File file) { 096 super.removePlugin(file); 097 LogUtil.userMessage("You must restart McIDAS-V to complete the removal of this plugin."); 098 } 099 100 /** 101 * Do not give the option to restart. Simply note that a restart is necessary at some point in the future. 102 */ 103 protected void notifyUser() { 104 LogUtil.userMessage("You must restart McIDAS-V to complete the installation of this plugin."); 105 return; 106 } 107}