Author: fbricon
Date: 2011-08-01 06:13:14 -0400 (Mon, 01 Aug 2011)
New Revision: 33407
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java
Log:
JBIDE-8969 : force loading of MavenProject and load available profiles from parent
hierarchy
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java 2011-08-01
09:18:46 UTC (rev 33406)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java 2011-08-01
10:13:14 UTC (rev 33407)
@@ -1,5 +1,6 @@
package org.jboss.tools.maven.core.internal.profiles;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -10,17 +11,25 @@
import java.util.Map;
import java.util.Set;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
import org.apache.maven.model.Profile;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsUtils;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.MavenUpdateRequest;
import org.eclipse.m2e.core.project.ResolverConfiguration;
+import org.eclipse.osgi.util.NLS;
import org.jboss.tools.maven.core.profiles.IProfileManager;
import org.jboss.tools.maven.core.profiles.ProfileState;
import org.jboss.tools.maven.core.profiles.ProfileStatus;
@@ -36,17 +45,17 @@
return;
}
final IProjectConfigurationManager configurationManager =
MavenPlugin.getProjectConfigurationManager();
- final ResolverConfiguration configuration =configurationManager
- .getResolverConfiguration(mavenProjectFacade.getProject());
+ IProject project = mavenProjectFacade.getProject();
+
+ final ResolverConfiguration configuration
=configurationManager.getResolverConfiguration(project);
+
final String profilesAsString = getAsString(profiles);
if (profilesAsString.equals(configuration.getActiveProfiles())) {
//Nothing changed
return;
}
- IProject project = mavenProjectFacade.getProject();
-
configuration.setActiveProfiles(profilesAsString);
boolean isSet = configurationManager.setResolverConfiguration(project, configuration);
if (isSet) {
@@ -71,30 +80,6 @@
return sb.toString();
}
- public Map<Profile, Boolean> getAvailableProfiles(IMavenProjectFacade facade)
throws CoreException {
- if (facade == null) {
- return Collections.emptyMap();
- }
- List<Profile> modelProfiles = facade.getMavenProject().getModel().getProfiles();
- if (modelProfiles == null || modelProfiles.isEmpty()) {
- return Collections.emptyMap();
- }
-
- ResolverConfiguration resolverConfiguration =
MavenPlugin.getProjectConfigurationManager()
- .getResolverConfiguration(facade.getProject());
-
- Map<Profile, Boolean> projectProfiles = new LinkedHashMap<Profile,
Boolean>(modelProfiles.size());
- List<Profile> activeProfiles = facade.getMavenProject().getActiveProfiles();
-
- for (Profile p : modelProfiles) {
- boolean isAutomaticallyActivated = isActive(p, activeProfiles)
- && !resolverConfiguration.getActiveProfileList().contains(p.getId());
- projectProfiles.put(p, isAutomaticallyActivated);
- }
- return Collections.unmodifiableMap(projectProfiles);
- }
-
-
public Map<Profile, Boolean> getAvailableSettingProfiles() throws CoreException {
Map<Profile, Boolean> settingsProfiles = new LinkedHashMap<Profile,
Boolean>();
Settings settings = MavenPlugin.getMaven().getSettings();
@@ -127,7 +112,9 @@
}
public List<ProfileStatus> getProfilesStatuses(
- IMavenProjectFacade facade) throws CoreException {
+ IMavenProjectFacade facade,
+ IProgressMonitor monitor
+ ) throws CoreException {
if (facade == null) {
return Collections.emptyList();
}
@@ -137,10 +124,10 @@
List<String> configuredProfiles = resolverConfiguration.getActiveProfileList();
- final List<Profile> activeProfiles =
facade.getMavenProject().getActiveProfiles();
+ MavenProject mavenProject = facade.getMavenProject(monitor);
+
+ List<Profile> projectProfiles = getAvailableProfiles(mavenProject.getModel(), new
NullProgressMonitor());
- List<Profile> projectProfiles = new
ArrayList<Profile>(facade.getMavenProject().getModel().getProfiles());
-
final Map<Profile, Boolean> availableSettingsProfiles =
getAvailableSettingProfiles();
Set<Profile> settingsProfiles = new
HashSet<Profile>(availableSettingsProfiles.keySet());
@@ -158,7 +145,6 @@
status.setActivationState(state);
Profile p = get(id, projectProfiles);
-
if (p == null){
p = get(id, settingsProfiles);
if(p != null){
@@ -174,6 +160,7 @@
statuses.add(status);
}
+ final List<Profile> activeProfiles = mavenProject.getActiveProfiles();
//Iterate on the remaining project profiles
addStatuses(statuses, projectProfiles, new ActivationPredicate() {
@Override
@@ -192,6 +179,45 @@
return Collections.unmodifiableList(statuses);
}
+ protected List<Profile> getAvailableProfiles(Model projectModel, IProgressMonitor
monitor) throws CoreException {
+ if (projectModel == null) {
+ return null;
+ }
+ List<Profile> profiles = new
ArrayList<Profile>(projectModel.getProfiles());
+
+ Parent p = projectModel.getParent();
+ if (p != null) {
+ Model parentModel = resolvePomModel(p.getGroupId(), p.getArtifactId(), p.getVersion(),
monitor);
+ List<Profile> parentProfiles = getAvailableProfiles(parentModel, monitor);
+ if (parentProfiles != null && !parentProfiles.isEmpty()) {
+ profiles.addAll(parentProfiles);
+ }
+ }
+
+ return profiles;
+ }
+
+ private Model resolvePomModel(String groupId, String artifactId, String version,
IProgressMonitor monitor)
+ throws CoreException {
+ monitor.subTask(NLS.bind("Resolving {0}:{1}:{2}", new Object[] { groupId,
artifactId, version}));
+
+ IMavenProjectFacade facade =
MavenPlugin.getMavenProjectRegistry().getMavenProject(groupId, artifactId, version);
+ IMaven maven = MavenPlugin.getMaven();
+
+ if (facade != null) {
+ return facade.getMavenProject(monitor).getModel();
+ }
+
+ List<ArtifactRepository> repositories = maven.getArtifactRepositories();
+ Artifact artifact = maven.resolve(groupId, artifactId, version, "pom",
null, repositories, monitor); //$NON-NLS-1$
+ File file = artifact.getFile();
+ if(file == null) {
+ return null;
+ }
+
+ return maven.readModel(file);
+ }
+
private void addStatuses(List<ProfileStatus> statuses, Collection<Profile>
profiles, ActivationPredicate predicate) {
for (Profile p : profiles) {
ProfileStatus status = new ProfileStatus(p.getId());
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java 2011-08-01
09:18:46 UTC (rev 33406)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java 2011-08-01
10:13:14 UTC (rev 33407)
@@ -16,17 +16,8 @@
*/
public interface IProfileManager {
- /**
- * Returns an unmodifiable Map of all the available profiles for a given project.
- * The value of each Map.Entry indicates if the profile is active.
- * @param mavenProjectFacade a facade of the maven project
- * @return an unmodifiable Map of all the available profiles for a given project.
- * @throws CoreException
- */
- Map<Profile, Boolean> getAvailableProfiles(IMavenProjectFacade mavenProjectFacade)
throws CoreException;
+ List<ProfileStatus> getProfilesStatuses(IMavenProjectFacade mavenProjectFacade,
IProgressMonitor monitor) throws CoreException;
- List<ProfileStatus> getProfilesStatuses(IMavenProjectFacade mavenProjectFacade)
throws CoreException;
-
/**
* Returns an unmodifiable Map of all the available profiles defined in the
* Maven settings.xml file.<br/>
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java 2011-08-01
09:18:46 UTC (rev 33406)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java 2011-08-01
10:13:14 UTC (rev 33407)
@@ -62,19 +62,13 @@
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
- final Set<IMavenProjectFacade> allfacades = getSelectedMavenProjects(event);
+ final Set<IMavenProjectFacade> facades = getSelectedMavenProjects(event);
- if (allfacades.isEmpty()) {
+ if (facades.isEmpty()) {
display(window, Messages.ProfileSelectionHandler_Select_some_maven_projects);
return null;
}
- Set<IMavenProjectFacade> facades = getValidMavenProjects(allfacades);
- if (facades.isEmpty()) {
- display(window, Messages.ProfileSelectionHandler_Maven_Builder_still_processing);
- return null;
- }
-
System.out.print("Select projects "+facades); //$NON-NLS-1$
final IProfileManager profileManager =
MavenCoreActivator.getDefault().getProfileManager();
@@ -253,8 +247,9 @@
final IProfileManager profileManager) throws CoreException {
Map<IMavenProjectFacade, List<ProfileStatus>> allProfiles =
new HashMap<IMavenProjectFacade, List<ProfileStatus>>(facades.size());
+ IProgressMonitor monitor = new NullProgressMonitor();
for (IMavenProjectFacade facade : facades) {
- allProfiles.put(facade, profileManager.getProfilesStatuses(facade));
+ allProfiles.put(facade, profileManager.getProfilesStatuses(facade, monitor));
}
return allProfiles;
}
@@ -290,19 +285,6 @@
return facades;
}
-
- private Set<IMavenProjectFacade>
getValidMavenProjects(Set<IMavenProjectFacade> facades) {
- Set<IMavenProjectFacade> validFacades = new
HashSet<IMavenProjectFacade>(facades);
- Iterator<IMavenProjectFacade> ite = validFacades.iterator();
- while (ite.hasNext()) {
- IMavenProjectFacade facade = ite.next();
- if (facade.getMavenProject() == null) {
- System.err.println(facade.getProject() + " facade has no MavenProject!!!");
//$NON-NLS-1$
- ite.remove();
- }
- }
- return validFacades;
- }
private IProject[] getSelectedProjects(ISelection selection) {
Set<IProject> projects = new HashSet<IProject>();
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java 2011-08-01
09:18:46 UTC (rev 33406)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java 2011-08-01
10:13:14 UTC (rev 33407)
@@ -10,6 +10,7 @@
************************************************************************************/
package org.jboss.tools.maven.ui.internal.profiles;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -25,6 +26,7 @@
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
@@ -146,7 +148,8 @@
addSelectionButton(container, Messages.SelectProfilesDialog_SelectAll, true);
addSelectionButton(container, Messages.SelectProfilesDialog_DeselectAll, false);
-
+ addActivationButton(container, "Activate", true);
+ addActivationButton(container, "Deactivate", false);
offlineModeBtn = addCheckButton(container, Messages.SelectProfilesDialog_Offline,
offlineMode);
forceUpdateBtn = addCheckButton(container, Messages.SelectProfilesDialog_Force_update,
forceUpdate);
}
@@ -287,6 +290,41 @@
return button;
}
+ private Button addActivationButton(Composite container, String label, final boolean
ischecked) {
+ Button button = new Button(container, SWT.NONE);
+ button.setLayoutData(new GridData(SWT.FILL, SWT.UP,
+ false, false, 1, 1));
+ button.setText(label);
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ ISelection s = profileTableViewer.getSelection();
+ if (s instanceof IStructuredSelection) {
+ IStructuredSelection sel = (IStructuredSelection) s;
+ Iterator<?> ite = sel.iterator();
+ while (ite.hasNext()) {
+ System.err.println(ite.next());
+ }
+ }
+// for (ProfileSelection profile : sharedProfiles) {
+// profileTableViewer.setChecked(profile, ischecked);
+// profile.setSelected(ischecked);
+// if (!ischecked || profile.getActivationState() == null) {
+// profile.setActivationState(ProfileState.Active);
+// }
+// }
+ profileTableViewer.refresh();
+ updateProfilesAsText();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return button;
+ }
+
+
@Override
protected void createButtonsForButtonBar(Composite parent) {
if (profileTableViewer != null) {