Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/net.sf.j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20191021071533
20191024113542
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20191021071533
20191024113542
3 changes: 2 additions & 1 deletion sources/net.sf.j2s.core/src/net/sf/j2s/core/CorePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class CorePlugin extends Plugin {
* register the bundle version properly. So we use VERSION here instead.
*
*/
public static String VERSION = "3.2.4.07";
public static String VERSION = "3.2.4.08";
// BH 2019.10.24 support for multiple buildStart
// TODO/NOTE final static int FOO = (/**@j2sNative 5 || */3) stated but not recognized when used as its new value
// BH 2/3/2019 -- 3.2.4.07 fixes "final static Float = (float)" missing definition
// BH 1/2/2019 -- 3.2.4.06 fixes try(resources) with more than one resource missing semicolon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.sf.j2s.core;

import java.util.ArrayList;

import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.compiler.BuildContext;
import org.eclipse.jdt.core.compiler.ReconcileContext;
Expand All @@ -13,8 +16,9 @@
*
*/
public class Java2ScriptCompilationParticipant extends org.eclipse.jdt.core.compiler.CompilationParticipant {
private BuildContext[] javaFiles;
private ArrayList<BuildContext[]>contexts;
private boolean isCleanBuild;
private static String isActiveNotified = "";

public Java2ScriptCompilationParticipant() {
System.out.println("CompilationParticipant started");
Expand All @@ -34,9 +38,14 @@ public Java2ScriptCompilationParticipant() {
* the project to participate in
* @return whether this participant is active for a given project
*/
@Override
public boolean isActive(IJavaProject project) {
boolean isj2s = Java2ScriptCompiler.isActive(project);
System.out.println("isActive " + isj2s + " " + project.getProject().getLocation());
String loc = " " + project.getProject().getLocation().toString() + " ";
if (isActiveNotified.indexOf(loc) < 0) {
System.out.println("j2s isActive " + isj2s + loc);
isActiveNotified += loc;
}
return isj2s;
}

Expand All @@ -55,8 +64,11 @@ public boolean isActive(IJavaProject project) {
* the project about to build
* @return READY_FOR_BUILD or NEEDS_FULL_BUILD
*/
@Override
public int aboutToBuild(IJavaProject project) {
System.out.println("aboutToBuild " + project.getProject().getLocation());
System.out.println("j2s aboutToBuild " + project.getProject().getName() + " " + project.getProject().getLocation());
if (contexts == null)
contexts = new ArrayList<>();
return READY_FOR_BUILD;
}

Expand All @@ -68,8 +80,9 @@ public int aboutToBuild(IJavaProject project) {
* @param project
* the project about to be cleaned
*/
@Override
public void cleanStarting(IJavaProject project) {
System.out.println("cleanStarting " + project.getProject().getLocation());
System.out.println("j2s cleanStarting " + project.getProject().getLocation());
isCleanBuild = true;
}

Expand All @@ -85,9 +98,12 @@ public void cleanStarting(IJavaProject project) {
* @param isBatch
* identifies when the build is a batch build
*/
@Override
public void buildStarting(BuildContext[] files, boolean isBatch) {
javaFiles = files;
System.out.println("buildStarting " + files.length + " files, isBatch=" + isBatch);
if (files.length == 0)
return;
contexts.add(files);
System.out.println("j2s buildStarting " + files.length + " files, contexts.size() = " + contexts.size() + ", isBatch=" + isBatch);
}

/**
Expand All @@ -96,38 +112,67 @@ public void buildStarting(BuildContext[] files, boolean isBatch) {
* needed to be compiled or the build failed. Only sent to participants
* interested in the project.
*
* @param project
* the project about to build
* @param project the project about to build
* @since 3.4
*/
@Override
public void buildFinished(IJavaProject project) {
if (javaFiles != null) {
if (contexts != null) {
Java2ScriptCompiler j2sCompiler = new Java2ScriptCompiler();
boolean breakOnError = j2sCompiler.doBreakOnError();
j2sCompiler.startBuild(isCleanBuild);
if (!j2sCompiler.initializeProject(project, true)) {
System.out.println(".j2s disabled");
return;
}
System.out.println("building JavaScript " + project.getProject().getLocation());
for (int i = 0; i < javaFiles.length; i++) {
System.out.println("transpiling " + javaFiles[i]);
System.out.println("j2s building JavaScript " + project.getProject().getName() + " "
+ project.getProject().getLocation());
int ntotal = 0, nerror = 0;
for (int j = 0; j < contexts.size(); j++) {
BuildContext[] files = contexts.get(j);
System.out.println("j2s building JavaScript for " + files.length + " file"+plural(files.length));

for (int i = 0, n = files.length; i < n; i++) {
// trying to keep the progess monitor running - didn't work
// try {
// Thread.currentThread().sleep(1);
// } catch (InterruptedException e) {
// // ignore
// }
if (!j2sCompiler.compileToJavaScript(javaFiles[i].getFile())) {
System.out.println("Error processing " + javaFiles[i].getFile());
break;
// System.out.println("j2s file"
// + " name=" + files[i].getFile().getName()
// + " fullpath=" + files[i].getFile().getFullPath()
// + " location=" + files[i].getFile().getLocation());
//
IFile f = files[i].getFile();
String filePath = f.getLocation().toString();
if (j2sCompiler.excludeFile(f)) {
System.out.println("j2s excluded " + filePath);
} else {
System.out.println("j2s transpiling (" + (i + 1) + "/" + n + ") " + filePath);
if (j2sCompiler.compileToJavaScript(f)) {
ntotal++;
} else {
nerror++;
System.out.println("j2s Error processing " + filePath);
if (breakOnError)
break;
}
}
}
}
javaFiles = null;
System.out.println("build finished " + project.getProject().getLocation());
}
contexts = null;
System.out.println(
"j2s buildFinished " + ntotal + " file"+plural(ntotal) + " transpiled for " + project.getProject().getLocation());
System.out.println("j2s buildFinished nerror = " + nerror);
}
isCleanBuild = false;
}

private static String plural(int n) {
return (n == 1 ? "" : "s");
}

/**
* Returns whether this participant is interested in only Annotations.
* <p>
Expand All @@ -136,6 +181,7 @@ public void buildFinished(IJavaProject project) {
*
* @return whether this participant is interested in only Annotations.
*/
@Override
public boolean isAnnotationProcessor() {
return false;
}
Expand All @@ -150,6 +196,7 @@ public boolean isAnnotationProcessor() {
* @param files
* is an array of BuildContext
*/
@Override
public void processAnnotations(BuildContext[] files) {
// nothing to do
}
Expand All @@ -170,6 +217,7 @@ public void processAnnotations(BuildContext[] files) {
* @param context
* the reconcile context to act on
*/
@Override
public void reconcile(ReconcileContext context) {
// fired whenever a source file is changed -- before it is saved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,26 @@ class Java2ScriptCompiler {
*/
private static final String J2S_LOG_METHODS_CALLED = "j2s.log.methods.called";

private static final String J2S_LOG_ALL_CALLS = "j2s.log.all.calls";
/**
* stop processing files if any file has an exception; default is TRUE
*
*/
private static final String J2S_BREAK_ON_ERROR = "j2s.break.on.error";
private static final String J2S_BREAK_ON_ERROR_FALSE = "false";

private static final String J2S_LOG_ALL_CALLS = "j2s.log.all.calls";
private static final String J2S_LOG_ALL_CALLS_TRUE = "true";

private static final String J2S_EXCLUDED_PATHS = "j2s.excluded.paths";

private static final String J2S_TESTING = "j2s.testing";

private static final String J2S_TESTING_TRUE = "true";

private static final String J2S_COMPILER_NONQUALIFIED_PACKAGES = "j2s.compiler.nonqualified.packages";

private static final String J2S_COMPILER_NONQUALIFIED_CLASSES = "j2s.compiler.nonqualified.classes";

private static final String J2S_COMPILER_MODE = "j2s.compiler.mode";

private static final String J2S_COMPILER_MODE_DEBUG = "debug";

private static final String J2S_CLASS_REPLACEMENTS = "j2s.class.replacements";
Expand All @@ -93,6 +97,8 @@ class Java2ScriptCompiler {
private String htmlTemplate = null;

private String projectFolder;

private String projectPath;

private String j2sPath;

Expand Down Expand Up @@ -120,6 +126,12 @@ class Java2ScriptCompiler {

private boolean isDebugging;

private boolean breakOnError;

public boolean doBreakOnError() {
return breakOnError;
}

static boolean isActive(IJavaProject project) {
try {
return new File(project.getProject().getLocation().toOSString(), J2S_OPTIONS_FILE_NAME).exists();
Expand Down Expand Up @@ -166,6 +178,7 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
// the file .j2s does not exist in the project directory -- skip this project
return false;
}
projectPath = "/" + project.getProject().getName() + "/";
projectFolder = project.getProject().getLocation().toOSString();
props = new Properties();
try {
Expand Down Expand Up @@ -218,6 +231,8 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
logAllCalls = J2S_LOG_ALL_CALLS_TRUE.equalsIgnoreCase(getProperty(J2S_LOG_ALL_CALLS));
}

breakOnError = !J2S_BREAK_ON_ERROR_FALSE.equalsIgnoreCase(getProperty(J2S_BREAK_ON_ERROR));

excludedPaths = getProperty(J2S_EXCLUDED_PATHS);

lstExcludedPaths = null;
Expand All @@ -227,7 +242,7 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
String[] paths = excludedPaths.split(";");
for (int i = 0; i < paths.length; i++)
if (paths[i].trim().length() > 0)
lstExcludedPaths.add(paths[i].trim() + "/");
lstExcludedPaths.add(projectPath + paths[i].trim() + "/");
if (lstExcludedPaths.size() == 0)
lstExcludedPaths = null;
}
Expand Down Expand Up @@ -273,6 +288,16 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
return true;
}

boolean excludeFile(IFile javaSource) {
String filePath = javaSource.getFullPath().toString();
if (lstExcludedPaths != null) {
for (int i = lstExcludedPaths.size(); --i >= 0;)
if (filePath.startsWith(lstExcludedPaths.get(i))) {
return true;
}
}
return false;
}
/**
* from Java2ScriptCompilationParticipant.java
*
Expand All @@ -282,13 +307,6 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
* @param javaSource
*/
boolean compileToJavaScript(IFile javaSource) {

String fileName = new String(javaSource.getName());
if (lstExcludedPaths != null) {
for (int i = lstExcludedPaths.size(); --i >= 0;)
if (fileName.startsWith(lstExcludedPaths.get(i)))
return true;
}
org.eclipse.jdt.core.ICompilationUnit createdUnit = JavaCore.createCompilationUnitFrom(javaSource);
astParser.setSource(createdUnit);
// note: next call must come before each createAST call
Expand Down Expand Up @@ -318,14 +336,14 @@ boolean compileToJavaScript(IFile javaSource) {
e.printStackTrace();
e.printStackTrace(System.out);
// find the file and delete it.
String filePath = j2sPath;
String outPath = j2sPath;
String rootName = root.getJavaElement().getElementName();
rootName = rootName.substring(0, rootName.lastIndexOf('.'));
String packageName = visitor.getMyPackageName();
if (packageName != null) {
File folder = new File(filePath, packageName.replace('.', File.separatorChar));
filePath = folder.getAbsolutePath();
File jsFile = new File(filePath, rootName + ".js"); //$NON-NLS-1$
File folder = new File(outPath, packageName.replace('.', File.separatorChar));
outPath = folder.getAbsolutePath();
File jsFile = new File(outPath, rootName + ".js"); //$NON-NLS-1$
if (jsFile.exists()) {
System.out.println("Java2ScriptCompiler deleting " + jsFile);
jsFile.delete();
Expand Down Expand Up @@ -388,7 +406,7 @@ private void logMethods(String logCalled, String logDeclared, boolean doAppend)
private String getProperty(String key) {
String val = props.getProperty(key);
if (showJ2SSettings)
System.err.println(key + " = " + val);
System.out.println(key + " = " + val);
return val;
}

Expand Down
Loading