Skip to content

Commit 37d4591

Browse files
committed
Added friendly message for invalid <sources> and <tests> resources
1 parent 16b60d8 commit 37d4591

2 files changed

Lines changed: 45 additions & 40 deletions

File tree

‎utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public void execute() throws MojoExecutionException {
9292
try {
9393
sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource());
9494
} catch (Exception e) {
95-
throw new MojoExecutionException("Invalid <sources> in your pom.xml");
95+
throw new MojoExecutionException(format("Invalid <sources> in your pom.xml: %s", e.getMessage()));
9696
}
9797
FileMapperOptions testMappingOptions = null;
9898
try {
9999
testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest());
100100
} catch (Exception e) {
101-
throw new MojoExecutionException("Invalid <tests> in your pom.xml");
101+
throw new MojoExecutionException(format("Invalid <tests> in your pom.xml: %s", e.getMessage()));
102102
}
103103

104104
Connection connection = null;
Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.utplsql.helper;
22

3+
import static java.lang.String.format;
4+
35
import java.io.File;
46
import java.util.ArrayList;
57
import java.util.Arrays;
@@ -9,58 +11,61 @@
911
import org.codehaus.plexus.util.DirectoryScanner;
1012

1113
/**
12-
* Utility to Scan all resources
14+
* Utility to Scan all resources
1315
*
1416
* @author Alberto Hernández
1517
*
1618
*/
17-
public class SQLScannerHelper
18-
{
19-
19+
public class SQLScannerHelper {
20+
2021
private SQLScannerHelper() {
2122
// NA
2223
}
2324

24-
/**
25-
*
26-
* @param resouces
27-
* @return
28-
*/
29-
public static List<String> findSQLs(List<Resource> resources)
30-
{
25+
/**
26+
*
27+
* @param resouces
28+
* @return
29+
*/
30+
public static List<String> findSQLs(List<Resource> resources) {
3131
List<String> founds = new ArrayList<>();
32-
33-
for (Resource resource: resources)
34-
{
35-
// Build Scanner
36-
DirectoryScanner scanner = buildScanner(resource);
37-
scanner.scan();
32+
33+
for (Resource resource : resources) {
34+
// Build Scanner
35+
DirectoryScanner scanner = buildScanner(resource);
36+
scanner.scan();
3837
for (String basename : scanner.getIncludedFiles()) {
3938
founds.add(new File(scanner.getBasedir(), basename).getAbsolutePath());
4039
}
4140

42-
// Append all scanned objects
41+
// Append all scanned objects
4342
founds.addAll(Arrays.asList());
44-
}
45-
46-
return founds;
47-
}
43+
}
44+
45+
return founds;
46+
}
47+
48+
/**
49+
* Build a scanner in forder to Find all Resource files
50+
*
51+
* @param resource
52+
* @return
53+
*/
54+
private static DirectoryScanner buildScanner(Resource resource) {
55+
if (resource != null) {
56+
File baseDir = new File(resource.getDirectory());
57+
if (!baseDir.exists() || !baseDir.isDirectory() || !baseDir.canRead()) {
58+
throw new IllegalArgumentException(
59+
format("Invalid <directory> %s in resource. Check your pom.xml", resource.getDirectory()));
60+
}
4861

49-
/**
50-
* Build a scanner in forder to Find all Resource files
51-
* @param resource
52-
* @return
53-
*/
54-
private static DirectoryScanner buildScanner(Resource resource)
55-
{
56-
DirectoryScanner scanner = new DirectoryScanner();
57-
58-
scanner.setBasedir(resource.getDirectory());
59-
scanner.setIncludes(resource.getIncludes().toArray(new String[0]));
60-
scanner.setExcludes(resource.getExcludes().toArray(new String[0]));
61-
62-
63-
return scanner;
64-
}
62+
DirectoryScanner scanner = new DirectoryScanner();
63+
scanner.setBasedir(resource.getDirectory());
64+
scanner.setIncludes(resource.getIncludes().toArray(new String[0]));
65+
scanner.setExcludes(resource.getExcludes().toArray(new String[0]));
66+
return scanner;
67+
}
68+
throw new IllegalArgumentException();
69+
}
6570

6671
}

0 commit comments

Comments
 (0)