use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class ResourcesMojoTest method testPropertyFiles_MainAndExtra.
/**
* @throws Exception
*/
public void testPropertyFiles_MainAndExtra() throws Exception {
File testPom = new File(getBasedir(), defaultPomFilePath);
ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_MainAndExtra");
List<Resource> resources = project.getBuild().getResources();
LinkedList<String> filterList = new LinkedList<String>();
LinkedList<String> extraFilterList = new LinkedList<String>();
assertNotNull(mojo);
project.addFile("main-extra.properties", "current working directory=${dir}; old working directory=${dir2}");
project.addFile("filter.properties", "dir:testdir");
project.addFile("extra-filter.properties", "dir2:testdir2");
project.setResourceFiltering(0, true);
project.cleanBuildEnvironment();
project.setupBuildEnvironment();
filterList.add(project.getResourcesDirectory() + "filter.properties");
extraFilterList.add(project.getResourcesDirectory() + "extra-filter.properties");
// setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "resources", resources);
setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
setVariableValueToObject(mojo, "buildFilters", filterList);
setVariableValueToObject(mojo, "filters", extraFilterList);
setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
mojo.execute();
String resourcesDir = project.getOutputDirectory();
String checkString = "current working directory=testdir; old working directory=testdir2";
File file = new File(resourcesDir, "main-extra.properties");
assertContent(file.getAbsolutePath(), checkString);
}
use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class ResourcesMojoTest method testPropertyFiles_Extra.
/**
* @throws Exception
*/
public void testPropertyFiles_Extra() throws Exception {
File testPom = new File(getBasedir(), defaultPomFilePath);
ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
MavenProjectResourcesStub project = new MavenProjectResourcesStub("resourcePropertyFiles_Extra");
List<Resource> resources = project.getBuild().getResources();
LinkedList<String> filterList = new LinkedList<String>();
assertNotNull(mojo);
project.addFile("extra.properties", "current working directory=${dir}");
project.addFile("filter.properties", "dir:testdir");
project.setResourceFiltering(0, true);
project.setupBuildEnvironment();
filterList.add(project.getResourcesDirectory() + "filter.properties");
// setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "resources", resources);
setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
setVariableValueToObject(mojo, "filters", filterList);
setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
mojo.execute();
String resourcesDir = project.getOutputDirectory();
String checkString = "current working directory=testdir";
assertContent(resourcesDir + "/extra.properties", checkString);
}
use of org.apache.maven.model.Resource in project maven-plugins by apache.
the class TestResourcesTest method testTestResourceDirectoryCreation.
/**
* @throws Exception
*/
public void testTestResourceDirectoryCreation() throws Exception {
File testPom = new File(getBasedir(), defaultPomFilePath);
TestResourcesMojo mojo = (TestResourcesMojo) lookupMojo("testResources", testPom);
MavenProjectResourcesStub project = new MavenProjectResourcesStub("testResourceDirectoryStructure");
List<Resource> resources = project.getBuild().getResources();
assertNotNull(mojo);
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, "project", project);
setVariableValueToObject(mojo, "resources", resources);
setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getTestOutputDirectory()));
setVariableValueToObject(mojo, "buildFilters", Collections.emptyList());
setVariableValueToObject(mojo, "useBuildFilters", Boolean.TRUE);
mojo.execute();
String resorucesDir = project.getTestOutputDirectory();
assertTrue(FileUtils.fileExists(resorucesDir + "/file4.txt"));
assertTrue(FileUtils.fileExists(resorucesDir + "/package/file3.nottest"));
assertTrue(FileUtils.fileExists(resorucesDir + "/notpackage/file1.include"));
assertTrue(FileUtils.fileExists(resorucesDir + "/package/test"));
assertTrue(FileUtils.fileExists(resorucesDir + "/notpackage/test"));
}
use of org.apache.maven.model.Resource in project sling by apache.
the class GenerateAdapterMetadataMojo method addResource.
private void addResource() {
final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
boolean found = false;
final Iterator<Resource> rsrcIterator = this.project.getResources().iterator();
while (!found && rsrcIterator.hasNext()) {
final Resource rsrc = rsrcIterator.next();
found = rsrc.getDirectory().equals(ourRsrcPath);
}
if (!found) {
final Resource resource = new Resource();
resource.setDirectory(this.outputDirectory.getAbsolutePath());
this.project.addResource(resource);
}
}
use of org.apache.maven.model.Resource in project sling by apache.
the class ValidationMojo method execute.
/**
* @see org.apache.maven.plugin.AbstractMojo#execute()
*/
public void execute() throws MojoExecutionException {
if (this.skip) {
getLog().info("Validation is skipped.");
return;
}
final Iterator<Resource> rsrcIterator = this.project.getResources().iterator();
while (rsrcIterator.hasNext()) {
final Resource rsrc = rsrcIterator.next();
final File directory = new File(rsrc.getDirectory());
if (directory.exists()) {
getLog().debug("Scanning " + rsrc.getDirectory());
final DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(directory);
if (rsrc.getExcludes() != null && rsrc.getExcludes().size() > 0) {
scanner.setExcludes((String[]) rsrc.getExcludes().toArray(new String[rsrc.getExcludes().size()]));
}
scanner.addDefaultExcludes();
if (rsrc.getIncludes() != null && rsrc.getIncludes().size() > 0) {
scanner.setIncludes((String[]) rsrc.getIncludes().toArray(new String[rsrc.getIncludes().size()]));
}
scanner.scan();
final String[] files = scanner.getIncludedFiles();
if (files != null) {
for (int m = 0; m < files.length; m++) {
this.validate(directory, files[m]);
}
}
}
}
}
Aggregations