< prev index next >

test/jdk/tools/jpackage/linux/base/Base.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.File;

  25 import java.util.ArrayList;
  26 import java.util.List;
  27 
  28 public class Base {
  29 
  30     private static String TEST_NAME;
  31     private static String EXT;
  32     private static String OUTPUT;
  33     private static String[] CMD;
  34 
  35     private static void copyResults() throws Exception {
  36         List<String> files = new ArrayList<>();
  37         files.add(OUTPUT.toLowerCase());
  38         JPackageInstallerHelper.copyTestResults(files);
  39     }
  40 
  41     private static void testCreateInstaller() throws Exception {
  42         JPackageHelper.executeCLI(true, CMD);
  43         JPackageInstallerHelper.validateOutput(OUTPUT);
  44         copyResults();
  45     }
  46 
  47     private static void verifyInstall() throws Exception {
  48         String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
  49         JPackageInstallerHelper.validateApp(app);
  50     }
  51 
  52     private static void verifyUnInstall() throws Exception {
  53         String folderPath = JPackagePath.getLinuxInstallFolder(TEST_NAME);
  54         File folder = new File(folderPath);
  55         if (folder.exists()) {
  56             throw new AssertionError("Error: " + folder.getAbsolutePath() + " exist");
  57         }
  58     }
  59 
  60     private static void init(String name, String ext) {










  61         TEST_NAME = name;
  62         EXT = ext;
  63         if (EXT.equals("rpm")) {
  64             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1.x86_64." + EXT;
  65         } else {
  66             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
  67         }
  68         CMD = new String[]{
  69             "--package-type", EXT,
  70             "--input", "input",
  71             "--output", "output",
  72             "--name", TEST_NAME,
  73             "--main-jar", "hello.jar",
  74             "--main-class", "Hello" };
  75     }
  76 
  77     public static void run(String name, String ext) throws Exception {
  78         init(name, ext);
  79 
  80         if (JPackageInstallerHelper.isVerifyInstall()) {
  81             verifyInstall();
  82         } else if (JPackageInstallerHelper.isVerifyUnInstall()) {
  83             verifyUnInstall();
  84         } else {


   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.File;
  25 import java.nio.file.Files;
  26 import java.util.ArrayList;
  27 import java.util.List;
  28 
  29 public class Base {
  30 
  31     private static String TEST_NAME;
  32     private static String EXT;
  33     private static String OUTPUT;
  34     private static String[] CMD;
  35 
  36     private static void copyResults() throws Exception {
  37         List<String> files = new ArrayList<>();
  38         files.add(OUTPUT.toLowerCase());
  39         JPackageInstallerHelper.copyTestResults(files);
  40     }
  41 
  42     private static void testCreateInstaller() throws Exception {
  43         JPackageHelper.executeCLI(true, CMD);
  44         JPackageInstallerHelper.validateOutput(OUTPUT);
  45         copyResults();
  46     }
  47 
  48     private static void verifyInstall() throws Exception {
  49         String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
  50         JPackageInstallerHelper.validateApp(app);
  51     }
  52 
  53     private static void verifyUnInstall() throws Exception {
  54         String folderPath = JPackagePath.getLinuxInstallFolder(TEST_NAME);
  55         File folder = new File(folderPath);
  56         if (folder.exists()) {
  57             throw new AssertionError("Error: " + folder.getAbsolutePath() + " exist");
  58         }
  59     }
  60 
  61     static String getRpmArch() throws Exception {
  62         File out = File.createTempFile("rpmbuild", ".out");
  63         out.deleteOnExit();
  64         int code = JPackageHelper.execute(out, "rpmbuild", "-E=%{_target_cpu}");
  65         if (code != 0) {
  66             throw new AssertionError("Error: unable to get rpm arch");
  67         }
  68         return Files.readAllLines(out.toPath()).get(0);
  69     }
  70 
  71     private static void init(String name, String ext) throws Exception {
  72         TEST_NAME = name;
  73         EXT = ext;
  74         if (EXT.equals("rpm")) {
  75             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + getRpmArch() + "." + EXT;
  76         } else {
  77             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
  78         }
  79         CMD = new String[]{
  80             "--package-type", EXT,
  81             "--input", "input",
  82             "--output", "output",
  83             "--name", TEST_NAME,
  84             "--main-jar", "hello.jar",
  85             "--main-class", "Hello" };
  86     }
  87 
  88     public static void run(String name, String ext) throws Exception {
  89         init(name, ext);
  90 
  91         if (JPackageInstallerHelper.isVerifyInstall()) {
  92             verifyInstall();
  93         } else if (JPackageInstallerHelper.isVerifyUnInstall()) {
  94             verifyUnInstall();
  95         } else {
< prev index next >