use of org.apache.maven.model.building.FileModelSource in project bazel by bazelbuild.
the class Resolver method resolvePomDependencies.
/**
* Given a local path to a Maven project, this attempts to find the transitive dependencies of
* the project.
* @param projectPath The path to search for Maven projects.
*/
public String resolvePomDependencies(String projectPath) {
DefaultModelProcessor processor = new DefaultModelProcessor();
processor.setModelLocator(new DefaultModelLocator());
processor.setModelReader(new DefaultModelReader());
File pom = processor.locatePom(new File(projectPath));
FileModelSource pomSource = new FileModelSource(pom);
// First resolve the model source locations.
resolveSourceLocations(pomSource);
// Next, fully resolve the models.
resolveEffectiveModel(pomSource, Sets.<String>newHashSet(), null);
return pom.getAbsolutePath();
}
use of org.apache.maven.model.building.FileModelSource in project intellij-community by JetBrains.
the class Maven3ServerEmbedderImpl method readModel.
@Override
@Nullable
public MavenModel readModel(File file) throws RemoteException {
Map<String, Object> inputOptions = new HashMap<String, Object>();
inputOptions.put(ModelProcessor.SOURCE, new FileModelSource(file));
ModelReader reader = null;
if (!StringUtil.endsWithIgnoreCase(file.getName(), "xml")) {
try {
Object polyglotManager = myContainer.lookup("org.sonatype.maven.polyglot.PolyglotModelManager");
if (polyglotManager != null) {
Method getReaderFor = ReflectionUtil.getMethod(polyglotManager.getClass(), "getReaderFor", Map.class);
if (getReaderFor != null) {
reader = (ModelReader) getReaderFor.invoke(polyglotManager, inputOptions);
}
}
} catch (ComponentLookupException ignore) {
} catch (Throwable e) {
Maven3ServerGlobals.getLogger().warn(e);
}
}
if (reader == null) {
try {
reader = myContainer.lookup(ModelReader.class);
} catch (ComponentLookupException ignore) {
}
}
if (reader != null) {
try {
Model model = reader.read(file, inputOptions);
return MavenModelConverter.convertModel(model, null);
} catch (Exception e) {
Maven3ServerGlobals.getLogger().warn(e);
}
}
return null;
}
use of org.apache.maven.model.building.FileModelSource in project bazel by bazelbuild.
the class Resolver method resolveSourceLocations.
/**
* Find the POM files for a given pom's parent(s) and submodules.
*/
private void resolveSourceLocations(FileModelSource fileModelSource) {
Model model = modelResolver.getRawModel(fileModelSource, handler);
if (model == null) {
return;
}
// Self.
Parent parent = model.getParent();
if (model.getGroupId() == null) {
model.setGroupId(parent.getGroupId());
}
if (!modelResolver.putModelSource(model.getGroupId(), model.getArtifactId(), fileModelSource)) {
return;
}
// Parent.
File pomDirectory = new File(fileModelSource.getLocation()).getParentFile();
if (parent != null && !parent.getArtifactId().equals(model.getArtifactId())) {
File parentPom;
try {
parentPom = new File(pomDirectory, parent.getRelativePath()).getCanonicalFile();
} catch (IOException e) {
handler.handle(Event.error("Unable to get canonical path of " + pomDirectory + " and " + parent.getRelativePath()));
return;
}
if (parentPom.exists()) {
resolveSourceLocations(new FileModelSource(parentPom));
}
}
// Submodules.
for (String module : model.getModules()) {
resolveSourceLocations(new FileModelSource(new File(pomDirectory, module + "/pom.xml")));
}
}
Aggregations