Changeset 6593 in josm


Ignore:
Timestamp:
2014-01-01T23:07:33+01:00 (11 years ago)
Author:
stoecker
Message:

cleanup validator prefs to better support prefs format (resets some settings to default)

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

Legend:

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

    r6580 r6593  
    14901490        @Override
    14911491        public void visit(ListSetting setting) {
     1492            /* don't save default values */
     1493            if (setting.equals(defaultsMap.get(key)))
     1494                return;
    14921495            b.append("  <list key='").append(XmlWriter.encode(key)).append("'>\n");
    14931496            for (String s : setting.getValue()) {
     
    14991502        @Override
    15001503        public void visit(ListListSetting setting) {
     1504            /* don't save default values */
     1505            if (setting.equals(defaultsMap.get(key)))
     1506                return;
    15011507            b.append("  <lists key='").append(XmlWriter.encode(key)).append("'>\n");
    15021508            for (List<String> list : setting.getValue()) {
     
    15581564                "gpxLayer.downloadAlongTrack.area",            // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.area
    15591565                "gpxLayer.downloadAlongTrack.near",            // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.near
     1566                "validator.tests",                             // 01/2014 - can be removed mid-2014. Replaced by validator.skip
     1567                "validator.testsBeforeUpload",                 // 01/2014 - can be removed mid-2014. Replaced by validator.skipBeforeUpload
     1568                "validator.TagChecker.sources",                // 01/2014 - can be removed mid-2014. Replaced by validator.TagChecker.source
     1569                "validator.TagChecker.usedatafile",            // 01/2014 - can be removed mid-2014. Replaced by validator.TagChecker.source
     1570                "validator.TagChecker.useignorefile",          // 01/2014 - can be removed mid-2014. Replaced by validator.TagChecker.source
     1571                "validator.TagChecker.usespellfile",           // 01/2014 - can be removed mid-2014. Replaced by validator.TagChecker.source
    15601572        };
    15611573        for (String key : obsolete) {
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r6592 r6593  
    8585    @SuppressWarnings("unchecked")
    8686    private static final Class<Test>[] allAvailableTests = new Class[] {
     87        /* FIXME - unique error numbers for tests aren't properly unique - ignoring will not work as expected */
    8788        DuplicateNode.class, // ID    1 ..   99
    8889        OverlappingWays.class, // ID  101 ..  199
     
    231232
    232233    private static void applyPrefs(Map<String, Test> tests, boolean beforeUpload) {
    233         Pattern regexp = Pattern.compile("(\\w+)=(true|false),?");
    234         Matcher m = regexp.matcher(Main.pref.get(beforeUpload ? ValidatorPreference.PREF_TESTS_BEFORE_UPLOAD
    235                 : ValidatorPreference.PREF_TESTS));
    236         int pos = 0;
    237         while (m.find(pos)) {
    238             String testName = m.group(1);
     234        for(String testName : Main.pref.getCollection(beforeUpload
     235        ? ValidatorPreference.PREF_SKIP_TESTS_BEFORE_UPLOAD : ValidatorPreference.PREF_SKIP_TESTS)) {
    239236            Test test = tests.get(testName);
    240237            if (test != null) {
    241                 boolean enabled = Boolean.valueOf(m.group(2));
    242238                if (beforeUpload) {
    243                     test.testBeforeUpload = enabled;
     239                    test.testBeforeUpload = false;
    244240                } else {
    245                     test.enabled = enabled;
     241                    test.enabled = false;
    246242                }
    247243            }
    248             pos = m.end();
    249244        }
    250245    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6591 r6593  
    9494    public static final String PREF_CHECK_FIXMES = PREFIX + ".checkFixmes";
    9595
    96     public static final String PREF_SOURCES = PREFIX + ".sources";
    97     public static final String PREF_USE_DATA_FILE = PREFIX + ".usedatafile";
    98     public static final String PREF_USE_IGNORE_FILE = PREFIX + ".useignorefile";
    99     public static final String PREF_USE_SPELL_FILE = PREFIX + ".usespellfile";
     96    public static final String PREF_SOURCES = PREFIX + ".source";
    10097
    10198    public static final String PREF_CHECK_KEYS_BEFORE_UPLOAD = PREF_CHECK_KEYS + "BeforeUpload";
     
    120117    protected JCheckBox prefCheckFixmesBeforeUpload;
    121118    protected JCheckBox prefCheckPaintBeforeUpload;
    122 
    123     protected JCheckBox prefUseDataFile;
    124     protected JCheckBox prefUseIgnoreFile;
    125     protected JCheckBox prefUseSpellFile;
    126119
    127120    protected static final int EMPTY_VALUES      = 1200;
     
    172165
    173166        spellCheckKeyData = new HashMap<String, String>();
    174         String sources = Main.pref.get( PREF_SOURCES, "");
    175         if (Main.pref.getBoolean(PREF_USE_DATA_FILE, true)) {
    176             if (sources == null || sources.length() == 0) {
    177                 sources = DATA_FILE;
    178             } else {
    179                 sources = DATA_FILE + ";" + sources;
    180             }
    181         }
    182         if (Main.pref.getBoolean(PREF_USE_IGNORE_FILE, true)) {
    183             if (sources == null || sources.length() == 0) {
    184                 sources = IGNORE_FILE;
    185             } else {
    186                 sources = IGNORE_FILE + ";" + sources;
    187             }
    188         }
    189         if (Main.pref.getBoolean(PREF_USE_SPELL_FILE, true)) {
    190             if( sources == null || sources.length() == 0) {
    191                 sources = SPELL_FILE;
    192             } else {
    193                 sources = SPELL_FILE + ";" + sources;
    194             }
    195         }
    196 
     167       
    197168        String errorSources = "";
    198         if (sources.length() == 0)
    199             return;
    200         for (String source : sources.split(";")) {
     169        for (String source : Main.pref.getCollection(PREF_SOURCES, Arrays.asList(DATA_FILE, IGNORE_FILE, SPELL_FILE))) {
    201170            BufferedReader reader = null;
    202171            try {
     
    511480        testPanel.add(prefCheckComplexBeforeUpload, a);
    512481
    513         final String sources = Main.pref.get(PREF_SOURCES);
     482        final Collection<String> sources = Main.pref.getCollection(PREF_SOURCES, Arrays.asList(DATA_FILE, IGNORE_FILE, SPELL_FILE));
    514483        sourcesList = new EditableList(tr("TagChecker source"));
    515         sourcesList.setItems(sources != null ? Arrays.asList(sources.split(";")) : Collections.<String>emptyList());
     484        sourcesList.setItems(sources);
    516485        testPanel.add(new JLabel(tr("Data sources ({0})", "*.cfg")), GBC.eol().insets(23, 0, 0, 0));
    517486        testPanel.add(sourcesList, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(23, 0, 0, 0));
     
    545514        prefCheckFixmesBeforeUpload.setSelected(Main.pref.getBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, true));
    546515        testPanel.add(prefCheckFixmesBeforeUpload, a);
    547 
    548         prefUseDataFile = new JCheckBox(tr("Use default data file."), Main.pref.getBoolean(PREF_USE_DATA_FILE, true));
    549         prefUseDataFile.setToolTipText(tr("Use the default data file (recommended)."));
    550         testPanel.add(prefUseDataFile, GBC.eol().insets(20,0,0,0));
    551 
    552         prefUseIgnoreFile = new JCheckBox(tr("Use default tag ignore file."), Main.pref.getBoolean(PREF_USE_IGNORE_FILE, true));
    553         prefUseIgnoreFile.setToolTipText(tr("Use the default tag ignore file (recommended)."));
    554         testPanel.add(prefUseIgnoreFile, GBC.eol().insets(20,0,0,0));
    555 
    556         prefUseSpellFile = new JCheckBox(tr("Use default spellcheck file."), Main.pref.getBoolean(PREF_USE_SPELL_FILE, true));
    557         prefUseSpellFile.setToolTipText(tr("Use the default spellcheck file (recommended)."));
    558         testPanel.add(prefUseSpellFile, GBC.eol().insets(20,0,0,0));
    559516    }
    560517
     
    579536        Main.pref.put(PREF_CHECK_KEYS_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected());
    580537        Main.pref.put(PREF_CHECK_FIXMES_BEFORE_UPLOAD, prefCheckFixmesBeforeUpload.isSelected());
    581         Main.pref.put(PREF_USE_DATA_FILE, prefUseDataFile.isSelected());
    582         Main.pref.put(PREF_USE_IGNORE_FILE, prefUseIgnoreFile.isSelected());
    583         Main.pref.put(PREF_USE_SPELL_FILE, prefUseSpellFile.isSelected());
    584         final List<String> sources = sourcesList.getItems();
    585         return Main.pref.put(PREF_SOURCES, sources.isEmpty() ? null : Utils.join(";", sources));
     538        return Main.pref.putCollection(PREF_SOURCES, sourcesList.getItems());
    586539    }
    587540
    588541    @Override
    589542    public Command fixError(TestError testError) {
    590 
    591543        List<Command> commands = new ArrayList<Command>(50);
    592544
     
    631583    @Override
    632584    public boolean isFixable(TestError testError) {
    633 
    634585        if (testError.getTester() instanceof TagChecker) {
    635586            int code = testError.getCode();
  • trunk/src/org/openstreetmap/josm/gui/preferences/validator/ValidatorPreference.java

    r6529 r6593  
    88import java.awt.event.ActionListener;
    99import java.util.Collection;
     10import java.util.LinkedList;
    1011
    1112import javax.swing.BorderFactory;
     
    5253
    5354    /** The preferences key for enabled tests */
    54     public static final String PREF_TESTS = PREFIX + ".tests";
     55    public static final String PREF_SKIP_TESTS = PREFIX + ".skip";
    5556
    5657    /** The preferences key for enabled tests */
     
    5859
    5960    /** The preferences key for enabled tests before upload*/
    60     public static final String PREF_TESTS_BEFORE_UPLOAD = PREFIX + ".testsBeforeUpload";
     61    public static final String PREF_SKIP_TESTS_BEFORE_UPLOAD = PREFIX + ".skipBeforeUpload";
    6162
    6263    /** The preferences key for ignored severity other on upload */
     
    126127    @Override
    127128    public boolean ok() {
    128         StringBuilder tests = new StringBuilder();
    129         StringBuilder testsBeforeUpload = new StringBuilder();
     129        Collection<String> tests = new LinkedList<String>();
     130        Collection<String> testsBeforeUpload = new LinkedList<String>();
    130131
    131132        for (Test test : allTests) {
    132133            test.ok();
    133134            String name = test.getClass().getSimpleName();
    134             tests.append(',').append(name).append('=').append(test.enabled);
    135             testsBeforeUpload.append(',').append(name).append('=').append(test.testBeforeUpload);
     135            if(!test.enabled)
     136                tests.add(name);
     137            if(!test.testBeforeUpload)
     138                testsBeforeUpload.add(name);
    136139        }
    137 
    138         if (tests.length() > 0) {
    139             tests = tests.deleteCharAt(0);
    140         }
    141         if (testsBeforeUpload.length() > 0) {
    142             testsBeforeUpload = testsBeforeUpload.deleteCharAt(0);
    143         }
    144 
    145140        OsmValidator.initializeTests(allTests);
    146141
    147         Main.pref.put(PREF_TESTS, tests.toString());
    148         Main.pref.put(PREF_TESTS_BEFORE_UPLOAD, testsBeforeUpload.toString());
     142        Main.pref.putCollection(PREF_SKIP_TESTS, tests);
     143        Main.pref.putCollection(PREF_SKIP_TESTS_BEFORE_UPLOAD, testsBeforeUpload);
    149144        Main.pref.put(PREF_USE_IGNORE, prefUseIgnore.isSelected());
    150145        Main.pref.put(PREF_OTHER, prefOther.isSelected());
Note: See TracChangeset for help on using the changeset viewer.