Ticket #13309: patch-fix-13309-2.2.patch

File patch-fix-13309-2.2.patch, 14.2 KB (added by michael2402, 8 years ago)
  • scripts/TagInfoExtract.groovy

    diff --git a/scripts/TagInfoExtract.groovy b/scripts/TagInfoExtract.groovy
    index 828e325..0bb00a7 100644
    a b class TagInfoExtract {  
    370370     * Initialize the script.
    371371     */
    372372    def init() {
    373         Main.initApplicationPreferences()
    374373        Main.determinePlatformHook()
    375374        Main.pref.enableSaveOnPut(false)
    376375        Main.setProjection(Projections.getProjectionByCode("EPSG:3857"))
  • src/org/openstreetmap/josm/Main.java

    diff --git a/src/org/openstreetmap/josm/Main.java b/src/org/openstreetmap/josm/Main.java
    index 85245aa..01d0378 100644
    a b public abstract class Main {  
    167167    /**
    168168     * Global application preferences
    169169     */
    170     public static Preferences pref;
     170    public static final Preferences pref = new Preferences();
    171171
    172172    /**
    173173     * The MapFrame. Use {@link Main#setMapFrame} to set or clear it.
    public abstract class Main {  
    514514    public static volatile PlatformHook platform;
    515515
    516516    /**
    517      * Initializes {@code Main.pref} in normal application context.
    518      * @since 6471
    519      */
    520     public static void initApplicationPreferences() {
    521         Main.pref = new Preferences();
    522     }
    523 
    524     /**
    525517     * Set or clear (if passed <code>null</code>) the map.
    526518     * <p>
    527519     * To be removed any time
  • src/org/openstreetmap/josm/data/Preferences.java

    diff --git a/src/org/openstreetmap/josm/data/Preferences.java b/src/org/openstreetmap/josm/data/Preferences.java
    index 6c738e9..e145cac 100644
    a b public class Preferences {  
    778778        }
    779779    }
    780780
     781    /**
     782     * Resets the preferences to their initial state. This resets all values and file associations.
     783     * The default values and listeners are not removed.
     784     * <p>
     785     * It is meant to be called before {@link #init(boolean)}
     786     */
     787    public void resetToInitialState() {
     788        resetToDefault();
     789        preferencesDir = null;
     790        cacheDir = null;
     791        userdataDir = null;
     792        saveOnPut = true;
     793        initSuccessful = false;
     794    }
     795
     796    /**
     797     * Reset all values stored in this map to the default values. This clears the preferences.
     798     */
    781799    public final void resetToDefault() {
    782800        settingsMap.clear();
    783801    }
  • src/org/openstreetmap/josm/gui/MainApplication.java

    diff --git a/src/org/openstreetmap/josm/gui/MainApplication.java b/src/org/openstreetmap/josm/gui/MainApplication.java
    index ea120a1..e42444a 100644
    a b public class MainApplication extends Main {  
    325325            Main.info(tr("Printing debugging messages to console"));
    326326        }
    327327
    328         initApplicationPreferences();
    329 
    330328        Policy.setPolicy(new Policy() {
    331329            // Permissions for plug-ins loaded when josm is started via webstart
    332330            private PermissionCollection pc;
  • test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    diff --git a/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java b/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
    index fab7dde..0789584 100644
    a b import javax.json.spi.JsonProvider;  
    1919
    2020import org.junit.Assert;
    2121import org.junit.Before;
    22 import org.junit.BeforeClass;
     22import org.junit.Rule;
    2323import org.junit.Test;
    24 import org.openstreetmap.josm.JOSMFixture;
    25 import org.openstreetmap.josm.Main;
    2624import org.openstreetmap.josm.TestUtils;
    2725import org.openstreetmap.josm.data.Version;
    2826import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     27import org.openstreetmap.josm.testutils.JOSMTestRules;
     28
     29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2930
    3031/**
    3132 * Tests the {@link HttpClient} using the webservice <a href="https://httpbin.org/">https://httpbin.org/</a>.
    3233 */
    3334public class HttpClientTest {
    3435
    35     private ProgressMonitor progress;
     36    /**
     37     *
     38     */
     39    @Rule
     40    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     41    public JOSMTestRules test = new JOSMTestRules().preferences();
    3642
    37     @BeforeClass
    38     public static void setUpBeforeClass() {
    39         JOSMFixture.createFunctionalTestFixture().init();
    40     }
     43    private ProgressMonitor progress;
    4144
    4245    @Before
    4346    public void setUp() {
    public class HttpClientTest {  
    172175     */
    173176    @Test
    174177    public void testOpenUrlGzip() throws IOException {
    175         Main.initApplicationPreferences();
    176178        final URL url = new URL("https://www.openstreetmap.org/trace/1613906/data");
    177179        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
    178180            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
    public class HttpClientTest {  
    185187     */
    186188    @Test
    187189    public void testOpenUrlBzip() throws IOException {
    188         Main.initApplicationPreferences();
    189190        final URL url = new URL("https://www.openstreetmap.org/trace/785544/data");
    190191        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
    191192            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
    public class HttpClientTest {  
    198199     */
    199200    @Test
    200201    public void testTicket9660() throws IOException {
    201         Main.initApplicationPreferences();
    202202        final URL url = new URL("http://www.openstreetmap.org/trace/1350010/data");
    203203        try (BufferedReader x = HttpClient.create(url).connect()
    204204                .uncompress(true).uncompressAccordingToContentDisposition(true).getContentReader()) {
  • test/unit/org/openstreetmap/josm/JOSMFixture.java

    diff --git a/test/unit/org/openstreetmap/josm/JOSMFixture.java b/test/unit/org/openstreetmap/josm/JOSMFixture.java
    index 81d579b..f9bcc23 100644
    a b public class JOSMFixture {  
    9090        }
    9191        System.setProperty("josm.home", josmHome);
    9292        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    93         Main.initApplicationPreferences();
     93        Main.pref.resetToInitialState();
    9494        Main.pref.enableSaveOnPut(false);
    9595        I18n.init();
    9696        // initialize the plaform hook, and
  • test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java

    diff --git a/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java b/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java
    index 0c0ae11..3e52858 100644
    a b import org.junit.BeforeClass;  
    1616import org.junit.Test;
    1717import org.openstreetmap.josm.JOSMFixture;
    1818import org.openstreetmap.josm.Main;
    19 import org.openstreetmap.josm.data.Preferences;
    2019import org.openstreetmap.josm.data.coor.EastNorth;
    2120import org.openstreetmap.josm.data.osm.DataSet;
    2221import org.openstreetmap.josm.data.osm.Node;
    import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;  
    3231 */
    3332public class SelectActionTest {
    3433
    35     /**
    36      * Override some configuration variables without change in preferences.xml
    37      */
    38     static class PreferencesMock extends Preferences {
    39         @Override
    40         public synchronized int getInteger(String key, int def) {
    41             if ("edit.initial-move-delay".equals(key)) {
    42                 return 0;
    43             } else {
    44                 return super.getInteger(key, def);
    45             }
    46         }
    47     }
    48 
    4934    boolean nodesMerged;
    5035
    5136    class SelectActionMock extends SelectAction {
    public class SelectActionTest {  
    10388        dataSet.addSelected(n2);
    10489        dataSet.addSelected(w);
    10590
    106         Main.pref = new PreferencesMock();
     91        Main.pref.put("edit.initial-move-delay", "0");
    10792        Main.getLayerManager().addLayer(layer);
    10893        try {
    10994            SelectAction action = new SelectActionMock(Main.map, dataSet, layer);
  • test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java
    index d58ebf7..159a7fe 100644
    a b import java.io.InputStream;  
    77import java.util.List;
    88
    99import org.junit.Assert;
    10 import org.junit.BeforeClass;
     10import org.junit.Before;
     11import org.junit.Rule;
    1112import org.junit.Test;
    12 import org.openstreetmap.josm.Main;
    1313import org.openstreetmap.josm.data.osm.DataSet;
    1414import org.openstreetmap.josm.data.osm.Relation;
    1515import org.openstreetmap.josm.data.osm.RelationMember;
    16 import org.openstreetmap.josm.data.projection.Projections;
    1716import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1817import org.openstreetmap.josm.io.IllegalDataException;
    1918import org.openstreetmap.josm.io.OsmReader;
     19import org.openstreetmap.josm.testutils.JOSMTestRules;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2022
    2123/**
    2224 * Unit tests of {@link RelationSorter} class.
    import org.openstreetmap.josm.io.OsmReader;  
    2426public class RelationSorterTest {
    2527
    2628    private final RelationSorter sorter = new RelationSorter();
    27     private static DataSet testDataset;
     29    private DataSet testDataset;
     30
     31    /**
     32     * Use Mercator projection
     33     */
     34    @Rule
     35    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     36    public JOSMTestRules test = new JOSMTestRules().preferences().projection();
    2837
    29     @BeforeClass
    30     public static void loadData() throws IllegalDataException, IOException {
    31         Main.initApplicationPreferences();
    32         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    33         try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
    34             testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     38    /**
     39     * Load the test data set
     40     * @throws IllegalDataException
     41     * @throws IOException
     42     */
     43    @Before
     44    public void loadData() throws IllegalDataException, IOException {
     45        if (testDataset == null) {
     46            try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
     47                testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     48            }
    3549        }
    3650    }
    3751
  • test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java
    index c9ee5b1..536867d 100644
    a b import java.util.Arrays;  
    88import java.util.List;
    99
    1010import org.junit.Assert;
    11 import org.junit.BeforeClass;
     11import org.junit.Before;
     12import org.junit.Rule;
    1213import org.junit.Test;
    13 import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.data.osm.DataSet;
    1515import org.openstreetmap.josm.data.osm.Relation;
    16 import org.openstreetmap.josm.data.projection.Projections;
    1716import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1817import org.openstreetmap.josm.io.IllegalDataException;
    1918import org.openstreetmap.josm.io.OsmReader;
     19import org.openstreetmap.josm.testutils.JOSMTestRules;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2022
    2123/**
    2224 * Unit tests of {@link WayConnectionTypeCalculator} class.
    public class WayConnectionTypeCalculatorTest {  
    2527
    2628    private RelationSorter sorter = new RelationSorter();
    2729    private WayConnectionTypeCalculator wayConnectionTypeCalculator = new WayConnectionTypeCalculator();
    28     private static DataSet testDataset;
    29 
    30     @BeforeClass
    31     public static void loadData() throws IllegalDataException, IOException {
    32         Main.initApplicationPreferences();
    33         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    34         try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
    35             testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     30    private DataSet testDataset;
     31
     32    /**
     33     * Use Mercator projection
     34     */
     35    @Rule
     36    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     37    public JOSMTestRules test = new JOSMTestRules().preferences().projection();
     38
     39    /**
     40     * Load the test data set
     41     * @throws IllegalDataException
     42     * @throws IOException
     43     */
     44    @Before
     45    public void loadData() throws IllegalDataException, IOException {
     46        if (testDataset == null) {
     47            try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
     48                testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     49            }
    3650        }
    3751    }
    3852
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index 634b625..49b6536 100644
    a b public class JOSMTestRules implements TestRule {  
    200200
    201201        // Add preferences
    202202        if (usePreferences) {
    203             Main.initApplicationPreferences();
     203            Main.pref.resetToInitialState();
    204204            Main.pref.enableSaveOnPut(false);
    205205            // No pref init -> that would only create the preferences file.
    206206            // We force the use of a wrong API server, just in case anyone attempts an upload
    public class JOSMTestRules implements TestRule {  
    246246    private void cleanUpFromJosmFixture() {
    247247        MemoryManagerTest.resetState(true);
    248248        Main.getLayerManager().resetState();
    249         Main.pref = null;
     249        Main.pref.resetToInitialState();
    250250        Main.platform = null;
    251251        System.gc();
    252252    }
    public class JOSMTestRules implements TestRule {  
    267267        MemoryManagerTest.resetState(allowMemoryManagerLeaks);
    268268
    269269        // TODO: Remove global listeners and other global state.
    270         Main.pref = null;
     270        Main.pref.resetToInitialState();;
    271271        Main.platform = null;
    272272        // Parts of JOSM uses weak references - destroy them.
    273273        System.gc();