Source Code Cross Referenced for SalmonFrameworkCreationWizard.java in  » J2EE » Sofia » com » salmonllc » ideTools » eclipse » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.ideTools.eclipse 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.ideTools.eclipse;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.lang.reflect.InvocationTargetException;
006:        import java.util.Hashtable;
007:        import java.util.StringTokenizer;
008:        import java.util.Vector;
009:
010:        import org.eclipse.core.resources.IFolder;
011:        import org.eclipse.core.resources.IProject;
012:        import org.eclipse.core.resources.IProjectDescription;
013:        import org.eclipse.core.resources.IResource;
014:        import org.eclipse.core.resources.IWorkspaceRoot;
015:        import org.eclipse.core.resources.ResourcesPlugin;
016:        import org.eclipse.core.runtime.CoreException;
017:        import org.eclipse.core.runtime.IConfigurationElement;
018:        import org.eclipse.core.runtime.IExecutableExtension;
019:        import org.eclipse.core.runtime.IProgressMonitor;
020:        import org.eclipse.core.runtime.NullProgressMonitor;
021:        import org.eclipse.core.runtime.Path;
022:        import org.eclipse.jdt.core.IClasspathEntry;
023:        import org.eclipse.jdt.core.IJavaProject;
024:        import org.eclipse.jdt.core.JavaCore;
025:        import org.eclipse.jdt.core.JavaModelException;
026:        import org.eclipse.jdt.internal.ui.JavaPlugin;
027:        import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
028:        import org.eclipse.jdt.launching.IVMInstall;
029:        import org.eclipse.jdt.launching.JavaRuntime;
030:        import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPage;
031:        import org.eclipse.jface.operation.IRunnableWithProgress;
032:        import org.eclipse.jface.preference.IPreferenceStore;
033:        import org.eclipse.jface.viewers.IStructuredSelection;
034:        import org.eclipse.swt.SWT;
035:        import org.eclipse.swt.widgets.MessageBox;
036:        import org.eclipse.swt.widgets.Shell;
037:        import org.eclipse.ui.IWorkbench;
038:        import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
039:        import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
040:        import com.salmonllc.ideTools.IDETool;
041:        import com.salmonllc.properties.Props;
042:
043:        /**
044:         * @author Administrator
045:         *
046:         * To change this generated comment edit the template variable "typecomment":
047:         * Window>Preferences>Java>Templates.
048:         * To enable and disable the creation of type comments go to
049:         * Window>Preferences>Java>Code Generation.
050:         */
051:        public class SalmonFrameworkCreationWizard extends NewElementWizard
052:                implements  IExecutableExtension {
053:
054:            private SalmonWizardNewProjectCreationPage _mainPage;
055:            private SalmonFrameworkCreationWizardPage _sofiaPage;
056:            private SalmonFrameworkUpgradeWizardPage _upgradePage;
057:            private NewJavaProjectWizardPage _javaPage;
058:            private IConfigurationElement _configElement;
059:            private boolean _inError = false;
060:            private boolean _doUpgrade = false;
061:            private IProject _currentProject;
062:
063:            /**
064:             * Constructor for SalmonProjectCreationWizard.
065:             */
066:            public SalmonFrameworkCreationWizard() {
067:                super ();
068:            }
069:
070:            public void init(IWorkbench workbench,
071:                    IStructuredSelection selection) {
072:                IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
073:                IProject[] p = root.getProjects();
074:                _inError = false;
075:                _doUpgrade = false;
076:
077:                IVMInstall vm = JavaRuntime.getDefaultVMInstall();
078:                File f = vm.getInstallLocation();
079:                if (!SalmonPlugin.isMacOS()) {
080:                    File toolsJar = new File(f.getAbsolutePath()
081:                            + File.separator + "lib" + File.separator
082:                            + "tools.jar");
083:                    if (!toolsJar.exists()) {
084:                        MessageBox box = new MessageBox(new Shell(),
085:                                SWT.ICON_ERROR | SWT.OK | SWT.SYSTEM_MODAL);
086:                        box.setText("JDK not found.");
087:                        box
088:                                .setMessage("The Java Runtime Environment being used by Eclipse is not a full Java Development Kit. A Full JDK is required to run SOFIA. Please change the JRE to a JDK under Window->Preferences->Java->Installed JRE's and then try this operation again.");
089:                        box.open();
090:                        _inError = true;
091:                        return;
092:                    }
093:                }
094:
095:                try {
096:                    for (int i = 0; i < p.length; i++) {
097:                        if (p[i].isOpen()) {
098:                            if (p[i]
099:                                    .hasNature(SalmonPlugin.NATURE_SOFIA_FRAMEWORK)) {
100:                                _currentProject = p[i];
101:                                _doUpgrade = true;
102:                                return;
103:                            }
104:                        }
105:                    }
106:                } catch (Exception e) {
107:                }
108:
109:            }
110:
111:            /**
112:             * @see org.eclipse.jface.wizard.IWizard#performFinish()
113:             */
114:            public boolean performFinish() {
115:                IRunnableWithProgress op1 = new WorkspaceModifyDelegatingOperation(
116:                        _javaPage.getRunnable());
117:                IRunnableWithProgress op2 = new WorkspaceModifyDelegatingOperation(
118:                        getRunnable());
119:                try {
120:                    if (!_doUpgrade)
121:                        getContainer().run(false, true, op1);
122:                    getContainer().run(false, true, op2);
123:                } catch (Exception e) {
124:                    e.printStackTrace();
125:                }
126:
127:                return true;
128:            }
129:
130:            public void addPages() {
131:                super .addPages();
132:                if (_inError) {
133:                    return;
134:                }
135:
136:                _mainPage = new SalmonWizardNewProjectCreationPage("Page 1",
137:                        "Salmon Open Framework",
138:                        "Create a project in the workspace with the SOFIA classes");
139:                _mainPage
140:                        .setTitle("Install The Salmon Open Framework for Internet Applications (SOFIA)");
141:                _upgradePage = new SalmonFrameworkUpgradeWizardPage(
142:                        "Page1",
143:                        "A Salmon Framework Project already exists in your workspace. Would you like to do an upgrade?");
144:                _upgradePage
145:                        .setTitle("Install The Salmon Open Framework for Internet Applications (SOFIA)");
146:
147:                if (!_doUpgrade)
148:                    addPage(_mainPage);
149:                else
150:                    addPage(_upgradePage);
151:
152:                _sofiaPage = new SalmonFrameworkCreationWizardPage("Page 2",
153:                        true);
154:                _sofiaPage.setTitle("SOFIA Framework Options");
155:                _sofiaPage
156:                        .setDescription("Set up options for installing the Salmon Open Framework project");
157:
158:                addPage(_sofiaPage);
159:
160:                IWorkspaceRoot root = JavaPlugin.getWorkspace().getRoot();
161:                _javaPage = new NewJavaProjectWizardPage(root, _mainPage);
162:            }
163:
164:            public void setInitializationData(IConfigurationElement cfig,
165:                    String propertyName, Object data) {
166:                _configElement = cfig;
167:            }
168:
169:            private IFolder createFolder(IFolder parent, String newFolder)
170:                    throws CoreException {
171:                IFolder ret = parent.getFolder(newFolder);
172:                ret.create(false, true, null);
173:                return ret;
174:            }
175:
176:            private IFolder createFolder(IProject parent, String newFolder)
177:                    throws CoreException {
178:                IFolder ret = parent.getFolder(newFolder);
179:                ret.create(false, true, null);
180:                return ret;
181:            }
182:
183:            private void clearSourceEntries(IJavaProject project)
184:                    throws CoreException {
185:                IClasspathEntry[] entries = project.getRawClasspath();
186:                Vector v = new Vector(entries.length);
187:                for (int i = 0; i < entries.length; i++) {
188:                    if (entries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE)
189:                        v.add(entries[i]);
190:                }
191:                IClasspathEntry[] newEntries = new IClasspathEntry[v.size()];
192:                v.copyInto(newEntries);
193:                project.setRawClasspath(newEntries, null);
194:            }
195:
196:            private void addSourceEntry(IJavaProject project, IFolder f)
197:                    throws CoreException {
198:                IClasspathEntry[] entries = project.getRawClasspath();
199:                IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
200:                System.arraycopy(entries, 0, newEntries, 0, entries.length);
201:                newEntries[entries.length] = JavaCore.newSourceEntry(f
202:                        .getFullPath());
203:                project.setRawClasspath(newEntries, null);
204:            }
205:
206:            private void addNatureEntry(IProject project) {
207:                try {
208:                    //Add a nature to this project
209:                    IProjectDescription description = project.getDescription();
210:                    String[] natures = description.getNatureIds();
211:                    String[] newNatures = new String[natures.length + 1];
212:                    System.arraycopy(natures, 0, newNatures, 0, natures.length);
213:                    newNatures[natures.length] = SalmonPlugin.NATURE_SOFIA_FRAMEWORK;
214:                    description.setNatureIds(newNatures);
215:
216:                    project.setDescription(description, null);
217:                } catch (CoreException e) {
218:                    e.printStackTrace();
219:                }
220:            }
221:
222:            private void addNewJarsToClassPath(IJavaProject[] proj) {
223:                IClasspathEntry[] entriesToAdd = new IClasspathEntry[1];
224:                String dir = _sofiaPage.getTomcatHome();
225:                entriesToAdd[0] = JavaCore.newLibraryEntry(new Path(dir
226:                        + File.separator + "common" + File.separator + "lib"
227:                        + File.separator + "portlet-api-1.0.jar"), null, null);
228:                Vector vect = new Vector();
229:
230:                for (int i = 0; i < proj.length; i++) {
231:                    try {
232:                        IClasspathEntry[] entries = proj[i].getRawClasspath();
233:                        for (int j = 0; j < entriesToAdd.length; j++) {
234:                            //don't add it if it is already there
235:                            boolean found = false;
236:                            for (int k = 0; k < entries.length; k++) {
237:                                if (entriesToAdd[j].equals(entries[k])) {
238:                                    found = true;
239:                                    break;
240:                                }
241:                            }
242:                            if (!found)
243:                                vect.add(entriesToAdd[j]);
244:                        }
245:                        if (vect.size() > 0) {
246:                            IClasspathEntry[] newEntries = new IClasspathEntry[entries.length
247:                                    + vect.size()];
248:                            System.arraycopy(entries, 0, newEntries, 0,
249:                                    entries.length);
250:                            int index = entries.length;
251:                            for (int j = 0; j < vect.size(); j++)
252:                                newEntries[index++] = (IClasspathEntry) vect
253:                                        .elementAt(j);
254:
255:                            proj[i].setRawClasspath(newEntries, null);
256:                            vect.setSize(0);
257:                        }
258:
259:                    } catch (JavaModelException e) {
260:                        e.printStackTrace();
261:                    }
262:
263:                }
264:
265:            }
266:
267:            private void addServerJarsToClassPath(IJavaProject project,
268:                    boolean tomcat40, boolean tomcat50) {
269:                try {
270:                    String dir = _sofiaPage.getTomcatHome();
271:                    IClasspathEntry[] entries = project.getRawClasspath();
272:                    if (tomcat50) {
273:                        boolean jmxJarExists = new File(dir + File.separator
274:                                + "bin" + File.separator + "jmx.jar").exists();
275:                        int len = jmxJarExists ? 13 : 12;
276:                        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length
277:                                + len];
278:                        System.arraycopy(entries, 0, newEntries, 0,
279:                                entries.length);
280:                        newEntries[entries.length] = JavaCore.newLibraryEntry(
281:                                new Path(dir + File.separator + "bin"
282:                                        + File.separator + "bootstrap.jar"),
283:                                null, null);
284:                        newEntries[entries.length + 1] = JavaCore
285:                                .newLibraryEntry(new Path(dir + File.separator
286:                                        + "bin" + File.separator
287:                                        + "commons-daemon.jar"), null, null);
288:                        newEntries[entries.length + 2] = JavaCore
289:                                .newLibraryEntry(new Path(dir + File.separator
290:                                        + "bin" + File.separator
291:                                        + "commons-launcher.jar"), null, null);
292:                        newEntries[entries.length + 3] = JavaCore
293:                                .newLibraryEntry(new Path(dir + File.separator
294:                                        + "bin" + File.separator
295:                                        + "commons-logging-api.jar"), null,
296:                                        null);
297:                        newEntries[entries.length + 4] = JavaCore
298:                                .newLibraryEntry(new Path(dir + File.separator
299:                                        + "server" + File.separator + "lib"
300:                                        + File.separator + "catalina.jar"),
301:                                        null, null);
302:                        newEntries[entries.length + 5] = JavaCore
303:                                .newLibraryEntry(new Path(dir + File.separator
304:                                        + "common" + File.separator + "lib"
305:                                        + File.separator + "mail.jar"), null,
306:                                        null);
307:                        newEntries[entries.length + 6] = JavaCore
308:                                .newLibraryEntry(new Path(dir + File.separator
309:                                        + "common" + File.separator + "lib"
310:                                        + File.separator + "activation.jar"),
311:                                        null, null);
312:                        newEntries[entries.length + 7] = JavaCore
313:                                .newLibraryEntry(new Path(dir + File.separator
314:                                        + "common" + File.separator + "lib"
315:                                        + File.separator + "servlet-api.jar"),
316:                                        null, null);
317:                        newEntries[entries.length + 8] = JavaCore
318:                                .newLibraryEntry(new Path(dir + File.separator
319:                                        + "common" + File.separator + "lib"
320:                                        + File.separator + "jsp-api.jar"),
321:                                        null, null);
322:                        newEntries[entries.length + 9] = JavaCore
323:                                .newLibraryEntry(new Path(dir + File.separator
324:                                        + "common" + File.separator + "lib"
325:                                        + File.separator
326:                                        + "portlet-api-1.0.jar"), null, null);
327:                        newEntries[entries.length + 10] = JavaCore
328:                                .newLibraryEntry(new Path(dir + File.separator
329:                                        + "server" + File.separator + "lib"
330:                                        + File.separator
331:                                        + "commons-digester.jar"), null, null);
332:                        newEntries[entries.length + 11] = JavaCore
333:                                .newLibraryEntry(new Path(dir + File.separator
334:                                        + "server" + File.separator + "lib"
335:                                        + File.separator + "tomcat-util.jar"),
336:                                        null, null);
337:                        if (jmxJarExists)
338:                            newEntries[entries.length + 12] = JavaCore
339:                                    .newLibraryEntry(new Path(dir
340:                                            + File.separator + "bin"
341:                                            + File.separator + "jmx.jar"),
342:                                            null, null);
343:
344:                        project.setRawClasspath(newEntries, null);
345:                    } else if (tomcat40) {
346:                        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 5];
347:                        System.arraycopy(entries, 0, newEntries, 0,
348:                                entries.length);
349:                        newEntries[entries.length] = JavaCore.newLibraryEntry(
350:                                new Path(dir + File.separator + "server"
351:                                        + File.separator + "lib"
352:                                        + File.separator + "catalina.jar"),
353:                                null, null);
354:                        newEntries[entries.length + 1] = JavaCore
355:                                .newLibraryEntry(new Path(dir + File.separator
356:                                        + "common" + File.separator + "lib"
357:                                        + File.separator + "mail.jar"), null,
358:                                        null);
359:                        newEntries[entries.length + 2] = JavaCore
360:                                .newLibraryEntry(new Path(dir + File.separator
361:                                        + "common" + File.separator + "lib"
362:                                        + File.separator + "activation.jar"),
363:                                        null, null);
364:                        newEntries[entries.length + 3] = JavaCore
365:                                .newLibraryEntry(new Path(dir + File.separator
366:                                        + "common" + File.separator + "lib"
367:                                        + File.separator + "servlet.jar"),
368:                                        null, null);
369:                        newEntries[entries.length + 4] = JavaCore
370:                                .newLibraryEntry(new Path(dir + File.separator
371:                                        + "common" + File.separator + "lib"
372:                                        + File.separator
373:                                        + "portlet-api-1.0.jar"), null, null);
374:                        project.setRawClasspath(newEntries, null);
375:                    } else {
376:                        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 8];
377:                        System.arraycopy(entries, 0, newEntries, 0,
378:                                entries.length);
379:                        newEntries[entries.length] = JavaCore.newLibraryEntry(
380:                                new Path(dir + File.separator + "server"
381:                                        + File.separator + "lib"
382:                                        + File.separator + "catalina.jar"),
383:                                null, null);
384:                        newEntries[entries.length + 1] = JavaCore
385:                                .newLibraryEntry(new Path(dir + File.separator
386:                                        + "common" + File.separator + "lib"
387:                                        + File.separator + "mail.jar"), null,
388:                                        null);
389:                        newEntries[entries.length + 2] = JavaCore
390:                                .newLibraryEntry(new Path(dir + File.separator
391:                                        + "common" + File.separator + "lib"
392:                                        + File.separator + "activation.jar"),
393:                                        null, null);
394:                        newEntries[entries.length + 3] = JavaCore
395:                                .newLibraryEntry(new Path(dir + File.separator
396:                                        + "common" + File.separator + "lib"
397:                                        + File.separator + "servlet.jar"),
398:                                        null, null);
399:                        newEntries[entries.length + 4] = JavaCore
400:                                .newLibraryEntry(new Path(dir + File.separator
401:                                        + "common" + File.separator + "lib"
402:                                        + File.separator
403:                                        + "portlet-api-1.0.jar"), null, null);
404:                        newEntries[entries.length + 5] = JavaCore
405:                                .newLibraryEntry(new Path(dir + File.separator
406:                                        + "server" + File.separator + "lib"
407:                                        + File.separator
408:                                        + "commons-digester.jar"), null, null);
409:                        newEntries[entries.length + 6] = JavaCore
410:                                .newLibraryEntry(new Path(dir + File.separator
411:                                        + "server" + File.separator + "lib"
412:                                        + File.separator + "tomcat-util.jar"),
413:                                        null, null);
414:                        newEntries[entries.length + 7] = JavaCore
415:                                .newLibraryEntry(new Path(dir + File.separator
416:                                        + "bin" + File.separator
417:                                        + "bootstrap.jar"), null, null);
418:                        project.setRawClasspath(newEntries, null);
419:
420:                    }
421:
422:                } catch (Exception e) {
423:                    e.printStackTrace();
424:                }
425:            }
426:
427:            private String replace(String sString, String sOldString,
428:                    String sNewString) {
429:                StringBuffer sbString = new StringBuffer(sString);
430:                while (true) {
431:                    int iIndex = sbString.toString().indexOf(sOldString);
432:                    if (iIndex < 0)
433:                        break;
434:                    sbString.replace(iIndex, iIndex + sOldString.length(),
435:                            sNewString);
436:                }
437:                return sbString.toString();
438:            }
439:
440:            private String doubleSlash(String in) {
441:                StringBuffer sb = new StringBuffer(in.length());
442:                for (int i = 0; i < in.length(); i++) {
443:                    char c = in.charAt(i);
444:                    if (c == '\\')
445:                        sb.append("\\\\");
446:                    else
447:                        sb.append(c);
448:                }
449:                return sb.toString();
450:            }
451:
452:            private void setUpPreferences(IFolder propertiesFolder) {
453:                IPreferenceStore pref = SalmonPlugin.getEclipsePreferences();
454:                pref.putValue(SalmonPlugin.PREF_SALMON_PROPS_PATH,
455:                        propertiesFolder.getLocation().toOSString());
456:                if (!pref.contains(SalmonPlugin.PREF_SAVE_ON_BROWSER_RUN))
457:                    pref.setValue(SalmonPlugin.PREF_SAVE_ON_BROWSER_RUN, true);
458:                if (!pref.contains(SalmonPlugin.PREF_ASK_SAVE_ON_BROWSER_RUN))
459:                    pref.setValue(SalmonPlugin.PREF_ASK_SAVE_ON_BROWSER_RUN,
460:                            false);
461:                if (!pref.contains(SalmonPlugin.PREF_RESTART_SERVER_EACH_RUN))
462:                    pref.setValue(SalmonPlugin.PREF_RESTART_SERVER_EACH_RUN,
463:                            true);
464:                if (!pref
465:                        .contains(SalmonPlugin.PREF_CHANGE_DEFAULT_ON_SELECTION))
466:                    pref
467:                            .setValue(
468:                                    SalmonPlugin.PREF_CHANGE_DEFAULT_ON_SELECTION,
469:                                    true);
470:            }
471:
472:            private void copySystemPropertiesFile(IFolder propsFolder) {
473:                try {
474:                    File inFile = new File(SalmonPlugin
475:                            .getSourceSystemProperties(_sofiaPage
476:                                    .getTomcatHome(), false, false));
477:                    File outFile = new File(propsFolder.getLocation()
478:                            .toOSString()
479:                            + File.separator + "System.properties");
480:                    IDETool.copyFile(inFile, outFile);
481:                } catch (Exception e) {
482:                    e.printStackTrace();
483:                }
484:            }
485:
486:            private void copyFrameworkClasses(IFolder javaFolder) {
487:                try {
488:                    File inFile = new File(_sofiaPage.getSOFIAHome()
489:                            + File.separator + "SourceCode" + File.separator
490:                            + "Framework");
491:                    File outFile = new File(javaFolder.getLocation()
492:                            .toOSString());
493:                    IDETool.copyDirectory(inFile, outFile);
494:                } catch (Exception e) {
495:                    e.printStackTrace();
496:                }
497:            }
498:
499:            private void updateTomcatClasses(IFolder javaFolder,
500:                    boolean tomcat40, boolean tomcat50) {
501:                File ideToolsDir = new File(javaFolder.getLocation()
502:                        .toOSString()
503:                        + File.separator
504:                        + "com"
505:                        + File.separator
506:                        + "salmonllc"
507:                        + File.separator + "ideTools");
508:                File javaDir = new File(javaFolder.getLocation().toOSString());
509:
510:                //First delete any tomcat classes in there already
511:                File[] list = ideToolsDir.listFiles();
512:                for (int i = 0; i < list.length; i++) {
513:                    String name = list[i].getName();
514:                    if (name.startsWith("Tomcat")
515:                            && !name.equals("TomcatBootstrap.java"))
516:                        deleteFile(list[i]);
517:
518:                }
519:
520:                String frameworkDir = _sofiaPage.getSOFIAHome()
521:                        + File.separator + "Resources" + File.separator;
522:                if (isTomcat40())
523:                    frameworkDir += "Tomcat40";
524:                else if (isTomcat50())
525:                    frameworkDir += "Tomcat50";
526:                else
527:                    frameworkDir += "Tomcat41";
528:                frameworkDir += File.separator + "Source";
529:
530:                try {
531:                    IDETool.copyDirectory(new File(frameworkDir), javaDir);
532:                } catch (IOException e) {
533:                    e.printStackTrace();
534:                }
535:            }
536:
537:            private void updateFrameworkClasses(IJavaProject proj,
538:                    IFolder javaFolder, boolean tomcat40, boolean tomcat50) {
539:
540:                try {
541:                    //boolean oldTomcat40 = true;
542:                    Props p = SalmonPlugin.getSystemProps();
543:                    //String oldServerType = p.getProperty(Props.IDE_SERVER_TYPE);
544:                    //if (!oldServerType.equals(IDETool.SERVER_TOMCAT40)) 
545:                    //	oldTomcat40 = false;					
546:                    //String oldTomcatPath=p.getProperty(Props.IDE_TOMCAT_PATH);
547:
548:                    File folder = new File(javaFolder.getLocation()
549:                            .toOSString());
550:                    File list[] = folder.listFiles();
551:                    for (int i = 0; i < list.length; i++) {
552:                        deleteFile(list[i]);
553:                    }
554:
555:                    File inFile = new File(_sofiaPage.getSOFIAHome()
556:                            + File.separator + "SourceCode" + File.separator
557:                            + "Framework");
558:                    IDETool.copyDirectory(inFile, folder);
559:                    updateTomcatClasses(javaFolder, tomcat40, tomcat50);
560:
561:                    //update the System.properties and add any new properties
562:                    Props.mergeSystemProperties(SalmonPlugin
563:                            .getSourceSystemProperties(_sofiaPage
564:                                    .getTomcatHome(), false, false));
565:
566:                    //set up new classpath and jars
567:                    setUpSystemProperties(tomcat40, tomcat50, true, false);
568:                    removeOldServerJarsFromProjectClassPath(proj);
569:                    addServerJarsToClassPath(proj, tomcat40, tomcat50);
570:
571:                } catch (Exception e) {
572:                    e.printStackTrace();
573:                }
574:            }
575:
576:            private void removeOldServerJarsFromProjectClassPath(
577:                    IJavaProject project) {
578:                try {
579:                    String serverJars[] = new String[14];
580:                    serverJars[0] = "server" + File.separator + "lib"
581:                            + File.separator + "catalina.jar";
582:                    serverJars[1] = "server" + File.separator + "lib"
583:                            + File.separator + "commons-digester.jar";
584:                    serverJars[2] = "server" + File.separator + "lib"
585:                            + File.separator + "tomcat-util.jar";
586:                    serverJars[3] = "common" + File.separator + "lib"
587:                            + File.separator + "mail.jar";
588:                    serverJars[4] = "common" + File.separator + "lib"
589:                            + File.separator + "activation.jar";
590:                    serverJars[5] = "common" + File.separator + "lib"
591:                            + File.separator + "servlet.jar";
592:                    serverJars[6] = "common" + File.separator + "lib"
593:                            + File.separator + "portlet-api-1.0.jar";
594:                    serverJars[7] = "common" + File.separator + "lib"
595:                            + File.separator + "servlet-api.jar";
596:                    serverJars[8] = "common" + File.separator + "lib"
597:                            + File.separator + "jsp-api.jar";
598:                    serverJars[9] = "bin" + File.separator
599:                            + "commons-daemon.jar";
600:                    serverJars[10] = "bin" + File.separator
601:                            + "commons-launcher.jar";
602:                    serverJars[11] = "bin" + File.separator
603:                            + "commons-logging-api.jar";
604:                    serverJars[12] = "bin" + File.separator + "jmx.jar";
605:                    serverJars[13] = "bin" + File.separator + "bootstrap.jar";
606:
607:                    IClasspathEntry[] entries = project.getRawClasspath();
608:                    Vector v = new Vector(entries.length);
609:                    for (int i = 0; i < entries.length; i++) {
610:                        String test = entries[i].getPath().toOSString()
611:                                .toLowerCase();
612:                        boolean include = true;
613:                        for (int j = 0; j < serverJars.length; j++) {
614:                            if (test.endsWith(serverJars[j])) {
615:                                include = false;
616:                                break;
617:                            }
618:                        }
619:
620:                        if (include)
621:                            v.add(entries[i]);
622:                    }
623:                    IClasspathEntry[] newEntries = new IClasspathEntry[v.size()];
624:                    v.copyInto(newEntries);
625:                    project.setRawClasspath(newEntries, null);
626:                } catch (Exception e) {
627:                    e.printStackTrace();
628:                }
629:            }
630:
631:            private void deleteFile(File f) {
632:                if (f.isDirectory()) {
633:                    File list[] = f.listFiles();
634:                    for (int i = 0; i < list.length; i++) {
635:                        deleteFile(list[i]);
636:                    }
637:                }
638:                f.delete();
639:            }
640:
641:            private void setUpSystemProperties(boolean tomcat40,
642:                    boolean tomcat50, boolean updateClassPath,
643:                    boolean updatePropertyLocation) throws IOException {
644:                //Sets up system properties for Tomcat 4.0 or Tomcat 4.1
645:
646:                Props p = SalmonPlugin.getSystemProps();
647:
648:                Hashtable changes = new Hashtable();
649:
650:                //add classpath--------------
651:                String classPath = "";
652:                //tools.jar (not on Mac/OS)
653:                if (!SalmonPlugin.isMacOS()) {
654:                    IVMInstall vm = JavaRuntime.getDefaultVMInstall();
655:                    File f = vm.getInstallLocation();
656:                    classPath += f.getAbsolutePath() + File.separator + "lib"
657:                            + File.separator + "tools.jar" + File.pathSeparator;
658:                }
659:
660:                if (tomcat40) {
661:                    //only include the bootstrap.jar from the bin directory for tomcat 4.0
662:                    classPath += _sofiaPage.getTomcatHome() + File.separator
663:                            + "bin" + File.separator + "bootstrap.jar"
664:                            + File.pathSeparator;
665:                } else {
666:                    //include all the jars tomcat/bin directory for tomcat 4.1
667:                    File binDir = new File(_sofiaPage.getTomcatHome()
668:                            + File.separator + "bin");
669:                    File[] binDirFiles = binDir.listFiles();
670:                    if (binDirFiles != null) {
671:                        for (int i = 0; i < binDirFiles.length; i++) {
672:                            String path = binDirFiles[i].getAbsolutePath();
673:                            if (path.endsWith(".jar"))
674:                                classPath += path + File.pathSeparator;
675:                        }
676:                    }
677:
678:                }
679:
680:                //tomcat/common/lib directory
681:                File comDir = new File(_sofiaPage.getTomcatHome()
682:                        + File.separator + "common" + File.separator + "lib");
683:                File[] comDirFiles = comDir.listFiles();
684:                if (comDirFiles != null) {
685:                    for (int i = 0; i < comDirFiles.length; i++) {
686:                        String path = comDirFiles[i].getAbsolutePath();
687:                        if (!path.endsWith("salmon.jar"))
688:                            classPath += path + File.pathSeparator;
689:                    }
690:                }
691:
692:                //tomcat/server/lib directory
693:                File serverDir = new File(_sofiaPage.getTomcatHome()
694:                        + File.separator + "server" + File.separator + "lib");
695:                File[] serverDirFiles = serverDir.listFiles();
696:                if (serverDirFiles != null) {
697:                    for (int i = 0; i < serverDirFiles.length; i++)
698:                        classPath += serverDirFiles[i].getAbsolutePath()
699:                                + File.pathSeparator;
700:                }
701:
702:                //jdbc jar file
703:                if (_sofiaPage.getJDBCJar().length() > 0)
704:                    classPath += _sofiaPage.getJDBCJar();
705:
706:                //if we are doing an upgrade, leave old jars in the classpath, put them at the end just in case
707:                if (updateClassPath) {
708:                    String oldClassPath = SalmonPlugin.getSystemProps()
709:                            .getProperty(Props.IDE_CLASSPATH);
710:                    if (oldClassPath != null) {
711:                        StringTokenizer stok = new StringTokenizer(
712:                                oldClassPath, File.pathSeparator);
713:                        while (stok.hasMoreTokens()) {
714:                            String tok = stok.nextToken() + File.pathSeparator;
715:                            if (classPath.indexOf(tok) == -1)
716:                                classPath += tok;
717:                        }
718:                    }
719:                }
720:                changes.put(Props.IDE_CLASSPATH, classPath);
721:                //end classpath-----------
722:
723:                //VM Arguments
724:                String vmArgs = "-Dcatalina.home=\""
725:                        + _sofiaPage.getTomcatHome() + "\" -Djava.io.tmpdir=\""
726:                        + _sofiaPage.getTomcatHome() + File.separator
727:                        + "temp\"";
728:                changes.put(Props.IDE_VMARGS, vmArgs);
729:
730:                //Server Working Directory
731:                changes.put(Props.IDE_WORKING_DIRECTORY, _sofiaPage
732:                        .getTomcatHome());
733:
734:                //Server Config File
735:                String serverConfigFile = _sofiaPage.getTomcatHome()
736:                        + File.separator + "conf" + File.separator
737:                        + "server.xml";
738:                changes.put(Props.IDE_SERVER_CONFIG_FILE, serverConfigFile);
739:
740:                //Server Type
741:                if (tomcat40)
742:                    changes.put(Props.IDE_SERVER_TYPE, IDETool.SERVER_TOMCAT40);
743:                else if (tomcat50)
744:                    changes.put(Props.IDE_SERVER_TYPE, IDETool.SERVER_TOMCAT50);
745:                else
746:                    changes.put(Props.IDE_SERVER_TYPE, IDETool.SERVER_TOMCAT41);
747:
748:                if (updatePropertyLocation) {
749:                    if (SalmonPlugin
750:                            .arePropsInSourceApplicationPaths(_sofiaPage
751:                                    .getTomcatHome()))
752:                        changes.put(Props.IDE_USE_APP_PROPERTIES, "true");
753:                    else
754:                        changes.put(Props.IDE_USE_APP_PROPERTIES, "false");
755:                }
756:
757:                //Set the framework resources path
758:                changes.put(Props.IDE_FRAMEWORK_RESOURCES_PATH, _sofiaPage
759:                        .getSOFIAHome()
760:                        + File.separator + "Resources");
761:
762:                //save the changes
763:                Props.updateSystemProperties(changes);
764:            }
765:
766:            public IRunnableWithProgress getRunnable() {
767:                return new IRunnableWithProgress() {
768:                    public void run(IProgressMonitor monitor)
769:                            throws InvocationTargetException,
770:                            InterruptedException {
771:                        if (monitor == null)
772:                            monitor = new NullProgressMonitor();
773:                        monitor.beginTask("Building Framework Project", 10);
774:                        try {
775:                            if (!_doUpgrade) {
776:                                IJavaProject javaProj = _javaPage
777:                                        .getNewJavaProject();
778:                                IProject proj = javaProj.getProject();
779:                                boolean isTomcat40 = isTomcat40();
780:                                boolean isTomcat50 = isTomcat50();
781:
782:                                //First clear out the old source entries. There is a blank one that causes a lot of trouble			
783:                                clearSourceEntries(javaProj);
784:
785:                                //Create a bin folder for the output
786:                                IFolder binFolder = createFolder(proj, "bin");
787:                                javaProj.setOutputLocation(binFolder
788:                                        .getFullPath(), null);
789:
790:                                //Create a Java folder for the Java source
791:                                IFolder javaFolder = createFolder(proj, "Java");
792:                                addSourceEntry(javaProj, javaFolder);
793:
794:                                //Create a properties folder for the properties file
795:                                IFolder propertiesFolder = createFolder(proj,
796:                                        "properties");
797:
798:                                //Add the Salmon Project Nature to the project and add the Salmon project to the classpath
799:                                addNatureEntry(proj);
800:
801:                                //set up the preferences
802:                                setUpPreferences(propertiesFolder);
803:
804:                                //add server jars to class path
805:                                addServerJarsToClassPath(javaProj, isTomcat40,
806:                                        isTomcat50);
807:
808:                                //copy the java classes for the framework
809:                                copyFrameworkClasses(javaFolder);
810:                                updateTomcatClasses(javaFolder, isTomcat40,
811:                                        isTomcat50);
812:
813:                                //copy the System.properties file
814:                                copySystemPropertiesFile(propertiesFolder);
815:
816:                                //set up the properties
817:                                setUpSystemProperties(isTomcat40, isTomcat50,
818:                                        false, false);
819:
820:                                //Refresh the project to get all the copied files
821:                                proj.refreshLocal(IResource.DEPTH_INFINITE,
822:                                        null);
823:
824:                                BasicNewProjectResourceWizard
825:                                        .updatePerspective(_configElement);
826:                            } else {
827:                                IJavaProject javaProj = JavaCore
828:                                        .create(_currentProject);
829:                                IClasspathEntry[] entries = javaProj
830:                                        .getRawClasspath();
831:                                for (int i = 0; i < entries.length; i++) {
832:                                    if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
833:                                        IFolder fol = _currentProject
834:                                                .getFolder(entries[i].getPath()
835:                                                        .lastSegment());
836:                                        updateFrameworkClasses(javaProj, fol,
837:                                                isTomcat40(), isTomcat50());
838:                                        break;
839:                                    }
840:                                }
841:
842:                                //add any extra jars to existing projects
843:                                IJavaProject sofiaProjs[] = SalmonPlugin
844:                                        .getFrameworkProjects();
845:                                addNewJarsToClassPath(sofiaProjs);
846:
847:                                //Refresh the project to get all the copied files
848:                                _currentProject.refreshLocal(
849:                                        IResource.DEPTH_INFINITE, null);
850:
851:                            }
852:                        } catch (Exception e) {
853:                            MessageBox box = new MessageBox(new Shell(),
854:                                    SWT.ICON_ERROR | SWT.OK | SWT.SYSTEM_MODAL);
855:                            box.setText("Error Creating Project.");
856:                            box.setMessage(e.getMessage());
857:                            box.open();
858:                            throw new InvocationTargetException(e);
859:                        } finally {
860:                            monitor.done();
861:                        }
862:                    }
863:
864:                };
865:            }
866:
867:            private boolean isTomcat40() {
868:                File inFile = new File(_sofiaPage.getTomcatHome()
869:                        + File.separator + "classes");
870:                return inFile.exists();
871:            }
872:
873:            private boolean isTomcat50() {
874:                File inFile = new File(_sofiaPage.getTomcatHome()
875:                        + File.separator + "common" + File.separator + "lib"
876:                        + File.separator + "servlet-api.jar");
877:                return inFile.exists();
878:            }
879:
880:            /* (non-Javadoc)
881:             * @see org.eclipse.jdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
882:             */
883:            protected void finishPage(IProgressMonitor monitor)
884:                    throws InterruptedException, CoreException {
885:
886:            }
887:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.