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