Author: rob.stryker(a)jboss.com
Date: 2008-10-25 06:41:15 -0400 (Sat, 25 Oct 2008)
New Revision: 11179
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/ant/
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/ant/antTemplate.xml
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.classpath
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.packages
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.project
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/output/
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/src/
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/src/Text
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/TranslationTest.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/AntLauncher.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
Log:
Test case of running archives from outside of eclipse (in this case via a launch config)
Modified: trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF 2008-10-24
18:37:48 UTC (rev 11178)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF 2008-10-25
10:41:15 UTC (rev 11179)
@@ -10,7 +10,11 @@
org.eclipse.core.resources,
org.jboss.tools.tests,
org.jboss.tools.common.test,
- org.eclipse.core.variables;bundle-version="3.2.100"
+ org.eclipse.core.variables;bundle-version="3.2.100",
+ org.eclipse.debug.core;bundle-version="3.4.0",
+ org.apache.ant;bundle-version="1.7.0",
+ org.eclipse.ant.ui;bundle-version="3.3.0",
+ org.eclipse.jdt.launching;bundle-version="3.4.0"
Eclipse-LazyStart: true
Bundle-ClassPath: archivestest.jar
Export-Package: org.jboss.ide.eclipse.archives.test,
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/ant/antTemplate.xml
===================================================================
--- trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/ant/antTemplate.xml
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/ant/antTemplate.xml 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1,24 @@
+<project>
+ <property name="eclipse.home" location="${UNIT_TEST_ECLIPSE_LOC}"
/>
+ <property name="archives.home"
location="${UNIT_TEST_ARCHIVES_HOME}"/>
+ <property name="example_variable" value="test" />
+
+ <path id="generate-archives-classpath">
+ <fileset dir="${eclipse.home}">
+ <include name="plugins/org.eclipse.equinox.common_*.jar" />
+ </fileset>
+ <fileset dir="${archives.home}">
+ <include
+ name="plugins/org.jboss.ide.eclipse.archives.core**/archivescore.jar"
/>
+ <include name="plugins/org.jboss.ide.eclipse.archives.core**/lib/*.jar"
/>
+ </fileset>
+ </path>
+
+ <taskdef name="generate-archives"
classpathref="generate-archives-classpath"
+ classname="org.jboss.ide.eclipse.archives.core.ant.GenerateArchivesTask"
/>
+
+ <target name="run-packaging">
+ <property name="${UNIT_TEST_PROJECT_NAME}.dir"
value="${UNIT_TEST_PROJECT_DIR}" />
+ <generate-archives projectPath="${${UNIT_TEST_PROJECT_NAME}.dir}" />
+ </target>
+</project>
\ No newline at end of file
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.classpath
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.classpath
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.classpath 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.packages
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.packages
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.packages 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<packages version="1.2">
+ <package name="SimpleAntTest.jar" type="jar"
todir="output" exploded="false" inWorkspace="false">
+ <fileset dir="" includes="**" excludes="**/*jar"
inWorkspace="true" flatten="false">
+ <properties></properties>
+ </fileset>
+ <properties>
+ <property
name="org.jboss.ide.eclipse.as.core.packages.ModuleIDPropertyKey"
value="1224926072579"></property>
+ </properties>
+ </package>
+ <properties></properties>
+</packages>
\ No newline at end of file
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.project
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.project
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/.project 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>SimpleAntTest</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.jboss.ide.eclipse.archives.core.archivesBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.jboss.ide.eclipse.archives.core.archivesNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/src/Text
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/src/Text
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/inputs/projects/SimpleAntTest/src/Text 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1 @@
+this is a text file
\ No newline at end of file
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2008-10-24
18:37:48 UTC (rev 11178)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2008-10-25
10:41:15 UTC (rev 11179)
@@ -4,6 +4,7 @@
import junit.framework.TestSuite;
import org.jboss.ide.eclipse.archives.test.core.ArchivesCoreTest;
+import org.jboss.ide.eclipse.archives.test.core.ant.SimpleAntTest;
import org.jboss.ide.eclipse.archives.test.model.ModelCreationTest;
import org.jboss.ide.eclipse.archives.test.model.ModelTruezipBridgeTest;
import org.jboss.ide.eclipse.archives.test.model.ModelUtilTest;
@@ -27,7 +28,8 @@
suite.addTestSuite(ModelUtilTest.class);
suite.addTestSuite(ModelCreationTest.class);
suite.addTestSuite(ModelTruezipBridgeTest.class);
-
+ suite.addTestSuite(SimpleAntTest.class);
+
// jiras
suite.addTestSuite(JBIDE1406Test.class);
suite.addTestSuite(JBIDE2099Test.class);
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/TranslationTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/TranslationTest.java
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/TranslationTest.java 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1,40 @@
+package org.jboss.ide.eclipse.archives.test.core;
+
+import junit.framework.TestCase;
+
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.ArchivesCoreMessages;
+import org.jboss.ide.eclipse.archives.core.WorkspaceArchivesCore;
+import org.jboss.ide.eclipse.archives.core.ant.AntArchivesCore;
+
+public class TranslationTest extends TestCase {
+ private static WorkspaceArchivesCore workspaceCore;
+ private static AntArchivesCore antCore;
+
+ public void testArchivesCore() {
+ ArchivesCore core = ArchivesCore.getInstance();
+ assertEquals(ArchivesCore.WORKSPACE, core.getRunType());
+ assertEquals(WorkspaceArchivesCore.class, core.getClass());
+ workspaceCore = (WorkspaceArchivesCore)core;
+
+ assertNotNull(ArchivesCoreMessages.RefreshProjectFailed);
+ String workspaceBind = ArchivesCore.bind(ArchivesCoreMessages.RefreshProjectFailed,
"Test");
+ assertNotNull(workspaceBind);
+
+ AntArchivesCore core2 = new AntArchivesCore();
+ ArchivesCore.setInstance(core2);
+ assertEquals(ArchivesCore.STANDALONE, ArchivesCore.getInstance().getRunType());
+ antCore = core2;
+
+ String antBind = ArchivesCore.bind(ArchivesCoreMessages.RefreshProjectFailed,
"Test");
+ assertNotNull(antBind);
+ assertEquals(workspaceBind, antBind);
+ ArchivesCore.setInstance(core);
+
+ }
+
+ public void testAntStartup() {
+ // TODO Test to make sure a launch config starting with ant can also bind such strings
+ // SEE JMX CODE for example
+ }
+}
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/AntLauncher.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/AntLauncher.java
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/AntLauncher.java 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1,164 @@
+package org.jboss.ide.eclipse.archives.test.core.ant;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import junit.framework.Assert;
+
+import org.eclipse.ant.internal.ui.launchConfigurations.AntLaunchShortcut;
+import
org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.IStreamListener;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStreamMonitor;
+import org.jboss.ide.eclipse.archives.test.ArchivesTest;
+import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
+import org.osgi.framework.Bundle;
+
+public class AntLauncher {
+ protected String projectName;
+ protected String fileName;
+ protected String target;
+ protected IFile antFile;
+ protected IProject project;
+ protected ILaunch launch;
+ protected ILaunchConfiguration configuration;
+ protected IProcessListener listener;
+
+ public interface IProcessListener {
+ public void out(String text);
+ public void err(String text);
+ }
+
+ public AntLauncher(String projectName, String fileName, String target) {
+ this.projectName = projectName;
+ this.fileName = fileName;
+ this.target = target;
+ }
+
+ protected void createProjectData(IPath template, HashMap<String, String>
replacements) throws CoreException {
+ try {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ project = root.getProject(projectName);
+ if( project.exists() )
+ fail("project already exists");
+
+ project.create(new NullProgressMonitor());
+ if( !project.exists() )
+ fail("project not created");
+
+ project.open(new NullProgressMonitor());
+ if( !project.isOpen() )
+ fail("project is not open");
+
+ antFile = project.getFile(fileName);
+ if( antFile.exists())
+ fail("build file already exists");
+
+ String s = getBuildXmlContents(template, replacements);
+ InputStream is = new ByteArrayInputStream(s.getBytes("UTF-8"));
+ antFile.create(is, true, new NullProgressMonitor());
+ } catch(CoreException ce ) {
+ ce.printStackTrace();
+ fail(ce.getMessage());
+ } catch( UnsupportedEncodingException uee) {
+ uee.printStackTrace();
+ fail(uee.getMessage());
+ } catch( IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ }
+ }
+
+ public void deleteProject() throws CoreException {
+ project.delete(true, new NullProgressMonitor());
+ }
+
+ protected void launch() throws CoreException {
+ try {
+ ILaunchConfiguration config = getLaunchConfiguration(antFile.getFullPath(), project,
"run", target);
+ launch = config.launch("run", new NullProgressMonitor());
+ IProcess[] processes = launch.getProcesses();
+ Assert.assertNotNull(processes);
+ Assert.assertTrue(processes.length == 1);
+
+ processes[0].getStreamsProxy().getOutputStreamMonitor().addListener(
+ new IStreamListener() {
+ public void streamAppended(String text,
+ IStreamMonitor monitor) {
+ if( listener != null )
+ listener.out(text);
+ }
+ });
+ processes[0].getStreamsProxy().getErrorStreamMonitor().addListener(
+ new IStreamListener() {
+ public void streamAppended(String text,
+ IStreamMonitor monitor) {
+ if( listener != null )
+ listener.err(text);
+ }
+ });
+ } catch( CoreException ce ) {
+ ce.printStackTrace();
+ fail(ce.getMessage());
+ }
+ }
+
+ private String getBuildXmlContents(IPath template, HashMap<String, String> map)
throws IOException {
+ Bundle bundle = ArchivesTest.getDefault().getBundle();
+ URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
+ IPath bundlePath = new Path(bundleURL.getFile());
+ IPath templateFile = bundlePath.append(template);
+ String result = FileIOUtil.getFileContents(templateFile.toFile());
+ String key, val;
+ if( result != null ) {
+ Iterator<String> i = map.keySet().iterator();
+ while(i.hasNext()) {
+ key = i.next();
+ val = map.get(key);
+ while(result.indexOf(key) != -1)
+ result = result.replace(key, val);
+ }
+ }
+
+ return result;
+ }
+
+ private ILaunchConfiguration getLaunchConfiguration(IPath filePath, IProject project,
String mode, String targetAttribute) throws CoreException {
+ ILaunchConfiguration configuration = null;
+ configuration = AntLaunchShortcut.createDefaultLaunchConfiguration(filePath, (project
!= null && project.exists() ? project : null));
+ try {
+ if (targetAttribute != null && !
targetAttribute.equals(configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS,
""))) { //$NON-NLS-1$
+ ILaunchConfigurationWorkingCopy copy = configuration.getWorkingCopy();
+ copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS,
targetAttribute);
+ copy.doSave();
+ }
+ } catch (CoreException exception) {
+ exception.printStackTrace();
+ fail(exception.getMessage());
+ }
+ return configuration;
+ }
+
+ private void fail(String msg) throws CoreException {
+ Assert.fail(msg);
+ }
+}
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/core/ant/SimpleAntTest.java 2008-10-25
10:41:15 UTC (rev 11179)
@@ -0,0 +1,113 @@
+package org.jboss.ide.eclipse.archives.test.core.ant;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.test.ArchivesTest;
+import org.jboss.ide.eclipse.archives.test.core.ant.AntLauncher.IProcessListener;
+import org.osgi.framework.Bundle;
+
+public class SimpleAntTest extends TestCase implements IProcessListener {
+ protected static final String ECLIPSE_LOC = "${UNIT_TEST_ECLIPSE_LOC}";
+ protected static final String ARCHIVES_HOME = "${UNIT_TEST_ARCHIVES_HOME}";
+ protected static final String PROJECT_NAME = "${UNIT_TEST_PROJECT_NAME}";
+ protected static final String PROJECT_DIR = "${UNIT_TEST_PROJECT_DIR}";
+
+ // if running from runtime workbench, set this to true. otherwise its running in a full
build
+ private final static boolean RUNTIME_WORKBENCH = false;
+
+ // if running via runtime workbench, the archives core plugin should be exported
somewhere
+ // so that its jars can be picked up by the ant launch
+ private final static String PLUGIN_LOCATION="/home/rob/tmp/plugins";
+ private AntLauncher launcher;
+ private IPath outputFolder;
+ private boolean done = false;
+ private boolean success = false;
+ private String errorString = "";
+ public void setUp() {
+ try {
+ launcher = new AntLauncher("AntTest", "build.xml",
"run-packaging");
+ launcher.listener = this;
+ IPath templatePath = new
Path("inputs").append("ant").append("antTemplate.xml");
+ HashMap<String, String> map = new HashMap<String, String>();
+
+ Bundle bundle = ArchivesTest.getDefault().getBundle();
+ URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
+ IPath bundlePath = new Path(bundleURL.getFile());
+ IPath projectLoc = bundlePath.append(new
Path("inputs").append("projects").append("SimpleAntTest"));
+ outputFolder = projectLoc.append("output");
+
+ String eclipseHome = new File(new
URL(System.getProperty("eclipse.home.location")).toURI()).getAbsolutePath();
+
+ map.put(ECLIPSE_LOC, eclipseHome);
+ map.put(PROJECT_NAME, "SimpleAntTest");
+ map.put(ARCHIVES_HOME, RUNTIME_WORKBENCH ? PLUGIN_LOCATION : eclipseHome);
+ map.put(PROJECT_DIR, projectLoc.toOSString());
+ launcher.createProjectData(templatePath, map);
+ } catch( CoreException ce) {
+ fail(ce.getMessage());
+ } catch( IOException ioe) {
+ fail(ioe.getMessage());
+ } catch( URISyntaxException urise) {
+ fail(urise.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ try {
+ launcher.deleteProject();
+ File[] children = outputFolder.toFile().listFiles();
+ if( children.length > 0 ) {
+ for( int i = 0; i < children.length; i++ )
+ children[i].delete();
+ }
+ } catch( CoreException ce ) {
+ }
+ }
+
+ public void testOne() {
+ try {
+ assertTrue(outputFolder.toFile().list().length == 0);
+ launcher.launch();
+ } catch( CoreException ce) {
+ fail(ce.getMessage());
+ }
+
+ int maxWait = 60*1000; // max wait 60s
+ int waited = 0;
+ while( !done && waited < maxWait ) {
+ try {
+ Thread.currentThread().sleep(500);
+ } catch( InterruptedException ie) {}
+ waited += 500;
+ }
+
+ if( !done || !success )
+ fail("The ant task did not successfully complete. " + errorString);
+
+ assertTrue(outputFolder.toFile().list().length == 1);
+ File out = outputFolder.toFile().listFiles()[0];
+ assertTrue(out.exists());
+
+ }
+ public void out(String text) {
+ if( "BUILD SUCCESSFUL\n".equals(text))
+ done = success = true;
+ }
+ public void err(String text) {
+ if( "BUILD FAILED\n".equals(text)) {
+ success = false;
+ done = true;
+ }
+ errorString += text + "\n";
+ }
+}