mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new project model: fixed loading from xml
This commit is contained in:
@@ -18,6 +18,8 @@ public abstract class JpsElementFactory {
|
||||
return JpsServiceManager.getInstance().getService(JpsElementFactory.class);
|
||||
}
|
||||
|
||||
public abstract JpsModel createModel();
|
||||
|
||||
public abstract <P extends JpsElementProperties> JpsModule createModule(@NotNull String name, @NotNull JpsModuleType<P> type, @NotNull P properties);
|
||||
|
||||
public abstract <P extends JpsElementProperties> JpsLibrary createLibrary(@NotNull String name, @NotNull JpsLibraryType<P> type, @NotNull P properties);
|
||||
|
||||
@@ -4,4 +4,5 @@ package org.jetbrains.jps.model.java;
|
||||
* @author nik
|
||||
*/
|
||||
public enum LanguageLevel {
|
||||
JDK_1_3, JDK_1_4, JDK_1_5, JDK_1_6, JDK_1_7, JDK_1_8
|
||||
}
|
||||
|
||||
@@ -19,6 +19,19 @@ import org.jetbrains.jps.model.module.impl.JpsModuleReferenceImpl;
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsElementFactoryImpl extends JpsElementFactory {
|
||||
@Override
|
||||
public JpsModel createModel() {
|
||||
return new JpsModelImpl(new JpsEventDispatcherBase() {
|
||||
@Override
|
||||
public void fireElementRenamed(@NotNull JpsNamedElement element, @NotNull String oldName, @NotNull String newName) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireElementChanged(@NotNull JpsElement element) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <P extends JpsElementProperties> JpsModule createModule(@NotNull String name, @NotNull JpsModuleType<P> type, @NotNull P properties) {
|
||||
return new JpsModuleImpl(type, name, properties);
|
||||
|
||||
@@ -2,10 +2,7 @@ package org.jetbrains.jps.service.impl;
|
||||
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -13,7 +10,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class JpsServiceManagerImpl extends JpsServiceManager {
|
||||
private final ConcurrentHashMap<Class, Object> myServices = new ConcurrentHashMap<Class, Object>();
|
||||
private final ConcurrentHashMap<Class, List<Object>> myExtensions = new ConcurrentHashMap<Class, List<Object>>();
|
||||
private final ConcurrentHashMap<Class, List<?>> myExtensions = new ConcurrentHashMap<Class, List<?>>();
|
||||
|
||||
@Override
|
||||
public <T> T getService(Class<T> serviceClass) {
|
||||
@@ -30,12 +27,25 @@ public class JpsServiceManagerImpl extends JpsServiceManager {
|
||||
"More than one implementation for " + serviceClass + " found: " + service.getClass() + " and " + iterator.next().getClass());
|
||||
}
|
||||
myServices.putIfAbsent(serviceClass, service);
|
||||
//noinspection unchecked
|
||||
service = (T)myServices.get(serviceClass);
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> getExtensions(Class<T> extensionClass) {
|
||||
return ServiceLoader.load(extensionClass);
|
||||
List<?> cached = myExtensions.get(extensionClass);
|
||||
if (cached == null) {
|
||||
final ServiceLoader<T> loader = ServiceLoader.load(extensionClass);
|
||||
List<T> extensions = new ArrayList<T>();
|
||||
for (T t : loader) {
|
||||
extensions.add(t);
|
||||
}
|
||||
myExtensions.putIfAbsent(extensionClass, extensions);
|
||||
cached = myExtensions.get(extensionClass);
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (List<T>)cached;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -43,11 +43,12 @@ public class JpsLibraryTableLoader {
|
||||
MultiMap<JpsOrderRootType, String> recursiveJarDirectories = new MultiMap<JpsOrderRootType, String>();
|
||||
for (Element jarDirectory : JDOMUtil.getChildren(libraryElement, "jarDirectory")) {
|
||||
String url = jarDirectory.getAttributeValue("url");
|
||||
String rootType = jarDirectory.getAttributeValue("type");
|
||||
String rootTypeId = jarDirectory.getAttributeValue("type");
|
||||
final JpsOrderRootType rootType = rootTypeId != null ? getRootType(rootTypeId) : JpsOrderRootType.COMPILED;
|
||||
boolean recursive = Boolean.parseBoolean(jarDirectory.getAttributeValue("recursive"));
|
||||
jarDirectories.putValue(getRootType(rootType), url);
|
||||
jarDirectories.putValue(rootType, url);
|
||||
if (recursive) {
|
||||
recursiveJarDirectories.putValue(getRootType(rootType), url);
|
||||
recursiveJarDirectories.putValue(rootType, url);
|
||||
}
|
||||
}
|
||||
for (Element rootsElement : JDOMUtil.getChildren(libraryElement)) {
|
||||
|
||||
+7
-3
@@ -21,9 +21,13 @@ public abstract class JpsLoaderBase {
|
||||
}
|
||||
|
||||
protected Element loadRootElement(final File file) {
|
||||
return loadRootElement(file, myMacroExpander);
|
||||
}
|
||||
|
||||
protected static Element loadRootElement(final File file, final JpsMacroExpander macroExpander) {
|
||||
try {
|
||||
final Element element = JDOMUtil.loadDocument(file).getRootElement();
|
||||
myMacroExpander.substitute(element, SystemInfo.isFileSystemCaseSensitive);
|
||||
macroExpander.substitute(element, SystemInfo.isFileSystemCaseSensitive);
|
||||
return element;
|
||||
}
|
||||
catch (JDOMException e) {
|
||||
@@ -35,11 +39,11 @@ public abstract class JpsLoaderBase {
|
||||
}
|
||||
|
||||
protected static boolean isXmlFile(File file) {
|
||||
return file.isFile() && FileUtil.getNameWithoutExtension(file).equalsIgnoreCase("xml");
|
||||
return file.isFile() && FileUtil.getExtension(file.getName()).equalsIgnoreCase("xml");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Element findComponent(Element root, String componentName) {
|
||||
protected static Element findComponent(Element root, String componentName) {
|
||||
for (Element element : JDOMUtil.getChildren(root, "component")) {
|
||||
if (componentName.equals(element.getAttributeValue("name"))) {
|
||||
return element;
|
||||
|
||||
+3
-1
@@ -5,7 +5,9 @@ import org.jdom.Element;
|
||||
import org.jetbrains.jps.model.JpsCompositeElement;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.JpsElementReference;
|
||||
import org.jetbrains.jps.model.java.*;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootProperties;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkType;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsSdkType;
|
||||
import org.jetbrains.jps.model.module.*;
|
||||
|
||||
+27
-3
@@ -16,17 +16,26 @@ import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsProjectLoader extends JpsLoaderBase {
|
||||
private static final ExecutorService ourThreadPool = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors());
|
||||
private final JpsProject myProject;
|
||||
private final Map<String, String> myPathVariables;
|
||||
|
||||
public JpsProjectLoader(JpsProject project, Map<String, String> pathVariables, File baseDir) {
|
||||
super(createMacroExpander(pathVariables, baseDir));
|
||||
myProject = project;
|
||||
myPathVariables = pathVariables;
|
||||
}
|
||||
|
||||
private static JpsMacroExpander createMacroExpander(Map<String, String> pathVariables, File baseDir) {
|
||||
@@ -95,17 +104,32 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
Element componentRoot = findComponent(root, "ProjectModuleManager");
|
||||
if (componentRoot == null) return;
|
||||
final Element modules = componentRoot.getChild("modules");
|
||||
List<Future<JpsModule>> futures = new ArrayList<Future<JpsModule>>();
|
||||
for (Element moduleElement : JDOMUtil.getChildren(modules, "module")) {
|
||||
final String path = moduleElement.getAttributeValue("filepath");
|
||||
JpsModule module = loadModule(path);
|
||||
myProject.addModule(module);
|
||||
futures.add(ourThreadPool.submit(new Callable<JpsModule>() {
|
||||
@Override
|
||||
public JpsModule call() throws Exception {
|
||||
return loadModule(path);
|
||||
}
|
||||
}));
|
||||
}
|
||||
try {
|
||||
for (Future<JpsModule> future : futures) {
|
||||
myProject.addModule(future.get());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private JpsModule loadModule(String path) {
|
||||
final File file = new File(path);
|
||||
String name = FileUtil.getNameWithoutExtension(file);
|
||||
final Element moduleRoot = loadRootElement(file);
|
||||
final JpsMacroExpander expander = new JpsMacroExpander(myPathVariables);
|
||||
expander.addFileHierarchyReplacements("MODULE_DIR", file.getParentFile());
|
||||
final Element moduleRoot = loadRootElement(file, expander);
|
||||
final String typeId = moduleRoot.getAttributeValue("type");
|
||||
final JpsModuleType<?> moduleType = getModuleType(typeId);
|
||||
final JpsModule module = createModule(name, moduleRoot, moduleType);
|
||||
|
||||
Reference in New Issue
Block a user