use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.
the class GrammarExtensionMojo method merge.
private void merge(BufferedWriter writer, Pair<String, String> baseBlocks, String[] extensions) throws IOException, MojoExecutionException {
String errorMessage = "Merged base node doesn't conform to expected mergable node structure";
int block1Open = baseBlocks.first.indexOf(OPEN_BRACE);
int block1Close = baseBlocks.first.lastIndexOf(CLOSE_BRACE);
// first block
writer.write(OPEN_BRACE);
if (extensions[0] != null) {
writer.write(extensions[0]);
}
writer.write(baseBlocks.first.substring(block1Open + 1, block1Close));
if (extensions[1] != null) {
writer.write(extensions[1]);
}
writer.write(CLOSE_BRACE);
writer.newLine();
// second block
writer.write(OPEN_BRACE);
writer.newLine();
if (extensions[2] != null) {
writer.write(extensions[2]);
}
String innerBlock2String = null;
if (baseBlocks.second != null) {
BufferedReader blockReader = stringToReader(baseBlocks.second);
Position blockPosition = new Position();
blockPosition.index = 0;
blockPosition.line = blockReader.readLine();
while (blockPosition.line != null && (blockPosition.line.trim().length() == 0 || blockPosition.line.indexOf(OPEN_BRACE) < 0)) {
if (blockPosition.line.trim().length() > 0) {
writer.write(blockPosition.line);
writer.newLine();
}
blockPosition.line = blockReader.readLine();
}
if (blockPosition.line == null) {
throw new MojoExecutionException(errorMessage);
}
int block2Open = blockPosition.line.indexOf(OPEN_BRACE);
blockPosition.line = blockPosition.line.substring(block2Open + 1);
while (blockPosition.line != null && (blockPosition.line.trim().length() == 0 || blockPosition.line.indexOf(OPEN_PAREN) < 0)) {
if (blockPosition.line.trim().length() > 0) {
writer.write(blockPosition.line);
writer.newLine();
}
blockPosition.line = blockReader.readLine();
}
if (blockPosition.line == null) {
throw new MojoExecutionException(errorMessage);
}
int innerBlock1Open = blockPosition.line.indexOf(OPEN_PAREN);
writer.write(" ");
writer.write(OPEN_PAREN);
blockPosition.index = innerBlock1Open;
readBlock(blockReader, OPEN_PAREN, CLOSE_PAREN, blockPosition);
String innerBlock1String = record.toString();
writer.newLine();
writer.write(" ");
writer.write(innerBlock1String.substring(innerBlock1String.indexOf(OPEN_PAREN) + 1, innerBlock1String.lastIndexOf(CLOSE_PAREN)).trim());
writer.newLine();
record.reset();
// read second inner block
blockPosition.line = blockReader.readLine();
while (blockPosition.line != null && blockPosition.line.trim().length() == 0) {
blockPosition.line = blockReader.readLine();
}
int innerBlock2Open = blockPosition.line.indexOf(OPEN_BRACE);
if (innerBlock2Open < 0) {
throw new MojoExecutionException(errorMessage);
}
blockPosition.index = innerBlock2Open;
readBlock(blockReader, OPEN_BRACE, CLOSE_BRACE, blockPosition);
innerBlock2String = record.toString();
record.reset();
}
if (extensions[3] != null) {
writer.write(extensions[3]);
}
writer.newLine();
writer.write(" ");
writer.write(CLOSE_PAREN);
writer.newLine();
writer.write(" ");
writer.write(OPEN_BRACE);
if (extensions[4] != null) {
writer.write(extensions[4]);
}
if (innerBlock2String != null) {
writer.newLine();
writer.write(" ");
writer.write(innerBlock2String.substring(innerBlock2String.indexOf(OPEN_BRACE) + 1, innerBlock2String.lastIndexOf(CLOSE_BRACE)).trim());
writer.newLine();
}
if (extensions[5] != null) {
writer.write(extensions[5]);
}
// Close inner second block
writer.write(" ");
writer.write(CLOSE_BRACE);
writer.newLine();
// Close second block
writer.write(CLOSE_BRACE);
writer.newLine();
}
use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.
the class TestDataGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
FileSetManager mgr = new FileSetManager();
// this seems pretty hacky, but necessary to get the correct result.
File inputFilesDirectory = new File(inputFiles.getDirectory());
if (!inputFilesDirectory.isAbsolute()) {
inputFiles.setDirectory(new File(project.getBasedir(), inputFiles.getDirectory()).getAbsolutePath());
}
final String[] includedFiles = mgr.getIncludedFiles(inputFiles);
getLog().info("Processing " + includedFiles.length + " files...");
for (String file : includedFiles) {
getLog().info(" -" + file);
try {
TemplateHelper.INSTANCE.processFile(new File(inputFiles.getDirectory(), file), new File(outputDir, file.replace(".template", "")));
} catch (IOException e) {
e.printStackTrace();
throw new MojoExecutionException("failure", e);
}
}
}
use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.
the class GenerateFileMojo method execute.
@java.lang.Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
init();
readExtraMaps();
addDependenciesToLicenseMap();
resolveLicenseContent();
resolveNoticeFiles();
resolveLicenseFiles();
rebuildLicenseContentProjectMap();
combineCommonGavs();
SourcePointerResolver.execute(this);
persistLicenseMap();
buildNoticeProjectMap();
generateFiles();
} catch (IOException | TemplateException | ProjectBuildingException e) {
throw new MojoExecutionException("Unexpected exception: " + e, e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.
the class SupplementalModelHelper method loadSupplements.
static Map<String, Model> loadSupplements(Log log, String[] models) throws MojoExecutionException {
if (models == null) {
log.debug("Supplemental data models won't be loaded. " + "No models specified.");
return Collections.emptyMap();
}
List<Supplement> supplements = new ArrayList<>();
for (String set : models) {
log.debug("Preparing ruleset: " + set);
try {
File f = new File(set);
if (!f.exists()) {
throw new MojoExecutionException("Cold not resolve " + set);
}
if (!f.canRead()) {
throw new MojoExecutionException("Supplemental data models won't be loaded. " + "File " + f.getAbsolutePath() + " cannot be read, check permissions on the file.");
}
log.debug("Loading supplemental models from " + f.getAbsolutePath());
SupplementalDataModelXpp3Reader reader = new SupplementalDataModelXpp3Reader();
try (FileInputStream fis = new FileInputStream(f);
Reader fileReader = new InputStreamReader(fis)) {
SupplementalDataModel supplementalModel = reader.read(fileReader);
supplements.addAll(supplementalModel.getSupplement());
}
} catch (Exception e) {
String msg = "Error loading supplemental data models: " + e.getMessage();
log.error(msg, e);
throw new MojoExecutionException(msg, e);
}
}
log.debug("Loading supplements complete.");
Map<String, Model> supplementMap = new HashMap<>();
for (Supplement sd : supplements) {
Xpp3Dom dom = (Xpp3Dom) sd.getProject();
Model m = getSupplement(log, dom);
supplementMap.put(generateSupplementMapKey(m.getGroupId(), m.getArtifactId()), m);
}
return supplementMap;
}
use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.
the class AbstractHyracksMojo method launch.
protected Process launch(File command, String options, File workingDir) throws MojoExecutionException {
if (!command.isFile()) {
throw new MojoExecutionException(command.getAbsolutePath() + " is not an executable program");
}
getLog().info("Executing Hyracks command: " + command + " with args [" + options + "]");
String osName = System.getProperty("os.name");
try {
if (osName.startsWith("Windows")) {
return launchWindowsBatch(command, options);
} else {
return launchUnixScript(command, options, workingDir);
}
} catch (IOException e) {
throw new MojoExecutionException("Error executing command: " + command.getAbsolutePath(), e);
}
}
Aggregations