/*
 * Copyright 2014 - 2015 SATO taichi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package io.gige.compiler.internal;

import static java.util.stream.StreamSupport.stream;

import java.io.File;
import java.util.Arrays;
import java.util.Optional;

import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;

import org.eclipse.jdt.internal.compiler.batch.FileSystem;

/** @author taichi */
public class ClasspathContainer extends FileSystem {

  protected ClasspathContainer(Classpath[] paths) {
    super(paths, null, true);
  }

  public static FileSystem configure(StandardJavaFileManager standardManager) {
    Classpath[] paths =
        Arrays.asList(
                StandardLocation.PLATFORM_CLASS_PATH,
                StandardLocation.SOURCE_PATH,
                StandardLocation.SOURCE_OUTPUT,
                StandardLocation.CLASS_PATH)
            .stream()
            .map(loc -> Optional.ofNullable(standardManager.getLocation(loc)))
            .filter(Optional::isPresent)
            .map(Optional::get)
            .<File>flatMap(files -> stream(files.spliterator(), false))
            .map(file -> FileSystem.getClasspath(file.getAbsolutePath(), null, null))
            .filter(cp -> cp != null)
            .toArray(Classpath[]::new);
    return new ClasspathContainer(paths);
  }
}

@@ -640,62 +640,8 @@
 l;%0A%0A
-import static java.util.stream.StreamSupport.stream;%0A%0A
 impo
@@ -704,24 +704,95 @@
 il.Optional;
+%0Aimport java.util.stream.Stream;%0Aimport java.util.stream.StreamSupport;
 %0A%0Aimport jav
@@ -921,16 +921,68 @@
 eSystem;
+%0Aimport org.eclipse.jdt.internal.compiler.util.Util;
 %0A%0A/** @a
@@ -1226,104 +1226,125 @@
     
-Classpath%5B%5D
+var
  p
+l
 at
-hs =%0A        Arrays.asList(%0A                StandardLocation.PLATFORM_CLASS_PATH,
+form = Util.collectPlatformLibraries(Util.getJavaHome()).stream();%0A    var standards =%0A        Arrays.asList(
 %0A   
@@ -1689,16 +1689,30 @@
 iles -%3E 
+StreamSupport.
 stream(f
@@ -1760,15 +1760,59 @@
 map(
-file -%3E
+%0A                file -%3E %7B%0A                  return
  Fil
@@ -1867,16 +1867,35 @@
 l, null)
+;%0A                %7D
 )%0A      
@@ -1925,29 +1925,76 @@
 != null)
+;
 %0A    
-        
+Classpath%5B%5D paths = Stream.concat(platform, standards)
 .toArray

support modules