Changeset 873 in josm for trunk/src


Ignore:
Timestamp:
2008-08-26T22:35:52+02:00 (16 years ago)
Author:
stoecker
Message:

cleanups in plugin handling

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r812 r873  
    7272         */
    7373        public String getPreferencesDir() {
     74                final String path = getPreferencesDirFile().getPath();
     75                if (path.endsWith(File.separator))
     76                        return path;
     77                return path + File.separator;
     78        }
     79
     80        public File getPreferencesDirFile() {
    7481                if (System.getenv("APPDATA") != null)
    75                         return System.getenv("APPDATA")+"/JOSM/";
    76                 return System.getProperty("user.home")+"/.josm/";
     82                        return new File(System.getenv("APPDATA"), "JOSM");
     83                return new File(System.getProperty("user.home"), ".josm");
     84        }
     85       
     86        public File getPluginsDirFile() {
     87                return new File(getPreferencesDirFile(), "plugins");
    7788        }
    7889
     
    8596                String s;
    8697                if ((s = System.getenv("JOSM_RESOURCES")) != null) {
    87                         if (!s.endsWith("/") && !s.endsWith("\\"))
    88                                 s = s + "/";
     98                        if (!s.endsWith(File.separator))
     99                                s = s + File.separator;
    89100                        locations.add(s);
    90101                }
    91102                if ((s = System.getProperty("josm.resources")) != null) {
    92                         if (!s.endsWith("/") && !s.endsWith("\\"))
    93                                 s = s + "/";
     103                        if (!s.endsWith(File.separator))
     104                                s = s + File.separator;
    94105                        locations.add(s);
    95106                }
    96107                String appdata = System.getenv("APPDATA");
    97                 if (System.getenv("ALLUSERSPROFILE") != null && appdata != null && appdata.lastIndexOf("\\") != -1) {
    98                         appdata = appdata.substring(appdata.lastIndexOf("\\"));
    99                         locations.add(System.getenv("ALLUSERSPROFILE")+appdata+"/JOSM/");
     108                if (System.getenv("ALLUSERSPROFILE") != null && appdata != null
     109                        && appdata.lastIndexOf(File.separator) != -1) {
     110                        appdata = appdata.substring(appdata.lastIndexOf(File.separator));
     111                        locations.add(new File(new File(System.getenv("ALLUSERSPROFILE"),
     112                                appdata), "JOSM").getPath());
    100113                }
    101114                locations.add("/usr/local/share/josm/");
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r795 r873  
    2222
    2323import org.openstreetmap.josm.Main;
     24import org.openstreetmap.josm.plugins.PluginDownloader;
    2425import org.openstreetmap.josm.tools.BugReportExceptionHandler;
    2526/**
     
    8485                final File prefDir = new File(Main.pref.getPreferencesDir());
    8586                // check if preferences directory has moved (TODO: Update code. Remove this after some time)
    86                 File oldPrefDir = new File(System.getProperty("user.home")+"/.josm");
     87                File oldPrefDir = new File(System.getProperty("user.home"), ".josm");
    8788                if (!prefDir.isDirectory() && oldPrefDir.isDirectory()) {
    8889                        if (oldPrefDir.renameTo(prefDir)) {
     
    119120                }
    120121
     122                if (!PluginDownloader.moveUpdatedPlugins()) {
     123                        JOptionPane.showMessageDialog(null,
     124                                tr("Activating the updated plugins failed."),
     125                                tr("Plugins"), JOptionPane.ERROR_MESSAGE);
     126                }
     127               
    121128                // load the early plugins
    122129                Main.loadPlugins(true);
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r627 r873  
    102102                        public void actionPerformed(ActionEvent e) {
    103103                                update();
     104                                refreshPluginPanel(gui);
    104105                        }
    105106
     
    168169
    169170        private void update() {
     171                // refresh description
     172                PluginDownloader.downloadDescription();
     173
    170174                Set<PluginDescription> toUpdate = new HashSet<PluginDescription>();
    171175                StringBuilder toUpdateStr = new StringBuilder();
     
    212216                for (final PluginDescription plugin : availablePlugins) {
    213217                        boolean enabled = enabledPlugins.contains(plugin.name);
    214                         final JCheckBox pluginCheck = new JCheckBox(plugin.name+(plugin.version != null && !plugin.version.equals("") ? " Version: "+plugin.version : ""), enabled);
     218                        String remoteversion = plugin.version;
     219                        if(remoteversion == null || remoteversion.equals(""))
     220                                remoteversion = tr("unknown");
     221
     222                        String localversion;
     223                        PluginInformation p = PluginInformation.findPlugin(plugin.name);
     224                        if(p != null)
     225                        {
     226                                if(p.version != null && !p.version.equals(""))
     227                                        localversion = p.version;
     228                                else
     229                                        localversion = tr("unknown");
     230                                localversion = " (" + localversion + ")";
     231                        }
     232                        else
     233                                localversion = "";
     234
     235                        final JCheckBox pluginCheck = new JCheckBox(tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion), enabled);
    215236                        pluginPanel.add(pluginCheck);
    216237
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r627 r873  
    5353         */
    5454        public final String getPluginDir() {
    55                 return Main.pref.getPreferencesDir()+"plugins/"+info.name+"/";
     55                return new File(Main.pref.getPluginsDirFile(), info.name).getPath();
    5656        }
    5757
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java

    r627 r873  
    1313import java.io.FileOutputStream;
    1414import java.io.FileWriter;
     15import java.io.FilenameFilter;
    1516import java.io.IOException;
    1617import java.io.InputStream;
     
    5455
    5556                @Override protected void realRun() throws SAXException, IOException {
     57                        File pluginDir = Main.pref.getPluginsDirFile();
     58                        if (!pluginDir.exists())
     59                                pluginDir.mkdirs();
    5660                        for (PluginDescription d : toUpdate) {
    57                                 File tempFile = new File(Main.pref.getPreferencesDir()+"temp.jar");
    58                                 if (download(d.resource, tempFile)) {
    59                                         tempFile.renameTo(new File(Main.pref.getPreferencesDir()+"plugins/"+d.name+".jar"));
     61                                File pluginFile = new File(pluginDir, d.name + ".jar.new");
     62                                if (download(d.resource, pluginFile))
    6063                                        count++;
    61                                 } else
     64                                else
    6265                                        errors += d.name + "\n";
    6366                        }
     67                        PluginDownloader.moveUpdatedPlugins();
    6468                }
    6569        }
     
    7983                                r.close();
    8084                                new File(Main.pref.getPreferencesDir()+"plugins").mkdir();
    81                                 FileWriter out = new FileWriter(Main.pref.getPreferencesDir()+"plugins/"+count+"-site-"+site.replaceAll("[/:\\\\ <>|]", "_")+".xml");
     85                                FileWriter out = new FileWriter(new File(Main.pref
     86                                        .getPluginsDirFile(), count + "-site-"
     87                                        + site.replaceAll("[/:\\\\ <>|]", "_") + ".xml"));
    8288                                out.append(txt);
    8389                                out.close();
     
    123129
    124130        public static boolean downloadPlugin(PluginDescription pd) {
    125                 File file = new File(Main.pref.getPreferencesDir()+"plugins/"+pd.name+".jar");
     131                File file = new File(Main.pref.getPluginsDirFile(), pd.name + ".jar");
    126132                if (!download(pd.resource, file)) {
    127133                        JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.resource));
     
    163169                Main.worker.execute(new UpdateTask(update));
    164170        }
     171       
     172        public static boolean moveUpdatedPlugins() {
     173                File pluginDir = Main.pref.getPluginsDirFile();
     174                boolean ok = true;             
     175                if (pluginDir.exists() && pluginDir.isDirectory()) {
     176                        final File[] files = pluginDir.listFiles(new FilenameFilter() {
     177                                public boolean accept(File dir, String name) {
     178                        return name.endsWith(".new");
     179                }});
     180                        for (File updatedPlugin : files) {
     181                                final String filePath = updatedPlugin.getPath();
     182                                File plugin = new File(filePath.substring(0, filePath.length() - 4));
     183                                ok = plugin.delete() && updatedPlugin.renameTo(plugin) && ok;
     184                        }
     185                }
     186                return ok;
     187        }
    165188}
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r627 r873  
    196196
    197197        for (String s : locations) {
    198                 File pluginFile = new File(s+"/"+pluginName+".jar");
     198                File pluginFile = new File(s, pluginName + ".jar");
    199199                if (pluginFile.exists()) {
    200200                                PluginInformation info = new PluginInformation(pluginFile);
Note: See TracChangeset for help on using the changeset viewer.