diff options
author | aclement <aclement> | 2007-01-15 09:37:23 +0000 |
---|---|---|
committer | aclement <aclement> | 2007-01-15 09:37:23 +0000 |
commit | 8559a350a486171c332791c8364d857a074531e0 (patch) | |
tree | 9fea02d68204d89bb16c1abb162b02338abfc9d7 /ajde | |
parent | fb86dd4ca2edac7e1eb639cfde1d4b2a4f450457 (diff) | |
download | aspectj-8559a350a486171c332791c8364d857a074531e0.tar.gz aspectj-8559a350a486171c332791c8364d857a074531e0.zip |
148190#35
Diffstat (limited to 'ajde')
20 files changed, 1733 insertions, 13 deletions
diff --git a/ajde/src/org/aspectj/ajde/IRuntimeProperties.java b/ajde/src/org/aspectj/ajde/IRuntimeProperties.java new file mode 100644 index 000000000..9970c597e --- /dev/null +++ b/ajde/src/org/aspectj/ajde/IRuntimeProperties.java @@ -0,0 +1,30 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde; + +/** + * Interface to enable users to specify which class to run + */ +public interface IRuntimeProperties { + + /** + * @return class which contains the main method and should + * be used to run the application + */ + public String getClassToExecute(); + + /** + * @return args which should be used as part of the execution + * of the application + */ + public String getExecutionArgs(); + +} diff --git a/ajde/src/org/aspectj/ajde/IUIBuildMessageHandler.java b/ajde/src/org/aspectj/ajde/IUIBuildMessageHandler.java new file mode 100644 index 000000000..7e9678d22 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/IUIBuildMessageHandler.java @@ -0,0 +1,27 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde; + +import org.aspectj.ajde.core.IBuildMessageHandler; + +/** + * Extension to the IBuildMessageHandler to be used if only one BuildMessageHandler + * is going to be used for all projects/build configuration files. Provides a method + * for resetting the state of the BuildMessageHandler between compiles + */ +public interface IUIBuildMessageHandler extends IBuildMessageHandler { + + /** + * Reset the state of the message handler + */ + public void reset(); + +} diff --git a/ajde/src/org/aspectj/ajde/IconRegistry.java b/ajde/src/org/aspectj/ajde/IconRegistry.java new file mode 100644 index 000000000..4cdec89f2 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/IconRegistry.java @@ -0,0 +1,158 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde; + +import javax.swing.*; + +import org.aspectj.ajde.ui.*; +import org.aspectj.asm.*; +import org.aspectj.asm.IProgramElement; + +/** + * Default icons. Override behavior for custom icons. + * + * @author Mik Kersten + */ +public class IconRegistry extends AbstractIconRegistry { + + //public static IconRegistry INSTANCE = null; + protected String RESOURCE_PATH = "org/aspectj/ajde/resources/"; + + private final Icon START_AJDE = makeIcon("actions/startAjde.gif"); + private final Icon STOP_AJDE = makeIcon("actions/stopAjde.gif"); + private final Icon BUILD = makeIcon("actions/build.gif"); + private final Icon DEBUG = makeIcon("actions/debug.gif"); + private final Icon EXECUTE = makeIcon("actions/execute.gif"); + private final Icon AJBROWSER = makeIcon("structure/advice.gif"); + private final Icon AJBROWSER_ENABLED = makeIcon("actions/browserEnabled.gif"); + private final Icon AJBROWSER_DISABLED = makeIcon("actions/browserDisabled.gif"); + private final Icon STRUCTURE_VIEW = makeIcon("actions/structureView.gif"); + + private final Icon HIDE_ASSOCIATIONS = makeIcon("actions/hideAssociations.gif"); + private final Icon HIDE_NON_AJ = makeIcon("actions/hideNonAJ.gif"); + private final Icon GRANULARITY = makeIcon("actions/granularity.gif"); + private final Icon AJDE_SMALL = makeIcon("actions/ajdeSmall.gif"); + + private final Icon ERROR = makeIcon("structure/error.gif"); + private final Icon WARNING = makeIcon("structure/warning.gif"); + private final Icon INFO = makeIcon("structure/info.gif"); + + private final Icon POPUP = makeIcon("actions/popup.gif"); + private final Icon FILTER = makeIcon("actions/filter.gif"); + private final Icon RELATIONS = makeIcon("actions/relations.gif"); + private final Icon ORDER = makeIcon("actions/order.gif"); + + private final Icon ZOOM_STRUCTURE_TO_FILE_MODE = makeIcon("actions/zoomStructureToFileMode.gif"); + private final Icon ZOOM_STRUCTURE_TO_GLOBAL_MODE = makeIcon("actions/zoomStructureToGlobalMode.gif"); + private final Icon SPLIT_STRUCTURE_VIEW = makeIcon("actions/splitStructureView.gif"); + private final Icon MERGE_STRUCTURE_VIEW = makeIcon("actions/mergeStructureView.gif"); + + private final Icon BACK = makeIcon("actions/back.gif"); + private final Icon FORWARD = makeIcon("actions/forward.gif"); + private final Icon SEARCH = makeIcon("actions/search.gif"); + private final Icon OPEN_CONFIG = makeIcon("actions/openConfig.gif"); + private final Icon CLOSE_CONFIG = makeIcon("actions/closeConfig.gif"); + private final Icon SAVE = makeIcon("actions/save.gif"); + private final Icon SAVE_ALL = makeIcon("actions/saveAll.gif"); + private final Icon BROWSER_OPTIONS = makeIcon("actions/browseroptions.gif"); + + private final Icon ACCESSIBILITY_PUBLIC = makeIcon("structure/accessibility-public.gif"); + private final Icon ACCESSIBILITY_PACKAGE = makeIcon("structure/accessibility-package.gif"); + private final Icon ACCESSIBILITY_PROTECTED = makeIcon("structure/accessibility-protected.gif"); + private final Icon ACCESSIBILITY_PRIVATE = makeIcon("structure/accessibility-private.gif"); + private final Icon ACCESSIBILITY_PRIVILEGED = makeIcon("structure/accessibility-privileged.gif"); + + public Icon getAjdeSmallIcon() { return AJDE_SMALL; } + public Icon getHideAssociationsIcon() { return HIDE_ASSOCIATIONS; } + public Icon getHideNonAJIcon() { return HIDE_NON_AJ; } + public Icon getGranularityIcon() { return GRANULARITY; } + public Icon getErrorIcon() { return ERROR; } + public Icon getWarningIcon() { return WARNING; } + public Icon getInfoIcon() { return INFO; } + public Icon getAJBrowserIcon() { return AJBROWSER; } + public Icon getAJBrowserEnabledIcon() { return AJBROWSER_ENABLED; } + public Icon getAJBrowserDisabledIcon() { return AJBROWSER_DISABLED; } + public Icon getPopupIcon() { return POPUP; } + public Icon getFilterIcon() { return FILTER; } + public Icon getOrderIcon() { return ORDER; } + public Icon getRelationsIcon() { return RELATIONS; } + public Icon getStartAjdeIcon() { return START_AJDE; } + public Icon getStopAjdeIcon() { return STOP_AJDE; } + public Icon getBackIcon() { return BACK; } + public Icon getForwardIcon() { return FORWARD; } + public Icon getSearchIcon() { return SEARCH; } + public Icon getBuildIcon() { return BUILD; } + public Icon getDebugIcon() { return DEBUG; } + public Icon getExecuteIcon() { return EXECUTE; } + public Icon getOpenConfigIcon() { return OPEN_CONFIG; } + public Icon getCloseConfigIcon() { return CLOSE_CONFIG; } + public Icon getOpenIcon() { return OPEN_CONFIG; } + public Icon getSaveIcon() { return SAVE; } + public Icon getSaveAllIcon() { return SAVE_ALL; } + public Icon getBrowserOptionsIcon() { return BROWSER_OPTIONS; } + public Icon getZoomStructureToFileModeIcon() { return ZOOM_STRUCTURE_TO_FILE_MODE; } + public Icon getZoomStructureToGlobalModeIcon() { return ZOOM_STRUCTURE_TO_GLOBAL_MODE; } + public Icon getSplitStructureViewIcon() { return SPLIT_STRUCTURE_VIEW; } + public Icon getMergeStructureViewIcon() { return MERGE_STRUCTURE_VIEW; } + public Icon getStructureViewIcon() { return STRUCTURE_VIEW; } + + public Icon getAssociationSwingIcon(IRelationship.Kind relation) { + return convertToSwingIcon(getIcon(relation)); + } + + public AbstractIcon getStructureIcon(IProgramElement.Kind kind, IProgramElement.Accessibility accessibility) { + return getIcon(kind); + } + + public Icon getStructureSwingIcon(IProgramElement.Kind kind, IProgramElement.Accessibility accessibility) { + return convertToSwingIcon(getStructureIcon(kind, accessibility)); + } + + public Icon getStructureSwingIcon(IProgramElement.Kind kind) { + return convertToSwingIcon(getIcon(kind)); + } + + public Icon getAccessibilitySwingIcon(IProgramElement.Accessibility accessibility) { + if (accessibility == IProgramElement.Accessibility.PUBLIC) { + return ACCESSIBILITY_PUBLIC; + } else if (accessibility == IProgramElement.Accessibility.PACKAGE) { + return ACCESSIBILITY_PACKAGE; + } else if (accessibility == IProgramElement.Accessibility.PROTECTED) { + return ACCESSIBILITY_PROTECTED; + } else if (accessibility == IProgramElement.Accessibility.PRIVATE) { + return ACCESSIBILITY_PRIVATE; + } else if (accessibility == IProgramElement.Accessibility.PRIVILEGED) { + return ACCESSIBILITY_PRIVILEGED; + } else { + return null; + } + } + + public Icon convertToSwingIcon(AbstractIcon iconAdapter) { + if (iconAdapter != null) { + return (Icon)iconAdapter.getIconResource(); + } else { + return null; + } + } + + protected AbstractIcon createIcon(String path) { + return new AbstractIcon(new ImageIcon(ClassLoader.getSystemResource(path))); + } + + protected Icon makeIcon(String iconPath) { + return new ImageIcon(ClassLoader.getSystemResource(RESOURCE_PATH + iconPath)); + } +} diff --git a/ajde/src/org/aspectj/ajde/IdeUIAdapter.java b/ajde/src/org/aspectj/ajde/IdeUIAdapter.java new file mode 100644 index 000000000..9c526fb0d --- /dev/null +++ b/ajde/src/org/aspectj/ajde/IdeUIAdapter.java @@ -0,0 +1,23 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde; + +/** + * @author Mik Kersten + */ +public interface IdeUIAdapter { + + public void displayStatusInformation(String message); +} diff --git a/ajde/src/org/aspectj/ajde/internal/BuildConfigListener.java b/ajde/src/org/aspectj/ajde/internal/BuildConfigListener.java new file mode 100644 index 000000000..30d3f1e35 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/internal/BuildConfigListener.java @@ -0,0 +1,37 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + + +package org.aspectj.ajde.internal; + +import java.util.EventListener; +import java.util.List; + +/** + * @author Mik Kersten + */ +public interface BuildConfigListener extends EventListener { + + /** + * Called when the current configuration has changed. + * + * @param configFilePath the path to the new current configuration file + */ + public void currConfigChanged(String configFilePath); + + /** + * Called when items are added to or deleted from the configurations list. + */ + public void configsListUpdated(List configsList); +} diff --git a/ajde/src/org/aspectj/ajde/internal/BuildConfigManager.java b/ajde/src/org/aspectj/ajde/internal/BuildConfigManager.java new file mode 100644 index 000000000..f049357c5 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/internal/BuildConfigManager.java @@ -0,0 +1,99 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.internal; + +import java.util.List; + +import org.aspectj.ajde.ui.BuildConfigModel; + +/** + * @author Mik Kersten + */ +public interface BuildConfigManager { + + public static final String CONFIG_FILE_SUFFIX = ".lst"; + + public static final String DEFAULT_CONFIG_LABEL = "<all project files>"; + + /** + * Returns the currently active build configuration file. The current active + * build configuration file that is set in this class is used for building and + * for updating the structure model. + * + * @return full path to the file + */ + public String getActiveConfigFile(); + + /** + * Sets the currently active build configuration file. + * + * @param full path to the file + */ + public void setActiveConfigFile(String currConfigFilePath); + + /** + * Add a listner that will be notified of build configuration change events + */ + public void addListener(BuildConfigListener configurationListener); + + /** + * Remove a configuration listener. + */ + public void removeListener(BuildConfigListener configurationListener); + + /** + * Build a model for the corresponding configuration file. + * + * @param full path to the file + */ + public BuildConfigModel buildModel(String configFilePath); + + /** + * Save the given configuration model to the file that it was generated from. + */ + public void writeModel(BuildConfigModel model); + + /** + * Write a list of source files into a configuration file. File paths will be + * written relative to the path of the configuration file. + */ + public void writePaths(String configFilePath, List paths); + + /** + * Add files to a configuration. + * + * @param configFilePath full path to the configuration file + * @param files list of full paths to the files to be added + */ + public void addFilesToConfig(String configFilePath, List files); + + /** + * Remove files from a configuration. + * + * @param configFilePath full path to the configuration file + * @param files list of full paths to the files to be removed + */ + public void removeFilesFromConfig(String configFilePath, List files); + + + /** + * @return list (of Strings) of all build configuration files + * found so far + */ + public List /*String*/ getAllBuildConfigFiles(); + +} + + diff --git a/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaBuildOptions.java b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaBuildOptions.java new file mode 100644 index 000000000..313ad0d1a --- /dev/null +++ b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaBuildOptions.java @@ -0,0 +1,168 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.util.Map; + +import org.aspectj.ajde.core.JavaOptions; + +/** + * Class which handles the setting of the java options and the + * java options map required by ICompilerConfiguration#getJavaOptionsMap() + */ +public class JavaBuildOptions { + + private Map javaBuildOptions; + + public JavaBuildOptions() { + javaBuildOptions = JavaOptions.getDefaultJavaOptions(); + } + + public Map getJavaBuildOptionsMap() { + return javaBuildOptions; + } + + public void setOption(String javaOption, String value) { + javaBuildOptions.put(javaOption,value); + } + + // ----------------- compliance settings --------------- + + // compliance + public void setComplianceLevel(String level) { + if (JavaOptions.isValidJvmVersion(level)) { + javaBuildOptions.put(JavaOptions.COMPLIANCE_LEVEL,level); + } + } + // source + public void setSourceCompatibilityLevel(String level) { + if (JavaOptions.isValidJvmVersion(level)) { + javaBuildOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL,level); + } + } + // target + public void setTargetLevel(String level) { + if (JavaOptions.isValidJvmVersion(level)) { + javaBuildOptions.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL,level); + } + } + + // ---------------- compiler warning options ------------------ + + // warn method with constructor name + public void setWarnMethodWithConstructorName(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME,option); + } + } + // warn overriding package default method + public void setWarnOverridingPackageDefaultMethod(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD,option); + } + } + // warn deprecation + public void setWarnDeprecation(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_DEPRECATION,option); + } + } + // warn hidden catch blocks + public void setWarnHiddenCatchBlocks(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_HIDDEN_CATCH_BLOCKS,option); + } + } + // warn unused locals + public void setWarnUnusedLocals(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_UNUSED_LOCALS,option); + } + } + // warn unused parameters + public void setWarnUnusedParameters(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_UNUSED_PARAMETER,option); + } + } + // warn unused imports + public void setWarnUnusedImports(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_UNUSED_IMPORTS,option); + } + } + // warn synthetic access + public void setWarnSyntheticAccess(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_SYNTHETIC_ACCESS,option); + } + } + // warn assert identifier + public void setWarnAssertIdentifier(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_ASSERT_IDENITIFIER,option); + } + } + // warn non nls + public void setWarnNonNLS(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put( + JavaOptions.WARN_NON_NLS,option); + } + } + + // --------------- debug options -------------------- + + // debug source + public void setDebugSource(String option) { + if (JavaOptions.isGenerateOrNot(option)) { + javaBuildOptions.put( + JavaOptions.DEBUG_SOURCE,option); + } + } + // debug lines + public void setDebugLines(String option) { + if (JavaOptions.isGenerateOrNot(option)) { + javaBuildOptions.put( + JavaOptions.DEBUG_LINES,option); + } + } + // debug vars + public void setDebugVariables(String option) { + if (JavaOptions.isGenerateOrNot(option)) { + javaBuildOptions.put( + JavaOptions.DEBUG_VARS,option); + } + } + // preserve all locals + public void setPreserveAllLocals(String value) { + if (JavaOptions.isValidPreserveAllLocalsOption(value)) { + javaBuildOptions.put(JavaOptions.PRESERVE_ALL_LOCALS,value); + } + } + + // ----------- other settings + // character encoding + public void setCharacterEncoding(String value) { + javaBuildOptions.put(JavaOptions.CHARACTER_ENCODING, value); + } + + +} diff --git a/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaCompilerWarningsOptionsPanel.java b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaCompilerWarningsOptionsPanel.java new file mode 100644 index 000000000..f34ace5df --- /dev/null +++ b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaCompilerWarningsOptionsPanel.java @@ -0,0 +1,140 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the java compiler warning options. + * Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaCompilerWarningsOptionsPanel extends OptionsPanel { + + private final String[] ignoreOrWarning = new String[] {JavaOptions.IGNORE,JavaOptions.WARNING}; + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border warningsEtchedBorder; + private TitledBorder warningsTitleBorder; + private Border warningsCompoundBorder; + private JPanel warningsPanel; + private Box warningsBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private Map/*String --> JComboBox*/ warningComboBoxes = new HashMap(); + + public JavaCompilerWarningsOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Compiler Warning Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createWarningContents(); + } + + public void saveOptions() throws IOException { + Set s = warningComboBoxes.entrySet(); + for (Iterator iterator = s.iterator(); iterator.hasNext();) { + Map.Entry entry = (Entry) iterator.next(); + String javaOption = (String) entry.getKey(); + JComboBox combo = (JComboBox)entry.getValue(); + String value = (String) combo.getSelectedItem(); + javaBuildOptions.setOption(javaOption, value); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + + private void createWarningContents() { + createWarningsEntry("Method with a constructor name",JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME); + createWarningsEntry("Method overriden but not package visible",JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD); + createWarningsEntry("Deprecated API's",JavaOptions.WARN_DEPRECATION); + createWarningsEntry("Hidden catch block",JavaOptions.WARN_HIDDEN_CATCH_BLOCKS); + createWarningsEntry("Unused local or private member",JavaOptions.WARN_UNUSED_LOCALS); + createWarningsEntry("Parameter is never read",JavaOptions.WARN_UNUSED_PARAMETER); + createWarningsEntry("Unused import",JavaOptions.WARN_UNUSED_IMPORTS); + createWarningsEntry("Synthetic access",JavaOptions.WARN_SYNTHETIC_ACCESS); + createWarningsEntry("Assert identifier",JavaOptions.WARN_ASSERT_IDENITIFIER); + createWarningsEntry("Non-externalized strings",JavaOptions.WARN_NON_NLS); + warningsPanel.add(warningsBox,null); + } + + private void createWarningsEntry(String labelText, String javaOptionToSet) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText(labelText); + panel.add(label,BorderLayout.WEST); + + JComboBox warnings = new JComboBox(ignoreOrWarning); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value.equals(JavaOptions.IGNORE)) { + warnings.setSelectedIndex(0); + } else { + warnings.setSelectedIndex(1); + } + panel.add(warnings,BorderLayout.EAST); + warningsBox.add(panel,null); + warningComboBoxes.put(javaOptionToSet,warnings); + } + + private void createBorders() { + warningsEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + warningsTitleBorder = new TitledBorder(warningsEtchedBorder, "Warning Options"); + warningsCompoundBorder = BorderFactory.createCompoundBorder(warningsTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + warningsTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + warningsPanel = new JPanel(); + warningsPanel.setBorder(warningsCompoundBorder); + parentPanel.add(warningsPanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java new file mode 100644 index 000000000..09eabe901 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java @@ -0,0 +1,143 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the java compiler compliance options. + * Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaComplianceOptionsPanel extends OptionsPanel { + + private final String[] complianceLevels = new String[] {JavaOptions.VERSION_13, JavaOptions.VERSION_14, JavaOptions.VERSION_15, JavaOptions.VERSION_16}; + + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border complianceEtchedBorder; + private TitledBorder complianceTitleBorder; + private Border complianceCompoundBorder; + private JPanel compliancePanel; + private Box complianceBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private Map/*String --> JComboBox*/ complianceComboBoxes = new HashMap(); + + public JavaComplianceOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Compliance Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createComplianceContents(); + } + + public void saveOptions() throws IOException { + Set s = complianceComboBoxes.entrySet(); + for (Iterator iterator = s.iterator(); iterator.hasNext();) { + Map.Entry entry = (Entry) iterator.next(); + String javaOption = (String) entry.getKey(); + JComboBox combo = (JComboBox)entry.getValue(); + String value = (String) combo.getSelectedItem(); + javaBuildOptions.setOption(javaOption, value); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + + private void createComplianceContents() { + createComplianceEntry("AjCompiler compliance level: ",JavaOptions.COMPLIANCE_LEVEL); + createComplianceEntry("Source compatibility: ",JavaOptions.SOURCE_COMPATIBILITY_LEVEL); + createComplianceEntry("Generated class file compatibility: ",JavaOptions.TARGET_COMPATIBILITY_LEVEL); + compliancePanel.add(complianceBox); + } + + private void createComplianceEntry(String labelText, String javaOptionToSet) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText(labelText); + panel.add(label,BorderLayout.WEST); + + JComboBox levels = new JComboBox(complianceLevels); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value == null) { + // default to 1.5 + levels.setSelectedIndex(2); + } else if (value.equals(JavaOptions.VERSION_13)) { + levels.setSelectedIndex(0); + } else if (value.equals(JavaOptions.VERSION_14)){ + levels.setSelectedIndex(1); + } else if (value.equals(JavaOptions.VERSION_15)){ + levels.setSelectedIndex(2); + } else if (value.equals(JavaOptions.VERSION_16)){ + levels.setSelectedIndex(3); + } + panel.add(levels,BorderLayout.EAST); + complianceBox.add(panel,null); + complianceComboBoxes.put(javaOptionToSet,levels); + } + + + private void createBorders() { + complianceEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + complianceTitleBorder = new TitledBorder(complianceEtchedBorder, "Compliance Options"); + complianceCompoundBorder = BorderFactory.createCompoundBorder(complianceTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + complianceTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + compliancePanel = new JPanel(); + compliancePanel.setBorder(complianceCompoundBorder); + + parentPanel.add(compliancePanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java new file mode 100644 index 000000000..7d19d6a08 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java @@ -0,0 +1,148 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the java compiler debug options. + * Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaDebugOptionsPanel extends OptionsPanel { + + private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE}; + private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE}; + + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border debugEtchedBorder; + private TitledBorder debugTitleBorder; + private Border debugCompoundBorder; + private JPanel debugPanel; + private Box debugBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private Map/*String --> JComboBox*/ debugComboBoxes = new HashMap(); + + public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Debug Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createDebugContents(); + } + + public void saveOptions() throws IOException { + Set s = debugComboBoxes.entrySet(); + for (Iterator iterator = s.iterator(); iterator.hasNext();) { + Map.Entry entry = (Entry) iterator.next(); + String javaOption = (String) entry.getKey(); + JComboBox combo = (JComboBox)entry.getValue(); + String value = (String) combo.getSelectedItem(); + javaBuildOptions.setOption(javaOption, value); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + private void createDebugContents() { + createDebugEntry("Add line number attributes to generated class files",JavaOptions.DEBUG_LINES); + createDebugEntry("Add source file name to generated class file",JavaOptions.DEBUG_SOURCE); + createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS); + createDebugEntry("Preserve unused (never read) local variables",JavaOptions.PRESERVE_ALL_LOCALS); + debugPanel.add(debugBox); + } + + private void createDebugEntry(String labelText, String javaOptionToSet) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText(labelText); + panel.add(label,BorderLayout.WEST); + + JComboBox debug = null; + if (javaOptionToSet.equals(JavaOptions.PRESERVE_ALL_LOCALS)) { + debug = new JComboBox(preserveOptions); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value.equals(JavaOptions.PRESERVE)) { + debug.setSelectedIndex(0); + } else { + debug.setSelectedIndex(1); + } + } else { + debug = new JComboBox(debugOptions); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value.equals(JavaOptions.GENERATE)) { + debug.setSelectedIndex(0); + } else { + debug.setSelectedIndex(1); + } + } + panel.add(debug,BorderLayout.EAST); + debugBox.add(panel,null); + debugComboBoxes.put(javaOptionToSet,debug); + } + + + private void createBorders() { + debugEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options"); + debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + debugPanel = new JPanel(); + debugPanel.setBorder(debugCompoundBorder); + + parentPanel.add(debugPanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaOtherOptionsPanel.java b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaOtherOptionsPanel.java new file mode 100644 index 000000000..5ffaf13c3 --- /dev/null +++ b/ajde/src/org/aspectj/ajde/ui/javaoptions/JavaOtherOptionsPanel.java @@ -0,0 +1,120 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.io.IOException; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the character encoding java + * compiler option. Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaOtherOptionsPanel extends OptionsPanel { + + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border otherEtchedBorder; + private TitledBorder otherTitleBorder; + private Border otherCompoundBorder; + private JPanel otherPanel; + private Box otherBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private JTextField characterEncoding; + + public JavaOtherOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Other Build Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createOtherContents(); + } + + public void saveOptions() throws IOException { + String text = characterEncoding.getText(); + if (text != null ) { + javaBuildOptions.setCharacterEncoding(text); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + private void createOtherContents() { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText("Character encoding (will default to platform encoding)"); + panel.add(label,BorderLayout.WEST); + + characterEncoding = new JTextField(); + characterEncoding.setFont(new java.awt.Font("SansSerif", 0, 11)); + characterEncoding.setMinimumSize(new Dimension(100, 21)); + characterEncoding.setPreferredSize(new Dimension(150, 21)); + panel.add(characterEncoding,BorderLayout.EAST); + + String option = (String) javaBuildOptions.getJavaBuildOptionsMap().get( + JavaOptions.CHARACTER_ENCODING); + if (option != null) { + characterEncoding.setText(option); + } + + otherBox.add(panel,null); + otherPanel.add(otherBox); + } + + private void createBorders() { + otherEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + otherTitleBorder = new TitledBorder(otherEtchedBorder, "Other Options"); + otherCompoundBorder = BorderFactory.createCompoundBorder(otherTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + otherTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + otherPanel = new JPanel(); + otherPanel.setBorder(otherCompoundBorder); + parentPanel.add(otherPanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeCompilerTests.java b/ajde/testsrc/org/aspectj/ajde/AjdeCompilerTests.java new file mode 100644 index 000000000..0d9d6d68d --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/AjdeCompilerTests.java @@ -0,0 +1,76 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde; + +import org.aspectj.ajde.core.AjCompiler; + +/** + * Tests ajde's management of the AjCompiler instances. Expect + * there to be a different one for each .lst file and for ajde + * to only remember the compiler for the last .lst file. + */ +public class AjdeCompilerTests extends AjdeTestCase { + + protected void setUp() throws Exception { + super.setUp(); + initialiseProject("LstBuildConfigManagerTest"); + } + + // Expect to get a different compiler instance for each + // different config file + public void testGetSameAjCompilerForSameConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("bad-injar.lst"); + assertEquals("expected the same AjCompiler instance to be returned" + + " for the same configFile but found different ones", c1, c2); + } + + // Expect to get a different compiler instance for each + // different config file + public void testGetDifferentAjCompilerForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertNotSame("expected different AjCompiler instances to be returned" + + " for different configFiles but found the smae", c1, c2); + } + + // want to keep the same setting regardless of the configFile + // being built - therefore the same instance should be passed + // from one AjCompiler instance to the next + public void testSameCompilerConfigForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertEquals("expected the same compilerConfig instance to be associated" + + " with the different AjCompiler's however found different ones", + c1.getCompilerConfiguration(), c2.getCompilerConfiguration()); + } + + // want to have a different messageHandler instance for the different + // config files - or we can just reset?!?! Resetting would be easier + public void testSameMessageHandlerForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertEquals("expected the same messageHandler instance to be associated" + + " with the different AjCompiler's however found different ones", + c1.getMessageHandler(), c2.getMessageHandler()); + } + + // can have the same buildProgressMonitor for the different configFiles + // because it holds no state + public void testSameBuildProgressMonitorForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertEquals("expected the same buildProgressMonitor instance to be associated" + + " with the different AjCompiler's however found different ones", + c1.getBuildProgressMonitor(), c2.getBuildProgressMonitor()); + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java index b6d9cf02c..ea70c88c0 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java @@ -62,9 +62,16 @@ public class AjdeTestCase extends TestCase { */ public void initialiseProject(String projectName) { + + File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName); + File destination=new File(getWorkingDir(),projectName); + if (!destination.exists()) {destination.mkdir();} + copy(projectSrc,destination); + projectDir = destination.getAbsolutePath(); + // need to initialize via AjdeUIManager Ajde.getDefault().init( - new TestCompilerConfiguration(projectName), + new TestCompilerConfiguration(projectDir), new TestMessageHandler(), new TestBuildProgressMonitor(), new TestEditorAdapter(), @@ -73,18 +80,6 @@ public class AjdeTestCase extends TestCase { new JFrame(), new TestRuntimeProperties(), true); - - File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName); - File destination=new File(getWorkingDir(),projectName); - if (!destination.exists()) {destination.mkdir();} - copy(projectSrc,destination); - projectDir = destination.getAbsolutePath(); - -// compiler = new AjCompiler( -// projectDir, -// new TestCompilerConfiguration(projectDir), -// new TestBuildProgressMonitor(), -// new TestMessageHandler()); } /** diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java new file mode 100644 index 000000000..935dcc363 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java @@ -0,0 +1,96 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.aspectj.ajde.core.IBuildProgressMonitor; + +/** + * Test implementation of IBuildProgressMonitor which prints out + * progress to the console and enables users to cancel the build process + * after a specified string has been printed. + */ +public class TestBuildProgressMonitor implements IBuildProgressMonitor { + + private static boolean debugTests = false; + + public int numWovenClassMessages = 0; + public int numWovenAspectMessages = 0; + public int numCompiledMessages = 0; + + private String programmableString; + private int count; + private List messagesReceived = new ArrayList(); + private int currentVal; + private boolean isCancelRequested = false; + + public void finish(boolean wasFullBuild) { + System.out.println("build finished. Was full build: " + wasFullBuild); + } + + public boolean isCancelRequested() { + return isCancelRequested; + } + + public void setProgress(double percentDone) { + System.out.println("progress. Completed " + percentDone + " percent"); + } + + public void setProgressText(String text) { + System.out.println("progress text: " + text); + String newText = text+" [Percentage="+currentVal+"%]"; + messagesReceived.add(newText); + if (text.startsWith("woven aspect ")) numWovenAspectMessages++; + if (text.startsWith("woven class ")) numWovenClassMessages++; + if (text.startsWith("compiled:")) numCompiledMessages++; + if (programmableString != null + && text.indexOf(programmableString) != -1) { + count--; + if (count==0) { + if (debugTests) System.out.println("Just got message '"+newText+"' - asking build to cancel"); + isCancelRequested = true; + programmableString = null; + } + } + } + + public void begin() { + System.out.println("build started"); + currentVal = 0; + } + + // ------------- methods to help with testing ------------- + public void cancelOn(String string,int count) { + programmableString = string; + this.count = count; + } + + public boolean containsMessage(String prefix,String distinguishingMarks) { + for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + if (element.startsWith(prefix) && + element.indexOf(distinguishingMarks)!=-1) return true; + } + return false; + } + + public void dumpMessages() { + System.out.println("ProgressMonitorMessages"); + for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + System.out.println(element); + } + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java new file mode 100644 index 000000000..85e14fc5b --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java @@ -0,0 +1,163 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.io.File; +import java.io.FileFilter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.aspectj.ajde.core.ICompilerConfiguration; +import org.aspectj.ajde.core.IOutputLocationManager; +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.tools.ajc.AjcTests; +import org.aspectj.util.FileUtil; + +/** + * Test implementation of ICompilerConfiguration. Allows users to configure + * the settings via setter methods. By default returns null for all options + * except getClasspath(), getJavaOptionsMap() (by default returns that it's + * 1.3 compliant), getOutputLocationManager(), getSourcePathResources() (it + * recursively looks for them) and getProjectSourceFiles(). If no source + * files are specified by the user, then getProjectSourceFiles() returns + * an empty list. + */ +public class TestCompilerConfiguration implements ICompilerConfiguration { + + private String projectPath; + + private Set aspectpath; + private Set inpath; + private String outjar; + private Map javaOptions; + private String nonStandardOptions; + private List projectSourceFiles = new ArrayList(); + private Map sourcePathResources; + + private String srcDirName = "src"; + + private IOutputLocationManager outputLoc; + + public TestCompilerConfiguration(String projectPath) { + this.projectPath = projectPath; + } + + public Set getAspectPath() { + return aspectpath; + } + + public String getClasspath() { + return projectPath + + File.pathSeparator + + System.getProperty("sun.boot.class.path") + + File.pathSeparator + + AjcTests.aspectjrtClasspath(); + } + + public Set getInpath() { + return inpath; + } + + public Map getJavaOptionsMap() { + if (javaOptions == null) { + javaOptions = new Hashtable(); + javaOptions.put(JavaOptions.COMPLIANCE_LEVEL,JavaOptions.VERSION_13); + javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL,JavaOptions.VERSION_13); + } + return javaOptions; + } + + public String getNonStandardOptions() { + return nonStandardOptions; + } + + public String getOutJar() { + return outjar; + } + + public IOutputLocationManager getOutputLocationManager() { + if (outputLoc == null) { + outputLoc = new TestOutputLocationManager(projectPath); + } + return outputLoc; + } + + public List getProjectSourceFiles() { + return projectSourceFiles; + } + + public Map getSourcePathResources() { + if (sourcePathResources == null) { + sourcePathResources = new HashMap(); + + /* Allow the user to override the testProjectPath by using sourceRoots */ + File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; + + for (int j = 0; j < srcBase.length; j++) { + File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() { + public boolean accept(File pathname) { + String name = pathname.getName().toLowerCase(); + return !name.endsWith(".class") + && !name.endsWith(".java") + && !name.endsWith(".aj") + && !name.endsWith(".lst") + && !name.endsWith(".jar"); + } + }); + for (int i = 0; i < fromResources.length; i++) { + String normPath = FileUtil.normalizedPath(fromResources[i] ,srcBase[j]); + sourcePathResources.put(normPath, fromResources[i]); + + } + } + } + return sourcePathResources; + } + + + // -------------------- setter methods useful for testing --------------- + public void setAspectPath(Set aspectPath) { + this.aspectpath = aspectPath; + } + + public void setInpath(Set inpath) { + this.inpath = inpath; + } + + public void setOutjar(String outjar) { + this.outjar = outjar; + } + + public void setJavaOptions(Map javaOptions) { + this.javaOptions = javaOptions; + } + + public void setNonStandardOptions(String options) { + this.nonStandardOptions = options; + } + + public void setProjectSourceFiles(List projectSourceFiles) { + this.projectSourceFiles = projectSourceFiles; + } + + public void setSourcePathResources(Map sourcePathResources) { + this.sourcePathResources = sourcePathResources; + } + + public void setSourceDir(String srcDirName) { + this.srcDirName = srcDirName; + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestEditorAdapter.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestEditorAdapter.java new file mode 100644 index 000000000..6c94e7f33 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestEditorAdapter.java @@ -0,0 +1,48 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.io.IOException; +import java.util.List; + +import org.aspectj.ajde.EditorAdapter; +import org.aspectj.bridge.ISourceLocation; + +/** + * EditorAdapter with empty implementation + */ +public class TestEditorAdapter implements EditorAdapter { + + public String getCurrFile() { + return null; + } + + public void pasteToCaretPos(String text) { + } + + public void saveContents() throws IOException { + } + + public void showSourceLine(String filePath, int lineNumber, + boolean highlight) { + } + + public void showSourceLine(ISourceLocation sourceLocation, boolean highlight) { + } + + public void showSourceLine(int lineNumber, boolean highlight) { + } + + public void showSourcelineAnnotation(String filePath, int lineNumber, + List items) { + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java new file mode 100644 index 000000000..2bc23ec60 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java @@ -0,0 +1,23 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import org.aspectj.ajde.IdeUIAdapter; + +/** + * IdeUIAdapter with empty implementation + */ +public class TestIdeUIAdapter implements IdeUIAdapter { + + public void displayStatusInformation(String message) { + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestMessageHandler.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestMessageHandler.java new file mode 100644 index 000000000..8901b02f4 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestMessageHandler.java @@ -0,0 +1,112 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.aspectj.ajde.IUIBuildMessageHandler; +import org.aspectj.bridge.AbortException; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessage.Kind; + +/** + * Test implementation of IBuildMessageHandler. By default it + * ignores INFO and WEAVEINFO messages. Stores all messages it's + * not ignoring in an ArrayList and ERRORS and ABORTS also in + * a separate ArrayList enabling users to query whether anything + * went wrong with the build. + */ +public class TestMessageHandler implements IUIBuildMessageHandler { + + private List ignoring; + private List messages; + private List errors; + + public TestMessageHandler() { + ignoring = new ArrayList(); + messages = new ArrayList(); + errors = new ArrayList(); + ignore(IMessage.INFO); + ignore(IMessage.WEAVEINFO); + } + + public boolean handleMessage(IMessage message) throws AbortException { + IMessage.Kind kind = message.getKind(); + if (isIgnoring(kind)) { + return true; + } + TestMessage t = new TestMessage(message); + messages.add(t); + if (kind.equals(IMessage.ABORT) || message.getThrown() != null) { + System.err.println("> AjCompiler error: "+message.getMessage()); //$NON-NLS-1$ + message.getThrown().printStackTrace(); + errors.add(t); + } else if (kind.equals(IMessage.ERROR)) { + errors.add(t); + } + System.out.println("> "+message); //$NON-NLS-1$ + return true; + } + + public void dontIgnore(Kind kind) { + if (null != kind) { + ignoring.remove(kind); + } + } + + public boolean isIgnoring(Kind kind) { + return ((null != kind) && (ignoring.contains(kind))); + } + + public void ignore(Kind kind) { + if ((null != kind) && (!ignoring.contains(kind))) { + ignoring.add(kind); + } + } + + public List getMessages() { + return messages; + } + + public List getErrors() { + return errors; + } + + public static class TestMessage { + IMessage message; + + public TestMessage(IMessage m) { + message = m; + } + + public IMessage getContainedMessage() { + return message; + } + + public String toString() { + String loc = "<no location>"; + if (null != message.getSourceLocation()) { + loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine(); + } + return "TestMessage [" + message.getMessage() + + ", " + loc + + ", " + message.getKind() + + "]"; + } + } + + public void reset() { + messages.clear(); + errors.clear(); + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java new file mode 100644 index 000000000..eede163d8 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java @@ -0,0 +1,86 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.aspectj.ajde.core.IOutputLocationManager; + +/** + * Test implementation of IOutputLocationManager. By default returns the + * same location for both resources and classes, however, setter methods + * enable the user to specify different location for these. Note that the + * user is unable to specify different output location for different class + * files. + */ +public class TestOutputLocationManager implements IOutputLocationManager { + + private String testProjectOutputPath; + private File classOutputLoc; + private File resourceOutputLoc; + private List allOutputLocations; + + public TestOutputLocationManager(String testProjectPath) { + this.testProjectOutputPath = testProjectPath + File.separator + "bin"; + } + + public String getUniqueIdentifier() { + return testProjectOutputPath; + } + + public File getOutputLocationForClass(File compilationUnit) { + initLocations(); + return classOutputLoc; + } + + public File getOutputLocationForResource(File resource) { + initLocations(); + return resourceOutputLoc; + } + + // -------------- setter methods useful for testing ------------- + public void setOutputLocForClass(File f) { + classOutputLoc = f; + } + + public void setOutputLocForResource(File f) { + resourceOutputLoc = f; + } + + public List getAllOutputLocations() { + if(allOutputLocations == null) { + allOutputLocations = new ArrayList(); + initLocations(); + allOutputLocations.add(classOutputLoc); + if (!classOutputLoc.equals(resourceOutputLoc)) { + allOutputLocations.add(resourceOutputLoc); + } + } + return allOutputLocations; + } + + public File getDefaultOutputLocation() { + return classOutputLoc; + } + + private void initLocations() { + if (classOutputLoc == null) { + classOutputLoc = new File(testProjectOutputPath); + } + if (resourceOutputLoc == null) { + resourceOutputLoc = new File(testProjectOutputPath); + } + } + + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java new file mode 100644 index 000000000..a9e923e2a --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java @@ -0,0 +1,28 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import org.aspectj.ajde.IRuntimeProperties; + +/** + * IRuntimeProperties with empty implementation + */ +public class TestRuntimeProperties implements IRuntimeProperties { + + public String getClassToExecute() { + return null; + } + + public String getExecutionArgs() { + return null; + } + +} |