Search in sources :

Example 1 with Supplement

use of org.apache.maven.plugin.resources.remote.Supplement 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)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Model (org.apache.maven.model.Model)1 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Supplement (org.apache.maven.plugin.resources.remote.Supplement)1 SupplementalDataModel (org.apache.maven.plugin.resources.remote.SupplementalDataModel)1 SupplementalDataModelXpp3Reader (org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader)1 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1