Skip to content

Commit

Permalink
Ensure that file:${project_loc:/project}/my.target validates on Windo…
Browse files Browse the repository at this point in the history
…ws (#122)

as a location URI in  the 'Create target reference' page

Also provide choices of available workspace *.target files in the
drop-down of the 'Create target reference' page

#121
  • Loading branch information
merks authored May 23, 2022
1 parent ffcbbec commit f1bb7c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()]);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f1bb7c1

Please sign in to comment.