mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Maven: synchorous interpolation to avoid reflective-access problems
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.embedder;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.StringSearchModelInterpolator;
|
||||
import org.apache.maven.project.path.DefaultPathTranslator;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CustomModelInterpolator extends StringSearchModelInterpolator {
|
||||
public CustomModelInterpolator() {
|
||||
}
|
||||
|
||||
public CustomModelInterpolator(DefaultPathTranslator pathTranslator) {
|
||||
super(pathTranslator);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void interpolateObject(Object obj,
|
||||
Model model,
|
||||
File projectDir,
|
||||
ProjectBuilderConfiguration config,
|
||||
boolean debugEnabled) throws ModelInterpolationException {
|
||||
super.interpolateObject(obj, model, projectDir, config, debugEnabled);
|
||||
}
|
||||
}
|
||||
+37
@@ -41,7 +41,9 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.extension.ExtensionManager;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
||||
import org.apache.maven.monitor.event.DefaultEventMonitor;
|
||||
@@ -52,6 +54,12 @@ import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.*;
|
||||
import org.apache.maven.project.artifact.ProjectArtifactFactory;
|
||||
import org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||
import org.apache.maven.project.interpolation.StringSearchModelInterpolator;
|
||||
import org.apache.maven.project.path.DefaultPathTranslator;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.apache.maven.settings.Proxy;
|
||||
import org.apache.maven.settings.Server;
|
||||
@@ -61,6 +69,7 @@ import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.component.repository.ComponentDescriptor;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.maven.project.*;
|
||||
@@ -531,6 +540,33 @@ public class MavenEmbedderWrapper {
|
||||
});
|
||||
}
|
||||
|
||||
public static Model interpolate(Model model, File basedir) {
|
||||
try {
|
||||
AbstractStringBasedModelInterpolator interpolator = new CustomModelInterpolator(new DefaultPathTranslator());
|
||||
interpolator.initialize();
|
||||
|
||||
Properties context = MavenEmbedderFactory.collectSystemProperties();
|
||||
|
||||
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setExecutionProperties(context);
|
||||
model = interpolator.interpolate(ModelUtils.cloneModel(model), basedir, config, false);
|
||||
}
|
||||
catch (ModelInterpolationException e) {
|
||||
MavenLog.LOG.warn(e);
|
||||
}
|
||||
catch (InitializationException e) {
|
||||
MavenLog.LOG.error(e);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static void alignModel(Model model, File basedir) {
|
||||
PathTranslator pathTranslator = new DefaultPathTranslator();
|
||||
pathTranslator.alignToBaseDirectory(model, basedir);
|
||||
Build build = model.getBuild();
|
||||
build.setScriptSourceDirectory(pathTranslator.alignToBaseDirectory(build.getScriptSourceDirectory(), basedir));
|
||||
}
|
||||
|
||||
private void withProjectCachesDo(Function<Map, ?> func) {
|
||||
MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
|
||||
Field field;
|
||||
@@ -556,6 +592,7 @@ public class MavenEmbedderWrapper {
|
||||
setImplementation(ProjectArtifactFactory.class, CustomArtifactFactory.class);
|
||||
setImplementation(ArtifactResolver.class, CustomArtifactResolver.class);
|
||||
setImplementation(WagonManager.class, CustomWagonManager.class);
|
||||
setImplementation(ModelInterpolator.class, CustomModelInterpolator.class);
|
||||
}
|
||||
|
||||
private <T> void setImplementation(Class<T> componentClass,
|
||||
|
||||
+2
-21
@@ -499,30 +499,11 @@ public class MavenProjectReader {
|
||||
}
|
||||
|
||||
private Model expandProperties(Model model, File basedir) {
|
||||
try {
|
||||
AbstractStringBasedModelInterpolator interpolator = new StringSearchModelInterpolator(new DefaultPathTranslator());
|
||||
interpolator.initialize();
|
||||
|
||||
Properties context = MavenEmbedderFactory.collectSystemProperties();
|
||||
|
||||
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setExecutionProperties(context);
|
||||
model = interpolator.interpolate(ModelUtils.cloneModel(model), basedir, config, false);
|
||||
}
|
||||
catch (ModelInterpolationException e) {
|
||||
MavenLog.LOG.warn(e);
|
||||
}
|
||||
catch (InitializationException e) {
|
||||
MavenLog.LOG.error(e);
|
||||
}
|
||||
|
||||
return model;
|
||||
return MavenEmbedderWrapper.interpolate(model, basedir);
|
||||
}
|
||||
|
||||
private void alignModel(Model model, File basedir) {
|
||||
PathTranslator pathTranslator = new DefaultPathTranslator();
|
||||
pathTranslator.alignToBaseDirectory(model, basedir);
|
||||
Build build = model.getBuild();
|
||||
build.setScriptSourceDirectory(pathTranslator.alignToBaseDirectory(build.getScriptSourceDirectory(), basedir));
|
||||
MavenEmbedderWrapper.alignModel(model, basedir);
|
||||
}
|
||||
|
||||
private MavenProjectProblem createStructureProblem(VirtualFile file, String description) {
|
||||
|
||||
Reference in New Issue
Block a user