Skip to content

Commit 548515b

Browse files
authored
Merge pull request #42 from utPLSQL/feature/include_coverage_html_assets
Feature/include coverage html assets
2 parents 3c51dd8 + aa60fda commit 548515b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3304
-374
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ buildNumber.properties
1515

1616
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
1717
!/.mvn/wrapper/maven-wrapper.jar
18+
19+
#Exclude CoverageHTMLReporter resources as they are managed by maven
20+
src/main/resources/CoverageHTMLReporter/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ before_script:
4444
- cp .travis/settings.xml $MAVEN_CFG/settings.xml
4545

4646
script:
47-
- mvn test -B
47+
- mvn verify -B
4848

4949
before_deploy:
5050
- if [ ! -z "$TRAVIS_TAG" ]; then VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=${VERSION}; fi

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,45 @@ http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN901
9292

9393
*Sections 6.1 and 6.5 are the more important ones, and the only ones you need if you're using the latest Maven version.*
9494

95+
### Local database with utPLSQL and utPLSQL-demo-project
96+
97+
To usefully contribute you'll have to setup a local database with installed [latest utPLSQL v3](https://github.com/utPLSQL/utPLSQL) and [utPLSQL-demo-project](https://github.com/utPLSQL/utPLSQL-demo-project).
98+
The demo-project will serve as your test user. See .travis.yml to see an example on how it can be installed.
99+
100+
### Maven settings for utPLSQL-local profile
101+
102+
utPLSQL-java-api comes with a preconfigured profile "utPLSQL-local". This profile uses properties to set the correct
103+
environment variables for DB_URL, DB_USER and DB_PASS which is needed to run the integration tests.
104+
You can set these properties by adding the following to your Maven settings.xml:
105+
106+
```xml
107+
<settings>
108+
<!-- ... -->
109+
<profiles>
110+
<profile>
111+
<id>utPLSQL-local</id>
112+
<properties>
113+
<dbUrl>localhost:1521/XE</dbUrl>
114+
<dbUser>app</dbUser>
115+
<dbPass>app</dbPass>
116+
</properties>
117+
</profile>
118+
</profiles>
119+
120+
<activeProfiles>
121+
<activeProfile>utPLSQL-local</activeProfile>
122+
</activeProfiles>
123+
</settings>
124+
```
125+
95126
After configuring your access to Oracle's Maven repository, you will be able to successfully build this API.
96127

97128
```bash
98129
cd utPLSQL-java-api
99-
mvn clean package install -DskipTests
130+
mvn clean package install
100131
```
101132

102-
The cmd above is ignoring unit tests because it needs a database connection with the latest utPLSQL v3 installed. Please take a look on .travis.yml and .travis folder to see how testing was configured.
133+
### Skip the local database part
134+
135+
If you want to skip the local database part, just run ``mvn clean package install -DskipTests``.
136+
You will still be able to run ``mvn test`` because integration tests are run in the ``verify``-phase.

pom.xml

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<maven.compiler.source>1.8</maven.compiler.source>
1616
<maven.compiler.target>1.8</maven.compiler.target>
17+
<junit.platform.version>1.0.3</junit.platform.version>
18+
<junit.jupiter.version>5.0.3</junit.jupiter.version>
19+
<coverage.resources.directory>${basedir}/src/main/resources/CoverageHTMLReporter</coverage.resources.directory>
20+
<coverage.resources.version>1.0.0</coverage.resources.version>
21+
<coverage.resources.zip.directory>utPLSQL-coverage-html-${coverage.resources.version}</coverage.resources.zip.directory>
22+
<coverage.resources.zip>${coverage.resources.zip.directory}.zip</coverage.resources.zip>
1723
</properties>
1824

1925
<dependencies>
@@ -30,9 +36,15 @@
3036
<scope>compile</scope>
3137
</dependency>
3238
<dependency>
33-
<groupId>junit</groupId>
34-
<artifactId>junit</artifactId>
35-
<version>4.12</version>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter-api</artifactId>
41+
<version>${junit.jupiter.version}</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.junit.jupiter</groupId>
46+
<artifactId>junit-jupiter-engine</artifactId>
47+
<version>${junit.jupiter.version}</version>
3648
<scope>test</scope>
3749
</dependency>
3850
</dependencies>
@@ -66,8 +78,119 @@
6678
<version>0.0.6</version>
6779
</extension>
6880
</extensions>
81+
<plugins>
82+
<plugin>
83+
<groupId>com.googlecode.maven-download-plugin</groupId>
84+
<artifactId>download-maven-plugin</artifactId>
85+
<version>1.3.0</version>
86+
<executions>
87+
<execution>
88+
<!-- the wget goal actually binds itself to this phase by default -->
89+
<phase>process-resources</phase>
90+
<goals>
91+
<goal>wget</goal>
92+
</goals>
93+
<configuration>
94+
<url>https://codeload.github.com/utPLSQL/utPLSQL-coverage-html/zip/${coverage.resources.version}</url>
95+
<outputFileName>${coverage.resources.zip}</outputFileName>
96+
<!-- default target location, just to demonstrate the parameter -->
97+
<outputDirectory>${coverage.resources.directory}</outputDirectory>
98+
</configuration>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
<plugin>
103+
<artifactId>maven-antrun-plugin</artifactId>
104+
<version>1.7</version>
105+
<executions>
106+
<execution>
107+
<phase>process-resources</phase>
108+
<goals>
109+
<goal>run</goal>
110+
</goals>
111+
<configuration>
112+
<target>
113+
<echo message="unzip Resources" />
114+
<unzip src="${coverage.resources.directory}/${coverage.resources.zip}" dest="${coverage.resources.directory}" />
115+
<echo message="move unzipped assets to target resources directory" />
116+
<move toDir="${coverage.resources.directory}" includeEmptyDirs="yes" verbose="false">
117+
<fileset dir="${coverage.resources.directory}/${coverage.resources.zip.directory}/assets">
118+
<include name="**/*" />
119+
<include name="**/*.*" />
120+
</fileset>
121+
</move>
122+
<echo message="delete unzip directory" />
123+
<delete dir="${coverage.resources.directory}/${coverage.resources.zip.directory}" includeEmptyDirs="yes" verbose="false"/>
124+
<echo message="delete Resources ZIP" />
125+
<delete file="${coverage.resources.directory}/${coverage.resources.zip}" verbose="false"/>
126+
</target>
127+
</configuration>
128+
</execution>
129+
</executions>
130+
</plugin>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-surefire-plugin</artifactId>
134+
<version>2.19.1</version>
135+
<configuration>
136+
<excludes>
137+
<exclude>**/*IT.java</exclude>
138+
</excludes>
139+
</configuration>
140+
<dependencies>
141+
<dependency>
142+
<groupId>org.junit.platform</groupId>
143+
<artifactId>junit-platform-surefire-provider</artifactId>
144+
<version>${junit.platform.version}</version>
145+
</dependency>
146+
</dependencies>
147+
</plugin>
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-failsafe-plugin</artifactId>
151+
<version>2.19.1</version>
152+
<executions>
153+
<execution>
154+
<goals>
155+
<goal>integration-test</goal>
156+
<goal>verify</goal>
157+
</goals>
158+
</execution>
159+
</executions>
160+
<dependencies>
161+
<dependency>
162+
<groupId>org.junit.platform</groupId>
163+
<artifactId>junit-platform-surefire-provider</artifactId>
164+
<version>${junit.platform.version}</version>
165+
</dependency>
166+
</dependencies>
167+
</plugin>
168+
</plugins>
69169
</build>
70170

171+
<profiles>
172+
<profile>
173+
<id>utPLSQL-local</id>
174+
<build>
175+
<pluginManagement>
176+
<plugins>
177+
<plugin>
178+
<groupId>org.apache.maven.plugins</groupId>
179+
<artifactId>maven-failsafe-plugin</artifactId>
180+
<configuration>
181+
<environmentVariables>
182+
<DB_URL>${dbUrl}</DB_URL>
183+
<DB_USER>${dbUser}</DB_USER>
184+
<DB_PASS>${dbPass}</DB_PASS>
185+
</environmentVariables>
186+
</configuration>
187+
</plugin>
188+
</plugins>
189+
</pluginManagement>
190+
</build>
191+
</profile>
192+
</profiles>
193+
71194
<distributionManagement>
72195
<repository>
73196
<id>packagecloud-utPLSQL</id>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.utplsql.api;
2+
3+
/**
4+
* This class provides an easy way to get environmental variables.
5+
* This is mainly to improve testability but also to standardize the way how utPLSQL API and CLI read from
6+
* environment.
7+
* <p>
8+
* Variables are obtained from the following scopes in that order (chain breaks as soon as a value is obtained):
9+
* <ul>
10+
* <li>Properties (System.getProperty())</li>
11+
* <li>Environment (System.getEnv())</li>
12+
* <li>Default value</li>
13+
* </ul>
14+
* <p>
15+
* An empty string is treated the same as null.
16+
*
17+
* @author pesse
18+
*/
19+
public class EnvironmentVariableUtil {
20+
21+
/**
22+
* Returns the value for a given key from environment (see class description)
23+
*
24+
* @param key Key of environment or property value
25+
* @return Environment value or null
26+
*/
27+
public static String getEnvValue(String key) {
28+
return getEnvValue(key, null);
29+
}
30+
31+
/**
32+
* Returns the value for a given key from environment or a default value (see class description)
33+
*
34+
* @param key Key of environment or property value
35+
* @param defaultValue Default value if nothing found
36+
* @return Environment value or defaultValue
37+
*/
38+
public static String getEnvValue(String key, String defaultValue) {
39+
40+
String val = System.getProperty(key);
41+
if (val == null || val.isEmpty()) val = System.getenv(key);
42+
if (val == null || val.isEmpty()) val = defaultValue;
43+
44+
return val;
45+
}
46+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.utplsql.api;
2+
3+
import com.sun.nio.zipfs.ZipFileSystem;
4+
import com.sun.nio.zipfs.ZipPath;
5+
import org.utplsql.api.reporter.CoverageHTMLReporter;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
import java.net.URI;
10+
import java.net.URISyntaxException;
11+
import java.nio.file.*;
12+
import java.util.ArrayList;
13+
import java.util.Collections;
14+
import java.util.Enumeration;
15+
import java.util.List;
16+
import java.util.zip.ZipEntry;
17+
import java.util.zip.ZipFile;
18+
19+
/**
20+
* Helper class for dealing with Resources
21+
*
22+
* @author pesse
23+
*/
24+
public class ResourceUtil {
25+
26+
/**
27+
* Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system
28+
*
29+
* @param resourceName The name of the resource
30+
* @return Path to the resource, either in JAR or on file system
31+
* @throws IOException
32+
* @throws URISyntaxException
33+
*/
34+
public static Path getPathToResource(String resourceName) throws IOException, URISyntaxException {
35+
URI uri = CoverageHTMLReporter.class.getResource(resourceName).toURI();
36+
Path myPath;
37+
if (uri.getScheme().equalsIgnoreCase("jar")) {
38+
FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
39+
myPath = fileSystem.getPath(resourceName);
40+
} else {
41+
myPath = Paths.get(uri);
42+
}
43+
44+
return myPath;
45+
}
46+
47+
/**
48+
* Returns the relative paths of all children of the given resource. Relative path begins from the first atom of the given path.
49+
*
50+
* @param resourceAsPath The resource to get children from
51+
* @param filesOnly If set to true it will only return files, not directories
52+
* @return List of relative Paths to the children
53+
* @throws IOException
54+
* @throws URISyntaxException
55+
*/
56+
public static List<Path> getListOfChildren(Path resourceAsPath, boolean filesOnly) throws IOException, URISyntaxException {
57+
58+
Path resourcePath = getPathToResource("/" + resourceAsPath.toString());
59+
int relativeStartIndex = resourcePath.getNameCount() - resourceAsPath.getNameCount();
60+
61+
final List<Path> result = new ArrayList<>();
62+
63+
if (resourcePath instanceof ZipPath) {
64+
try (ZipFile zf = new ZipFile(resourcePath.getFileSystem().toString())) {
65+
66+
for (Enumeration list = zf.entries(); list.hasMoreElements(); ) {
67+
ZipEntry entry = (ZipEntry) list.nextElement();
68+
// Get entry-path with root element so we can compare it
69+
Path entryPath = resourcePath.getRoot().resolve(resourcePath.getFileSystem().getPath(entry.toString()));
70+
71+
if (entryPath.startsWith(resourcePath) && (!filesOnly || !entry.isDirectory()))
72+
result.add(entryPath.subpath(relativeStartIndex, entryPath.getNameCount()));
73+
}
74+
}
75+
} else {
76+
Files.walk(resourcePath)
77+
.filter(p -> !filesOnly || p.toFile().isFile())
78+
.forEach(p -> result.add(p.subpath(relativeStartIndex, p.getNameCount())));
79+
80+
}
81+
82+
return result;
83+
}
84+
}

0 commit comments

Comments
 (0)