diff --git a/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/DefaultConfiguration.java b/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/DefaultConfiguration.java index e4aa1cd5..490ca4e1 100644 --- a/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/DefaultConfiguration.java +++ b/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/DefaultConfiguration.java @@ -62,6 +62,10 @@ public String getTestFilePattern() { public String getPHPUnitConfigFile() { return ""; //$NON-NLS-1$ } + + public String getPHPUnitPharFile() { + return ""; //$NON-NLS-1" + } /** * @since 2.5.0 diff --git a/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/preference/MakeGoodProperties.java b/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/preference/MakeGoodProperties.java index 1e638715..916848e6 100644 --- a/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/preference/MakeGoodProperties.java +++ b/com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/preference/MakeGoodProperties.java @@ -37,6 +37,7 @@ public class MakeGoodProperties { private static String TESTING_FRAMEWORK_KEY = "testing_framework"; //$NON-NLS-1$ private static String TEST_FOLDERS = "test_folders"; //$NON-NLS-1$ private static String PHPUNIT_CONFIG_FILE = "phpunit_config_file"; //$NON-NLS-1$ + private static String PHPUNIT_PHAR_FILE = "phpunit_phar_file"; //$NON-NLS-1$ /** * @since 2.0.0 @@ -130,6 +131,14 @@ public String getPHPUnitConfigFile() { public void setPHPUnitConfigFile(String phpunitConfigFile) { preferences.put(PHPUNIT_CONFIG_FILE, phpunitConfigFile); } + + public String getPHPUnitPharFile() { + return preferences.get(PHPUNIT_PHAR_FILE, defaultConfiguration.getPHPUnitConfigFile()); + } + + public void setPHPUnitPharFile(String phpunitPharFile) { + preferences.put(PHPUNIT_PHAR_FILE, phpunitPharFile); + } /** * @since 2.0.0 diff --git a/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/CommandLineBuilder.java b/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/CommandLineBuilder.java index d13e16ca..225a0a90 100644 --- a/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/CommandLineBuilder.java +++ b/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/CommandLineBuilder.java @@ -38,35 +38,51 @@ public class CommandLineBuilder { public static boolean stopOnFailure = false; private String junitXMLFile; + // Flag indicating whether these command arguments should be compatible with a phpunit phar launch + private boolean isPharLaunch; - public CommandLineBuilder(String junitXMLFile) { + public CommandLineBuilder(String junitXMLFile, boolean isPharLaunch) { this.junitXMLFile = junitXMLFile; + this.isPharLaunch = isPharLaunch; } public String build() throws CoreException, MethodNotFoundException, ResourceNotFoundException { MakeGoodProperties property = new MakeGoodProperties(TestLifecycle.getInstance().getTestTargets().getFirstResource()); StringBuilder buffer = new StringBuilder(); - buffer.append(" --no-ansi"); //$NON-NLS-1$ - buffer.append(" " + property.getTestingFramework().name().toLowerCase()); //$NON-NLS-1$ - - String preloadScript = property.getPreloadScript(); - if (!preloadScript.equals("")) { //$NON-NLS-1$ - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IResource preloadResource = root.findMember(preloadScript); - if (preloadResource == null) { - throw new ResourceNotFoundException("The resource [ " + preloadScript + " ] is not found."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - buffer.append(" -p \"" + preloadResource.getLocation().toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - } - - buffer.append(" --log-junit=\"" + junitXMLFile + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - buffer.append(" --log-junit-realtime"); //$NON-NLS-1$ - - if (stopOnFailure) { - buffer.append(" -s"); //$NON-NLS-1$ + if(!isPharLaunch) { + buffer.append(" --no-ansi"); //$NON-NLS-1$ + buffer.append(" " + property.getTestingFramework().name().toLowerCase()); //$NON-NLS-1$ + + + String preloadScript = property.getPreloadScript(); + if (!preloadScript.equals("")) { //$NON-NLS-1$ + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource preloadResource = root.findMember(preloadScript); + if (preloadResource == null) { + throw new ResourceNotFoundException("The resource [ " + preloadScript + " ] is not found."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + if(isPharLaunch) { + buffer.append(" --bootstrap \"" + preloadResource.getLocation().toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + buffer.append(" -p \"" + preloadResource.getLocation().toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } + } } + + buffer.append(" --log-junit=\"" + junitXMLFile + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + if(isPharLaunch) { + if (stopOnFailure) { + buffer.append(" --stop-on-failure"); //$NON-NLS-1$ + } + } else { + buffer.append(" --log-junit-realtime"); //$NON-NLS-1$ + + if (stopOnFailure) { + buffer.append(" -s"); //$NON-NLS-1$ + } + } if (property.getTestingFramework() == TestingFramework.PHPUnit) { String phpunitConfigFile = property.getPHPUnitConfigFile(); @@ -76,7 +92,11 @@ public String build() throws CoreException, MethodNotFoundException, ResourceNot throw new ResourceNotFoundException("The resource [ " + phpunitConfigFile + " ] is not found."); //$NON-NLS-1$ //$NON-NLS-2$ } - buffer.append(" --phpunit-config=\"" + resource.getLocation().toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + if(isPharLaunch) { + buffer.append(" -c \""+ resource.getLocation().toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + buffer.append(" --phpunit-config=\"" + resource.getLocation().toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } } } @@ -116,26 +136,28 @@ public String build() throws CoreException, MethodNotFoundException, ResourceNot } } - if (testClasses.size() > 0) { - for (String testClass: testClasses) { - buffer.append(" --test-class=\"" + testClass.toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - if (testMethods.size() > 0) { - for (String testMethod: testMethods) { - buffer.append(" --test-method=\"" + testMethod.toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - buffer.append(" -R"); //$NON-NLS-1$ - buffer.append( - " --test-file-pattern=\"" + //$NON-NLS-1$ - (property.getTestFilePattern().equals("") ? property.getTestingFramework().getTestFilePattern() : property.getTestFilePattern()) + //$NON-NLS-1$ - "\"" //$NON-NLS-1$ - ); - for (String testFile: testFiles) { - buffer.append(" \"" + testFile + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + if(!isPharLaunch) { + if (testClasses.size() > 0) { + for (String testClass: testClasses) { + buffer.append(" --test-class=\"" + testClass.toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + if (testMethods.size() > 0) { + for (String testMethod: testMethods) { + buffer.append(" --test-method=\"" + testMethod.toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + buffer.append(" -R"); //$NON-NLS-1$ + buffer.append( + " --test-file-pattern=\"" + //$NON-NLS-1$ + (property.getTestFilePattern().equals("") ? property.getTestingFramework().getTestFilePattern() : property.getTestFilePattern()) + //$NON-NLS-1$ + "\"" //$NON-NLS-1$ + ); + for (String testFile: testFiles) { + buffer.append(" \"" + testFile + "\""); //$NON-NLS-1$ //$NON-NLS-2$ + } } return buffer.toString(); diff --git a/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/MakeGoodLaunchConfigurationDelegate.java b/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/MakeGoodLaunchConfigurationDelegate.java index fa02a71f..2bce7c87 100644 --- a/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/MakeGoodLaunchConfigurationDelegate.java +++ b/com.piece_framework.makegood.launch/src/com/piece_framework/makegood/launch/MakeGoodLaunchConfigurationDelegate.java @@ -16,6 +16,8 @@ import java.util.HashSet; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -41,6 +43,7 @@ import org.eclipse.php.internal.debug.core.preferences.PHPProjectPreferences; import org.eclipse.php.internal.debug.core.preferences.PHPexeItem; +import com.piece_framework.makegood.core.preference.MakeGoodProperties; import com.piece_framework.makegood.stagehandtestrunner.StagehandTestRunner; @SuppressWarnings("restriction") @@ -259,7 +262,7 @@ IPHPDebugConstants.ATTR_FILE_FULL_PATH, getCommandPath() workingCopy.setAttribute(MAKEGOOD_JUNIT_XML_FILE, junitXMLFile); workingCopy.setAttribute( IDebugParametersKeys.EXE_CONFIG_PROGRAM_ARGUMENTS, - new CommandLineBuilder(junitXMLFile).build() + getCommandArguments(junitXMLFile) ); IProject project = TestLifecycle.getInstance().getTestTargets().getProject(); @@ -270,9 +273,32 @@ IPHPDebugConstants.ATTR_FILE_FULL_PATH, getCommandPath() return workingCopy; } + + public static String getCommandArguments(String junitXMLFile) throws CoreException, MethodNotFoundException, ResourceNotFoundException { + MakeGoodProperties property = new MakeGoodProperties(TestLifecycle.getInstance().getTestTargets().getFirstResource()); + String pharFile = property.getPHPUnitPharFile().trim(); + if("".equals(pharFile)) { + String args = new CommandLineBuilder(junitXMLFile, false).build(); + return args; + } else { + String args = new CommandLineBuilder(junitXMLFile, true).build(); + return args; + } + } + + public static String getCommandPath() throws CoreException, ResourceNotFoundException { + MakeGoodProperties property = new MakeGoodProperties(TestLifecycle.getInstance().getTestTargets().getFirstResource()); + String pharFile = property.getPHPUnitPharFile().trim(); + if("".equals(pharFile)) + return StagehandTestRunner.getCommandPath(); + else { + IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(pharFile); + if (resource == null) { + throw new ResourceNotFoundException("The resource [ " + pharFile + " ] is not found."); //$NON-NLS-1$ //$NON-NLS-2$ + } - public static String getCommandPath() throws CoreException { - return StagehandTestRunner.getCommandPath(); + return resource.getLocation().toString(); //$NON-NLS-1$ //$NON-NLS-2$ + } } public static String getJUnitXMLFile(ILaunch launch) throws CoreException { diff --git a/com.piece_framework.makegood.ui/messages.properties b/com.piece_framework.makegood.ui/messages.properties index d7977cea..26310875 100644 --- a/com.piece_framework.makegood.ui/messages.properties +++ b/com.piece_framework.makegood.ui/messages.properties @@ -6,8 +6,12 @@ MakeGoodPropertyPage_preloadScriptLabel=Preload Script: MakeGoodPropertyPage_preloadScriptBrowseLabel=&Browse... MakeGoodPropertyPage_phpunitConfigFileDialogTitle=PHPUnit XML Configuration File MakeGoodPropertyPage_phpunitConfigFileDialogMessage=Select a PHPUnit XML configuration file: +MakeGoodPropertyPage_phpunitPharFileDialogTitle=PHPUnit Phar File +MakeGoodPropertyPage_phpunitPharFileDialogMessage=Select a PHPUnit Phar file: MakeGoodPropertyPage_phpunitConfigFileLabel=XML Configuration File: MakeGoodPropertyPage_phpunitConfigFileBrowseLabel=Browse... +MakeGoodPropertyPage_phpunitPharFileLabel=PHPUnit Phar File: +MakeGoodPropertyPage_phpunitPharFileBrowseLabel=Browse... MakeGoodPropertyPage_testFolderAddLabel=&Add... MakeGoodPropertyPage_testFolderRemoveLabel=&Remove MakeGoodPropertyPage_testFolderDialogMessage=Select the test folder: diff --git a/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/Messages.java b/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/Messages.java index 963d55eb..228669ab 100644 --- a/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/Messages.java +++ b/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/Messages.java @@ -28,8 +28,12 @@ public class Messages extends NLS { public static String MakeGoodPropertyPage_preloadScriptLabel; public static String MakeGoodPropertyPage_phpunitConfigFileDialogTitle; public static String MakeGoodPropertyPage_phpunitConfigFileDialogMessage; + public static String MakeGoodPropertyPage_phpunitPharFileDialogTitle; + public static String MakeGoodPropertyPage_phpunitPharFileDialogMessage; public static String MakeGoodPropertyPage_phpunitConfigFileLabel; public static String MakeGoodPropertyPage_phpunitConfigFileBrowseLabel; + public static String MakeGoodPropertyPage_phpunitPharFileLabel; + public static String MakeGoodPropertyPage_phpunitPharFileBrowseLabel; public static String MakeGoodPropertyPage_testFolderRemoveLabel; /** diff --git a/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/preferences/MakeGoodPropertyPage.java b/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/preferences/MakeGoodPropertyPage.java index 771f2eef..e5e4c204 100644 --- a/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/preferences/MakeGoodPropertyPage.java +++ b/com.piece_framework.makegood.ui/src/com/piece_framework/makegood/ui/preferences/MakeGoodPropertyPage.java @@ -63,6 +63,7 @@ public class MakeGoodPropertyPage extends PropertyPage { private static final int SELECTION_ALLOW_FOLDER = 2; private Text preloadScriptText; private Text phpunitConfigFileText; + private Text phpunitPharFileText; private Button phpunitButton; private TreeViewer testFolderTreeViewer; @@ -185,6 +186,23 @@ public void selectionChanged(SelectionChangedEvent event) { new FileViewerFilter() ) ); + + Label phpunitPharFileLabel = new Label(phpunitConfigFile, SWT.NONE); + phpunitPharFileLabel.setText(Messages.MakeGoodPropertyPage_phpunitPharFileLabel); + phpunitPharFileText = new Text(phpunitConfigFile, SWT.SINGLE | SWT.BORDER); + phpunitPharFileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + Button phpunitPharFileBrowseButton = new Button(phpunitConfigFile, SWT.NONE); + phpunitPharFileBrowseButton.setText(Messages.MakeGoodPropertyPage_phpunitPharFileBrowseLabel); + phpunitPharFileBrowseButton.addSelectionListener( + new FileSelectionListener( + phpunitPharFileText, + Messages.MakeGoodPropertyPage_phpunitPharFileDialogTitle, + Messages.MakeGoodPropertyPage_phpunitPharFileDialogMessage, + SELECTION_ALLOW_FILE, + new FileViewerFilter() + ) + ); + frameworkTabItems.add(phpunitTabItem); loadProperties(createMakeGoodProperty()); @@ -211,6 +229,7 @@ public boolean performOk() { property.setPreloadScript(preloadScriptText.getText()); property.setTestFilePattern(testFilePatternText.getText()); property.setPHPUnitConfigFile(phpunitConfigFileText.getText()); + property.setPHPUnitPharFile(phpunitPharFileText.getText()); property.flush(); return true; @@ -274,6 +293,7 @@ private void loadProperties(MakeGoodProperties property) { preloadScriptText.setText(property.getPreloadScript()); testFilePatternText.setText(property.getTestFilePattern()); phpunitConfigFileText.setText(property.getPHPUnitConfigFile()); + phpunitPharFileText.setText(property.getPHPUnitPharFile()); } /** @@ -285,6 +305,7 @@ private void loadProperties(DefaultConfiguration defaultConfiguration) { preloadScriptText.setText(defaultConfiguration.getPreloadScript()); testFilePatternText.setText(defaultConfiguration.getTestFilePattern()); phpunitConfigFileText.setText(defaultConfiguration.getPHPUnitConfigFile()); + phpunitPharFileText.setText(defaultConfiguration.getPHPUnitPharFile()); } /**