Search in sources :

Example 1 with SupplementalDataModelXpp3Reader

use of org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader 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 2 with SupplementalDataModelXpp3Reader

use of org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader in project maven-plugins by apache.

the class ProcessRemoteResourcesMojo method loadSupplements.

private Map<String, Model> loadSupplements(String[] models) throws MojoExecutionException {
    if (models == null) {
        getLog().debug("Supplemental data models won't be loaded.  " + "No models specified.");
        return Collections.emptyMap();
    }
    List<Supplement> supplements = new ArrayList<Supplement>();
    for (String set : models) {
        getLog().debug("Preparing ruleset: " + set);
        try {
            File f = locator.getResourceAsFile(set, getLocationTemp(set));
            if (null == f || !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.");
            }
            getLog().debug("Loading supplemental models from " + f.getAbsolutePath());
            SupplementalDataModelXpp3Reader reader = new SupplementalDataModelXpp3Reader();
            SupplementalDataModel supplementalModel = reader.read(new FileReader(f));
            supplements.addAll(supplementalModel.getSupplement());
        } catch (Exception e) {
            String msg = "Error loading supplemental data models: " + e.getMessage();
            getLog().error(msg, e);
            throw new MojoExecutionException(msg, e);
        }
    }
    getLog().debug("Loading supplements complete.");
    Map<String, Model> supplementMap = new HashMap<String, Model>();
    for (Supplement sd : supplements) {
        Xpp3Dom dom = (Xpp3Dom) sd.getProject();
        Model m = getSupplement(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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) InvalidDependencyVersionException(org.apache.maven.project.artifact.InvalidDependencyVersionException) InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) MalformedURLException(java.net.MalformedURLException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ParseErrorException(org.apache.velocity.exception.ParseErrorException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) Model(org.apache.maven.model.Model) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

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