use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.
the class MavenPropertyCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile psiFile = parameters.getOriginalFile();
Project project = psiFile.getProject();
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
if (!manager.isMavenizedProject())
return;
MavenProject projectFile = MavenDomUtil.findContainingProject(psiFile);
if (projectFile == null)
return;
if (!MavenDomUtil.isMavenFile(psiFile) && !MavenDomUtil.isFilteredResourceFile(psiFile))
return;
String text = psiFile.getText();
int offset = parameters.getOffset();
int braceOffset = findOpenBrace(text, offset);
if (braceOffset == -1)
return;
TextRange range = TextRange.create(braceOffset, offset);
String prefix = range.substring(text);
MavenFilteredPropertyPsiReference ref = new MavenFilteredPropertyPsiReference(projectFile, psiFile, prefix, range);
addVariants(Arrays.asList(ref.getVariants()), result.withPrefixMatcher(prefix));
}
use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method collectVariants.
protected void collectVariants(final List<Object> result, Set<String> variants) {
int prefixLength = 0;
if (myText.startsWith("pom.")) {
prefixLength = "pom.".length();
} else if (myText.startsWith("project.")) {
prefixLength = "project.".length();
}
MavenProject mavenProject = myMavenProject;
while (myText.startsWith("parent.", prefixLength)) {
MavenId parentId = mavenProject.getParentId();
if (parentId == null)
return;
mavenProject = myProjectsManager.findProject(parentId);
if (mavenProject == null)
return;
prefixLength += "parent.".length();
}
final String prefix = prefixLength == 0 ? null : myText.substring(0, prefixLength);
PsiDirectory baseDir = getBaseDir(mavenProject);
addVariant(result, "basedir", baseDir, prefix, MavenIcons.MavenLogo);
if (prefix == null) {
result.add(createLookupElement(baseDir, "project.baseUri", MavenIcons.MavenLogo));
result.add(createLookupElement(baseDir, "pom.baseUri", MavenIcons.MavenLogo));
result.add(LookupElementBuilder.create(TIMESTAMP_PROP).withIcon(MavenIcons.MavenLogo));
}
processSchema(MavenSchemaProvider.MAVEN_PROJECT_SCHEMA_URL, new SchemaProcessor<Object>() {
@Override
public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
if (property.startsWith("project.")) {
addVariant(result, property.substring("project.".length()), descriptor, prefix, MavenIcons.MavenLogo);
}
return null;
}
});
processSchema(MavenSchemaProvider.MAVEN_SETTINGS_SCHEMA_URL, new SchemaProcessor<Object>() {
@Override
public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
result.add(createLookupElement(descriptor, property, MavenIcons.MavenLogo));
return null;
}
});
collectPropertiesVariants(result, variants);
collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.SYSTEM_PROPERTIES_FILE, null, result, variants);
collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.ENV_PROPERTIES_FILE, "env.", result, variants);
MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
for (String prop : runnerSettings.getMavenProperties().keySet()) {
if (variants.add(prefix)) {
result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
for (String prop : MavenUtil.getPropertiesFromMavenOpts().keySet()) {
if (variants.add(prop)) {
result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
for (Object key : myMavenProject.getProperties().keySet()) {
if (key instanceof String) {
String property = (String) key;
if (variants.add(property)) {
result.add(LookupElementBuilder.create(property).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
}
MavenDomConfiguration pluginCfg = DomUtil.findDomElement(myElement, MavenDomConfiguration.class);
if (pluginCfg != null) {
MavenPluginDescriptor.processDescriptors(descriptor -> {
if (descriptor.properties != null) {
for (MavenPluginDescriptor.ModelProperty property : descriptor.properties) {
if (property.insideConfigurationOnly) {
result.add(LookupElementBuilder.create(property.name).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
}
return true;
}, pluginCfg);
}
}
use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.
the class MavenExternalParameters method dumpModulesPaths.
private static File dumpModulesPaths(@NotNull Project project) throws IOException {
ApplicationManager.getApplication().assertReadAccessAllowed();
Properties res = new Properties();
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (manager.isMavenizedModule(module)) {
MavenProject mavenProject = manager.findProject(module);
if (mavenProject != null && !manager.isIgnored(mavenProject)) {
res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":pom" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getFile().getPath());
res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ':' + mavenProject.getPackaging() + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getOutputDirectory());
res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":test-jar" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getTestOutputDirectory());
addArtifactFileMapping(res, mavenProject, "sources");
addArtifactFileMapping(res, mavenProject, "test-sources");
addArtifactFileMapping(res, mavenProject, "javadoc");
addArtifactFileMapping(res, mavenProject, "test-javadoc");
}
}
}
File file = new File(PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties");
FileUtil.ensureExists(file.getParentFile());
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
try {
res.store(out, null);
} finally {
out.close();
}
return file;
}
use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.
the class MavenProjectConstantListConverter method getValues.
protected Collection<String> getValues(@NotNull ConvertContext context) {
DomElement element = context.getInvocationElement();
MavenProject project = MavenDomUtil.findContainingProject(element);
if (project == null)
return Collections.emptyList();
return getValues(context, project);
}
use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.
the class SelectMavenProjectDialog method createCenterPanel.
protected JComponent createCenterPanel() {
ComboBoxUtil.setModel(myMavenProjectsComboBox, new DefaultComboBoxModel(), myMavenDomProjectModels, 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);
});
myReplaceAllListener = new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updateControls();
}
};
myMavenProjectsComboBox.addItemListener(myReplaceAllListener);
myMavenProjectsComboBox.setSelectedItem(0);
myReplaceAllCheckBox.setVisible(myHasUsagesInProjects);
myExtractExclusions.setVisible(myHasExclusions);
updateControls();
return myMainPanel;
}
Aggregations