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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations