use of org.apache.maven.plugin.MojoExecutionException in project jangaroo-tools by CoreMedia.
the class PomConverter method changePackaging.
/**
* Changes the packaging from jangaroo to jangaroo-pkg in {@code /project/packaging}
*/
private static void changePackaging(Document document) throws MojoExecutionException {
try {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
Node packagingNode = (Node) xPath.evaluate("/project/packaging[text() = 'jangaroo']", document, NODE);
if (packagingNode != null) {
packagingNode.setTextContent("jangaroo-pkg");
}
} 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 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 midpoint by Evolveum.
the class SchemaDocMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("SchemaDoc plugin started");
PrismContext prismContext = createInitializedPrismContext();
File outDir = initializeOutDir();
PathGenerator pathGenerator = new PathGenerator(outDir);
VelocityEngine velocityEngine = createVelocityEngine();
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
try {
renderSchemaIndex(schemaRegistry, prismContext, velocityEngine, pathGenerator);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
for (PrismSchema schema : schemaRegistry.getSchemas()) {
try {
renderSchema(schema, prismContext, velocityEngine, pathGenerator);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
try {
copyResources(outDir);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
File archiveFile = null;
try {
archiveFile = generateArchive(outDir, finalName + "-schemadoc.zip");
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (ArchiverException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
projectHelper.attachArtifact(project, "zip", "schemadoc", archiveFile);
getLog().info("SchemaDoc plugin finished");
}
use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.
the class GrammarExtensionMojo method processExtension.
private void processExtension() throws MojoExecutionException {
try (BufferedReader reader = Files.newBufferedReader(Paths.get(base, gextension), StandardCharsets.UTF_8)) {
StringBuilder identifier = new StringBuilder();
String nextOperation = OVERRIDEPRODUCTION;
while (read || (position.line = reader.readLine()) != null) {
read = false;
if (position.line.trim().startsWith("//")) {
// skip comments
continue;
}
String[] tokens = position.line.split(REGEX_WS_PAREN);
position.index = 0;
int openBraceIndex = position.line.indexOf(OPEN_BRACE);
int openAngularIndex = position.line.trim().indexOf(OPEN_ANGULAR);
if (tokens.length > 0 && identifier.length() == 0 && EXTENSIONKEYWORDS.contains(tokens[0])) {
switch(tokens[0]) {
case KWIMPORT:
handleImport(reader);
break;
case KWUNIMPORT:
handleUnImport(reader);
break;
case NEWPRODUCTION:
nextOperation = NEWPRODUCTION;
break;
case NEW_AT_THE_END_PRODUCTION:
nextOperation = NEW_AT_THE_END_PRODUCTION;
break;
case NEW_AT_THE_END_CLASS_DEFINITION:
nextOperation = NEW_AT_THE_END_CLASS_DEFINITION;
break;
case MERGEPRODUCTION:
nextOperation = MERGEPRODUCTION;
shouldReplace = shouldReplace(tokens, position.line);
break;
case OVERRIDEPRODUCTION:
nextOperation = OVERRIDEPRODUCTION;
break;
default:
break;
}
} else if (openBraceIndex >= 0 && openAngularIndex < 0) {
String beforeBrace = position.line.substring(0, openBraceIndex);
if (beforeBrace.trim().length() > 0) {
identifier.append(beforeBrace);
} else if (identifier.length() == 0) {
identifier.append(lastIdentifier);
}
position.index = openBraceIndex;
switch(nextOperation) {
case NEWPRODUCTION:
handleNew(identifier, reader);
break;
case NEW_AT_THE_END_CLASS_DEFINITION:
readFinalProduction(identifier, reader);
addFinalProduction(identifier, extensionMethodsAtTheClassDef);
break;
case OVERRIDEPRODUCTION:
handleOverride(identifier, reader);
break;
case MERGEPRODUCTION:
handleMerge(identifier, reader);
break;
default:
throw new MojoExecutionException("Malformed extention file");
}
nextOperation = NEWPRODUCTION;
} else if (openAngularIndex == 0) {
if (nextOperation != NEWPRODUCTION && nextOperation != NEW_AT_THE_END_PRODUCTION) {
throw new MojoExecutionException("Can only add new REGEX production kind");
}
position.index = position.line.indexOf(OPEN_ANGULAR);
readFinalProduction(identifier, reader);
if (nextOperation == NEWPRODUCTION) {
addFinalProduction(identifier, extensionFinals);
} else if (nextOperation == NEW_AT_THE_END_PRODUCTION) {
addFinalProduction(identifier, extensionFinalsAtTheEnd);
}
} else if (identifier.length() > 0 || position.line.trim().length() > 0) {
identifier.append(position.line);
identifier.append('\n');
}
}
} catch (Exception e) {
getLog().error(e);
throw new MojoExecutionException(e.getMessage(), e);
}
}
Aggregations