Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Initial work on project paths
  • Loading branch information
viniciusam committed Jun 18, 2017
commit b6a39063317c4dd5791679d4e4c42c5ff4da7b6d
Empty file.
Empty file.
Empty file.
Empty file.
48 changes: 48 additions & 0 deletions src/main/java/io/github/utplsql/cli/FileWalker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.github.utplsql.cli;

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

/**
* Created by Vinicius on 18/06/2017.
*/
public class FileWalker {

public List<String> getFileList(File baseDir, String inspectPath) {
return getFileList(baseDir, inspectPath, true);
}

public List<String> getFileList(File baseDir, String inspectPath, boolean relative) {
File inspectDir = new File(baseDir, inspectPath);

if (!inspectDir.isDirectory())
throw new IllegalArgumentException(inspectPath + " is not a directory.");

List<String> fileList = new ArrayList<>();
listDirFiles(baseDir, inspectDir, fileList, relative);

return fileList;
}

private void listDirFiles(File baseDir, File directory, List<String> fileList, boolean relative) {
File[] directoryFiles = directory.listFiles();

if (directoryFiles == null)
return;

for (File file : directoryFiles) {
if (file.isFile()) {
String absolutePath = file.getAbsolutePath();

if (relative)
absolutePath = absolutePath.substring(baseDir.getAbsolutePath().length() + 1);

fileList.add(absolutePath);
} else {
listDirFiles(baseDir, file, fileList, relative);
}
}
}

}
25 changes: 24 additions & 1 deletion src/main/java/io/github/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.utplsql.api.reporter.Reporter;
import io.github.utplsql.api.reporter.ReporterFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
Expand Down Expand Up @@ -49,6 +50,12 @@ public class RunCommand {
description = "enables printing of test results in colors as defined by ANSICONSOLE standards")
private boolean colorConsole = false;

@Parameter(names = {"-source_path"}, description = "path to project source files")
private String sourcePath;

@Parameter(names = {"-test_path"}, description = "path to project source files")
private String testPath;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wrong description here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will fix.


public ConnectionInfo getConnectionInfo() {
return connectionInfoList.get(0);
}
Expand Down Expand Up @@ -91,6 +98,19 @@ public void run() throws Exception {
final List<String> testPaths = getTestPaths();
final List<Reporter> reporterList = new ArrayList<>();

final File baseDir = new File("").getAbsoluteFile();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this using current dir(from where cli was invoked)? If so great!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes!

List<String> sourceFilesTmp = null;
List<String> testFilesTmp = null;

if (this.sourcePath != null)
sourceFilesTmp = new FileWalker().getFileList(baseDir, this.sourcePath);

if (this.testPath != null)
testFilesTmp = new FileWalker().getFileList(baseDir, this.testPath);

final List<String> sourceFiles = sourceFilesTmp;
final List<String> testFiles = testFilesTmp;

if (testPaths.isEmpty()) testPaths.add(ci.getUser());

// Do the reporters initialization, so we can use the id to run and gather results.
Expand All @@ -108,11 +128,14 @@ public void run() throws Exception {

ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());

// Run tests.
executorService.submit(() -> {
try (Connection conn = ci.getConnection()){
new TestRunner()
.addPathList(testPaths)
.addReporterList(reporterList)
.withSourceFiles(sourceFiles)
.withTestFiles(testFiles)
.colorConsole(colorConsole)
.run(conn);
} catch (SQLException e) {
Expand All @@ -121,7 +144,7 @@ public void run() throws Exception {
}
});


// Gather each reporter results on a separate thread.
for (ReporterOptions ro : reporterOptionsList) {
executorService.submit(() -> {
List<PrintStream> printStreams = new ArrayList<>();
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/io/github/utplsql/cli/FileWalkerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.utplsql.cli;

import org.junit.Assert;
import org.junit.Test;

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

/**
* Created by Vinicius on 18/06/2017.
*/
public class FileWalkerTest {

private final File BASE_DIR = new File(new File("").getAbsolutePath(), "assets/demo_project");

@Test
public void fileWalker_Relative() {
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source");
Assert.assertArrayEquals(new Object[] {
"source/packages/package.pkb".replace('/', File.separatorChar),
"source/packages/package.pks".replace('/', File.separatorChar),
"source/script.sql".replace('/', File.separatorChar),
"source/triggers/trigger.trg".replace('/', File.separatorChar),
}, fileList.toArray());
}

@Test
public void fileWalker_Absolute() {
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source", false);
Assert.assertArrayEquals(new Object[] {
BASE_DIR.getAbsolutePath() + "/source/packages/package.pkb".replace('/', File.separatorChar),
BASE_DIR.getAbsolutePath() + "/source/packages/package.pks".replace('/', File.separatorChar),
BASE_DIR.getAbsolutePath() + "/source/script.sql".replace('/', File.separatorChar),
BASE_DIR.getAbsolutePath() + "/source/triggers/trigger.trg".replace('/', File.separatorChar),
}, fileList.toArray());
}

}