diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/RemoteTargetHandle.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/RemoteTargetHandle.java index 259af094c2..11ea6dc0ac 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/RemoteTargetHandle.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/RemoteTargetHandle.java @@ -108,11 +108,17 @@ public ITargetDefinition getTargetDefinition() throws CoreException { return definition; } + public static URI getEffectiveUri(String uri) throws CoreException, URISyntaxException { + Objects.requireNonNull(uri); + IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); + URI resolvedUri = new URI(convertRawToUri(manager.performStringSubstitution(uri))); + return resolvedUri; + } + public static RemoteTargetHandle get(String uri) throws CoreException { Objects.requireNonNull(uri); try { - IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); - URI resolvedUri = new URI(convertRawToUri(manager.performStringSubstitution(uri))); + URI resolvedUri = getEffectiveUri(uri); RemoteTargetHandle handle = REMOTE_HANDLES.computeIfAbsent(resolvedUri, RemoteTargetHandle::new); synchronized (handle) { if (handle.state != RemoteState.EXISTS) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java index 7221cb31e6..cd2baffbf0 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java @@ -20,16 +20,17 @@ import java.net.*; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.debug.ui.StringVariableSelectionDialog; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.osgi.util.NLS; import org.eclipse.pde.core.target.*; -import org.eclipse.pde.internal.core.target.TargetReferenceBundleContainer; -import org.eclipse.pde.internal.core.target.WorkspaceFileTargetHandle; +import org.eclipse.pde.internal.core.PDECore; +import org.eclipse.pde.internal.core.target.*; import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.internal.ui.SWTFactory; import org.eclipse.swt.SWT; @@ -204,6 +205,19 @@ private String[] getLocationComboItems() { WorkspaceFileTargetHandle wsHandle = (WorkspaceFileTargetHandle) handle; String name = wsHandle.getTargetFile().getProject().getName(); previousLocations.add(String.format("file:${project_loc:/%s}/", name)); //$NON-NLS-1$ + + for (ITargetHandle targetHandle : PDECore.getDefault().acquireService(ITargetPlatformService.class) + .getTargets(new NullProgressMonitor())) { + if (!handle.equals(targetHandle) && targetHandle instanceof WorkspaceFileTargetHandle) { + IFile targetFile = ((WorkspaceFileTargetHandle) targetHandle).getTargetFile(); + String location = String.format("file:${project_loc:/%s}/%s", targetFile.getProject().getName(), //$NON-NLS-1$ + targetFile.getProjectRelativePath()); + if (!previousLocations.contains(location)) { + previousLocations.add(location); + } + } + } + } return previousLocations.toArray(new String[previousLocations.size()]); } @@ -260,28 +274,28 @@ protected boolean validateInput() { } // Resolve any variables - String locationString; + URI location; try { - locationString = VariablesPlugin.getDefault().getStringVariableManager() - .performStringSubstitution(furiLocation.getText().trim()); + location = RemoteTargetHandle.getEffectiveUri(furiLocation.getText().trim()); } catch (CoreException e) { setMessage(e.getMessage(), IMessageProvider.WARNING); return true; + } catch (URISyntaxException e) { + setMessage(e.getMessage(), IMessageProvider.ERROR); + return false; } try { - // check that it could be parsed as an URI - URI uri = new URI(locationString); // and be converted to an URL - URL url = uri.toURL(); + URL url = location.toURL(); if ("file".equalsIgnoreCase(url.getProtocol())) { //$NON-NLS-1$ - File file = new File(uri); + File file = new File(location); if (!file.isFile()) { setMessage(NLS.bind(Messages.EditTargetContainerPage_Not_A_File, file.getAbsolutePath()), IMessageProvider.WARNING); return true; } } - } catch (URISyntaxException | MalformedURLException | RuntimeException e) { + } catch (MalformedURLException | RuntimeException e) { setMessage(e.getMessage(), IMessageProvider.ERROR); return false; }