Author: dennyxu
Date: 2008-06-26 04:31:49 -0400 (Thu, 26 Jun 2008)
New Revision: 8952
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/project/facet/JBossWSFacetInstallPage.java
Log:
JBIDE-2262: if the user don't configure the facet on the page, do not allow him to add
the facet to the project
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java 2008-06-26
08:19:17 UTC (rev 8951)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java 2008-06-26
08:31:49 UTC (rev 8952)
@@ -11,8 +11,10 @@
package org.jboss.tools.ws.core.classpath;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -20,7 +22,11 @@
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
@@ -131,6 +137,66 @@
return null;
}
+ public List<String> getAllRuntimeJars(JbossWSRuntime rt){
+ List<String> jarList = new ArrayList<String>();
+ if (rt != null) {
+ if (rt.isUserConfigClasspath()) {
+ jarList.addAll(rt.getLibraries());
+
+ } else {
+ IPath wsPath = new Path(rt.getHomeDir());
+ if (wsPath != null) {
+ IPath libPath = wsPath
+ .append(JbossWSCoreMessages.Dir_Lib);
+ List<File> libs = getJarsOfFolder(libPath.toFile());
+ libPath = wsPath
+ .append(JbossWSCoreMessages.Dir_Client);
+ List<File> clientJars = getJarsOfFolder(libPath.toFile());
+
+ jarList = mergeTwoList(libs, clientJars);
+ }
+ }
+
+ }
+ return jarList;
+ }
+
+
+
+ private List<File> getJarsOfFolder(File folder){
+ List<File> jars = new ArrayList<File>();
+ if(folder.isDirectory()){
+ for(File file: folder.listFiles()){
+ if(file.isFile() && (file.getName().endsWith(".jar") ||
file.getName().endsWith(".zip"))){
+ jars.add(file);
+ }else if (folder.isDirectory()){
+ jars.addAll(getJarsOfFolder(file));
+ }
+ }
+ }
+
+ return jars;
+ }
+
+ // if two folders have the same jar file, one of them will be ignored.
+ private List<String> mergeTwoList(List<File> jarList1, List<File>
jarList2){
+ List<String> rtList = new ArrayList<String>();
+ List<String> distinctFileNames = new ArrayList<String>();
+
+ for(File jarFile: jarList1){
+ distinctFileNames.add(jarFile.getName());
+ rtList.add(jarFile.getAbsolutePath());
+ }
+ for(File jarFile: jarList2){
+ if(!distinctFileNames.contains(jarFile.getName())){
+ rtList.add(jarFile.getAbsolutePath());
+ }
+ }
+
+ return rtList;
+
+ }
+
/**
* Remove given JbossWSRuntime from manager
*
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java 2008-06-26
08:19:17 UTC (rev 8951)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/facet/delegate/JBossWSFacetInstallDataModelProvider.java 2008-06-26
08:31:49 UTC (rev 8952)
@@ -12,8 +12,11 @@
import java.util.Set;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.jboss.tools.ws.core.utils.StatusUtils;
public class JBossWSFacetInstallDataModelProvider extends
@@ -58,4 +61,16 @@
public Object create() {
return DataModelFactory.createDataModel(this);
}
+
+
+ @Override
+ public IStatus validate(String name) {
+ boolean serverSupplied = getBooleanProperty(JBOSS_WS_RUNTIME_IS_SERVER_SUPPLIED);
+ String runtimeName = getStringProperty(JBOSS_WS_RUNTIME_ID);
+ if (!serverSupplied
+ && (runtimeName == null || runtimeName.equals(""))) {
+ return StatusUtils.errorStatus("");
+ }
+ return super.validate(name);
+ }
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/project/facet/JBossWSFacetInstallPage.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/project/facet/JBossWSFacetInstallPage.java 2008-06-26
08:19:17 UTC (rev 8951)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/project/facet/JBossWSFacetInstallPage.java 2008-06-26
08:31:49 UTC (rev 8952)
@@ -16,6 +16,13 @@
import java.util.List;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
@@ -29,6 +36,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
+import
org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.frameworks.datamodel.IDataModelListener;
@@ -37,7 +45,9 @@
import org.jboss.tools.ws.core.classpath.JbossWSRuntime;
import org.jboss.tools.ws.core.classpath.JbossWSRuntimeManager;
import org.jboss.tools.ws.core.facet.delegate.IJBossWSFacetDataModelProperties;
+import org.jboss.tools.ws.core.utils.StatusUtils;
import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages;
+import org.jboss.tools.ws.creation.ui.CreationUIPlugin;
import org.jboss.tools.ws.ui.preferences.JbossRuntimeListFieldEditor;
/**
@@ -140,13 +150,27 @@
}
- protected void saveJBosswsRuntimeToModel(JbossWSRuntime jbws){
- model.setStringProperty(
- IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_HOME,
- jbws.getHomeDir());
- model.setStringProperty(
- IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_ID,
- jbws.getName());
+ protected void saveJBosswsRuntimeToModel(JbossWSRuntime jbws) {
+ String duplicateMsg = "";
+ try {
+ duplicateMsg = getDuplicateJars(jbws.getName());
+ } catch (JavaModelException e1) {
+ CreationUIPlugin.getDefault().getLog().log(
+ StatusUtils.errorStatus(e1));
+ }
+ if ("".equals(duplicateMsg)) {
+ model.setStringProperty(
+ IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_HOME,
+ jbws.getHomeDir());
+ model.setStringProperty(
+ IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_ID, jbws
+ .getName());
+ }else{
+ model.setStringProperty(
+ IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_ID, null);
+ model.setStringProperty(
+ IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_HOME, null);
+ }
}
protected void setServerSuppliedSelection(EventObject e) {
@@ -156,7 +180,12 @@
.setBooleanProperty(
IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_IS_SERVER_SUPPLIED,
true);
- enableUserSupplied(false);
+ //remove user supplied properties
+ model.setStringProperty(
+ IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_ID, null);
+ model.setStringProperty(
+ IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_HOME, null);
+ enableUserSupplied(false);
changePageStatus();
}
@@ -170,13 +199,10 @@
false);
String runtimeId = cmbRuntimes.getText();
JbossWSRuntime jbws =
JbossWSRuntimeManager.getInstance().findRuntimeByName(runtimeId);
+
+
if (jbws != null) {
- model.setStringProperty(
- IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_ID, jbws
- .getName());
- model.setStringProperty(
- IJBossWSFacetDataModelProperties.JBOSS_WS_RUNTIME_HOME,
- jbws.getHomeDir());
+ saveJBosswsRuntimeToModel(jbws);
}
enableUserSupplied(true);
changePageStatus();
@@ -234,15 +260,25 @@
}
protected void changePageStatus() {
+
if (btnUserSupplied.getSelection()
&& cmbRuntimes.getSelectionIndex() == -1) {
setErrorMessage(JBossWSCreationCoreMessages.Error_WS_No_Runtime_Specifed);
} else if (!btnUserSupplied.getSelection()
&& !btnServerSupplied.getSelection()) {
setErrorMessage(JBossWSCreationCoreMessages.Error_WS_Chose_runtime);
+ }else if(btnUserSupplied.getSelection()){
+ String duplicateMsg = "";
+ try {
+ duplicateMsg = getDuplicateJars(cmbRuntimes.getText());
+ } catch (JavaModelException e1) {
+ CreationUIPlugin.getDefault().getLog().log(StatusUtils.errorStatus(e1));
+ }
+ setErrorMessage("Duplicated jar on classpath:" + duplicateMsg);
}else{
setErrorMessage(null);
}
+
setPageComplete(isPageComplete());
}
@@ -250,7 +286,7 @@
public boolean isPageComplete() {
if (btnServerSupplied.getSelection()
|| (btnUserSupplied.getSelection() && cmbRuntimes
- .getSelectionIndex() != -1)) {
+ .getSelectionIndex() != -1)) {
return true;
} else {
return false;
@@ -260,5 +296,41 @@
public void propertyChanged(DataModelEvent event) {
}
+
+ protected String getDuplicateJars(String jbwsName) throws JavaModelException{
+ List<String> allExistingJars = new ArrayList<String>();
+ List<String> runtimeJars = new ArrayList<String>();
+ JbossWSRuntime jbws = JbossWSRuntimeManager.getInstance().findRuntimeByName(jbwsName);
+ if(jbws.isUserConfigClasspath()){
+ runtimeJars.addAll(jbws.getLibraries());
+ }else{
+ runtimeJars.addAll(JbossWSRuntimeManager.getInstance().getAllRuntimeJars(jbws));
+ }
+
+ String prjName =
model.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] entries = javaProject.getRawClasspath();
+ for(IClasspathEntry entry: entries){
+ if(entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER){
+ IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
javaProject);
+ for(IClasspathEntry containedEntry: container.getClasspathEntries()){
+ allExistingJars.add(containedEntry.getPath().toOSString());
+ }
+ }else if(entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY){
+ allExistingJars.add(entry.getPath().toOSString());
+ }
+ }
+
+ for(String jarName: runtimeJars){
+ if(allExistingJars.contains(jarName)){
+ return jarName;
+ }
+ }
+
+ return "";
+
+ }
+
}
\ No newline at end of file