use of org.apache.maven.plugin.MojoExecutionException in project jangaroo-tools by CoreMedia.
the class PomConverter method writePom.
/**
* Serializes the given DOM document into a POM file within the given directory.
*/
private static void writePom(Document document, File projectBaseDir) throws MojoExecutionException {
try {
File pomFile = new File(projectBaseDir, "pom.xml");
// keep trailing whitespace because it's not reproduced by the transformer and we want to keep the diff small
String pom = readFileToString(pomFile);
String trailingWhitespace = pom.substring(pom.lastIndexOf('>') + 1);
PrintWriter pomWriter = new PrintWriter(pomFile);
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
// the transformer does not reproduce the new line after the XML declaration, so we do it on our own
// see https://bugs.openjdk.java.net/browse/JDK-7150637
transformer.setOutputProperty(OMIT_XML_DECLARATION, "yes");
if (document.getXmlEncoding() != null) {
pomWriter.print("<?xml version=\"");
pomWriter.print(document.getXmlVersion());
pomWriter.print("\" encoding=\"");
pomWriter.print(document.getXmlEncoding());
pomWriter.println("\"?>");
}
transformer.transform(new DOMSource(document), new StreamResult(pomWriter));
pomWriter.write(trailingWhitespace);
} finally {
pomWriter.close();
}
} catch (IOException e) {
throw new MojoExecutionException("error while generating modified POM", e);
} catch (TransformerException e) {
throw new MojoExecutionException("error while generating modified POM", e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project jangaroo-tools by CoreMedia.
the class PomConverter method removeExmlPlugin.
/**
* Replaces exml-maven-plugin configuration by jangaroo-maven-plugin configuration within
* {@code /project/build/plugins} and {@code /project/build/pluginManagement/plugins}.
*/
private static void removeExmlPlugin(Document document) throws MojoExecutionException {
try {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
Node pluginsNode = (Node) xPath.evaluate("/project/build/plugins", document, NODE);
removeExmlPlugin(pluginsNode);
pluginsNode = (Node) xPath.evaluate("/project/build/pluginManagement/plugins", document, NODE);
removeExmlPlugin(pluginsNode);
} catch (XPathException e) {
throw new MojoExecutionException("error while generating modified POM", e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project jangaroo-tools by CoreMedia.
the class AbstractCompilerMojo method buildOutputFile.
private void buildOutputFile(File tempOutputDir, File outputFile) throws MojoExecutionException {
final Log log = getLog();
if (log.isDebugEnabled()) {
log.debug("Output file: " + outputFile);
}
try {
// If the directory where the output file is going to land
// doesn't exist then create it.
File outputFileDirectory = outputFile.getParentFile();
if (!outputFileDirectory.exists()) {
//noinspection ResultOfMethodCallIgnored
if (outputFileDirectory.mkdirs()) {
log.debug("created output directory " + outputFileDirectory);
}
}
@SuppressWarnings({ "unchecked" }) List<File> // resource bundle classes should always be loaded dynamically:
files = FileUtils.getFiles(tempOutputDir, "**/*.js", "**/*_properties_*.js");
// We should now have all the files we want to concat so let's do it.
Writer fos = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8");
int tempOutputDirPathLength = tempOutputDir.getAbsolutePath().length() + 1;
for (File file : files) {
String className = file.getAbsolutePath();
className = className.substring(tempOutputDirPathLength, className.length() - ".js".length());
className = className.replace(File.separatorChar, '.');
fos.write("// class " + className + "\n");
IOUtil.copy(new FileInputStream(file), fos, "UTF-8");
fos.write('\n');
}
fos.close();
} catch (IOException e) {
throw new MojoExecutionException("could not build output file " + outputFile + ": " + e.toString(), e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project jangaroo-tools by CoreMedia.
the class PropertiesMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (!generatedSourcesDirectory.exists()) {
getLog().info("generating sources into: " + generatedSourcesDirectory.getPath());
getLog().debug("created " + generatedSourcesDirectory.mkdirs());
}
if (properties == null) {
properties = new FileSet();
properties.setDirectory(resourceDirectory.getAbsolutePath());
properties.addInclude("**/*.properties");
}
FileLocations config = new FileLocations();
config.setOutputDirectory(generatedSourcesDirectory);
for (String srcFileRelativePath : new FileSetManager().getIncludedFiles(properties)) {
config.addSourceFile(new File(resourceDirectory, srcFileRelativePath));
}
try {
config.setSourcePath(Arrays.asList(resourceDirectory));
} catch (IOException e) {
throw new MojoExecutionException("configuration failure", e);
}
PropertyClassGenerator generator = new PropertyClassGenerator(config);
try {
generator.generate();
} catch (PropcException e) {
throw new MojoExecutionException("Generation failure", e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project jangaroo-tools by CoreMedia.
the class JooTestMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (!skip && !skipTests && !skipJooUnitTests && isTestAvailable()) {
Server server = jettyRunTest(true);
String url = getTestUrl(server);
try {
File testResultOutputFile = new File(testResultOutputDirectory, getTestResultFileName());
File phantomTestRunner = new File(testResultOutputDirectory, "phantomjs-joounit-page-runner.js");
FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("/net/jangaroo/jooc/mvnplugin/phantomjs-joounit-page-runner.js"), phantomTestRunner);
final PhantomJsTestRunner phantomJsTestRunner = new PhantomJsTestRunner(phantomBin, url, testResultOutputFile.getPath(), phantomTestRunner.getPath(), jooUnitTestExecutionTimeout, jooUnitMaxRetriesOnCrashes, getLog());
if (phantomJsTestRunner.canRun()) {
executePhantomJs(testResultOutputFile, phantomJsTestRunner);
} else {
executeSelenium(url);
}
} catch (IOException e) {
throw new MojoExecutionException("Cannot create local copy of phantomjs-joounit-page-runner.js", e);
} finally {
try {
server.stop();
} catch (Exception e) {
// never mind we just couldn't step the selenium server.
getLog().error("Could not stop test Jetty.", e);
}
}
}
}
Aggregations