Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/include coverage html assets #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 9, 2018
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ buildNumber.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar

#Exclude CoverageHTMLReporter resources as they are managed by maven
src/main/resources/CoverageHTMLReporter/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ before_script:
- cp .travis/settings.xml $MAVEN_CFG/settings.xml

script:
- mvn test -B
- mvn verify -B

before_deploy:
- if [ ! -z "$TRAVIS_TAG" ]; then VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=${VERSION}; fi
Expand Down
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,45 @@ http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN901

*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.*

### Local database with utPLSQL and utPLSQL-demo-project

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).
The demo-project will serve as your test user. See .travis.yml to see an example on how it can be installed.

### Maven settings for utPLSQL-local profile

utPLSQL-java-api comes with a preconfigured profile "utPLSQL-local". This profile uses properties to set the correct
environment variables for DB_URL, DB_USER and DB_PASS which is needed to run the integration tests.
You can set these properties by adding the following to your Maven settings.xml:

```xml
<settings>
<!-- ... -->
<profiles>
<profile>
<id>utPLSQL-local</id>
<properties>
<dbUrl>localhost:1521/XE</dbUrl>
<dbUser>app</dbUser>
<dbPass>app</dbPass>
</properties>
</profile>
</profiles>

<activeProfiles>
<activeProfile>utPLSQL-local</activeProfile>
</activeProfiles>
</settings>
```

After configuring your access to Oracle's Maven repository, you will be able to successfully build this API.

```bash
cd utPLSQL-java-api
mvn clean package install -DskipTests
mvn clean package install
```

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.
### Skip the local database part

If you want to skip the local database part, just run ``mvn clean package install -DskipTests``.
You will still be able to run ``mvn test`` because integration tests are run in the ``verify``-phase.
129 changes: 126 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.platform.version>1.0.3</junit.platform.version>
<junit.jupiter.version>5.0.3</junit.jupiter.version>
<coverage.resources.directory>${basedir}/src/main/resources/CoverageHTMLReporter</coverage.resources.directory>
<coverage.resources.version>1.0.0</coverage.resources.version>
<coverage.resources.zip.directory>utPLSQL-coverage-html-${coverage.resources.version}</coverage.resources.zip.directory>
<coverage.resources.zip>${coverage.resources.zip.directory}.zip</coverage.resources.zip>
</properties>

<dependencies>
Expand All @@ -30,9 +36,15 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -66,8 +78,119 @@
<version>0.0.6</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<!-- the wget goal actually binds itself to this phase by default -->
<phase>process-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://codeload.github.com/utPLSQL/utPLSQL-coverage-html/zip/${coverage.resources.version}</url>
<outputFileName>${coverage.resources.zip}</outputFileName>
<!-- default target location, just to demonstrate the parameter -->
<outputDirectory>${coverage.resources.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="unzip Resources" />
<unzip src="${coverage.resources.directory}/${coverage.resources.zip}" dest="${coverage.resources.directory}" />
<echo message="move unzipped assets to target resources directory" />
<move toDir="${coverage.resources.directory}" includeEmptyDirs="yes" verbose="false">
<fileset dir="${coverage.resources.directory}/${coverage.resources.zip.directory}/assets">
<include name="**/*" />
<include name="**/*.*" />
</fileset>
</move>
<echo message="delete unzip directory" />
<delete dir="${coverage.resources.directory}/${coverage.resources.zip.directory}" includeEmptyDirs="yes" verbose="false"/>
<echo message="delete Resources ZIP" />
<delete file="${coverage.resources.directory}/${coverage.resources.zip}" verbose="false"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>utPLSQL-local</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<environmentVariables>
<DB_URL>${dbUrl}</DB_URL>
<DB_USER>${dbUser}</DB_USER>
<DB_PASS>${dbPass}</DB_PASS>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>

<distributionManagement>
<repository>
<id>packagecloud-utPLSQL</id>
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/org/utplsql/api/EnvironmentVariableUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.utplsql.api;

/**
* This class provides an easy way to get environmental variables.
* This is mainly to improve testability but also to standardize the way how utPLSQL API and CLI read from
* environment.
* <p>
* Variables are obtained from the following scopes in that order (chain breaks as soon as a value is obtained):
* <ul>
* <li>Properties (System.getProperty())</li>
* <li>Environment (System.getEnv())</li>
* <li>Default value</li>
* </ul>
* <p>
* An empty string is treated the same as null.
*
* @author pesse
*/
public class EnvironmentVariableUtil {

/**
* Returns the value for a given key from environment (see class description)
*
* @param key Key of environment or property value
* @return Environment value or null
*/
public static String getEnvValue(String key) {
return getEnvValue(key, null);
}

/**
* Returns the value for a given key from environment or a default value (see class description)
*
* @param key Key of environment or property value
* @param defaultValue Default value if nothing found
* @return Environment value or defaultValue
*/
public static String getEnvValue(String key, String defaultValue) {

String val = System.getProperty(key);
if (val == null || val.isEmpty()) val = System.getenv(key);
if (val == null || val.isEmpty()) val = defaultValue;

return val;
}
}
84 changes: 84 additions & 0 deletions src/main/java/org/utplsql/api/ResourceUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.utplsql.api;

import com.sun.nio.zipfs.ZipFileSystem;
import com.sun.nio.zipfs.ZipPath;
import org.utplsql.api.reporter.CoverageHTMLReporter;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
* Helper class for dealing with Resources
*
* @author pesse
*/
public class ResourceUtil {

/**
* Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system
*
* @param resourceName The name of the resource
* @return Path to the resource, either in JAR or on file system
* @throws IOException
* @throws URISyntaxException
*/
public static Path getPathToResource(String resourceName) throws IOException, URISyntaxException {
URI uri = CoverageHTMLReporter.class.getResource(resourceName).toURI();
Path myPath;
if (uri.getScheme().equalsIgnoreCase("jar")) {
FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
myPath = fileSystem.getPath(resourceName);
} else {
myPath = Paths.get(uri);
}

return myPath;
}

/**
* Returns the relative paths of all children of the given resource. Relative path begins from the first atom of the given path.
*
* @param resourceAsPath The resource to get children from
* @param filesOnly If set to true it will only return files, not directories
* @return List of relative Paths to the children
* @throws IOException
* @throws URISyntaxException
*/
public static List<Path> getListOfChildren(Path resourceAsPath, boolean filesOnly) throws IOException, URISyntaxException {

Path resourcePath = getPathToResource("/" + resourceAsPath.toString());
int relativeStartIndex = resourcePath.getNameCount() - resourceAsPath.getNameCount();

final List<Path> result = new ArrayList<>();

if (resourcePath instanceof ZipPath) {
try (ZipFile zf = new ZipFile(resourcePath.getFileSystem().toString())) {

for (Enumeration list = zf.entries(); list.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) list.nextElement();
// Get entry-path with root element so we can compare it
Path entryPath = resourcePath.getRoot().resolve(resourcePath.getFileSystem().getPath(entry.toString()));

if (entryPath.startsWith(resourcePath) && (!filesOnly || !entry.isDirectory()))
result.add(entryPath.subpath(relativeStartIndex, entryPath.getNameCount()));
}
}
} else {
Files.walk(resourcePath)
.filter(p -> !filesOnly || p.toFile().isFile())
.forEach(p -> result.add(p.subpath(relativeStartIndex, p.getNameCount())));

}

return result;
}
}
Loading