Search in sources :

Example 6 with GalleyMavenException

use of org.commonjava.maven.galley.maven.GalleyMavenException 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 7 with GalleyMavenException

use of org.commonjava.maven.galley.maven.GalleyMavenException in project galley by Commonjava.

the class MavenPomReader method readLocalPom.

public MavenPomView readLocalPom(final ProjectVersionRef ref, final Transfer transfer, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
    DocRef<ProjectVersionRef> dr;
    try {
        dr = getDocRef(ref, transfer, cache, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to parse POM for: {}. Reason: {}", e, ref, e.getMessage());
    }
    final MavenPomView view = new MavenPomView(ref, Collections.singletonList(dr), xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
    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) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 8 with GalleyMavenException

use of org.commonjava.maven.galley.maven.GalleyMavenException 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 9 with GalleyMavenException

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

Example 10 with GalleyMavenException

use of org.commonjava.maven.galley.maven.GalleyMavenException in project galley by Commonjava.

the class MavenPomReader method read.

public MavenPomView read(final ProjectVersionRef ref, final Transfer pom, final List<? extends Location> locations, final EventMetadata eventMetadata, final String... activeProfileLocations) throws GalleyMavenException {
    final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
    DocRef<ProjectVersionRef> dr;
    try {
        dr = getDocRef(ref, pom, false, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, ref, stack.size(), ref, e.getMessage());
    }
    stack.add(dr);
    ProjectVersionRef next = xml.getParentRef(dr.getDoc());
    while (next != null && dr != null) {
        try {
            dr = getDocRef(next, locations, false, 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());
    }
    final MavenPomView view = new MavenPomView(ref, stack, xpath, pluginDefaults, pluginImplications, xml, activeProfileLocations);
    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)

Aggregations

GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)17 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)10 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)9 ArrayList (java.util.ArrayList)8 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)7 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)6 Location (org.commonjava.maven.galley.model.Location)6 MavenMetadataView (org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView)5 TreeMap (java.util.TreeMap)4 SingleVersion (org.commonjava.maven.atlas.ident.version.SingleVersion)4 TransferException (org.commonjava.maven.galley.TransferException)4 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)4 DocRef (org.commonjava.maven.galley.maven.model.view.DocRef)4 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)4 URI (java.net.URI)3 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)3 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)3 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)2 ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)2 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)2