Changeset 17663 in josm


Ignore:
Timestamp:
2021-03-25T01:56:53+01:00 (3 years ago)
Author:
Don-vip
Message:

see #18737 - add JNLP robustness in order to be able to quit unsigned JAR with OpenWebStart and display about screen

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AboutAction.java

    r17188 r17663  
    22package org.openstreetmap.josm.actions;
    33
     4import static java.awt.GridBagConstraints.HORIZONTAL;
     5import static javax.swing.SwingConstants.CENTER;
    46import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    57import static org.openstreetmap.josm.tools.I18n.tr;
     
    105107                "<p style='font-size:50%'></p>" +
    106108                "</html>");
    107         info.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 10));
     109        info.add(label, GBC.eol().fill(HORIZONTAL).insets(10, 0, 0, 10));
    108110        info.add(new JLabel(tr("Homepage")), GBC.std().insets(10, 0, 10, 0));
    109111        info.add(new UrlLabel(Config.getUrls().getJOSMWebsite(), 2), GBC.eol());
     
    121123
    122124        JPanel inst = new JPanel(new GridBagLayout());
    123         final String pathToPreferences = ShowStatusReportAction
    124                 .paramCleanup(Preferences.main().getPreferenceFile().getAbsolutePath());
    125         inst.add(new JLabel(tr("Preferences are stored in {0}", pathToPreferences)), GBC.eol().insets(0, 0, 0, 10));
     125        inst.add(new JLabel(tr("Preferences are stored in {0}", getPathToPreferences())), GBC.eol().insets(0, 0, 0, 10));
    126126        inst.add(new JLabel(tr("Symbolic names for directories and the actual paths:")),
    127127                GBC.eol().insets(0, 0, 0, 10));
     
    147147        JPanel panel = new JPanel(new GridBagLayout());
    148148        panel.setPreferredSize(new Dimension(890, 300));
    149         panel.add(new JLabel("", ImageProvider.get("logo.svg", ImageProvider.ImageSizes.ABOUT_LOGO),
    150                 JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
     149        panel.add(new JLabel("", ImageProvider.get("logo.svg", ImageSizes.ABOUT_LOGO), CENTER), GBC.std().insets(0, 5, 0, 0));
    151150        panel.add(about, GBC.std().fill());
    152151        return panel;
     152    }
     153
     154    private static String getPathToPreferences() {
     155        File preferenceFile = Preferences.main().getPreferenceFile();
     156        try {
     157            return ShowStatusReportAction.paramCleanup(preferenceFile.getAbsolutePath());
     158        } catch (SecurityException e) {
     159            Logging.warn(e);
     160            return ShowStatusReportAction.paramCleanup(preferenceFile.getPath());
     161        }
    153162    }
    154163
     
    176185            putValue(Action.NAME, "...");
    177186            this.dir = dir;
    178             setEnabled(dir != null && new File(dir).isDirectory());
     187            try {
     188                setEnabled(dir != null && new File(dir).isDirectory());
     189            } catch (SecurityException e) {
     190                setEnabled(false);
     191                Logging.warn(e);
     192            }
    179193        }
    180194
     
    209223        dirLabel.setFont(GuiHelper.getMonospacedFont(dirLabel));
    210224        dirLabel.setOpaque(false);
    211         inst.add(dirLabel, GBC.std().fill(GBC.HORIZONTAL));
     225        inst.add(dirLabel, GBC.std().fill(HORIZONTAL));
    212226        JButton btn = new JButton(new OpenDirAction(dir));
    213227        btn.setToolTipText(tr("Open directory"));
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r17369 r17663  
    4242 */
    4343public final class JCSCacheManager {
    44     private static final long maxObjectTTL = -1;
     44    private static final long MAX_OBJECT_TTL = -1;
    4545    private static final String PREFERENCE_PREFIX = "jcs.cache";
     46
     47    /**
     48     * Property that determines the disk cache implementation
     49     */
    4650    public static final BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true);
    4751
    48     private static final AuxiliaryCacheFactory DISK_CACHE_FACTORY =
    49             USE_BLOCK_CACHE.get() ? new BlockDiskCacheFactory() : new IndexedDiskCacheFactory();
     52    private static final AuxiliaryCacheFactory DISK_CACHE_FACTORY = getDiskCacheFactory();
    5053    private static FileLock cacheDirLock;
    5154
     
    139142        props.setProperty("jcs.default.elementattributes",                    CacheEntryAttributes.class.getCanonicalName());
    140143        props.setProperty("jcs.default.elementattributes.IsEternal",          "false");
    141         props.setProperty("jcs.default.elementattributes.MaxLife",            Long.toString(maxObjectTTL));
    142         props.setProperty("jcs.default.elementattributes.IdleTime",           Long.toString(maxObjectTTL));
     144        props.setProperty("jcs.default.elementattributes.MaxLife",            Long.toString(MAX_OBJECT_TTL));
     145        props.setProperty("jcs.default.elementattributes.IdleTime",           Long.toString(MAX_OBJECT_TTL));
    143146        props.setProperty("jcs.default.elementattributes.IsSpool",            "true");
    144147        // CHECKSTYLE.ON: SingleSpaceSeparator
     
    148151            Logging.log(Logging.LEVEL_WARN, "Unable to initialize JCS", e);
    149152        }
     153    }
     154
     155    private static AuxiliaryCacheFactory getDiskCacheFactory() {
     156        try {
     157            return useBlockCache() ? new BlockDiskCacheFactory() : new IndexedDiskCacheFactory();
     158        } catch (SecurityException | LinkageError e) {
     159            Logging.error(e);
     160            return null;
     161        }
     162    }
     163
     164    private static boolean useBlockCache() {
     165        return USE_BLOCK_CACHE.get() == Boolean.TRUE;
    150166    }
    151167
     
    173189    @SuppressWarnings("unchecked")
    174190    public static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) {
    175         CacheAccess<K, V> cacheAccess = JCS.getInstance(cacheName, getCacheAttributes(maxMemoryObjects));
    176         CompositeCache<K, V> cc = cacheAccess.getCacheControl();
    177 
    178         if (cachePath != null && cacheDirLock != null) {
    179             IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName);
     191        CacheAccess<K, V> cacheAccess = getCacheAccess(cacheName, getCacheAttributes(maxMemoryObjects));
     192
     193        if (cachePath != null && cacheDirLock != null && cacheAccess != null && DISK_CACHE_FACTORY != null) {
     194            CompositeCache<K, V> cc = cacheAccess.getCacheControl();
    180195            try {
     196                IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName);
    181197                if (cc.getAuxCaches().length == 0) {
    182198                    cc.setAuxCaches(new AuxiliaryCache[]{DISK_CACHE_FACTORY.createCache(
     
    192208    }
    193209
     210    private static <K, V> CacheAccess<K, V> getCacheAccess(String cacheName, CompositeCacheAttributes cacheAttributes) {
     211        try {
     212            return JCS.getInstance(cacheName, cacheAttributes);
     213        } catch (SecurityException | LinkageError e) {
     214            Logging.error(e);
     215            return null;
     216        }
     217    }
     218
    194219    /**
    195220     * Close all files to ensure, that all indexes and data are properly written
     
    201226    private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName) {
    202227        IDiskCacheAttributes ret;
    203         removeStaleFiles(cachePath + File.separator + cacheName, USE_BLOCK_CACHE.get() ? "_INDEX_v2" : "_BLOCK_v2");
    204         String newCacheName = cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK_v2" : "_INDEX_v2");
    205 
    206         if (USE_BLOCK_CACHE.get()) {
     228        removeStaleFiles(cachePath + File.separator + cacheName, useBlockCache() ? "_INDEX_v2" : "_BLOCK_v2");
     229        String newCacheName = cacheName + (useBlockCache() ? "_BLOCK_v2" : "_INDEX_v2");
     230
     231        if (useBlockCache()) {
    207232            BlockDiskCacheAttributes blockAttr = new BlockDiskCacheAttributes();
    208233            /*
  • trunk/src/org/openstreetmap/josm/spi/lifecycle/Lifecycle.java

    r16995 r17663  
    7979            }
    8080            // asynchronous initializations to be completed eventually
    81             initSequence.asynchronousRunnableTasks().forEach(service::submit);
    82             initSequence.asynchronousCallableTasks().forEach(service::submit);
     81            initSequence.asynchronousRunnableTasks().forEach(x -> {
     82                if (x != null) service.submit(x);
     83            });
     84            initSequence.asynchronousCallableTasks().forEach(x -> {
     85                if (x != null) service.submit(x);
     86            });
    8387            try {
    8488                service.shutdown();
Note: See TracChangeset for help on using the changeset viewer.