@Test public void testFindByBundleIdentifier() { ApplicationFinder f = new LaunchServicesApplicationFinder(); assertEquals(new Application("com.apple.Preview", "Preview"), f.getDescription("com.apple.Preview")); assertEquals(Application.notfound, f.getDescription("com.apple.Preview_")); }
@Override public Application getDescription(final String search) { if(applicationNameCache.contains(search)) { return applicationNameCache.get(search); } if(log.isDebugEnabled()) { log.debug(String.format("Find application for %s", search)); } final String identifier; final String name; synchronized(NSWorkspace.class) { final NSWorkspace workspace = NSWorkspace.sharedWorkspace(); final String path; if(null != workspace.absolutePathForAppBundleWithIdentifier(search)) { path = workspace.absolutePathForAppBundleWithIdentifier(search); } else { log.warn(String.format("Cannot determine installation path for bundle identifier %s. Try with name.", search)); path = workspace.fullPathForApplication(search); } if(StringUtils.isNotBlank(path)) { final NSBundle app = NSBundle.bundleWithPath(path); if(null == app) { log.error(String.format("Loading bundle %s failed", path)); identifier = search; name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { NSDictionary dict = app.infoDictionary(); if(null == dict) { log.error(String.format("Loading application dictionary for bundle %s failed", path)); applicationNameCache.put(search, Application.notfound); return null; } else { final NSObject bundlename = dict.objectForKey("CFBundleName"); if(null == bundlename) { log.warn(String.format("No CFBundleName in bundle %s", path)); name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { name = bundlename.toString(); } final NSObject bundleIdentifier = dict.objectForKey("CFBundleIdentifier"); if(null == bundleIdentifier) { log.warn(String.format("No CFBundleName in bundle %s", path)); identifier = search; } else { identifier = bundleIdentifier.toString(); } } } } else { log.warn(String.format("Cannot determine installation path for %s", search)); applicationNameCache.put(search, Application.notfound); return Application.notfound; } } final Application application = new Application(identifier, name); applicationNameCache.put(search, application); return application; }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application getDescription(final String search) { if(applicationNameCache.contains(search)) { return applicationNameCache.get(search); } if(log.isDebugEnabled()) { log.debug(String.format("Find application for %s", search)); } final String identifier; final String name; synchronized(NSWorkspace.class) { final NSWorkspace workspace = NSWorkspace.sharedWorkspace(); final String path; if(null != workspace.absolutePathForAppBundleWithIdentifier(search)) { path = workspace.absolutePathForAppBundleWithIdentifier(search); } else { log.warn(String.format("Cannot determine installation path for bundle identifier %s. Try with name.", search)); path = workspace.fullPathForApplication(search); } if(StringUtils.isNotBlank(path)) { final NSBundle app = NSBundle.bundleWithPath(path); if(null == app) { log.error(String.format("Loading bundle %s failed", path)); identifier = search; name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { NSDictionary dict = app.infoDictionary(); if(null == dict) { log.error(String.format("Loading application dictionary for bundle %s failed", path)); applicationNameCache.put(search, Application.notfound); return null; } else { final NSObject bundlename = dict.objectForKey("CFBundleName"); if(null == bundlename) { log.warn(String.format("No CFBundleName in bundle %s", path)); name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { name = bundlename.toString(); } final NSObject bundleIdentifier = dict.objectForKey("CFBundleIdentifier"); if(null == bundleIdentifier) { log.warn(String.format("No CFBundleName in bundle %s", path)); identifier = search; } else { identifier = bundleIdentifier.toString(); } } } } else { log.warn(String.format("Cannot determine installation path for %s", search)); applicationNameCache.put(search, Application.notfound); return Application.notfound; } } final Application application = new Application(identifier, name); applicationNameCache.put(search, application); return application; } }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application getDescription(final String search) { if(applicationNameCache.contains(search)) { return applicationNameCache.get(search); } if(log.isDebugEnabled()) { log.debug(String.format("Find application for %s", search)); } final String identifier; final String name; synchronized(NSWorkspace.class) { final NSWorkspace workspace = NSWorkspace.sharedWorkspace(); final String path; if(null != workspace.absolutePathForAppBundleWithIdentifier(search)) { path = workspace.absolutePathForAppBundleWithIdentifier(search); } else { log.warn(String.format("Cannot determine installation path for bundle identifier %s. Try with name.", search)); path = workspace.fullPathForApplication(search); } if(StringUtils.isNotBlank(path)) { final NSBundle app = NSBundle.bundleWithPath(path); if(null == app) { log.error(String.format("Loading bundle %s failed", path)); identifier = search; name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { NSDictionary dict = app.infoDictionary(); if(null == dict) { log.error(String.format("Loading application dictionary for bundle %s failed", path)); applicationNameCache.put(search, Application.notfound); return null; } else { final NSObject bundlename = dict.objectForKey("CFBundleName"); if(null == bundlename) { log.warn(String.format("No CFBundleName in bundle %s", path)); name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { name = bundlename.toString(); } final NSObject bundleIdentifier = dict.objectForKey("CFBundleIdentifier"); if(null == bundleIdentifier) { log.warn(String.format("No CFBundleName in bundle %s", path)); identifier = search; } else { identifier = bundleIdentifier.toString(); } } } } else { log.warn(String.format("Cannot determine installation path for %s", search)); applicationNameCache.put(search, Application.notfound); return Application.notfound; } } final Application application = new Application(identifier, name); applicationNameCache.put(search, application); return application; } LaunchServicesApplicationFinder(); }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application getDescription(final String search) { if(applicationNameCache.contains(search)) { return applicationNameCache.get(search); } if(log.isDebugEnabled()) { log.debug(String.format("Find application for %s", search)); } final String identifier; final String name; synchronized(NSWorkspace.class) { final NSWorkspace workspace = NSWorkspace.sharedWorkspace(); final String path; if(null != workspace.absolutePathForAppBundleWithIdentifier(search)) { path = workspace.absolutePathForAppBundleWithIdentifier(search); } else { log.warn(String.format("Cannot determine installation path for bundle identifier %s. Try with name.", search)); path = workspace.fullPathForApplication(search); } if(StringUtils.isNotBlank(path)) { final NSBundle app = NSBundle.bundleWithPath(path); if(null == app) { log.error(String.format("Loading bundle %s failed", path)); identifier = search; name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { NSDictionary dict = app.infoDictionary(); if(null == dict) { log.error(String.format("Loading application dictionary for bundle %s failed", path)); applicationNameCache.put(search, Application.notfound); return null; } else { final NSObject bundlename = dict.objectForKey("CFBundleName"); if(null == bundlename) { log.warn(String.format("No CFBundleName in bundle %s", path)); name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { name = bundlename.toString(); } final NSObject bundleIdentifier = dict.objectForKey("CFBundleIdentifier"); if(null == bundleIdentifier) { log.warn(String.format("No CFBundleName in bundle %s", path)); identifier = search; } else { identifier = bundleIdentifier.toString(); } } } } else { log.warn(String.format("Cannot determine installation path for %s", search)); applicationNameCache.put(search, Application.notfound); return Application.notfound; } } final Application application = new Application(identifier, name); applicationNameCache.put(search, application); return application; } LaunchServicesApplicationFinder(); @Override List<Application> findAll(final String filename); @Override Application find(final String filename); @Override Application getDescription(final String search); @Override boolean isInstalled(final Application application); boolean register(final Local application); }
LaunchServicesApplicationFinder implements ApplicationFinder { @Override public Application getDescription(final String search) { if(applicationNameCache.contains(search)) { return applicationNameCache.get(search); } if(log.isDebugEnabled()) { log.debug(String.format("Find application for %s", search)); } final String identifier; final String name; synchronized(NSWorkspace.class) { final NSWorkspace workspace = NSWorkspace.sharedWorkspace(); final String path; if(null != workspace.absolutePathForAppBundleWithIdentifier(search)) { path = workspace.absolutePathForAppBundleWithIdentifier(search); } else { log.warn(String.format("Cannot determine installation path for bundle identifier %s. Try with name.", search)); path = workspace.fullPathForApplication(search); } if(StringUtils.isNotBlank(path)) { final NSBundle app = NSBundle.bundleWithPath(path); if(null == app) { log.error(String.format("Loading bundle %s failed", path)); identifier = search; name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { NSDictionary dict = app.infoDictionary(); if(null == dict) { log.error(String.format("Loading application dictionary for bundle %s failed", path)); applicationNameCache.put(search, Application.notfound); return null; } else { final NSObject bundlename = dict.objectForKey("CFBundleName"); if(null == bundlename) { log.warn(String.format("No CFBundleName in bundle %s", path)); name = FilenameUtils.removeExtension(new FinderLocal(path).getDisplayName()); } else { name = bundlename.toString(); } final NSObject bundleIdentifier = dict.objectForKey("CFBundleIdentifier"); if(null == bundleIdentifier) { log.warn(String.format("No CFBundleName in bundle %s", path)); identifier = search; } else { identifier = bundleIdentifier.toString(); } } } } else { log.warn(String.format("Cannot determine installation path for %s", search)); applicationNameCache.put(search, Application.notfound); return Application.notfound; } } final Application application = new Application(identifier, name); applicationNameCache.put(search, application); return application; } LaunchServicesApplicationFinder(); @Override List<Application> findAll(final String filename); @Override Application find(final String filename); @Override Application getDescription(final String search); @Override boolean isInstalled(final Application application); boolean register(final Local application);  }