use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenJUnitPatcher method patchJavaParameters.
private static void patchJavaParameters(@NotNull Module module, @NotNull JavaParameters javaParameters, @NotNull MavenProject mavenProject, @NotNull String plugin, @NotNull Element config) {
MavenDomProjectModel domModel = MavenDomUtil.getMavenDomProjectModel(module.getProject(), mavenProject.getFile());
MavenTestRunningSettings testRunningSettings = MavenProjectSettings.getInstance(module.getProject()).getTestRunningSettings();
List<String> paths = MavenJDOMUtil.findChildrenValuesByPath(config, "additionalClasspathElements", "additionalClasspathElement");
if (paths.size() > 0) {
for (String path : paths) {
javaParameters.getClassPath().add(resolvePluginProperties(plugin, path, domModel));
}
}
if (testRunningSettings.isPassSystemProperties() && isEnabled(plugin, "systemPropertyVariables")) {
Element systemPropertyVariables = config.getChild("systemPropertyVariables");
if (systemPropertyVariables != null) {
for (Element element : systemPropertyVariables.getChildren()) {
String propertyName = element.getName();
if (!javaParameters.getVMParametersList().hasProperty(propertyName)) {
String value = resolvePluginProperties(plugin, element.getValue(), domModel);
value = resolveVmProperties(javaParameters.getVMParametersList(), value);
if (isResolved(plugin, value)) {
javaParameters.getVMParametersList().addProperty(propertyName, value);
}
}
}
}
}
if (testRunningSettings.isPassEnvironmentVariables() && isEnabled(plugin, "environmentVariables")) {
Element environmentVariables = config.getChild("environmentVariables");
if (environmentVariables != null) {
for (Element element : environmentVariables.getChildren()) {
String variableName = element.getName();
if (!javaParameters.getEnv().containsKey(variableName)) {
String value = resolvePluginProperties(plugin, element.getValue(), domModel);
value = resolveVmProperties(javaParameters.getVMParametersList(), value);
if (isResolved(plugin, value)) {
javaParameters.addEnv(variableName, value);
}
}
}
}
}
if (testRunningSettings.isPassArgLine() && isEnabled(plugin, "argLine")) {
Element argLine = config.getChild("argLine");
if (argLine != null) {
String value = resolvePluginProperties(plugin, argLine.getTextTrim(), domModel);
value = resolveVmProperties(javaParameters.getVMParametersList(), value);
if (StringUtil.isNotEmpty(value) && isResolved(plugin, value)) {
javaParameters.getVMParametersList().addParametersString(value);
}
}
}
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenNavigationUtil method createNavigatableForDependency.
@Nullable
public static Navigatable createNavigatableForDependency(final Project project, final VirtualFile file, final MavenArtifact artifact) {
return new NavigatableAdapter() {
public void navigate(boolean requestFocus) {
if (!file.isValid())
return;
MavenDomProjectModel projectModel = MavenDomUtil.getMavenDomProjectModel(project, file);
if (projectModel == null)
return;
MavenDomDependency dependency = findDependency(projectModel, artifact.getGroupId(), artifact.getArtifactId());
if (dependency == null)
return;
XmlTag artifactId = dependency.getArtifactId().getXmlTag();
if (artifactId == null)
return;
navigate(project, artifactId.getContainingFile().getVirtualFile(), artifactId.getTextOffset() + artifactId.getName().length() + 2, requestFocus);
}
};
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenModulePsiReference method getVariants.
@NotNull
public Object[] getVariants() {
List<DomFileElement<MavenDomProjectModel>> files = MavenDomUtil.collectProjectModels(getProject());
List<Object> result = new ArrayList<>();
for (DomFileElement<MavenDomProjectModel> eachDomFile : files) {
VirtualFile eachVFile = eachDomFile.getOriginalFile().getVirtualFile();
if (Comparing.equal(eachVFile, myVirtualFile))
continue;
PsiFile psiFile = eachDomFile.getFile();
String modulePath = calcRelativeModulePath(myVirtualFile, eachVFile);
result.add(LookupElementBuilder.create(psiFile, modulePath).withPresentableText(modulePath));
}
return result.toArray();
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenPathReferenceConverter method createReferences.
public static PsiReference[] createReferences(final DomElement genericDomValue, PsiElement element, @NotNull final Condition<PsiFileSystemItem> fileFilter, boolean isAbsolutePath) {
ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
TextRange range = manipulator.getRangeInElement(element);
String text = range.substring(element.getText());
FileReferenceSet set = new FileReferenceSet(text, element, range.getStartOffset(), null, SystemInfo.isFileSystemCaseSensitive, false) {
private MavenDomProjectModel model;
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return fileFilter;
}
@Override
protected boolean isSoft() {
return true;
}
@Override
public FileReference createFileReference(TextRange range, int index, String text) {
return new FileReference(this, range, index, text) {
@Override
protected void innerResolveInContext(@NotNull String text, @NotNull PsiFileSystemItem context, Collection<ResolveResult> result, boolean caseSensitive) {
if (model == null) {
DomElement rootElement = DomUtil.getFileElement(genericDomValue).getRootElement();
if (rootElement instanceof MavenDomProjectModel) {
model = (MavenDomProjectModel) rootElement;
}
}
String resolvedText = model == null ? text : MavenPropertyResolver.resolve(text, model);
if (resolvedText.equals(text)) {
if (getIndex() == 0 && resolvedText.length() == 2 && resolvedText.charAt(1) == ':') {
// it's root on windows, e.g. "C:"
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(resolvedText + '/');
if (file != null) {
PsiDirectory psiDirectory = context.getManager().findDirectory(file);
if (psiDirectory != null) {
result.add(new PsiElementResolveResult(psiDirectory));
}
}
} else {
super.innerResolveInContext(resolvedText, context, result, caseSensitive);
}
} else {
VirtualFile contextFile = context.getVirtualFile();
if (contextFile == null)
return;
VirtualFile file = null;
if (getIndex() == 0) {
file = LocalFileSystem.getInstance().findFileByPath(resolvedText);
}
if (file == null) {
file = LocalFileSystem.getInstance().findFileByPath(contextFile.getPath() + '/' + resolvedText);
}
if (file != null) {
PsiFileSystemItem res = file.isDirectory() ? context.getManager().findDirectory(file) : context.getManager().findFile(file);
if (res != null) {
result.add(new PsiElementResolveResult(res));
}
}
}
}
};
}
};
if (isAbsolutePath) {
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, file -> {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return FileReferenceSet.ABSOLUTE_TOP_LEVEL.fun(file);
}
virtualFile = VfsUtil.getRootFile(virtualFile);
PsiDirectory root = file.getManager().findDirectory(virtualFile);
if (root == null) {
return FileReferenceSet.ABSOLUTE_TOP_LEVEL.fun(file);
}
return Collections.<PsiFileSystemItem>singletonList(root);
});
}
return set.getAllReferences();
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method resolveModelProperty.
@Nullable
private PsiElement resolveModelProperty(@NotNull MavenDomProjectModel projectDom, @NotNull final String path, @NotNull final Set<DomElement> recursionGuard) {
if (!recursionGuard.add(projectDom))
return null;
String pathWithProjectPrefix = "project." + path;
if (!MavenModelClassesProperties.isPathValid(MavenModelClassesProperties.MAVEN_PROJECT_CLASS, path) && !MavenModelClassesProperties.isPathValid(MavenModelClassesProperties.MAVEN_MODEL_CLASS, path)) {
if (!schemaHasProperty(MavenSchemaProvider.MAVEN_PROJECT_SCHEMA_URL, pathWithProjectPrefix))
return null;
}
PsiElement result = MavenDomUtil.findTag(projectDom, pathWithProjectPrefix);
if (result != null)
return result;
if (pathWithProjectPrefix.equals("project.groupId") || pathWithProjectPrefix.equals("project.version")) {
return MavenDomUtil.findTag(projectDom, "project.parent." + path);
}
result = new MavenDomProjectProcessorUtils.DomParentProjectFileProcessor<PsiElement>(myProjectsManager) {
protected PsiElement doProcessParent(VirtualFile parentFile) {
MavenDomProjectModel parentProjectDom = MavenDomUtil.getMavenDomProjectModel(myProject, parentFile);
if (parentProjectDom == null)
return null;
return resolveModelProperty(parentProjectDom, path, recursionGuard);
}
}.process(projectDom);
if (result != null)
return result;
return myElement;
}
Aggregations