From f074139558369e4a1ef9b8614f9813d844e7db6b Mon Sep 17 00:00:00 2001 From: Rajiv Senthilnathan Date: Tue, 3 Oct 2017 16:13:49 -0400 Subject: [PATCH] Shared library warnings for maven projects --- .../icons/obj16/error.gif | Bin 0 -> 339 bytes .../ibm/ws/st/jee/ui/internal/Activator.java | 16 ++-- .../ibm/ws/st/jee/ui/internal/Messages.java | 9 +- .../ws/st/jee/ui/internal/Messages.properties | 7 ++ .../ui/internal/SharedLibPropertiesPage.java | 32 ++++++- .../ui/internal/SharedLibSelectionDialog.java | 86 +++++++++++++++++- ...UtilityProjectSharedLibPropertiesPage.java | 32 ++++++- 7 files changed, 170 insertions(+), 12 deletions(-) create mode 100644 dev/com.ibm.ws.st.jee.ui/icons/obj16/error.gif diff --git a/dev/com.ibm.ws.st.jee.ui/icons/obj16/error.gif b/dev/com.ibm.ws.st.jee.ui/icons/obj16/error.gif new file mode 100644 index 0000000000000000000000000000000000000000..4353e6f3b151ca21202fc19270effc2db4dd8038 GIT binary patch literal 339 zcmZ?wbhEHb6krfwxXQrrHNWUulA0A5Cfs6XTo^dV zMMu0`yjf7VNPs^}g}+Cj#zlxPi*qt3U!jYHs0!EIELI)~HwkWb7Dg7fg&q<@ydu0p Ni@dgMb#i2|1^}AhY3u+1 literal 0 HcmV?d00001 diff --git a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Activator.java b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Activator.java index e406061d..716005e1 100644 --- a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Activator.java +++ b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Activator.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package com.ibm.ws.st.jee.ui.internal; @@ -42,6 +42,7 @@ public class Activator extends AbstractUIPlugin { public static final String IMG_LIBRARY = "library"; public static final String IMG_SERVER = "server"; + public static final String IMG_ERROR = "error"; public Activator() { // do nothing @@ -49,7 +50,7 @@ public Activator() { /* * (non-Javadoc) - * + * * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override @@ -66,7 +67,7 @@ public void start(BundleContext context) throws Exception { /* * (non-Javadoc) - * + * * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override @@ -77,7 +78,7 @@ public void stop(BundleContext context) throws Exception { /** * Returns the shared instance - * + * * @return the shared instance */ public static Activator getInstance() { @@ -86,7 +87,7 @@ public static Activator getInstance() { /** * Register an image with the registry. - * + * * @param key java.lang.String * @param partialURL java.lang.String */ @@ -109,13 +110,14 @@ protected ImageRegistry createImageRegistry() { registerImage(registry, IMG_LIBRARY, URL_OBJ + "library.gif"); registerImage(registry, IMG_SERVER, URL_OBJ + "server.gif"); + registerImage(registry, IMG_ERROR, URL_OBJ + "error.gif"); return registry; } /** * Return the image with the given key from the image registry. - * + * * @param key * @return Image */ @@ -125,7 +127,7 @@ public static Image getImage(String key) { /** * Return the image with the given key from the image registry. - * + * * @param key * @return ImageDescriptor */ diff --git a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.java b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.java index 7d9969ff..34241f61 100644 --- a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.java +++ b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package com.ibm.ws.st.jee.ui.internal; @@ -19,6 +19,7 @@ public class Messages extends NLS { public static String browse; public static String remove; public static String add; + public static String sharedLibGeneralDescription; public static String sharedLibDescription; public static String sharedLibId; public static String sharedLibDirectory; @@ -40,6 +41,12 @@ public class Messages extends NLS { public static String sharedLibAPIVisibilitySpec; public static String sharedLibAPIVisibilityThirdParty; + public static String sharedLibWarning; + + // Maven + public static String sharedLibMavenDescription; + public static String sharedLibMavenServer; + static { NLS.initializeMessages(Activator.PLUGIN_ID + ".internal.Messages", Messages.class); } diff --git a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.properties b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.properties index d6bf0d3b..a7d1e079 100644 --- a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.properties +++ b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/Messages.properties @@ -24,6 +24,7 @@ browse=&Browse... add=&Add... remove=&Remove +sharedLibGeneralDescription=Shared libraries are files used by multiple applications. You can use shared libraries and global libraries to reduce the number of duplicate library files on your system.\n sharedLibDescription=Specify the shared library settings for this utility project. sharedLibId=Shared library &ID: sharedLibDirectory=A&rchive directory: @@ -40,9 +41,15 @@ sharedLibAPIVisibilityIBMAPI=IB&M API sharedLibAPIVisibilitySpec=&Spec sharedLibAPIVisibilityThirdParty=&Third party +sharedLibWarning=Additional user action may be required. See description below for details. + sharedLibReferences=Specify the shared library &IDs that the project uses: sharedLibConfirmRemoveTitle=Remove Shared Library sharedLibConfirmRemoveMessage=The {0} utility project is published on one or more servers. By setting the value of the shared library ID to an empty string, the utility project is no longer considered a shared library and will be removed from the affected servers.\n\nAre you sure that you want to continue? sharedLibServerUpdateFailedTitle=Server Configuration Update Failed sharedLibServerUpdateFailedMessage=The server configuration could not be updated for one or more servers. Check the workspace logs for more details. + +#Maven specific messages +sharedLibMavenDescription=This dialog configures this project to reference shared libraries and modifies server configuration files when the application is published. If the server is based on configuration files located in Maven output folders the shared library configuration may be lost after subsequent Maven goals are executed. To prevent loss of configuration copy the shared library configuration to server configuration files in Maven source folders.\n +sharedLibMavenServer=The selected library reference is from a server located in a Maven output directory that can be removed. It is recommended to configure shared libraries in the server configuration files in source locations to prevent loss of configuration. diff --git a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibPropertiesPage.java b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibPropertiesPage.java index b32032d5..db93fc27 100644 --- a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibPropertiesPage.java +++ b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibPropertiesPage.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package com.ibm.ws.st.jee.ui.internal; @@ -14,9 +14,11 @@ import java.util.EnumSet; import java.util.List; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -167,6 +169,34 @@ public void widgetSelected(SelectionEvent selectionEvent) { return composite; } + @Override + protected Label createDescriptionLabel(Composite parent) { + + String descriptionMsg = getDescriptionMsg(); + + Label descriptionLabel = new Label(parent, SWT.WRAP); + descriptionLabel.setText(descriptionMsg); + return descriptionLabel; + } + + private String getDescriptionMsg() { + IAdaptable element = getElement(); + project = element.getAdapter(IProject.class); + + // Maven projects might be targeted to a runtime in a target folder. If that's the case the shared lib + // configuration could be lost upon a maven clean. Therefore, warn the user so that they're aware and suggest + // they copy their configuration to server config files in src folders so that they're preserved even after a maven clean. + if (project != null) { + IFile pom = project.getFile("pom.xml"); + if (pom != null && pom.exists()) { + setMessage(Messages.sharedLibWarning, IMessageProvider.WARNING); + return Messages.sharedLibMavenDescription; + } + } + + return Messages.sharedLibGeneralDescription; + } + protected void loadSettings() { IAdaptable element = getElement(); project = element.getAdapter(IProject.class); diff --git a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibSelectionDialog.java b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibSelectionDialog.java index 64f9f2c4..881d4e03 100644 --- a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibSelectionDialog.java +++ b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/SharedLibSelectionDialog.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package com.ibm.ws.st.jee.ui.internal; @@ -17,6 +17,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.PopupDialog; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; @@ -29,10 +30,12 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; @@ -41,6 +44,8 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; +import com.ibm.ws.st.core.internal.Constants; +import com.ibm.ws.st.core.internal.WebSphereServer; import com.ibm.ws.st.core.internal.WebSphereServerInfo; import com.ibm.ws.st.core.internal.WebSphereUtil; import com.ibm.ws.st.core.internal.config.ConfigUtils; @@ -56,6 +61,10 @@ public class SharedLibSelectionDialog extends Dialog { protected String id = null; protected List currentRefIds; + Label messageLabel = null; + Label errorLabel = null; + TreeItem currentlySelectedItem = null; + public SharedLibSelectionDialog(Shell parent, List currentRefIds) { super(parent); this.currentRefIds = currentRefIds; @@ -82,7 +91,7 @@ protected Control createDialogArea(Composite parent) { layout.verticalSpacing = 7; layout.numColumns = 2; composite.setLayout(layout); - GridData data = new GridData(GridData.FILL_BOTH); + GridData data = new GridData(GridData.FILL, GridData.FILL, true, true); data.minimumWidth = 300; composite.setLayoutData(data); composite.setFont(parent.getFont()); @@ -160,6 +169,7 @@ public void widgetDisposed(DisposeEvent event) { serverItem.setText(NLS.bind(Messages.sharedLibServer, ws.getServerName())); serverItem.setImage(Activator.getImage(Activator.IMG_SERVER)); serverItem.setForeground(gray); + serverItem.setData(ws); ConfigurationFile configFile = ws.getConfigRoot(); String[] ids = ConfigUtils.getSharedLibraryIds(configFile); @@ -188,6 +198,8 @@ public void widgetSelected(SelectionEvent event) { if (items == null || items.length != 1) return; + currentlySelectedItem = items[0]; + Object obj = items[0].getData(); if (obj == null || !(obj instanceof String)) { idText.setText(""); @@ -208,6 +220,32 @@ public void mouseDoubleClick(MouseEvent event) { } }); + // Validation message composite + Composite messageComposite = new Composite(parent, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + messageComposite.setLayout(layout); + + data = new GridData(GridData.FILL_BOTH); + messageComposite.setLayoutData(data); + + Image errorIcon = Activator.getImage(Activator.IMG_ERROR); + errorLabel = new Label(messageComposite, SWT.NONE); + errorLabel.setImage(errorIcon); + errorLabel.setVisible(false); + data = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false); + errorLabel.setLayoutData(data); + + messageLabel = new Label(messageComposite, SWT.WRAP); + messageLabel.setText(""); + messageLabel.setVisible(false); + data = new GridData(GridData.FILL, GridData.FILL, true, true); + data.widthHint = 500; + data.grabExcessVerticalSpace = true; + data.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING; + data.verticalIndent = PopupDialog.POPUP_VERTICALSPACING; + messageLabel.setLayoutData(data); + return composite; } @@ -223,9 +261,53 @@ protected void validate() { boolean ok = false; if (id != null && !id.trim().isEmpty()) ok = !currentRefIds.contains(id); + + String validationMsg = ""; + if (ok) { + validationMsg = validateServer(); + ok = validationMsg.isEmpty(); + } + handleValidationMessages(validationMsg); getButton(IDialogConstants.OK_ID).setEnabled(ok); } + private String validateServer() { + if (currentlySelectedItem != null) { + TreeItem parent = currentlySelectedItem.getParentItem(); + if (parent != null) { + WebSphereServerInfo wsInfo = (WebSphereServerInfo) parent.getData(); + if (wsInfo != null) { + WebSphereServer wsServer = WebSphereUtil.getWebSphereServer(wsInfo); + /* + * Maven type servers are currently created in target folders by default so we will block them + * and ask the user to manually configure their server using the config files in the src folders + */ + if (wsServer != null && Constants.SERVER_TYPE_LIBERTY_MAVEN.equals(wsServer.getServerType())) + return Messages.sharedLibMavenServer; + + } + } + } + return ""; + } + + private void handleValidationMessages(final String msg) { + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if (messageLabel != null) { + errorLabel.setVisible(!msg.isEmpty()); + messageLabel.setText(msg); + messageLabel.setVisible(!msg.isEmpty()); + Point location = messageLabel.getShell().getLocation(); // preserve location + messageLabel.getShell().pack(); + messageLabel.getShell().setLocation(location); + } + } + }); + } + public String getId() { return id; } diff --git a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/UtilityProjectSharedLibPropertiesPage.java b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/UtilityProjectSharedLibPropertiesPage.java index 3a6c54a1..c6629a67 100644 --- a/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/UtilityProjectSharedLibPropertiesPage.java +++ b/dev/com.ibm.ws.st.jee.ui/src/com/ibm/ws/st/jee/ui/internal/UtilityProjectSharedLibPropertiesPage.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package com.ibm.ws.st.jee.ui.internal; @@ -15,6 +15,7 @@ import java.util.List; import java.util.Properties; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -23,6 +24,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; @@ -376,4 +378,32 @@ static void publish(List servers) { s.setServerPublishState(IServer.PUBLISH_STATE_INCREMENTAL); } } + + @Override + protected Label createDescriptionLabel(Composite parent) { + + String descriptionMsg = getDescriptionMsg(); + + Label descriptionLabel = new Label(parent, SWT.WRAP); + descriptionLabel.setText(descriptionMsg); + return descriptionLabel; + } + + private String getDescriptionMsg() { + IAdaptable element = getElement(); + project = element.getAdapter(IProject.class); + + // Maven projects might be targeted to a runtime in a target folder. If that's the case the shared lib + // configuration could be lost upon a maven clean. Therefore, warn the user so that they're aware and suggest + // they copy their configuration to server config files in src folders so that they're preserved even after a maven clean. + if (project != null) { + IFile pom = project.getFile("pom.xml"); + if (pom != null && pom.exists()) { + setMessage(Messages.sharedLibWarning, IMessageProvider.WARNING); + return Messages.sharedLibMavenDescription; + } + } + + return Messages.sharedLibGeneralDescription; + } }