Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4179153

Browse files
author
zhourenjian
committed
1. Highly integrate Java2Script's incremental build with Java's. That is to say, compiling one *.java to *.class will now also compile to *.js at the same time.
2. Now Java's javabuilder is replaced with java2scriptbuilder 3. Fix bugs of migrating from Eclipse 3.2 4. Wizards now add Java's classpath variables correctly.
1 parent acf36bb commit 4179153

8 files changed

+348
-128
lines changed

plugin.xml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@
7373
<with variable="selection">
7474
<count value="1"/>
7575
<iterate>
76-
<or>
77-
<test property="org.eclipse.debug.ui.matchesPattern" value="*.java"/>
78-
<test property="org.eclipse.debug.ui.matchesPattern" value="*.class"/>
79-
<adapt type="org.eclipse.jdt.core.IJavaElement"/>
80-
<instanceof value="org.eclipse.jdt.internal.ui.javaeditor.InternalClassFileEditorInput"/>
81-
</or>
82-
<test property="org.eclipse.jdt.debug.ui.hasMainType"/>
76+
<or>
77+
<test property="org.eclipse.jdt.launching.hasMain"/>
78+
<and>
79+
<test property="org.eclipse.jdt.launching.hasProjectNature" args="org.eclipse.jdt.core.javanature"/>
80+
<or>
81+
<test property="org.eclipse.jdt.launching.isContainer"/>
82+
<test property="org.eclipse.jdt.launching.isPackageFragment"/>
83+
<test property="org.eclipse.jdt.launching.isPackageFragmentRoot"/>
84+
</or>
85+
</and>
86+
</or>
8387
</iterate>
84-
</with>
88+
</with>
8589
</enablement>
8690
</contextualLaunch>
8791
<perspective
@@ -109,20 +113,15 @@
109113
id="net.sf.j2s.debug.ui.localJ2SJUnitShortcut">
110114
<contextualLaunch>
111115
<enablement>
112-
<with
113-
variable="selection">
114-
<count
115-
value="1">
116-
</count>
117-
<iterate>
118-
<or>
119-
<test property="org.eclipse.debug.ui.matchesPattern" value="*.java"/>
120-
<test property="org.eclipse.debug.ui.matchesPattern" value="*.class"/>
121-
<adapt type="org.eclipse.jdt.core.IJavaElement"/>
122-
</or>
123-
<!--test property="org.eclipse.pde.core.PluginNature"/-->
124-
<test property="org.eclipse.jdt.junit.isTest"/>
125-
</iterate>
116+
<with variable="selection">
117+
<count value="1"/>
118+
<iterate>
119+
<adapt type="org.eclipse.jdt.core.IJavaElement">
120+
<test property="org.eclipse.jdt.core.isInJavaProject"/>
121+
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="junit.framework.Test"/>
122+
<test property="org.eclipse.jdt.junit.canLaunchAsJUnit" forcePluginActivation="true"/>
123+
</adapt>
124+
</iterate>
126125
</with>
127126
</enablement>
128127
</contextualLaunch>
@@ -259,12 +258,6 @@
259258
</action>
260259
</viewerContribution>
261260
</extension>
262-
<extension
263-
point="org.eclipse.jdt.ui.javadocCompletionProcessor">
264-
<javadocCompletionProcessor
265-
class="net.sf.j2s.ui.text.javadoc.JavaDocCompletionEvaluator"
266-
id="net.sf.j2s.javadocCompletionProcessor"/>
267-
</extension>
268261
<extension
269262
point="org.eclipse.ui.preferencePages">
270263
<page

src/net/sf/j2s/ui/actions/UnitJavaScriptUtil.java

Lines changed: 66 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,38 @@
1212
package net.sf.j2s.ui.actions;
1313

1414
import java.io.File;
15-
import java.io.FileNotFoundException;
16-
import java.io.IOException;
17-
import java.io.InputStream;
1815
import java.util.ArrayList;
1916

2017
import net.sf.j2s.ui.Java2ScriptUIPlugin;
2118

2219
import org.eclipse.core.filesystem.EFS;
2320
import org.eclipse.core.filesystem.IFileStore;
2421
import org.eclipse.core.resources.IFile;
25-
import org.eclipse.core.resources.IWorkspace;
22+
import org.eclipse.core.resources.IWorkspaceRoot;
2623
import org.eclipse.core.resources.ResourcesPlugin;
27-
import org.eclipse.core.runtime.CoreException;
2824
import org.eclipse.core.runtime.IPath;
2925
import org.eclipse.core.runtime.Path;
3026
import org.eclipse.core.runtime.Platform;
31-
import org.eclipse.core.runtime.content.IContentType;
3227
import org.eclipse.jdt.core.ICompilationUnit;
3328
import org.eclipse.jdt.core.IJavaElement;
3429
import org.eclipse.jdt.core.IJavaModel;
3530
import org.eclipse.jdt.core.IJavaProject;
3631
import org.eclipse.jdt.core.JavaModelException;
3732
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
3833
import org.eclipse.jface.dialogs.MessageDialog;
34+
import org.eclipse.osgi.util.NLS;
3935
import org.eclipse.swt.widgets.Shell;
4036
import org.eclipse.ui.IEditorDescriptor;
4137
import org.eclipse.ui.IEditorInput;
4238
import org.eclipse.ui.IEditorRegistry;
43-
import org.eclipse.ui.IWorkbench;
4439
import org.eclipse.ui.IWorkbenchPage;
4540
import org.eclipse.ui.IWorkbenchWindow;
4641
import org.eclipse.ui.PartInitException;
4742
import org.eclipse.ui.editors.text.EditorsUI;
48-
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
43+
import org.eclipse.ui.ide.FileStoreEditorInput;
44+
import org.eclipse.ui.ide.IDE;
45+
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
46+
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
4947
import org.eclipse.ui.part.FileEditorInput;
5048

5149
/**
@@ -93,106 +91,90 @@ public static boolean openEditor( ICompilationUnit unit) {
9391
IFileStore fileStore= EFS.getLocalFileSystem().getStore(new Path(file.getParent()));
9492
fileStore= fileStore.getChild(file.getName());
9593
if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
96-
IEditorInput input= createEditorInput(fileStore);
97-
if (input == null) {
98-
return false;
99-
}
100-
IWorkbenchWindow fWindow = Java2ScriptUIPlugin.getDefault().getWorkbench()
101-
.getActiveWorkbenchWindow();
102-
String editorId= getEditorId(fWindow, fileStore);
103-
IWorkbenchPage page= fWindow.getActivePage();
94+
IWorkbenchWindow fWindow = Java2ScriptUIPlugin.getDefault()
95+
.getWorkbench().getActiveWorkbenchWindow();
96+
IWorkbenchPage page = fWindow.getActivePage();
10497
try {
105-
page.openEditor(input, editorId);
98+
// Copy from IDE.openEditorOnFileStore
99+
IEditorInput input = getEditorInput(fileStore);
100+
String editorId = null;
101+
IEditorDescriptor descriptor;
102+
try {
103+
descriptor = IDE.getEditorDescriptor("java2script.txt"); // text editor
104+
if (descriptor != null)
105+
editorId = descriptor.getId();
106+
} catch (PartInitException e) {
107+
}
108+
109+
// open the editor on the file
110+
page.openEditor(input, editorId);
106111
return true;
107112
} catch (PartInitException e) {
108-
EditorsPlugin.log(e.getStatus());
113+
String msg = NLS.bind(IDEWorkbenchMessages.OpenLocalFileAction_message_errorOnOpen, fileStore.getName());
114+
IDEWorkbenchPlugin.log(msg,e.getStatus());
115+
MessageDialog.openError(fWindow.getShell(), IDEWorkbenchMessages.OpenLocalFileAction_title, msg);
109116
}
110117
}
111118
}
112119
return false;
113120
}
114-
/*
115-
* XXX: Requested a helper to get the correct editor descriptor
116-
* see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=110203
117-
*/
118-
private static String getEditorId(IWorkbenchWindow fWindow, IFileStore file) {
119-
IWorkbench workbench= fWindow.getWorkbench();
120-
IEditorRegistry editorRegistry= workbench.getEditorRegistry();
121-
IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName(), getContentType(file));
122-
123-
// check the OS for in-place editor (OLE on Win32)
124-
if (descriptor == null && editorRegistry.isSystemInPlaceEditorAvailable(file.getName()))
125-
descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
126-
127-
// // check the OS for external editor
128-
// if (descriptor == null && editorRegistry.isSystemExternalEditorAvailable(file.getName()))
129-
// descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
130-
131-
if (descriptor != null)
132-
return descriptor.getId();
133-
134-
return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
135-
}
136-
137-
private static IContentType getContentType (IFileStore fileStore) {
138-
if (fileStore == null)
139-
return null;
140-
141-
InputStream stream= null;
142-
try {
143-
stream= fileStore.openInputStream(EFS.NONE, null);
144-
return Platform.getContentTypeManager().findContentTypeFor(stream, fileStore.getName());
145-
} catch (IOException x) {
146-
EditorsPlugin.log(x);
147-
return null;
148-
} catch (CoreException x) {
149-
// Do not log FileNotFoundException (no access)
150-
if (!(x.getStatus().getException() instanceof FileNotFoundException))
151-
EditorsPlugin.log(x);
152-
153-
return null;
154-
} finally {
155-
try {
156-
if (stream != null)
157-
stream.close();
158-
} catch (IOException x) {
159-
EditorsPlugin.log(x);
160-
}
161-
}
162-
}
163121

164-
private static IEditorInput createEditorInput(IFileStore fileStore) {
165-
IFile workspaceFile= getWorkspaceFile(fileStore);
122+
/**
123+
* Create the Editor Input appropriate for the given <code>IFileStore</code>.
124+
* The result is a normal file editor input if the file exists in the
125+
* workspace and, if not, we create a wrapper capable of managing an
126+
* 'external' file using its <code>IFileStore</code>.
127+
*
128+
* @param fileStore
129+
* The file store to provide the editor input for
130+
* @return The editor input associated with the given file store
131+
*/
132+
private static IEditorInput getEditorInput(IFileStore fileStore) {
133+
IFile workspaceFile = getWorkspaceFile(fileStore);
166134
if (workspaceFile != null)
167135
return new FileEditorInput(workspaceFile);
168-
else {
169-
//return new FileEditorInput(new Path(fileStore.toURI().getPath()).)
170-
return null;
171-
}
136+
return new FileStoreEditorInput(fileStore);
172137
}
173138

139+
/**
140+
* Determine whether or not the <code>IFileStore</code> represents a file
141+
* currently in the workspace.
142+
*
143+
* @param fileStore
144+
* The <code>IFileStore</code> to test
145+
* @return The workspace's <code>IFile</code> if it exists or
146+
* <code>null</code> if not
147+
*/
174148
private static IFile getWorkspaceFile(IFileStore fileStore) {
175-
IWorkspace workspace= ResourcesPlugin.getWorkspace();
176-
IFile[] files= workspace.getRoot().findFilesForLocation(new Path(fileStore.toURI().getPath()));
177-
files= filterNonExistentFiles(files);
149+
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
150+
IFile[] files = root.findFilesForLocationURI(fileStore.toURI());
151+
files = filterNonExistentFiles(files);
178152
if (files == null || files.length == 0)
179153
return null;
180-
if (files.length == 1)
181-
return files[0];
182-
return null;
154+
155+
// for now only return the first file
156+
return files[0];
183157
}
184158

185-
private static IFile[] filterNonExistentFiles(IFile[] files){
159+
/**
160+
* Filter the incoming array of <code>IFile</code> elements by removing
161+
* any that do not currently exist in the workspace.
162+
*
163+
* @param files
164+
* The array of <code>IFile</code> elements
165+
* @return The filtered array
166+
*/
167+
private static IFile[] filterNonExistentFiles(IFile[] files) {
186168
if (files == null)
187169
return null;
188170

189-
int length= files.length;
190-
ArrayList existentFiles= new ArrayList(length);
191-
for (int i= 0; i < length; i++) {
171+
int length = files.length;
172+
ArrayList existentFiles = new ArrayList(length);
173+
for (int i = 0; i < length; i++) {
192174
if (files[i].exists())
193175
existentFiles.add(files[i]);
194176
}
195-
return (IFile[])existentFiles.toArray(new IFile[existentFiles.size()]);
177+
return (IFile[]) existentFiles.toArray(new IFile[existentFiles.size()]);
196178
}
197179

198180
protected static String getRelativeJSPath(ICompilationUnit unit) {

src/net/sf/j2s/ui/property/J2SPropertyPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public boolean performOk() {
191191
try {
192192
Java2ScriptProjectNature pn = new Java2ScriptProjectNature();
193193
pn.setProject(project);
194-
pn.addToBuildSpec("net.sf.j2s.core.java2scriptbuilder");
194+
pn.configure();
195195
} catch (CoreException e) {
196196
e.printStackTrace();
197197
}
@@ -206,7 +206,7 @@ public boolean performOk() {
206206
try {
207207
Java2ScriptProjectNature pn = new Java2ScriptProjectNature();
208208
pn.setProject(project);
209-
pn.removeFromBuildSpec("net.sf.j2s.core.java2scriptbuilder");
209+
pn.deconfigure();
210210
} catch (CoreException e) {
211211
e.printStackTrace();
212212
}

src/net/sf/j2s/ui/wizards/Java2ScriptAJAXProjectWizard.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
import java.io.FileNotFoundException;
1717
import java.io.FileOutputStream;
1818
import java.io.IOException;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.eclipse.core.runtime.IPath;
23+
import org.eclipse.core.runtime.Path;
24+
import org.eclipse.jdt.core.IClasspathEntry;
25+
import org.eclipse.jdt.core.JavaCore;
26+
1927
import net.sf.j2s.ui.launching.J2SLaunchingUtil;
2028
import net.sf.j2s.ui.property.J2SClasspathModel;
2129

@@ -35,6 +43,17 @@ protected void updateJava2ScriptWizardTitle() {
3543

3644
protected void updateJava2ScriptLibraries(J2SClasspathModel classpathModel, String j2sLibPath) {
3745
}
46+
47+
protected IClasspathEntry[] updateJavaLibraries(
48+
IClasspathEntry[] defaultEntries) {
49+
List list = new ArrayList();
50+
for (int i = 0; i < defaultEntries.length; i++) {
51+
list.add(i, defaultEntries[i]);
52+
}
53+
list.add(JavaCore.newVariableEntry(new Path("AJAX_CORE"), new Path("AJAX_CORE_SRC"), null));
54+
list.add(JavaCore.newVariableEntry(new Path("AJAX_RPC"), new Path("AJAX_RPC_SRC"), null));
55+
return super.updateJavaLibraries((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]));
56+
}
3857

3958
protected void updateJava2ScriptProject(String prjFolder, String binRelative) {
4059
try {

0 commit comments

Comments
 (0)