use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class IntroducePropertyDialog method createCenterPanel.
protected JComponent createCenterPanel() {
myFieldNamePanel.setLayout(new BorderLayout());
myNameField = new NameSuggestionsField(myProject);
myNameChangedListener = new NameSuggestionsField.DataChanged() {
public void dataChanged() {
updateOkStatus();
}
};
myNameField.addDataChangedListener(myNameChangedListener);
myNameField.setSuggestions(getSuggestions());
myFieldNamePanel.add(myNameField, BorderLayout.CENTER);
List<MavenDomProjectModel> projects = getProjects();
ComboBoxUtil.setModel(myMavenProjectsComboBox, new DefaultComboBoxModel(), projects, model -> {
String projectName = model.getName().getStringValue();
MavenProject mavenProject = MavenDomUtil.findProject(model);
if (mavenProject != null) {
projectName = mavenProject.getDisplayName();
}
if (StringUtil.isEmptyOrSpaces(projectName)) {
projectName = "pom.xml";
}
return Pair.create(projectName, model);
});
myMavenProjectsComboBox.setSelectedItem(myMavenDomProjectModel);
return myMainPanel;
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenDependencyCompletionAndResolutionTest method testChooseFileIntentionForSystemDependency.
public void testChooseFileIntentionForSystemDependency() throws Throwable {
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency><caret>" + " <groupId>xxx</groupId>" + " <artifactId>xxx</artifactId>" + " <version>xxx</version>" + " <scope>system</system>" + " </dependency>" + "</dependencies>");
IntentionAction action = getIntentionAtCaret("Choose File");
assertNotNull(action);
String libPath = myIndicesFixture.getRepositoryHelper().getTestDataPath("local1/junit/junit/4.0/junit-4.0.jar");
final VirtualFile libFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(libPath);
((ChooseFileIntentionAction) ((IntentionActionWrapper) action).getDelegate()).setFileChooser(() -> new VirtualFile[] { libFile });
XmlCodeStyleSettings xmlSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getCustomSettings(XmlCodeStyleSettings.class);
int prevValue = xmlSettings.XML_TEXT_WRAP;
try {
// prevent file path from wrapping.
xmlSettings.XML_TEXT_WRAP = CommonCodeStyleSettings.DO_NOT_WRAP;
myFixture.launchAction(action);
} finally {
xmlSettings.XML_TEXT_WRAP = prevValue;
((ChooseFileIntentionAction) ((IntentionActionWrapper) action).getDelegate()).setFileChooser(null);
}
MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, myProjectPom);
MavenDomDependency dep = model.getDependencies().getDependencies().get(0);
assertEquals(findPsiFile(libFile), dep.getSystemPath().getValue());
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenResourceCompilerConfigurationGenerator method generateManifest.
private static void generateManifest(@NotNull MavenProject mavenProject, @NotNull Module module, @NotNull MavenModuleResourceConfiguration resourceConfig) {
if (mavenProject.isAggregator())
return;
if (Boolean.valueOf(IDEA_MAVEN_DISABLE_MANIFEST)) {
resourceConfig.manifest = null;
return;
}
try {
String jdkVersion = null;
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null && (jdkVersion = sdk.getVersionString()) != null) {
final int quoteIndex = jdkVersion.indexOf('"');
if (quoteIndex != -1) {
jdkVersion = jdkVersion.substring(quoteIndex + 1, jdkVersion.length() - 1);
}
}
Manifest manifest = new ManifestBuilder(mavenProject).withJdkVersion(jdkVersion).build();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
manifest.write(outputStream);
MavenDomProjectModel domModel = MavenDomUtil.getMavenDomProjectModel(module.getProject(), mavenProject.getFile());
if (domModel != null) {
final String resolvedText = MavenPropertyResolver.resolve(outputStream.toString(CharsetToolkit.UTF8), domModel);
resourceConfig.manifest = Base64.getEncoder().encodeToString(resolvedText.getBytes(StandardCharsets.UTF_8));
}
} finally {
StreamUtil.closeStream(outputStream);
}
resourceConfig.classpath = ManifestBuilder.getClasspath(mavenProject);
} catch (ManifestBuilder.ManifestBuilderException e) {
LOG.warn("Unable to generate artifact manifest", e);
} catch (Exception e) {
LOG.warn("Unable to save generated artifact manifest", e);
}
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class IntroducePropertyDialog method getSuggestions.
private String[] getSuggestions(int level) {
Collection<String> result = new THashSet<>();
String value = mySelectedString.trim();
boolean addUnqualifiedForm = true;
XmlTag parent = PsiTreeUtil.getParentOfType(myContext, XmlTag.class, false);
DomElement domParent = DomUtil.getDomElement(parent);
if (domParent != null) {
DomElement domSuperParent = domParent.getParent();
DomFileElement<DomElement> domFile = DomUtil.getFileElement(domParent);
if (domSuperParent != null && domFile != null && domFile.getRootElement() == domSuperParent) {
value = domSuperParent.getXmlElementName();
addUnqualifiedForm = false;
} else {
MavenDomShortArtifactCoordinates coordinates = DomUtil.getParentOfType(domParent, MavenDomShortArtifactCoordinates.class, false);
if (coordinates != null && !(coordinates instanceof MavenDomProjectModel) && domParent != coordinates.getArtifactId()) {
String artifactId = coordinates.getArtifactId().getStringValue();
if (!StringUtil.isEmptyOrSpaces(artifactId)) {
value = artifactId;
addUnqualifiedForm = false;
}
}
}
}
while (true) {
String newValue = value.replaceAll(" ", " ");
if (newValue.equals(value))
break;
value = newValue;
}
value = value.replaceAll(" ", ".");
List<String> parts = StringUtil.split(value, ".");
String shortValue = parts.get(parts.size() - 1);
if (addUnqualifiedForm) {
result.add(value);
result.add(shortValue);
}
String suffix = "";
while (parent != null && level != 0) {
suffix = parent.getName() + suffix;
result.add(suffix);
result.add(value + "." + suffix);
result.add(shortValue + "." + suffix);
suffix = "." + suffix;
parent = parent.getParentTag();
level--;
}
result = new ArrayList<>(result);
Collections.sort((List) result, CodeStyleSettingsManager.getSettings(myProject).PREFER_LONGER_NAMES ? StringLenComparator.getDescendingInstance() : StringLenComparator.getInstance());
return ArrayUtil.toStringArray(result);
}
use of org.jetbrains.idea.maven.dom.model.MavenDomProjectModel in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method doResolve.
// See org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator.createValueSources()
@Nullable
protected PsiElement doResolve() {
boolean hasPrefix = false;
String unprefixed = myText;
if (myText.startsWith("pom.")) {
unprefixed = myText.substring("pom.".length());
hasPrefix = true;
} else if (myText.startsWith("project.")) {
unprefixed = myText.substring("project.".length());
hasPrefix = true;
}
MavenProject mavenProject = myMavenProject;
while (unprefixed.startsWith("parent.")) {
if (unprefixed.equals("parent.groupId") || unprefixed.equals("parent.artifactId") || unprefixed.equals("parent.version") || unprefixed.equals("parent.relativePath")) {
break;
}
MavenId parentId = mavenProject.getParentId();
if (parentId == null)
return null;
mavenProject = myProjectsManager.findProject(parentId);
if (mavenProject == null)
return null;
unprefixed = unprefixed.substring("parent.".length());
}
if (unprefixed.equals("basedir") || (hasPrefix && mavenProject == myMavenProject && unprefixed.equals("baseUri"))) {
return getBaseDir(mavenProject);
}
if (myText.equals(TIMESTAMP_PROP)) {
return myElement;
}
if (hasPrefix) {
MavenDomProjectModel domProjectModel = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
if (domProjectModel != null) {
PsiElement res = resolveModelProperty(domProjectModel, unprefixed, new HashSet<>());
if (res != null) {
return res;
}
}
}
// todo resolve properties from config.
MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
if (runnerSettings.getMavenProperties().containsKey(myText) || runnerSettings.getVmOptions().contains("-D" + myText + '=')) {
return myElement;
}
if (MavenUtil.getPropertiesFromMavenOpts().containsKey(myText)) {
return myElement;
}
MavenDomProfile profile = DomUtil.findDomElement(myElement, MavenDomProfile.class);
if (profile != null) {
PsiElement result = MavenDomProjectProcessorUtils.findProperty(profile.getProperties(), myText);
if (result != null)
return result;
}
MavenDomConfiguration pluginCfg = DomUtil.findDomElement(myElement, MavenDomConfiguration.class);
if (pluginCfg != null) {
boolean notFound = MavenPluginDescriptor.processDescriptors(descriptor -> {
if (descriptor.properties != null) {
for (MavenPluginDescriptor.ModelProperty property : descriptor.properties) {
if (property.insideConfigurationOnly && property.name.equals(myText)) {
return false;
}
}
}
return true;
}, pluginCfg);
if (!notFound) {
return myElement;
}
}
if (myProjectDom != null) {
PsiElement result = MavenDomProjectProcessorUtils.searchProperty(myText, myProjectDom, myProject);
if (result != null)
return result;
}
if ("java.home".equals(myText)) {
PsiElement element = resolveToCustomSystemProperty("java.home", MavenUtil.getModuleJreHome(myProjectsManager, mavenProject));
if (element != null) {
return element;
}
}
if ("java.version".equals(myText)) {
PsiElement element = resolveToCustomSystemProperty("java.version", MavenUtil.getModuleJavaVersion(myProjectsManager, mavenProject));
if (element != null) {
return element;
}
}
MavenPropertiesVirtualFileSystem mavenPropertiesVirtualFileSystem = MavenPropertiesVirtualFileSystem.getInstance();
IProperty property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, myText);
if (property != null)
return property.getPsiElement();
if (myText.startsWith("env.")) {
property = mavenPropertiesVirtualFileSystem.findEnvProperty(myProject, myText.substring("env.".length()));
if (property != null)
return property.getPsiElement();
}
String textWithEnv = "env." + myText;
property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, textWithEnv);
if (property != null)
return property.getPsiElement();
property = mavenPropertiesVirtualFileSystem.findEnvProperty(myProject, textWithEnv);
if (property != null)
return property.getPsiElement();
if (!hasPrefix) {
MavenDomProjectModel domProjectModel = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
if (domProjectModel != null) {
PsiElement res = resolveModelProperty(domProjectModel, unprefixed, new HashSet<>());
if (res != null) {
return res;
}
}
}
if (mavenProject.getProperties().containsKey(myText)) {
return myElement;
}
if (myText.startsWith("settings.")) {
return resolveSettingsModelProperty();
}
return null;
}
Aggregations