diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/BLauncherCmd.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/BLauncherCmd.java index bd70b9d5727a..c2449bab214c 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/BLauncherCmd.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/BLauncherCmd.java @@ -72,10 +72,6 @@ public interface BLauncherCmd { * @return usage info for the specified command */ static String getCommandUsageInfo(String commandName) { - if (commandName == null) { - throw LauncherUtils.createUsageExceptionWithHelp("invalid command"); - } - String fileName = "cli-help/ballerina-" + commandName + ".help"; try { return BCompileUtil.readFileAsString(fileName); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java index 4c047f3967a1..8d36f6b0ad62 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java @@ -28,6 +28,5 @@ public class BallerinaCliCommands { public static final String HELP = "help"; public static final String VERSION = "version"; public static final String RUN = "run"; - public static final String ENCRYPT = "encrypt"; public static final String HOME = "home"; } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java index 0484107b8811..fc7a66f9de8d 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java @@ -21,8 +21,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; /** * Utility methods for compile Ballerina files. @@ -31,9 +29,6 @@ */ public class BCompileUtil { - //TODO find a way to remove below line. - private static Path resourceDir = Paths.get("src/test/resources").toAbsolutePath(); - public static String readFileAsString(String path) throws IOException { InputStream is = ClassLoader.getSystemResourceAsStream(path); InputStreamReader inputStreamREader = null; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BFileUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BFileUtil.java deleted file mode 100644 index 54e9018d2201..000000000000 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BFileUtil.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package io.ballerina.cli.launcher.util; - -import java.io.IOException; -import java.nio.file.CopyOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.BasicFileAttributes; - -import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; - -/** - * Utility methods for doing file operations. - * - * @since 0.975.0 - */ -public class BFileUtil { - - private static final String IGNORE = ".gitignore"; - - private BFileUtil() {} - - /** - * Copy a file or directory to a target location. - * - * @param sourcePath File or directory to be copied - * @param targetPath Target location - */ - public static void copy(Path sourcePath, Path targetPath) { - try { - Files.walkFileTree(sourcePath, new SimpleFileVisitor() { - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) { - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - if (Files.exists(dir)) { - Files.createDirectories(targetPath.resolve(sourcePath.relativize(dir))); - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (!IGNORE.equals(file.getFileName().toString()) && Files.exists(file)) { - CopyOption[] option = { - StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES - }; - Files.copy(file, targetPath.resolve(sourcePath.relativize(file)), option); - } - return FileVisitResult.CONTINUE; - } - }); - } catch (IOException e) { - throw createLauncherException( - "error occured while copying from '" + sourcePath + "' " + "to '" + targetPath + "'"); - } - } - - /** - * Delete a file or directory. - * - * @param path Path to the file or directory - */ - public static void delete(Path path) { - try { - Files.walkFileTree(path, new SimpleFileVisitor() { - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) { - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (Files.exists(file)) { - Files.delete(file); - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - if (Files.exists(dir)) { - Files.list(dir).forEach(BFileUtil::delete); - } - return FileVisitResult.CONTINUE; - } - }); - } catch (IOException e) { - throw createLauncherException("error occurred while deleting '" + path + "'"); - } - } - -}