Author: snjeza
Date: 2012-05-25 12:07:10 -0400 (Fri, 25 May 2012)
New Revision: 41432
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/AddRepositoryDialog.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/RepositoryWrapper.java
Log:
JBIDE-11969 - configure maven repo adds jbosstools-maven-repository profile
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/AddRepositoryDialog.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/AddRepositoryDialog.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/AddRepositoryDialog.java 2012-05-25
16:07:10 UTC (rev 41432)
@@ -0,0 +1,699 @@
+package org.jboss.tools.maven.ui.wizard;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.maven.repository.RepositorySystem;
+import org.apache.maven.settings.Profile;
+import org.apache.maven.settings.Repository;
+import org.apache.maven.settings.Settings;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMaven;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.maven.ui.Activator;
+
+public class AddRepositoryDialog extends TitleAreaDialog {
+
+ private static final String URL_ALREADY_EXISTS = "URL already exists";
+ private static final String URL_IS_NOT_VALID = "URL isn't valid.";
+ private static final String REPOSITORY_NAME_IS_EMPTY = "The use of an empty
repository name is discouraged.";
+ private static final String REPOSITORY_URL_IS_REQUIRED = "Repository URL is
required.";
+ private static final String REPOSITORY_ID_IS_REQUIRED = "Repository ID is
required.";
+ private static final String PROFILE_ID_IS_REQUIRED = "Profile ID is
required.";
+ private static final String ADD_MAVEN_REPOSITORY_TITLE = "Add Maven
Repository";
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ private static final String CONFIGURE_MAVEN_REPOSITORIES =
"ConfigureMavenRepositories"; //$NON-NLS-1$
+ private static final String LASTPATH = "lastPath"; //$NON-NLS-1$
+ private static final String JSF_IMPL = "com" + File.separator +
"sun" + File.separator + "faces" + File.separator +
"jsf-impl"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ private static final String WFK_BOMS = "com" + File.separator +
"redhat" + File.separator + "jboss" + File.separator + "wfk"
+ File.separator + "boms"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$ //$NON-NLS-5$
+ private static final String JBOSS_EAP_MAVEN_REPOSITORY = "JBoss EAP Maven
Repository"; //$NON-NLS-1$
+ private static final String JBOSS_EAP_MAVEN_REPOSITORY_ID =
"jboss-eap-maven-repository";; //$NON-NLS-1$
+ private static final String JBOSS_WFK_MAVEN_REPOSITORY_ID =
"jboss-wfk-maven-repository";; //$NON-NLS-1$
+
+ private Set<RepositoryWrapper> availableRepositories;
+ private Set<RepositoryWrapper> includedRepositories;
+ private IMaven maven;
+ private Combo profileCombo;
+ private Button activeByDefaultButton;
+ private boolean activeByDefault;
+ private Text idText;
+ private Text urlText;
+ private Text nameText;
+ private Image jbossImage;
+ private IDialogSettings dialogSettings;
+ private String localRepository;
+ private ControlDecoration profileComboDecoration;
+ private ControlDecoration idTextDecoration;
+ private ControlDecoration nameTextDecoration;
+ private ControlDecoration urlTextDecoration;
+ private ControlDecoration urlValidTextDecoration;
+ private ControlDecoration urlExistsTextDecoration;
+
+ private RepositoryWrapper repositoryWrapper;
+
+ public AddRepositoryDialog(Shell parentShell,
+ Set<RepositoryWrapper> availableRepositories,
+ Set<RepositoryWrapper> includedRepositories, IMaven maven) {
+ super(parentShell);
+ setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER | SWT.RESIZE
+ | getDefaultOrientation());
+ this.availableRepositories = availableRepositories;
+ this.includedRepositories = includedRepositories;
+ this.maven = maven;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ getShell().setText(ADD_MAVEN_REPOSITORY_TITLE);
+ setTitle(ADD_MAVEN_REPOSITORY_TITLE);
+ setMessage("Enter a new repository");
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite contents = new Composite(area, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true);
+ gd.heightHint = 300;
+ gd.widthHint = 500;
+ contents.setLayoutData(gd);
+ contents.setLayout(new GridLayout(1, false));
+ applyDialogFont(contents);
+ initializeDialogUnits(area);
+
+ Group profileGroup = new Group(contents, SWT.NONE);
+ profileGroup.setText("Profile");
+ profileGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
+ profileGroup.setLayout(new GridLayout(3, false));
+
+ createLabel(profileGroup, "Profile ID:");
+
+ profileCombo = new Combo(profileGroup, SWT.NONE);
+ profileCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL |
GridData.GRAB_HORIZONTAL));
+ String[] profileIDs = getProfileIds();
+ profileCombo.setItems(profileIDs);
+ profileCombo.setText(EMPTY_STRING);
+ profileCombo.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ });
+ profileComboDecoration = addDecoration(profileCombo,
FieldDecorationRegistry.DEC_REQUIRED, PROFILE_ID_IS_REQUIRED);
+
+ activeByDefaultButton = new Button(profileGroup, SWT.CHECK);
+ activeByDefaultButton.setLayoutData(new GridData(GridData.FILL,
+ GridData.FILL, false, false));
+ activeByDefaultButton.setText("Active by default");
+
+ profileCombo.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Settings settings;
+ String id = profileCombo.getText();
+ if (id == null || id.trim().isEmpty()) {
+ return;
+ }
+ for (RepositoryWrapper wrapper:availableRepositories) {
+ if (wrapper.getProfileId() != null && wrapper.getRepository() != null
&& id.equals(wrapper.getProfileId())) {
+ updateRepository(wrapper.getRepository());
+ activeByDefaultButton.setSelection(true);
+ return;
+ }
+ }
+ try {
+ settings = maven.getSettings();
+ for (Profile profile : settings.getProfiles()) {
+ if (id.equals(profile.getId())) {
+ if (profile.getActivation() == null) {
+ activeByDefaultButton.setSelection(false);
+ }
+ if (profile.getActivation() != null) {
+ activeByDefaultButton.setSelection(profile
+ .getActivation().isActiveByDefault());
+ }
+ List<Repository> repositories = profile
+ .getRepositories();
+ if (repositories != null
+ && repositories.size() == 1) {
+ Repository repository = repositories.get(0);
+ updateRepository(repository);
+ }
+ }
+ break;
+ }
+ } catch (CoreException e1) {
+ Activator.log(e1);
+ }
+
+ }
+
+ });
+
+ Group repositoryGroup = new Group(contents, SWT.NONE);
+ repositoryGroup.setText("Repository");
+ repositoryGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
false));
+ repositoryGroup.setLayout(new GridLayout(2, false));
+
+ createLabel(repositoryGroup, "ID:");
+ idText = createText(repositoryGroup);
+ idTextDecoration = addDecoration(idText, FieldDecorationRegistry.DEC_REQUIRED,
REPOSITORY_ID_IS_REQUIRED);
+
+ createLabel(repositoryGroup, "Name:");
+ nameText = createText(repositoryGroup);
+ nameTextDecoration = addDecoration(nameText, FieldDecorationRegistry.DEC_WARNING,
REPOSITORY_NAME_IS_EMPTY);
+
+ createLabel(repositoryGroup, "URL:");
+ urlText = createText(repositoryGroup);
+ urlTextDecoration = addDecoration(urlText, FieldDecorationRegistry.DEC_REQUIRED,
REPOSITORY_URL_IS_REQUIRED);
+ urlValidTextDecoration = addDecoration(urlText, FieldDecorationRegistry.DEC_ERROR,
URL_IS_NOT_VALID);
+ urlExistsTextDecoration = addDecoration(urlText, FieldDecorationRegistry.DEC_ERROR,
URL_ALREADY_EXISTS);
+
+ Button recognizeButton = new Button(contents, SWT.PUSH);
+ recognizeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, true, false));
+ recognizeButton.setText("Recognize JBoss Maven Enterprise Repositories...");
+ recognizeButton.setImage(getJBossImage());
+
+ recognizeButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
+ directoryDialog.setMessage("Select the directory in which to search for JBoss
Maven Enterprise Repositories:");
+ directoryDialog.setText("Search for JBoss Maven Enterprise Repositories");
+
+ dialogSettings = Activator.getDefault().getDialogSettings();
+ IDialogSettings configureMavenRepositories =
dialogSettings.getSection(CONFIGURE_MAVEN_REPOSITORIES);
+ if (configureMavenRepositories == null) {
+ configureMavenRepositories =
dialogSettings.addNewSection(CONFIGURE_MAVEN_REPOSITORIES);
+ }
+ String filterPath = configureMavenRepositories.get(LASTPATH);
+ if (filterPath != null) {
+ directoryDialog.setFilterPath(filterPath);
+ }
+ String pathStr = directoryDialog.open();
+ if (pathStr == null)
+ return;
+
+ configureMavenRepositories.put(LASTPATH, pathStr);
+ final IPath path = new Path(pathStr);
+
+ final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ dialog.setBlockOnOpen(false);
+ dialog.setCancelable(true);
+ dialog.open();
+ final IProgressMonitor monitor = dialog.getProgressMonitor();
+ monitor.beginTask("Searching...", 110);
+ final Set<RepositoryWrapper> repos = new HashSet<RepositoryWrapper>();
+
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor2) {
+ searchForRepositories(path, repos, monitor2);
+ }
+ };
+ try {
+ dialog.run(true, true, runnable);
+ } catch (Exception e1) {
+ Activator.log(e1);
+ }
+
+ if (monitor.isCanceled()) {
+ return;
+ }
+ if (repos.size() == 0) {
+ String url = new File(pathStr).toURI().toString();
+ url = url.trim();
+ if (!url.endsWith(RepositoryWrapper.SEPARATOR)) {
+ url = url + RepositoryWrapper.SEPARATOR;
+ }
+ Set<RepositoryWrapper> allRepositories = new
HashSet<RepositoryWrapper>();
+ allRepositories.addAll(includedRepositories);
+ allRepositories.addAll(availableRepositories);
+ boolean found = false;
+ for (RepositoryWrapper wrapper:allRepositories) {
+ if (url.equals(wrapper.getRepository().getUrl())) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ MessageDialog.openInformation(getShell(), "Information", "No new
repository found.");
+ return;
+ } else {
+ boolean ok = MessageDialog.openQuestion(getShell(), "Confirm Add
Repository", "No new repository found. Would you like me to add the '"
+ url + "' repository.");
+ if (ok) {
+ Repository repository =
ConfigureMavenRepositoriesWizardPage.getDefaultRepository();
+ repository.setId(getUniqueId(new File(pathStr), "id",
allRepositories));
+ repository.setName(new File(pathStr).getName());
+ repository.setUrl(url);
+ RepositoryWrapper wrapper = new RepositoryWrapper(repository,
repository.getId());
+ repos.add(wrapper);
+ }
+ }
+ }
+ for (RepositoryWrapper wrapper:repos) {
+ if (!includedRepositories.contains(wrapper)) {
+ availableRepositories.add(wrapper);
+ }
+ }
+ if (repos.size() > 0) {
+ String[] profileIDs = getProfileIds();
+ profileCombo.setItems(profileIDs);
+ RepositoryWrapper wrapper = repos.iterator().next();
+ profileCombo.setText(wrapper.getProfileId());
+ if (wrapper.getRepository() != null) {
+ updateRepository(wrapper.getRepository());
+ activeByDefaultButton.setSelection(true);
+ }
+ }
+ }
+ });
+
+ return area;
+ }
+
+ private Text createText(Composite parent) {
+ Text text = new Text(parent, SWT.SINGLE|SWT.BORDER);
+ text.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL |
GridData.GRAB_HORIZONTAL));
+ text.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+ });
+ return text;
+ }
+
+ protected void validate() {
+ idTextDecoration.hide();
+ urlTextDecoration.hide();
+ nameTextDecoration.hide();
+ profileComboDecoration.hide();
+ urlValidTextDecoration.hide();
+ urlExistsTextDecoration.hide();
+ getButton(IDialogConstants.OK_ID).setEnabled(true);
+ setMessage(null);
+ if (profileCombo.getText().trim().isEmpty()) {
+ setMessage(PROFILE_ID_IS_REQUIRED, IMessageProvider.ERROR);
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ showDecoration();
+ return;
+ }
+ if (idText.getText().trim().isEmpty()) {
+ setMessage(REPOSITORY_ID_IS_REQUIRED, IMessageProvider.ERROR);
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ showDecoration();
+ return;
+ }
+ if (urlText.getText().trim().isEmpty()) {
+ setMessage(REPOSITORY_URL_IS_REQUIRED, IMessageProvider.ERROR);
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ showDecoration();
+ return;
+ }
+ String urlString;
+ try {
+ urlString = new URL(urlText.getText().trim()).toString();
+ } catch (MalformedURLException e) {
+ setMessage(URL_IS_NOT_VALID, IMessageProvider.ERROR);
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ showDecoration();
+ return;
+ }
+ if (!urlString.endsWith(RepositoryWrapper.SEPARATOR)) {
+ urlString = urlString + RepositoryWrapper.SEPARATOR;
+ }
+ for (RepositoryWrapper wrapper:includedRepositories) {
+ if (urlString.equals(wrapper.getRepository().getUrl())) {
+ setMessage(URL_ALREADY_EXISTS, IMessageProvider.ERROR);
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ showDecoration();
+ return;
+ }
+ }
+ if (nameText.getText().trim().isEmpty()) {
+ setMessage(REPOSITORY_NAME_IS_EMPTY, IMessageProvider.WARNING);
+ showDecoration();
+ return;
+ }
+ }
+
+ private void showDecoration() {
+ if (profileCombo.getText().trim().isEmpty()) {
+ profileComboDecoration.show();
+ }
+ if (idText.getText().trim().isEmpty()) {
+ idTextDecoration.show();
+ }
+ if (urlText.getText().trim().isEmpty()) {
+ urlTextDecoration.show();
+ } else {
+ String urlString;
+ try {
+ urlString = new URL(urlText.getText().trim()).toString();
+ if (!urlString.endsWith(RepositoryWrapper.SEPARATOR)) {
+ urlString = urlString + RepositoryWrapper.SEPARATOR;
+ }
+ for (RepositoryWrapper wrapper:includedRepositories) {
+ if (urlString.equals(wrapper.getRepository().getUrl())) {
+ urlExistsTextDecoration.show();
+ }
+ }
+ } catch (MalformedURLException e) {
+ urlValidTextDecoration.show();
+ }
+ }
+ if (nameText.getText().trim().isEmpty()) {
+ nameTextDecoration.show();
+ }
+ }
+
+ private Label createLabel(Composite repositoryComposite, String text) {
+ Label label = new Label(repositoryComposite, SWT.NONE);
+ label.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false,
+ false));
+ label.setText(text);
+ return label;
+ }
+
+ private String[] getProfileIds() {
+ Set<String> ids = new TreeSet<String>();
+ ids.add(EMPTY_STRING);
+ for (RepositoryWrapper wrapper:availableRepositories) {
+ if (wrapper.getProfileId() != null && !wrapper.getProfileId().isEmpty()) {
+ ids.add(wrapper.getProfileId());
+ }
+ }
+// Settings settings;
+// try {
+// settings = maven.getSettings();
+// } catch (CoreException e) {
+// return ids.toArray(new String[0]);
+// }
+// for (Profile profile : settings.getProfiles()) {
+// if (profile.getId() != null) {
+// ids.add(profile.getId());
+// }
+// }
+// for (RepositoryWrapper wrapper:availableRepositories) {
+// if (wrapper.getProfileId() != null && !wrapper.getProfileId().isEmpty()) {
+// ids.add(wrapper.getProfileId());
+// }
+// }
+ return ids.toArray(new String[0]);
+ }
+
+ protected void updateRepository(Repository repository) {
+ idText.setText(repository.getId());
+ nameText.setText(repository.getName());
+ urlText.setText(repository.getUrl());
+ }
+
+ private Image getJBossImage() {
+ if (jbossImage == null) {
+ ImageDescriptor desc = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
+ "icons/jboss.png"); //$NON-NLS-1$
+ jbossImage = desc.createImage();
+ }
+ return jbossImage;
+ }
+
+ private void searchForRepositories(IPath path,
+ Set<RepositoryWrapper> repos, IProgressMonitor monitor) {
+ File[] files = null;
+ if (path != null) {
+ File f = path.toFile();
+ if (f.isDirectory()) {
+ files = new File[1];
+ files[0] = f;
+ }
+ else
+ return;
+ } else
+ files = File.listRoots();
+
+ if (files != null) {
+ int size = files.length;
+ int work = 100 / size;
+ int workLeft = 100 - (work * size);
+ for (int i = 0; i < size; i++) {
+ if (monitor.isCanceled())
+ return;
+ if (files[i] != null && files[i].isDirectory()) {
+ searchDir(repos, files[i], 4, monitor);
+ }
+ monitor.worked(work);
+ }
+ monitor.worked(workLeft);
+ } else
+ monitor.worked(100);
+ }
+
+ private void searchDir(Set<RepositoryWrapper> repos, File directory, int depth,
+ IProgressMonitor monitor) {
+
+ String localRepository = getLocalRepository();
+ if (localRepository != null &&
localRepository.trim().equals(directory.getAbsolutePath())) {
+ return;
+ }
+ monitor.setTaskName("Searching " + directory.getAbsolutePath());
+ File comFile = new File(directory, "com"); //$NON-NLS-1$
+ if (comFile.isDirectory()) {
+ if (getRepositoryFromDir(directory, repos, monitor)) {
+ return;
+ }
+ }
+
+ if (depth == 0)
+ return;
+
+ File[] files = directory.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ return file.isDirectory();
+ }
+ });
+ if (files != null) {
+ int size = files.length;
+ for (int i = 0; i < size; i++) {
+ if (monitor.isCanceled())
+ return;
+ searchDir(repos, files[i], depth - 1, monitor);
+ }
+ }
+ }
+
+ private boolean getRepositoryFromDir(File directory, Set<RepositoryWrapper> repos,
IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return false;
+ }
+
+ File file = new File(directory, JSF_IMPL);
+ if (file.isDirectory()) {
+ File[] list = file.listFiles(new FileFilter() {
+
+ public boolean accept(File pathname) {
+ if (pathname != null && pathname.getName() != null &&
pathname.getName().contains("redhat")) {
+ return true;
+ }
+ return false;
+ }
+ });
+ if (list != null && list.length >= 1) {
+ // JBoss EAP Maven Repository
+ Repository repository = ConfigureMavenRepositoriesWizardPage.getDefaultRepository();
+ Set<RepositoryWrapper> allRepositories = new
HashSet<RepositoryWrapper>();
+ allRepositories.addAll(repos);
+ allRepositories.addAll(includedRepositories);
+ allRepositories.addAll(availableRepositories);
+ String url = getUrl(directory);
+ if (url == null) {
+ return false;
+ }
+ for (RepositoryWrapper wrapper:allRepositories) {
+ if (url.equals(wrapper.getRepository().getUrl())) {
+ return true;
+ }
+ }
+ repository.setId(getUniqueId(directory, JBOSS_EAP_MAVEN_REPOSITORY_ID,
allRepositories));
+ repository.setName(JBOSS_EAP_MAVEN_REPOSITORY);
+ repository.setUrl(url);
+ RepositoryWrapper wrapper = new RepositoryWrapper(repository, repository.getId());
+ repos.add(wrapper);
+ return true;
+ }
+ }
+ file = new File(directory, WFK_BOMS);
+ if (file.isDirectory()) {
+ // JBoss WFK Maven Repository
+ Repository repository = ConfigureMavenRepositoriesWizardPage.getDefaultRepository();
+ Set<RepositoryWrapper> allRepositories = new
HashSet<RepositoryWrapper>();
+ allRepositories.addAll(repos);
+ allRepositories.addAll(includedRepositories);
+ allRepositories.addAll(availableRepositories);
+ String url = getUrl(directory);
+ if (url == null) {
+ return false;
+ }
+ for (RepositoryWrapper wrapper:allRepositories) {
+ if (url.equals(wrapper.getRepository().getUrl())) {
+ return true;
+ }
+ }
+ repository.setId(getUniqueId(directory, JBOSS_WFK_MAVEN_REPOSITORY_ID,
allRepositories));
+ repository.setName("JBoss WFK Maven Repository");
+ repository.setUrl(url);
+ RepositoryWrapper wrapper = new RepositoryWrapper(repository, repository.getId());
+ repos.add(wrapper);
+ return true;
+ }
+ return false;
+ }
+
+ protected String getUrl(File directory) {
+ String url;
+ try {
+ url = directory.toURI().toURL().toString();
+ } catch (MalformedURLException e1) {
+ Activator.log(e1);
+ return null;
+ }
+ url = url.trim();
+ if (!url.endsWith(RepositoryWrapper.SEPARATOR)) {
+ url = url + RepositoryWrapper.SEPARATOR;
+ }
+ return url;
+ }
+
+ private String getUniqueId(File directory, String simpleId, Set<RepositoryWrapper>
allRepositories) {
+ int i = 0;
+ String id = simpleId;
+ try {
+ id = directory.toURI().toURL().toString();
+ } catch (MalformedURLException e1) {
+ Activator.log(e1);
+ }
+ id = new Path(id).lastSegment();
+ id = id.replace(" ", "-"); //$NON-NLS-1$ //$NON-NLS-2$
+ id = id.replace("_", "-"); //$NON-NLS-1$ //$NON-NLS-2$
+ id = id.replace(".", "-"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ String startId = id;
+ while (true) {
+ boolean found = false;
+ for (RepositoryWrapper wrapper:allRepositories) {
+ if (id.equals(wrapper.getRepository().getId())) {
+ id = startId + "-" + i++; //$NON-NLS-1$
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return id;
+ }
+ }
+ }
+
+ private String getLocalRepository() {
+ if (localRepository == null) {
+ String userSettings = ConfigureMavenRepositoriesWizardPage.getUserSettings();
+ String globalSettings = MavenPlugin.getMavenRuntimeManager()
+ .getGlobalSettingsFile();
+ try {
+ Settings settings = maven.buildSettings(globalSettings,
+ userSettings);
+ localRepository = settings.getLocalRepository();
+ if (localRepository == null) {
+ localRepository = RepositorySystem.defaultUserLocalRepository
+ .getAbsolutePath();
+ }
+ } catch (CoreException e) {
+ Activator.log(e);
+ }
+ }
+ return localRepository;
+ }
+
+ @Override
+ public boolean close() {
+ if (jbossImage != null) {
+ jbossImage.dispose();
+ }
+ return super.close();
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ validate();
+ }
+
+ protected ControlDecoration addDecoration(Control control, String id, String
description) {
+ final ControlDecoration decPath = new ControlDecoration(control, SWT.TOP
+ | SWT.LEFT);
+ FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
+ FieldDecoration fd = registry.getFieldDecoration(id);
+ decPath.setImage(fd.getImage());
+ fd.setDescription(description);
+
+ decPath.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(
+ id).getImage());
+
+ decPath.setShowOnlyOnFocus(false);
+ decPath.setShowHover(true);
+ decPath.setDescriptionText(description);
+ return decPath;
+ }
+
+ public RepositoryWrapper getRepositoryWrapper() {
+ return repositoryWrapper;
+ }
+
+ @Override
+ protected void okPressed() {
+ Repository repository = ConfigureMavenRepositoriesWizardPage.getDefaultRepository();
+ repository.setId(idText.getText().trim());
+ repository.setName(nameText.getText().trim());
+ repository.setUrl(urlText.getText().trim());
+ repositoryWrapper = new RepositoryWrapper(repository, profileCombo.getText().trim());
+ activeByDefault = activeByDefaultButton.getSelection();
+ super.okPressed();
+ }
+
+ public boolean isActiveByDefault() {
+ return activeByDefault;
+ }
+}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java 2012-05-25
15:52:57 UTC (rev 41431)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java 2012-05-25
16:07:10 UTC (rev 41432)
@@ -13,7 +13,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -22,7 +21,6 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -41,7 +39,6 @@
import javax.xml.transform.stream.StreamResult;
import org.apache.maven.cli.MavenCli;
-import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Profile;
import org.apache.maven.settings.Repository;
import org.apache.maven.settings.RepositoryPolicy;
@@ -53,15 +50,8 @@
import org.eclipse.compare.structuremergeviewer.DiffNode;
import org.eclipse.compare.structuremergeviewer.Differencer;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnLayoutData;
@@ -77,16 +67,15 @@
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.ToolTip;
+import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
-import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
@@ -94,7 +83,6 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.jboss.tools.maven.ui.Activator;
@@ -112,6 +100,30 @@
*/
public class ConfigureMavenRepositoriesWizardPage extends WizardPage {
+ private static final String ACTIVE_PROFILE = "activeProfile"; //$NON-NLS-1$
+
+ private static final String ACTIVE_PROFILES = "activeProfiles"; //$NON-NLS-1$
+
+ private static final String REPOSITORY_APACHE_ORG_ID =
"repository-apache-org"; //$NON-NLS-1$
+
+ private static final String REPOSITORY_APACHE_ORG_PROFILE_ID =
REPOSITORY_APACHE_ORG_ID;
+
+ private static final String COM_SPRINGSOURCE_REPOSITORY_BUNDLES_EXTERNAL_ID =
"com-springsource-repository-bundles-external"; //$NON-NLS-1$
+
+ private static final String COM_SPRINGSOURCE_REPOSITORY_BUNDLES_EXTERNAL_PROFILE_ID =
COM_SPRINGSOURCE_REPOSITORY_BUNDLES_EXTERNAL_ID;
+
+ private static final String COM_SPRINGSOURCE_REPOSITORY_BUNDLES_RELEASE_ID =
"com-springsource-repository-bundles-release"; //$NON-NLS-1$
+
+ private static final String COM_SPRINGSOURCE_REPOSITORY_BUNDLES_RELEASE_PROFILE_ID =
COM_SPRINGSOURCE_REPOSITORY_BUNDLES_RELEASE_ID;
+
+ private static final String JAVA_NET_PUBLIC_ID = "java-net-public";
//$NON-NLS-1$
+
+ private static final String JAVA_NET_PUBLIC_PROFILE_ID = JAVA_NET_PUBLIC_ID;
+
+ private static final String JBOSS_PUBLIC_REPOSITORY_ID =
"jboss-public-repository"; //$NON-NLS-1$
+
+ private static final String JBOSS_PUBLIC_REPOSITORY_PROFILE_ID =
JBOSS_PUBLIC_REPOSITORY_ID;
+
private static final String ERROR_TITLE = "Error";
private static final String SNAPSHOTS_ELEMENT = "snapshots"; //$NON-NLS-1$
@@ -134,22 +146,13 @@
private static final String REPOSITORY_ELEMENT = "repository"; //$NON-NLS-1$
- private static final String LASTPATH = "lastPath"; //$NON-NLS-1$
-
- private static final String CONFIGURE_MAVEN_REPOSITORIES =
"ConfigureMavenRepositories"; //$NON-NLS-1$
-
- private static final String JBOSS_EAP_MAVEN_REPOSITORY = "JBoss EAP Maven
Repository"; //$NON-NLS-1$
-
private static final String PLUGIN_REPOSITORIES_ELEMENT =
"pluginRepositories"; //$NON-NLS-1$
private static final String PLUGIN_REPOSITORY_ELEMENT = "pluginRepository";
//$NON-NLS-1$
private static final String REPOSITORIES_ELEMENT = "repositories";
//$NON-NLS-1$
- private static final String ACTIVE_BY_DEFAULT_ELEMENT = "activeByDefault";
//$NON-NLS-1$
- private static final String ACTIVATION_ELEMENT = "activation"; //$NON-NLS-1$
-
private static final String ID_ELEMENT = "id"; //$NON-NLS-1$
private static final String PROFILE_ELEMENT = "profile"; //$NON-NLS-1$
@@ -158,36 +161,20 @@
private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
- public static final String JBOSSTOOLS_MAVEN_PROFILE_ID =
"jbosstools-maven-profile"; //$NON-NLS-1$
-
- private static final String JSF_IMPL = "com" + File.separator +
"sun" + File.separator + "faces" + File.separator +
"jsf-impl"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- private static final String WFK_BOMS = "com" + File.separator +
"redhat" + File.separator + "jboss" + File.separator + "wfk"
+ File.separator + "boms"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$ //$NON-NLS-5$
-
private static final String PAGE_NAME =
"org.jboss.tools.maven.ui.wizard.page"; //$NON-NLS-1$
- private static final String ADD_ALL = " Add All>> ";
- private static final String ADD = " Add>> ";
- private static final String REMOVE_ALL = " <<Remove All ";
- private static final String REMOVE = " <Remove ";
+ private static final String ADD_REPOSITORY = " Add Repository ";
+ private static final String REMOVE_ALL = " Remove All ";
+ private static final String REMOVE = " Remove ";
- private static final String JBOSS_EAP_MAVEN_REPOSITORY_ID =
"jboss-eap-maven-repository";; //$NON-NLS-1$
- private static final String JBOSS_WFK_MAVEN_REPOSITORY_ID =
"jboss-wfk-maven-repository";; //$NON-NLS-1$
-
private Button removeButton;
private Button removeAllButton;
- private Button addButton;
- private Button addAllButton;
- private IMavenConfiguration mavenConfiguration;
+ private Button addRepositoryButton;
private IMaven maven;
- private Image jbossImage;
private TableViewer includedRepositoriesViewer;
private Set<RepositoryWrapper> includedRepositories;
private Set<RepositoryWrapper> availableRepositories;
private Set<RepositoryWrapper> selectedIncludedRepositories = new
HashSet<RepositoryWrapper>();
- private Set<RepositoryWrapper> selectedAvailableRepositories = new
HashSet<RepositoryWrapper>();
- private TableViewer availableRepositoriesViewer;
- private String localRepository;
-
private Document document;
private CompareConfiguration compareConfiguration;
@@ -197,46 +184,17 @@
private String newSettings;
private String oldSettings;
-
- private Element jbossMavenProfile;
-
- private Element repositoriesElement;
-
- private Element pluginRepositoriesElement;
- private IDialogSettings dialogSettings;
-
public ConfigureMavenRepositoriesWizardPage() {
super(PAGE_NAME);
setTitle("Configure Maven Repositories");
- mavenConfiguration = MavenPlugin.getMavenConfiguration();
maven = MavenPlugin.getMaven();
- try {
- maven.reloadSettings();
- } catch (CoreException e) {
- Activator.log(e);
- }
+// try {
+// maven.reloadSettings();
+// } catch (CoreException e) {
+// Activator.log(e);
+// }
}
-
- private String getLocalRepository() {
- if (localRepository == null) {
- String userSettings = getUserSettings();
- String globalSettings = MavenPlugin.getMavenRuntimeManager()
- .getGlobalSettingsFile();
- try {
- Settings settings = maven.buildSettings(globalSettings,
- userSettings);
- localRepository = settings.getLocalRepository();
- if (localRepository == null) {
- localRepository = RepositorySystem.defaultUserLocalRepository
- .getAbsolutePath();
- }
- } catch (CoreException e) {
- Activator.log(e);
- }
- }
- return localRepository;
- }
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
@@ -270,8 +228,7 @@
}
DocumentBuilder builder;
try {
- DocumentBuilderFactory factory = DocumentBuilderFactory
- .newInstance();
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
Activator.log(e);
@@ -299,119 +256,22 @@
throw new RuntimeException(e1);
}
}
- NodeList profilesList = document.getElementsByTagName(PROFILES_ELEMENT);
- Node profiles;
- if (profilesList.getLength() > 0) {
- profiles = profilesList.item(0);
- NodeList profileNodes = profiles.getChildNodes();
- int length = profileNodes.getLength();
-
- for (int i = 0; i < length; i++) {
- Node profile = profileNodes.item(i);
- if (profile.getNodeType() == Node.ELEMENT_NODE
- && PROFILE_ELEMENT.equals(profile.getNodeName())) {
- NodeList profileElements = profile.getChildNodes();
- for (int j = 0; j < profileElements.getLength(); j++) {
- Node node = profileElements.item(j);
- if (node.getNodeType() == Node.ELEMENT_NODE
- && ID_ELEMENT.equals(node.getNodeName())) {
- String id = node.getTextContent();
- if (id != null) {
- id = id.trim();
- }
- if (JBOSSTOOLS_MAVEN_PROFILE_ID.equals(id)) {
- jbossMavenProfile = (Element) profile;
- break;
- }
- }
- }
- }
- if (jbossMavenProfile != null) {
- break;
- }
- }
- } else {
- profiles = document.createElement(PROFILES_ELEMENT);
- document.getDocumentElement().appendChild(profiles);
- }
-
- if (jbossMavenProfile == null) {
- createJBossMavenProfile(profiles);
- } else {
- configureJBossMavenProfile();
- }
-
+
Group repositoriesGroup = new Group(composite, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
GridLayout layout = new GridLayout(3, false);
repositoriesGroup.setLayout(layout);
repositoriesGroup.setLayoutData(gd);
repositoriesGroup.setText("Repositories");
-
- Composite availableRepositoriesComposite = new Composite(repositoriesGroup,
SWT.NONE);
- gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- availableRepositoriesComposite.setLayoutData(gd);
- availableRepositoriesComposite.setLayout(new GridLayout());
-
- Label availableRepositoriesLabel = new Label(availableRepositoriesComposite,
SWT.NONE);
- gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- availableRepositoriesLabel.setLayoutData(gd);
- availableRepositoriesLabel.setText("Available Repositories:");
-
- availableRepositoriesViewer = new TableViewer(availableRepositoriesComposite,
SWT.BORDER | SWT.MULTI |SWT.H_SCROLL|SWT.V_SCROLL);
- gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- gd.heightHint = 150;
- gd.widthHint = 350;
- availableRepositoriesViewer.getTable().setLayoutData(gd);
- availableRepositoriesViewer.getTable().setLinesVisible(false);
- availableRepositoriesViewer.getTable().setHeaderVisible(false);
- TableViewerColumn column = new TableViewerColumn(availableRepositoriesViewer,
SWT.NONE);
- column.getColumn().setText("Repository");
- //column.getColumn().setWidth(350);
- column.getColumn().setResizable(true);
- ColumnLayoutData columnLayoutData = new ColumnWeightData(350,350);
- TableLayout availableLayout = new
AutoResizeTableLayout(availableRepositoriesViewer.getTable());
- availableLayout.addColumnData(columnLayoutData);
- availableRepositoriesViewer.setContentProvider(new ArrayContentProvider());
- availableRepositoriesViewer.setLabelProvider(new RepositoryLabelProvider());
-
ColumnViewerToolTipSupport.enableFor(availableRepositoriesViewer,ToolTip.NO_RECREATE);
-
- Composite buttonsComposite = new Composite(repositoriesGroup, SWT.NONE);
- gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- buttonsComposite.setLayoutData(gd);
- buttonsComposite.setLayout(new GridLayout(1, false));
-
- Label buttonsLabel = new Label(buttonsComposite, SWT.NONE);
- gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- buttonsLabel.setLayoutData(gd);
-
- GC gc = new GC(buttonsComposite);
- int maxAddRemoveButtonsWidth = computeMaxAddRemoveButtonsWidth(gc);
- gc.dispose();
-
- Composite buttonsComp = new Composite(buttonsComposite, SWT.NONE);
- gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- buttonsComp.setLayoutData(gd);
- buttonsComp.setLayout(new GridLayout());
-
- removeButton = createButton(buttonsComp, maxAddRemoveButtonsWidth, REMOVE);
- removeAllButton = createButton(buttonsComp, maxAddRemoveButtonsWidth,
REMOVE_ALL);
- addButton = createButton(buttonsComp, maxAddRemoveButtonsWidth, ADD);
- addAllButton = createButton(buttonsComp, maxAddRemoveButtonsWidth, ADD_ALL);
-
+
Composite includedRepositoriesComposite = new Composite(repositoriesGroup,
SWT.NONE);
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
includedRepositoriesComposite.setLayoutData(gd);
includedRepositoriesComposite.setLayout(new GridLayout(1, false));
-
- Label includedRepositoriesLabel = new Label(includedRepositoriesComposite,
SWT.NONE);
- gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- includedRepositoriesLabel.setLayoutData(gd);
- includedRepositoriesLabel.setText("Included Repositories:");
-
+
includedRepositoriesViewer = new TableViewer(includedRepositoriesComposite,
SWT.BORDER | SWT.MULTI | SWT.H_SCROLL|SWT.V_SCROLL);
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- gd.widthHint = 350;
+ gd.widthHint = 500;
gd.heightHint = 150;
includedRepositoriesViewer.getTable().setLayoutData(gd);
includedRepositoriesViewer.getTable().setLinesVisible(false);
@@ -420,72 +280,16 @@
c.getColumn().setText("Repository");
c.getColumn().setResizable(true);
TableLayout includedLayout = new
AutoResizeTableLayout(includedRepositoriesViewer.getTable());
+ ColumnLayoutData columnLayoutData = new ColumnWeightData(350,350);
includedLayout.addColumnData(columnLayoutData);
includedRepositoriesViewer.setContentProvider(new ArrayContentProvider());
includedRepositoriesViewer.setLabelProvider(new RepositoryLabelProvider());
- ColumnViewerToolTipSupport.enableFor(availableRepositoriesViewer,
ToolTip.NO_RECREATE);
+ ColumnViewerToolTipSupport.enableFor(includedRepositoriesViewer,
ToolTip.NO_RECREATE);
- Button recognizeButton = new Button(composite, SWT.PUSH);
- recognizeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, true, false));
- recognizeButton.setText("Recognize JBoss Maven Enterprise Repositories...");
- recognizeButton.setImage(getJBossImage());
+ createButtons(repositoriesGroup);
+
- recognizeButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
- directoryDialog.setMessage("Select the directory in which to search for JBoss
Maven Enterprise Repositories:");
- directoryDialog.setText("Search for JBoss Maven Enterprise Repositories");
-
- dialogSettings = Activator.getDefault().getDialogSettings();
- IDialogSettings configureMavenRepositories =
dialogSettings.getSection(CONFIGURE_MAVEN_REPOSITORIES);
- if (configureMavenRepositories == null) {
- configureMavenRepositories =
dialogSettings.addNewSection(CONFIGURE_MAVEN_REPOSITORIES);
- }
- String filterPath = configureMavenRepositories.get(LASTPATH);
- if (filterPath != null) {
- directoryDialog.setFilterPath(filterPath);
- }
- String pathStr = directoryDialog.open();
- if (pathStr == null)
- return;
-
- configureMavenRepositories.put(LASTPATH, pathStr);
- final IPath path = new Path(pathStr);
-
- final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
- dialog.setBlockOnOpen(false);
- dialog.setCancelable(true);
- dialog.open();
- final IProgressMonitor monitor = dialog.getProgressMonitor();
- monitor.beginTask("Searching...", 110);
- final Set<RepositoryWrapper> repos = new HashSet<RepositoryWrapper>();
-
- IRunnableWithProgress runnable = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor2) {
- searchForRepositories(path, repos, monitor2);
- }
- };
- try {
- dialog.run(true, true, runnable);
- } catch (Exception e1) {
- Activator.log(e1);
- }
-
- if (monitor.isCanceled()) {
- return;
- }
- for (RepositoryWrapper wrapper:repos) {
- if (!includedRepositories.contains(wrapper)) {
- availableRepositories.add(wrapper);
- }
- }
- refreshRepositories();
- }
- });
-
includedRepositories = getIncludedRepositories();
availableRepositories = getAvailableRepositories();
List<RepositoryWrapper> remove = new ArrayList<RepositoryWrapper>();
@@ -498,24 +302,6 @@
availableRepositories.remove(repository);
}
- availableRepositoriesViewer.addSelectionChangedListener(new ISelectionChangedListener()
{
-
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection sel = event.getSelection();
- selectedAvailableRepositories.clear();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Iterator iterator = selection.iterator();
- while (iterator.hasNext()) {
- Object object = iterator.next();
- if (object instanceof RepositoryWrapper) {
- selectedAvailableRepositories.add((RepositoryWrapper) object);
- }
- }
- }
- configureButtons();
- }
- });
includedRepositoriesViewer.addSelectionChangedListener(new ISelectionChangedListener()
{
public void selectionChanged(SelectionChangedEvent event) {
@@ -538,15 +324,16 @@
@Override
public void widgetSelected(SelectionEvent e) {
- for (RepositoryWrapper wrapper:selectedIncludedRepositories) {
- if (wrapper.isJBossRepository()) {
+ boolean ok = getMessageDialog(selectedIncludedRepositories);
+ if (ok) {
+ for (RepositoryWrapper wrapper : selectedIncludedRepositories) {
includedRepositories.remove(wrapper);
availableRepositories.add(wrapper);
removeRepository(wrapper);
}
+ setPageComplete(true);
+ refreshRepositories();
}
- setPageComplete(true);
- refreshRepositories();
}
});
@@ -554,12 +341,14 @@
@Override
public void widgetSelected(SelectionEvent e) {
+ boolean ok = getMessageDialog(includedRepositories);
+ if (!ok) {
+ return;
+ }
List<RepositoryWrapper> list = new ArrayList<RepositoryWrapper>();
- for (RepositoryWrapper wrapper:includedRepositories) {
- if (wrapper.isJBossRepository()) {
- list.add(wrapper);
- removeRepository(wrapper);
- }
+ for (RepositoryWrapper wrapper : includedRepositories) {
+ list.add(wrapper);
+ removeRepository(wrapper);
}
includedRepositories.removeAll(list);
availableRepositories.addAll(list);
@@ -568,41 +357,24 @@
}
});
- addButton.addSelectionListener(new SelectionAdapter() {
+ addRepositoryButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- for (RepositoryWrapper wrapper:selectedAvailableRepositories) {
- if (wrapper.isJBossRepository()) {
- includedRepositories.add(wrapper);
- availableRepositories.remove(wrapper);
- addRepository(wrapper);
- }
+ AddRepositoryDialog dialog = new AddRepositoryDialog(getShell(),
availableRepositories, includedRepositories, maven);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ RepositoryWrapper wrapper = dialog.getRepositoryWrapper();
+ includedRepositories.add(wrapper);
+ availableRepositories.remove(wrapper);
+ addRepository(wrapper, dialog.isActiveByDefault());
+ setPageComplete(true);
+ refreshRepositories();
}
- setPageComplete(true);
- refreshRepositories();
}
});
- addAllButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<RepositoryWrapper> list = new ArrayList<RepositoryWrapper>();
- for (RepositoryWrapper wrapper:availableRepositories) {
- if (wrapper.isJBossRepository()) {
- list.add(wrapper);
- addRepository(wrapper);
- }
- }
- includedRepositories.addAll(list);
- availableRepositories.removeAll(list);
- setPageComplete(true);
- refreshRepositories();
- }
- });
-
Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setVisible(false);
@@ -615,19 +387,168 @@
setPageComplete(false);
}
- protected void createDefaultSettings() throws CoreException,
+ protected void createButtons(Composite parent) {
+ GridData gd;
+ Composite buttonsComposite = new Composite(parent, SWT.NONE);
+ gd = new GridData(SWT.FILL, SWT.TOP, false, false);
+ buttonsComposite.setLayoutData(gd);
+ buttonsComposite.setLayout(new GridLayout(1, false));
+
+ removeButton = createButton(buttonsComposite, REMOVE);
+ removeAllButton = createButton(buttonsComposite, REMOVE_ALL);
+ addRepositoryButton = createButton(buttonsComposite, ADD_REPOSITORY);
+ }
+
+ private void createDefaultSettings() throws CoreException,
UnsupportedEncodingException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
maven.writeSettings(new Settings(), out);
newSettings = new String(out.toByteArray(), UTF_8);
}
- protected void addRepository(RepositoryWrapper wrapper) {
- addRepository(wrapper, repositoriesElement, false);
- addRepository(wrapper, pluginRepositoriesElement, true);
+ private void addRepository(RepositoryWrapper wrapper, boolean activeByDefault) {
+ if (wrapper == null || wrapper.getProfileId() == null || wrapper.getRepository() ==
null) {
+ return;
+ }
+ String profileId = wrapper.getProfileId();
+ Element profile = getProfile(profileId);
+ Element repositoriesElement = getElement(profile, REPOSITORIES_ELEMENT);
+ if (repositoriesElement != null) {
+ addRepository(wrapper, repositoriesElement, false);
+ }
+ Element pluginRepositoriesElement = getElement(profile, PLUGIN_REPOSITORIES_ELEMENT);
+ if (pluginRepositoriesElement != null) {
+ addRepository(wrapper, pluginRepositoriesElement, true);
+ }
+ if (activeByDefault) {
+
+ NodeList activeProfilesList = document
+ .getElementsByTagName(ACTIVE_PROFILES);
+ Element activeProfiles = null;
+ if (activeProfilesList.getLength() > 0) {
+ activeProfiles = (Element) activeProfilesList.item(0);
+ }
+ if (activeProfiles == null) {
+ activeProfiles = document.createElement(ACTIVE_PROFILES);
+ document.getDocumentElement().appendChild(activeProfiles);
+ }
+ NodeList activeProfileList = activeProfiles.getChildNodes();
+ boolean activated = false;
+ for (int i = 0; i < activeProfileList.getLength(); i++) {
+ Node node = activeProfileList.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && ACTIVE_PROFILE.equals(node.getNodeName())) {
+ String id = node.getTextContent();
+ if (id != null) {
+ id = id.trim();
+ }
+ if (profileId.equals(id)) {
+ activated = true;
+ break;
+ }
+ }
+ }
+ if (!activated) {
+ addElement(activeProfiles, ACTIVE_PROFILE, profileId);
+ }
+ }
}
+ private Element getElement(Element element, String name) {
+ NodeList elements = element.getChildNodes();
+ int len = elements.getLength();
+ for (int i = 0; i < len; i++) {
+ Node node = elements.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE &&
name.equals(node.getNodeName())) {
+ return (Element) node;
+ }
+ }
+ return null;
+ }
+
+ private Element getProfile(String profileId) {
+ NodeList profilesList = document.getElementsByTagName(PROFILES_ELEMENT);
+ Node profiles;
+ Element profileElement = null;
+ if (profilesList.getLength() > 0) {
+ profiles = profilesList.item(0);
+ NodeList profileNodes = profiles.getChildNodes();
+ int length = profileNodes.getLength();
+
+ for (int i = 0; i < length; i++) {
+ Node profile = profileNodes.item(i);
+ if (profile.getNodeType() == Node.ELEMENT_NODE
+ && PROFILE_ELEMENT.equals(profile.getNodeName())) {
+ NodeList profileElements = profile.getChildNodes();
+ for (int j = 0; j < profileElements.getLength(); j++) {
+ Node node = profileElements.item(j);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && ID_ELEMENT.equals(node.getNodeName())) {
+ String id = node.getTextContent();
+ if (id != null) {
+ id = id.trim();
+ }
+ if (profileId.equals(id)) {
+ profileElement = (Element) profile;
+ break;
+ }
+ }
+ }
+ }
+ if (profileElement != null) {
+ break;
+ }
+ }
+ } else {
+ profiles = document.createElement(PROFILES_ELEMENT);
+ document.getDocumentElement().appendChild(profiles);
+ }
+
+ if (profileElement == null) {
+ profileElement = createProfile(profiles, profileId);
+ }
+ configureProfile(profileElement);
+ return profileElement;
+
+ }
+
+ private Element createProfile(Node profiles, String profileId) {
+ Element profile = document.createElement(PROFILE_ELEMENT);
+ profiles.appendChild(profile);
+ Element id = document.createElement(ID_ELEMENT);
+ id.setTextContent(profileId);
+ profile.appendChild(id);
+ return profile;
+ }
+
+ private void configureProfile(Element profileElement) {
+ NodeList nodeList = profileElement.getChildNodes();
+ int len = nodeList.getLength();
+ Element repositoriesElement = null;
+ Element pluginRepositoriesElement = null;
+ for (int i = 0; i < len; i++) {
+ Node node = nodeList.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE &&
REPOSITORIES_ELEMENT.equals(node.getNodeName())) {
+ repositoriesElement = (Element) node;
+ }
+ if (node.getNodeType() == Node.ELEMENT_NODE &&
PLUGIN_REPOSITORIES_ELEMENT.equals(node.getNodeName())) {
+ pluginRepositoriesElement = (Element) node;
+ }
+ if (repositoriesElement != null && pluginRepositoriesElement != null) {
+ return;
+ }
+ }
+ if (repositoriesElement == null) {
+ repositoriesElement = document.createElement(REPOSITORIES_ELEMENT);
+ profileElement.appendChild(repositoriesElement);
+ }
+ if (pluginRepositoriesElement == null) {
+ pluginRepositoriesElement = document.createElement(PLUGIN_REPOSITORIES_ELEMENT);
+ profileElement.appendChild(pluginRepositoriesElement);
+ }
+ }
+
private void addRepository(RepositoryWrapper wrapper, Element repos, boolean
isPluginRepository) {
Element repository;
if (isPluginRepository) {
@@ -667,9 +588,78 @@
}
protected void removeRepository(RepositoryWrapper wrapper) {
+ if (wrapper == null || wrapper.getProfileId() == null || wrapper.getRepository() ==
null || wrapper.getRepository().getUrl() == null) {
+ return;
+ }
String url = wrapper.getRepository().getUrl();
- removeRepository(url, repositoriesElement, false);
- removeRepository(url, pluginRepositoriesElement, true);
+ String profileId = wrapper.getProfileId();
+ Element profile = getProfile(profileId);
+ if (profile == null) {
+ return;
+ }
+ Element repositoriesElement = getElement(profile, REPOSITORIES_ELEMENT);
+ if (repositoriesElement != null) {
+ removeRepository(url, repositoriesElement, false);
+ }
+ Element pluginRepositoriesElement = getElement(profile, PLUGIN_REPOSITORIES_ELEMENT);
+ if (pluginRepositoriesElement != null) {
+ removeRepository(url, pluginRepositoriesElement, true);
+ }
+
+ // remove profile ?
+ if (repositoriesElement != null) {
+ NodeList nodeList = repositoriesElement.getChildNodes();
+ int len = nodeList.getLength();
+ for (int i = 0; i < len; i++) {
+ Node node = nodeList.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && REPOSITORY_ELEMENT.equals(node.getNodeName())) {
+ return;
+ }
+ }
+ }
+ if (pluginRepositoriesElement != null) {
+ NodeList nodeList = pluginRepositoriesElement.getChildNodes();
+ int len = nodeList.getLength();
+ for (int i = 0; i < len; i++) {
+ Node node = nodeList.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && PLUGIN_REPOSITORY_ELEMENT.equals(node.getNodeName())) {
+ return;
+ }
+ }
+ }
+ NodeList profilesList = document.getElementsByTagName(PROFILES_ELEMENT);
+ Element profiles = (Element) profilesList.item(0);
+ profiles.removeChild(profile);
+
+ NodeList activeProfilesList = document
+ .getElementsByTagName(ACTIVE_PROFILES);
+ Element activeProfiles = null;
+ if (activeProfilesList.getLength() > 0) {
+ activeProfiles = (Element) activeProfilesList.item(0);
+ }
+ if (activeProfiles != null) {
+ NodeList activeProfileList = activeProfiles.getChildNodes();
+ Node profileNode = null;
+ for (int i = 0; i < activeProfileList.getLength(); i++) {
+ Node node = activeProfileList.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && ACTIVE_PROFILE.equals(node.getNodeName())) {
+ String id = node.getTextContent();
+ if (id != null) {
+ id = id.trim();
+ }
+ if (profileId.equals(id)) {
+ profileNode = node;
+ break;
+ }
+ }
+ }
+ if (profileNode != null) {
+ activeProfiles.removeChild(profileNode);
+ }
+ }
}
protected void removeRepository(String url, Element repos, boolean isPluginRepository)
{
@@ -716,49 +706,6 @@
return null;
}
- private void configureJBossMavenProfile() {
- NodeList nodeList = jbossMavenProfile.getChildNodes();
- int len = nodeList.getLength();
- for (int i = 0; i < len; i++) {
- Node node = nodeList.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE &&
REPOSITORIES_ELEMENT.equals(node.getNodeName())) {
- repositoriesElement = (Element) node;
- }
- if (node.getNodeType() == Node.ELEMENT_NODE &&
PLUGIN_REPOSITORIES_ELEMENT.equals(node.getNodeName())) {
- pluginRepositoriesElement = (Element) node;
- }
- if (repositoriesElement != null && pluginRepositoriesElement != null) {
- return;
- }
- }
- if (repositoriesElement == null) {
- repositoriesElement = document.createElement(REPOSITORIES_ELEMENT);
- jbossMavenProfile.appendChild(repositoriesElement);
- }
- if (pluginRepositoriesElement == null) {
- pluginRepositoriesElement = document.createElement(PLUGIN_REPOSITORIES_ELEMENT);
- jbossMavenProfile.appendChild(pluginRepositoriesElement);
- }
- }
-
- private Element createJBossMavenProfile(Node profiles) {
- jbossMavenProfile = document.createElement(PROFILE_ELEMENT);
- profiles.appendChild(jbossMavenProfile);
- Element id = document.createElement(ID_ELEMENT);
- id.setTextContent(JBOSSTOOLS_MAVEN_PROFILE_ID);
- jbossMavenProfile.appendChild(id);
- Element activation = document.createElement(ACTIVATION_ELEMENT);
- jbossMavenProfile.appendChild(activation);
- Element activeByDefault = document.createElement(ACTIVE_BY_DEFAULT_ELEMENT);
- activeByDefault.setTextContent("true"); //$NON-NLS-1$
- activation.appendChild(activeByDefault);
- repositoriesElement = document.createElement(REPOSITORIES_ELEMENT);
- jbossMavenProfile.appendChild(repositoriesElement);
- pluginRepositoriesElement = document.createElement(PLUGIN_REPOSITORIES_ELEMENT);
- jbossMavenProfile.appendChild(pluginRepositoriesElement);
- return jbossMavenProfile;
- }
-
private void createPreviewer(Composite composite) {
compareConfiguration= new CompareConfiguration();
compareConfiguration.setAncestorLabel("Preview:");
@@ -810,145 +757,7 @@
return null;
}
- private void searchForRepositories(IPath path,
- Set<RepositoryWrapper> repos, IProgressMonitor monitor) {
- File[] files = null;
- if (path != null) {
- File f = path.toFile();
- if (f.isDirectory()) {
- files = new File[1];
- files[0] = f;
- }
- else
- return;
- } else
- files = File.listRoots();
- if (files != null) {
- int size = files.length;
- int work = 100 / size;
- int workLeft = 100 - (work * size);
- for (int i = 0; i < size; i++) {
- if (monitor.isCanceled())
- return;
- if (files[i] != null && files[i].isDirectory()) {
- searchDir(repos, files[i], 4, monitor);
- }
- monitor.worked(work);
- }
- monitor.worked(workLeft);
- } else
- monitor.worked(100);
- }
-
- private void searchDir(Set<RepositoryWrapper> repos, File directory, int depth,
- IProgressMonitor monitor) {
-
- String localRepository = getLocalRepository();
- if (localRepository != null &&
localRepository.trim().equals(directory.getAbsolutePath())) {
- return;
- }
- monitor.setTaskName("Searching " + directory.getAbsolutePath());
- File comFile = new File(directory, "com"); //$NON-NLS-1$
- if (comFile.isDirectory()) {
- RepositoryWrapper repository = getRepositoryFromDir(directory, repos, monitor);
- if (repository != null) {
- repos.add(repository);
- return;
- }
- }
-
- if (depth == 0)
- return;
-
- File[] files = directory.listFiles(new FileFilter() {
- public boolean accept(File file) {
- return file.isDirectory();
- }
- });
- if (files != null) {
- int size = files.length;
- for (int i = 0; i < size; i++) {
- if (monitor.isCanceled())
- return;
- searchDir(repos, files[i], depth - 1, monitor);
- }
- }
- }
-
- private RepositoryWrapper getRepositoryFromDir(File directory,
Set<RepositoryWrapper> repos, IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return null;
- }
-
- File file = new File(directory, JSF_IMPL);
- if (file.isDirectory()) {
- File[] list = file.listFiles(new FileFilter() {
-
- public boolean accept(File pathname) {
- if (pathname != null && pathname.getName() != null &&
pathname.getName().contains("redhat")) {
- return true;
- }
- return false;
- }
- });
- if (list != null && list.length >= 1) {
- // JBoss EAP Maven Repository
- Repository repository = getDefaultRepository();
- Set<RepositoryWrapper> allRepositories = new
HashSet<RepositoryWrapper>();
- allRepositories.addAll(repos);
- allRepositories.addAll(includedRepositories);
- allRepositories.addAll(availableRepositories);
- repository.setId(getUniqueId(JBOSS_EAP_MAVEN_REPOSITORY_ID, allRepositories));
- repository.setName(JBOSS_EAP_MAVEN_REPOSITORY);
- try {
- repository.setUrl(directory.toURI().toURL().toString());
- } catch (MalformedURLException e) {
- Activator.log(e);
- }
- RepositoryWrapper wrapper = new RepositoryWrapper(repository,
JBOSSTOOLS_MAVEN_PROFILE_ID);
- return wrapper;
- }
- }
- file = new File(directory, WFK_BOMS);
- if (file.isDirectory()) {
- // JBoss WFK Maven Repository
- Repository repository = getDefaultRepository();
- Set<RepositoryWrapper> allRepositories = new
HashSet<RepositoryWrapper>();
- allRepositories.addAll(repos);
- allRepositories.addAll(includedRepositories);
- allRepositories.addAll(availableRepositories);
- repository.setId(getUniqueId(JBOSS_WFK_MAVEN_REPOSITORY_ID, allRepositories));
- repository.setName("JBoss WFK Maven Repository");
- try {
- repository.setUrl(directory.toURI().toURL().toString());
- } catch (MalformedURLException e) {
- Activator.log(e);
- }
- RepositoryWrapper wrapper = new RepositoryWrapper(repository,
JBOSSTOOLS_MAVEN_PROFILE_ID);
- return wrapper;
- }
- return null;
- }
-
- private String getUniqueId(String id, Set<RepositoryWrapper> allRepositories) {
- int i = 0;
- String startId = id;
- while (true) {
- boolean found = false;
- for (RepositoryWrapper wrapper:allRepositories) {
- if (id.equals(wrapper.getRepository().getId())) {
- id = startId + "." + i++; //$NON-NLS-1$
- found = true;
- break;
- }
- }
- if (!found) {
- return id;
- }
- }
- }
-
private String readFile(File file) throws FileNotFoundException {
StringBuilder text = new StringBuilder();
String NL = System.getProperty("line.separator");
@@ -964,8 +773,8 @@
return text.toString();
}
- private String getUserSettings() {
- String userSettings = mavenConfiguration.getUserSettingsFile();
+ public static String getUserSettings() {
+ String userSettings = MavenPlugin.getMavenConfiguration().getUserSettingsFile();
if(userSettings == null || userSettings.length() == 0) {
userSettings = MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath();
}
@@ -973,32 +782,15 @@
}
private void configureButtons() {
- removeAllButton.setEnabled(false);
- removeButton.setEnabled(false);
- for (RepositoryWrapper wrapper:selectedIncludedRepositories) {
- if (JBOSSTOOLS_MAVEN_PROFILE_ID.equals(wrapper.getProfileId())) {
- removeButton.setEnabled(true);
- break;
- }
- }
- for (RepositoryWrapper wrapper:includedRepositories) {
- if (JBOSSTOOLS_MAVEN_PROFILE_ID.equals(wrapper.getProfileId())) {
- removeAllButton.setEnabled(true);
- break;
- }
- }
- addButton.setEnabled(selectedAvailableRepositories.size() > 0);
- addAllButton.setEnabled(availableRepositories.size() > 0);
+ removeAllButton.setEnabled(includedRepositories.size() > 0);
+ removeButton.setEnabled(selectedIncludedRepositories.size() > 0);
}
private void refreshRepositories() {
includedRepositoriesViewer.setInput(includedRepositories.toArray(new
RepositoryWrapper[0]));
- availableRepositoriesViewer.setInput(availableRepositories.toArray(new
RepositoryWrapper[0]));
previewViewer.refresh();
selectedIncludedRepositories.clear();
- selectedAvailableRepositories.clear();
includedRepositoriesViewer.setSelection(new
StructuredSelection(selectedIncludedRepositories.toArray(new RepositoryWrapper[0])));
- availableRepositoriesViewer.setSelection(new
StructuredSelection(selectedAvailableRepositories.toArray(new RepositoryWrapper[0])));
configureButtons();
}
@@ -1023,39 +815,39 @@
Set<RepositoryWrapper> repositories = new TreeSet<RepositoryWrapper>();
Repository repository = getDefaultRepository();
- repository.setId("jboss-public-repository"); //$NON-NLS-1$
+ repository.setId(JBOSS_PUBLIC_REPOSITORY_ID);
repository.setName("JBoss Public"); //$NON-NLS-1$
repository.setUrl("https://repository.jboss.org/nexus/content/groups...;
//$NON-NLS-1$
- repositories.add(new RepositoryWrapper(repository, JBOSSTOOLS_MAVEN_PROFILE_ID));
+ repositories.add(new RepositoryWrapper(repository,
JBOSS_PUBLIC_REPOSITORY_PROFILE_ID));
repository = getDefaultRepository();
- repository.setId("java-net-public"); //$NON-NLS-1$
+ repository.setId(JAVA_NET_PUBLIC_ID);
repository.setName("Java Net Public"); //$NON-NLS-1$
repository.setUrl("https://maven.java.net/content/groups/public/");
//$NON-NLS-1$
- repositories.add(new RepositoryWrapper(repository, JBOSSTOOLS_MAVEN_PROFILE_ID));
+ repositories.add(new RepositoryWrapper(repository, JAVA_NET_PUBLIC_PROFILE_ID));
repository = getDefaultRepository();
- repository.setId("com.springsource.repository.bundles.release");
//$NON-NLS-1$
+ repository.setId(COM_SPRINGSOURCE_REPOSITORY_BUNDLES_RELEASE_ID);
repository.setName("EBR Spring Release"); //$NON-NLS-1$
repository.setUrl("http://repository.springsource.com/maven/bundles/...;
//$NON-NLS-1$
- repositories.add(new RepositoryWrapper(repository, JBOSSTOOLS_MAVEN_PROFILE_ID));
+ repositories.add(new RepositoryWrapper(repository,
COM_SPRINGSOURCE_REPOSITORY_BUNDLES_RELEASE_PROFILE_ID));
repository = getDefaultRepository();
- repository.setId("com.springsource.repository.bundles.external");
//$NON-NLS-1$
+ repository.setId(COM_SPRINGSOURCE_REPOSITORY_BUNDLES_EXTERNAL_ID);
repository.setName("EBR External Release"); //$NON-NLS-1$
repository.setUrl("http://repository.springsource.com/maven/bundles/...;
//$NON-NLS-1$
- repositories.add(new RepositoryWrapper(repository, JBOSSTOOLS_MAVEN_PROFILE_ID));
+ repositories.add(new RepositoryWrapper(repository,
COM_SPRINGSOURCE_REPOSITORY_BUNDLES_EXTERNAL_PROFILE_ID));
repository = getDefaultRepository();
- repository.setId("repository.apache.org"); //$NON-NLS-1$
+ repository.setId(REPOSITORY_APACHE_ORG_ID);
repository.setName("Apache Repository"); //$NON-NLS-1$
repository.setUrl("https://repository.apache.org/content/groups/publ...;
//$NON-NLS-1$
- repositories.add(new RepositoryWrapper(repository, JBOSSTOOLS_MAVEN_PROFILE_ID));
+ repositories.add(new RepositoryWrapper(repository, REPOSITORY_APACHE_ORG_PROFILE_ID));
return repositories;
}
- private Repository getDefaultRepository() {
+ public static Repository getDefaultRepository() {
Repository repository = new Repository();
repository.setLayout(LAYOUT_DEFAULT);
RepositoryPolicy releases = new RepositoryPolicy();
@@ -1068,15 +860,6 @@
repository.setSnapshots(snapshots);
return repository;
}
-
- private Image getJBossImage() {
- if (jbossImage == null) {
- ImageDescriptor desc = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
- "icons/jboss.png"); //$NON-NLS-1$
- jbossImage = desc.createImage();
- }
- return jbossImage;
- }
private List<Profile> getActiveProfiles() throws CoreException {
Settings settings = maven.getSettings();
@@ -1091,49 +874,15 @@
return activeProfiles;
}
- private Button createButton(Composite buttonsComp,
- int maxAddRemoveButtonsWidth, String text) {
+ private Button createButton(Composite parent, String text) {
GridData gd;
- Button button = new Button(buttonsComp, SWT.NONE | SWT.LEFT);
- gd = new GridData();
- gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER;
- gd.widthHint = maxAddRemoveButtonsWidth;
+ Button button = new Button(parent, SWT.NONE | SWT.LEFT);
+ gd = new GridData(GridData.FILL, GridData.FILL, false, false);
button.setLayoutData(gd);
button.setText(text);
return button;
}
-
- private int computeMaxAddRemoveButtonsWidth(GC gc) {
- int maxWidth = 0;
- maxWidth = getGreaterWidth(gc,REMOVE, maxWidth);
- maxWidth = getGreaterWidth(gc,REMOVE_ALL, maxWidth);
- maxWidth = getGreaterWidth(gc,ADD, maxWidth);
- maxWidth = getGreaterWidth(gc,ADD_ALL, maxWidth);
-
- return maxWidth;
- }
-
- private int getGreaterWidth(GC gc, String str, int compareWidth) {
- int greaterWidth = compareWidth;
-
- Point strExtentPoint = gc.stringExtent(str);
- int strWidth = strExtentPoint.x;
- if (strWidth > compareWidth) {
- greaterWidth = strWidth;
- }
-
- return greaterWidth + 5;
- }
-
- @Override
- public void dispose() {
- if (jbossImage != null) {
- jbossImage.dispose();
- }
- super.dispose();
- }
-
class RepositoryLabelProvider extends CellLabelProvider {
public String getToolTipText(Object element) {
@@ -1268,4 +1017,24 @@
return true;
}
+ protected boolean getMessageDialog(Set<RepositoryWrapper> repos) {
+ if (repos.size() == 0) {
+ return false;
+ }
+ StringBuilder builder = new StringBuilder();
+ if (repos.size() == 1) {
+ builder.append("Are you sure you want to delete the '");
+ builder.append(repos.iterator().next().getRepository().getUrl());
+ builder.append("' repository?");
+ } else {
+ builder.append("Are you sure you want to delete the following
repositories:\n\n");
+ for (RepositoryWrapper wrapper:repos) {
+ builder.append(wrapper.getRepository().getUrl());
+ builder.append("\n");
+ }
+ builder.append("\n");
+ }
+ return MessageDialog.openQuestion(getShell(), "Question?",
builder.toString());
+ }
+
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/RepositoryWrapper.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/RepositoryWrapper.java 2012-05-25
15:52:57 UTC (rev 41431)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/RepositoryWrapper.java 2012-05-25
16:07:10 UTC (rev 41432)
@@ -16,9 +16,9 @@
/**
*
* @author snjeza
- *
+ *
*/
-public class RepositoryWrapper implements Comparable<RepositoryWrapper>{
+public class RepositoryWrapper implements Comparable<RepositoryWrapper> {
public static final String SEPARATOR = "/"; //$NON-NLS-1$
private Repository repository;
private String profileId;
@@ -26,7 +26,7 @@
public RepositoryWrapper(Repository repository, String profileId) {
Assert.isNotNull(repository);
- Assert.isNotNull(profileId);
+ // Assert.isNotNull(profileId);
this.repository = repository;
this.profileId = profileId;
url = repository.getUrl();
@@ -38,6 +38,10 @@
}
}
+ public RepositoryWrapper(Repository repository) {
+ this(repository, null);
+ }
+
public Repository getRepository() {
return repository;
}
@@ -53,16 +57,12 @@
public void setProfileId(String profileId) {
this.profileId = profileId;
}
-
- public boolean isJBossRepository() {
- return
ConfigureMavenRepositoriesWizardPage.JBOSSTOOLS_MAVEN_PROFILE_ID.equals(profileId);
- }
public String getDisplayName() {
String name = repository.getName() == null ? "<no-name>" :
repository.getName(); //$NON-NLS-1$
return name + "-" + repository.getUrl(); //$NON-NLS-1$
}
-
+
@Override
public int hashCode() {
final int prime = 31;