use of org.apache.maven.model.io.ModelReader 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;
}
Aggregations