Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ant/build.gant
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,10 @@ junit = { pluginName ->
compile("${pluginName}/test/junit", "build/test/junit/classes/${pluginName}"){
ant.compilerarg(value: '-Xlint:-options')
ant.include(name: '**/*.java')
ant.classpath{ant.pathelement(path: '${build.classes}/org.eclim')}
ant.classpath{
ant.pathelement(path: '${build.classes}/org.eclim')
ant.pathelement(path: '${build.classes}' + "/${pluginName}")
}
}

ant.path(id: 'junit'){
Expand All @@ -1130,6 +1133,7 @@ junit = { pluginName ->
ant.path(refid: 'junit')
ant.pathelement(path: "build/test/junit/classes/${pluginName}")
ant.pathelement(path: '${build.classes}/org.eclim')
ant.pathelement(path: '${build.classes}' + "/${pluginName}")
ant.fileset(dir: 'org.eclim/lib', includes: '*.jar', excludes: 'ant-*.jar')
}
ant.formatter(type: 'xml')
Expand All @@ -1141,6 +1145,8 @@ junit = { pluginName ->
ant.sysproperty(key: 'eclipse.home', value: '${eclipse}')
ant.sysproperty(key: 'eclim.version', value: '${eclim.version}')
ant.sysproperty(key: 'eclimd.port', value: '${nailgun.server.port}')
ant.sysproperty(key: 'http.server.port', value: '${http.server.port}')
ant.sysproperty(key: 'http.server.host', value: '${http.server.host}')
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* Copyright (C) 2005 - 2016 Eric Van Dewoestine
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.eclim.plugin.core.command.file;

import java.io.File;

import org.eclim.Services;
import org.eclim.annotation.Command;
import org.eclim.command.CommandException;
import org.eclim.command.CommandException.ErrorType;
import org.eclim.command.CommandLine;
import org.eclim.command.Options;
import org.eclim.logging.Logger;
import org.eclim.plugin.core.command.AbstractCommand;
import org.eclim.plugin.core.util.PathUtil;
import org.eclim.plugin.core.util.PathUtilException;

@Command(
name = "file_delete",
options =
"REQUIRED f relativeFilePath ARG," +
"REQUIRED p project ARG"
)

/**
* Command to delete a file.
*
* The <code>relativeFilePath</code> specifies the path relative to the
* <code>project</code> where the file/folder should be deleted.
*
* If the file is a directory, also all subdirectories will be deleted.
*
* Warning: you might have to update the <code>project</code> after calling this
* command.
*
*
* @author Lukas Roth
*
*/
public class FileDeleteCommand extends AbstractCommand
{
private static final Logger logger = Logger.getLogger(FileDeleteCommand.class);

@Override
public Object execute(CommandLine commandLine)
throws Exception
{
String relativeFilePath = commandLine.getValue(Options.FILE_OPTION);
String projectName = commandLine.getValue(Options.PROJECT_OPTION);
return fileDelete(relativeFilePath, projectName);
}

public Object fileDelete(String relativeFilePath, String projectName)
{
try {
PathUtil.checkPathForEscaping(relativeFilePath);
} catch (PathUtilException e) {
return new CommandException(e, ErrorType.CLIENT_ERROR);
}
String absoluteFilePath;
try {
absoluteFilePath = PathUtil.getAbsolutePath(projectName, relativeFilePath);
} catch (PathUtilException e) {
return new CommandException(e, ErrorType.CLIENT_ERROR);
}
return deleteFileOnFileSystem(absoluteFilePath, relativeFilePath);
}

private Object deleteFileOnFileSystem(String absoluteFilePath, String filePath)
{
File file = new File(absoluteFilePath);
if (!file.exists()) {
String message = Services.getMessage("file.delete.not.found", filePath);
logger.error(message);
return new CommandException(message, ErrorType.CLIENT_ERROR);
}
if (file.isDirectory()) {
org.eclim.util.file.FileUtils.deleteDirectory(file);
return Services.getMessage("file.delete.directory.deleted", filePath);
} else {
if (file.delete()) {
return Services.getMessage("file.delete.success", filePath);
} else {
String message = Services.getMessage("file.delete.error", filePath);
logger.error(Services.getMessage("file.delete.error", filePath));
return new CommandException(message, ErrorType.SYSTEM_ERROR);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* Copyright (C) 2005 - 2016 Eric Van Dewoestine
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.eclim.plugin.core.command.file;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import org.eclim.Services;
import org.eclim.annotation.Command;
import org.eclim.command.CommandException;
import org.eclim.command.CommandLine;
import org.eclim.command.Options;
import org.eclim.logging.Logger;
import org.eclim.plugin.core.command.AbstractCommand;
import org.eclim.plugin.core.util.PathUtil;
import org.eclim.plugin.core.util.PathUtilException;

@Command(
name = "file_list",
options =
"REQUIRED f relativeFilePath ARG," +
"REQUIRED p project ARG," +
"OPTIONAL r recursiveFlag ARG"
)

/**
* Command to get a list of all files and folders in the folder
* {@code relativeFilePath} which is a relative path to the project
* {@code project}.
*
* Example response:
*
* myFolder/
* mySecFolder/
* myFile.txt
*
*
* If the {@code recursiveFlag} argument is set to true the command traverses
* all the folders inside the {@code relativeFilePath} recursively and returns
* all the folders inclusive all subfolders and subfiles.
*
* Example response with {@code recursiveFlag} set to true:
*
* myFolder/
* myFolder/mySubFolder/
* myFolder/mySubFolder/mySubFile.txt
* mySecFolder/
* myFile.txt
*
* @author Lukas Roth
*
*/
public class FileListCommand extends AbstractCommand
{
private static final Logger logger = Logger.getLogger(FileListCommand.class);
private List<String> result;

@Override
public Object execute(CommandLine commandLine)
throws Exception
{
String relativeFilePath = commandLine.getValue(Options.FILE_OPTION);
String projectName = commandLine.getValue(Options.PROJECT_OPTION);
String recursiveFlag = commandLine.getValue(Options.RECURSIVE_OPTION);
boolean recursive = Boolean.parseBoolean(recursiveFlag);
try {
return fileList(projectName, relativeFilePath, recursive);
} catch (FileListCommandException e) {
return new CommandException(e, CommandException.ErrorType.CLIENT_ERROR);
}
}

public List<String> fileList(String projectName, String relativeFilePath,
boolean recursive)
throws FileListCommandException
{
validatePath(relativeFilePath);
File baseFile = getRootPath(projectName, relativeFilePath);
if (!baseFile.exists()) {
throw new FileListCommandException(
Services.getMessage("file.list.no.file", relativeFilePath, projectName));
}
result = new LinkedList<String>();
traverseChildNodes(baseFile, null, recursive);
return result;
}

private void validatePath(String path)
throws FileListCommandException
{
try {
PathUtil.checkPathForEscaping(path);
} catch (PathUtilException e) {
throw new FileListCommandException(
Services.getMessage("file.path.error.illegal.path", path), e);
}
}

private void traverseChildNodes(File baseFile, String path, boolean recursive)
{
File[] childNodes = baseFile.listFiles();
for (File child : childNodes) {
String childPath = (path == null) ? child.getName() :
(path + "/" + child.getName());
if (child.isFile()) {
result.add(childPath);
} else if (child.isDirectory()) {
result.add(childPath + "/");
if (recursive) {
traverseChildNodes(child, childPath, recursive);
}
}
}
}

private File getRootPath(String projectName, String relativeFilePath)
throws FileListCommandException
{
try {
return new File(PathUtil.getAbsolutePath(projectName, relativeFilePath));
} catch (PathUtilException e) {
throw new FileListCommandException(
Services.getMessage("file.list.absolute.path.error", projectName), e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.eclim.plugin.core.command.file;

public class FileListCommandException extends Exception
{

public FileListCommandException(String message, Exception exception)
{
super(message, exception);
}

public FileListCommandException(String message)
{
super(message);
}
}
Loading