Search in sources :

Example 1 with ModelInterpolationException

use of org.apache.maven.project.interpolation.ModelInterpolationException in project intellij-community by JetBrains.

the class MavenEmbedder method readProject.

@NotNull
private MavenExecutionResult readProject(@NotNull final MavenExecutionRequest request) {
    ProfileManager globalProfileManager = request.getGlobalProfileManager();
    globalProfileManager.loadSettingsProfiles(request.getSettings());
    MavenProject rootProject = null;
    final List<Exception> exceptions = new ArrayList<Exception>();
    Object result = null;
    try {
        final File pomFile = new File(request.getPomFile());
        if (!pomFile.exists()) {
            throw new FileNotFoundException("File doesn't exist: " + pomFile.getPath());
        }
        final Method getProjectsMethod = DefaultMaven.class.getDeclaredMethod("getProjects", MavenExecutionRequest.class);
        getProjectsMethod.setAccessible(true);
        Maven maven = getComponent(Maven.class);
        result = getProjectsMethod.invoke(maven, request);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        return handleException(e.getTargetException());
    } catch (Exception e) {
        return handleException(e);
    }
    if (result != null) {
        MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
        for (Object p : (List) result) {
            MavenProject project = (MavenProject) p;
            try {
                builder.calculateConcreteState(project, request.getProjectBuilderConfiguration(), false);
            } catch (ModelInterpolationException e) {
                exceptions.add(e);
            }
            if (project.isExecutionRoot()) {
                rootProject = project;
            }
        }
        if (rootProject == null && exceptions.isEmpty()) {
            throw new RuntimeException("Could't build project for unknown reason");
        }
    }
    return new MavenExecutionResult(rootProject, exceptions);
}
Also used : DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager) ProfileManager(org.apache.maven.profiles.ProfileManager) DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) FileNotFoundException(java.io.FileNotFoundException) Method(java.lang.reflect.Method) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MavenProjectBuilder(org.apache.maven.project.MavenProjectBuilder) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ModelInterpolationException

use of org.apache.maven.project.interpolation.ModelInterpolationException in project che by eclipse.

the class MavenServerImpl method internalInterpolate.

private static Model internalInterpolate(Model model, File projectDir) throws RemoteException {
    try {
        AbstractStringBasedModelInterpolator interpolator = new org.apache.maven.project.interpolation.StringSearchModelInterpolator(new DefaultPathTranslator());
        interpolator.initialize();
        //MavenServerUtil.collectSystemProperties();
        Properties props = new Properties();
        ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setExecutionProperties(props);
        config.setBuildStartTime(new Date());
        model = interpolator.interpolate(model, projectDir, config, false);
    } catch (ModelInterpolationException e) {
        MavenServerContext.getLogger().warning(e);
    } catch (InitializationException e) {
        MavenServerContext.getLogger().error(e);
    }
    return model;
}
Also used : ProjectBuilderConfiguration(org.apache.maven.project.ProjectBuilderConfiguration) DefaultProjectBuilderConfiguration(org.apache.maven.project.DefaultProjectBuilderConfiguration) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) AbstractStringBasedModelInterpolator(org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator) DefaultPathTranslator(org.apache.maven.project.path.DefaultPathTranslator) DefaultProjectBuilderConfiguration(org.apache.maven.project.DefaultProjectBuilderConfiguration) Properties(java.util.Properties) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) Date(java.util.Date)

Example 3 with ModelInterpolationException

use of org.apache.maven.project.interpolation.ModelInterpolationException in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method doInterpolate.

@NotNull
private static Model doInterpolate(@NotNull Model result, File basedir) throws RemoteException {
    try {
        AbstractStringBasedModelInterpolator interpolator = new CustomMaven3ModelInterpolator(new DefaultPathTranslator());
        interpolator.initialize();
        Properties props = MavenServerUtil.collectSystemProperties();
        ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setExecutionProperties(props);
        config.setBuildStartTime(new Date());
        result = interpolator.interpolate(result, basedir, config, false);
    } catch (ModelInterpolationException e) {
        Maven3ServerGlobals.getLogger().warn(e);
    } catch (InitializationException e) {
        Maven3ServerGlobals.getLogger().error(e);
    }
    return result;
}
Also used : ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) AbstractStringBasedModelInterpolator(org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator) DefaultPathTranslator(org.apache.maven.project.path.DefaultPathTranslator) SystemProperties(com.intellij.util.SystemProperties) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ModelInterpolationException

use of org.apache.maven.project.interpolation.ModelInterpolationException in project intellij-community by JetBrains.

the class Maven2ServerEmbedderImpl method doInterpolate.

private static Model doInterpolate(Model result, File basedir) throws RemoteException {
    try {
        AbstractStringBasedModelInterpolator interpolator = new CustomModelInterpolator(new DefaultPathTranslator());
        interpolator.initialize();
        Properties props = MavenServerUtil.collectSystemProperties();
        ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setExecutionProperties(props);
        result = interpolator.interpolate(result, basedir, config, false);
    } catch (ModelInterpolationException e) {
        Maven2ServerGlobals.getLogger().warn(e);
    } catch (InitializationException e) {
        Maven2ServerGlobals.getLogger().error(e);
    }
    return result;
}
Also used : ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) AbstractStringBasedModelInterpolator(org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator) DefaultPathTranslator(org.apache.maven.project.path.DefaultPathTranslator) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)

Example 5 with ModelInterpolationException

use of org.apache.maven.project.interpolation.ModelInterpolationException in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method doInterpolate.

private static Model doInterpolate(Model result, File basedir) throws RemoteException {
    try {
        AbstractStringBasedModelInterpolator interpolator = new CustomMaven3ModelInterpolator(new DefaultPathTranslator());
        interpolator.initialize();
        Properties props = MavenServerUtil.collectSystemProperties();
        ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setExecutionProperties(props);
        config.setBuildStartTime(new Date());
        result = interpolator.interpolate(result, basedir, config, false);
    } catch (ModelInterpolationException e) {
        Maven3ServerGlobals.getLogger().warn(e);
    } catch (InitializationException e) {
        Maven3ServerGlobals.getLogger().error(e);
    }
    return result;
}
Also used : ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) AbstractStringBasedModelInterpolator(org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator) DefaultPathTranslator(org.apache.maven.project.path.DefaultPathTranslator) SystemProperties(com.intellij.util.SystemProperties) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)

Aggregations

ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)5 AbstractStringBasedModelInterpolator (org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator)4 DefaultPathTranslator (org.apache.maven.project.path.DefaultPathTranslator)4 InitializationException (org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)4 SystemProperties (com.intellij.util.SystemProperties)2 NotNull (org.jetbrains.annotations.NotNull)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 Properties (java.util.Properties)1 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 DefaultProfileManager (org.apache.maven.profiles.DefaultProfileManager)1 ProfileManager (org.apache.maven.profiles.ProfileManager)1 DefaultProjectBuilderConfiguration (org.apache.maven.project.DefaultProjectBuilderConfiguration)1 MavenProject (org.apache.maven.project.MavenProject)1 MavenProjectBuilder (org.apache.maven.project.MavenProjectBuilder)1