| Revision | 190 (tree) |
|---|---|
| Time | 2016-01-02 01:31:14 |
| Author | t_nakayama1971 |
add workdir property
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import org.eclipse.core.runtime.CoreException; |
| 28 | 28 | import org.eclipse.core.runtime.IPath; |
| 29 | 29 | import org.eclipse.core.runtime.IStatus; |
| 30 | +import org.eclipse.core.runtime.Path; | |
| 30 | 31 | import org.eclipse.core.runtime.PlatformObject; |
| 31 | 32 | import org.eclipse.core.runtime.QualifiedName; |
| 32 | 33 | import org.eclipse.core.runtime.Status; |
| @@ -58,6 +59,8 @@ | ||
| 58 | 59 | private static final String KEY_WARLOCATION = "warLocation"; |
| 59 | 60 | /** KEY_ROOTDIR */ |
| 60 | 61 | private static final String KEY_ROOTDIR = "rootDir"; |
| 62 | + /** KEY_WORKDIR */ | |
| 63 | + private static final String KEY_WORKDIR = "workDir"; | |
| 61 | 64 | /** KEY_EXTRAINFO */ |
| 62 | 65 | private static final String KEY_EXTRAINFO = "extraInfo"; |
| 63 | 66 | /** EXTRA_BEGIN_TAG */ |
| @@ -76,6 +79,8 @@ | ||
| 76 | 79 | private String warLocation = ""; |
| 77 | 80 | /** rootDir */ |
| 78 | 81 | private String rootDir = ""; |
| 82 | + /** workDir */ | |
| 83 | + private String workDir = ""; | |
| 79 | 84 | /** extraInfo */ |
| 80 | 85 | private String extraInfo = ""; |
| 81 | 86 | /** updateXml */ |
| @@ -255,6 +260,22 @@ | ||
| 255 | 260 | } |
| 256 | 261 | |
| 257 | 262 | /** |
| 263 | + * Gets the workDir. | |
| 264 | + * @return Returns a String | |
| 265 | + */ | |
| 266 | + public String getWorkDir() { | |
| 267 | + return readProperty(KEY_WORKDIR); | |
| 268 | + } | |
| 269 | + | |
| 270 | + /** | |
| 271 | + * Sets the workDir. | |
| 272 | + * @param wd The workDir to set | |
| 273 | + */ | |
| 274 | + public void setWorkDir(final String wd) { | |
| 275 | + this.workDir = wd; | |
| 276 | + } | |
| 277 | + | |
| 278 | + /** | |
| 258 | 279 | * Gets the webpath. |
| 259 | 280 | * @return Returns a String |
| 260 | 281 | */ |
| @@ -426,6 +447,7 @@ | ||
| 426 | 447 | fileContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 427 | 448 | fileContent.append("<tomcatProjectProperties>\n"); |
| 428 | 449 | fileContent.append(" <rootDir>" + this.rootDir + "</rootDir>\n"); |
| 450 | + fileContent.append(" <workDir>" + this.workDir + "</workDir>\n"); | |
| 429 | 451 | fileContent.append(" <exportSource>" + this.exportSource + "</exportSource>\n"); |
| 430 | 452 | fileContent.append(" <reloadable>" + this.reloadable + "</reloadable>\n"); |
| 431 | 453 | fileContent.append(" <redirectLogger>" + this.redirectLogger + "</redirectLogger>\n"); |
| @@ -550,15 +572,12 @@ | ||
| 550 | 572 | * |
| 551 | 573 | * @return IFolder |
| 552 | 574 | */ |
| 553 | - public IFolder getWorkFolder() { | |
| 554 | - // TODO: | |
| 555 | - // if (getRootDirFolder() == null) { | |
| 556 | - // return project.getFolder("work"); | |
| 557 | - // } else { | |
| 558 | - // return getRootDirFolder().getFolder("work"); | |
| 559 | - // } | |
| 560 | - | |
| 561 | - return this.project.getFolder("work"); | |
| 575 | + public IPath getWorkFolder() { | |
| 576 | + String workFolder = getWorkDir(); | |
| 577 | + if (workFolder.isEmpty()) { | |
| 578 | + workFolder = TomcatLauncherPlugin.getTomcatDir() + "/work"; | |
| 579 | + } | |
| 580 | + return new Path(workFolder); | |
| 562 | 581 | } |
| 563 | 582 | |
| 564 | 583 | /** |
| @@ -627,11 +646,17 @@ | ||
| 627 | 646 | * @throws CoreException CoreException |
| 628 | 647 | */ |
| 629 | 648 | public void createWorkFolder() throws CoreException { |
| 630 | - IFolder folderHandle = getWorkFolder(); | |
| 631 | - createFolder(folderHandle); | |
| 649 | + IPath folderHandle = getWorkFolder(); | |
| 650 | + if (!folderHandle.toFile().exists()) { | |
| 651 | + if (!folderHandle.toFile().mkdirs()) { | |
| 652 | + throw new CoreException(new Status(IStatus.ERROR, | |
| 653 | + TomcatLauncherPlugin.getDefault().getBundle().getSymbolicName(), | |
| 654 | + " create directory failed.:" + folderHandle.toFile().toString())); | |
| 655 | + } | |
| 656 | + } | |
| 632 | 657 | |
| 633 | 658 | // Add a .cvsignore file in work directory |
| 634 | - createFile(this.project.getFile(".cvsignore"), "work"); | |
| 659 | + //createFile(this.project.getFile(".cvsignore"), "work"); | |
| 635 | 660 | } |
| 636 | 661 | |
| 637 | 662 | /** |
| @@ -677,12 +702,10 @@ | ||
| 677 | 702 | try { |
| 678 | 703 | // Create the folder resource in the workspace |
| 679 | 704 | folderHandle.create(false, true, null); |
| 680 | - //new SubProgressMonitor(monitor, 500)); | |
| 681 | 705 | } catch (final CoreException e) { |
| 682 | 706 | // If the folder already existed locally, just refresh to get contents |
| 683 | 707 | if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) { |
| 684 | 708 | folderHandle.refreshLocal(IResource.DEPTH_INFINITE, null); |
| 685 | - //new SubProgressMonitor(monitor, 500)); | |
| 686 | 709 | } |
| 687 | 710 | throw e; |
| 688 | 711 | } |
| @@ -701,7 +724,6 @@ | ||
| 701 | 724 | // If the file already existed locally, just refresh to get contents |
| 702 | 725 | if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) { |
| 703 | 726 | fileHandle.refreshLocal(IResource.DEPTH_INFINITE, null); |
| 704 | - //new SubProgressMonitor(monitor, 500)); | |
| 705 | 727 | } |
| 706 | 728 | throw e; |
| 707 | 729 | } |
| @@ -715,16 +737,26 @@ | ||
| 715 | 737 | * @throws CoreException CoreException |
| 716 | 738 | */ |
| 717 | 739 | private void setFolderAsSourceEntry(final IFolder folderHandle, final IFolder output) throws CoreException { |
| 718 | - IClasspathEntry[] entries = this.javaProject.getRawClasspath(); | |
| 719 | - IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; | |
| 720 | - System.arraycopy(entries, 0, newEntries, 0, entries.length); | |
| 721 | 740 | IPath outputPath = null; |
| 722 | 741 | if (output != null) { |
| 723 | 742 | outputPath = output.getFullPath(); |
| 724 | 743 | } |
| 744 | + setFolderAsSourceEntry(folderHandle.getFullPath(), outputPath); | |
| 745 | + } | |
| 725 | 746 | |
| 747 | + | |
| 748 | + /** | |
| 749 | + * ouput could be null (project default output will be used) | |
| 750 | + * @param folderPath IPath | |
| 751 | + * @param outputPath IPath | |
| 752 | + * @throws CoreException CoreException | |
| 753 | + */ | |
| 754 | + private void setFolderAsSourceEntry(final IPath folderPath, final IPath outputPath) throws CoreException { | |
| 755 | + IClasspathEntry[] entries = this.javaProject.getRawClasspath(); | |
| 756 | + IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; | |
| 757 | + System.arraycopy(entries, 0, newEntries, 0, entries.length); | |
| 726 | 758 | IPath[] emptyPath = {}; |
| 727 | - newEntries[entries.length] = JavaCore.newSourceEntry(folderHandle.getFullPath(), emptyPath, outputPath); | |
| 759 | + newEntries[entries.length] = JavaCore.newSourceEntry(folderPath, emptyPath, outputPath); | |
| 728 | 760 | |
| 729 | 761 | this.javaProject.setRawClasspath(newEntries, null); |
| 730 | 762 | } |
| @@ -1435,10 +1467,7 @@ | ||
| 1435 | 1467 | * @return String |
| 1436 | 1468 | */ |
| 1437 | 1469 | private String getContextWorkDir() { |
| 1438 | - String workFolderLocation = TomcatLauncherPlugin.getTomcatDir() + "/work"; | |
| 1439 | - if (getWorkFolder().exists()) { | |
| 1440 | - workFolderLocation = getWorkFolder().getLocation().toOSString(); | |
| 1441 | - } | |
| 1470 | + String workFolderLocation = getWorkFolder().toOSString(); | |
| 1442 | 1471 | return TomcatLauncherPlugin.getTomcatBootstrap().getContextWorkDir(workFolderLocation); |
| 1443 | 1472 | } |
| 1444 | 1473 |
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | package com.sysdeo.eclipse.tomcat; |
| 7 | 7 | |
| 8 | +import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.NATURE_ID; | |
| 8 | 9 | import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.PROPERTIES_PAGE_PROJECT_EXTRAINFO_LABEL; |
| 9 | 10 | import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.PROPERTIES_PAGE_PROJECT_ISTOMCATPROJECT_LABEL; |
| 10 | 11 | import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.WIZARD_PROJECT_REDIRECTLOGGER_LABEL; |
| @@ -12,9 +13,11 @@ | ||
| 12 | 13 | import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.WIZARD_PROJECT_ROOTDIR_LABEL; |
| 13 | 14 | import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.WIZARD_PROJECT_UPDATEXML_LABEL; |
| 14 | 15 | import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.WIZARD_PROJECT_WEBPATH_LABEL; |
| 16 | +import static com.sysdeo.eclipse.tomcat.TomcatPluginResources.WIZARD_PROJECT_WORKDIR_LABEL; | |
| 15 | 17 | |
| 16 | 18 | import org.eclipse.core.runtime.CoreException; |
| 17 | 19 | import org.eclipse.jdt.core.IJavaProject; |
| 20 | +import org.eclipse.jface.preference.DirectoryFieldEditor; | |
| 18 | 21 | import org.eclipse.swt.SWT; |
| 19 | 22 | import org.eclipse.swt.layout.GridData; |
| 20 | 23 | import org.eclipse.swt.layout.GridLayout; |
| @@ -48,6 +51,8 @@ | ||
| 48 | 51 | private Text rootDirText; |
| 49 | 52 | /** extraInfoText */ |
| 50 | 53 | private Text extraInfoText; |
| 54 | + /** DirectoryFieldEditor */ | |
| 55 | + private DirectoryFieldEditor workDir; | |
| 51 | 56 | |
| 52 | 57 | /** IJavaProject */ |
| 53 | 58 | private final IJavaProject javaProject; |
| @@ -80,10 +85,6 @@ | ||
| 80 | 85 | createWebpathGroup(group); |
| 81 | 86 | createExtraInformationGroup(group); |
| 82 | 87 | |
| 83 | - //blank | |
| 84 | - Label lbl = new Label(group, SWT.NULL); | |
| 85 | - lbl.setParent(composite); | |
| 86 | - | |
| 87 | 88 | createRootDirGroup(group); |
| 88 | 89 | |
| 89 | 90 | return composite; |
| @@ -104,8 +105,7 @@ | ||
| 104 | 105 | this.isTomcatProjectCheck.setEnabled(true); |
| 105 | 106 | |
| 106 | 107 | try { |
| 107 | - this.isTomcatProjectCheck.setSelection( | |
| 108 | - this.javaProject.getProject().hasNature(TomcatPluginResources.NATURE_ID)); | |
| 108 | + this.isTomcatProjectCheck.setSelection(this.javaProject.getProject().hasNature(NATURE_ID)); | |
| 109 | 109 | } catch (final CoreException ex) { |
| 110 | 110 | TomcatLauncherPlugin.log(ex.getMessage()); |
| 111 | 111 | } |
| @@ -171,6 +171,14 @@ | ||
| 171 | 171 | * @param parent Composite |
| 172 | 172 | */ |
| 173 | 173 | public void createRootDirGroup(final Composite parent) { |
| 174 | + Composite workDirGroup = new Composite(parent, SWT.NONE); | |
| 175 | + workDirGroup.setLayout(new GridLayout(3, false)); | |
| 176 | + workDirGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
| 177 | + | |
| 178 | + this.workDir = new DirectoryFieldEditor("", | |
| 179 | + WIZARD_PROJECT_WORKDIR_LABEL, workDirGroup); | |
| 180 | + this.workDir.setStringValue(getWorkDir()); | |
| 181 | + | |
| 174 | 182 | Composite rootDirGroup = new Composite(parent, SWT.NONE); |
| 175 | 183 | rootDirGroup.setLayout(new GridLayout(2, false)); |
| 176 | 184 | rootDirGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| @@ -242,6 +250,19 @@ | ||
| 242 | 250 | |
| 243 | 251 | /** |
| 244 | 252 | * |
| 253 | + * @return WorkDir | |
| 254 | + */ | |
| 255 | + protected String getWorkDir() { | |
| 256 | + String result = ""; | |
| 257 | + TomcatProject prj = this.tomcatProject; | |
| 258 | + if (prj != null) { | |
| 259 | + result = prj.getWorkDir(); | |
| 260 | + } | |
| 261 | + return result; | |
| 262 | + } | |
| 263 | + | |
| 264 | + /** | |
| 265 | + * | |
| 245 | 266 | * @return ExtraInfo |
| 246 | 267 | */ |
| 247 | 268 | protected String getExtraInfo() { |
| @@ -307,6 +328,7 @@ | ||
| 307 | 328 | prj.setRedirectLogger(this.redirectLoggerCheck.getSelection()); |
| 308 | 329 | prj.setExtraInfo(this.extraInfoText.getText()); |
| 309 | 330 | prj.setRootDir(this.rootDirText.getText()); |
| 331 | + prj.setWorkDir(this.workDir.getStringValue()); | |
| 310 | 332 | prj.saveProperties(); |
| 311 | 333 | } else { |
| 312 | 334 | this.tomcatProject.removeContext(); |
| @@ -164,6 +164,9 @@ | ||
| 164 | 164 | /** WIZARD_PROJECT_WEBPATH_LABEL */ |
| 165 | 165 | public static final String WIZARD_PROJECT_WEBPATH_LABEL = |
| 166 | 166 | TomcatLauncherPlugin.getResourceString("wizard.project.webpath.label"); |
| 167 | + /** WIZARD_PROJECT_WORKDIR_LABEL */ | |
| 168 | + public static final String WIZARD_PROJECT_WORKDIR_LABEL = | |
| 169 | + TomcatLauncherPlugin.getResourceString("wizard.project.workdir.label"); | |
| 167 | 170 | /** WIZARD_PROJECT_ROOTDIR_LABEL */ |
| 168 | 171 | public static final String WIZARD_PROJECT_ROOTDIR_LABEL = |
| 169 | 172 | TomcatLauncherPlugin.getResourceString("wizard.project.rootdir.label"); |