|
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 |
} |