use of org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub in project maven-plugins by apache.
the class RemoteResourcesMojoTest method testVelocityISO88591.
public void testVelocityISO88591() throws Exception {
final MavenProjectResourcesStub project = createTestProject("default-iso88591");
final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.3" });
setupDefaultProject(project);
ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.3"), null, "jar", "", new DefaultArtifactHandler()));
File file = new File(repo.getBasedir() + "/" + path + ".jar");
file.getParentFile().mkdirs();
buildResourceBundle("default-iso88591-create", "ISO-8859-1", new String[] { "ISO-8859-1.bin.vm" }, file);
mojo.execute();
file = (File) getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "ISO-8859-1.bin");
assertTrue(file.exists());
InputStream in = new FileInputStream(file);
byte[] data = IOUtil.toByteArray(in);
in.close();
byte[] expected = "äöüÄÖÜß".getBytes("ISO-8859-1");
assertTrue(Arrays.equals(expected, data));
}
use of org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub in project maven-plugins by apache.
the class RemoteResourcesMojoTest method testSimpleBundlesWithType.
public void testSimpleBundlesWithType() throws Exception {
final MavenProjectResourcesStub project = createTestProject("default-simplebundles");
final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.0:war" });
setupDefaultProject(project);
ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.0"), null, "war", "", new DefaultArtifactHandler()));
File file = new File(repo.getBasedir() + "/" + path + ".war");
file.getParentFile().mkdirs();
buildResourceBundle("default-simplebundles-create", null, new String[] { "SIMPLE.txt" }, file);
mojo.execute();
file = (File) getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "SIMPLE.txt");
assertTrue(file.exists());
}
use of org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub in project maven-plugins by apache.
the class RemoteResourcesMojoTest method testFilteredBundlesWithProjectProperties.
public void testFilteredBundlesWithProjectProperties() throws Exception {
final MavenProjectResourcesStub project = createTestProject("default-filterbundles-two");
final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test-filtered-bundles:test-filtered-bundles:2" });
mojo.includeProjectProperties = true;
setupDefaultProject(project);
project.addProperty("testingPropertyOne", "maven");
project.addProperty("testingPropertyTwo", "rules");
ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
String path = repo.pathOf(new DefaultArtifact("test-filtered-bundles", "test-filtered-bundles", VersionRange.createFromVersion("2"), null, "jar", "", new DefaultArtifactHandler()));
File file = new File(repo.getBasedir() + "/" + path + ".jar");
file.getParentFile().mkdirs();
buildResourceBundle("default-filterbundles-two-create", null, new String[] { "PROPERTIES.txt.vm" }, file);
mojo.execute();
// executing a second time (example: forked lifecycle) should still work
mojo.execute();
file = (File) getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "PROPERTIES.txt");
assertTrue(file.exists());
String data = FileUtils.fileRead(file);
assertTrue(data.contains("maven"));
assertTrue(data.contains("rules"));
}
use of org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub in project maven-plugins by apache.
the class RemoteResourcesMojoTest method buildResourceBundle.
protected void buildResourceBundle(String id, String sourceEncoding, String[] resourceNames, File jarName) throws Exception {
final MavenProjectResourcesStub project = createTestProject(id);
final File resourceDir = new File(project.getBasedir() + "/src/main/resources");
final BundleRemoteResourcesMojo mojo = lookupBundleMojoWithSettings(project, resourceDir, sourceEncoding);
setupDefaultProject(project);
for (String resourceName2 : resourceNames) {
File resource = new File(resourceDir, resourceName2);
URL source = getClass().getResource("/" + resourceName2);
FileUtils.copyURLToFile(source, resource);
}
mojo.execute();
File xmlFile = new File(project.getBasedir() + "/target/classes/META-INF/maven/remote-resources.xml");
assertTrue(xmlFile.exists());
String data = FileUtils.fileRead(xmlFile);
for (String resourceName1 : resourceNames) {
assertTrue(data.contains(resourceName1));
}
if (null != jarName) {
JarOutputStream jar = new JarOutputStream(new FileOutputStream(jarName));
jar.putNextEntry(new ZipEntry("META-INF/maven/remote-resources.xml"));
jar.write(data.getBytes());
jar.closeEntry();
for (String resourceName : resourceNames) {
File resource = new File(resourceDir, resourceName);
InputStream in = new FileInputStream(resource);
jar.putNextEntry(new ZipEntry(resourceName));
IOUtil.copy(in, jar);
jar.closeEntry();
in.close();
}
jar.close();
}
}
use of org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub in project maven-plugins by apache.
the class RemoteResourcesMojoTest method testVelocityUTF8.
public void testVelocityUTF8() throws Exception {
final MavenProjectResourcesStub project = createTestProject("default-utf8");
final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.2" });
setupDefaultProject(project);
ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.2"), null, "jar", "", new DefaultArtifactHandler()));
File file = new File(repo.getBasedir() + "/" + path + ".jar");
file.getParentFile().mkdirs();
buildResourceBundle("default-utf8-create", "UTF-8", new String[] { "UTF-8.bin.vm" }, file);
mojo.execute();
file = (File) getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "UTF-8.bin");
assertTrue(file.exists());
InputStream in = new FileInputStream(file);
byte[] data = IOUtil.toByteArray(in);
in.close();
byte[] expected = "äöüÄÖÜß".getBytes("UTF-8");
assertTrue(Arrays.equals(expected, data));
}
Aggregations