Commit 19962409 authored by Daniel Bluhm's avatar Daniel Bluhm

Add basic tests for DependecnyScraper

Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 35a9a2a9
......@@ -58,15 +58,13 @@ public class DependencyScraper extends AbstractMojo {
*/
@Parameter(
property = "outputDirectory",
defaultValue = "frontend/src",
required = false
required = true
)
private File outputDirectory;
@Parameter(
property = "sourceDirectory",
defaultValue = "frontend",
required = false
required = true
)
private String sourceDirectory;
......@@ -80,6 +78,19 @@ public class DependencyScraper extends AbstractMojo {
)
private List<String> includes;
/**
* Set of jar files that will be searched for matching files.
*/
private Set<File> jarFiles;
/**
* Setter for jarFiles.
* @param jarFiles to set.
*/
public void setJarFiles(Set<File> jarFiles) {
this.jarFiles = jarFiles;
}
/**
* Filter for whether a ZipEntry begins with the sourceDirectory.
* @param file to test
......@@ -153,9 +164,11 @@ public class DependencyScraper extends AbstractMojo {
* directory specified by parameters.
*/
public void execute() throws MojoExecutionException, MojoFailureException {
Set<File> jarFiles = project.getArtifacts().stream()
.filter(artifact -> "jar".equals(artifact.getType()))
.map(Artifact::getFile).collect(Collectors.toSet());
if (jarFiles == null) {
this.jarFiles = project.getArtifacts().stream()
.filter(artifact -> "jar".equals(artifact.getType()))
.map(Artifact::getFile).collect(Collectors.toSet());
}
for (File jar : jarFiles) {
try (JarFile jarFile = new JarFile(jar, false)) {
Set<ZipEntry> toCopy = jarFile.stream()
......
......@@ -2,12 +2,11 @@ package org.org.eclipse.ice.dev.dependencyscraper;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.plugin.testing.WithoutMojo;
import org.junit.Rule;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.File;
import java.util.Set;
public class DependencyScraperTest
{
......@@ -31,22 +30,19 @@ public class DependencyScraperTest
DependencyScraper myMojo = (DependencyScraper) rule.lookupConfiguredMojo(pom, "scrape");
assertNotNull(myMojo);
myMojo.setJarFiles(Set.of(new File(
"target/test-classes/project-to-test/pretend_dependency.jar"
)));
System.out.println(rule.getVariablesAndValuesFromObject(myMojo));
myMojo.execute();
// File outputDirectory = (File) rule.getVariableValueFromObject(myMojo, "outputDirectory");
// assertNotNull(outputDirectory);
// assertTrue(outputDirectory.exists());
//
// File touch = new File(outputDirectory, "touch.txt");
// assertTrue(touch.exists());
}
File outputDirectory = (File) rule.getVariableValueFromObject(myMojo, "outputDirectory");
assertNotNull(outputDirectory);
assertTrue(outputDirectory.exists());
System.out.println(outputDirectory);
/** Do not need the MojoRule. */
@WithoutMojo
@Test
public void testSomethingWhichDoesNotNeedTheMojoAndProbablyShouldBeExtractedIntoANewClassOfItsOwn()
{
assertTrue(true);
File test = new File(outputDirectory, "test.txt");
assertTrue(test.exists());
}
}
......@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.ice</groupId>
<artifactId>org.eclipse.ice.dev.dependencyscraper</artifactId>
<artifactId>org.eclipse.ice.dev.dependencyscraper.test</artifactId>
<version>3.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
......@@ -13,9 +13,11 @@
<build>
<plugins>
<plugin>
<artifactId>maven-my-plugin</artifactId>
<groupId>org.eclipse.ice</groupId>
<artifactId>org.eclipse.ice.dev.dependencyscraper</artifactId>
<configuration>
<sourceDirectory>META-INF</sourceDirectory>
<sourceDirectory>pretend_dependency</sourceDirectory>
<outputDirectory>test</outputDirectory>
<includes>
<include>*</include>
</includes>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment