Changeset 299 in josm


Ignore:
Timestamp:
Aug 8, 2007 2:59:36 AM (6 years ago)
Author:
imi
Message:
  • added update of plugins
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • .settings/org.eclipse.jdt.core.prefs

    r86 r299  
    1 #Fri Apr 21 12:51:47 CEST 2006 
     1#Tue Aug 07 22:54:52 GMT+01:00 2007 
    22eclipse.preferences.version=1 
     3org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning 
     4org.eclipse.jdt.core.compiler.problem.autoboxing=ignore 
     5org.eclipse.jdt.core.compiler.problem.deprecation=warning 
     6org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled 
     7org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled 
     8org.eclipse.jdt.core.compiler.problem.discouragedReference=warning 
     9org.eclipse.jdt.core.compiler.problem.emptyStatement=warning 
     10org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore 
     11org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled 
     12org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore 
     13org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning 
     14org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning 
     15org.eclipse.jdt.core.compiler.problem.forbiddenReference=error 
     16org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning 
     17org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning 
     18org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore 
     19org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore 
     20org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore 
     21org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning 
     22org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning 
     23org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error 
     24org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore 
     25org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error 
     26org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning 
     27org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore 
     28org.eclipse.jdt.core.compiler.problem.nullReference=ignore 
     29org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning 
     30org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore 
     31org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error 
     32org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore 
     33org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning 
     34org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore 
     35org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled 
     36org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning 
     37org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled 
     38org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore 
     39org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning 
     40org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning 
     41org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore 
     42org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning 
     43org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning 
     44org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning 
     45org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore 
     46org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning 
     47org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 
     48org.eclipse.jdt.core.compiler.problem.unusedImport=warning 
     49org.eclipse.jdt.core.compiler.problem.unusedLabel=warning 
     50org.eclipse.jdt.core.compiler.problem.unusedLocal=warning 
     51org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore 
     52org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled 
     53org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled 
     54org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled 
     55org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning 
     56org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning 
    357org.eclipse.jdt.core.formatter.align_type_members_on_columns=false 
    458org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 
  • src/org/openstreetmap/josm/actions/SaveActionBase.java

    r298 r299  
    104104                                return; 
    105105                        } 
    106                         ((OsmDataLayer)layer).cleanData(null, false); 
     106                        layer.cleanData(null, false); 
    107107                } catch (IOException e) { 
    108108                        e.printStackTrace(); 
  • src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r298 r299  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 
     1//License: GPL. Copyright 2007 by Immanuel Scholz and others 
    22package org.openstreetmap.josm.gui.preferences; 
    33 
     
    1414import java.util.Comparator; 
    1515import java.util.HashMap; 
     16import java.util.HashSet; 
    1617import java.util.LinkedList; 
    1718import java.util.Map; 
     19import java.util.Set; 
    1820import java.util.SortedMap; 
    1921import java.util.TreeMap; 
     
    5052                public String description; 
    5153                public String resource; 
    52                 public PluginDescription(String name, String description, String resource) { 
     54                public String version; 
     55                public PluginDescription(String name, String description, String resource, String version) { 
    5356                        this.name = name; 
    5457                        this.description = description; 
    5558                        this.resource = resource; 
    56         } 
     59                        this.version = version; 
     60                } 
    5761                public PluginDescription() { 
    58         } 
    59         } 
    60          
     62                } 
     63        } 
     64 
    6165        private Map<PluginDescription, Boolean> pluginMap; 
    6266        private Box pluginPanel = Box.createVerticalBox(); 
     
    7579                        public void actionPerformed(ActionEvent e) { 
    7680                                int count = PluginDownloader.downloadDescription(); 
    77                         if (count > 0) 
    78                                 JOptionPane.showMessageDialog(Main.parent, 
    79                                                 trn("Downloaded plugin information from {0} site", 
    80                                                                 "Downloaded plugin information from {0} sites", count, count)); 
    81                         else 
    82                                 JOptionPane.showMessageDialog(Main.parent, tr("No plugin information found.")); 
    83                         refreshPluginPanel(gui); 
    84             } 
     81                                if (count > 0) 
     82                                        JOptionPane.showMessageDialog(Main.parent, 
     83                                                        trn("Downloaded plugin information from {0} site", 
     84                                                                        "Downloaded plugin information from {0} sites", count, count)); 
     85                                else 
     86                                        JOptionPane.showMessageDialog(Main.parent, tr("No plugin information found.")); 
     87                                refreshPluginPanel(gui); 
     88                        } 
    8589                }); 
    8690                plugin.add(morePlugins, GBC.std().insets(0,0,10,0)); 
    87                  
     91 
    8892                JButton update = new JButton(tr("Update current")); 
    8993                update.addActionListener(new ActionListener(){ 
    9094                        public void actionPerformed(ActionEvent e) { 
    91                                 JOptionPane.showMessageDialog(Main.parent, tr("Not implemented yet.")); 
    92             } 
    93                 }); 
    94                 //TODO: plugin.add(update, GBC.std().insets(0,0,10,0)); 
     95                                update(); 
     96                        } 
     97 
     98                }); 
     99                plugin.add(update, GBC.std().insets(0,0,10,0)); 
    95100 
    96101                JButton configureSites = new JButton(tr("Configure Plugin Sites")); 
     
    98103                        public void actionPerformed(ActionEvent e) { 
    99104                                JOptionPane.showMessageDialog(Main.parent, tr("Not implemented yet.")); 
    100             } 
     105                        } 
    101106                }); 
    102107                //TODO: plugin.add(configureSites, GBC.std()); 
     
    105110        } 
    106111 
     112        private void update() { 
     113                Set<PluginDescription> toUpdate = new HashSet<PluginDescription>(); 
     114                StringBuilder toUpdateStr = new StringBuilder(); 
     115                for (PluginProxy proxy : Main.plugins) { 
     116                        PluginDescription description = findDescription(proxy.info.name); 
     117                        if (description != null && (description.version == null || description.version.equals("")) ? (proxy.info.version != null && proxy.info.version.equals("")) : !description.version.equals(proxy.info.version)) { 
     118                                toUpdate.add(description); 
     119                                toUpdateStr.append(description.name+"\n"); 
     120                        } 
     121                } 
     122                if (toUpdate.isEmpty()) { 
     123                        JOptionPane.showMessageDialog(Main.parent, tr("All installed plugins are up to date.")); 
     124                        return; 
     125                } 
     126                int answer = JOptionPane.showConfirmDialog(Main.parent, tr("Update the following plugins:\n\n{0}", toUpdateStr.toString()), tr("Update"), JOptionPane.OK_CANCEL_OPTION); 
     127                if (answer != JOptionPane.OK_OPTION) 
     128                        return; 
     129                PluginDownloader.update(toUpdate); 
     130        } 
     131 
     132        private PluginDescription findDescription(String name) { 
     133                for (PluginDescription d : pluginMap.keySet()) 
     134                        if (d.name.equals(name)) 
     135                                return d; 
     136                return null; 
     137        } 
     138 
    107139        private void refreshPluginPanel(final PreferenceDialog gui) { 
    108             Collection<PluginDescription> availablePlugins = getAvailablePlugins(); 
    109             pluginMap = new HashMap<PluginDescription, Boolean>(); 
    110             pluginPanel.removeAll(); 
     140                Collection<PluginDescription> availablePlugins = getAvailablePlugins(); 
     141                pluginMap = new HashMap<PluginDescription, Boolean>(); 
     142                pluginPanel.removeAll(); 
    111143                Collection<String> enabledPlugins = Arrays.asList(Main.pref.get("plugins").split(",")); 
    112144                for (final PluginDescription plugin : availablePlugins) { 
    113145                        boolean enabled = enabledPlugins.contains(plugin.name); 
    114                         final JCheckBox pluginCheck = new JCheckBox(plugin.name, enabled); 
     146                        final JCheckBox pluginCheck = new JCheckBox(plugin.name+(plugin.version != null && !plugin.version.equals("") ? " Version: "+plugin.version : ""), enabled); 
    115147                        pluginPanel.add(pluginCheck); 
    116148 
     
    130162                } 
    131163                plugin.updateUI(); 
    132     } 
     164        } 
    133165 
    134166        private Collection<PluginDescription> getAvailablePlugins() { 
    135167                SortedMap<String, PluginDescription> availablePlugins = new TreeMap<String, PluginDescription>(new Comparator<String>(){ 
    136168                        public int compare(String o1, String o2) { 
    137                     return o1.compareToIgnoreCase(o2); 
    138             } 
     169                                return o1.compareToIgnoreCase(o2); 
     170                        } 
    139171                }); 
    140172                for (String location : PluginInformation.getPluginLocations()) { 
     
    148180                                                try { 
    149181                                                        PluginInformation info = new PluginInformation(f); 
    150                                     availablePlugins.put(info.name, new PluginDescription(info.name, info.description, PluginInformation.getURLString(f.getPath()))); 
    151                             } catch (PluginException x) { 
    152                             } 
     182                                                        if (!availablePlugins.containsKey(info.name)) 
     183                                                                availablePlugins.put(info.name, new PluginDescription(info.name, info.description, PluginInformation.getURLString(f.getPath()), info.version)); 
     184                                                } catch (PluginException x) { 
     185                                                } 
    153186                                        } else if (f.getName().matches("^[0-9]+-site.*\\.xml$")) { 
    154187                                                try { 
    155                                 Uniform<PluginDescription> parser = new Uniform<PluginDescription>(new FileReader(f), "plugin", PluginDescription.class); 
    156                                 for (PluginDescription pd : parser) 
    157                                         if (!availablePlugins.containsKey(pd.name)) 
    158                                                 availablePlugins.put(pd.name, pd); 
    159                         } catch (Exception e) { 
    160                                 e.printStackTrace(); 
    161                                 JOptionPane.showMessageDialog(Main.parent, tr("Error reading plugin information file: {0}", f.getName())); 
    162                         } 
     188                                                        Uniform<PluginDescription> parser = new Uniform<PluginDescription>(new FileReader(f), "plugin", PluginDescription.class); 
     189                                                        for (PluginDescription pd : parser) 
     190                                                                if (!availablePlugins.containsKey(pd.name)) 
     191                                                                        availablePlugins.put(pd.name, pd); 
     192                                                } catch (Exception e) { 
     193                                                        e.printStackTrace(); 
     194                                                        JOptionPane.showMessageDialog(Main.parent, tr("Error reading plugin information file: {0}", f.getName())); 
     195                                                } 
    163196                                        } 
    164197                                } 
     
    170203                                                proxy.info.name,  
    171204                                                proxy.info.description,  
    172                                                 proxy.info.file == null ? null : PluginInformation.getURLString(proxy.info.file.getPath()))); 
    173             return availablePlugins.values(); 
    174     } 
     205                                                proxy.info.file == null ? null : PluginInformation.getURLString(proxy.info.file.getPath()), 
     206                                                                proxy.info.version)); 
     207                return availablePlugins.values(); 
     208        } 
    175209 
    176210        public void ok() { 
     
    195229                                        if (!PluginDownloader.downloadPlugin(pd)) 
    196230                                                pluginMap.put(pd, false); 
    197                                                  
     231 
    198232                } 
    199233 
     
    204238                if (plugins.endsWith(",")) 
    205239                        plugins = plugins.substring(0, plugins.length()-1); 
    206                  
     240 
    207241                String oldPlugins = Main.pref.get("plugins"); 
    208242                if (!plugins.equals(oldPlugins)) { 
  • src/org/openstreetmap/josm/plugins/PluginDownloader.java

    r298 r299  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 
     1//License: GPL. Copyright 2007 by Immanuel Scholz and others 
    22/** 
    33 *  
     
    66 
    77import static org.openstreetmap.josm.tools.I18n.tr; 
     8import static org.openstreetmap.josm.tools.I18n.trn; 
    89 
    910import java.io.BufferedReader; 
    1011import java.io.File; 
     12import java.io.FileNotFoundException; 
    1113import java.io.FileOutputStream; 
    1214import java.io.FileWriter; 
     
    1517import java.io.InputStreamReader; 
    1618import java.io.OutputStream; 
     19import java.net.MalformedURLException; 
    1720import java.net.URL; 
     21import java.util.Collection; 
    1822import java.util.regex.Matcher; 
    1923import java.util.regex.Pattern; 
     
    2226 
    2327import org.openstreetmap.josm.Main; 
     28import org.openstreetmap.josm.gui.PleaseWaitRunnable; 
    2429import org.openstreetmap.josm.gui.preferences.PluginPreference.PluginDescription; 
     30import org.xml.sax.SAXException; 
    2531 
    2632public class PluginDownloader { 
    27         private static final Pattern wiki = Pattern.compile("^</td></tr><tr><td><a class=\"ext-link\" href=\"([^\"]*)\"><span class=\"icon\">([^<]*)</span></a></td><td>[^<]*</td><td>(.*)"); 
     33 
     34        private static final class UpdateTask extends PleaseWaitRunnable { 
     35                private final Collection<PluginDescription> toUpdate; 
     36                private String errors = ""; 
     37                private int count = 0; 
     38 
     39                private UpdateTask(Collection<PluginDescription> toUpdate) { 
     40                        super(tr("Update Plugins")); 
     41                        this.toUpdate = toUpdate; 
     42                } 
     43 
     44                @Override protected void cancel() { 
     45                        finish(); 
     46                } 
     47 
     48                @Override protected void finish() { 
     49                        if (errors.length() > 0) 
     50                                JOptionPane.showMessageDialog(Main.parent, tr("There were problems with the following plugins:\n\n {0}",errors)); 
     51                        else 
     52                                JOptionPane.showMessageDialog(Main.parent, trn("{0} Plugin successfully updated. Please restart JOSM.", "{0} Plugins successfully updated. Please restart JOSM.", count, count)); 
     53                } 
     54 
     55                @Override protected void realRun() throws SAXException, IOException { 
     56                        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")); 
     60                                        count++; 
     61                                } else 
     62                                        errors += d.name + "\n"; 
     63                        } 
     64                } 
     65        } 
     66 
     67        private static final Pattern wiki = Pattern.compile("^</td></tr><tr><td><a class=\"ext-link\" href=\"([^\"]*)\"><span class=\"icon\">([^<]*)</span></a></td><td>[^<]*</td><td>([^<]*)</td><td>(.*)"); 
    2868 
    2969        public static int downloadDescription() { 
     
    66106                        b.append("    <resource>"+escape(m.group(1))+"</resource>\n"); 
    67107                        b.append("    <description>"+escape(m.group(3))+"</description>\n"); 
     108                        b.append("    <version>"+escape(m.group(4))+"</version>\n"); 
    68109                        b.append("  </plugin>\n"); 
    69110                } 
     
    73114 
    74115        private static String escape(String s) { 
    75             return s.replaceAll("<", "&lt;").replaceAll(">", "&gt;"); 
    76     } 
     116                return s.replaceAll("<", "&lt;").replaceAll(">", "&gt;"); 
     117        } 
    77118 
    78119        public static boolean downloadPlugin(PluginDescription pd) { 
    79120                File file = new File(Main.pref.getPreferencesDir()+"plugins/"+pd.name+".jar"); 
    80             try { 
    81                 InputStream in = new URL(pd.resource).openStream(); 
     121                if (!download(pd.resource, file)) { 
     122                        JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.resource)); 
     123                } else { 
     124                        try { 
     125                                PluginInformation.findPlugin(pd.name); 
     126                                return true; 
     127                        } catch (Exception e) { 
     128                                e.printStackTrace(); 
     129                                JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} seem to be broken or could not be downloaded automatically.", pd.name)); 
     130                        } 
     131                } 
     132                if (file.exists()) 
     133                        file.delete(); 
     134                return false; 
     135        } 
     136 
     137        private static boolean download(String url, File file) { 
     138                try { 
     139                        InputStream in = new URL(url).openStream(); 
    82140                        OutputStream out = new FileOutputStream(file); 
    83                 byte[] buffer = new byte[8192]; 
    84                 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) 
    85                         out.write(buffer, 0, read); 
    86                 out.close(); 
    87                 in.close(); 
    88                 try { 
    89                     PluginInformation.findPlugin(pd.name); 
    90                     return true; 
    91             } catch (Exception e) { 
    92                     e.printStackTrace(); 
    93                     JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} seem to be broken or could not be downloaded automatically.", pd.name)); 
    94             } 
    95         } catch (Exception e) { 
    96                 JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.resource)); 
    97         } 
    98         if (file.exists()) 
    99                 file.delete(); 
    100         return false; 
    101     } 
     141                        byte[] buffer = new byte[8192]; 
     142                        for (int read = in.read(buffer); read != -1; read = in.read(buffer)) 
     143                                out.write(buffer, 0, read); 
     144                        out.close(); 
     145                        in.close(); 
     146                        return true; 
     147                } catch (MalformedURLException e) { 
     148                        e.printStackTrace(); 
     149                } catch (FileNotFoundException e) { 
     150                        e.printStackTrace(); 
     151                } catch (IOException e) { 
     152                        e.printStackTrace(); 
     153                } 
     154                return false; 
     155        } 
     156 
     157        public static void update(Collection<PluginDescription> update) { 
     158                Main.worker.execute(new UpdateTask(update)); 
     159        } 
    102160} 
  • src/org/openstreetmap/josm/tools/OpenBrowser.java

    r298 r299  
    5252        } 
    5353 
    54         private static void linux(String url) throws IOException { 
     54        private static void linux(String url) { 
    5555                String[] programs = {"gnome-open", "kfmclient openURL", "firefox"}; 
    5656                for (String program : programs) { 
  • test/unit/org/openstreetmap/josm/testframework/MainMock.java

    r298 r299  
    33 
    44import java.awt.AWTEvent; 
    5 import java.awt.AWTException; 
    65import java.awt.Toolkit; 
    76import java.awt.event.AWTEventListener; 
     
    4443        } 
    4544 
    46         @BeforeClass public static void startPopupKiller() throws AWTException { 
     45        @BeforeClass public static void startPopupKiller() { 
    4746                Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener(){ 
    4847                        public void eventDispatched(AWTEvent event) { 
Note: See TracChangeset for help on using the changeset viewer.