8000 Merge pull request #18 from viniciusam/feature/project_path · Pazus/utPLSQL-cli@5361b15 · GitHub
[go: up one dir, main page]

Sk 10000 ip to content

Commit 5361b15

Browse files
authored
Merge pull request utPLSQL#18 from viniciusam/feature/project_path
Add source_path and test_path parameters
2 parents eb1d930 + 115d94c commit 5361b15

File tree

7 files changed

+113
-1
lines changed

7 files changed

+113
-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;
@@ -50,6 +51,12 @@ public class RunCommand {
5051
description = "enables printing of test results in colors as defined by ANSICONSOLE standards")
5152
private boolean colorConsole = false;
5253

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

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

97117
// Do the reporters initialization, so we can use the id to run and gather results.
@@ -109,11 +129,14 @@ public void run() throws Exception {
109129

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

132+
// Run tests.
112133
executorService.submit(() -> {
113134
try (Connection conn = ci.getConnection()){
114135
new TestRunner()
115136
.addPathList(testPaths)
116137
.addReporterList(reporterList)
138+
.withSourceFiles(sourceFiles)
139+
.withTestFiles(testFiles)
117140
.colorConsole(colorConsole)
118141
.run(conn);
119142
} catch (SQLException e) {
@@ -122,7 +145,7 @@ public void run() throws Exception {
122145
}
123146
});
124147

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

0 commit comments

Comments
 (0)
0