use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class AbstractSourceJarMojo method createArchiver.
/**
* @return {@link MavenArchiver}
* @throws MojoExecutionException in case of an error.
*/
protected MavenArchiver createArchiver() throws MojoExecutionException {
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
if (project.getBuild() != null) {
List<Resource> resources = project.getBuild().getResources();
for (Resource r : resources) {
if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
addDirectory(archiver.getArchiver(), new File(r.getDirectory()), getCombinedIncludes(null), getCombinedExcludes(null));
}
}
}
return archiver;
}
use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class MavenProjectResourcesStub method setupResources.
private void setupResources() {
Resource resource = new Resource();
// see MavenProjectBasicStub for details
// of getBasedir
// setup default resources
resource.setDirectory(getBasedir().getPath() + "/src/main/resources");
resource.setFiltering(false);
resource.setTargetPath(null);
build.addResource(resource);
}
use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class ResourcesMojoTest method testWindowsPathEscapingEnabled.
public void testWindowsPathEscapingEnabled() throws Exception {
File testPom = new File(getBasedir(), defaultPomFilePath);
ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
MavenProjectResourcesStub project = new MavenProjectResourcesStub("windows-paths");
List<Resource> resources = project.getBuild().getResources();
assertNotNull(mojo);
project.getProperties().setProperty("basePath", "C:\\Users\\Administrator");
project.getProperties().setProperty("docsPath", "${basePath}\\Documents");
project.addFile("path-listing.txt", "base path is ${basePath}\ndocuments path is ${docsPath}");
project.setResourceFiltering(0, true);
project.cleanBuildEnvironment();
project.setupBuildEnvironment();
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "resources", resources);
setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
setVariableValueToObject(mojo, "escapeWindowsPaths", Boolean.TRUE);
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue(FileUtils.fileExists(new File(resourcesDir, "path-listing.txt").getAbsolutePath()));
assertEquals("base path is C:\\\\Users\\\\Administrator\ndocuments path is C:\\\\Users\\\\Administrator\\\\Documents", FileUtils.fileRead(new File(resourcesDir, "path-listing.txt")));
}
use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class ResourcesMojoTest method testResourceDirectoryStructure_RelativePath.
/**
* @throws Exception
*/
public void testResourceDirectoryStructure_RelativePath() throws Exception {
File testPom = new File(getBasedir(), defaultPomFilePath);
ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceDirectoryStructure_RelativePath");
List<Resource> resources = project.getBuild().getResources();
assertNotNull(mojo);
project.setOutputDirectory("../relative_dir");
project.addFile("file4.txt");
project.addFile("package/file3.nottest");
project.addFile("notpackage/file1.include");
project.addFile("package/test/file1.txt");
project.addFile("notpackage/test/file2.txt");
project.setupBuildEnvironment();
setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "resources", resources);
setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue(FileUtils.fileExists(resourcesDir + "/file4.txt"));
assertTrue(FileUtils.fileExists(resourcesDir + "/package/file3.nottest"));
assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/file1.include"));
assertTrue(FileUtils.fileExists(resourcesDir + "/package/test"));
assertTrue(FileUtils.fileExists(resourcesDir + "/notpackage/test"));
}
use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class ResourcesMojoTest method testResourceProjectProperties_Filtering.
/**
* @throws Exception
*/
public void testResourceProjectProperties_Filtering() throws Exception {
File testPom = new File(getBasedir(), defaultPomFilePath);
ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourceProjectProperties_Filtering");
List<Resource> resources = project.getBuild().getResources();
assertNotNull(mojo);
project.addFile("file4.txt", "current working directory = ${user.dir}");
project.setResourceFiltering(0, true);
project.addProperty("user.dir", "FPJ kami!!!");
project.setupBuildEnvironment();
// setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "resources", resources);
setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
mojo.execute();
String resourcesDir = project.getOutputDirectory();
String checkString = "current working directory = FPJ kami!!!";
assertContent(resourcesDir + "/file4.txt", checkString);
}
Aggregations