Skip to content

Commit

Permalink
Merge branch 'sbryzak-FORGE-1727'
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jun 23, 2014
2 parents d49882c + b8c14cf commit 96a2804
Show file tree
Hide file tree
Showing 18 changed files with 1,296 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import org.jboss.forge.addon.resource.AbstractFileResource;
import org.jboss.forge.addon.resource.DefaultFileOperations;
import org.jboss.forge.addon.resource.FileOperations;
import org.jboss.forge.addon.resource.ResourceOperations;
import org.jboss.forge.addon.resource.Resource;
import org.jboss.forge.addon.resource.ResourceFactory;
import org.jboss.forge.addon.resource.ResourceFilter;
Expand Down Expand Up @@ -85,9 +85,9 @@ public ResourceTransaction getTransaction()
}

@Override
public FileOperations getFileOperations()
public <T> ResourceOperations<T> getResourceOperations(Class<T> type)
{
return DefaultFileOperations.INSTANCE;
return (ResourceOperations<T>) DefaultFileOperations.INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jboss.forge.addon.projects.facets.MetadataFacet;
import org.jboss.forge.addon.projects.facets.PackagingFacet;
import org.jboss.forge.addon.resource.DirectoryResource;
import org.jboss.forge.addon.resource.PathResource;
import org.jboss.forge.addon.resource.Resource;
import org.jboss.forge.addon.resource.ResourceFactory;
import org.jboss.forge.addon.ui.context.UIBuilder;
Expand All @@ -30,6 +31,7 @@
import org.jboss.forge.addon.ui.context.UINavigationContext;
import org.jboss.forge.addon.ui.context.UISelection;
import org.jboss.forge.addon.ui.context.UIValidationContext;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.SingleValued;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UISelectOne;
Expand Down Expand Up @@ -75,8 +77,8 @@ public class NewProjectWizardImpl implements UIWizard, NewProjectWizard
private UIInput<String> finalName;

@Inject
@WithAttributes(label = "Project location")
private UIInput<DirectoryResource> targetLocation;
@WithAttributes(label = "Project location", type = InputType.DIRECTORY_PICKER)
private UIInput<Resource> targetLocation;

@Inject
@WithAttributes(label = "Overwrite existing project location")
Expand Down Expand Up @@ -362,10 +364,12 @@ public void validate(UIValidationContext context)
public Result execute(UIExecutionContext context) throws Exception
{
Result result = Results.success("Project named '" + named.getValue() + "' has been created.");
DirectoryResource directory = targetLocation.getValue();
DirectoryResource targetDir = directory.getChildDirectory(named.getValue());
Resource directory = targetLocation.getValue();
Resource targetDir = directory.getChild(named.getValue());

if (targetDir.mkdirs() || overwrite.getValue())
if ((DirectoryResource.class.isInstance(targetDir) && ((DirectoryResource)targetDir).mkdirs()) ||
(PathResource.class.isInstance(targetDir) && ((PathResource)targetDir).mkdirs()) ||
overwrite.getValue())
{
ProjectType value = type.getValue();

Expand Down Expand Up @@ -410,7 +414,7 @@ public UIInput<String> getNamed()
return named;
}

public UIInput<DirectoryResource> getTargetLocation()
public UIInput<Resource> getTargetLocation()
{
return targetLocation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public Resource<?> getChild(final String name)
@Override
public boolean exists()
{
return getFileOperations().fileExists(file);
return getFileOperations().resourceExists(file);
}

@Override
public boolean isDirectory()
{
return getFileOperations().fileExistsAndIsDirectory(file);
return getFileOperations().resourceExistsAndIsDirectory(file);
}

@Override
Expand Down Expand Up @@ -138,7 +138,7 @@ public boolean delete(final boolean recursive)
return false;
}

File[] listFiles = getFileOperations().listFiles(file);
File[] listFiles = getFileOperations().listResources(file);
if ((listFiles != null) && (listFiles.length != 0))
{
throw new RuntimeException("directory not empty");
Expand All @@ -149,7 +149,7 @@ public boolean delete(final boolean recursive)
System.gc(); // ensure no lingering handles that would prevent deletion
}

if (getFileOperations().deleteFile(file))
if (getFileOperations().deleteResource(file))
{
return true;
}
Expand All @@ -159,7 +159,7 @@ public boolean delete(final boolean recursive)
@Override
public void deleteOnExit()
{
getFileOperations().deleteFileOnExit(file);
getFileOperations().deleteResourceOnExit(file);
}

private boolean _deleteRecursive(final File file, final boolean collect)
Expand All @@ -174,26 +174,26 @@ private boolean _deleteRecursive(final File file, final boolean collect)
return false;
}

File[] children = getFileOperations().listFiles(file);
File[] children = getFileOperations().listResources(file);
if (children != null)
{
for (File sf : children)
{
if (getFileOperations().fileExistsAndIsDirectory(sf))
if (getFileOperations().resourceExistsAndIsDirectory(sf))
{
_deleteRecursive(sf, false);
}
else
{
if (!getFileOperations().deleteFile(sf))
if (!getFileOperations().deleteResource(sf))
{
throw new RuntimeException("failed to delete: " + sf.getAbsolutePath());
}
}
}
}

return getFileOperations().deleteFile(file);
return getFileOperations().deleteResource(file);
}

@Override
Expand Down Expand Up @@ -274,7 +274,7 @@ public boolean createNewFile()
try
{
getParent().mkdirs();
if (getFileOperations().createNewFile(file))
if (getFileOperations().createNewResource(file))
{
return true;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ public boolean renameTo(final FileResource<?> target)

private boolean renameTo(final File target)
{
if (getFileOperations().renameFile(file, target))
if (getFileOperations().renameResource(file, target))
{
file = target;
return true;
Expand All @@ -326,25 +326,25 @@ private boolean renameTo(final File target)
@Override
public long getSize()
{
return getFileOperations().getFileLength(file);
return getFileOperations().getResourceLength(file);
}

@Override
public boolean isExecutable()
{
return (this.file.canExecute() && !getFileOperations().fileExistsAndIsDirectory(file));
return (this.file.canExecute() && !getFileOperations().resourceExistsAndIsDirectory(file));
}

@Override
public boolean isReadable()
{
return (this.file.canRead() && !getFileOperations().fileExistsAndIsDirectory(file));
return (this.file.canRead() && !getFileOperations().resourceExistsAndIsDirectory(file));
}

@Override
public boolean isWritable()
{
return (this.file.canWrite() && !getFileOperations().fileExistsAndIsDirectory(file));
return (this.file.canWrite() && !getFileOperations().resourceExistsAndIsDirectory(file));
}

@Override
Expand All @@ -365,9 +365,9 @@ public ResourceMonitor monitor(ResourceFilter filter)
return getResourceFactory().monitor(this, filter);
}

protected FileOperations getFileOperations()
protected ResourceOperations<File> getFileOperations()
{
return getResourceFactory().getFileOperations();
return getResourceFactory().<File>getResourceOperations(File.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,52 @@
import org.jboss.forge.furnace.util.Streams;

/**
* Default implementation for {@link FileOperations} interface
* Default implementation for {@link File} based {@link ResourceOperations} interface
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public enum DefaultFileOperations implements FileOperations
public enum DefaultFileOperations implements ResourceOperations<File>
{
INSTANCE;

@Override
public boolean fileExists(File f)
public boolean resourceExists(File f)
{
return f.exists();
}

@Override
public boolean fileExistsAndIsDirectory(File f)
public boolean resourceExistsAndIsDirectory(File f)
{
return f.isDirectory();
}

@Override
public File[] listFiles(File f)
public File[] listResources(File f)
{
return f.listFiles();
}

@Override
public long getFileLength(File f)
public long getResourceLength(File f)
{
return f.length();
}

@Override
public boolean deleteFile(File file)
public boolean deleteResource(File file)
{
return file.delete();
}

@Override
public void deleteFileOnExit(File file)
public void deleteResourceOnExit(File file)
{
file.deleteOnExit();
}

@Override
public boolean createNewFile(File file) throws IOException
public boolean createNewResource(File file) throws IOException
{
return file.createNewFile();
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public InputStream createInputStream(File file) throws IOException
}

@Override
public boolean renameFile(File srcFile, File destFile)
public boolean renameResource(File srcFile, File destFile)
{
if (srcFile == null)
{
Expand All @@ -109,7 +109,7 @@ public boolean renameFile(File srcFile, File destFile)
}

@Override
public void copyFile(File srcFile, File destFile) throws IOException
public void copyResource(File srcFile, File destFile) throws IOException
{
if (srcFile == null)
{
Expand Down
Loading

0 comments on commit 96a2804

Please sign in to comment.