Search in sources :

Example 1 with ModelReader

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;
}
Also used : ModelReader(org.apache.maven.model.io.ModelReader) THashMap(gnu.trove.THashMap) FileModelSource(org.apache.maven.model.building.FileModelSource) Model(org.apache.maven.model.Model) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) Method(java.lang.reflect.Method) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

THashMap (gnu.trove.THashMap)1 Method (java.lang.reflect.Method)1 RemoteException (java.rmi.RemoteException)1 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)1 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 Model (org.apache.maven.model.Model)1 FileModelSource (org.apache.maven.model.building.FileModelSource)1 ModelReader (org.apache.maven.model.io.ModelReader)1 ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 ContextException (org.codehaus.plexus.context.ContextException)1 InitializationException (org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)1 Nullable (org.jetbrains.annotations.Nullable)1