Author: lzoubek(a)redhat.com
Date: 2011-08-01 08:20:17 -0400 (Mon, 01 Aug 2011)
New Revision: 33409
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/SWTBotTest-default.properties
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JBPMBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JavaBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/SeamBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddESB.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJBPM.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJava.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java
Log:
swtbotext: support for downloading server runtimes
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/SWTBotTest-default.properties
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/SWTBotTest-default.properties 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/resources/SWTBotTest-default.properties 2011-08-01
12:20:17 UTC (rev 33409)
@@ -6,6 +6,9 @@
# note : when server is type of SOA, version is version of SOA (not the bundled EAP)
SERVER=EAP,5.0,1.6,/data/jboss/jboss-eap-5.0/jboss-as
#SERVER=EAP,5.0,1.6,/data/jboss/jboss-eap-5.0/jboss-as,remote.example.com,/opt/jboss-eap-5.0/jboss-as
+# note that zip will be unzipped into <server home> minus 1-2 folders. Change
<server home> to reflect
+# content of downloaded zip.
+SERVER_URL=http://localhost/eap5.zip
# remote system= <user>,<host>,<private key>
#RS=lzoubek,remote.example.com,/home/lzoubek/.ssh/id_rsa
#<seam version>,<seam runtime home>
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/RequirementAwareSuite.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -176,6 +176,7 @@
} catch (Exception e) {
log.error("Fulfilling failed", e);
}
+ log.info("Done");
return super.withBeforeClasses(statement);
}
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ESBBean.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -1,27 +1,10 @@
package org.jboss.tools.ui.bot.ext.config;
-public class ESBBean {
- public String version;
- public String esbHome;
-
- public static ESBBean fromString(String propValue) throws Exception{
- try {
- if (propValue==null) {
- return null;
- }
- String[] esbParams = propValue.split(",");
- ESBBean bean = new ESBBean();
- bean.esbHome=esbParams[1];
- bean.version=esbParams[0];
- return bean;
- }
- catch (Exception ex) {
- throw new Exception("Cannot parse ESB property line",ex);
- }
+public class ESBBean extends RuntimeBean{
+ public ESBBean() {
+ this.key = TestConfigurator.Keys.ESB;
}
- @Override
- public String toString() {
- return String.format("ESB runtime version=%s, home=%s",
- this.version, this.esbHome);
+ public static ESBBean fromString(String propValue) throws Exception {
+ return (ESBBean)fromString(propValue, new ESBBean());
}
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JBPMBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JBPMBean.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JBPMBean.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -1,27 +1,11 @@
package org.jboss.tools.ui.bot.ext.config;
-public class JBPMBean {
- public String version;
- public String jbpmHome;
-
- public static JBPMBean fromString(String propValue) throws Exception{
- try {
- if (propValue==null) {
- return null;
- }
- String[] jbpmParams = propValue.split(",");
- JBPMBean bean = new JBPMBean();
- bean.jbpmHome=jbpmParams[1];
- bean.version=jbpmParams[0];
- return bean;
- }
- catch (Exception ex) {
- throw new Exception("Cannot parse jBPM property line",ex);
- }
+public class JBPMBean extends RuntimeBean {
+
+ public JBPMBean() {
+ this.key = TestConfigurator.Keys.JBPM;
}
- @Override
- public String toString() {
- return String.format("jBPM runtime version=%s, home=%s",
- this.version, this.jbpmHome);
+ public static JBPMBean fromString(String propValue) throws Exception {
+ return (JBPMBean)fromString(propValue, new JBPMBean());
}
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JavaBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JavaBean.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/JavaBean.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -1,27 +1,11 @@
package org.jboss.tools.ui.bot.ext.config;
-public class JavaBean {
- public String version;
- public String javaHome;
+public class JavaBean extends RuntimeBean {
- public static JavaBean fromString(String propValue) throws Exception{
- try {
- if (propValue==null) {
- return null;
- }
- String[] esbParams = propValue.split(",");
- JavaBean bean = new JavaBean();
- bean.javaHome=esbParams[1];
- bean.version=esbParams[0];
- return bean;
- }
- catch (Exception ex) {
- throw new Exception("Cannot parse JAVA property line",ex);
- }
+ public JavaBean() {
+ this.key = TestConfigurator.Keys.JAVA;
}
- @Override
- public String toString() {
- return String.format("JAVA runtime version=%s, home=%s",
- this.version, this.javaHome);
+ public static JavaBean fromString(String propValue) throws Exception {
+ return (JavaBean)fromString(propValue, new JavaBean());
}
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/SeamBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/SeamBean.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/SeamBean.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -1,28 +1,11 @@
package org.jboss.tools.ui.bot.ext.config;
-public class SeamBean {
-
- public String version;
- public String seamHome;
-
+public class SeamBean extends RuntimeBean{
+
+ public SeamBean() {
+ this.key = TestConfigurator.Keys.SEAM;
+ }
public static SeamBean fromString(String propValue) throws Exception {
- try {
- if (propValue == null) {
- return null;
- }
- String[] seamParams = propValue.split(",");
- SeamBean bean = new SeamBean();
- bean.seamHome = seamParams[1];
- bean.version = seamParams[0];
- return bean;
- } catch (Exception ex) {
- throw new Exception("Cannot parse SEAM property line", ex);
- }
+ return (SeamBean)fromString(propValue, new SeamBean());
}
-
- @Override
- public String toString() {
- return String.format("Seam runtime version=%s, home=%s",
- this.version, this.seamHome);
- }
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/ServerBean.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -1,16 +1,16 @@
package org.jboss.tools.ui.bot.ext.config;
-import java.util.Arrays;
+import java.io.File;
+import org.jboss.tools.ui.bot.ext.helper.FileHelper;
+
/**
*
* @author lzoubek
*
*/
-public class ServerBean {
+public class ServerBean extends RuntimeBean {
- public String version;
- public String runtimeHome;
public String withJavaVersion;
public String type;
/**
@@ -21,6 +21,24 @@
* home of app server located in remote system
*/
public String remoteHome;
+ public static ServerBean fromString(String propValue, String url) throws Exception {
+ ServerBean bean = fromString(propValue);
+ if (bean!=null && url!=null) {
+ String runtimeFile = downloadRuntime(url);
+ if (runtimeFile!=null) {
+ // where to unzip it?
+ String runtimeOutput;
+ if (TestConfigurator.Values.SERVER_TYPE_JBOSSAS.equals(bean.type)) {
+ runtimeOutput=new File(bean.runtimeHome).getParent();
+ }
+ else {
+ runtimeOutput=new File(bean.runtimeHome).getParentFile().getParent();
+ }
+ FileHelper.unzipArchive(new File(runtimeFile), new File(runtimeOutput));
+ }
+ }
+ return bean;
+ }
/**
* creates bean instance from property string
* @param propValue property value
@@ -28,12 +46,12 @@
* @throws Exception
*/
public static ServerBean fromString(String propValue) throws Exception {
+ ServerBean bean = new ServerBean();
try {
if (propValue==null) {
return null;
}
- String[] serverParams = propValue.split(",");
- ServerBean bean = new ServerBean();
+ String[] serverParams = propValue.split(",");
bean.withJavaVersion = serverParams[2];
bean.runtimeHome=serverParams[3];
bean.version=serverParams[1];
@@ -46,12 +64,12 @@
return bean;
}
catch (Exception ex) {
- throw new Exception("Cannot parse SERVER property line",ex);
+ throw new Exception("Cannot parse "+bean.key+" property
line",ex);
}
}
@Override
public String toString() {
- return String.format("Server
type=%s,version=%s,home=%s,withJava=%s,remoteSystem=%s",
this.type,this.version,this.runtimeHome,this.withJavaVersion,this.remoteSystem);
+ return String.format("%s
type=%s,version=%s,home=%s,withJava=%s,remoteSystem=%s",this.key,
this.type,this.version,this.runtimeHome,this.withJavaVersion,this.remoteSystem);
}
/**
@@ -61,5 +79,8 @@
public String getName() {
return type + "-" + version;
}
+ public ServerBean() {
+ this.key = TestConfigurator.Keys.SERVER;
+ }
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfiguration.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -53,8 +53,7 @@
// properties got loaded
java = JavaBean.fromString(getProperty(Keys.JAVA));
printConfig(Keys.JAVA, java);
- log.info(getProperty(Keys.SERVER));
- server = ServerBean.fromString(getProperty(Keys.SERVER));
+ server =
ServerBean.fromString(getProperty(Keys.SERVER),getProperty(Keys.SERVER+TestConfigurator.RUNTIME_URL_SUFFIX));
printConfig(Keys.SERVER, server);
remoteSystem = RemoteSystemBean.fromString(getProperty(Keys.RS));
printConfig(Keys.RS, remoteSystem);
@@ -70,6 +69,7 @@
printConfig("Secure Storage",secureStorage);
checkConfig();
}
+
private static void printConfig(String propName, Object bean) {
if (bean == null) {
@@ -82,15 +82,15 @@
private boolean checkConfig() throws Exception {
if (java != null)
- checkDirExists(java.javaHome);
+ checkDirExists(java.runtimeHome);
if (seam != null)
- checkDirExists(seam.seamHome);
+ checkDirExists(seam.runtimeHome);
if (server != null)
checkDirExists(server.runtimeHome);
if (esb != null)
- checkDirExists(esb.esbHome);
+ checkDirExists(esb.runtimeHome);
if (jbpm != null)
- checkDirExists(jbpm.jbpmHome);
+ checkDirExists(jbpm.runtimeHome);
if (db != null) {
if (!db.internal)
checkFileExists(db.driverPath);
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/TestConfigurator.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -24,7 +24,7 @@
public class TestConfigurator {
private static final Logger log = Logger.getLogger(TestConfigurator.class);
-
+ public static final String RUNTIME_URL_SUFFIX="_URL";
public class Keys {
public static final String SERVER = "SERVER";
public static final String SEAM = "SEAM";
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddESB.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddESB.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddESB.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -13,7 +13,7 @@
@Override
public void handle() {
String esbName = "ESB-"+TestConfigurator.currentConfig.getEsb().version;
- SWTTestExt.eclipse.addESBRuntime(esbName,TestConfigurator.currentConfig.getEsb().version,TestConfigurator.currentConfig.getEsb().esbHome);
+ SWTTestExt.eclipse.addESBRuntime(esbName,TestConfigurator.currentConfig.getEsb().version,TestConfigurator.currentConfig.getEsb().runtimeHome);
SWTTestExt.configuredState.getEsb().isConfiured=true;
SWTTestExt.configuredState.getEsb().name=esbName;
SWTTestExt.configuredState.getEsb().version=TestConfigurator.currentConfig.getEsb().version;
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJBPM.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJBPM.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJBPM.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -13,7 +13,7 @@
@Override
public void handle() {
String jbpmName = "JBPM-"+TestConfigurator.currentConfig.getJBPM().version;
- SWTTestExt.eclipse.addJBPMRuntime(jbpmName,
TestConfigurator.currentConfig.getJBPM().jbpmHome);
+ SWTTestExt.eclipse.addJBPMRuntime(jbpmName,
TestConfigurator.currentConfig.getJBPM().runtimeHome);
SWTTestExt.configuredState.getJBPM().isConfigured=true;
SWTTestExt.configuredState.getJBPM().name=jbpmName;
SWTTestExt.configuredState.getJBPM().version=TestConfigurator.currentConfig.getJBPM().version;
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJava.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJava.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddJava.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -29,7 +29,7 @@
return "JRE-"+TestConfigurator.currentConfig.getJava().version;
}
private String getJavaHome() {
- return TestConfigurator.currentConfig.getJava().javaHome;
+ return TestConfigurator.currentConfig.getJava().runtimeHome;
}
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/config/requirement/AddSeam.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -13,7 +13,7 @@
@Override
public void handle() {
String seamName = "Seam-"+TestConfigurator.currentConfig.getSeam().version;
- SWTTestExt.eclipse.addSeamRuntime(seamName,
TestConfigurator.currentConfig.getSeam().version,
TestConfigurator.currentConfig.getSeam().seamHome);
+ SWTTestExt.eclipse.addSeamRuntime(seamName,
TestConfigurator.currentConfig.getSeam().version,
TestConfigurator.currentConfig.getSeam().runtimeHome);
SWTTestExt.configuredState.getSeam().isConfiured=true;
SWTTestExt.configuredState.getSeam().name=seamName;
SWTTestExt.configuredState.getSeam().version=TestConfigurator.currentConfig.getSeam().version;
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java 2011-08-01
10:28:00 UTC (rev 33408)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/FileHelper.java 2011-08-01
12:20:17 UTC (rev 33409)
@@ -10,12 +10,20 @@
******************************************************************************/
package org.jboss.tools.ui.bot.ext.helper;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
@@ -23,82 +31,165 @@
import org.jboss.tools.ui.bot.ext.view.PackageExplorer;
/**
- * Contains some file manipulation utils
+ * Contains some file manipulation utils
+ *
* @author Vladimir Pakan
- *
+ *
*/
public class FileHelper {
- /**
- * Recursively copies files and subdirectories from fromLocation to toLocation using
FileFilter fileFliter
- * @param fromLocation
- * @param toLocation
- * @param fileFilter
- * @throws IOException
- */
- public static void copyFilesBinaryRecursively(File fromLocation, File toLocation,
FileFilter fileFilter ) throws IOException{
- if (fromLocation.exists()){
- for (File fileToCopy : fromLocation.listFiles(fileFilter)){
- if (fileToCopy.isDirectory()){
- File newToDir = new File(toLocation, fileToCopy.getName());
- newToDir.mkdir();
- copyFilesBinaryRecursively (fileToCopy, newToDir, fileFilter);
- }
- else{
- copyFilesBinary(fileToCopy,toLocation);
- }
- }
- }
- }
- /**
- * Copies binary file originalFile to location toLocation
- * @param originalFile
- * @param toLocation
- * @throws IOException
- */
- public static void copyFilesBinary(File originalFile, File toLocation) throws
IOException{
- FileInputStream fis = null;
- FileOutputStream fos = null;
- try {
- fis = new FileInputStream(originalFile);
- fos = new FileOutputStream(new File(toLocation, originalFile.getName()));
- byte[] buffer = new byte[4096];
- int bytesRead;
+ public static final Logger log = Logger.getLogger(FileHelper.class);
- while ((bytesRead = fis.read(buffer)) != -1) {
- fos.write(buffer, 0, bytesRead); // write
- }
-
- }finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- // do nothing
- }
- }
- if (fos != null) {
- try {
- fos.flush();
- fos.close();
- } catch (IOException e) {
- // do nothing
- }
- }
- }
- }
+ /**
+ * Recursively copies files and subdirectories from fromLocation to
+ * toLocation using FileFilter fileFliter
+ *
+ * @param fromLocation
+ * @param toLocation
+ * @param fileFilter
+ * @throws IOException
+ */
+ public static void copyFilesBinaryRecursively(File fromLocation,
+ File toLocation, FileFilter fileFilter) throws IOException {
+ if (fromLocation.exists()) {
+ for (File fileToCopy : fromLocation.listFiles(fileFilter)) {
+ if (fileToCopy.isDirectory()) {
+ File newToDir = new File(toLocation, fileToCopy.getName());
+ newToDir.mkdir();
+ copyFilesBinaryRecursively(fileToCopy, newToDir, fileFilter);
+ } else {
+ copyFilesBinary(fileToCopy, toLocation);
+ }
+ }
+ }
+ }
- public static String getProjectLocation (String projectName , SWTBot bot){
- PackageExplorer packageExplorer = new PackageExplorer();
- SWTBot packageExplorerBot = packageExplorer.show().bot();
- SWTBotTree packageExplorerTree = packageExplorerBot.tree();
- packageExplorerTree.expandNode(projectName).select();
- bot.menu(IDELabel.Menu.FILE).menu(IDELabel.Menu.PROPERTIES).click();
- SWTBot propertiesBot = bot.shell(IDELabel.Shell.PROPERTIES_FOR + " " +
projectName).activate().bot();
- propertiesBot.tree().select(IDELabel.PropertiesWindow.RESOURCE);
- SWTBotText pathText =
propertiesBot.textWithLabel(IDELabel.PropertiesWindow.ResourceProperties.LOCATION);
- String projectLocation = pathText.getText();
- propertiesBot.button(IDELabel.Button.OK).click();
- return projectLocation;
- }
-
+ /**
+ * Copies binary file originalFile to location toLocation
+ *
+ * @param originalFile
+ * @param toLocation
+ * @throws IOException
+ */
+ public static void copyFilesBinary(File originalFile, File toLocation)
+ throws IOException {
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
+ try {
+ fis = new FileInputStream(originalFile);
+ fos = new FileOutputStream(new File(toLocation,
+ originalFile.getName()));
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+
+ while ((bytesRead = fis.read(buffer)) != -1) {
+ fos.write(buffer, 0, bytesRead); // write
+ }
+
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ if (fos != null) {
+ try {
+ fos.flush();
+ fos.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ }
+
+ public static String getProjectLocation(String projectName, SWTBot bot) {
+ PackageExplorer packageExplorer = new PackageExplorer();
+ SWTBot packageExplorerBot = packageExplorer.show().bot();
+ SWTBotTree packageExplorerTree = packageExplorerBot.tree();
+ packageExplorerTree.expandNode(projectName).select();
+ bot.menu(IDELabel.Menu.FILE).menu(IDELabel.Menu.PROPERTIES).click();
+ SWTBot propertiesBot = bot
+ .shell(IDELabel.Shell.PROPERTIES_FOR + " " + projectName)
+ .activate().bot();
+ propertiesBot.tree().select(IDELabel.PropertiesWindow.RESOURCE);
+ SWTBotText pathText = propertiesBot
+ .textWithLabel(IDELabel.PropertiesWindow.ResourceProperties.LOCATION);
+ String projectLocation = pathText.getText();
+ propertiesBot.button(IDELabel.Button.OK).click();
+ return projectLocation;
+ }
+
+ public static void unzipArchive(File archive, File outputDir)
+ throws Exception {
+ log.info("Unzipping " + archive.getCanonicalPath() + " to "
+ + outputDir.getCanonicalPath());
+ ZipFile zipfile = new ZipFile(archive);
+ for (Enumeration<? extends ZipEntry> e = zipfile.entries(); e
+ .hasMoreElements();) {
+ ZipEntry entry = (ZipEntry) e.nextElement();
+ unzipEntry(zipfile, entry, outputDir);
+ }
+ log.info("DONE");
+ }
+
+ static private boolean deleteDirectory(File path) {
+ if (path.exists()) {
+ File[] files = path.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ deleteDirectory(files[i]);
+ } else {
+ files[i].delete();
+ }
+ }
+ }
+ return (path.delete());
+ }
+
+ private static void unzipEntry(ZipFile zipfile, ZipEntry entry,
+ File outputDir) throws IOException {
+
+ if (entry.isDirectory()) {
+ createDir(new File(outputDir, entry.getName()));
+ return;
+ }
+
+ File outputFile = new File(outputDir, entry.getName());
+ if (!outputFile.getParentFile().exists()) {
+ createDir(outputFile.getParentFile());
+ }
+
+ BufferedInputStream inputStream = new BufferedInputStream(
+ zipfile.getInputStream(entry));
+ BufferedOutputStream outputStream = new BufferedOutputStream(
+ new FileOutputStream(outputFile));
+
+ try {
+ copy(inputStream, outputStream);
+ } finally {
+ outputStream.close();
+ inputStream.close();
+ }
+ }
+
+ private static void copy(InputStream in, OutputStream out)
+ throws IOException {
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+
+ private static void createDir(File dir) {
+ if (dir.exists()) {
+ deleteDirectory(dir);
+ }
+ if (!dir.mkdirs())
+ throw new RuntimeException("Can not create dir " + dir);
+ }
}