Skip to content

Commit 051252d

Browse files
author
sebastigurin
committed
1 parent dc97f29 commit 051252d

12 files changed

+1131
-20
lines changed

META-INF/MANIFEST.MF

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ Bundle-Version: 2.0.0
66
Bundle-Activator: net.sf.j2s.ui.Java2ScriptUIPlugin
77
Bundle-Vendor: j2s.sourceforge.net
88
Bundle-Localization: plugin
9-
Export-Package: net.sf.j2s.ui.resources
9+
Export-Package: net.sf.j2s.ui.launching,
10+
net.sf.j2s.ui.launching.template,
11+
net.sf.j2s.ui.preferences,
12+
net.sf.j2s.ui.property,
13+
net.sf.j2s.ui.resources
1014
Require-Bundle: org.eclipse.ui,
1115
org.eclipse.core.runtime,
1216
org.eclipse.ui.ide,
@@ -33,3 +37,4 @@ Require-Bundle: org.eclipse.ui,
3337
org.eclipse.jdt.junit,
3438
net.sf.j2s.ajax
3539
Eclipse-AutoStart: true
40+
Bundle-ClassPath: .

plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<?eclipse version="3.0"?>
33
<plugin>
44
<extension-point id="externalResourceProvider" name="External Resource Provider" schema="schema/externalResourceProvider.exsd"/>
5+
<extension-point id="j2sAppLauncherTemplateSupport" name="j2sAppLauncherTemplateSupport" schema="schema/j2sAppLauncherTemplateSupport.exsd"/>
56

67
<extension
78
point="org.eclipse.jdt.core.classpathVariableInitializer">

src/net/sf/j2s/ui/launching/IJ2SLauchingConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ public interface IJ2SLauchingConfiguration {
2121

2222
public static final String J2S_CLASS_PATH = "j2s.class.path";
2323
public static final String J2S_ABANDON_CLASS_PATH = "j2s.abandon.class.path";
24+
25+
public static final String VELOCITY_CODE = "j2s.launch.template.code";
26+
public static final String OUTPUT_FILE_NAME = "j2s.launch.template.fileName";
27+
public static final String APPLY_TEMPLATE = "j2s.launch.template.apply";
28+
public static final String TEMPLATE_NAME = "j2s.launch.template.name";
2429
}

src/net/sf/j2s/ui/launching/J2SLaunchConfigurationDelegate.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import java.io.File;
44

5+
import net.sf.j2s.ui.launching.template.J2SAppLauncherTemplateContributor;
6+
import net.sf.j2s.ui.launching.template.J2STemplateContext;
7+
import net.sf.j2s.ui.launching.template.TemplateContributionUtil;
8+
59
import org.eclipse.core.runtime.CoreException;
10+
import org.eclipse.core.runtime.IConfigurationElement;
611
import org.eclipse.core.runtime.IProgressMonitor;
12+
import org.eclipse.core.runtime.Platform;
713
import org.eclipse.debug.core.ILaunch;
814
import org.eclipse.debug.core.ILaunchConfiguration;
915
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
@@ -18,7 +24,23 @@ public void launch(ILaunchConfiguration configuration, String mode,
1824
ILaunch launch, IProgressMonitor monitor) throws CoreException {
1925
if (configuration != null) {
2026
try {
21-
J2SLaunchingUtil.launchingJ2SApp(configuration, mode, "html");
27+
/* sgurin: if configuration attribute IJ2SLauchingConfiguration.APPLY_TEMPLATE exists and is on
28+
* then we call net.sf.j2s.ui.launching.J2SAppLauncherTemplateContributor contributor class
29+
*/
30+
boolean applyTemplate = configuration.getAttribute("j2s.launch.template.apply", false);
31+
32+
if(applyTemplate) {
33+
try {
34+
J2SAppLauncherTemplateContributor contributor = TemplateContributionUtil.getInstance().getCurrentTemplateContribution();
35+
contributor.launchJ2SApp(new J2STemplateContext(configuration));
36+
} catch (Exception e) {
37+
applyTemplate=false;
38+
}
39+
}
40+
if(!applyTemplate){ // if applyTemplate is unchecked or if no template contributor class is found
41+
J2SLaunchingUtil.launchingJ2SApp(configuration, mode, "html");
42+
}
43+
2244
String mainType = J2SLaunchingUtil.getMainType(configuration);
2345
if (mainType != null) {
2446
File workingDir = J2SLaunchingUtil.getWorkingDirectory(configuration);
@@ -32,5 +54,4 @@ public void launch(ILaunchConfiguration configuration, String mode,
3254
//DebugUITools.launch(config, mode);
3355
}
3456
}
35-
3657
}

src/net/sf/j2s/ui/launching/J2SLaunchingTabGroup.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package net.sf.j2s.ui.launching;
22

3+
import java.util.Arrays;
4+
5+
import net.sf.j2s.ui.launching.template.J2SAppLauncherTemplateContributor;
6+
import net.sf.j2s.ui.launching.template.TemplateContributionUtil;
7+
8+
import org.eclipse.core.runtime.IConfigurationElement;
9+
import org.eclipse.core.runtime.IExtension;
10+
import org.eclipse.core.runtime.IExtensionPoint;
11+
import org.eclipse.core.runtime.Platform;
312
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
413
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
514
import org.eclipse.debug.ui.ILaunchConfigurationTab;
@@ -9,23 +18,42 @@ public class J2SLaunchingTabGroup extends AbstractLaunchConfigurationTabGroup {
918

1019
public J2SLaunchingTabGroup() {
1120
super();
12-
// TODO Auto-generated constructor stub
1321
}
1422

15-
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
16-
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
23+
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
24+
25+
/* sgurin: if some j2s template contributor is available, then hide HTMLOptionsTab and show
26+
the template contributor tab. If no template contribution is available, show HTMLOptionsTab so
27+
everithing is unchanged */
28+
29+
ILaunchConfigurationTab[] tabs = null;
30+
J2SAppLauncherTemplateContributor contrib = null;
31+
32+
try {
33+
contrib = TemplateContributionUtil.getInstance().getCurrentTemplateContribution();
34+
} catch (Exception e) {
35+
36+
}
37+
38+
if(contrib!=null) {
39+
tabs=new ILaunchConfigurationTab[] {
40+
new JavaMainTab(),
41+
new J2SArgumentsTab(),
42+
new J2SClasspathOptionTab(),
43+
new J2STemplateOptionsTab(contrib),
44+
new J2SConsoleOptionsTab()
45+
};
46+
}
47+
else {
48+
tabs=new ILaunchConfigurationTab[] {
1749
new JavaMainTab(),
1850
new J2SArgumentsTab(),
19-
//new J2SPathTab(),
20-
//new JavaJRETab(),
21-
// new JavaClasspathTab(),
2251
new J2SClasspathOptionTab(),
23-
//new SourceLookupTab(),
24-
//new EnvironmentTab(),
25-
//new CommonTab()
2652
new J2SGenerateHTMLOptionsTab(),
2753
new J2SConsoleOptionsTab()
28-
};
54+
};
55+
}
56+
2957
setTabs(tabs);
3058
}
3159

src/net/sf/j2s/ui/launching/J2SLaunchingUtil.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.sf.j2s.ui.launching;
22

3+
import java.io.BufferedReader;
34
import java.io.ByteArrayInputStream;
45
import java.io.ByteArrayOutputStream;
56
import java.io.File;
@@ -9,13 +10,16 @@
910
import java.io.FileOutputStream;
1011
import java.io.IOException;
1112
import java.io.InputStream;
13+
import java.io.InputStreamReader;
14+
import java.io.StringWriter;
1215
import java.net.MalformedURLException;
1316
import java.net.URL;
17+
import java.util.HashMap;
1418
import java.util.HashSet;
19+
import java.util.Map;
1520
import java.util.Properties;
1621
import java.util.Set;
1722

18-
import net.sf.j2s.core.astvisitors.ASTTigerVisitor;
1923
import net.sf.j2s.core.astvisitors.ASTTypeVisitor;
2024
import net.sf.j2s.core.astvisitors.DependencyASTVisitor;
2125
import net.sf.j2s.core.hotspot.InnerHotspotServer;
@@ -614,7 +618,7 @@ public static void writeMainHTML(File file, String html) {
614618
/*
615619
* Append the *.js in classpath
616620
*/
617-
static String generateClasspathHTML(
621+
public static String generateClasspathHTML(
618622
ILaunchConfiguration configuration, String mainType, File workingDir)
619623
throws CoreException {
620624
StringBuffer buf = new StringBuffer();
@@ -695,7 +699,7 @@ static String generateClasspathHTML(
695699
/*
696700
* Append the *.js in classpath
697701
*/
698-
static String generateClasspathJ2X(
702+
public static String generateClasspathJ2X(
699703
ILaunchConfiguration configuration, String varName, File workingDir)
700704
throws CoreException {
701705
boolean isUseGlobalURL = configuration.getAttribute(IJ2SLauchingConfiguration.USE_GLOBAL_ALAA_URL, false);
@@ -846,7 +850,7 @@ public boolean accept(File pathname) {
846850
/*
847851
* Append the *.js in classpath
848852
*/
849-
static String generateClasspathExistedClasses (
853+
public static String generateClasspathExistedClasses (
850854
ILaunchConfiguration configuration, String mainType, File workingDir, String indent)
851855
throws CoreException {
852856
boolean isUseGlobalURL = configuration.getAttribute(IJ2SLauchingConfiguration.USE_GLOBAL_ALAA_URL, false);
@@ -1020,7 +1024,7 @@ static String generateClasspathExistedClasses (
10201024
/*
10211025
* To generate ClazzLoader.ignore (...)
10221026
*/
1023-
static String generateClasspathIgnoredClasses (
1027+
public static String generateClasspathIgnoredClasses (
10241028
ILaunchConfiguration configuration, String mainType, File workingDir, String indent)
10251029
throws CoreException {
10261030
StringBuffer buf = new StringBuffer();
@@ -1183,7 +1187,7 @@ public static String readAFile(InputStream res) {
11831187
return null;
11841188
}
11851189

1186-
static File getWorkingDirectory(ILaunchConfiguration configuration)
1190+
public static File getWorkingDirectory(ILaunchConfiguration configuration)
11871191
throws CoreException {
11881192
File workingDir = null;
11891193
String path = configuration.getAttribute(
@@ -1234,7 +1238,7 @@ static File getWorkingDirectory(ILaunchConfiguration configuration)
12341238
return workingDir;
12351239
}
12361240

1237-
static String getMainType(ILaunchConfiguration configuration)
1241+
public static String getMainType(ILaunchConfiguration configuration)
12381242
throws CoreException {
12391243
String mainType;
12401244
mainType = configuration.getAttribute(
@@ -1247,4 +1251,41 @@ static String getMainType(ILaunchConfiguration configuration)
12471251
.performStringSubstitution(mainType);
12481252
return mainType;
12491253
}
1254+
1255+
1256+
//added by sgurin for template support:
1257+
public static void readString(InputStream in, StringWriter w) throws IOException {
1258+
BufferedReader br = new BufferedReader(new InputStreamReader(in));
1259+
String line = null;
1260+
while ((line = br.readLine()) != null) {
1261+
w.append(line + "\n");
1262+
}
1263+
br.close();
1264+
}
1265+
1266+
public static Map toMap(Object[]a) {
1267+
Map m = new HashMap();
1268+
for (int i = 0; i < a.length-1; i=i+2)
1269+
m.put(a[i], a[i+1]);
1270+
return m;
1271+
}
1272+
1273+
public static String inputStreamAsString(InputStream in)
1274+
throws IOException {
1275+
BufferedReader br = new BufferedReader(new InputStreamReader(in));
1276+
StringBuilder sb = new StringBuilder();
1277+
String line = null;
1278+
while ((line = br.readLine()) != null) {
1279+
sb.append(line + "\n");
1280+
}
1281+
br.close();
1282+
return sb.toString();
1283+
}
1284+
1285+
public static boolean arrayContains(Object[] a, Object o) {
1286+
for (int i = 0; i < a.length; i++)
1287+
if(a[i].equals(o))
1288+
return true;
1289+
return false;
1290+
}
12501291
}

0 commit comments

Comments
 (0)