Ignore:
Timestamp:
2017-09-07T23:41:42+02:00 (2 years ago)
Author:
bastiK
Message:

see #15229 - remove dependency of NTV2GridShiftFileWrapper on Main.platform

  • PlatformHook bundles all application-wide platform dependent code, which is

convenient, but problematic for separating modules

  • introduces lightweight tools.Platform for adding platform dependent code more locally
Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/PlatformHook.java

    r12748 r12776  
    2020
    2121import org.openstreetmap.josm.Main;
     22import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper;
    2223import org.openstreetmap.josm.io.CertificateAmendment.CertAmend;
    2324import org.openstreetmap.josm.tools.date.DateUtils;
     
    2930 */
    3031public interface PlatformHook {
     32
     33    /**
     34     * Visitor to construct a PlatformHook from a given {@link Platform} object.
     35     */
     36    public static final PlatformVisitor<PlatformHook> CONSTRUCT_FROM_PLATFORM = new PlatformVisitor<PlatformHook>() {
     37        @Override
     38        public PlatformHook visitUnixoid() {
     39            return new PlatformHookUnixoid();
     40        }
     41
     42        @Override
     43        public PlatformHook visitWindows() {
     44            return new PlatformHookWindows();
     45        }
     46
     47        @Override
     48        public PlatformHook visitOsx() {
     49            return new PlatformHookUnixoid();
     50        }
     51    };
     52
     53    /**
     54     * Get the platform corresponding to this platform hook.
     55     * @return the platform corresponding to this platform hook
     56     */
     57    Platform getPlatform();
    3158
    3259    /**
     
    231258     * @since 11642
    232259     */
    233     List<File> getDefaultProj4NadshiftDirectories();
     260    default List<File> getDefaultProj4NadshiftDirectories() {
     261        return getPlatform().accept(NTV2GridShiftFileWrapper.DEFAULT_PROJ4_NTV2_SHIFT_DIRS);
     262    }
    234263
    235264    /**
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r12748 r12776  
    1515import java.lang.reflect.Proxy;
    1616import java.util.Arrays;
    17 import java.util.Collections;
    1817import java.util.List;
    1918import java.util.Objects;
     
    3231
    3332    private NativeOsCallback osCallback;
     33
     34    @Override
     35    public Platform getPlatform() {
     36        return Platform.OSX;
     37    }
    3438
    3539    @Override
     
    423427                Main.pref.getJOSMDirectoryBaseName());
    424428    }
    425 
    426     @Override
    427     public List<File> getDefaultProj4NadshiftDirectories() {
    428         return Collections.emptyList();
    429     }
    430429}
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r12620 r12776  
    2222import java.security.cert.X509Certificate;
    2323import java.util.Arrays;
    24 import java.util.List;
    2524import java.util.Locale;
    2625
     
    6665            "尚未安裝"                // zh_TW
    6766    };
     67
     68    @Override
     69    public Platform getPlatform() {
     70        return Platform.UNIXOID;
     71    }
    6872
    6973    @Override
     
    422426
    423427    @Override
    424     public List<File> getDefaultProj4NadshiftDirectories() {
    425         return Arrays.asList(new File("/usr/local/share/proj"), new File("/usr/share/proj"));
    426     }
    427 
    428     @Override
    429428    public X509Certificate getX509Certificate(CertAmend certAmend)
    430429            throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r12744 r12776  
    5858import java.security.spec.X509EncodedKeySpec;
    5959import java.util.ArrayList;
    60 import java.util.Arrays;
    6160import java.util.Collection;
    6261import java.util.Enumeration;
     
    155154
    156155    private String oSBuildNumber;
     156
     157    @Override
     158    public Platform getPlatform() {
     159        return Platform.WINDOWS;
     160    }
    157161
    158162    @Override
     
    673677        return def;
    674678    }
    675 
    676     @Override
    677     public List<File> getDefaultProj4NadshiftDirectories() {
    678         return Arrays.asList(new File("C:\\PROJ\\NAD"));
    679     }
    680679}
Note: See TracChangeset for help on using the changeset viewer.