Skip to content

Commit b6a3906

Browse files
committed
Initial work on project paths
1 parent d50b8b5 commit b6a3906

File tree

7 files changed

+110
-1
lines changed

7 files changed

+110
-1
lines changed

assets/demo_project/source/packages/package.pkb

Whitespace-only changes.

assets/demo_project/source/packages/package.pks

Whitespace-only changes.

assets/demo_project/source/script.sql

Whitespace-only changes.

assets/demo_project/source/triggers/trigger.trg

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.github.utplsql.cli;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
/**
8+
* Created by Vinicius on 18/06/2017.
9+
*/
10+
public class FileWalker {
11+
12+
public List<String> getFileList(File baseDir, String inspectPath) {
13+
return getFileList(baseDir, inspectPath, true);
14+
}
15+
16+
public List<String> getFileList(File baseDir, String inspectPath, boolean relative) {
17+
File inspectDir = new File(baseDir, inspectPath);
18+
19+
if (!inspectDir.isDirectory())
20+
throw new IllegalArgumentException(inspectPath + " is not a directory.");
21+
22+
List<String> fileList = new ArrayList<>();
23+
listDirFiles(baseDir, inspectDir, fileList, relative);
24+
25+
return fileList;
26+
}
27+
28+
private void listDirFiles(File baseDir, File directory, List<String> fileList, boolean relative) {
29+
File[] directoryFiles = directory.listFiles();
30+
31+
if (directoryFiles == null)
32+
return;
33+
34+
for (File file : directoryFiles) {
35+
if (file.isFile()) {
36+
String absolutePath = file.getAbsolutePath();
37+
38+
if (relative)
39+
absolutePath = absolutePath.substring(baseDir.getAbsolutePath().length() + 1);
40+
41+
fileList.add(absolutePath);
42+
} else {
43+
listDirFiles(baseDir, file, fileList, relative);
44+
}
45+
}
46+
}
47+
48+
}

src/main/java/io/github/utplsql/cli/RunCommand.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.github.utplsql.api.reporter.Reporter;
99
import io.github.utplsql.api.reporter.ReporterFactory;
1010

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

53+
@Parameter(names = {"-source_path"}, description = "path to project source files")
54+
private String sourcePath;
55+
56+
@Parameter(names = {"-test_path"}, description = "path to project source files")
57+
private String testPath;
58+
5259
public ConnectionInfo getConnectionInfo() {
5360
return connectionInfoList.get(0);
5461
}
@@ -91,6 +98,19 @@ public void run() throws Exception {
9198
final List<String> testPaths = getTestPaths();
9299
final List<Reporter> reporterList = new ArrayList<>();
93100

101+
final File baseDir = new File("").getAbsoluteFile();
102+
List<String> sourceFilesTmp = null;
103+
List<String> testFilesTmp = null;
104+
105+
if (this.sourcePath != null)
106+
sourceFilesTmp = new FileWalker().getFileList(baseDir, this.sourcePath);
107+
108+
if (this.testPath != null)
109+
testFilesTmp = new FileWalker().getFileList(baseDir, this.testPath);
110+
111+
final List<String> sourceFiles = sourceFilesTmp;
112+
final List<String> testFiles = testFilesTmp;
113+
94114
if (testPaths.isEmpty()) testPaths.add(ci.getUser());
95115

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

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

131+
// Run tests.
111132
executorService.submit(() -> {
112133
try (Connection conn = ci.getConnection()){
113134
new TestRunner()
114135
.addPathList(testPaths)
115136
.addReporterList(reporterList)
137+
.withSourceFiles(sourceFiles)
138+
.withTestFiles(testFiles)
116139
.colorConsole(colorConsole)
117140
.run(conn);
118141
} catch (SQLException e) {
@@ -121,7 +144,7 @@ public void run() throws Exception {
121144
}
122145
});
123146

124-
147+
// Gather each reporter results on a separate thread.
125148
for (ReporterOptions ro : reporterOptionsList) {
126149
executorService.submit(() -> {
127150
List<PrintStream> printStreams = new ArrayList<>();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.github.utplsql.cli;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import java.io.File;
7+
import java.util.List;
8+
9+
/**
10+
* Created by Vinicius on 18/06/2017.
11+
*/
12+
public class FileWalkerTest {
13+
14+
private final File BASE_DIR = new File(new File("").getAbsolutePath(), "assets/demo_project");
15+
16+
@Test
17+
public void fileWalker_Relative() {
18+
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source");
19+
Assert.assertArrayEquals(new Object[] {
20+
"source/packages/package.pkb".replace('/', File.separatorChar),
21+
"source/packages/package.pks".replace('/', File.separatorChar),
22+
"source/script.sql".replace('/', File.separatorChar),
23+
"source/triggers/trigger.trg".replace('/', File.separatorChar),
24+
}, fileList.toArray());
25+
}
26+
27+
@Test
28+
public void fileWalker_Absolute() {
29+
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source", false);
30+
Assert.assertArrayEquals(new Object[] {
31+
BASE_DIR.getAbsolutePath() + "/source/packages/package.pkb".replace('/', File.separatorChar),
32+
BASE_DIR.getAbsolutePath() + "/source/packages/package.pks".replace('/', File.separatorChar),
33+
BASE_DIR.getAbsolutePath() + "/source/script.sql".replace('/', File.separatorChar),
34+
BASE_DIR.getAbsolutePath() + "/source/triggers/trigger.trg".replace('/', File.separatorChar),
35+
}, fileList.toArray());
36+
}
37+
38+
}

0 commit comments

Comments
 (0)