// overridden by test subclass
  protected String[] getCeylonProjectClasspath(IJavaProject javaProject) throws JavaModelException {
    final List<String> classpathList = new ArrayList<String>();

    for (CeylonClasspathContainer container : getCeylonClasspathContainers(javaProject)) {
      boolean changed = container.resolveClasspath(new NullProgressMonitor(), false);
      if (changed) {
        container.refreshClasspathContainer(new NullProgressMonitor(), javaProject);
      }
    }

    // add the car files of the output directory
    IProject project = javaProject.getProject();
    Context context = getProjectTypeChecker(project).getContext();

    IPath modulesFolder = getCeylonModulesOutputFolder(project).getLocation();
    classpathList.add(modulesFolder.append("default").append("default.car").toOSString());

    RepositoryManager provider = context.getRepositoryManager();
    Set<Module> modulesToAdd = context.getModules().getListOfModules();
    // modulesToAdd.add(projectModules.getLanguageModule());
    for (Module module : modulesToAdd) {
      String name = module.getNameAsString();
      if (name.equals(Module.DEFAULT_MODULE_NAME)
          || JDKUtils.isJDKModule(name)
          || JDKUtils.isOracleJDKModule(name)
          || !isProjectModule(javaProject, module)) {
        continue;
      }
      IPath modulePath = getModuleArchive(provider, module);
      if (modulePath != null) {
        if (modulePath.toFile().exists()) {
          // if (project.getLocation().isPrefixOf(modulePath)) {
          // if (!classpathList.contains(modulePath.toOSString())) {
          classpathList.add(modulePath.toOSString());
          // }
          // }
        } else {
          System.err.println(
              "ignoring nonexistent module artifact for launch classpath: " + modulePath);
        }
      } else {
        System.err.println(
            "no module archive found for launch classpath: "
                + module.getNameAsString()
                + "/"
                + module.getVersion());
      }
    }

    return classpathList.toArray(new String[classpathList.size()]);
  }
  /**
   * Prints a list of module name, version, path to the given file, to be used by the runtime
   * launcher, because passing it as an argument/environment would easily exceed the OS size limits.
   */
  private void writeModuleInfoFile(File tmpFile, ILaunchConfiguration configuration)
      throws IOException, CoreException {
    FileWriter writer = new FileWriter(tmpFile);
    IJavaProject javaProject = getJavaProject(configuration);
    IProject project = javaProject.getProject();
    Context context = getProjectTypeChecker(project).getContext();

    RepositoryManager provider = context.getRepositoryManager();
    Set<Module> modulesToAdd = context.getModules().getListOfModules();
    boolean seenDefault = false;
    for (Module module : modulesToAdd) {
      String name = module.getNameAsString();
      if (JDKUtils.isJDKModule(name) || JDKUtils.isOracleJDKModule(name)) {
        continue;
      }
      if (module.isDefault()) seenDefault = true;
      IPath modulePath = getModuleArchive(provider, module);
      if (modulePath != null && modulePath.toFile().exists()) {
        String path = modulePath.toOSString();
        System.err.println(
            "Adding module: " + module.getNameAsString() + "/" + module.getVersion() + ": " + path);
        // print module name + NL (+ version + NL)? + path + NL
        writer.append(module.getNameAsString());
        writer.append(System.lineSeparator());
        if (!module.isDefault()) {
          writer.append(module.getVersion());
          writer.append(System.lineSeparator());
        }
        writer.append(path);
        writer.append(System.lineSeparator());
      }
    }
    // for some reason the default module can be missing from the list of modules
    if (!seenDefault) {
      IPath modulesFolder = getCeylonModulesOutputFolder(project).getLocation();
      IPath defaultCar = modulesFolder.append("default").append("default.car");
      if (defaultCar.toFile().exists()) {
        String path = defaultCar.toOSString();
        Module module = context.getModules().getDefaultModule();
        System.err.println("Adding default module: " + module.getNameAsString() + ": " + path);
        // print module name + NL + path + NL
        writer.append(module.getNameAsString());
        writer.append(System.lineSeparator());
        writer.append(path);
        writer.append(System.lineSeparator());
      }
    }
    writer.flush();
    writer.close();
  }
示例#3
0
 public LanguageCompiler(Context context) {
   super(context);
   ceylonContext = getCeylonContextInstance(context);
   vfs = ceylonContext.getVfs();
   compilerDelegate = getCompilerDelegate(context);
   phasedUnits = getPhasedUnitsInstance(context);
   try {
     gen = CeylonTransformer.getInstance(context);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   modelLoader = CeylonModelLoader.instance(context);
   ceylonEnter = CeylonEnter.instance(context);
   options = Options.instance(context);
   isBootstrap = options.get(Option.BOOTSTRAPCEYLON) != null;
   timer = Timer.instance(context);
   sourceLanguage = SourceLanguage.instance(context);
   boolean isProgressPrinted =
       options.get(Option.CEYLONPROGRESS) != null && StatusPrinter.canPrint();
   if (isProgressPrinted) {
     sp = getStatusPrinterInstance(context);
     if (taskListener == null) {
       taskListener.add(new StatusPrinterTaskListener(sp));
     }
   }
 }
 private void loadCompiledModules(
     List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
   compilerDelegate.visitModules(phasedUnits);
   Modules modules = ceylonContext.getModules();
   // now make sure the phase units have their modules and packages set correctly
   for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
     Package pkg = pu.getPackage();
     loadModuleFromSource(pkg, modules, moduleTrees, trees);
   }
   // also make sure we have packages and modules set up for every Java file we compile
   for (JCCompilationUnit cu : trees) {
     // skip Ceylon CUs
     if (cu instanceof CeylonCompilationUnit) continue;
     String packageName = "";
     if (cu.pid != null) packageName = TreeInfo.fullName(cu.pid).toString();
     /*
      * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
      */
     Package pkg = modelLoader.findOrCreateModulelessPackage(packageName);
     loadModuleFromSource(pkg, modules, moduleTrees, trees);
   }
   for (PhasedUnit phasedUnit : phasedUnits.getPhasedUnits()) {
     for (Tree.ModuleDescriptor modDescr :
         phasedUnit.getCompilationUnit().getModuleDescriptors()) {
       String name = phasedUnit.getPackage().getNameAsString();
       CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
       CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
       moduleNamesToFileObjects.put(name, cfo);
     }
   }
 }
 public LanguageCompiler(Context context) {
   super(context);
   ceylonContext = getCeylonContextInstance(context);
   vfs = ceylonContext.getVfs();
   phasedUnits = getPhasedUnitsInstance(context);
   try {
     gen = CeylonTransformer.getInstance(context);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   modelLoader = CeylonModelLoader.instance(context);
   ceylonEnter = CeylonEnter.instance(context);
   options = Options.instance(context);
 }
 public LanguageCompiler(Context context) {
   super(context);
   ceylonContext = getCeylonContextInstance(context);
   vfs = ceylonContext.getVfs();
   compilerDelegate = getCompilerDelegate(context);
   phasedUnits = getPhasedUnitsInstance(context);
   try {
     gen = CeylonTransformer.getInstance(context);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   modelLoader = CeylonModelLoader.instance(context);
   ceylonEnter = CeylonEnter.instance(context);
   options = Options.instance(context);
   isBootstrap = options.get(OptionName.BOOTSTRAPCEYLON) != null;
   timer = Timer.instance(context);
 }
 private void loadCompiledModules(
     List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
   phasedUnits.visitModules();
   Modules modules = ceylonContext.getModules();
   // now make sure the phase units have their modules and packages set correctly
   for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
     Package pkg = pu.getPackage();
     loadModuleFromSource(pkg, modules, moduleTrees);
   }
   // also make sure we have packages and modules set up for every Java file we compile
   for (JCCompilationUnit cu : trees) {
     // skip Ceylon CUs
     if (cu instanceof CeylonCompilationUnit) continue;
     String packageName = "";
     if (cu.pid != null) packageName = TreeInfo.fullName(cu.pid).toString();
     Package pkg = modelLoader.findOrCreatePackage(null, packageName);
     loadModuleFromSource(pkg, modules, moduleTrees);
   }
 }
示例#8
0
 private Module loadModuleFromSource(
     String pkgName,
     LinkedList<JCCompilationUnit> moduleTrees,
     List<JCCompilationUnit> parsedTrees) {
   if (pkgName.isEmpty()) return null;
   String moduleClassName = pkgName + ".module";
   JavaFileObject fileObject;
   try {
     if (options.get(Option.VERBOSE) != null) {
       log.printRawLines(
           WriterKind.NOTICE, "[Trying to load source for module " + moduleClassName + "]");
     }
     fileObject =
         fileManager.getJavaFileForInput(
             StandardLocation.SOURCE_PATH, moduleClassName, Kind.SOURCE);
     if (options.get(Option.VERBOSE) != null) {
       log.printRawLines(WriterKind.NOTICE, "[Got file object: " + fileObject + "]");
     }
   } catch (IOException e) {
     e.printStackTrace();
     return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
   }
   if (fileObject != null) {
     // first make sure we're not already compiling it: this can happen if we have several versions
     // of the
     // same module already loaded: we will get one which isn't the one we compile, but that's not
     // the one
     // we really want to compile.
     for (JCCompilationUnit parsedTree : parsedTrees) {
       if (parsedTree.sourcefile.equals(fileObject)
           && parsedTree instanceof CeylonCompilationUnit) {
         // same file! we already parsed it, let's return this one's module
         PhasedUnit phasedUnit = ((CeylonCompilationUnit) parsedTree).phasedUnit;
         // the module visitor does load the module but does not set the unit's package module
         if (phasedUnit.getPackage().getModule() == null) {
           // so find the module it created
           for (Module mod : ceylonContext.getModules().getListOfModules()) {
             // we recognise it with the unit
             if (mod.getUnit() == phasedUnit.getUnit()) {
               // set the package's module
               Package pkg = phasedUnit.getPackage();
               pkg.setModule(mod);
               mod.getPackages().add(pkg);
               modulesLoadedFromSource.add(mod);
               break;
             }
           }
         }
         // now return it
         return phasedUnit.getPackage().getModule();
       }
     }
     JCCompilationUnit javaCompilationUnit = parse(fileObject);
     Module module;
     if (javaCompilationUnit instanceof CeylonCompilationUnit) {
       CeylonCompilationUnit ceylonCompilationUnit = (CeylonCompilationUnit) javaCompilationUnit;
       moduleTrees.add(ceylonCompilationUnit);
       // parse the module info from there
       module = ceylonCompilationUnit.phasedUnit.visitSrcModulePhase();
       ceylonCompilationUnit.phasedUnit.visitRemainingModulePhase();
       // now set the module
       if (module != null) {
         ceylonCompilationUnit.phasedUnit.getPackage().setModule(module);
       }
     } else {
       // there was a syntax error in the module descriptor, make a pretend module so that we can
       // correctly mark all declarations as part of that module, but we won't generate any code
       // for it
       ModuleManager moduleManager = phasedUnits.getModuleManager();
       module = moduleManager.getOrCreateModule(Arrays.asList(pkgName.split("\\.")), "bogus");
     }
     // now remember it
     if (module != null) {
       modulesLoadedFromSource.add(module);
       return module;
     }
   }
   return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
 }