Package org.sugarj.common

Examples of org.sugarj.common.Environment


    return null;
  }
 
  protected void clean(IProgressMonitor monitor) throws CoreException {
    File f = getProject().getLocation().append(JavaCore.create(getProject()).getOutputLocation().makeRelativeTo(getProject().getFullPath())).toFile();
    Environment environment = SugarJParseController.makeProjectEnvironment(getProject());
    try {
      FileCommands.delete(new AbsolutePath(f.getPath()));
      FileCommands.delete(environment.getParseBin());
      FileCommands.delete(environment.getCacheDir());
    } catch (IOException e) {
    }
   
  }
View Full Code Here


    build(monitor, resources, "project " + getProject().getName());
  }

  private void build(IProgressMonitor monitor, final List<BuildInput> inputs, String what) {
    final Environment environment = SugarJParseController.makeProjectEnvironment(getProject());
    environment.setGenerateFiles(true);
   
    CommandExecution.SILENT_EXECUTION = false;
    CommandExecution.SUB_SILENT_EXECUTION = false;
    CommandExecution.FULL_COMMAND_LINE = true;

    Log.out = SugarJConsole.getOutputPrintStream();
    Log.err = SugarJConsole.getErrorPrintStream();
    SugarJConsole.activateConsoleOnce();

    Job buildJob = new Job("Build " + what) {
      @Override
      protected IStatus run(IProgressMonitor monitor) {
        ProcessingListener marker = new MarkingProcessingListener(getProject());
        Driver.addProcessingDoneListener(marker);
//        getLock(getProject()).acquire();
        for (BuildInput input : inputs)
          try {
            if (Thread.currentThread().isInterrupted()) {
              monitor.setCanceled(true);
              monitor.done();
              return Status.CANCEL_STATUS;
            }
             
            monitor.beginTask("compile " + input.sourceFile.getRelativePath(), IProgressMonitor.UNKNOWN);

            RelativePath depFile = new RelativePath(environment.getParseBin(), FileCommands.dropExtension(input.sourceFile.getRelativePath()) + ".dep");
            Result res = Result.readDependencyFile(depFile);
            if (res == null || !res.isUpToDate(input.sourceFile, environment))
              res = Driver.run(input.sourceFile, environment, monitor, input.baseLang);
           
            IWorkbenchWindow[] workbenchWindows = PlatformUI.getWorkbench().getWorkbenchWindows();
View Full Code Here

*/
public class Main {

  public static void main(String[] args) throws Throwable {

    Environment environment = getConsoleEnvironment();
   
    Set<RelativePath> allInputFiles = new HashSet<RelativePath>();
   
    try {
      String[] sources = DriverCLI.handleOptions(args, environment);
     
      for (String source : sources) {
        RelativePath sourceLocation = ModuleSystemCommands.locateSourceFile(source, environment.getSourcePath());
       
        if (sourceLocation == null) {
          Log.log.logErr("Could not locate source file \"" + source +"\".", Log.ALWAYS);
          continue;
        }
View Full Code Here

  }
 
  // without running eclipse platform,
  // set up a default environment reasonable for command-line execution.
  private static Environment getConsoleEnvironment() {
    Environment environment = new Environment(true, StdLib.stdLibDir);
    environment.setCacheDir(new RelativePath(new AbsolutePath(FileCommands.TMP_DIR), ".sugarjcache"));
    environment.addToSourcePath(new AbsolutePath("."));
    environment.setAtomicImportParsing(true);
    environment.setNoChecking(true);
   
    for (String cp : System.getProperty("java.class.path").split(System.getProperty("path.separator"))) {
      if (cp.length() > 0)
        environment.addToIncludePath(new AbsolutePath(cp));
    }
    return environment;
  }
View Full Code Here

  public static Environment makeProjectEnvironment(IProject project) {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null)
      return null;
   
    Environment env = null;
   
    try {
      env = makeProjectEnvironment(javaProject);
    } catch (JavaModelException e) {
      throw new RuntimeException(e);
View Full Code Here

   
    return env;
  }
 
  private static Environment makeProjectEnvironment(IJavaProject project) throws JavaModelException {
    Environment env = new Environment(false, StdLib.stdLibDir);
   
    IPath fullPath = project.getProject().getFullPath();
    Path root = new AbsolutePath(project.getProject().getLocation().makeAbsolute().toString());
    Path bin = new RelativePath(root, project.getOutputLocation().makeRelativeTo(fullPath).toString());
    env.setRoot(root);
    env.setBin(bin);
   
    for (IPackageFragmentRoot fragment : project.getAllPackageFragmentRoots()) {
      IPath path = fragment.getPath();
      boolean externalPath = fragment.getResource() == null;
      String p = externalPath ? path.toString() : path.makeRelativeTo(fullPath).toString();

      Path includePath;
      if (fullPath.isPrefixOf(path))
        includePath = p.isEmpty() ? root : new RelativePath(root, p);
      else if (externalPath)
        includePath = new AbsolutePath(p);
      else
        includePath = new RelativePath(root, p);
     
      if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE && fragment.getParent().equals(project))
        env.addToSourcePath(includePath);
      else if (fragment.getKind() == IPackageFragmentRoot.K_BINARY)
        env.addToIncludePath(includePath);
    }
   
    for (String reqProject : project.getRequiredProjectNames()) {
      IJavaProject reqJavaProject = JavaCore.create(project.getProject().getWorkspace().getRoot().getProject(reqProject));
      if (reqJavaProject != null) {
        Environment projEnv = makeProjectEnvironment(reqJavaProject);
//        env.getSourcePath().addAll(projEnv.getSourcePath());
        env.addToIncludePath(projEnv.getParseBin());
      }
    }
 
    setDefaultEnvironmentOptions(env);
   
View Full Code Here

TOP

Related Classes of org.sugarj.common.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.