Package org.jetbrains.jps.incremental

Source Code of org.jetbrains.jps.incremental.BuilderRegistry

package org.jetbrains.jps.incremental;

import org.jetbrains.jps.incremental.java.JavaBuilder;
import org.jetbrains.jps.incremental.resourses.ResourcesBuilder;

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* @author Eugene Zhuravlev
*         Date: 9/17/11
*/
public class BuilderRegistry {
  private static class Holder {
    static final BuilderRegistry ourInstance = new BuilderRegistry();
  }
  private final Map<BuilderCategory, List<Builder>> myBuilders = new HashMap<BuilderCategory, List<Builder>>();
  private ExecutorService myTasksExecutor;

  public static BuilderRegistry getInstance() {
    return Holder.ourInstance;
  }

  private BuilderRegistry() {
    for (BuilderCategory category : BuilderCategory.values()) {
      myBuilders.put(category, new ArrayList<Builder>());
    }
    final Runtime runtime = Runtime.getRuntime();
    myTasksExecutor = Executors.newFixedThreadPool(runtime.availableProcessors());
    runtime.addShutdownHook(new Thread() {
      public void run() {
        myTasksExecutor.shutdownNow();
      }
    });

    // todo: some builder registration mechanism needed
    myBuilders.get(BuilderCategory.TRANSLATOR).add(new JavaBuilder(myTasksExecutor));
    myBuilders.get(BuilderCategory.TRANSLATOR).add(new ResourcesBuilder());

  }

  public List<BuildTask> getBeforeTasks(){
    return Collections.emptyList(); // todo
  }

  public List<BuildTask> getAfterTasks(){
    return Collections.emptyList(); // todo
  }

  public List<Builder> getBuilders(BuilderCategory category){
    return myBuilders.get(category); // todo
  }

  public void shutdown() {
    try {
      for (List<Builder> builders : myBuilders.values()) {
        for (Builder builder : builders) {
          builder.cleanupResources();
        }
      }
    }
    finally {
      myTasksExecutor.shutdownNow();
    }
  }

}
TOP

Related Classes of org.jetbrains.jps.incremental.BuilderRegistry

TOP
Copyright © 2018 www.massapi.com. 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.