use of org.eclipse.osgi.service.datalocation.Location in project rt.equinox.framework by eclipse.
the class BasicLocationTests method doAllTestLocationDataArea.
private void doAllTestLocationDataArea(Location location, String dataAreaPrefix) {
doTestLocateDataArea(location, dataAreaPrefix, getName());
doTestLocateDataArea(location, dataAreaPrefix, "");
doTestLocateDataArea(location, dataAreaPrefix, "test/multiple/paths");
doTestLocateDataArea(location, dataAreaPrefix, "test/multiple/../paths");
doTestLocateDataArea(location, dataAreaPrefix, "test\\multiple\\paths");
doTestLocateDataArea(location, dataAreaPrefix, "/test/begin/slash");
File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/" + getName());
Location createdLocation = location.createLocation(null, null, false);
try {
createdLocation.set(testLocationFile.toURL(), false);
} catch (Exception e) {
fail("Failed to set location", e);
}
doTestLocateDataArea(createdLocation, dataAreaPrefix, getName());
doTestLocateDataArea(createdLocation, dataAreaPrefix, "");
doTestLocateDataArea(createdLocation, dataAreaPrefix, "test/multiple/paths");
doTestLocateDataArea(createdLocation, dataAreaPrefix, "test/multiple/../paths");
doTestLocateDataArea(location, dataAreaPrefix, "test\\multiple\\paths");
doTestLocateDataArea(location, dataAreaPrefix, "/test/begin/slash");
createdLocation = location.createLocation(null, null, false);
try {
createdLocation.getDataArea("shouldFail");
fail("expected failure when location is not set");
} catch (IOException e) {
// expected;
}
}
use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.
the class DefaultRepositoryView method init.
/**
* {@inheritDoc}
*/
@Override
public void init(final IViewSite site) throws PartInitException {
super.init(site);
m_manager = null;
Location loc = Platform.getInstallLocation();
if (loc == null) {
LOGGER.error("Cannot detected KNIME installation directory");
return;
} else if (!loc.getURL().getProtocol().equals("file")) {
LOGGER.error("KNIME installation directory is not local");
return;
}
File instDir = new File(loc.getURL().getPath());
File customDefinition = new File(instDir, DEFINITION_FILE);
if (customDefinition.exists()) {
try {
m_manager = new CustomRepositoryManager(customDefinition);
setPartName(m_manager.getCustomName());
} catch (Exception ex) {
throw new PartInitException("Could not load custom repository content", ex);
}
}
}
use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.
the class KNIMESplashHandler method readSplashExtensions.
private List<IConfigurationElement> readSplashExtensions() {
// Get all splash handler extensions
IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(SPLASH_EXTENSION_ID).getExtensions();
List<IConfigurationElement> configElements = new ArrayList<IConfigurationElement>();
// add and check for duplicates
for (IExtension ext : extensions) {
for (IConfigurationElement elem : ext.getConfigurationElements()) {
String id1 = elem.getAttribute("id");
boolean exists = false;
if (id1 != null) {
// check if the same id already exists
for (IConfigurationElement elem2 : configElements) {
String id2 = elem2.getAttribute("id");
if (id1.equals(id2)) {
exists = true;
break;
}
}
}
if (!exists) {
configElements.add(elem);
}
}
}
// sort splash icons by name or by config file
Comparator<IConfigurationElement> comparator = new DefaultComparator();
Location loc = Platform.getInstallLocation();
if ((loc != null) && "file".equals(loc.getURL().getProtocol())) {
File instDir = new File(loc.getURL().getPath());
File splashConfig = new File(instDir, "splash.config");
if (splashConfig.exists()) {
try {
comparator = new ConfiguredComparator(splashConfig);
} catch (IOException ex) {
Bundle thisBundle = FrameworkUtil.getBundle(getClass());
Platform.getLog(thisBundle).log(new Status(IStatus.ERROR, thisBundle.getSymbolicName(), "Error while reading splash config file", ex));
}
}
}
Collections.sort(configElements, comparator);
return configElements;
}
use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.
the class KNIMEApplication method checkInstanceLocation.
/**
* Return true if a valid workspace path has been set and false otherwise.
* Prompt for and set the path if possible and required.
*
* @return true if a valid instance location has been set and false
* otherwise
*/
private boolean checkInstanceLocation() {
// -data @none was specified but an ide requires workspace
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null) {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceMandatoryTitle, IDEWorkbenchMessages.IDEApplication_workspaceMandatoryMessage);
return false;
}
// -data "/valid/path", workspace already set
if (instanceLoc.isSet()) {
// chosen to overwrite it).
if (!checkValidWorkspace(instanceLoc.getURL())) {
return false;
}
// metadata version information if successful
try {
if (instanceLoc.lock()) {
writeWorkspaceVersion();
return true;
}
// we failed to create the directory.
// Two possibilities:
// 1. directory is already in use
// 2. directory could not be created
File workspaceDirectory = new File(instanceLoc.getURL().getFile());
if (workspaceDirectory.exists()) {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage, workspaceDirectory.getAbsolutePath()));
} else {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}
} catch (IOException e) {
MessageDialog.openError(null, IDEWorkbenchMessages.InternalError, e.getMessage());
}
return false;
}
URL defaultLocation = instanceLoc.getDefault();
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
if (defaultLocation.getPath().contains("/Knime.app/")) {
URL url = Platform.getInstallLocation().getURL();
try {
defaultLocation = new URL(url.getProtocol(), url.getHost(), url.getPath() + "/workspace");
} catch (MalformedURLException ex) {
// should not happen
}
}
}
// -data @noDefault or -data not specified, prompt and set
ChooseWorkspaceData launchData = new ChooseWorkspaceData(defaultLocation);
boolean force = false;
while (true) {
URL workspaceUrl = promptForWorkspace(launchData, force);
if (workspaceUrl == null) {
return false;
}
// if there is an error with the first selection, then force the
// dialog to open to give the user a chance to correct
force = true;
try {
// instance data area, so other checking is unneeded
if (instanceLoc.set(workspaceUrl, true)) {
launchData.writePersistedData();
writeWorkspaceVersion();
return true;
}
// by this point it has been determined that the workspace is
// already in use -- force the user to choose again
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage, workspaceUrl.getPath()));
} catch (Exception e) {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}
}
}
use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.
the class ExampleWorkflowExtractor method run.
/**
* {@inheritDoc}
*/
@Override
public void run() {
Location loc = Platform.getInstallLocation();
if (loc == null) {
NodeLogger.getLogger(getClass()).error("Cannot detect KNIME installation directory");
return;
} else if (!loc.getURL().getProtocol().equals("file")) {
NodeLogger.getLogger(getClass()).error("KNIME installation directory is not local");
return;
}
String path = loc.getURL().getPath();
if (Platform.OS_WIN32.equals(Platform.getOS()) && path.matches("^/[a-zA-Z]:/.*")) {
// Windows path with drive letter => remove first slash
path = path.substring(1);
}
Path initialWorkspace = Paths.get(path, "knime-workspace.zip");
if (!Files.exists(initialWorkspace)) {
NodeLogger.getLogger(getClass()).warn(initialWorkspace.toAbsolutePath() + " not found in installation directory, not creating inital workspace");
return;
}
File workspace = KNIMEPath.getWorkspaceDirPath();
try (ZipInputStream is = new ZipInputStream(Files.newInputStream(initialWorkspace))) {
FileUtil.unzip(is, workspace, 0);
} catch (IOException ex) {
NodeLogger.getLogger(getClass()).error("Could not extract example workflows: " + ex.getMessage(), ex);
}
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
for (IWorkbenchPage page : window.getPages()) {
for (IViewReference ref : page.getViewReferences()) {
if (ExplorerView.ID.equals(ref.getId())) {
final ExplorerView explorer = (ExplorerView) ref.getView(true);
final TreeViewer viewer = explorer.getViewer();
if (viewer.getControl() != null && viewer.getControl().getDisplay() != null) {
viewer.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
viewer.refresh();
viewer.expandAll();
}
});
}
}
}
}
}
}
Aggregations