Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared library warnings for maven projects #32

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dev/com.ibm.ws.st.jee.ui/icons/obj16/error.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -42,14 +42,15 @@ 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
}

/*
* (non-Javadoc)
*
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
Expand All @@ -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
Expand All @@ -77,7 +78,7 @@ public void stop(BundleContext context) throws Exception {

/**
* Returns the shared instance
*
*
* @return the shared instance
*/
public static Activator getInstance() {
Expand All @@ -86,7 +87,7 @@ public static Activator getInstance() {

/**
* Register an image with the registry.
*
*
* @param key java.lang.String
* @param partialURL java.lang.String
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
* 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;

import java.util.ArrayList;
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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -56,6 +61,10 @@ public class SharedLibSelectionDialog extends Dialog {
protected String id = null;
protected List<String> currentRefIds;

Label messageLabel = null;
Label errorLabel = null;
TreeItem currentlySelectedItem = null;

public SharedLibSelectionDialog(Shell parent, List<String> currentRefIds) {
super(parent);
this.currentRefIds = currentRefIds;
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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("");
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
Loading