Skip to content

Commit

Permalink
JBIDE-17890: Support for #/projectName in Forge 2 console
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 25, 2014
1 parent 6e7720e commit 4c46907
Showing 1 changed file with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.jboss.forge.addon.resource.Resource;
import org.jboss.forge.addon.resource.ResourceFactory;
import org.jboss.forge.addon.shell.spi.command.CdTokenHandler;
Expand All @@ -14,26 +16,34 @@
* Handles the '#' workspace shortcut character in JBossTools Forge CLI
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public class WorkspaceCdTokenHandler implements CdTokenHandler
{
private ResourceFactory resourceFactory;
public class WorkspaceCdTokenHandler implements CdTokenHandler {
private ResourceFactory resourceFactory;

public WorkspaceCdTokenHandler(ResourceFactory resourceFactory)
{
this.resourceFactory = resourceFactory;
}
public WorkspaceCdTokenHandler(ResourceFactory resourceFactory) {
this.resourceFactory = resourceFactory;
}

@Override
public List<Resource<?>> getNewCurrentResources(UIContext context, String token)
{
List<Resource<?>> result = new ArrayList<>();
if (token.startsWith("#"))
{
File file = ResourcesPlugin.getWorkspace().getRoot().getLocation().makeAbsolute().toFile();
Resource<File> resource = resourceFactory.create(new File(file, token.replaceFirst("#", "")));
result.add(resource);
}
return result;
}
@Override
public List<Resource<?>> getNewCurrentResources(UIContext context,
String token) {
List<Resource<?>> result = new ArrayList<>();
if (token.startsWith("#")) {
IPath location;
String projectName = token.replaceFirst("#/?", "");
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (projectName.isEmpty()) {
location = root.getLocation();
} else {
location = root.getProject(projectName).getLocation();
}
if (location != null) {
File file = location.makeAbsolute().toFile();
Resource<File> resource = resourceFactory.create(file);
result.add(resource);
}
}
return result;
}
}

1 comment on commit 4c46907

@lincolnthree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Good fix for this! :D

Please sign in to comment.