Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
if (sources.isEmpty()) {
File defaultSourceDirectory = new File(project.getBasedir(),PluginDefault.SOURCE_DIRECTORY);
if (defaultSourceDirectory.exists()) {
sources.add(PluginDefault.buildDefaultSource(project.getBasedir()));
sources.add(PluginDefault.buildDefaultSource());
} else {
return new FileMapperOptions(new ArrayList<String>());
}
}

List<String> scripts = SQLScannerHelper.findSQLs(project.getBasedir(),sources);
List<String> scripts = SQLScannerHelper.findSQLs(project.getBasedir(),sources,PluginDefault.SOURCE_DIRECTORY, PluginDefault.SOURCE_FILE_PATTERN);
FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts);

if (StringUtils.isNotEmpty(sourcesOwner)) {
Expand Down Expand Up @@ -263,15 +263,15 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
try {
// Check if this element is empty
if (tests.isEmpty()) {
File defaultTestDirecyory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY);
if (defaultTestDirecyory.exists()) {
tests.add(PluginDefault.buildDefaultTest(project.getBasedir()));
File defaultTestDirectory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY);
if (defaultTestDirectory.exists()) {
tests.add(PluginDefault.buildDefaultTest());
} else {
return new FileMapperOptions(new ArrayList<String>());
}
}

List<String> scripts = SQLScannerHelper.findSQLs(project.getBasedir(),tests);
List<String> scripts = SQLScannerHelper.findSQLs(project.getBasedir(),tests,PluginDefault.TEST_DIRECTORY, PluginDefault.TEST_FILE_PATTERN);
FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts);

if (StringUtils.isNotEmpty(testsOwner)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public class PluginDefault

// Test Directory
public static final String TEST_DIRECTORY = "src/test/plsql";

/**
* Default source file pattern.
*/
public static final String SOURCE_FILE_PATTERN = "**/*.*";

/**
* Default test file pattern.
*/
public static final String TEST_FILE_PATTERN = "**/*.pkg";

private PluginDefault()
{
Expand All @@ -37,25 +47,25 @@ private PluginDefault()
*
* @return a {@link Resource}
*/
public static Resource buildDefaultSource(File baseDir)
public static Resource buildDefaultSource()
{
return buildDirectory(baseDir,SOURCE_DIRECTORY, "**/*.*");
return buildDirectory(SOURCE_DIRECTORY, SOURCE_FILE_PATTERN);
}

/**
* This method returns {@link Resource} for the default {@code test} directory
*
* @return a {@link Resource}
*/
public static Resource buildDefaultTest(File baseDir)
public static Resource buildDefaultTest()
{
return buildDirectory(baseDir, TEST_DIRECTORY, "**/*.pkg");
return buildDirectory(TEST_DIRECTORY, TEST_FILE_PATTERN);
}

private static Resource buildDirectory(File baseDir, String directory, String includes)
private static Resource buildDirectory(String directory, String includes)
{
Resource resource = new Resource();
resource.setDirectory(baseDir.getAbsolutePath()+"/"+directory);
resource.setDirectory(directory);
resource.setIncludes(Arrays.asList(includes));
return resource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ private SQLScannerHelper() {
* @param resouces
* @return
*/
public static List<String> findSQLs(File baseDir,List<Resource> resources) {
public static List<String> findSQLs(File baseDir,List<Resource> resources, String defaultDirectory, String defaultFilePattern) {
List<String> founds = new ArrayList<String>();

for (Resource resource : resources) {
if (resource.getDirectory() == null) {
// use default directory if not set.
resource.setDirectory(defaultDirectory);
}

if (resource.getIncludes().isEmpty()) {
// use default file pattern if not set.
resource.getIncludes().add(defaultFilePattern);
}
// Build Scanner
DirectoryScanner scanner = buildScanner(resource);
DirectoryScanner scanner = buildScanner(baseDir.getPath(),resource);
scanner.scan();
for (String basename : scanner.getIncludedFiles()) {
founds.add(baseDir.toURI().relativize(new File(scanner.getBasedir(), basename).toURI()).getPath());
Expand All @@ -51,16 +60,16 @@ public static List<String> findSQLs(File baseDir,List<Resource> resources) {
* @param resource
* @return
*/
private static DirectoryScanner buildScanner(Resource resource) {
private static DirectoryScanner buildScanner(String baseDir,Resource resource) {
if (resource != null) {
File baseDir = new File(resource.getDirectory());
if (!baseDir.exists() || !baseDir.isDirectory() || !baseDir.canRead()) {
File fileBaseDir = new File(baseDir,resource.getDirectory());
if (!fileBaseDir.exists() || !fileBaseDir.isDirectory() || !fileBaseDir.canRead()) {
throw new IllegalArgumentException(
format("Invalid <directory> %s in resource. Check your pom.xml", resource.getDirectory()));
}

DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(resource.getDirectory());
scanner.setBasedir(fileBaseDir.getPath());
scanner.setIncludes(resource.getIncludes().toArray(new String[0]));
scanner.setExcludes(resource.getExcludes().toArray(new String[0]));
return scanner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,57 @@ public void testSourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists()
assertTrue(tests.getFilePaths().contains("src/test/plsql/f2.pkg"));

}

/**
* testSourcesAndTestsParameterHaveNotDirectoryTag.
*
* Given : a pom.xml with source and test tag not containing a directory tag.
* When : pom is read and buildSourcesOptions / buildTestsOptions are run
* Then : it should find all sources/tests files in default directories
*/
@Test
public void testSourcesAndTestsParameterHaveNotDirectoryTag() throws Exception {
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/partialSourceAndTestTag/missingDirectory/"), "test");
Assert.assertNotNull(utplsqlMojo);

// check sources
FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions");
assertEquals(2, sources.getFilePaths().size());
assertTrue(sources.getFilePaths().contains("src/main/plsql/f1.sql"));
assertTrue(sources.getFilePaths().contains("src/main/plsql/foo/f2.sql"));

// check tests
FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions");
assertEquals(3, tests.getFilePaths().size());
assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.pkg"));
assertTrue(tests.getFilePaths().contains("src/test/plsql/f2.pkg"));
assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.sql"));
}

/**
* testSourcesAndTestsParameterHaveNotDirectoryTag.
*
* Given : a pom.xml with source and test tag not containing a directory tag.
* When : pom is read and buildSourcesOptions / buildTestsOptions are run
* Then : it should find all sources/tests files in default directories
*/
@Test
public void testSourcesAndTestsParameterHaveNotIncludesTag() throws Exception {
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/partialSourceAndTestTag/missingIncludes/"), "test");
Assert.assertNotNull(utplsqlMojo);

// check sources
FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions");
assertEquals(2, sources.getFilePaths().size());
assertTrue(sources.getFilePaths().contains("src/main/foo/f1.sql"));
assertTrue(sources.getFilePaths().contains("src/main/foo/foo/f2.sql"));

// check tests
FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions");
assertEquals(2, tests.getFilePaths().size());
assertTrue(tests.getFilePaths().contains("src/test/bar/foo/f1.pkg"));
assertTrue(tests.getFilePaths().contains("src/test/bar/f2.pkg"));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>


<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin-test</artifactId>
<version>3.1.0-SNAPSHOT</version>

<packaging>pom</packaging>

<name>utplsql-maven-plugin Maven Plugin Test</name>

<url>http://utplsql.org</url>

<properties>
<dbUrl>jdbc:oracle:thin:@180.129.3.101:1521:xe</dbUrl>
<dbUser>ut3</dbUser>
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
<project.basedir>/</project.basedir>
</properties>

<build>

<plugins>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>{project.version}</version>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- Mandatory Attributes -->

<ignoreFailure>false</ignoreFailure>

<paths>
<path>:plsql</path>
</paths>

<reporters>
<reporter>
<name>UT_COVERAGE_SONAR_REPORTER</name>
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
<reporter>
<name>UT_SONAR_TEST_REPORTER</name>
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
</reporters>

<sources>
<source>
<includes>
<include>**/*sql</include>
</includes>
</source>
</sources>
<tests>
<test>
<includes>
<include>**/*sql</include>

</includes>
</test>
<test>
<includes>
<include>**/*.pkg</include>
</includes>
</test>
</tests>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>


<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin-test</artifactId>
<version>3.1.0-SNAPSHOT</version>

<packaging>pom</packaging>

<name>utplsql-maven-plugin Maven Plugin Test</name>

<url>http://utplsql.org</url>

<properties>
<dbUrl>jdbc:oracle:thin:@180.129.3.101:1521:xe</dbUrl>
<dbUser>ut3</dbUser>
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
<project.basedir>/</project.basedir>
</properties>

<build>

<plugins>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>{project.version}</version>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- Mandatory Attributes -->

<ignoreFailure>false</ignoreFailure>

<paths>
<path>:plsql</path>
</paths>

<reporters>
<reporter>
<name>UT_COVERAGE_SONAR_REPORTER</name>
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
<reporter>
<name>UT_SONAR_TEST_REPORTER</name>
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
</reporters>

<sources>
<source>
<directory>src/main/foo</directory>
</source>
</sources>
<tests>
<test>
<directory>src/test/bar</directory>
</test>
</tests>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<sources>
<source>
<directory>src/test/resources/testSourcesTestsParams/srcs</directory>
<directory>srcs</directory>
<includes>
<include>**/*sql</include>
</includes>
Expand All @@ -75,7 +75,7 @@

<tests>
<test>
<directory>src/test/resources/testSourcesTestsParams/te/st</directory>
<directory>te/st</directory>
<includes>
<include>**/*.spc</include>
<include>**/*.bdy</include>
Expand Down