org.jetbrains.idea.maven.project.MavenProject Java Examples

The following examples show how to use org.jetbrains.idea.maven.project.MavenProject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
private List<MavenArtifact> ensureDownloaded(Module module, MavenProject mavenProject, Set<MavenId> deploymentIds, String classifier) {
    List<MavenArtifact> result = new ArrayList<>();
    long start = System.currentTimeMillis();
    try {
        MavenEmbedderWrapper serverWrapper = MavenServerManager.getInstance().createEmbedder(module.getProject(), false, mavenProject.getDirectory(), mavenProject.getDirectory());
        if (classifier != null) {
            for(MavenId id : deploymentIds) {
                result.add(serverWrapper.resolve(new MavenArtifactInfo(id, "jar", classifier), mavenProject.getRemoteRepositories()));
            }
        } else {
            List<MavenArtifactInfo> infos = deploymentIds.stream().map(id -> new MavenArtifactInfo(id, "jar", classifier)).collect(Collectors.toList());
            result = serverWrapper.resolveTransitively(infos, mavenProject.getRemoteRepositories());
        }
    } catch (MavenProcessCanceledException e) {
        LOGGER.warn(e.getLocalizedMessage(), e);
    }
    return result;
}
 
Example #2
Source File: RunTestFileAction.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
	MavenProject mavenProject = MavenActionUtil.getMavenProject(e.getDataContext());
	if (mavenProject != null) {

		PsiFile psiFile = LangDataKeys.PSI_FILE.getData(e.getDataContext());
		if (psiFile instanceof PsiClassOwner) {
			List<String> goals = getGoals(e, (PsiClassOwner) psiFile,
					MavenActionUtil.getMavenProject(e.getDataContext()));

			final DataContext context = e.getDataContext();
			MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), null, goals,
					MavenActionUtil.getProjectsManager(context).getExplicitProfiles());
			run(context, params);
		} else {
			Messages.showWarningDialog(e.getProject(), "Cannot run for current file", "Maven Test File");
		}
	}
}
 
Example #3
Source File: RunTestFileAction.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
protected List<String> getGoals(AnActionEvent e, PsiClassOwner psiFile, MavenProject mavenProject) {
	List<String> goals = new ArrayList<String>();
	boolean skipTests = isSkipTests(mavenProject);
	// so many possibilities...
	if (skipTests || isExcludedFromSurefire(psiFile, mavenProject)) {
		MavenPlugin failsafePlugin = mavenProject.findPlugin("org.apache.maven.plugins", "maven-failsafe-plugin");
		if (failsafePlugin != null) {
               addFailSafeParameters(e, psiFile, goals, failsafePlugin);
           } else {
               addSurefireParameters(e, psiFile, goals);
           }
		goals.add("verify");
	} else {
		addSurefireParameters(e, psiFile, goals);
		goals.add("test-compile");
		goals.add("surefire:test");
	}

	return goals;
}
 
Example #4
Source File: MavenImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
private void doImportProjects(final List<VirtualFile> files, boolean failOnReadingError, String... profiles) {
  initProjectsManager(false);

  readProjects(files, profiles);

  UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
    myProjectsManager.waitForResolvingCompletion();
    myProjectsManager.scheduleImportInTests(files);
    myProjectsManager.importProjects();
  });

  if (failOnReadingError) {
    for (MavenProject each : myProjectsTree.getProjects()) {
      assertFalse("Failed to import Maven project: " + each.getProblems(), each.hasReadingProblems());
    }
  }
}
 
Example #5
Source File: MavenMonitor.java    From spring-javaformat with Apache License 2.0 6 votes vote down vote up
private void attachListener(MavenProjectsManager mavenProjectsManager) {
	mavenProjectsManager.addProjectsTreeListener(new Listener() {

		@Override
		public void projectsUpdated(List<Pair<MavenProject, MavenProjectChanges>> updated,
				List<MavenProject> deleted) {
			check();
		}

		@Override
		public void projectResolved(Pair<MavenProject, MavenProjectChanges> projectWithChanges,
				NativeMavenProjectHolder nativeMavenProject) {
			check();
		}

		@Override
		public void pluginsResolved(MavenProject project) {
			check();
		}

	});
}
 
Example #6
Source File: MavenToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void getDeploymentFiles(Module module, MavenProject mavenProject, List<VirtualFile>[] result) {
    Set<MavenArtifact> downloaded = new HashSet<>();
    Set<MavenId> toDownload = new HashSet<>();
    for (MavenArtifact artifact : mavenProject.getDependencies()) {
        if (artifact.getFile() != null) {
            String deploymentIdStr = ToolDelegate.getDeploymentJarId(artifact.getFile());
            if (deploymentIdStr != null) {
                MavenId deploymentId = new MavenId(deploymentIdStr);
                if (mavenProject.findDependencies(deploymentId).isEmpty()) {
                    toDownload.add(deploymentId);
                }
            }
        }
    }
    List<MavenArtifact> binaryDependencies = ensureDownloaded(module, mavenProject, toDownload, null);
    toDownload.clear();
    for (MavenArtifact binaryDependency : binaryDependencies) {
        if (!"test".equals(binaryDependency.getScope())) {
            if (processDependency(mavenProject, result, downloaded, binaryDependency, BINARY)) {
                toDownload.add(binaryDependency.getMavenId());
            }
        }
    }
    List<MavenArtifact> sourcesDependencies = ensureDownloaded(module, mavenProject, toDownload, "sources");
    for (MavenArtifact sourceDependency : sourcesDependencies) {
        processDependency(mavenProject, result, downloaded, sourceDependency, SOURCES);
    }
}
 
Example #7
Source File: MyFileEditorProvider.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
private boolean isPomFile(@NotNull final Project project, @NotNull final VirtualFile file) {
	final String path = file.getPath();
	if (!path.endsWith("/" + MavenConstants.POM_XML))
		return false;
	MavenProjectsManager instance = MavenProjectsManager.getInstance(project);
	final MavenProject mavenProject = instance == null ? null : instance.findProject(file);
	if (mavenProject != null) {
		return mavenProject.getPath().equals(path);
	}
	return false;
}
 
Example #8
Source File: UIFormEditor.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
public UIFormEditor(final Project project, final VirtualFile file) {
	final MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(file);
	if (mavenProject == null) {
		throw new RuntimeException("Report this bug please. MavenProject not found for file " + file.getPath());
	}
	myEditor = new GuiForm(project, file, mavenProject);
}
 
Example #9
Source File: BaseAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
private static VirtualFile getVirtualFile(MavenArtifactNode myArtifactNode, Project project, MavenProject mavenProject) {
	final MavenArtifactNode parent = myArtifactNode.getParent();
	final VirtualFile file;
	if (parent == null) {
		file = mavenProject.getFile();
	} else {
		// final MavenId id = parent.getArtifact().getMavenId(); //this doesn't work for snapshots
		MavenArtifact artifact = parent.getArtifact();
		final MavenId id = new MavenId(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());

		final MavenProject pr = MavenProjectsManager.getInstance(project).findProject(id);
		file = pr == null ? MavenNavigationUtil.getArtifactFile(project, id) : pr.getFile();
	}
	return file;
}
 
Example #10
Source File: UnifiedModuleImpl.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public void init(MavenProject mavenProject, @NotNull Module module) {
    this.mavenProject = mavenProject;
    this.module = module;
    this.slingConfiguration = null;
    SlingModuleFacet slingModuleFacet = SlingModuleFacet.getFacetByModule(module);
    if(slingModuleFacet != null) {
        slingConfiguration = slingModuleFacet.getConfiguration();
    }
}
 
Example #11
Source File: RootMavenActionGroup.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
protected MavenProjectInfo getMavenProject(DataContext dataContext) {
	MavenProject mavenProject = MavenActionUtil.getMavenProject(dataContext);
	if (mavenProject == null) {
		return new MavenProjectInfo(null, false);
	}
	MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(dataContext);
	List<MavenProject> rootProjects = projectsManager.getRootProjects();

	MavenProject root = null;
	if (rootProjects.contains(mavenProject)) {
		root = mavenProject;
	} else {
		MavenId parentId = mavenProject.getParentId();
		while (parentId != null) {
			mavenProject = projectsManager.findProject(parentId);
			if (mavenProject == null) {
				break;
			}
			if (rootProjects.contains(mavenProject)) {
				root = mavenProject;
				break;
			}
			parentId = mavenProject.getParentId();
		}
	}

	return new MavenProjectInfo(root, true);
}
 
Example #12
Source File: MuleBeforeRunTasksProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private MavenProject getMavenProject(Module module) { //RunConfiguration runConfiguration, Project project)
        final MavenProjectsManager instance = MavenProjectsManager.getInstance(module.getProject());
        return instance.findProject(module);
//
//        if (runConfiguration instanceof MuleConfiguration)
//        {
//            MuleConfiguration muleConfiguration = (MuleConfiguration) runConfiguration;
//            return instance.findProject(muleConfiguration.getModule());
//        }
//        return null;
    }
 
Example #13
Source File: RunTestFileAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
private boolean isExcludedFromSurefire(PsiClassOwner psiFile, MavenProject mavenProject) {
	boolean excluded = false;
	try {
		Element pluginConfiguration = mavenProject.getPluginConfiguration("org.apache.maven.plugins",
				"maven-surefire-plugin");
		excluded = false;
		String fullName = null;
		if (pluginConfiguration != null) {
			Element excludes = pluginConfiguration.getChild("excludes");
			if (excludes != null) {
				List<Element> exclude = excludes.getChildren("exclude");
				for (Element element : exclude) {
					if (fullName == null) {
						fullName = getPsiFilePath(psiFile);
					}
					excluded = matchClassRegexPatter(fullName, element.getText());
					if (excluded) {
						break;
					}
				}
			}
		}
	} catch (Exception e) {
		LOG.warn(e);
	}
	return excluded;
}
 
Example #14
Source File: MavenImporter.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Override
public void process(IdeModifiableModelsProvider ideModifiableModelsProvider, Module module,
    MavenRootModelAdapter mavenRootModelAdapter, MavenProjectsTree mavenProjectsTree,
    MavenProject mavenProject, MavenProjectChanges mavenProjectChanges,
    Map<MavenProject, String> map, List<MavenProjectsProcessorTask> processorTasks) {
  String skip = this.findConfigValue(mavenProject, "skip");
  if (!"true".equals(skip)) {
    processorTasks.add(new MavenProcessorTask(module));
  } else {
    debug(() -> log.debug(
        "Skipping index check for project " + module.getProject().getName() + " & module "
            + module.getName()));
  }
}
 
Example #15
Source File: RunTestFileAction.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
private boolean isSkipTests(MavenProject mavenProject) {
	Element pluginConfiguration = mavenProject.getPluginConfiguration("org.apache.maven.plugins",
			"maven-surefire-plugin");
	boolean skipTests = false;
	if (pluginConfiguration != null) {
		Element skip;
		if ((skip = pluginConfiguration.getChild("skip")) != null) {
			skipTests = Boolean.parseBoolean(skip.getText());
		} else if ((skip = pluginConfiguration.getChild("skipTests")) != null) {
			skipTests = Boolean.parseBoolean(skip.getText());
		}
	}
	return skipTests;
}
 
Example #16
Source File: MavenImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected MavenArtifactDownloader.DownloadResult downloadArtifacts(Collection<MavenProject> projects,
                                                                   List<MavenArtifact> artifacts) {
  final MavenArtifactDownloader.DownloadResult[] unresolved = new MavenArtifactDownloader.DownloadResult[1];

  AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<>();
  result.doWhenDone((AsyncResult.Handler<MavenArtifactDownloader.DownloadResult>) downloadResult -> unresolved[0] = downloadResult);

  myProjectsManager.scheduleArtifactsDownloading(projects, artifacts, true, true, result);
  myProjectsManager.waitForArtifactsDownloadingCompletion();

  return unresolved[0];
}
 
Example #17
Source File: MavenImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected void readProjects(VirtualFile... files) {
  List<MavenProject> projects = new ArrayList<>();
  for (VirtualFile each : files) {
    projects.add(myProjectsManager.findProject(each));
  }
  myProjectsManager.forceUpdateProjects(projects);
  waitForReadingCompletion();
}
 
Example #18
Source File: MavenToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private boolean processDependency(MavenProject mavenProject, List<VirtualFile>[] result, Set<MavenArtifact> downloaded, MavenArtifact dependency, int type) {
    boolean added = false;

    if (mavenProject.findDependencies(dependency.getMavenId()).isEmpty() && !downloaded.contains(dependency)) {
        downloaded.add(dependency);
        VirtualFile jarRoot = getJarFile(dependency.getFile());
        if (jarRoot != null) {
            result[type].add(jarRoot);
            added = true;
        }
    }
    return added;
}
 
Example #19
Source File: MavenToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<VirtualFile>[] getDeploymentFiles(Module module) {
    MavenProject mavenProject = MavenProjectsManager.getInstance(module.getProject()).findProject(module);
    List<VirtualFile>[] result = ToolDelegate.initDeploymentFiles();
    if (mavenProject != null) {
        getDeploymentFiles(module, mavenProject, result);
    }
    return result;
}
 
Example #20
Source File: MavenMonitor.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private boolean hasSpringFormatPlugin(List<MavenProject> projects) {
	for (MavenProject project : projects) {
		if (project.findPlugin(PLUGIN_GROUP_ID, PLUGIN_ARTIFACT_ID) != null) {
			return true;
		}
	}
	return false;
}
 
Example #21
Source File: QuickRunMavenGoalAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
protected boolean isVisible(AnActionEvent e) {
	MavenProject mavenProject = MavenActionUtil.getMavenProject(e.getDataContext());
	return mavenProject != null;
}
 
Example #22
Source File: JumpToSourceAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
public JumpToSourceAction(Project project, MavenProject mavenProject, MavenArtifactNode myTreeNode) {
	super(project, mavenProject, myTreeNode, getLabel());
}
 
Example #23
Source File: CreateCustomGoalAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
protected boolean isVisible(AnActionEvent e) {
	MavenProject mavenProject = MavenActionUtil.getMavenProject(e.getDataContext());
	return mavenProject != null;
}
 
Example #24
Source File: BaseAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
public BaseAction(Project myProject, MavenProject myMavenProject, MavenArtifactNode myTreeNode, final String text) {
	super(text);
	this.myProject = myProject;
	this.myMavenProject = myMavenProject;
	myArtifact = myTreeNode;
}
 
Example #25
Source File: BaseAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
/**
 * org.jetbrains.idea.maven.navigator.MavenProjectsStructure.DependencyNode#getNavigatable()
 */
public static Navigatable getNavigatable(MavenArtifactNode myArtifactNode, Project project, MavenProject mavenProject) {
	final VirtualFile file = getVirtualFile(myArtifactNode, project, mavenProject);
	return file == null ? null : MavenNavigationUtil.createNavigatableForDependency(project, file, myArtifactNode.getArtifact());
}
 
Example #26
Source File: ExcludeDependencyAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
public ExcludeDependencyAction(Project project, MavenProject mavenProject, MavenArtifactNode myTreeNode) {
	super(project, mavenProject, myTreeNode, "Exclude");
}
 
Example #27
Source File: LeftTreePopupHandler.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
public LeftTreePopupHandler(Project project, MavenProject mavenProject, JTree tree) {
	this.project = project;
	this.mavenProject = mavenProject;
	this.tree = tree;
}
 
Example #28
Source File: GoalEditor.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
public GoalEditor(String title, String initialValue, ApplicationSettings applicationSettings, boolean persist, Project project, DataContext dataContext) {
		super(true);
		setTitle(title);
		saveGoalCheckBox.setSelected(PropertiesComponent.getInstance().getBoolean(SAVE, true));
		saveGoalCheckBox.setVisible(persist);

		try {
//		optionsPanel.add(new JBLabel("Append:"));
//		optionsPanel.setLayout(new WrapLayout());
			optionsPanel.add(getLinkLabel("-DskipTests", null));
			optionsPanel.add(getLinkLabel(new ListItem("--update-snapshots", "Forces a check for updated releases and snapshots on remote repositories")));
			optionsPanel.add(getLinkLabel(new ListItem("--offline", "Work offline")));
			optionsPanel.add(getLinkLabel(new ListItem("--debug", "Produce execution debug output")));
			optionsPanel.add(getLinkLabel(new ListItem("--non-recursive", "Do not recurse into sub-projects")));

//		optionsPanel2.setLayout(new WrapLayout());
			optionsPanel2.add(listPopup("Option...", getOptions(false), false));
			optionsPanel2.add(listPopup("Short Option...", getOptions(true), true));

			optionsPanel2.add(listPopup("Alias...", toListItems(applicationSettings.getAliases().getAliases()), false));

//		goalsPanel.add(new JBLabel("Goals:"));
//		goalsPanel.setLayout(new WrapLayout());

			goalsPanel.add(listPopup("Lifecycle Goal...", getGoals(), false));
			goalsPanel.add(listPopup("Existing Goal...", getExistingGoals(applicationSettings), false));
			goalsPanel.add(listPopup("Util...", getHelpfulGoals(), false));


			if (dataContext != null) {
				MavenProject mavenProject = MavenActionUtil.getMavenProject(dataContext);
				if (mavenProject != null) {
					List<ListItem> listItems = new ArrayList<>();
					for (MavenPlugin mavenPlugin : mavenProject.getDeclaredPlugins()) {
						MavenPluginInfo pluginInfo = MavenArtifactUtil.readPluginInfo(
							MavenProjectsManager.getInstance(project).getLocalRepository(), mavenPlugin.getMavenId());
						if (pluginInfo != null) {
							boolean first = true;
							for (MavenPluginInfo.Mojo mojo : pluginInfo.getMojos()) {
								ListItem listItem = new ListItem(mojo.getDisplayName());
								if (first) {
									listItem.separatorAbove = new ListItem(mavenPlugin.getArtifactId());
								}
								listItems.add(listItem);
								first = false;
							}
						}
					}
					goalsPanel.add(listPopup("Plugin Goal...", listItems.toArray(new ListItem[0]), false));
				}


			}

		} catch (Throwable e) {
			LOG.error(Objects.toString(e), e);
		}

//		aliasesPanel.add(new JBLabel("Aliases:"));

		init();

		myEditor.getDocument().addDocumentListener(new DocumentListener() {
			@Override
			public void documentChanged(@NotNull DocumentEvent event) {
				updateControls();
			}
		});
		append(initialValue);

		updateControls();
//		IdeFocusManager.findInstanceByComponent(mainPanel).requestFocus(myEditor.getComponent(), true);
	}
 
Example #29
Source File: DebugTestFileAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
@Override
protected List<String> getGoals(AnActionEvent e, PsiClassOwner psiFile, MavenProject mavenProject) {
	List<String> goals = super.getGoals(e, psiFile, mavenProject);
	goals.addAll(Debug.DEBUG_FORK_MODE);
	return goals;
}
 
Example #30
Source File: QuickRunRootMavenGoalAction.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
protected boolean isVisible(AnActionEvent e) {
	MavenProject mavenProject = MavenActionUtil.getMavenProject(e.getDataContext());
	return mavenProject != null;
}