Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 39084 Details for
Bug 104622
Automatically add required Cactus jars to project
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch for automatic library attachment with external resource plug-in
org.eclipse.jst.server.ui.libraryInstall.v2.patch (text/plain), 37.48 KB, created by
Daniel R Somerfield
on 2006-04-20 14:19:31 EDT
(
hide
)
Description:
Patch for automatic library attachment with external resource plug-in
Filename:
MIME Type:
Creator:
Daniel R Somerfield
Created:
2006-04-20 14:19:31 EDT
Size:
37.48 KB
patch
obsolete
>Index: plugin.xml >=================================================================== >RCS file: /home/webtools/jst/components/server/plugins/org.eclipse.jst.server.ui/plugin.xml,v >retrieving revision 1.13 >diff -u -r1.13 plugin.xml >--- plugin.xml 18 Jan 2006 23:23:58 -0000 1.13 >+++ plugin.xml 20 Apr 2006 18:05:25 -0000 >@@ -81,4 +81,12 @@ > class="org.eclipse.jst.server.ui.internal.ServerClasspathContainerPage"> > </classpathContainerPage> > </extension> >+ <extension >+ point="org.eclipse.jdt.ui.quickFixProcessors"> >+ <quickFixProcessor >+ name="cactusQuickFixProcessor" >+ class="org.eclipse.jst.server.ui.internal.cactus.CactusQuickFixProcessor" >+ id="org.eclipse.jst.server.ui.internal.cactus.CactusQuickFixProcessor"> >+ </quickFixProcessor> >+ </extension> > </plugin> >\ No newline at end of file >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/webtools/jst/components/server/plugins/org.eclipse.jst.server.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.8 >diff -u -r1.8 MANIFEST.MF >--- META-INF/MANIFEST.MF 1 Mar 2006 17:33:13 -0000 1.8 >+++ META-INF/MANIFEST.MF 20 Apr 2006 18:05:25 -0000 >@@ -22,5 +22,7 @@ > org.eclipse.ui.ide, > org.eclipse.jdt.ui, > org.eclipse.wst.common.project.facet.core, >- org.eclipse.wst.common.project.facet.ui >+ org.eclipse.wst.common.project.facet.ui, >+ org.eclipse.wst.common.modulecore, >+ org.eclipse.jface.text > Eclipse-AutoStart: true >Index: sjavaui/org/eclipse/jst/server/ui/internal/Messages.java >=================================================================== >RCS file: /home/webtools/jst/components/server/plugins/org.eclipse.jst.server.ui/sjavaui/org/eclipse/jst/server/ui/internal/Messages.java,v >retrieving revision 1.5 >diff -u -r1.5 Messages.java >--- sjavaui/org/eclipse/jst/server/ui/internal/Messages.java 18 Jan 2006 23:20:55 -0000 1.5 >+++ sjavaui/org/eclipse/jst/server/ui/internal/Messages.java 20 Apr 2006 18:05:25 -0000 >@@ -41,7 +41,12 @@ > public static String NewServletTestCaseWizard_ErrorTitleNew; > public static String NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed; > public static String NewServletTestCaseWizard_ErrorMessageSeeErrorLog; >- >+ public static String NewServletTestCaseWizard_WarningMessageSelectAWebProject; >+ public static String NewServletTestCaseWizard_WarningTitleWebProjectRequired; >+ public static String NewServletTestCaseWizard_WarningMessageSuperclassIsEmpty; >+ public static String NewServletTestCaseWizard_WarningMessageSuperclassDoesNotExist; >+ public static String NewServletTestCaseWizard_WarningMessageSuperclassIsInterface; >+ public static String NewServletTestCaseWizard_WarningMessageSuperclassNotServletTestCase; > static { > NLS.initializeMessages(JavaServerUIPlugin.PLUGIN_ID + ".internal.Messages", Messages.class); > } >Index: sjavaui/org/eclipse/jst/server/ui/internal/Messages.properties >=================================================================== >RCS file: /home/webtools/jst/components/server/plugins/org.eclipse.jst.server.ui/sjavaui/org/eclipse/jst/server/ui/internal/Messages.properties,v >retrieving revision 1.4 >diff -u -r1.4 Messages.properties >--- sjavaui/org/eclipse/jst/server/ui/internal/Messages.properties 18 Jan 2006 23:20:55 -0000 1.4 >+++ sjavaui/org/eclipse/jst/server/ui/internal/Messages.properties 20 Apr 2006 18:05:25 -0000 >@@ -29,10 +29,23 @@ > LaunchTestAction_message_selectDebugConfiguration=Select JUnit configuration to debug > LaunchTestAction_message_selectRunConfiguration=Select JUnit configuration to run > >-NewServletTestCaseWizard_WindowTitle=New JUnit Test Case >+NewServletTestCaseWizard_WindowTitle=New Cactus Test Case > NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary=Missing library > NewServletTestCaseWizard_ErrorMessageMissingType=Missing type >-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/. >+NewServletTestCaseWizard_ErrorMessageMissingLibrary=You are missing cactus dependencies in your web project. Would you like to install them? > NewServletTestCaseWizard_ErrorTitleNew=New > NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed=Creation of element failed. >-NewServletTestCaseWizard_ErrorMessageSeeErrorLog=See error log for more details. >\ No newline at end of file >+NewServletTestCaseWizard_ErrorMessageSeeErrorLog=See error log for more details. >+NewServletTestCaseWizard_WarningMessageSelectAWebProject=Warning: Cactus libraries can only be installed in a web project. Please select a web project. >+NewServletTestCaseWizard_WarningTitleWebProjectRequired=Web project required. >+NewServletTestCaseWizard_WarningMessageSuperclassIsEmpty=Superclass is empty. >+NewServletTestCaseWizard_WarningMessageSuperclassDoesNotExist=Superclass does not exist. >+NewServletTestCaseWizard_WarningMessageSuperclassIsInterface=Superclass is interface. >+NewServletTestCaseWizard_WarningMessageSuperclassNotServletTestCase=Superclass does not extends org.apache.cactus.ServletTestCase. >+CactusAddLibrariesProposal.ErrorMessageCouldntInstallLibraries=Couldn't install libraries >+CactusAddLibrariesProposal.ErrorMessageCactusBundleNotFound=Cactus bundle could not be found. >+CactusAddLibrariesProposal.ErrorMessageDestDirNotFound=Destination folder did not exist. >+CactusAddLibrariesProposal.ErrorMessageInstallationOfLibsFailed=Installation of libraries failed. >+CactusAddLibrariesProposal.ErrorMessageInstallDirNotFound=Cactus install directory could not be found >+CactusAddLibrariesProposal.AdditionalInfoAddCactusLibraries=Add the Cactus libraries to do the WEB-INF/lib directory >+CactusAddLibrariesProposal.DisplayStringAddCactusLibs=Add Cactus Libraries >Index: sjavaui/org/eclipse/jst/server/ui/internal/cactus/NewServletTestCaseWizard.java >=================================================================== >RCS file: /home/webtools/jst/components/server/plugins/org.eclipse.jst.server.ui/sjavaui/org/eclipse/jst/server/ui/internal/cactus/NewServletTestCaseWizard.java,v >retrieving revision 1.1 >diff -u -r1.1 NewServletTestCaseWizard.java >--- sjavaui/org/eclipse/jst/server/ui/internal/cactus/NewServletTestCaseWizard.java 6 Jun 2005 01:47:12 -0000 1.1 >+++ sjavaui/org/eclipse/jst/server/ui/internal/cactus/NewServletTestCaseWizard.java 20 Apr 2006 18:05:26 -0000 >@@ -12,15 +12,23 @@ > > import java.io.StringWriter; > import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; > > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; > import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IMethod; >+import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.ITypeHierarchy; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne; > import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageTwo; >@@ -32,13 +40,28 @@ > import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin; > import org.eclipse.jst.server.ui.internal.Messages; > import org.eclipse.osgi.util.NLS; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Label; > import org.eclipse.swt.widgets.Shell; >-import org.eclipse.ui.*; >+import org.eclipse.ui.INewWizard; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; > import org.eclipse.ui.ide.IDE; > import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; >+import org.eclipse.wst.common.project.facet.core.IFacetedProject; >+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; >+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; >+ > /** > * > */ >@@ -46,23 +69,25 @@ > private static final String SUPERCLASS_NAME = "org.apache.cactus.ServletTestCase"; //$NON-NLS-1$ > > protected static final String[] CLASSES_TO_CHECK = { >- "org.apache.cactus.ServletTestCase", "junit.framework.TestCase", >- "org.apache.commons.logging.Log", "org.aspectj.lang.JoinPoint", >- "org.apache.commons.httpclient.HttpClient" }; >+ "org.apache.cactus.ServletTestCase", "junit.framework.TestCase", //$NON-NLS-1$ //$NON-NLS-2$ >+ "org.apache.commons.logging.Log", "org.aspectj.lang.JoinPoint", //$NON-NLS-1$ //$NON-NLS-2$ >+ "org.apache.commons.httpclient.HttpClient" }; //$NON-NLS-1$ > > protected static final String[] REQUIRED_LIBRARIES = { >- "cactus-1.7.jar", "junit-3.8.1.jar", "aspectjrt-1.2.1.jar", >- "commons-logging-1.0.4.jar", "commons-httpclient-2.0.2.jar" }; >+ "cactus-1.7.2.jar", "junit-3.8.1.jar", "aspectjrt-1.2.1.jar", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ "commons-logging-1.0.4.jar", "commons-httpclient-2.0.2.jar" }; //$NON-NLS-1$ //$NON-NLS-2$ > > private IWorkbench fWorkbench; > private IStructuredSelection fSelection; > private NewTestCaseWizardPageTwo fPage2; > private NewTestCaseWizardPageOne fPage1; >- >+ > public NewServletTestCaseWizard() { > super(); > setWindowTitle(Messages.NewServletTestCaseWizard_WindowTitle); > setDefaultPageImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_WIZ_CACTUS_TEST)); >+ >+ > } > > public void init(IWorkbench workbench, IStructuredSelection selection) { >@@ -73,46 +98,324 @@ > public void addPages() { > super.addPages(); > fPage2 = new NewTestCaseWizardPageTwo(); >- fPage1 = new NewTestCaseWizardPageOne(fPage2) { >- public void createControl(Composite parent) { >- super.createControl(parent); >- setSuperClass(SUPERCLASS_NAME, true); >- } >- >- protected IStatus validateIfJUnitProject() { >- IPackageFragmentRoot root = getPackageFragmentRoot(); >- if (root == null) >- return Status.OK_STATUS; >- >- IJavaProject project = root.getJavaProject(); >- try { >- for (int i = 0; i < CLASSES_TO_CHECK.length; i++) { >- IType type = project.findType(CLASSES_TO_CHECK[i]); >- if (type == null) { >- MessageDialog.openError(getShell(), >- Messages.NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary, >- NLS.bind(Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, REQUIRED_LIBRARIES)); >- return Status.OK_STATUS; >- } >- } >- } catch (JavaModelException e) { >- JavaServerUIPlugin.log(e); >- } >- return Status.OK_STATUS; >- } >- }; >+ fPage1 = new CactusPage1(fPage2); > addPage(fPage1); > fPage1.init(getSelection()); > addPage(fPage2); > > } >+ >+ private class CactusPage1 extends NewTestCaseWizardPageOne >+ { >+ >+ private Button fBeginButton; >+ private Button fEndButton; >+ private Button fBeginXXXButton; >+ private Button fEndXXXButton; >+ private Composite fCactusButtonComposite; >+ >+ public CactusPage1(NewTestCaseWizardPageTwo page2) { >+ super(page2); >+ >+ } >+ >+ public void init(IStructuredSelection selection) { >+ super.init(selection); >+ } >+ >+ public void createControl(Composite parent) { >+ super.createControl(parent); >+ setSuperClass(SUPERCLASS_NAME, true); >+ >+ >+ } >+ >+ protected IStatus superClassChanged() { >+ String superClassName= getSuperClass(); >+ if (superClassName == null || superClassName.trim().equals("")) { //$NON-NLS-1$ >+ Status status = new Status(IStatus.ERROR, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, Messages.NewServletTestCaseWizard_WarningMessageSuperclassIsEmpty, null); >+ return status; >+ } >+ >+ if (superClassName.equals("org.apache.cactus.ServletTestCase")){ >+ //Short-circuit if this IS ServletTestCase >+ return Status.OK_STATUS; >+ } >+ >+ if (getPackageFragmentRoot() != null) >+ { >+ IType type; >+ try { >+ type = resolveClassNameToType(getPackageFragmentRoot().getJavaProject(), getPackageFragment(), superClassName); >+ if (type == null) { >+ Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassDoesNotExist, null); >+ return status; >+ } >+ >+ >+ >+ if (type.isInterface()) { >+ Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassIsInterface, null); >+ return status; >+ } >+ >+ ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >+ IType [] superTypes = hierarchy.getAllSuperclasses(type); >+ for (int i=0; i<superTypes.length; i++) >+ { >+ if (superTypes[i].getFullyQualifiedName().equals("org.apache.cactus.ServletTestCase")) >+ { >+ return Status.OK_STATUS; >+ } >+ } >+ >+ Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassNotServletTestCase, null); >+ return status; >+ >+ } catch (JavaModelException e) { >+ JavaServerUIPlugin.log(e); >+ } >+ >+ } >+ >+ return Status.OK_STATUS; >+ } >+ >+ private IType resolveClassNameToType(IJavaProject jproject, IPackageFragment pack, String classToTestName) throws JavaModelException { >+ >+ IType type= jproject.findType(classToTestName); >+ >+ // search in current package >+ if (type == null && pack != null && !pack.isDefaultPackage()) { >+ type= jproject.findType(pack.getElementName(), classToTestName); >+ } >+ >+ // search in java.lang >+ if (type == null) { >+ type= jproject.findType("java.lang", classToTestName); //$NON-NLS-1$ >+ } >+ return type; >+ } >+ >+ protected IStatus validateIfJUnitProject() { >+ try { >+ if (checkForWebProject()) >+ { >+ checkForCactusLibraries(); >+ } >+ else >+ { >+ String msg = Messages.NewServletTestCaseWizard_WarningMessageSelectAWebProject; >+ MessageDialog.openWarning(getShell(), Messages.NewServletTestCaseWizard_WarningTitleWebProjectRequired, msg); >+ return new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, msg, null); >+ } >+ } catch (CoreException e) { >+ return new Status(Status.ERROR, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, "Failed to check for cactus libraries." ,e); >+ } >+ >+ return Status.OK_STATUS; >+ } >+ >+ protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException { >+ super.createTypeMembers(type, imports, monitor); >+ if (fBeginButton.getSelection()) >+ { >+ generateBeginMethod(type, imports); >+ } >+ >+ if (fEndButton.getSelection()) >+ { >+ generateEndMethod(type, imports); >+ } >+ >+ if (fBeginXXXButton.getSelection()) >+ { >+ generateBeginXXXMethods(type, imports); >+ } >+ >+ if (fEndXXXButton.getSelection()) >+ { >+ generateEndXXXMethods(type, imports); >+ } >+ >+ } >+ >+ private void generateBeginMethod(IType type, ImportsManager imports) >+ throws JavaModelException >+ { >+ StringBuilder methodBuffer = new StringBuilder(); >+ methodBuffer.append("public void begin("); //$NON-NLS-1$ >+ methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$ >+ methodBuffer.append(" request) throws "); //$NON-NLS-1$ >+ methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$ >+ methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$ >+ type.createMethod(methodBuffer.toString(), null, false, null); >+ } >+ >+ private void generateEndMethod(IType type, ImportsManager imports) >+ throws JavaModelException >+ { >+ StringBuilder methodBuffer = new StringBuilder(); >+ methodBuffer.append("public void end("); //$NON-NLS-1$ >+ methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$ >+ methodBuffer.append(" request) throws "); //$NON-NLS-1$ >+ methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$ >+ methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$ >+ type.createMethod(methodBuffer.toString(), null, false, null); >+ } >+ >+ private void generateBeginXXXMethods(IType type, ImportsManager imports) >+ throws JavaModelException >+ { >+ generateXXXMethods(type, imports, "begin"); //$NON-NLS-1$ >+ } >+ >+ private void generateXXXMethods(IType type, ImportsManager imports, String prefix) throws JavaModelException >+ { >+ IMethod [] testMethods = type.getMethods(); >+ for (int i=0; i<testMethods.length; i++) >+ { >+ IMethod testMethod = testMethods[i]; >+ String testMethodName = testMethod.getElementName(); >+ if (testMethodName.startsWith("test")) //$NON-NLS-1$ >+ { >+ String newMethodName = prefix + testMethodName.substring(4); >+ StringBuilder methodBuffer = new StringBuilder(); >+ methodBuffer.append("public void "); //$NON-NLS-1$ >+ methodBuffer.append(newMethodName); >+ methodBuffer.append("("); //$NON-NLS-1$ >+ methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$ >+ methodBuffer.append(" request) throws "); //$NON-NLS-1$ >+ methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$ >+ methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$ >+ type.createMethod(methodBuffer.toString(), testMethod, false, null); >+ >+ } >+ >+ } >+ } >+ >+ private void generateEndXXXMethods(IType type, ImportsManager imports) >+ throws JavaModelException >+ { >+ generateXXXMethods(type, imports, "end"); //$NON-NLS-1$ >+ } >+ >+ protected void createMethodStubSelectionControls(Composite composite, int nColumns) { >+ super.createMethodStubSelectionControls(composite, nColumns); >+ createEmptySpace(composite); >+ fCactusButtonComposite = new Composite(composite, SWT.NONE); >+ GridData gd = new GridData(); >+ gd.horizontalSpan = 3; >+ fCactusButtonComposite.setLayoutData(gd); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 1; >+ layout.marginWidth = layout.marginHeight = 0; >+ layout.makeColumnsEqualWidth = true; >+ fCactusButtonComposite.setLayout(layout); >+ >+ fBeginButton = createSelectionButton("begin()", fCactusButtonComposite); //$NON-NLS-1$ >+ fEndButton = createSelectionButton("end()", fCactusButtonComposite); //$NON-NLS-1$ >+ fBeginXXXButton = createSelectionButton("beginXXX() methods", fCactusButtonComposite); //$NON-NLS-1$ >+ fEndXXXButton = createSelectionButton("endXXX() methods", fCactusButtonComposite); //$NON-NLS-1$ >+ >+ } >+ >+ private Button createSelectionButton(String text, Composite group) { >+ Button button= new Button(group, SWT.CHECK | SWT.LEFT); >+ button.setFont(group.getFont()); >+ button.setText(text); >+ GridData data = new GridData(); >+ data.horizontalAlignment = SWT.BEGINNING; >+ data.verticalAlignment = GridData.CENTER; >+ button.setLayoutData(data); >+ return button; >+ } >+ >+ } >+ >+ private static Control createEmptySpace(Composite parent) { >+ return createEmptySpace(parent, 1); >+ } >+ >+ private static Control createEmptySpace(Composite parent, int span) { >+ Label label= new Label(parent, SWT.LEFT); >+ GridData gd= new GridData(); >+ gd.horizontalAlignment= GridData.BEGINNING; >+ gd.grabExcessHorizontalSpace= false; >+ gd.horizontalSpan= span; >+ gd.horizontalIndent= 0; >+ gd.widthHint= 0; >+ gd.heightHint= 0; >+ label.setLayoutData(gd); >+ return label; >+ } >+ > > private IStructuredSelection getSelection() { > return fSelection; > } >+ >+ private boolean checkForWebProject() throws CoreException >+ { >+ IPackageFragmentRoot root = fPage1.getPackageFragmentRoot(); >+ if (root == null) >+ return false; >+ >+ IJavaProject project = root.getJavaProject(); >+ IFacetedProject facetedProject = ProjectFacetsManager.create(project.getProject()); >+ if (facetedProject != null) >+ { >+ Iterator facets = facetedProject.getProjectFacets().iterator(); >+ while(facets.hasNext()) >+ { >+ IProjectFacetVersion facet = (IProjectFacetVersion) facets.next(); >+ if (facet.getProjectFacet().getId().equals("jst.web")) //$NON-NLS-1$ >+ { >+ return true; >+ } >+ >+ } >+ } >+ >+ return false; >+ } >+ >+ private void checkForCactusLibraries() >+ { >+ IPackageFragmentRoot root = fPage1.getPackageFragmentRoot(); >+ if (root == null) >+ return; >+ >+ IJavaProject project = root.getJavaProject(); >+ >+ List missingLibraries = new ArrayList(); >+ try { >+ for (int i = 0; i < CLASSES_TO_CHECK.length; i++) { >+ IType type = project.findType(CLASSES_TO_CHECK[i]); >+ if (type == null) { >+ missingLibraries.add(REQUIRED_LIBRARIES[i]); >+ } >+ } >+ >+ if (missingLibraries.size() > 0) >+ { >+ if (MessageDialog.openQuestion(getShell(), Messages.NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary, >+ NLS.bind(Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, missingLibraries.toArray()))) >+ { >+ CactusAddLibrariesProposal.installLibraries(project.getProject()); >+ } >+ } >+ >+ >+ } catch (JavaModelException e) { >+ JavaServerUIPlugin.log(e); >+ } >+ } > > public boolean performFinish() { > if (finishPage(fPage1.getRunnable())) { >+ > IType newClass = fPage1.getCreatedType(); > > IResource resource = newClass.getCompilationUnit().getResource(); >@@ -120,26 +423,12 @@ > BasicNewResourceWizard.selectAndReveal(resource, fWorkbench > .getActiveWorkbenchWindow()); > openResource(resource); >- // checkLibraryMissing(); > } > return true; > } > return false; > } > >- /*private void checkLibraryMissing() { >- IType newClass = fPage1.getCreatedType(); >- IJavaProject project = newClass.getJavaProject(); >- try { >- IType type = project.findType(SUPERCLASS_NAME); >- MessageDialog.openError(getShell(), NLS.bind( >- Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, REQUIRED_LIBRARIES), >- Messages.NewServletTestCaseWizard_ErrorMessageMissingType); >- } catch (JavaModelException e) { >- JavaServerUIPlugin.log(e); >- } >- }*/ >- > protected boolean finishPage(IRunnableWithProgress runnable) { > IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); > try { >@@ -148,7 +437,6 @@ > } catch (InvocationTargetException e) { > String title = Messages.NewServletTestCaseWizard_ErrorTitleNew; // NewJUnitWizard_op_error_title > String message = Messages.NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed; // NewJUnitWizard_op_error_message >- // ExceptionHandler.handle(e, shell, title, message); > displayMessageDialog(e, e.getMessage(), getShell(), title, message); > return false; > } catch (InterruptedException e) { >@@ -191,14 +479,14 @@ > } > } > >- public static IWorkbenchPage getActivePage() { >+ private static IWorkbenchPage getActivePage() { > IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow(); > if (activeWorkbenchWindow == null) > return null; > return activeWorkbenchWindow.getActivePage(); > } > >- public static IWorkbenchWindow getActiveWorkbenchWindow() { >+ private static IWorkbenchWindow getActiveWorkbenchWindow() { > IWorkbench workbench = JavaServerUIPlugin.getInstance().getWorkbench(); > if (workbench != null) > return workbench.getActiveWorkbenchWindow(); >Index: .settings/org.eclipse.jdt.core.prefs >=================================================================== >RCS file: .settings/org.eclipse.jdt.core.prefs >diff -N .settings/org.eclipse.jdt.core.prefs >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .settings/org.eclipse.jdt.core.prefs 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+#Wed Mar 22 09:05:23 PST 2006 >+eclipse.preferences.version=1 >+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled >+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 >+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve >+org.eclipse.jdt.core.compiler.compliance=1.4 >+org.eclipse.jdt.core.compiler.debug.lineNumber=generate >+org.eclipse.jdt.core.compiler.debug.localVariable=generate >+org.eclipse.jdt.core.compiler.debug.sourceFile=generate >+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning >+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning >+org.eclipse.jdt.core.compiler.source=1.3 >Index: .settings/org.eclipse.jdt.ui.prefs >=================================================================== >RCS file: .settings/org.eclipse.jdt.ui.prefs >diff -N .settings/org.eclipse.jdt.ui.prefs >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .settings/org.eclipse.jdt.ui.prefs 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,3 @@ >+#Wed Mar 22 09:05:22 PST 2006 >+eclipse.preferences.version=1 >+internal.default.compliance=default >Index: sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusAddLibrariesProposal.java >=================================================================== >RCS file: sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusAddLibrariesProposal.java >diff -N sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusAddLibrariesProposal.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusAddLibrariesProposal.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,123 @@ >+package org.eclipse.jst.server.ui.internal.cactus; >+ >+import java.io.File; >+import java.io.IOException; >+import java.net.URL; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.ui.text.java.IInvocationContext; >+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.contentassist.IContextInformation; >+import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.ui.actions.CopyFilesAndFoldersOperation; >+import org.eclipse.wst.common.componentcore.ComponentCore; >+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; >+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; >+import org.osgi.framework.Bundle; >+ >+public class CactusAddLibrariesProposal implements IJavaCompletionProposal { >+ >+ private final IInvocationContext fContext; >+ >+ public CactusAddLibrariesProposal(IInvocationContext context) { >+ fContext = context; >+ } >+ >+ public int getRelevance() { >+ return 0; >+ } >+ >+ public void apply(IDocument document) { >+ >+ ICompilationUnit javaFile = fContext.getCompilationUnit(); >+ installLibraries(javaFile.getJavaProject().getProject()); >+ >+ } >+ >+ public static void installLibraries(final IProject project) >+ { >+ >+ try >+ { >+ >+ Bundle bundle = Platform.getBundle("org.apache.cactus"); //$NON-NLS-1$ >+ if (bundle == null) >+ { >+ showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageCactusBundleNotFound")); //$NON-NLS-1$ >+ return; >+ } >+ URL cactusLibDir = Platform.find(bundle, new Path("lib")); //$NON-NLS-1$ >+ if (cactusLibDir == null) >+ { >+ showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageInstallDirNotFound")); //$NON-NLS-1$ >+ return; >+ } >+ URL localURL = Platform.asLocalURL(cactusLibDir); >+ final File sourceDirectory = new File(localURL.getPath()); >+ IVirtualComponent component = ComponentCore.createComponent(project); >+ IVirtualFolder vf = component.getRootFolder().getFolder( "WEB-INF/lib" ); //$NON-NLS-1$ >+ final IContainer destinationDirectory = vf.getUnderlyingFolder(); >+ >+ IFolder destinationFolder = project.getFolder(destinationDirectory.getProjectRelativePath()); >+ >+ if (destinationFolder.exists()) >+ { >+ File [] filesToCopy = sourceDirectory.listFiles(); >+ String [] filesToCopyNames = new String[filesToCopy.length]; >+ for (int i=0; i<filesToCopy.length; i++) >+ { >+ filesToCopyNames[i] = filesToCopy[i].getAbsolutePath(); >+ } >+ CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(JavaServerUIPlugin.getActiveWorkbenchShell()); >+ operation.copyFiles(filesToCopyNames, destinationFolder); >+ } >+ else >+ { >+ showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageDestDirNotFound")); //$NON-NLS-1$ >+ return; >+ } >+ >+ } >+ catch (IOException e) { >+ JavaServerUIPlugin.log(e); >+ showInstallFailedDialog(Messages.getString("CactusAddLibrariesProposal.ErrorMessageInstallationOfLibsFailed")); //$NON-NLS-1$ >+ >+ } >+ >+ } >+ >+ private static void showInstallFailedDialog(String message) >+ { >+ MessageDialog.openError(JavaServerUIPlugin.getActiveWorkbenchShell(), Messages.getString("CactusAddLibrariesProposal.ErrorMessageCouldntInstallLibraries"), message); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ >+ public Point getSelection(IDocument document) { >+ return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength()); >+ } >+ >+ public String getAdditionalProposalInfo() { >+ return Messages.getString("CactusAddLibrariesProposal.AdditionalInfoAddCactusLibraries"); //$NON-NLS-1$ >+ } >+ >+ public String getDisplayString() { >+ return Messages.getString("CactusAddLibrariesProposal.DisplayStringAddCactusLibs"); //$NON-NLS-1$ >+ } >+ >+ public Image getImage() { >+ return null; >+ } >+ >+ public IContextInformation getContextInformation() { >+ return null; >+ } >+ >+} >Index: sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusQuickFixProcessor.java >=================================================================== >RCS file: sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusQuickFixProcessor.java >diff -N sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusQuickFixProcessor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ sjavaui/org/eclipse/jst/server/ui/internal/cactus/CactusQuickFixProcessor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,70 @@ >+package org.eclipse.jst.server.ui.internal.cactus; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.jdt.core.IBuffer; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.compiler.IProblem; >+import org.eclipse.jdt.ui.text.java.IInvocationContext; >+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; >+import org.eclipse.jdt.ui.text.java.IProblemLocation; >+import org.eclipse.jdt.ui.text.java.IQuickFixProcessor; >+import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin; >+ >+public class CactusQuickFixProcessor implements IQuickFixProcessor { >+ >+ public boolean hasCorrections(ICompilationUnit unit, int problemId) { >+ return IProblem.ImportNotFound == problemId; >+ } >+ >+ public IJavaCompletionProposal[] getCorrections(IInvocationContext context, >+ IProblemLocation[] locations) throws CoreException { >+ if (isCactusProblem(context, locations)) >+ { >+ return new IJavaCompletionProposal[]{new CactusAddLibrariesProposal(context)}; >+ } >+ else >+ { >+ return new IJavaCompletionProposal[0]; >+ } >+ } >+ >+ private boolean isCactusProblem(IInvocationContext context, IProblemLocation[] locations) { >+ ICompilationUnit unit= context.getCompilationUnit(); >+ for (int i= 0; i < locations.length; i++) { >+ IProblemLocation location= locations[i]; >+ try { >+ String s= getStringUntilWhiteSpaceOrEnd(location.getOffset(), unit); >+ if ("ServletTestCase".equals(s) || s.contains("org.apache.cactus")) >+ { >+ return true; >+ } >+ } catch (JavaModelException e) { >+ JavaServerUIPlugin.log(e); >+ } >+ } >+ return false; >+ } >+ >+ private String getStringUntilWhiteSpaceOrEnd(int offset, ICompilationUnit unit) throws JavaModelException >+ { >+ StringBuilder builder = new StringBuilder(); >+ IBuffer buffer = unit.getBuffer(); >+ int length = buffer.getLength(); >+ >+ for (int index = offset; index<length ; index++) >+ { >+ char c = buffer.getChar(index); >+ if (Character.isWhitespace(c)) >+ { >+ return builder.toString(); >+ } >+ else >+ { >+ builder.append(c); >+ } >+ >+ } >+ return builder.toString(); >+ } >+} >Index: sjavaui/org/eclipse/jst/server/ui/internal/cactus/Messages.java >=================================================================== >RCS file: sjavaui/org/eclipse/jst/server/ui/internal/cactus/Messages.java >diff -N sjavaui/org/eclipse/jst/server/ui/internal/cactus/Messages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ sjavaui/org/eclipse/jst/server/ui/internal/cactus/Messages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,23 @@ >+package org.eclipse.jst.server.ui.internal.cactus; >+ >+import java.util.MissingResourceException; >+import java.util.ResourceBundle; >+ >+public class Messages { >+ private static final String BUNDLE_NAME = "org.eclipse.jst.server.ui.internal.Messages"; //$NON-NLS-1$ >+ >+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle >+ .getBundle(BUNDLE_NAME); >+ >+ private Messages() { >+ } >+ >+ public static String getString(String key) { >+ // TODO Auto-generated method stub >+ try { >+ return RESOURCE_BUNDLE.getString(key); >+ } catch (MissingResourceException e) { >+ return '!' + key + '!'; >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 104622
:
37246
|
37247
|
39084
|
39085
|
39090
|
40774
|
40788