< prev index next >

functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/AppWrapper.java

Print this page




 104         if (!getModuleTempSources().isEmpty()) {
 105             Utils.createDir(
 106                     Paths.get(getModulePathBasedOnExtension(extension)));
 107         }
 108     }
 109 
 110     private void createSrcBundleAndBinDirs() throws IOException {
 111         Utils.createDir(getSrcDir());
 112         Utils.createDir(getBundlesDir());
 113         Utils.createDir(getBinDir());
 114     }
 115 
 116     public void preinstallApp(ExtensionType[] extensionArray) throws IOException {
 117         createSrcBundleAndBinDirs();
 118 
 119         for (ExtensionType extension : extensionArray) {
 120             Utils.createDir(Paths.get(getModulePathBasedOnExtension(extension)));
 121         }
 122     }
 123 

 124     private List<Source> getJarTempSources() {
 125         return sources.stream().filter((source) -> !source.isModule())
 126                 .collect(Collectors.toList());
 127     }
 128 
 129     public Path getWorkDir() {
 130         return workDir;
 131     }
 132 
 133     public void setWorkDir(Path workDir) {
 134         this.workDir = workDir;
 135     }
 136 
 137     public List<Source> getSources() {
 138         return sources;
 139     }
 140 
 141     public String getMainClass() {
 142         return this.mainClass;
 143     }


 183         int resultForModule = compileAppForModules(javacOptions, extension,
 184                 classpath);
 185         int resultForJar = compileAppForJars(javacOptions, extension,
 186                 classpath);
 187         int result = 0;
 188         if (resultForJar < 0 || resultForModule < 0) {
 189             result = -1;
 190         }
 191         return result;
 192     }
 193 
 194     public int compileApp(Path... classpath) throws IOException {
 195         return compileApp(new String[0], classpath);
 196     }
 197 
 198     public int compileApp(String[] javacOptions, Path... classpath)
 199             throws IOException {
 200         return compileApp(javacOptions, null, classpath);
 201     }
 202 
 203     public int compileAndCreateJavaExtensionProduct(ExtensionType extension, Path... classpath) throws IOException, ExecutionException  {
 204         int resultForModule = compileAppForModules(new String[0], extension, classpath);
 205         jarApp(extension);
 206         compileAppForJars(new String[0], extension, classpath);
 207         jarApp(ExtensionType.NormalJar);
 208         return resultForModule;
 209     }
 210 
 211     private int compileAppForJars(String[] javacOptions,
 212             ExtensionType extension, Path[] classpath) throws IOException {
 213         if (getJarTempSources().isEmpty()) {
 214             return 0;
 215         }
 216         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 217         final List<String> argsList = new ArrayList<>();
 218 
 219         if (javacOptions != null && javacOptions.length > 0) {
 220             for (int i = 0; i < javacOptions.length; i++) {
 221                 String javacOption = javacOptions[i];
 222                 argsList.add(javacOption);
 223             }
 224         }
 225 
 226         argsList.add("-d");
 227         argsList.add(getBinDir().toString());
 228 
 229         int result = 0;
 230         for (Source tempSource : getJarTempSources()) {
 231             List<String> newArgs = new ArrayList<String>();
 232             newArgs.addAll(argsList);
 233 

 234             newArgs.add("-classpath");
 235             if (classpath.length != 0) {
 236                 newArgs.add(Stream.of(classpath)
 237                         .map(eachPath -> eachPath.toAbsolutePath().toString())
 238                         .collect(joining(File.pathSeparator)));
 239             } else {
 240                 newArgs.add(getBinDir().toString());
 241             }
 242 
 243             if (paramsForJarsCompilation != null) {
 244                 newArgs.add(this.paramsForJarsCompilation);
 245             }
 246 
 247             if (extension != null) {
 248                 newArgs.add("-mp");
 249                 newArgs.add(String.join(File.pathSeparator, getModulePathBasedOnExtension(extension), JMODS_PATH_IN_JDK));
 250             }
 251 
 252             String string = getSrcDir() + File.separator
 253                     + tempSource.getPackageName().replace(".", File.separator);
 254             Path path = Paths.get(string);
 255             Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
 256                 @Override
 257                 public FileVisitResult visitFile(Path file,
 258                         BasicFileAttributes attr) {
 259 
 260                     if (file.toString().endsWith(".java")) {
 261                         newArgs.add(file.toString());
 262                     }
 263                     return FileVisitResult.CONTINUE;
 264                 }
 265             });
 266 
 267             ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 268             LOG.log(Level.INFO,
 269                     "====================COMPILATION STARTS FOR NORMAL JAR===========================");
 270             LOG.log(Level.INFO,"compilation command for jars is " + newArgs);
 271             result = compiler.run(System.in, outputStream, System.err,
 272                     newArgs.toArray(new String[newArgs.size()]));
 273             LOG.log(Level.INFO,
 274                     "====================COMPILATION ENDS FOR NORMAL JAR=============================");

 275         }
 276         return result;
 277     }
 278 
 279     private int compileAppForModules(String[] javacOptions,
 280             ExtensionType extension, Path... classpath) throws IOException {
 281         if (getModuleTempSources().isEmpty()) {
 282             return 0;
 283         }
 284         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 285         int result = 0;
 286         for (Source source : getModuleTempSources()) {
 287             final List<String> argsList = new ArrayList<>();
 288 
 289             if (javacOptions != null && javacOptions.length > 0) {
 290                 for (int i = 0; i < javacOptions.length; i++) {
 291                     String javacOption = javacOptions[i];
 292                     argsList.add(javacOption);
 293                 }
 294             }


 300                     source.getModuleName()));
 301             Files.walkFileTree(
 302                     Paths.get(String.join(File.separator,
 303                             getSrcDir().toString(), source.getModuleName())),
 304                     new SimpleFileVisitor<Path>() {
 305                         public FileVisitResult visitFile(Path file,
 306                                 BasicFileAttributes attr) {
 307                             if (file.toString().endsWith(".java")) {
 308                                 argsList.add(file.toString());
 309                             }
 310                             return FileVisitResult.CONTINUE;
 311                         }
 312                     });
 313             if (classpath.length != 0) {
 314                 argsList.add("-classpath");
 315                 argsList.add(Stream.of(classpath)
 316                         .map(path -> path.toAbsolutePath().toString())
 317                         .collect(joining(File.pathSeparator)));
 318             }
 319             ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 320             if(extension != null) {
 321                 LOG.log(Level.INFO,
 322                         "====================COMPILATION STARTS FOR "+extension+" ===========================");
 323                 LOG.log(Level.INFO, "compilation command for "+extension+" is "+argsList);
 324             } else {
 325                 LOG.log(Level.INFO,
 326                         "compilation command for modules is " + argsList);
 327             }
 328            
 329             int tempResult = compiler.run(System.in, outputStream, System.err,
 330                     argsList.toArray(new String[argsList.size()]));
 331             if (tempResult != 0) {
 332                 result = tempResult;
 333             }
 334             String out = outputStream.toString();
 335             if (!out.trim().isEmpty()) {
 336                 LOG.log(Level.INFO, out);
 337             }
 338             if(extension != null) {
 339                 LOG.log(Level.INFO,
 340                         "===================COMPILATION ENDS FOR "+extension+ " ==============================");
 341             } else {
 342                 LOG.log(Level.INFO, "===================COMPILATION ENDS===================");
 343             }
 344             LOG.log(Level.INFO, "\n");
 345         }
 346         return result;
 347     }
 348 
 349     public List<Path> getJarFilesList() throws IOException {
 350         try (DirectoryStream<Path> jarsStream = Files
 351                 .newDirectoryStream(getJarDir(), "*.jar")) {
 352             List<Path> jars = new ArrayList<>();
 353             jarsStream.forEach(jars::add);
 354             return jars;
 355         }
 356     }
 357 
 358     private void createSimpleJar(List<Pair<String, String>> services,
 359             boolean crossClassPath) throws IOException {
 360 
 361         if (getJarTempSources().isEmpty()) {
 362             return;
 363         }
 364         Map<String, List<Source>> jars = getJarTempSources().stream()


 657                 System.out.println();
 658             }
 659         }
 660     }
 661 
 662     public String getIdentifier() {
 663         try (JarFile mainJar = new JarFile(getMainJarFile().toFile());) {
 664             Manifest manifest = mainJar.getManifest();
 665             for (Map.Entry<Object, Object> entry : manifest.getMainAttributes()
 666                     .entrySet()) {
 667                 if (entry.getKey().toString().equals("Main-Class")) {
 668                     return entry.getValue().toString();
 669                 }
 670             }
 671         } catch (IOException ex) {
 672             throw new RuntimeException(ex);
 673         }
 674         return "";
 675     }
 676 
 677     public String getAllModuleNamesSeparatedByPathSeparator() {
 678         return getModuleTempSources().stream().map(Source::getModuleName)
 679                 .collect(Collectors.joining(File.pathSeparator));
 680     }
 681     
 682     public String getAllModuleNamesSeparatedByComma() {
 683         return getModuleTempSources().stream().map(Source::getModuleName)
 684                 .collect(Collectors.joining(","));
 685     }
 686 
 687     public List<String> getAllModuleNamesAsList() {
 688         return getModuleTempSources().stream().map(Source::getModuleName)
 689                 .collect(Collectors.toList());
 690     }
 691 
 692     public String getMainModuleName() {
 693         List<Source> collect = sources.stream()
 694                 .filter((source) -> source.isMainModule())
 695                 .collect(Collectors.toList());
 696         return !collect.isEmpty() ? collect.get(0).getModuleName() : null;
 697     }
 698 
 699     public boolean isAppContainsModules() {
 700         return !getModuleTempSources().isEmpty();
 701     }
 702 
 703     private String getModulePathBasedOnExtension(ExtensionType extension) {
 704         if (extension == null) {


 104         if (!getModuleTempSources().isEmpty()) {
 105             Utils.createDir(
 106                     Paths.get(getModulePathBasedOnExtension(extension)));
 107         }
 108     }
 109 
 110     private void createSrcBundleAndBinDirs() throws IOException {
 111         Utils.createDir(getSrcDir());
 112         Utils.createDir(getBundlesDir());
 113         Utils.createDir(getBinDir());
 114     }
 115 
 116     public void preinstallApp(ExtensionType[] extensionArray) throws IOException {
 117         createSrcBundleAndBinDirs();
 118 
 119         for (ExtensionType extension : extensionArray) {
 120             Utils.createDir(Paths.get(getModulePathBasedOnExtension(extension)));
 121         }
 122     }
 123 
 124 
 125     private List<Source> getJarTempSources() {
 126         return sources.stream().filter((source) -> !source.isModule())
 127                 .collect(Collectors.toList());
 128     }
 129 
 130     public Path getWorkDir() {
 131         return workDir;
 132     }
 133 
 134     public void setWorkDir(Path workDir) {
 135         this.workDir = workDir;
 136     }
 137 
 138     public List<Source> getSources() {
 139         return sources;
 140     }
 141 
 142     public String getMainClass() {
 143         return this.mainClass;
 144     }


 184         int resultForModule = compileAppForModules(javacOptions, extension,
 185                 classpath);
 186         int resultForJar = compileAppForJars(javacOptions, extension,
 187                 classpath);
 188         int result = 0;
 189         if (resultForJar < 0 || resultForModule < 0) {
 190             result = -1;
 191         }
 192         return result;
 193     }
 194 
 195     public int compileApp(Path... classpath) throws IOException {
 196         return compileApp(new String[0], classpath);
 197     }
 198 
 199     public int compileApp(String[] javacOptions, Path... classpath)
 200             throws IOException {
 201         return compileApp(javacOptions, null, classpath);
 202     }
 203 
 204     public int compileAndCreateExtensionEndProduct(ExtensionType extension, Path... classpath) throws IOException, ExecutionException  {
 205         int resultForModule = compileAppForModules(new String[0], extension, classpath);
 206         jarApp(extension);
 207         compileAppForJars(new String[0], extension, classpath);
 208         jarApp(ExtensionType.NormalJar);
 209         return resultForModule;
 210     }
 211 
 212     private int compileAppForJars(String[] javacOptions,
 213             ExtensionType extension, Path[] classpath) throws IOException {
 214         if (getJarTempSources().isEmpty()) {
 215             return 0;
 216         }
 217         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 218         final List<String> argsList = new ArrayList<>();
 219 
 220         if (javacOptions != null && javacOptions.length > 0) {
 221             for (int i = 0; i < javacOptions.length; i++) {
 222                 String javacOption = javacOptions[i];
 223                 argsList.add(javacOption);
 224             }
 225         }
 226 
 227         argsList.add("-d");
 228         argsList.add(getBinDir().toString());
 229 
 230         int result = 0;
 231         for (Source tempSource : getJarTempSources()) {
 232             List<String> newArgs = new ArrayList<String>();
 233             newArgs.addAll(argsList);
 234 
 235 
 236             newArgs.add("-classpath");
 237             if (classpath.length != 0) {
 238                 newArgs.add(Stream.of(classpath)
 239                         .map(eachPath -> eachPath.toAbsolutePath().toString())
 240                         .collect(joining(File.pathSeparator)));
 241             } else {
 242                 newArgs.add(getBinDir().toString());
 243             }
 244 
 245             if (paramsForJarsCompilation != null) {
 246                 newArgs.add(this.paramsForJarsCompilation);
 247             }
 248 
 249             if (extension != null) {
 250                 newArgs.add("-mp");
 251                 newArgs.add(String.join(File.pathSeparator, getModulePathBasedOnExtension(extension), JMODS_PATH_IN_JDK));
 252             }
 253 
 254             String string = getSrcDir() + File.separator
 255                     + tempSource.getPackageName().replace(".", File.separator);
 256             Path path = Paths.get(string);
 257             Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
 258                 @Override
 259                 public FileVisitResult visitFile(Path file,
 260                         BasicFileAttributes attr) {
 261 
 262                     if (file.toString().endsWith(".java")) {
 263                         newArgs.add(file.toString());
 264                     }
 265                     return FileVisitResult.CONTINUE;
 266                 }
 267             });
 268 
 269             ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 270             System.out.println(
 271                     "====================COMPILATION STARTS===========================");
 272             System.out.println("compilation command for jars is " + newArgs);
 273             result = compiler.run(System.in, outputStream, System.err,
 274                     newArgs.toArray(new String[newArgs.size()]));
 275             System.out.println(
 276                     "===================COMPILATION ENDS===============================");
 277             System.out.println();
 278         }
 279         return result;
 280     }
 281 
 282     private int compileAppForModules(String[] javacOptions,
 283             ExtensionType extension, Path... classpath) throws IOException {
 284         if (getModuleTempSources().isEmpty()) {
 285             return 0;
 286         }
 287         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 288         int result = 0;
 289         for (Source source : getModuleTempSources()) {
 290             final List<String> argsList = new ArrayList<>();
 291 
 292             if (javacOptions != null && javacOptions.length > 0) {
 293                 for (int i = 0; i < javacOptions.length; i++) {
 294                     String javacOption = javacOptions[i];
 295                     argsList.add(javacOption);
 296                 }
 297             }


 303                     source.getModuleName()));
 304             Files.walkFileTree(
 305                     Paths.get(String.join(File.separator,
 306                             getSrcDir().toString(), source.getModuleName())),
 307                     new SimpleFileVisitor<Path>() {
 308                         public FileVisitResult visitFile(Path file,
 309                                 BasicFileAttributes attr) {
 310                             if (file.toString().endsWith(".java")) {
 311                                 argsList.add(file.toString());
 312                             }
 313                             return FileVisitResult.CONTINUE;
 314                         }
 315                     });
 316             if (classpath.length != 0) {
 317                 argsList.add("-classpath");
 318                 argsList.add(Stream.of(classpath)
 319                         .map(path -> path.toAbsolutePath().toString())
 320                         .collect(joining(File.pathSeparator)));
 321             }
 322             ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 323             System.out.println(
 324                     "====================COMPILATION STARTS===========================");
 325             System.out.println(



 326                     "compilation command for modules is " + argsList);

 327 
 328             int tempResult = compiler.run(System.in, outputStream, System.err,
 329                     argsList.toArray(new String[argsList.size()]));
 330             if (tempResult != 0) {
 331                 result = tempResult;
 332             }
 333             String out = outputStream.toString();
 334             if (!out.trim().isEmpty()) {
 335                 LOG.log(Level.INFO, out);
 336             }
 337             System.out.println(
 338                     "===================COMPILATION ENDS===============================");
 339             System.out.println();




 340         }
 341         return result;
 342     }
 343 
 344     public List<Path> getJarFilesList() throws IOException {
 345         try (DirectoryStream<Path> jarsStream = Files
 346                 .newDirectoryStream(getJarDir(), "*.jar")) {
 347             List<Path> jars = new ArrayList<>();
 348             jarsStream.forEach(jars::add);
 349             return jars;
 350         }
 351     }
 352 
 353     private void createSimpleJar(List<Pair<String, String>> services,
 354             boolean crossClassPath) throws IOException {
 355 
 356         if (getJarTempSources().isEmpty()) {
 357             return;
 358         }
 359         Map<String, List<Source>> jars = getJarTempSources().stream()


 652                 System.out.println();
 653             }
 654         }
 655     }
 656 
 657     public String getIdentifier() {
 658         try (JarFile mainJar = new JarFile(getMainJarFile().toFile());) {
 659             Manifest manifest = mainJar.getManifest();
 660             for (Map.Entry<Object, Object> entry : manifest.getMainAttributes()
 661                     .entrySet()) {
 662                 if (entry.getKey().toString().equals("Main-Class")) {
 663                     return entry.getValue().toString();
 664                 }
 665             }
 666         } catch (IOException ex) {
 667             throw new RuntimeException(ex);
 668         }
 669         return "";
 670     }
 671 
 672     public String addAllModules() {
 673         return getModuleTempSources().stream().map(Source::getModuleName)
 674                 .collect(Collectors.joining(File.pathSeparator));





 675     }
 676 
 677     public List<String> getAllModuleNamesAsList() {
 678         return getModuleTempSources().stream().map(Source::getModuleName)
 679                 .collect(Collectors.toList());
 680     }
 681 
 682     public String getMainModuleName() {
 683         List<Source> collect = sources.stream()
 684                 .filter((source) -> source.isMainModule())
 685                 .collect(Collectors.toList());
 686         return !collect.isEmpty() ? collect.get(0).getModuleName() : null;
 687     }
 688 
 689     public boolean isAppContainsModules() {
 690         return !getModuleTempSources().isEmpty();
 691     }
 692 
 693     private String getModulePathBasedOnExtension(ExtensionType extension) {
 694         if (extension == null) {
< prev index next >