Search in sources :

Example 21 with MojoExecutionException

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();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BufferedReader(java.io.BufferedReader)

Example 22 with MojoExecutionException

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);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) FileSetManager(org.apache.maven.shared.model.fileset.util.FileSetManager)

Example 23 with MojoExecutionException

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);
    }
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Example 24 with MojoExecutionException

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;
}
Also used : SupplementalDataModelXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SupplementalDataModelXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileInputStream(java.io.FileInputStream) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Supplement(org.apache.maven.plugin.resources.remote.Supplement) SupplementalDataModel(org.apache.maven.plugin.resources.remote.SupplementalDataModel) Model(org.apache.maven.model.Model) SupplementalDataModel(org.apache.maven.plugin.resources.remote.SupplementalDataModel) File(java.io.File)

Example 25 with MojoExecutionException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1221 IOException (java.io.IOException)656 File (java.io.File)572 MojoFailureException (org.apache.maven.plugin.MojoFailureException)275 Artifact (org.apache.maven.artifact.Artifact)162 ArrayList (java.util.ArrayList)151 FileInputStream (java.io.FileInputStream)77 MavenProject (org.apache.maven.project.MavenProject)76 HashMap (java.util.HashMap)68 Properties (java.util.Properties)63 FileOutputStream (java.io.FileOutputStream)61 Map (java.util.Map)60 URL (java.net.URL)59 MalformedURLException (java.net.MalformedURLException)57 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)52 FileWriter (java.io.FileWriter)50 List (java.util.List)49 URLClassLoader (java.net.URLClassLoader)45 LinkedHashSet (java.util.LinkedHashSet)40 InputStream (java.io.InputStream)38