Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 242635
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-3 / +2 lines)
Lines 40-46 Link Here
40
 org.eclipse.wst.command.env.core;bundle-version="[1.0.101,1.1.0)",
40
 org.eclipse.wst.command.env.core;bundle-version="[1.0.101,1.1.0)",
41
 org.eclipse.wst.command.env;bundle-version="[1.0.101,1.1.0)",
41
 org.eclipse.wst.command.env;bundle-version="[1.0.101,1.1.0)",
42
 org.eclipse.jem.workbench;bundle-version="[2.0.0,3.0.0)",
42
 org.eclipse.jem.workbench;bundle-version="[2.0.0,3.0.0)",
43
 org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
44
 org.eclipse.wst.ws;bundle-version="[1.0.100,1.2.0)",
43
 org.eclipse.wst.ws;bundle-version="[1.0.100,1.2.0)",
45
 org.eclipse.wst.ws.parser;bundle-version="[1.0.100,1.1.0)",
44
 org.eclipse.wst.ws.parser;bundle-version="[1.0.100,1.1.0)",
46
 org.eclipse.wst.server.core;bundle-version="[1.0.102,2.0.0)",
45
 org.eclipse.wst.server.core;bundle-version="[1.0.102,2.0.0)",
Lines 56-63 Link Here
56
 org.eclipse.wst.common.environment;bundle-version="[1.0.100,1.1.0)",
55
 org.eclipse.wst.common.environment;bundle-version="[1.0.100,1.1.0)",
57
 org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)",
56
 org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)",
58
 org.eclipse.jst.server.core;bundle-version="[1.0.102,2.0.0)",
57
 org.eclipse.jst.server.core;bundle-version="[1.0.102,2.0.0)",
59
 org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
58
 org.eclipse.emf.codegen;bundle-version="[2.2.0,3.0.0)",
60
 org.eclipse.emf.codegen;bundle-version="[2.2.0,3.0.0)"
59
 org.eclipse.core.commands;bundle-version="[3.5.0,3.6.0)"
61
Eclipse-LazyStart: true
60
Eclipse-LazyStart: true
62
Bundle-RequiredExecutionEnvironment: J2SE-1.4
61
Bundle-RequiredExecutionEnvironment: J2SE-1.4
63
Bundle-ActivationPolicy: lazy
62
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/jst/ws/internal/consumption/common/FacetUtils.java (-159 / +64 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-25 Link Here
15
 * 20080325   222473 makandre@ca.ibm.com - Andrew Mak, Create EAR version based on the version of modules to be added
15
 * 20080325   222473 makandre@ca.ibm.com - Andrew Mak, Create EAR version based on the version of modules to be added
16
 * 20080429   213730 trungha@ca.ibm.com - Trung Ha
16
 * 20080429   213730 trungha@ca.ibm.com - Trung Ha
17
 * 20080507   229532 kathy@ca.ibm.com - Kathy Chan
17
 * 20080507   229532 kathy@ca.ibm.com - Kathy Chan
18
 * 20090303   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
18
 *******************************************************************************/
19
 *******************************************************************************/
19
20
20
package org.eclipse.jst.ws.internal.consumption.common;
21
package org.eclipse.jst.ws.internal.consumption.common;
21
22
22
import java.lang.reflect.InvocationTargetException;
23
import java.util.ArrayList;
23
import java.util.ArrayList;
24
import java.util.Collections;
24
import java.util.Collections;
25
import java.util.HashSet;
25
import java.util.HashSet;
Lines 30-35 Link Here
30
import org.eclipse.core.resources.IProject;
30
import org.eclipse.core.resources.IProject;
31
import org.eclipse.core.resources.ResourcesPlugin;
31
import org.eclipse.core.resources.ResourcesPlugin;
32
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.IConfigurationElement;
34
import org.eclipse.core.runtime.IExtension;
35
import org.eclipse.core.runtime.IExtensionPoint;
36
import org.eclipse.core.runtime.IExtensionRegistry;
33
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
38
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.Platform;
39
import org.eclipse.core.runtime.Platform;
Lines 37-43 Link Here
37
import org.eclipse.jdt.core.IJavaProject;
41
import org.eclipse.jdt.core.IJavaProject;
38
import org.eclipse.jdt.core.JavaCore;
42
import org.eclipse.jdt.core.JavaCore;
39
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
43
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
40
import org.eclipse.jface.operation.IRunnableWithProgress;
41
import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil;
44
import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil;
42
import org.eclipse.jst.j2ee.internal.ejb.project.operations.EjbFacetInstallDataModelProvider;
45
import org.eclipse.jst.j2ee.internal.ejb.project.operations.EjbFacetInstallDataModelProvider;
43
import org.eclipse.jst.j2ee.internal.ejb.project.operations.IEjbFacetInstallDataModelProperties;
46
import org.eclipse.jst.j2ee.internal.ejb.project.operations.IEjbFacetInstallDataModelProperties;
Lines 54-61 Link Here
54
import org.eclipse.jst.ws.internal.common.ResourceUtils;
57
import org.eclipse.jst.ws.internal.common.ResourceUtils;
55
import org.eclipse.jst.ws.internal.consumption.ConsumptionMessages;
58
import org.eclipse.jst.ws.internal.consumption.ConsumptionMessages;
56
import org.eclipse.osgi.util.NLS;
59
import org.eclipse.osgi.util.NLS;
57
import org.eclipse.swt.widgets.Display;
58
import org.eclipse.ui.PlatformUI;
59
import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
60
import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
60
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
61
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
61
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
62
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
Lines 70-76 Link Here
70
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action.Type;
71
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action.Type;
71
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
72
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
72
import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
73
import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
73
import org.osgi.framework.Bundle;
74
74
75
import com.ibm.icu.util.StringTokenizer;
75
import com.ibm.icu.util.StringTokenizer;
76
76
Lines 92-97 Link Here
92
public class FacetUtils
92
public class FacetUtils
93
{
93
{
94
94
95
  private static IFacetOperationDelegate delegate; //if a delegate is plugged in, delegate some operations to it
96
  private static boolean failedToLoadDelegate = false;
95
  /**
97
  /**
96
   * Returns an array of valid projects. Valid projects include projects with the facets nature or
98
   * Returns an array of valid projects. Valid projects include projects with the facets nature or
97
   * projects with the Java nature.
99
   * projects with the Java nature.
Lines 768-801 Link Here
768
    status[0] = Status.OK_STATUS;
770
    status[0] = Status.OK_STATUS;
769
    final Set actions = getInstallActions(projectFacetVersions);
771
    final Set actions = getInstallActions(projectFacetVersions);
770
    
772
    
771
    // Create a runnable that applies the install actions to the faceted project
773
    if (isExtensionPresent())
772
    IRunnableWithProgress runnable = new IRunnableWithProgress()
774
    {    
773
    {
775
    	status[0] = delegate.addFacetsToProject(fproject, projectFacetVersions);
774
      public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
775
      {
776
        try
777
        {
778
          fproject.modify(actions, shellMonitor);
779
        } catch (CoreException e)
780
        {
781
          status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, e);
782
        }
783
      }
784
    };    
785
        
786
    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)    
787
    if (displayPresent())
788
    {    	
789
	    try
790
	    {
791
	      PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
792
	    } catch (InvocationTargetException ite)
793
	    {
794
	      status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ite);
795
	    } catch (InterruptedException ie)
796
	    {
797
	      status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ie);
798
	    }
799
	}
776
	}
800
	else
777
	else
801
	{
778
	{
Lines 857-913 Link Here
857
    final IStatus[] status = new IStatus[1];
834
    final IStatus[] status = new IStatus[1];
858
    status[0] = Status.OK_STATUS;
835
    status[0] = Status.OK_STATUS;
859
    IProject project = ProjectUtilities.getProject(projectName);
836
    IProject project = ProjectUtilities.getProject(projectName);
837
    
860
    if (!project.exists())
838
    if (!project.exists())
861
    {
839
    {
862
      // Create a runnable that creates a new faceted project.
840
		if (isExtensionPresent())
863
      IRunnableWithProgress runnable = new IRunnableWithProgress()
841
		{
864
      {
842
		  status[0] = delegate.createNewFacetedProject(projectName);
865
        public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
843
	  	}
866
        {
844
	  	else
867
          try
845
	  	{
868
          {
846
  		  try
869
            IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, shellMonitor);
847
  		  {
870
            if (fProject == null)
848
              IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, null);
871
            {
849
              if (fProject == null)
872
              status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
873
            }
874
          } catch (CoreException e)
875
          {
876
            status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
877
          }
878
        }
879
      };
880
881
    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)    	  
882
      try
883
      {
884
    	  if (displayPresent())
885
    	  {
886
    		  PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);    		  
887
    	  }
888
    	  else
889
    	  {
890
    		  try
891
              {
892
                IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, null);
893
                if (fProject == null)
894
                {
895
                  status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
896
                }
897
              } catch (CoreException e)
898
              {
850
              {
899
                status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
851
                status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
900
              }  
852
              }
901
    	  }        
853
  		  } 
902
      } catch (InvocationTargetException ite)
854
  		  catch (CoreException e)
903
      {
855
  		  {
904
        status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ite);
856
              status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
905
      } catch (InterruptedException ie)
857
  		  }  
906
      {
858
	  	}        
907
        status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ie);
908
      }
909
    }
859
    }
910
911
    return status[0];
860
    return status[0];
912
  }
861
  }
913
  
862
  
Lines 927-960 Link Here
927
    final IStatus[] status = new IStatus[1];
876
    final IStatus[] status = new IStatus[1];
928
    status[0] = Status.OK_STATUS;
877
    status[0] = Status.OK_STATUS;
929
878
930
    //Create a runnable that sets the fixed facets on the faceted project
879
    if (isExtensionPresent())
931
    IRunnableWithProgress runnable = new IRunnableWithProgress()
932
    {
880
    {
933
      public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
881
    	status[0] = delegate.setFixedFacetsOnProject(fProject, fixedFacets);
934
      {
935
        try
936
        {
937
          fProject.setFixedProjectFacets(fixedFacets);
938
        } catch (CoreException e)
939
        {
940
          status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, e);
941
        }
942
      }
943
    };
944
945
    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)
946
    if (displayPresent())
947
    {
948
    	try
949
        {
950
          PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
951
        } catch (InvocationTargetException ite)
952
        {
953
          status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ite);
954
        } catch (InterruptedException ie)
955
        {
956
          status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ie);
957
        }	
958
    }
882
    }
959
    else
883
    else
960
    {
884
    {
Lines 1008-1041 Link Here
1008
    final IStatus[] status = new IStatus[1];
932
    final IStatus[] status = new IStatus[1];
1009
    status[0] = Status.OK_STATUS;
933
    status[0] = Status.OK_STATUS;
1010
934
1011
    //Create a runnable that sets the facet runtime on the faceted project
935
    if (isExtensionPresent())
1012
    IRunnableWithProgress runnable = new IRunnableWithProgress()
1013
    {
1014
      public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException
1015
      {
1016
        try
1017
        {
1018
        	fProject.setTargetedRuntimes(Collections.singleton(fRuntime), shellMonitor);
1019
        } catch (CoreException e)
1020
        {
1021
          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
1022
        }
1023
      }
1024
    };
1025
1026
    // Run the runnable in another thread unless there is no UI thread (Ant scenarios)
1027
    if (displayPresent())
1028
    {
936
    {
1029
    	try
937
    	status[0] = delegate.setFacetRuntimeOnProject(fProject, fRuntime);
1030
        {
1031
          PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
1032
        } catch (InvocationTargetException ite)
1033
        {
1034
          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ite);
1035
        } catch (InterruptedException ie)
1036
        {
1037
          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ie);
1038
        }	
1039
    }
938
    }
1040
    else 
939
    else 
1041
    {
940
    {
Lines 1046-1054 Link Here
1046
        {
945
        {
1047
          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
946
          status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
1048
        }
947
        }
1049
    }
948
    }    
1050
        
1051
    
1052
    return status[0];
949
    return status[0];
1053
  }
950
  }
1054
  
951
  
Lines 1471-1496 Link Here
1471
  		return rfv;
1368
  		return rfv;
1472
  	}
1369
  	}
1473
	
1370
	
1474
	// Check to see if SWT is active and the Display is present or not
1371
	private static boolean isExtensionPresent() {
1475
	private static boolean displayPresent() {
1372
		
1476
		Bundle b = Platform.getBundle("org.eclipse.swt");
1373
		if (failedToLoadDelegate) {
1477
	    if (b==null) {
1374
			return false;
1478
	    	return false;
1375
		} if (delegate != null) {
1479
	    }
1376
			return true;
1480
	    if ((b.getState() != Bundle.RESOLVED && b.getState() != Bundle.ACTIVE) ) {
1377
		}
1481
	    	return false;
1378
		IExtensionRegistry registry = Platform.getExtensionRegistry();  
1482
	    }
1379
		IExtensionPoint point = registry.getExtensionPoint("org.eclipse.jst.ws.consumption.internalFacetOperationDelegate");
1483
	    try {
1380
		if (point == null) {
1484
	    	if (Display.getCurrent() == null) {
1381
			failedToLoadDelegate = true;
1485
	    		return false;
1382
			return false;
1486
	    	} else {
1383
		}
1487
	    		return true;
1384
		IExtension[] extensions = point.getExtensions();
1488
	    	}
1385
1489
	    } catch (NoClassDefFoundError e1) {
1386
		//this extension point is internal, we know there will only be zero or one plugged in
1490
	    	return false;
1387
		if (extensions.length > 0 && extensions[0] != null) {
1491
	    } catch (Exception e) {  // if the Display class cannot be loaded for whatever reason
1388
			IConfigurationElement[] elements = extensions[0].getConfigurationElements();
1492
	    	return false;
1389
			if (elements.length > 0 && elements[0] != null) {
1493
	    
1390
				try {
1494
	    } 
1391
					delegate = (IFacetOperationDelegate)elements[0].createExecutableExtension("class");
1392
					return true;
1393
				} catch (CoreException e) {
1394
					//do nothing, just report that we failed to load the extension
1395
				}
1396
			}
1397
		}
1398
		failedToLoadDelegate = true;//set this so we don't try to load it again
1399
		return false;
1495
	}
1400
	}
1496
}
1401
}
(-)plugin.properties (-2 / +6 lines)
Lines 1-12 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2005 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
7
#
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
# IBM Corporation - initial API and implementation
10
# yyyymmdd bug      Email and other contact information
11
# -------- -------- -----------------------------------------------------------
12
# 20090302   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
10
###############################################################################
13
###############################################################################
11
14
12
#
15
#
Lines 17-19 Link Here
17
XP_WSFINDER=org.eclipse.jst.ws.internal.consumption.wsfinder
20
XP_WSFINDER=org.eclipse.jst.ws.internal.consumption.wsfinder
18
XP_WEB_SERVICE_START_SERVER_TYPE=WebServiceStartServerType
21
XP_WEB_SERVICE_START_SERVER_TYPE=WebServiceStartServerType
19
XP_SERVER_DEFAULTER=Server Defaulter
22
XP_SERVER_DEFAULTER=Server Defaulter
23
XP_FACET_OP_DELEGATE=Facet Operation Delegate
(-)plugin.xml (+5 lines)
Lines 17-22 Link Here
17
   <extension-point
17
   <extension-point
18
      id="serverDefaulter"
18
      id="serverDefaulter"
19
      name="%XP_SERVER_DEFAULTER"/>
19
      name="%XP_SERVER_DEFAULTER"/>
20
      
21
   <!-- The following extension point is internal and likely to be removed in a future release. -->
22
   <extension-point id="internalFacetOperationDelegate"
23
   		name="%XP_FACET_OP_DELEGATE"
24
   		schema="schema/facetOperationDelegate.exsd"/>
20
25
21
   
26
   
22
   <extension
27
   <extension
(-)schema/facetOperationDelegate.exsd (+80 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.jst.ws.consumption" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.eclipse.jst.ws.consumption" id="internalFacetOperationDelegate" name="Facet Operation Delegate"/>
7
      </appinfo>
8
      <documentation>
9
         &lt;b&gt;Internal Extension Point:&lt;/b&gt; This internal extension point allows an IFacetOperationDelegate to be plugged in that is delegated some facet operations. &lt;b&gt;Do not use this extension point.&lt;/b&gt;
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element internal="true" />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="FacetOperationDelegate"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="FacetOperationDelegate">
51
      <annotation>
52
         <documentation>
53
            This element specifies the FacetOperationDelegate
54
         </documentation>
55
      </annotation>
56
      <complexType>
57
         <attribute name="class" type="string" use="required">
58
            <annotation>
59
               <documentation>
60
                  Class that provides the implementation of IFacetOperationDelegate
61
               </documentation>
62
            </annotation>
63
         </attribute>
64
      </complexType>
65
   </element>
66
67
   <annotation>
68
      <appinfo>
69
         <meta.section type="since"/>
70
      </appinfo>
71
      <documentation>
72
         WTP 3.1
73
      </documentation>
74
   </annotation>
75
76
77
78
79
80
</schema>
(-)src/org/eclipse/jst/ws/internal/consumption/common/IFacetOperationDelegate.java (+72 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 * yyyymmdd bug      Email and other contact information
11
 * -------- -------- -----------------------------------------------------------
12
 * 20090303   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
13
 *******************************************************************************/
14
package org.eclipse.jst.ws.internal.consumption.common;
15
16
import java.util.Set;
17
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
20
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
21
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
22
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
23
24
public interface IFacetOperationDelegate {
25
26
	/**
27
	  * Adds the provided set of facet versions to the provided faceted project
28
	  * 
29
	  * @param fproject A faceted project which exists in the workspace
30
	  * @param projectFacetVersions A set containing elements of type {@link IProjectFacetVersion}
31
	  * @return An IStatus with a severity of IStatus.OK if the facet 
32
	  * versions were added successfully. Otherwise, an IStatus with a severity of
33
	  * IStatus.ERROR. 
34
	  */
35
	 public IStatus addFacetsToProject(final IFacetedProject fproject, final Set projectFacetVersions);
36
	 
37
	 /**
38
	   * Creates a new faceted project with the provided name
39
	   * 
40
	   * @param projectName A String containing the name of the project to be created
41
	   * @return An IStatus with a severity of IStatus.OK if the faceted project
42
	   * was created successfully or if a project of the provided name already
43
	   * exists in the workspace. Otherwise, an IStatus with severity of
44
	   * IStatus.ERROR. 
45
	   */
46
	  public IStatus createNewFacetedProject(final String projectName);
47
	  
48
	  /**
49
	   * Sets the provided set of facets as fixed on the faceted project
50
	   * 
51
	   * @param fProject A faceted project which exists in the workspace
52
	   * @param fixedFacets A set containing elements of type {@link IProjectFacet}
53
	   * @return An IStatus with a severity of IStatus.OK if the facets 
54
	   * were successfully set as fixed facets on the faceted project. 
55
	   * Otherwise, an IStatus with a severity of IStatus.ERROR.
56
	   * 
57
	   * @see IFacetedProject#setFixedProjectFacets
58
	   */
59
	  public IStatus setFixedFacetsOnProject(final IFacetedProject fProject, final Set fixedFacets);
60
	  
61
	  /**
62
	   * Binds the faceted project to the facet runtime
63
	   * 
64
	   * @param fProject A faceted project which exists in the workspace
65
	   * @param fRuntime A facet runtime
66
	   * @return An IStatus with a severity of IStatus.OK if the faceted project
67
	   * was bound to the facet runtime successfully. Otherwise, an IStatus with severity of
68
	   * IStatus.ERROR. 
69
	   */
70
	  public IStatus setFacetRuntimeOnProject(final IFacetedProject fProject, final IRuntime fRuntime);
71
	
72
}
(-)plugin.xml (-1 / +6 lines)
Lines 759-763 Link Here
759
              property="ListServers"
759
              property="ListServers"
760
              transform="org.eclipse.wst.command.internal.env.ant.String2BooleanTransformer"
760
              transform="org.eclipse.wst.command.internal.env.ant.String2BooleanTransformer"
761
              />  	
761
              />  	
762
      </extension> 
762
      </extension>
763
      
764
     <extension
765
           point="org.eclipse.jst.ws.consumption.internalFacetOperationDelegate">
766
  			<FacetOperationDelegate class="org.eclipse.jst.ws.internal.consumption.ui.common.FacetOperationDelegate" />
767
     </extension> 
763
</plugin>
768
</plugin>
(-)src/org/eclipse/jst/ws/internal/consumption/ui/common/FacetOperationDelegate.java (+307 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 * yyyymmdd bug      Email and other contact information
11
 * -------- -------- -----------------------------------------------------------
12
 * 20090303   242635 mahutch@ca.ibm.com - Mark Hutchinson, Remove unnecessary UI dependencies from org.eclipse.jst.ws.consumption
13
 *******************************************************************************/
14
package org.eclipse.jst.ws.internal.consumption.ui.common;
15
16
import java.lang.reflect.InvocationTargetException;
17
import java.util.Collections;
18
import java.util.HashSet;
19
import java.util.Iterator;
20
import java.util.Set;
21
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.core.runtime.Status;
28
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
29
import org.eclipse.jface.operation.IRunnableWithProgress;
30
import org.eclipse.jst.ws.internal.consumption.ConsumptionMessages;
31
import org.eclipse.jst.ws.internal.consumption.common.FacetUtils;
32
import org.eclipse.jst.ws.internal.consumption.common.IFacetOperationDelegate;
33
import org.eclipse.osgi.util.NLS;
34
import org.eclipse.swt.widgets.Display;
35
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
37
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
38
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
39
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
40
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
41
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
42
import org.osgi.framework.Bundle;
43
44
public class FacetOperationDelegate implements IFacetOperationDelegate {
45
46
	public IStatus addFacetsToProject(final IFacetedProject fproject, final Set projectFacetVersions) {
47
		final IStatus[] status = new IStatus[1];
48
		status[0] = Status.OK_STATUS;
49
		final Set actions = FacetUtils.getInstallActions(projectFacetVersions);
50
51
		// Create a runnable that applies the install actions to the faceted project
52
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
53
			public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
54
				try {
55
					fproject.modify(actions, shellMonitor);
56
				} catch (CoreException e) {
57
					status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, e);
58
				}
59
			}
60
		};
61
62
		// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
63
		if (displayPresent()) {
64
			try {
65
				PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
66
			} catch (InvocationTargetException ite) {
67
				status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ite);
68
			} catch (InterruptedException ie) {
69
				status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, ie);
70
			}
71
		} else {
72
			try {
73
				fproject.modify(actions, null);
74
			} catch (CoreException e) {
75
				status[0] = getErrorStatusForAddingFacets(fproject.getProject().getName(), projectFacetVersions, e);
76
			}
77
		}
78
79
		return status[0];
80
	}
81
82
	public IStatus createNewFacetedProject(final String projectName) {
83
		final IStatus[] status = new IStatus[1];
84
		status[0] = Status.OK_STATUS;
85
		IProject project = ProjectUtilities.getProject(projectName);
86
		if (!project.exists()) {
87
			// Create a runnable that creates a new faceted project.
88
			IRunnableWithProgress runnable = new IRunnableWithProgress() {
89
				public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
90
					try {
91
						IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, shellMonitor);
92
						if (fProject == null) {
93
							status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
94
						}
95
					} catch (CoreException e) {
96
						status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
97
					}
98
				}
99
			};
100
101
			// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
102
			try {
103
				if (displayPresent()) {
104
					PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
105
				} else {
106
					try {
107
						IFacetedProject fProject = ProjectFacetsManager.create(projectName, null, null);
108
						if (fProject == null) {
109
							status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }));
110
						}
111
					} catch (CoreException e) {
112
						status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), e);
113
					}
114
				}
115
			} catch (InvocationTargetException ite) {
116
				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ite);
117
			} catch (InterruptedException ie) {
118
				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_PROJECT_CREATION, new String[] { projectName }), ie);
119
			}
120
		}
121
122
		return status[0];
123
	}
124
125
	public IStatus setFacetRuntimeOnProject(final IFacetedProject fProject, final IRuntime fRuntime) {
126
		final IStatus[] status = new IStatus[1];
127
		status[0] = Status.OK_STATUS;
128
129
		// Create a runnable that sets the facet runtime on the faceted project
130
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
131
			public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
132
				try {
133
					fProject.setTargetedRuntimes(Collections.singleton(fRuntime), shellMonitor);
134
				} catch (CoreException e) {
135
					status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
136
				}
137
			}
138
		};
139
140
		// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
141
		if (displayPresent()) {
142
			try {
143
				PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
144
			} catch (InvocationTargetException ite) {
145
				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ite);
146
			} catch (InterruptedException ie) {
147
				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), ie);
148
			}
149
		} else {
150
			try {
151
				fProject.setTargetedRuntimes(Collections.singleton(fRuntime), null);
152
153
			} catch (CoreException e) {
154
				status[0] = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_SETTING_RUNTIME, new String[] { fProject.getProject().getName(), fRuntime.getName() }), e);
155
			}
156
		}
157
158
		return status[0];
159
	}
160
161
	public IStatus setFixedFacetsOnProject(final IFacetedProject fProject, final Set fixedFacets) {
162
		final IStatus[] status = new IStatus[1];
163
		status[0] = Status.OK_STATUS;
164
165
		// Create a runnable that sets the fixed facets on the faceted project
166
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
167
			public void run(IProgressMonitor shellMonitor) throws InvocationTargetException, InterruptedException {
168
				try {
169
					fProject.setFixedProjectFacets(fixedFacets);
170
				} catch (CoreException e) {
171
					status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, e);
172
				}
173
			}
174
		};
175
176
		// Run the runnable in another thread unless there is no UI thread (Ant scenarios)
177
		if (displayPresent()) {
178
			try {
179
				PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
180
			} catch (InvocationTargetException ite) {
181
				status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ite);
182
			} catch (InterruptedException ie) {
183
				status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, ie);
184
			}
185
		} else {
186
			try {
187
				fProject.setFixedProjectFacets(fixedFacets);
188
			} catch (CoreException e) {
189
				status[0] = getErrorStatusForSettingFixedFacets(fProject.getProject().getName(), fixedFacets, e);
190
			}
191
		}
192
193
		return status[0];
194
	}
195
196
	// Check to see if SWT is active and the Display is present or not
197
	private static boolean displayPresent() {
198
		Bundle b = Platform.getBundle("org.eclipse.swt");
199
		if (b == null) {
200
			return false;
201
		}
202
		if ((b.getState() != Bundle.RESOLVED && b.getState() != Bundle.ACTIVE)) {
203
			return false;
204
		}
205
		try {
206
			if (Display.getCurrent() == null) {
207
				return false;
208
			} else {
209
				return true;
210
			}
211
		} catch (NoClassDefFoundError e1) {
212
			return false;
213
		} catch (Exception e) { 
214
			// if the Display class cannot be loaded for whatever reason
215
			return false;
216
217
		}
218
	}
219
220
	// the following private methods had to be copied from FacetUtils
221
	/**
222
	 * Returns a translatable delimited list of facet labels derived from the
223
	 * provided set of facets
224
	 * 
225
	 * @param facets
226
	 *            a set containing elements of type {@link IProjectFacet}
227
	 * @return String a delimited list of facet labels
228
	 */
229
	private static String getFacetListMessageString(Set facets) {
230
		String facetListMessage = "";
231
		int size = facets.size();
232
		if (size > 0) {
233
			Iterator itr = facets.iterator();
234
			IProjectFacet firstProjectFacet = (IProjectFacet) itr.next();
235
			facetListMessage = firstProjectFacet.getLabel();
236
237
			// Continue appending to facetListMessage until all the facet labels
238
			// are in the list.
239
			while (itr.hasNext()) {
240
				IProjectFacet projectFacet = (IProjectFacet) itr.next();
241
				String pfLabel = projectFacet.getLabel();
242
				facetListMessage = NLS.bind(ConsumptionMessages.MSG_FACETS, new String[] { facetListMessage, pfLabel });
243
			}
244
		}
245
246
		return facetListMessage;
247
	}
248
249
	/**
250
	 * Returns an error status indicating that the facets could not be set as
251
	 * fixed facets on the faceted project
252
	 * 
253
	 * @param projectName
254
	 *            a project name to insert in the error message in the IStatus
255
	 * @param facets
256
	 *            a set containing elements of type {@link IProjectFacet}. The
257
	 *            facets in this set will be listed in the error message in the
258
	 *            IStatus.
259
	 * @param t
260
	 *            a Throwable which will be inserted in the IStatus
261
	 * @return an IStatus with severity IStatus.ERROR
262
	 */
263
	private static IStatus getErrorStatusForSettingFixedFacets(String projectName, Set facets, Throwable t) {
264
		IStatus status = Status.OK_STATUS;
265
		int size = facets.size();
266
		if (size > 0) {
267
			String facetList = getFacetListMessageString(facets);
268
			status = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_FIXED_FACETS, new String[] { projectName, facetList }), t);
269
		}
270
271
		return status;
272
	}
273
274
	/**
275
	 * Returns an error status indicating that the facet versions could not be
276
	 * added to the faceted project
277
	 * 
278
	 * @param projectName
279
	 *            a project name to insert in the error message in the IStatus
280
	 * @param projectFacetVersions
281
	 *            a set containing elements of type {@link IProjectFacetVersion}
282
	 *            . The facets in this set will be listed in the error message
283
	 *            in the IStatus.
284
	 * @param t
285
	 *            a Throwable which will be inserted in the IStatus
286
	 * @return an IStatus with severity IStatus.ERROR
287
	 */
288
	private static IStatus getErrorStatusForAddingFacets(String projectName, Set projectFacetVersions, Throwable t) {
289
		IStatus status = Status.OK_STATUS;
290
		int size = projectFacetVersions.size();
291
		if (size > 0) {
292
			Set facets = new HashSet();
293
			// Iterate over projectFacetVersions to form a set of IProjectFacets
294
			Iterator itr = projectFacetVersions.iterator();
295
			while (itr.hasNext()) {
296
				IProjectFacetVersion projectFacet = (IProjectFacetVersion) itr.next();
297
				IProjectFacet facet = projectFacet.getProjectFacet();
298
				facets.add(facet);
299
			}
300
			String facetList = getFacetListMessageString(facets);
301
			status = StatusUtils.errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_ADDING_FACETS_TO_PROJECT, new String[] { projectName, facetList }), t);
302
		}
303
304
		return status;
305
	}
306
307
}

Return to bug 242635