From b804e58ee4b90718e7d78a53f91bec08630cad2d Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Thu, 27 Oct 2016 14:14:35 +0200 Subject: [PATCH 1/4] Add a Makefile to auto-build everything in a headless environment --- Makefile | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ configure.xml | 47 ++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 Makefile create mode 100644 configure.xml diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..59d4dc41d --- /dev/null +++ b/Makefile @@ -0,0 +1,94 @@ +# To use this file, run: +# +# $ make CONFIGURE_FLAGS="-Dplugin.path=/path/to/your/eclipse/plugins" +# +# For example, on Debian GNU/Linux: +# +# $ make CONFIGURE_FLAGS="-Dplugin.path=/usr/lib/eclipse:/usr/share/eclipse/dropins/jdt" +# +# You can also add e.g. "-DforceContextQualifier=none" to make the jars be +# output under a stable filename. +# +# Due to https://github.com/zhourenjian/java2script/issues/7 you may need to +# run this using xvfb https://packages.debian.org/sid/xvfb +# +CONFIGURE_FLAGS += +CORE_FLAGS += -DjavacFailOnError=true +INCUBATOR_FLAGS += -DjavacFailOnError=true -DjavacSource=1.6 -DjavacTarget=1.6 + +# Order is important; dependencies must go earlier. +CORE_PLUGINS = net.sf.j2s.core net.sf.j2s.ajax net.sf.j2s.ui net.sf.j2s.lib +INCUBATOR_PLUGINS = net.sf.j2s.ui.template.velocity net.sf.j2s.ui.cmdline +CORE_J2SLIB = net.sf.j2s.ajax net.sf.j2s.java.core net.sf.j2s.java.org.eclipse.swt + +BUILD_WORKSPACE := $(PWD)/autobuild +ECLIPSE_AUTO = eclipse \ + -configuration $(BUILD_WORKSPACE)/configuration \ + -user $(BUILD_WORKSPACE) \ + -data $(BUILD_WORKSPACE) \ + -nosplash -clean + +ECLIPSE_ANT = $(ECLIPSE_AUTO) \ + -application org.eclipse.ant.core.antRunner +ECLIPSE_ANT_BUILD = $(ECLIPSE_ANT) build.update.jar +ECLIPSE_ANT_CLEAN = if [ -f build.xml ]; then \ + $(ECLIPSE_ANT) clean; \ + rm -rf build.xml javaCompiler...args; \ +fi +ECLIPSE_J2S = $(ECLIPSE_AUTO) \ + -application net.sf.j2s.ui.cmdlineApi + +all: build-libs + +configure: + $(ECLIPSE_ANT) -f configure.xml $(CONFIGURE_FLAGS) + +build-plugins: configure + set -e; for i in $(CORE_PLUGINS:%=sources/%); do \ + ( cd $$i && $(ECLIPSE_ANT_BUILD) $(CORE_FLAGS); ) \ + done + set -e; for i in $(INCUBATOR_PLUGINS:%=incubator/%); do \ + ( cd $$i && $(ECLIPSE_ANT_BUILD) $(INCUBATOR_FLAGS); ) \ + done + +local-install-plugins: build-plugins + $(MAKE) DESTDIR=$(BUILD_WORKSPACE) eclipsedir= install-plugins + mkdir -p $(BUILD_WORKSPACE)/features + touch $(BUILD_WORKSPACE)/artifacts.xml + $(ECLIPSE_AUTO) -initialize + +build-libs: local-install-plugins + set -e; for i in $(CORE_J2SLIB); do \ + $(ECLIPSE_J2S) -cmd build -path $$PWD/sources/$$i; \ + done + mkdir -p sources/net.sf.j2s.lib/bin sources/net.sf.j2s.lib/j2slib + cd sources/net.sf.j2s.lib/bin && jar xf ../library.jar + cd sources/net.sf.j2s.lib && ant -f build/build.xml + cd sources/net.sf.j2s.lib && zip -r j2slib.zip j2slib + +clean: + for i in $(INCUBATOR_PLUGINS:%=incubator/%); do \ + ( cd $$i && $(ECLIPSE_ANT_CLEAN); ) \ + done + for i in $(CORE_PLUGINS:%=sources/%); do \ + ( cd $$i && $(ECLIPSE_ANT_CLEAN); ) \ + done + rm -rf $(BUILD_WORKSPACE)/.metadata + +prefix ?= /usr/local +eclipsedir ?= $(prefix)/share/eclipse +datadir ?= $(prefix)/share/java2script +pluginsdir ?= $(eclipsedir)/plugins + +install-plugins: + test -z "$(DESTDIR)$(pluginsdir)" || mkdir -p "$(DESTDIR)$(pluginsdir)" + install -t "$(DESTDIR)$(pluginsdir)" \ + $(join $(CORE_PLUGINS:%=sources/%/),$(CORE_PLUGINS:%=%_2.0.0.jar)) \ + $(join $(INCUBATOR_PLUGINS:%=incubator/%/),$(INCUBATOR_PLUGINS:%=%_1.0.0.*.jar)) + +install: install-plugins + test -z "$(DESTDIR)$(datadir)" || mkdir -p "$(DESTDIR)$(datadir)" + install -t "$(DESTDIR)$(datadir)" \ + sources/net.sf.j2s.lib/j2slib.zip + +.PHONY: all configure build-plugins local-install-plugins build-libs clean install-plugins install diff --git a/configure.xml b/configure.xml new file mode 100644 index 000000000..9c3149a96 --- /dev/null +++ b/configure.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + From 30d9dfcb4a2a9c782ed58867116247a282e5a792 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Thu, 27 Oct 2016 14:14:48 +0200 Subject: [PATCH 2/4] Work around a JDK segfault --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 59d4dc41d..89f1fae8f 100644 --- a/Makefile +++ b/Makefile @@ -57,9 +57,17 @@ local-install-plugins: build-plugins touch $(BUILD_WORKSPACE)/artifacts.xml $(ECLIPSE_AUTO) -initialize +# Work around https://bugs.eclipse.org/bugs/show_bug.cgi?id=465693 (actually a JDK bug) +# Otherwise the net.sf.j2s.java.core build wil segfault about half of the time. +# Annoyingly, the segfault causes java to exit 0; I was unable to figure out why. +# So we add some extra checks, testing for the absence of crash logs. +BADMETHOD1 = org/eclipse/jdt/internal/compiler/parser/TypeConverter.decodeType +WORKAROUND1 = -vmargs -XX:CompileCommand=exclude,$(BADMETHOD1) build-libs: local-install-plugins + test ! -f *err*.log set -e; for i in $(CORE_J2SLIB); do \ - $(ECLIPSE_J2S) -cmd build -path $$PWD/sources/$$i; \ + $(ECLIPSE_J2S) -cmd build -path $$PWD/sources/$$i $(WORKAROUND1); \ + test ! -f *err*.log; \ done mkdir -p sources/net.sf.j2s.lib/bin sources/net.sf.j2s.lib/j2slib cd sources/net.sf.j2s.lib/bin && jar xf ../library.jar From 99c633ba4a39f83eb580e2fa87043b6b35e3a22c Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Thu, 27 Oct 2016 16:04:19 +0200 Subject: [PATCH 3/4] Enable/disable the correct build commands When building net.sf.j2s.ajax as a PDE project and then a J2S project --- Makefile | 4 ++++ switch-build-command.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 switch-build-command.sh diff --git a/Makefile b/Makefile index 89f1fae8f..4ed40894e 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,8 @@ configure: $(ECLIPSE_ANT) -f configure.xml $(CONFIGURE_FLAGS) build-plugins: configure + sh switch-build-command.sh sources/net.sf.j2s.ajax/.project \ + -net.sf.j2s.core.java2scriptbuilder +org.eclipse.jdt.core.javabuilder set -e; for i in $(CORE_PLUGINS:%=sources/%); do \ ( cd $$i && $(ECLIPSE_ANT_BUILD) $(CORE_FLAGS); ) \ done @@ -64,6 +66,8 @@ local-install-plugins: build-plugins BADMETHOD1 = org/eclipse/jdt/internal/compiler/parser/TypeConverter.decodeType WORKAROUND1 = -vmargs -XX:CompileCommand=exclude,$(BADMETHOD1) build-libs: local-install-plugins + sh switch-build-command.sh sources/net.sf.j2s.ajax/.project \ + +net.sf.j2s.core.java2scriptbuilder -org.eclipse.jdt.core.javabuilder test ! -f *err*.log set -e; for i in $(CORE_J2SLIB); do \ $(ECLIPSE_J2S) -cmd build -path $$PWD/sources/$$i $(WORKAROUND1); \ diff --git a/switch-build-command.sh b/switch-build-command.sh new file mode 100644 index 000000000..18b7ce6a1 --- /dev/null +++ b/switch-build-command.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +enable() { +perl -0 -p \ + -e 's||\1|gs' +} + +disable() { +perl -0 -p \ + -e 's|\n((\s*)\s*'"$1"'.*?\n(\s*).*?\n)|\n\2\n|sg' \ +| perl -0 -p \ + -e 's|)\s*-->|\1|gs' +} + +file="$1" +shift + +while [ -n "$1" ]; do +case "$1" in ++*) cmd=enable;name="${1#+}";; +-*) cmd=disable;name="${1#-}";; +*) false;; +esac +echo "$cmd" "$name" +sed -e 's/\r$//g' "$file" | $cmd "$name" | sed -e 's/$/\r/g' > "$file.tmp" +mv "$file.tmp" "$file" +shift +done From 19f470bd11ab4bc0490dcf7192358eb6dd66cc57 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Sun, 6 Nov 2016 17:08:27 +0100 Subject: [PATCH 4/4] Properly fail the whole build if there was an error --- sources/net.sf.j2s.lib/build/build.xml | 76 +++++++++---------- .../src/net/sf/j2s/lib/build/UTF8Concat.java | 3 +- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/sources/net.sf.j2s.lib/build/build.xml b/sources/net.sf.j2s.lib/build/build.xml index a03428969..a15ba4103 100644 --- a/sources/net.sf.j2s.lib/build/build.xml +++ b/sources/net.sf.j2s.lib/build/build.xml @@ -39,7 +39,7 @@ - - - - - - - - - - - - - - - - - --> - + @@ -52,7 +52,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -78,7 +78,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -105,7 +105,7 @@ - + @@ -122,7 +122,7 @@ - + @@ -135,7 +135,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -166,7 +166,7 @@ - + @@ -185,7 +185,7 @@ target: j2s.pack.common - - - - - - - - - - - - - - - - - --> - + @@ -375,7 +375,7 @@ - + @@ -387,7 +387,7 @@ - + @@ -510,7 +510,7 @@ - + @@ -543,7 +543,7 @@ target: pack.swt.css - - - - - - - - - - - - - - - - - --> - + @@ -567,7 +567,7 @@ target: pack.swt.basic ================================= --> - + @@ -715,7 +715,7 @@ target: pack.swt.more ================================= --> - + @@ -746,7 +746,7 @@ - + @@ -759,7 +759,7 @@ - + @@ -772,7 +772,7 @@ - + @@ -785,7 +785,7 @@ - + @@ -799,7 +799,7 @@ - + @@ -812,7 +812,7 @@ - + @@ -826,7 +826,7 @@ - + @@ -842,7 +842,7 @@ - + @@ -861,7 +861,7 @@ - + @@ -874,7 +874,7 @@ - + @@ -887,7 +887,7 @@ - + @@ -900,7 +900,7 @@ - + @@ -913,7 +913,7 @@ - + @@ -925,7 +925,7 @@ - + @@ -938,7 +938,7 @@ - + @@ -959,7 +959,7 @@ target: pack.swt.shell ================================= --> - + @@ -991,7 +991,7 @@ target: pack.swt.dnd ================================= --> - + @@ -1027,7 +1027,7 @@ target: pack.jface.viewer ================================= --> - + @@ -1081,7 +1081,7 @@ target: pack.jface.resource ================================= --> - + @@ -1124,7 +1124,7 @@ target: pack.jface.util ================================= --> - + @@ -1151,7 +1151,7 @@ target: pack.jface.window ================================= --> - + diff --git a/sources/net.sf.j2s.lib/src/net/sf/j2s/lib/build/UTF8Concat.java b/sources/net.sf.j2s.lib/src/net/sf/j2s/lib/build/UTF8Concat.java index 5a1ab1c61..3d25741ed 100644 --- a/sources/net.sf.j2s.lib/src/net/sf/j2s/lib/build/UTF8Concat.java +++ b/sources/net.sf.j2s.lib/src/net/sf/j2s/lib/build/UTF8Concat.java @@ -79,7 +79,7 @@ public static void main(String[] args) { //*/ } catch (FileNotFoundException e) { e.printStackTrace(); - return; + System.exit(1); } } try { @@ -98,6 +98,7 @@ public static void main(String[] args) { fos.close(); } catch (IOException e) { e.printStackTrace(); + System.exit(1); } }