summaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-05-07 04:02:44 +0000
committerwisberg <wisberg>2003-05-07 04:02:44 +0000
commit7367c59373eb402653448b551a72e9469af751b0 (patch)
tree5e59c4324d368c02d3eeaa8d29ffe17ea5a5783d /testing
parent966bb389b8bc349cfdf675ec332e26cccbbaaedb (diff)
downloadaspectj-7367c59373eb402653448b551a72e9469af751b0.tar.gz
aspectj-7367c59373eb402653448b551a72e9469af751b0.zip
AJDE compiler, supports fresh incremental builds
Diffstat (limited to 'testing')
-rw-r--r--testing/src/org/aspectj/testing/ajde/CompileCommand.java253
1 files changed, 253 insertions, 0 deletions
diff --git a/testing/src/org/aspectj/testing/ajde/CompileCommand.java b/testing/src/org/aspectj/testing/ajde/CompileCommand.java
new file mode 100644
index 000000000..e9d75466a
--- /dev/null
+++ b/testing/src/org/aspectj/testing/ajde/CompileCommand.java
@@ -0,0 +1,253 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Wes Isberg initial implementation
+ * ******************************************************************/
+
+package org.aspectj.testing.ajde;
+
+import java.awt.Frame;
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.List;
+
+import org.aspectj.ajde.*;
+import org.aspectj.ajde.ui.*;
+import org.aspectj.ajde.ui.internal.*;
+import org.aspectj.ajde.ui.swing.*;
+import org.aspectj.asm.StructureNode;
+import org.aspectj.bridge.*;
+import org.aspectj.util.FileUtil;
+
+/**
+ * This re-uses the same config file to setup ajde
+ * so that recompiles appear to be of the same configuration.
+ * @since Java 1.3 (uses dynamic proxies)
+ */
+public class CompileCommand implements ICommand {
+ // time out waiting for build at three minutes
+ long MAX_TIME = 180 * 1000;
+ // this proxy ignores calls
+ InvocationHandler proxy = new VoidInvocationHandler();
+ MyTaskListManager myHandler = new MyTaskListManager();
+ long endTime;
+ boolean buildNextFresh;
+
+ /**
+ * Clients call this before repeatCommand as a one-shot
+ * request for a full rebuild of the same configuration.
+ * (Requires a downcast from ICommand to CompileCommand.)
+ */
+ public void buildNextFresh() {
+ buildNextFresh = true;
+ }
+
+ // --------- ICommand interface
+ public boolean runCommand(String[] args, IMessageHandler handler) {
+ setup(args);
+ myHandler.start();
+ long startTime = System.currentTimeMillis();
+ Ajde.getDefault().getBuildManager().buildFresh();
+ // System.err.println("compiling " + Arrays.asList(args));
+ waitForCompletion(startTime);
+ myHandler.finish(handler);
+ return !myHandler.hasError();
+ }
+
+ public boolean repeatCommand(IMessageHandler handler) {
+ myHandler.start();
+ long startTime = System.currentTimeMillis();
+ // System.err.println("recompiling...");
+ if (buildNextFresh) {
+ buildNextFresh = false;
+ Ajde.getDefault().getBuildManager().buildFresh();
+ } else {
+ Ajde.getDefault().getBuildManager().build();
+ }
+ waitForCompletion(startTime);
+ myHandler.finish(handler);
+ return !myHandler.hasError();
+ }
+
+ // set by build progress monitor when done
+ void setEndTime(long endTime) {
+ this.endTime = endTime;
+ }
+
+ private void waitForCompletion(long startTime) {
+ long maxTime = startTime + MAX_TIME;
+ while ((startTime > endTime)
+ && (maxTime > System.currentTimeMillis())){
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+
+ private void setup(String[] args) {
+ File config = writeConfig(args);
+ if (null == config) {
+ throw new Error("unable to write config file");
+ }
+ EditorAdapter editorAdapter
+ = (EditorAdapter) makeProxy(EditorAdapter.class);
+ TaskListManager taskListManager = myHandler;
+ BuildProgressMonitor buildProgressMonitor
+ = new DefaultBuildProgressMonitor(new Frame()){
+ public void finish() {
+ super.finish();
+ setEndTime(System.currentTimeMillis());
+ }
+ };
+ ProjectPropertiesAdapter projectPropertiesAdapter
+ = new NullIdeProperties("");
+ BuildOptionsAdapter buildOptionsAdapter
+ = new AjcBuildOptions(new UserPreferencesStore(false));
+ IdeUIAdapter ideUIAdapter
+ = (IdeUIAdapter) makeProxy(IdeUIAdapter.class);
+ ErrorHandler errorHandler
+ = (ErrorHandler) makeProxy(ErrorHandler.class);
+
+ AbstractIconRegistry iconRegistry = new AbstractIconRegistry() {
+ protected AbstractIcon createIcon(String path) {
+ return new AbstractIcon(new Object());
+ }
+ };
+ StructureViewNodeFactory structureViewNodeFactory =
+ new StructureViewNodeFactory(iconRegistry) {
+ protected StructureViewNode createConcreteNode(
+ StructureNode node,
+ AbstractIcon icon,
+ List children) {
+ return new SwingTreeViewNode(node, icon, children);
+ }
+ };
+
+ Ajde.init(
+ editorAdapter,
+ taskListManager,
+ buildProgressMonitor,
+ projectPropertiesAdapter,
+ buildOptionsAdapter,
+ structureViewNodeFactory,
+ ideUIAdapter,
+ errorHandler
+ );
+
+ Ajde.getDefault().getConfigurationManager().setActiveConfigFile(config.getAbsolutePath());
+ }
+
+ private File writeConfig(String[] args) {
+ File result = new File(FileUtil.getTempDir("CompileCommand"), "config.lst");
+ OutputStream out = null;
+ try {
+ out = new FileOutputStream(result);
+ PrintStream outs = new PrintStream(out, true);
+ for (int i = 0; i < args.length; i++) {
+ outs.println(args[i]);
+ }
+ return result;
+ } catch (IOException e) {
+ return null;
+ } finally{
+ try {
+ out.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ private Object makeProxy(Class interfac){
+ return Proxy.newProxyInstance(
+ interfac.getClassLoader(),
+ new Class[] { interfac },
+ proxy);
+ }
+}
+
+class MyTaskListManager extends MessageHandler
+ implements TaskListManager {
+ boolean hasError;
+ boolean hasWarning;
+ MyTaskListManager() {
+ super(true);
+ }
+ public void addProjectTask(String message, IMessage.Kind kind) {
+ maintainHasWarning(kind);
+ }
+
+ public void addSourcelineTask(IMessage message) {
+ maintainHasWarning(message.getKind());
+ handleMessage(message);
+ }
+
+ public void addSourcelineTask(
+ String message,
+ ISourceLocation sourceLocation,
+ IMessage.Kind kind) {
+ addSourcelineTask(new Message(message, kind, null, sourceLocation));
+ }
+
+ public void clearTasks() {
+ if (hasWarning) {
+ hasWarning = false;
+ }
+ if (hasError) {
+ hasError = false;
+ }
+ init(true);
+ }
+
+ public boolean hasWarning() {
+ return hasWarning;
+ }
+
+ boolean hasError() {
+ return hasError;
+ }
+
+ void start() {
+ clearTasks();
+ }
+ void finish(IMessageHandler copyTo) {
+ if (copyTo == this) {
+ return;
+ }
+ IMessage[] messages = getMessages(null, true);
+ for (int i = 0; i < messages.length; i++) {
+ copyTo.handleMessage(messages[i]);
+ }
+ }
+ private void maintainHasWarning(IMessage.Kind kind) {
+ if (!hasError) {
+ if (IMessage.ERROR.isSameOrLessThan(kind)) {
+ hasError = true;
+ hasWarning = true;
+ }
+ }
+ if (!hasWarning && IMessage.WARNING.isSameOrLessThan(kind)) {
+ hasWarning = true;
+ }
+ }
+}
+
+class VoidInvocationHandler implements InvocationHandler {
+ public Object invoke(Object me, Method method, Object[] args)
+ throws Throwable {
+// System.err.println("Proxying"
+// // don't call toString on self b/c proxied
+// // + " me=" + me.getClass().getName()
+// + " method=" + method
+// + " args=" + (LangUtil.isEmpty(args)
+// ? "[]" : Arrays.asList(args).toString()));
+ return null;
+ }
+}
+
83 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820