Search in sources :

Example 1 with MavenSettingsView

use of org.commonjava.maven.galley.maven.model.view.settings.MavenSettingsView in project galley by Commonjava.

the class MavenSettingsReader method read.

/**
     * Read (and stack by inheritance) one or more settings.xml files, and return a view that can be used to 
     * query various parts of the Maven settings object.<br/>
     * <br/>
     * <b>NOTE:</b> The first file in the list should be the most specific (eg. user-level),
     * followed by ancester files in the inheritance hierarchy (parent, grand-parent, etc.).
     * 
     * @param settingsFiles One or more files to parse, in most-local-first order
     * @return The settings object
     * @throws GalleyMavenException XML parsing failed, or a file could not be read.
     */
public MavenSettingsView read(final File... settingsFiles) throws GalleyMavenException {
    final List<DocRef<File>> drs = new ArrayList<DocRef<File>>();
    for (final File f : settingsFiles) {
        if (f == null || !f.exists()) {
            continue;
        }
        try {
            final Document doc = xml.parse(f);
            drs.add(new DocRef<File>(f, f, doc));
        } catch (final GalleyMavenXMLException e) {
            throw new GalleyMavenException("Failed to parse settings XML: {}. Reason: {}", e, f, e.getMessage());
        }
    }
    if (drs.isEmpty()) {
        return null;
    }
    final MavenSettingsView view = new MavenSettingsView(drs, xpath, xml);
    return view;
}
Also used : MavenSettingsView(org.commonjava.maven.galley.maven.model.view.settings.MavenSettingsView) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) Document(org.w3c.dom.Document) File(java.io.File)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)1 DocRef (org.commonjava.maven.galley.maven.model.view.DocRef)1 MavenSettingsView (org.commonjava.maven.galley.maven.model.view.settings.MavenSettingsView)1 Document (org.w3c.dom.Document)1