Search in sources :

Example 1 with DocRef

use of org.commonjava.maven.galley.maven.model.view.DocRef 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)

Example 2 with DocRef

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

the class AbstractMavenXmlReader method getAllCached.

protected synchronized Map<Location, DocRef<T>> getAllCached(final T ref, final List<? extends Location> locations) {
    final Map<Location, DocRef<T>> result = new HashMap<Location, DocRef<T>>();
    for (final Location location : locations) {
        final DocCacheKey<T> key = new DocCacheKey<T>(ref, location);
        final WeakReference<DocRef<T>> reference = cache.get(key);
        if (reference != null) {
            final DocRef<T> dr = reference.get();
            if (dr == null) {
                cache.remove(key);
            } else {
                result.put(location, dr);
            }
        }
    }
    return result;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) Location(org.commonjava.maven.galley.model.Location)

Example 3 with DocRef

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

the class AbstractMavenXmlReader method getFirstCached.

protected synchronized DocRef<T> getFirstCached(final T ref, final Collection<? extends Location> locations) throws TransferException {
    for (final Location location : locationExpander.expand(locations)) {
        final DocCacheKey<T> key = new DocCacheKey<T>(ref, location);
        final WeakReference<DocRef<T>> reference = cache.get(key);
        if (reference != null) {
            final DocRef<T> dr = reference.get();
            if (dr == null) {
                cache.remove(key);
            } else {
                return dr;
            }
        }
    }
    return null;
}
Also used : DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) Location(org.commonjava.maven.galley.model.Location)

Example 4 with DocRef

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

the class MavenPomReader method read.

public MavenPomView read(final ProjectVersionRef ref, final List<? extends Location> locations, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
    final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
    ProjectVersionRef next = ref;
    do {
        DocRef<ProjectVersionRef> dr;
        try {
            dr = getDocRef(next, locations, cache, eventMetadata);
        } catch (final TransferException e) {
            throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, next, stack.size(), ref, e.getMessage());
        }
        if (dr == null) {
            throw new GalleyMavenException("Cannot resolve {}, {} levels dep in the ancestry stack of: {}", next, stack.size(), ref);
        }
        stack.add(dr);
        next = xml.getParentRef(dr.getDoc());
    } while (next != null);
    final MavenPomView view = new MavenPomView(ref, stack, xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
    assembleImportedInformation(view, locations);
    logStructure(view);
    return view;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 5 with DocRef

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

the class MavenMetadataReader method getMetadata.

public MavenMetadataView getMetadata(final ProjectRef ref, final List<? extends Location> locations, final EventMetadata eventMetadata) throws GalleyMavenException {
    final List<DocRef<ProjectRef>> docs = new ArrayList<DocRef<ProjectRef>>(locations.size());
    final Map<Location, DocRef<ProjectRef>> cached = getAllCached(ref, locations);
    final List<? extends Location> toRetrieve = new ArrayList<Location>(locations);
    for (final Location loc : locations) {
        final DocRef<ProjectRef> dr = cached.get(loc);
        if (dr != null) {
            docs.add(dr);
            toRetrieve.remove(loc);
        } else {
            docs.add(null);
        }
    }
    List<Transfer> transfers;
    try {
        transfers = metadataManager.retrieveAll(toRetrieve, ref, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to resolve metadata for: {} from: {}. Reason: {}", e, ref, locations, e.getMessage());
    }
    logger.debug("Resolved {} transfers:\n  {}", transfers.size(), new JoinString("\n  ", transfers));
    if (transfers != null && !transfers.isEmpty()) {
        for (final Transfer transfer : transfers) {
            final DocRef<ProjectRef> dr = new DocRef<ProjectRef>(ref, transfer.getLocation(), xml.parse(transfer, eventMetadata));
            final int idx = locations.indexOf(transfer.getLocation());
            //
            if (idx > -1) {
                docs.set(idx, dr);
            } else {
                docs.add(dr);
            }
        }
    }
    for (final Iterator<DocRef<ProjectRef>> iterator = docs.iterator(); iterator.hasNext(); ) {
        final DocRef<ProjectRef> docRef = iterator.next();
        if (docRef == null) {
            iterator.remove();
        }
    }
    logger.debug("Got {} metadata documents for: {}", docs.size(), ref);
    return new MavenMetadataView(docs, xpath, xml);
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) TransferException(org.commonjava.maven.galley.TransferException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Transfer(org.commonjava.maven.galley.model.Transfer) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Location(org.commonjava.maven.galley.model.Location)

Aggregations

DocRef (org.commonjava.maven.galley.maven.model.view.DocRef)6 ArrayList (java.util.ArrayList)4 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)4 TransferException (org.commonjava.maven.galley.TransferException)3 Location (org.commonjava.maven.galley.model.Location)3 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)2 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)2 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)2 File (java.io.File)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)1 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)1 MavenMetadataView (org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView)1 MavenSettingsView (org.commonjava.maven.galley.maven.model.view.settings.MavenSettingsView)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 Document (org.w3c.dom.Document)1