001 /*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2013
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
029 package edu.wisc.ssec.mcidasv;
030
031 import java.io.File;
032 import java.util.ArrayList;
033 import java.util.List;
034
035 import javax.swing.JLabel;
036
037 import org.slf4j.Logger;
038 import org.slf4j.LoggerFactory;
039
040 import edu.wisc.ssec.mcidasv.servermanager.LocalEntryEditor;
041
042 import ucar.unidata.idv.IntegratedDataViewer;
043 import ucar.unidata.idv.PluginManager;
044 import ucar.unidata.util.GuiUtils;
045 import ucar.unidata.util.IOUtil;
046 import ucar.unidata.util.LogUtil;
047 import ucar.unidata.util.ResourceCollection;
048
049 public class McvPluginManager extends PluginManager {
050
051 private static final Logger logger = LoggerFactory.getLogger(LocalEntryEditor.class);
052
053 public McvPluginManager(IntegratedDataViewer idv) {
054 super(idv);
055 }
056
057 @Override protected void loadPlugins() throws Exception {
058 ResourceCollection rc = getResourceManager().getResources(
059 getResourceManager().RSC_PLUGINS);
060
061 for (int i = 0; i < rc.size(); i++) {
062 String path = rc.get(i).toString();
063 if (!rc.isWritable(i))
064 continue;
065
066 logger.debug("loadPlugins: path={}", path);
067 File pluginDir = new File(path);
068 File[] plugins = pluginDir.listFiles();
069 if (plugins == null)
070 continue;
071
072 for (File plugin : plugins) {
073 String current = plugin.getName();
074 if (current.startsWith(".tmp.") || current.endsWith(".deletethis"))
075 continue;
076
077 if (current.startsWith("http%3A%2F%2Fwww.unidata")) {
078 String newName = "http%3A%2F%2Fwww.ssec.wisc.edu%2Fmcidas%2Fsoftware%2Fv%2Fresources%2Fplugins%2F"+IOUtil.getFileTail(decode(current));
079 logger.debug(" current={}", current);
080 logger.debug(" newName={}\n",newName);
081 File checkExisting = new File(plugin.getParent(), newName);
082 if (checkExisting.exists())
083 logger.debug(" newName already exists...");
084 else
085 logger.debug(" rename plugin...");
086 }
087 }
088 }
089 super.loadPlugins();
090 }
091
092 /**
093 * McIDAS-V overrides {@link PluginManager#removePlugin(File)} so that the
094 * user is given an update on their plugin situation.
095 */
096 @Override public void removePlugin(File file) {
097 super.removePlugin(file);
098 LogUtil.userMessage("You must restart McIDAS-V to complete the removal of this plugin.");
099 }
100
101 /**
102 * Do not give the option to restart. Simply note that a restart is necessary at some point in the future.
103 */
104 protected void notifyUser() {
105 LogUtil.userMessage("You must restart McIDAS-V to complete the installation of this plugin.");
106 return;
107 }
108 }