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 104622 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+8 lines)
Lines 81-84 Link Here
81
       class="org.eclipse.jst.server.ui.internal.ServerClasspathContainerPage">
81
       class="org.eclipse.jst.server.ui.internal.ServerClasspathContainerPage">
82
    </classpathContainerPage>
82
    </classpathContainerPage>
83
  </extension>
83
  </extension>
84
   <extension
85
         point="org.eclipse.jdt.ui.quickFixProcessors">
86
      <quickFixProcessor
87
            name="cactusQuickFixProcessor"
88
            class="org.eclipse.jst.server.ui.internal.cactus.CactusQuickFixProcessor"
89
            id="org.eclipse.jst.server.ui.internal.cactus.CactusQuickFixProcessor">
90
      </quickFixProcessor>
91
   </extension>
84
</plugin>
92
</plugin>
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 22-26 Link Here
22
 org.eclipse.ui.ide,
22
 org.eclipse.ui.ide,
23
 org.eclipse.jdt.ui,
23
 org.eclipse.jdt.ui,
24
 org.eclipse.wst.common.project.facet.core,
24
 org.eclipse.wst.common.project.facet.core,
25
 org.eclipse.wst.common.project.facet.ui
25
 org.eclipse.wst.common.project.facet.ui,
26
 org.eclipse.wst.common.modulecore,
27
 org.eclipse.jface.text
26
Eclipse-AutoStart: true
28
Eclipse-AutoStart: true
(-)sjavaui/org/eclipse/jst/server/ui/internal/Messages.java (-1 / +6 lines)
Lines 41-47 Link Here
41
	public static String NewServletTestCaseWizard_ErrorTitleNew;
41
	public static String NewServletTestCaseWizard_ErrorTitleNew;
42
	public static String NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed;
42
	public static String NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed;
43
	public static String NewServletTestCaseWizard_ErrorMessageSeeErrorLog;
43
	public static String NewServletTestCaseWizard_ErrorMessageSeeErrorLog;
44
44
    public static String NewServletTestCaseWizard_WarningMessageSelectAWebProject;
45
    public static String NewServletTestCaseWizard_WarningTitleWebProjectRequired;
46
    public static String NewServletTestCaseWizard_WarningMessageSuperclassIsEmpty;
47
    public static String NewServletTestCaseWizard_WarningMessageSuperclassDoesNotExist;
48
    public static String NewServletTestCaseWizard_WarningMessageSuperclassIsInterface;
49
    public static String NewServletTestCaseWizard_WarningMessageSuperclassNotServletTestCase;
45
	static {
50
	static {
46
		NLS.initializeMessages(JavaServerUIPlugin.PLUGIN_ID + ".internal.Messages", Messages.class);
51
		NLS.initializeMessages(JavaServerUIPlugin.PLUGIN_ID + ".internal.Messages", Messages.class);
47
	}
52
	}
(-)sjavaui/org/eclipse/jst/server/ui/internal/Messages.properties (-3 / +16 lines)
Lines 29-38 Link Here
29
LaunchTestAction_message_selectDebugConfiguration=Select JUnit configuration to debug
29
LaunchTestAction_message_selectDebugConfiguration=Select JUnit configuration to debug
30
LaunchTestAction_message_selectRunConfiguration=Select JUnit configuration to run
30
LaunchTestAction_message_selectRunConfiguration=Select JUnit configuration to run
31
31
32
NewServletTestCaseWizard_WindowTitle=New JUnit Test Case
32
NewServletTestCaseWizard_WindowTitle=New Cactus Test Case
33
NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary=Missing library
33
NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary=Missing library
34
NewServletTestCaseWizard_ErrorMessageMissingType=Missing type
34
NewServletTestCaseWizard_ErrorMessageMissingType=Missing type
35
NewServletTestCaseWizard_ErrorMessageMissingLibrary=You are missing cactus dependencies in your web project. The following libraries are required: {0}, {1}, {2}, {3} and {4}. Other versions might work but have not necessarily been tested. All libraries can be downloaded at http://jakarta.apache.org/cactus/.
35
NewServletTestCaseWizard_ErrorMessageMissingLibrary=You are missing cactus dependencies in your web project. Would you like to install them?
36
NewServletTestCaseWizard_ErrorTitleNew=New
36
NewServletTestCaseWizard_ErrorTitleNew=New
37
NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed=Creation of element failed.
37
NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed=Creation of element failed.
38
NewServletTestCaseWizard_ErrorMessageSeeErrorLog=See error log for more details.
38
NewServletTestCaseWizard_ErrorMessageSeeErrorLog=See error log for more details.
39
NewServletTestCaseWizard_WarningMessageSelectAWebProject=Warning: Cactus libraries can only be installed in a web project. Please select a web project.
40
NewServletTestCaseWizard_WarningTitleWebProjectRequired=Web project required.
41
NewServletTestCaseWizard_WarningMessageSuperclassIsEmpty=Superclass is empty.
42
NewServletTestCaseWizard_WarningMessageSuperclassDoesNotExist=Superclass does not exist.
43
NewServletTestCaseWizard_WarningMessageSuperclassIsInterface=Superclass is interface.
44
NewServletTestCaseWizard_WarningMessageSuperclassNotServletTestCase=Superclass does not extends org.apache.cactus.ServletTestCase.
45
CactusAddLibrariesProposal.ErrorMessageCouldntInstallLibraries=Couldn't install libraries
46
CactusAddLibrariesProposal.ErrorMessageCactusBundleNotFound=Cactus bundle could not be found.
47
CactusAddLibrariesProposal.ErrorMessageDestDirNotFound=Destination folder did not exist.
48
CactusAddLibrariesProposal.ErrorMessageInstallationOfLibsFailed=Installation of libraries failed.
49
CactusAddLibrariesProposal.ErrorMessageInstallDirNotFound=Cactus install directory could not be found
50
CactusAddLibrariesProposal.AdditionalInfoAddCactusLibraries=Add the Cactus libraries to do the WEB-INF/lib directory
51
CactusAddLibrariesProposal.DisplayStringAddCactusLibs=Add Cactus Libraries
(-)sjavaui/org/eclipse/jst/server/ui/internal/cactus/NewServletTestCaseWizard.java (-52 / +340 lines)
Lines 12-26 Link Here
12
12
13
import java.io.StringWriter;
13
import java.io.StringWriter;
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.List;
15
18
16
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Status;
25
import org.eclipse.core.runtime.Status;
21
import org.eclipse.jdt.core.IJavaProject;
26
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.core.IMethod;
28
import org.eclipse.jdt.core.IPackageFragment;
22
import org.eclipse.jdt.core.IPackageFragmentRoot;
29
import org.eclipse.jdt.core.IPackageFragmentRoot;
23
import org.eclipse.jdt.core.IType;
30
import org.eclipse.jdt.core.IType;
31
import org.eclipse.jdt.core.ITypeHierarchy;
24
import org.eclipse.jdt.core.JavaModelException;
32
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne;
33
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne;
26
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageTwo;
34
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageTwo;
Lines 32-44 Link Here
32
import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin;
40
import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin;
33
import org.eclipse.jst.server.ui.internal.Messages;
41
import org.eclipse.jst.server.ui.internal.Messages;
34
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.osgi.util.NLS;
43
import org.eclipse.swt.SWT;
44
import org.eclipse.swt.layout.GridData;
45
import org.eclipse.swt.layout.GridLayout;
46
import org.eclipse.swt.widgets.Button;
35
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Display;
49
import org.eclipse.swt.widgets.Display;
50
import org.eclipse.swt.widgets.Label;
37
import org.eclipse.swt.widgets.Shell;
51
import org.eclipse.swt.widgets.Shell;
38
import org.eclipse.ui.*;
52
import org.eclipse.ui.INewWizard;
53
import org.eclipse.ui.IWorkbench;
54
import org.eclipse.ui.IWorkbenchPage;
55
import org.eclipse.ui.IWorkbenchWindow;
56
import org.eclipse.ui.PartInitException;
57
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
58
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
40
import org.eclipse.ui.ide.IDE;
59
import org.eclipse.ui.ide.IDE;
41
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
60
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
61
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
62
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
63
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
64
42
/**
65
/**
43
 *
66
 *
44
 */
67
 */
Lines 46-68 Link Here
46
	private static final String SUPERCLASS_NAME = "org.apache.cactus.ServletTestCase"; //$NON-NLS-1$
69
	private static final String SUPERCLASS_NAME = "org.apache.cactus.ServletTestCase"; //$NON-NLS-1$
47
70
48
	protected static final String[] CLASSES_TO_CHECK = {
71
	protected static final String[] CLASSES_TO_CHECK = {
49
		"org.apache.cactus.ServletTestCase", "junit.framework.TestCase",
72
		"org.apache.cactus.ServletTestCase", "junit.framework.TestCase", //$NON-NLS-1$ //$NON-NLS-2$
50
		"org.apache.commons.logging.Log", "org.aspectj.lang.JoinPoint",
73
		"org.apache.commons.logging.Log", "org.aspectj.lang.JoinPoint", //$NON-NLS-1$ //$NON-NLS-2$
51
		"org.apache.commons.httpclient.HttpClient" };
74
		"org.apache.commons.httpclient.HttpClient" }; //$NON-NLS-1$
52
75
53
	protected static final String[] REQUIRED_LIBRARIES = {
76
	protected static final String[] REQUIRED_LIBRARIES = {
54
		"cactus-1.7.jar", "junit-3.8.1.jar", "aspectjrt-1.2.1.jar",
77
		"cactus-1.7.2.jar", "junit-3.8.1.jar", "aspectjrt-1.2.1.jar", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
55
		"commons-logging-1.0.4.jar", "commons-httpclient-2.0.2.jar" };
78
		"commons-logging-1.0.4.jar", "commons-httpclient-2.0.2.jar" }; //$NON-NLS-1$ //$NON-NLS-2$
56
79
57
	private IWorkbench fWorkbench;
80
	private IWorkbench fWorkbench;
58
	private IStructuredSelection fSelection;
81
	private IStructuredSelection fSelection;
59
	private NewTestCaseWizardPageTwo fPage2;
82
	private NewTestCaseWizardPageTwo fPage2;
60
	private NewTestCaseWizardPageOne fPage1;
83
	private NewTestCaseWizardPageOne fPage1;
61
	
84
    
62
	public NewServletTestCaseWizard() {
85
	public NewServletTestCaseWizard() {
63
		super();
86
		super();
64
		setWindowTitle(Messages.NewServletTestCaseWizard_WindowTitle);
87
		setWindowTitle(Messages.NewServletTestCaseWizard_WindowTitle);
65
		setDefaultPageImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_WIZ_CACTUS_TEST));
88
		setDefaultPageImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_WIZ_CACTUS_TEST));
89
        
90
66
	}
91
	}
67
92
68
	public void init(IWorkbench workbench, IStructuredSelection selection) {
93
	public void init(IWorkbench workbench, IStructuredSelection selection) {
Lines 73-118 Link Here
73
	public void addPages() {
98
	public void addPages() {
74
		super.addPages();
99
		super.addPages();
75
		fPage2 = new NewTestCaseWizardPageTwo();
100
		fPage2 = new NewTestCaseWizardPageTwo();
76
		fPage1 = new NewTestCaseWizardPageOne(fPage2) {
101
		fPage1 = new CactusPage1(fPage2);
77
			public void createControl(Composite parent) {
78
				super.createControl(parent);
79
				setSuperClass(SUPERCLASS_NAME, true);
80
			}
81
82
			protected IStatus validateIfJUnitProject() {
83
				IPackageFragmentRoot root = getPackageFragmentRoot();
84
				if (root == null)
85
					return Status.OK_STATUS;
86
87
				IJavaProject project = root.getJavaProject();
88
				try {
89
					for (int i = 0; i < CLASSES_TO_CHECK.length; i++) {
90
						IType type = project.findType(CLASSES_TO_CHECK[i]);
91
						if (type == null) {
92
							MessageDialog.openError(getShell(),
93
									Messages.NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary,
94
									NLS.bind(Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, REQUIRED_LIBRARIES));
95
							return Status.OK_STATUS;
96
						}
97
					}
98
				} catch (JavaModelException e) {
99
					JavaServerUIPlugin.log(e);
100
				}
101
				return Status.OK_STATUS;
102
			}
103
		};
104
		addPage(fPage1);
102
		addPage(fPage1);
105
		fPage1.init(getSelection());
103
		fPage1.init(getSelection());
106
		addPage(fPage2);
104
		addPage(fPage2);
107
105
108
	}
106
	}
107
    
108
    private class CactusPage1 extends NewTestCaseWizardPageOne
109
    {
110
111
        private Button fBeginButton;
112
        private Button fEndButton;
113
        private Button fBeginXXXButton;
114
        private Button fEndXXXButton;
115
        private Composite fCactusButtonComposite;
116
        
117
        public CactusPage1(NewTestCaseWizardPageTwo page2) {
118
            super(page2);
119
            
120
        }
121
        
122
        public void init(IStructuredSelection selection) {
123
            super.init(selection);
124
        }
125
        
126
        public void createControl(Composite parent) {
127
            super.createControl(parent);
128
            setSuperClass(SUPERCLASS_NAME, true);
129
130
            
131
        }
132
        
133
        protected IStatus superClassChanged() {
134
            String superClassName= getSuperClass();
135
            if (superClassName == null || superClassName.trim().equals("")) { //$NON-NLS-1$
136
                Status status = new Status(IStatus.ERROR, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, Messages.NewServletTestCaseWizard_WarningMessageSuperclassIsEmpty, null);
137
                return status;  
138
            }
139
            
140
            if (superClassName.equals("org.apache.cactus.ServletTestCase")){
141
                //Short-circuit if this IS ServletTestCase
142
                return Status.OK_STATUS; 
143
            }
144
            
145
            if (getPackageFragmentRoot() != null)
146
            {
147
                IType type;
148
                try {
149
                    type = resolveClassNameToType(getPackageFragmentRoot().getJavaProject(), getPackageFragment(), superClassName);
150
                    if (type == null) {
151
                        Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassDoesNotExist, null);
152
                        return status;                        
153
                    }
154
                    
155
156
                    
157
                    if (type.isInterface()) {
158
                        Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassIsInterface, null);
159
                        return status;
160
                    }
161
                    
162
                    ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
163
                    IType [] superTypes = hierarchy.getAllSuperclasses(type);
164
                    for (int i=0; i<superTypes.length; i++)
165
                    {
166
                        if (superTypes[i].getFullyQualifiedName().equals("org.apache.cactus.ServletTestCase"))
167
                        {
168
                            return Status.OK_STATUS; 
169
                        }
170
                    }
171
                    
172
                    Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassNotServletTestCase, null);
173
                    return status;
174
                    
175
                } catch (JavaModelException e) {
176
                    JavaServerUIPlugin.log(e);
177
                }    
178
               
179
            }
180
          
181
            return Status.OK_STATUS;
182
        }
183
        
184
        private IType resolveClassNameToType(IJavaProject jproject, IPackageFragment pack, String classToTestName) throws JavaModelException {
185
            
186
            IType type= jproject.findType(classToTestName);
187
            
188
            // search in current package
189
            if (type == null && pack != null && !pack.isDefaultPackage()) {
190
                type= jproject.findType(pack.getElementName(), classToTestName);
191
            }
192
            
193
            // search in java.lang
194
            if (type == null) {
195
                type= jproject.findType("java.lang", classToTestName); //$NON-NLS-1$
196
            }
197
            return type;
198
        }
199
200
        protected IStatus validateIfJUnitProject() {
201
            try {
202
                if (checkForWebProject())
203
                {
204
                    checkForCactusLibraries();                
205
                }
206
                else
207
                {
208
                    String msg = Messages.NewServletTestCaseWizard_WarningMessageSelectAWebProject;
209
                    MessageDialog.openWarning(getShell(), Messages.NewServletTestCaseWizard_WarningTitleWebProjectRequired, msg);
210
                    return new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, msg, null);
211
                }
212
            } catch (CoreException e) {
213
                return new Status(Status.ERROR, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, "Failed to check for cactus libraries." ,e);
214
            }
215
216
            return Status.OK_STATUS;
217
        }
218
219
        protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
220
            super.createTypeMembers(type, imports, monitor);
221
            if (fBeginButton.getSelection())
222
            {
223
                generateBeginMethod(type, imports);
224
            }
225
            
226
            if (fEndButton.getSelection())
227
            {
228
                generateEndMethod(type, imports);
229
            }
230
            
231
            if (fBeginXXXButton.getSelection())
232
            {
233
                generateBeginXXXMethods(type, imports);
234
            }
235
            
236
            if (fEndXXXButton.getSelection())
237
            {
238
                generateEndXXXMethods(type, imports);
239
            }
240
                
241
        }
242
        
243
        private void generateBeginMethod(IType type, ImportsManager imports)
244
        throws JavaModelException
245
        {
246
            StringBuilder methodBuffer = new StringBuilder();
247
            methodBuffer.append("public void begin("); //$NON-NLS-1$
248
            methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$
249
            methodBuffer.append(" request) throws "); //$NON-NLS-1$
250
            methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$
251
            methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$
252
            type.createMethod(methodBuffer.toString(), null, false, null);
253
        }
254
        
255
        private void generateEndMethod(IType type, ImportsManager imports)
256
        throws JavaModelException
257
        {
258
            StringBuilder methodBuffer = new StringBuilder();
259
            methodBuffer.append("public void end("); //$NON-NLS-1$
260
            methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$
261
            methodBuffer.append(" request) throws "); //$NON-NLS-1$
262
            methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$
263
            methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$
264
            type.createMethod(methodBuffer.toString(), null, false, null);       
265
        }
266
        
267
        private void generateBeginXXXMethods(IType type, ImportsManager imports)
268
        throws JavaModelException
269
        {
270
            generateXXXMethods(type, imports, "begin"); //$NON-NLS-1$
271
        }
272
        
273
        private void generateXXXMethods(IType type, ImportsManager imports, String prefix) throws JavaModelException
274
        {
275
            IMethod [] testMethods = type.getMethods();
276
            for (int i=0; i<testMethods.length; i++)
277
            {
278
                IMethod testMethod = testMethods[i];
279
                String testMethodName = testMethod.getElementName();
280
                if (testMethodName.startsWith("test")) //$NON-NLS-1$
281
                {
282
                    String newMethodName = prefix + testMethodName.substring(4);
283
                    StringBuilder methodBuffer = new StringBuilder();
284
                    methodBuffer.append("public void "); //$NON-NLS-1$
285
                    methodBuffer.append(newMethodName);
286
                    methodBuffer.append("("); //$NON-NLS-1$
287
                    methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$
288
                    methodBuffer.append(" request) throws "); //$NON-NLS-1$
289
                    methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$
290
                    methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$
291
                    type.createMethod(methodBuffer.toString(), testMethod, false, null);  
292
                    
293
                }
294
295
            }           
296
        }
297
        
298
        private void generateEndXXXMethods(IType type, ImportsManager imports)
299
        throws JavaModelException
300
        {
301
            generateXXXMethods(type, imports, "end");          //$NON-NLS-1$
302
        }
303
        
304
        protected void createMethodStubSelectionControls(Composite composite, int nColumns) {
305
            super.createMethodStubSelectionControls(composite, nColumns);
306
            createEmptySpace(composite);
307
            fCactusButtonComposite = new Composite(composite, SWT.NONE);
308
            GridData gd = new GridData();
309
            gd.horizontalSpan = 3;
310
            fCactusButtonComposite.setLayoutData(gd);
311
            GridLayout layout = new GridLayout();
312
            layout.numColumns = 1;
313
            layout.marginWidth = layout.marginHeight = 0;
314
            layout.makeColumnsEqualWidth = true;
315
            fCactusButtonComposite.setLayout(layout);
316
317
            fBeginButton = createSelectionButton("begin()", fCactusButtonComposite); //$NON-NLS-1$
318
            fEndButton = createSelectionButton("end()", fCactusButtonComposite); //$NON-NLS-1$
319
            fBeginXXXButton = createSelectionButton("beginXXX() methods", fCactusButtonComposite); //$NON-NLS-1$
320
            fEndXXXButton = createSelectionButton("endXXX() methods", fCactusButtonComposite); //$NON-NLS-1$
321
            
322
        }
323
        
324
        private Button createSelectionButton(String text, Composite group) {
325
            Button button= new Button(group, SWT.CHECK | SWT.LEFT);
326
            button.setFont(group.getFont());            
327
            button.setText(text);
328
            GridData data = new GridData();
329
            data.horizontalAlignment = SWT.BEGINNING;
330
            data.verticalAlignment = GridData.CENTER;
331
            button.setLayoutData(data);
332
            return button;
333
        }
334
        
335
    }
336
    
337
    private static Control createEmptySpace(Composite parent) {
338
        return createEmptySpace(parent, 1);
339
    }
340
    
341
    private static Control createEmptySpace(Composite parent, int span) {
342
        Label label= new Label(parent, SWT.LEFT);
343
        GridData gd= new GridData();
344
        gd.horizontalAlignment= GridData.BEGINNING;
345
        gd.grabExcessHorizontalSpace= false;
346
        gd.horizontalSpan= span;
347
        gd.horizontalIndent= 0;
348
        gd.widthHint= 0;
349
        gd.heightHint= 0;
350
        label.setLayoutData(gd);
351
        return label;
352
    }
353
    
109
354
110
	private IStructuredSelection getSelection() {
355
	private IStructuredSelection getSelection() {
111
		return fSelection;
356
		return fSelection;
112
	}
357
	}
358
    
359
    private boolean checkForWebProject() throws CoreException
360
    {
361
        IPackageFragmentRoot root = fPage1.getPackageFragmentRoot();
362
        if (root == null)
363
            return false;
364
365
        IJavaProject project = root.getJavaProject();
366
        IFacetedProject facetedProject = ProjectFacetsManager.create(project.getProject());
367
        if (facetedProject != null)
368
        {
369
            Iterator facets = facetedProject.getProjectFacets().iterator();
370
            while(facets.hasNext())
371
            {
372
                IProjectFacetVersion facet = (IProjectFacetVersion) facets.next();
373
                if (facet.getProjectFacet().getId().equals("jst.web")) //$NON-NLS-1$
374
                {
375
                    return true;
376
                }
377
                    
378
            }            
379
        }
380
381
        return false;
382
    }
383
    
384
    private void checkForCactusLibraries()
385
    {
386
        IPackageFragmentRoot root = fPage1.getPackageFragmentRoot();
387
        if (root == null)
388
            return;
389
390
        IJavaProject project = root.getJavaProject();
391
        
392
        List missingLibraries = new ArrayList();
393
        try {
394
            for (int i = 0; i < CLASSES_TO_CHECK.length; i++) {
395
                IType type = project.findType(CLASSES_TO_CHECK[i]);
396
                if (type == null) {
397
                    missingLibraries.add(REQUIRED_LIBRARIES[i]);
398
                }
399
            }
400
            
401
            if (missingLibraries.size() > 0)
402
            {
403
                if (MessageDialog.openQuestion(getShell(), Messages.NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary,
404
                        NLS.bind(Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, missingLibraries.toArray())))
405
                {
406
                    CactusAddLibrariesProposal.installLibraries(project.getProject());
407
                }
408
            }
409
410
            
411
        } catch (JavaModelException e) {
412
            JavaServerUIPlugin.log(e);
413
        }        
414
    }
113
415
114
	public boolean performFinish() {
416
	public boolean performFinish() {
115
		if (finishPage(fPage1.getRunnable())) {
417
		if (finishPage(fPage1.getRunnable())) {
418
116
			IType newClass = fPage1.getCreatedType();
419
			IType newClass = fPage1.getCreatedType();
117
420
118
			IResource resource = newClass.getCompilationUnit().getResource();
421
			IResource resource = newClass.getCompilationUnit().getResource();
Lines 120-145 Link Here
120
				BasicNewResourceWizard.selectAndReveal(resource, fWorkbench
423
				BasicNewResourceWizard.selectAndReveal(resource, fWorkbench
121
						.getActiveWorkbenchWindow());
424
						.getActiveWorkbenchWindow());
122
				openResource(resource);
425
				openResource(resource);
123
				// checkLibraryMissing();
124
			}
426
			}
125
			return true;
427
			return true;
126
		}
428
		}
127
		return false;
429
		return false;
128
	}
430
	}
129
431
130
	/*private void checkLibraryMissing() {
131
		IType newClass = fPage1.getCreatedType();
132
		IJavaProject project = newClass.getJavaProject();
133
		try {
134
			IType type = project.findType(SUPERCLASS_NAME);
135
			MessageDialog.openError(getShell(), NLS.bind(
136
					Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, REQUIRED_LIBRARIES),
137
					Messages.NewServletTestCaseWizard_ErrorMessageMissingType);
138
		} catch (JavaModelException e) {
139
			JavaServerUIPlugin.log(e);
140
		}
141
	}*/
142
143
	protected boolean finishPage(IRunnableWithProgress runnable) {
432
	protected boolean finishPage(IRunnableWithProgress runnable) {
144
		IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable);
433
		IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable);
145
		try {
434
		try {
Lines 148-154 Link Here
148
		} catch (InvocationTargetException e) {
437
		} catch (InvocationTargetException e) {
149
			String title = Messages.NewServletTestCaseWizard_ErrorTitleNew; // NewJUnitWizard_op_error_title
438
			String title = Messages.NewServletTestCaseWizard_ErrorTitleNew; // NewJUnitWizard_op_error_title
150
			String message = Messages.NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed; // NewJUnitWizard_op_error_message
439
			String message = Messages.NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed; // NewJUnitWizard_op_error_message
151
			// ExceptionHandler.handle(e, shell, title, message);
152
			displayMessageDialog(e, e.getMessage(), getShell(), title, message);
440
			displayMessageDialog(e, e.getMessage(), getShell(), title, message);
153
			return false;
441
			return false;
154
		} catch (InterruptedException e) {
442
		} catch (InterruptedException e) {
Lines 191-204 Link Here
191
		}
479
		}
192
	}
480
	}
193
481
194
	public static IWorkbenchPage getActivePage() {
482
	private static IWorkbenchPage getActivePage() {
195
		IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
483
		IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
196
		if (activeWorkbenchWindow == null)
484
		if (activeWorkbenchWindow == null)
197
			return null;
485
			return null;
198
		return activeWorkbenchWindow.getActivePage();
486
		return activeWorkbenchWindow.getActivePage();
199
	}
487
	}
200
488
201
	public static IWorkbenchWindow getActiveWorkbenchWindow() {
489
	private static IWorkbenchWindow getActiveWorkbenchWindow() {
202
		IWorkbench workbench = JavaServerUIPlugin.getInstance().getWorkbench();
490
		IWorkbench workbench = JavaServerUIPlugin.getInstance().getWorkbench();
203
		if (workbench != null)
491
		if (workbench != null)
204
			return workbench.getActiveWorkbenchWindow();
492
			return workbench.getActiveWorkbenchWindow();
(-).settings/org.eclipse.jdt.core.prefs (+12 lines)
Added Link Here
1
#Wed Mar 22 09:05:23 PST 2006
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6
org.eclipse.jdt.core.compiler.compliance=1.4
7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
11
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
12
org.eclipse.jdt.core.compiler.source=1.3
(-).settings/org.eclipse.jdt.ui.prefs (+3 lines)
Added Link Here
1
#Wed Mar 22 09:05:22 PST 2006
2
eclipse.preferences.version=1
3
internal.default.compliance=default
(-)sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusAddLibrariesProposal.java (+123 lines)
Added Link Here
1
package org.eclipse.jst.server.ui.internal.cactus;
2
3
import java.io.File;
4
import java.io.IOException;
5
import java.net.URL;
6
7
import org.eclipse.core.resources.IContainer;
8
import org.eclipse.core.resources.IFolder;
9
import org.eclipse.core.resources.IProject;
10
import org.eclipse.core.runtime.Path;
11
import org.eclipse.core.runtime.Platform;
12
import org.eclipse.jdt.core.ICompilationUnit;
13
import org.eclipse.jdt.ui.text.java.IInvocationContext;
14
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
15
import org.eclipse.jface.dialogs.MessageDialog;
16
import org.eclipse.jface.text.IDocument;
17
import org.eclipse.jface.text.contentassist.IContextInformation;
18
import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
22
import org.eclipse.wst.common.componentcore.ComponentCore;
23
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
24
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
25
import org.osgi.framework.Bundle;
26
27
public class CactusAddLibrariesProposal implements IJavaCompletionProposal {
28
29
    private final IInvocationContext fContext;
30
    
31
    public CactusAddLibrariesProposal(IInvocationContext context) {
32
       fContext = context;
33
    }
34
35
    public int getRelevance() {
36
        return 0;
37
    }
38
39
    public void apply(IDocument document) {
40
    
41
        ICompilationUnit javaFile = fContext.getCompilationUnit();
42
        installLibraries(javaFile.getJavaProject().getProject());
43
    
44
    }
45
    
46
    public static void installLibraries(final IProject project)
47
    {
48
        
49
        try
50
        {
51
          
52
            Bundle bundle = Platform.getBundle("org.apache.cactus"); //$NON-NLS-1$
53
            if (bundle == null)
54
            {
55
                showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageCactusBundleNotFound"));                //$NON-NLS-1$
56
                return;
57
            }
58
            URL cactusLibDir = Platform.find(bundle, new Path("lib")); //$NON-NLS-1$
59
            if (cactusLibDir == null)
60
            {
61
                showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageInstallDirNotFound"));                 //$NON-NLS-1$
62
                return;
63
            }
64
            URL localURL = Platform.asLocalURL(cactusLibDir);
65
            final File sourceDirectory = new File(localURL.getPath());
66
            IVirtualComponent component = ComponentCore.createComponent(project);
67
            IVirtualFolder vf = component.getRootFolder().getFolder( "WEB-INF/lib" ); //$NON-NLS-1$
68
            final IContainer destinationDirectory = vf.getUnderlyingFolder();
69
            
70
            IFolder destinationFolder = project.getFolder(destinationDirectory.getProjectRelativePath());
71
            
72
            if (destinationFolder.exists())
73
            {
74
                File [] filesToCopy = sourceDirectory.listFiles();
75
                String [] filesToCopyNames = new String[filesToCopy.length];
76
                for (int i=0; i<filesToCopy.length; i++)
77
                {
78
                    filesToCopyNames[i] = filesToCopy[i].getAbsolutePath();
79
                }
80
                CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(JavaServerUIPlugin.getActiveWorkbenchShell());
81
                operation.copyFiles(filesToCopyNames, destinationFolder);
82
            }
83
            else
84
            {
85
                showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageDestDirNotFound")); //$NON-NLS-1$
86
                return;
87
            }             
88
            
89
        }
90
        catch (IOException e) {
91
            JavaServerUIPlugin.log(e);
92
            showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageInstallationOfLibsFailed")); //$NON-NLS-1$
93
94
        }        
95
        
96
    }
97
    
98
    private static void showInstallFailedDialog(String message)
99
    {
100
        MessageDialog.openError(JavaServerUIPlugin.getActiveWorkbenchShell(), Messages.getString("CactusAddLibrariesProposal.ErrorMessageCouldntInstallLibraries"), message);         //$NON-NLS-1$ //$NON-NLS-2$
101
    }
102
103
    public Point getSelection(IDocument document) {
104
        return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength());
105
    }
106
107
    public String getAdditionalProposalInfo() {
108
        return Messages.getString("CactusAddLibrariesProposal.AdditionalInfoAddCactusLibraries"); //$NON-NLS-1$
109
    }
110
111
    public String getDisplayString() {
112
        return Messages.getString("CactusAddLibrariesProposal.DisplayStringAddCactusLibs"); //$NON-NLS-1$
113
    }
114
115
    public Image getImage() {
116
        return null;
117
    }
118
119
    public IContextInformation getContextInformation() {
120
        return null;
121
    }
122
123
}
(-)sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusQuickFixProcessor.java (+70 lines)
Added Link Here
1
package org.eclipse.jst.server.ui.internal.cactus;
2
3
import org.eclipse.core.runtime.CoreException;
4
import org.eclipse.jdt.core.IBuffer;
5
import org.eclipse.jdt.core.ICompilationUnit;
6
import org.eclipse.jdt.core.JavaModelException;
7
import org.eclipse.jdt.core.compiler.IProblem;
8
import org.eclipse.jdt.ui.text.java.IInvocationContext;
9
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
10
import org.eclipse.jdt.ui.text.java.IProblemLocation;
11
import org.eclipse.jdt.ui.text.java.IQuickFixProcessor;
12
import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin;
13
14
public class CactusQuickFixProcessor implements IQuickFixProcessor {
15
16
    public boolean hasCorrections(ICompilationUnit unit, int problemId) {
17
        return IProblem.ImportNotFound == problemId;
18
    }
19
20
    public IJavaCompletionProposal[] getCorrections(IInvocationContext context,
21
            IProblemLocation[] locations) throws CoreException {
22
       if (isCactusProblem(context, locations))
23
       {
24
           return new IJavaCompletionProposal[]{new CactusAddLibrariesProposal(context)};
25
       }
26
       else
27
       {
28
           return new IJavaCompletionProposal[0];
29
       }
30
    }
31
32
    private boolean isCactusProblem(IInvocationContext context, IProblemLocation[] locations) {
33
        ICompilationUnit unit= context.getCompilationUnit();
34
        for (int i= 0; i < locations.length; i++) {
35
            IProblemLocation location= locations[i];
36
            try {
37
                String s= getStringUntilWhiteSpaceOrEnd(location.getOffset(), unit);
38
                if ("ServletTestCase".equals(s) || s.contains("org.apache.cactus"))
39
                {
40
                    return true;
41
                }
42
            } catch (JavaModelException e) {
43
                JavaServerUIPlugin.log(e);
44
            }
45
        }
46
        return false;
47
    }
48
    
49
    private String getStringUntilWhiteSpaceOrEnd(int offset, ICompilationUnit unit) throws JavaModelException
50
    {
51
        StringBuilder builder = new StringBuilder();
52
        IBuffer buffer = unit.getBuffer();
53
        int length = buffer.getLength();
54
55
        for (int index = offset; index<length ; index++)
56
        {
57
            char c = buffer.getChar(index);
58
            if (Character.isWhitespace(c))
59
            {
60
                return builder.toString();
61
            }
62
            else
63
            {
64
                builder.append(c);        
65
            }
66
67
        }
68
        return builder.toString();
69
    }
70
}
(-)sjavaui/org/eclipse/jst/server/ui/internal/cactus/Messages.java (+23 lines)
Added Link Here
1
package org.eclipse.jst.server.ui.internal.cactus;
2
3
import java.util.MissingResourceException;
4
import java.util.ResourceBundle;
5
6
public class Messages {
7
    private static final String BUNDLE_NAME = "org.eclipse.jst.server.ui.internal.Messages"; //$NON-NLS-1$
8
9
    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
10
            .getBundle(BUNDLE_NAME);
11
12
    private Messages() {
13
    }
14
15
    public static String getString(String key) {
16
        // TODO Auto-generated method stub
17
        try {
18
            return RESOURCE_BUNDLE.getString(key);
19
        } catch (MissingResourceException e) {
20
            return '!' + key + '!';
21
        }
22
    }
23
}

Return to bug 104622