mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new project model: saving to xml
This commit is contained in:
@@ -38,8 +38,8 @@ import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
import org.jetbrains.jps.model.library.JpsSdkProperties;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.serialization.JpsProjectLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkPropertiesLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkTableLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkPropertiesSerializer;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkTableSerializer;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@@ -536,7 +536,7 @@ final class BuildSession implements Runnable, CanceledStatus {
|
||||
JpsLibrary jpsLibrary = null;
|
||||
if (library instanceof SdkLibrary) {
|
||||
final SdkLibrary sdkLibrary = (SdkLibrary)library;
|
||||
final JpsSdkPropertiesLoader<?> loader = JpsSdkTableLoader.getSdkPropertiesLoader(sdkLibrary.getTypeName());
|
||||
final JpsSdkPropertiesSerializer<?> loader = JpsSdkTableSerializer.getSdkPropertiesSerializer(sdkLibrary.getTypeName());
|
||||
if (loader != null) {
|
||||
jpsLibrary = addLibrary(model, sdkLibrary, loader);
|
||||
}
|
||||
@@ -567,7 +567,7 @@ final class BuildSession implements Runnable, CanceledStatus {
|
||||
}
|
||||
}
|
||||
|
||||
private static <P extends JpsSdkProperties> JpsLibrary addLibrary(JpsModel model, SdkLibrary sdkLibrary, JpsSdkPropertiesLoader<P> loader) {
|
||||
private static <P extends JpsSdkProperties> JpsLibrary addLibrary(JpsModel model, SdkLibrary sdkLibrary, JpsSdkPropertiesSerializer<P> loader) {
|
||||
try {
|
||||
final String xml = sdkLibrary.getAdditionalDataXml();
|
||||
final Element element = xml != null ? JDOMUtil.loadDocument(xml).getRootElement() : null;
|
||||
|
||||
@@ -33,10 +33,10 @@ public abstract class JpsJavaExtensionService {
|
||||
@NotNull
|
||||
public abstract JpsJavaProjectExtension getOrCreateProjectExtension(@NotNull JpsProject project);
|
||||
|
||||
|
||||
@Nullable
|
||||
public abstract JpsJavaProjectExtension getProjectExtension(@NotNull JpsProject project);
|
||||
|
||||
|
||||
@NotNull
|
||||
public abstract JpsJavaModuleExtension getOrCreateModuleExtension(@NotNull JpsModule module);
|
||||
|
||||
@@ -49,6 +49,9 @@ public abstract class JpsJavaExtensionService {
|
||||
@Nullable
|
||||
public abstract JpsJavaDependencyExtension getDependencyExtension(@NotNull JpsDependencyElement dependency);
|
||||
|
||||
@Nullable
|
||||
public abstract ExplodedDirectoryModuleExtension getExplodedDirectoryExtension(@NotNull JpsModule module);
|
||||
|
||||
@NotNull
|
||||
public abstract ExplodedDirectoryModuleExtension getOrCreateExplodedDirectoryExtension(@NotNull JpsModule module);
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ import org.jetbrains.jps.model.JpsElementProperties;
|
||||
* @author nik
|
||||
*/
|
||||
public interface JpsTypedLibrary<P extends JpsElementProperties> extends JpsLibrary {
|
||||
@NotNull
|
||||
@Override
|
||||
JpsLibraryType<P> getType();
|
||||
|
||||
@NotNull
|
||||
P getProperties();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.jps.model.JpsElementChildRole;
|
||||
public class JpsElementChildRoleBase<E extends JpsElement> extends JpsElementChildRole<E> {
|
||||
private String myDebugName;
|
||||
|
||||
protected JpsElementChildRoleBase(String debugName) {
|
||||
public JpsElementChildRoleBase(String debugName) {
|
||||
myDebugName = debugName;
|
||||
}
|
||||
|
||||
|
||||
+15
-2
@@ -2,6 +2,7 @@ package org.jetbrains.jps.model.java.impl;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsElementCreator;
|
||||
import org.jetbrains.jps.model.impl.JpsElementBase;
|
||||
import org.jetbrains.jps.model.impl.JpsElementChildRoleBase;
|
||||
import org.jetbrains.jps.model.java.ExplodedDirectoryModuleExtension;
|
||||
@@ -11,8 +12,6 @@ import org.jetbrains.jps.model.java.ExplodedDirectoryModuleExtension;
|
||||
*/
|
||||
public class ExplodedDirectoryModuleExtensionImpl extends JpsElementBase<ExplodedDirectoryModuleExtensionImpl> implements
|
||||
ExplodedDirectoryModuleExtension {
|
||||
public static final JpsElementChildRoleBase<ExplodedDirectoryModuleExtension> ROLE = JpsElementChildRoleBase.create("exploded directory");
|
||||
|
||||
private String myExplodedUrl;
|
||||
private boolean myExcludeExploded;
|
||||
|
||||
@@ -61,4 +60,18 @@ public class ExplodedDirectoryModuleExtensionImpl extends JpsElementBase<Explode
|
||||
setExcludeExploded(modified.myExcludeExploded);
|
||||
setExplodedUrl(modified.myExplodedUrl);
|
||||
}
|
||||
|
||||
public static class ExplodedDirectoryModuleExtensionRole extends JpsElementChildRoleBase<ExplodedDirectoryModuleExtension> implements JpsElementCreator<ExplodedDirectoryModuleExtension> {
|
||||
public static final ExplodedDirectoryModuleExtensionRole INSTANCE = new ExplodedDirectoryModuleExtensionRole();
|
||||
|
||||
public ExplodedDirectoryModuleExtensionRole() {
|
||||
super("exploded directory");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ExplodedDirectoryModuleExtension create() {
|
||||
return new ExplodedDirectoryModuleExtensionImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -56,11 +56,13 @@ public class JpsJavaExtensionServiceImpl extends JpsJavaExtensionService {
|
||||
@Override
|
||||
@NotNull
|
||||
public ExplodedDirectoryModuleExtension getOrCreateExplodedDirectoryExtension(@NotNull JpsModule module) {
|
||||
ExplodedDirectoryModuleExtension extension = module.getContainer().getChild(ExplodedDirectoryModuleExtensionImpl.ROLE);
|
||||
if (extension == null) {
|
||||
extension = module.getContainer().setChild(ExplodedDirectoryModuleExtensionImpl.ROLE, new ExplodedDirectoryModuleExtensionImpl());
|
||||
}
|
||||
return extension;
|
||||
return module.getContainer().getOrSetChild(ExplodedDirectoryModuleExtensionImpl.ExplodedDirectoryModuleExtensionRole.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ExplodedDirectoryModuleExtension getExplodedDirectoryExtension(@NotNull JpsModule module) {
|
||||
return module.getContainer().getChild(ExplodedDirectoryModuleExtensionImpl.ExplodedDirectoryModuleExtensionRole.INSTANCE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -30,8 +30,8 @@ public class JpsLibraryImpl<P extends JpsElementProperties> extends JpsNamedComp
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JpsLibraryType<?> getType() {
|
||||
return myContainer.getChild(TYPED_DATA_ROLE).getType();
|
||||
public JpsLibraryType<P> getType() {
|
||||
return (JpsLibraryType<P>)myContainer.getChild(TYPED_DATA_ROLE).getType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
org.jetbrains.jps.model.serialization.java.JpsJavaModelLoaderExtension
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension
|
||||
+2
-2
@@ -6,11 +6,11 @@ import org.jetbrains.jps.model.JpsElementType;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsElementPropertiesLoader<P extends JpsElementProperties, Type extends JpsElementType<P>> {
|
||||
public abstract class JpsElementPropertiesSerializer<P extends JpsElementProperties, Type extends JpsElementType<P>> {
|
||||
private final String myTypeId;
|
||||
private final Type myType;
|
||||
|
||||
public JpsElementPropertiesLoader(Type type, String typeId) {
|
||||
public JpsElementPropertiesSerializer(Type type, String typeId) {
|
||||
myType = type;
|
||||
myTypeId = typeId;
|
||||
}
|
||||
+2
-2
@@ -32,11 +32,11 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
|
||||
private void loadSdks(File optionsDir) {
|
||||
final Element root = loadRootElement(new File(optionsDir, "jdk.table.xml"));
|
||||
JpsSdkTableLoader.loadSdks(findComponent(root, "ProjectJdkTable"), myGlobal.getLibraryCollection());
|
||||
JpsSdkTableSerializer.loadSdks(findComponent(root, "ProjectJdkTable"), myGlobal.getLibraryCollection());
|
||||
}
|
||||
|
||||
private void loadGlobalLibraries(File optionsDir) {
|
||||
final Element root = loadRootElement(new File(optionsDir, "applicationLibraries.xml"));
|
||||
JpsLibraryTableLoader.loadLibraries(findComponent(root, "libraryTable"), myGlobal.getLibraryCollection());
|
||||
JpsLibraryTableSerializer.loadLibraries(findComponent(root, "libraryTable"), myGlobal.getLibraryCollection());
|
||||
}
|
||||
}
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElementProperties;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsLibraryPropertiesLoader<P extends JpsElementProperties> extends JpsElementPropertiesLoader<P, JpsLibraryType<P>> {
|
||||
public JpsLibraryPropertiesLoader(JpsLibraryType<P> type, String typeId) {
|
||||
super(type, typeId);
|
||||
}
|
||||
|
||||
public abstract P loadProperties(@Nullable Element propertiesElement);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElementProperties;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryType;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsLibraryPropertiesSerializer<P extends JpsElementProperties> extends
|
||||
JpsElementPropertiesSerializer<P, JpsLibraryType<P>> {
|
||||
public JpsLibraryPropertiesSerializer(JpsLibraryType<P> type, String typeId) {
|
||||
super(type, typeId);
|
||||
}
|
||||
|
||||
public abstract P loadProperties(@Nullable Element propertiesElement);
|
||||
|
||||
public abstract void saveProperties(P properties, Element element);
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryRootTypeSerializer implements Comparable<JpsLibraryRootTypeSerializer> {
|
||||
private String myTypeId;
|
||||
private JpsOrderRootType myType;
|
||||
private boolean myWriteIfEmpty;
|
||||
|
||||
public JpsLibraryRootTypeSerializer(@NotNull String typeId, @NotNull JpsOrderRootType type, boolean writeIfEmpty) {
|
||||
myTypeId = typeId;
|
||||
myType = type;
|
||||
myWriteIfEmpty = writeIfEmpty;
|
||||
}
|
||||
|
||||
public boolean isWriteIfEmpty() {
|
||||
return myWriteIfEmpty;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return myTypeId;
|
||||
}
|
||||
|
||||
public JpsOrderRootType getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(JpsLibraryRootTypeSerializer o) {
|
||||
return myTypeId.compareTo(o.myTypeId);
|
||||
}
|
||||
}
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.DummyJpsElementProperties;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.JpsElementProperties;
|
||||
import org.jetbrains.jps.model.java.JpsJavaLibraryType;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryTableLoader {
|
||||
private static final Map<String, JpsOrderRootType> PREDEFINED_ROOT_TYPES = new HashMap<String, JpsOrderRootType>();
|
||||
|
||||
static {
|
||||
PREDEFINED_ROOT_TYPES.put("CLASSES", JpsOrderRootType.COMPILED);
|
||||
PREDEFINED_ROOT_TYPES.put("SOURCES", JpsOrderRootType.SOURCES);
|
||||
}
|
||||
|
||||
public static void loadLibraries(Element libraryTableElement, JpsLibraryCollection result) {
|
||||
for (Element libraryElement : JDOMUtil.getChildren(libraryTableElement, "library")) {
|
||||
result.addLibrary(loadLibrary(libraryElement));
|
||||
}
|
||||
}
|
||||
|
||||
public static JpsLibrary loadLibrary(Element libraryElement) {
|
||||
return loadLibrary(libraryElement, libraryElement.getAttributeValue("name"));
|
||||
}
|
||||
|
||||
public static JpsLibrary loadLibrary(Element libraryElement, String name) {
|
||||
String typeId = libraryElement.getAttributeValue("type");
|
||||
final JpsLibraryPropertiesLoader<?> loader = getLibraryPropertiesLoader(typeId);
|
||||
JpsLibrary library = createLibrary(name, loader, libraryElement.getChild("properties"));
|
||||
|
||||
MultiMap<JpsOrderRootType, String> jarDirectories = new MultiMap<JpsOrderRootType, String>();
|
||||
MultiMap<JpsOrderRootType, String> recursiveJarDirectories = new MultiMap<JpsOrderRootType, String>();
|
||||
for (Element jarDirectory : JDOMUtil.getChildren(libraryElement, "jarDirectory")) {
|
||||
String url = jarDirectory.getAttributeValue("url");
|
||||
String rootTypeId = jarDirectory.getAttributeValue("type");
|
||||
final JpsOrderRootType rootType = rootTypeId != null ? getRootType(rootTypeId) : JpsOrderRootType.COMPILED;
|
||||
boolean recursive = Boolean.parseBoolean(jarDirectory.getAttributeValue("recursive"));
|
||||
jarDirectories.putValue(rootType, url);
|
||||
if (recursive) {
|
||||
recursiveJarDirectories.putValue(rootType, url);
|
||||
}
|
||||
}
|
||||
for (Element rootsElement : JDOMUtil.getChildren(libraryElement)) {
|
||||
final String rootTypeId = rootsElement.getName();
|
||||
if (!rootTypeId.equals("jarDirectory")) {
|
||||
final JpsOrderRootType rootType = getRootType(rootTypeId);
|
||||
for (Element rootElement : JDOMUtil.getChildren(rootsElement, "root")) {
|
||||
String url = rootElement.getAttributeValue("url");
|
||||
JpsLibraryRoot.InclusionOptions options;
|
||||
if (jarDirectories.get(rootType).contains(url)) {
|
||||
final boolean recursive = recursiveJarDirectories.get(rootType).contains(url);
|
||||
options = recursive ? JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY : JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT;
|
||||
}
|
||||
else {
|
||||
options = JpsLibraryRoot.InclusionOptions.ROOT_ITSELF;
|
||||
}
|
||||
library.addRoot(url, rootType, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
private static <P extends JpsElementProperties> JpsLibrary createLibrary(String name, JpsLibraryPropertiesLoader<P> loader,
|
||||
final Element propertiesElement) {
|
||||
return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), loader.loadProperties(propertiesElement));
|
||||
}
|
||||
|
||||
private static JpsOrderRootType getRootType(String rootTypeId) {
|
||||
final JpsOrderRootType type = PREDEFINED_ROOT_TYPES.get(rootTypeId);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
final JpsOrderRootType rootType = extension.getRootType(rootTypeId);
|
||||
if (rootType != null) {
|
||||
return rootType;
|
||||
}
|
||||
}
|
||||
return JpsOrderRootType.COMPILED;
|
||||
}
|
||||
|
||||
private static JpsLibraryPropertiesLoader<?> getLibraryPropertiesLoader(@Nullable String typeId) {
|
||||
if (typeId != null) {
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
for (JpsLibraryPropertiesLoader<?> loader : extension.getLibraryPropertiesLoaders()) {
|
||||
if (loader.getTypeId().equals(typeId)) {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new JpsLibraryPropertiesLoader<DummyJpsElementProperties>(JpsJavaLibraryType.INSTANCE, null) {
|
||||
@Override
|
||||
public DummyJpsElementProperties loadProperties(@Nullable Element propertiesElement) {
|
||||
return DummyJpsElementProperties.INSTANCE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.DummyJpsElementProperties;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.JpsElementProperties;
|
||||
import org.jetbrains.jps.model.java.JpsJavaLibraryType;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsLibraryTableSerializer {
|
||||
private static final JpsLibraryRootTypeSerializer[] PREDEFINED_ROOT_TYPES_SERIALIZERS = {
|
||||
new JpsLibraryRootTypeSerializer("CLASSES", JpsOrderRootType.COMPILED, true),
|
||||
new JpsLibraryRootTypeSerializer("SOURCES", JpsOrderRootType.SOURCES, true)
|
||||
};
|
||||
private static final String NAME_ATTRIBUTE = "name";
|
||||
private static final String TYPE_ATTRIBUTE = "type";
|
||||
private static final String PROPERTIES_TAG = "properties";
|
||||
private static final String JAR_DIRECTORY_TAG = "jarDirectory";
|
||||
private static final String URL_ATTRIBUTE = "url";
|
||||
private static final String ROOT_TAG = "root";
|
||||
private static final String RECURSIVE_ATTRIBUTE = "recursive";
|
||||
private static final String LIBRARY_TAG = "library";
|
||||
private static final JpsLibraryPropertiesSerializer<DummyJpsElementProperties> JAVA_LIBRARY_PROPERTIES_SERIALIZER =
|
||||
new JpsLibraryPropertiesSerializer<DummyJpsElementProperties>(JpsJavaLibraryType.INSTANCE, null) {
|
||||
@Override
|
||||
public DummyJpsElementProperties loadProperties(@Nullable Element propertiesElement) {
|
||||
return DummyJpsElementProperties.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProperties(DummyJpsElementProperties properties, Element element) {
|
||||
}
|
||||
};
|
||||
|
||||
public static void loadLibraries(Element libraryTableElement, JpsLibraryCollection result) {
|
||||
for (Element libraryElement : JDOMUtil.getChildren(libraryTableElement, LIBRARY_TAG)) {
|
||||
result.addLibrary(loadLibrary(libraryElement));
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveLibraries(JpsLibraryCollection libraryCollection, Element libraryTableElement) {
|
||||
List<JpsLibrary> libraries = new ArrayList<JpsLibrary>();
|
||||
for (JpsLibrary library : libraryCollection.getLibraries()) {
|
||||
if (!(library.getType() instanceof JpsSdkType<?>)) {
|
||||
libraries.add(library);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(libraries, new Comparator<JpsLibrary>() {
|
||||
@Override
|
||||
public int compare(JpsLibrary o1, JpsLibrary o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
for (JpsLibrary library : libraries) {
|
||||
Element libraryTag = new Element(LIBRARY_TAG);
|
||||
saveLibrary(library, libraryTag, library.getName());
|
||||
libraryTableElement.addContent(libraryTag);
|
||||
}
|
||||
}
|
||||
|
||||
public static JpsLibrary loadLibrary(Element libraryElement) {
|
||||
return loadLibrary(libraryElement, libraryElement.getAttributeValue(NAME_ATTRIBUTE));
|
||||
}
|
||||
|
||||
public static JpsLibrary loadLibrary(Element libraryElement, String name) {
|
||||
String typeId = libraryElement.getAttributeValue(TYPE_ATTRIBUTE);
|
||||
final JpsLibraryPropertiesSerializer<?> loader = getLibraryPropertiesSerializer(typeId);
|
||||
JpsLibrary library = createLibrary(name, loader, libraryElement.getChild(PROPERTIES_TAG));
|
||||
|
||||
MultiMap<JpsOrderRootType, String> jarDirectories = new MultiMap<JpsOrderRootType, String>();
|
||||
MultiMap<JpsOrderRootType, String> recursiveJarDirectories = new MultiMap<JpsOrderRootType, String>();
|
||||
for (Element jarDirectory : JDOMUtil.getChildren(libraryElement, JAR_DIRECTORY_TAG)) {
|
||||
String url = jarDirectory.getAttributeValue(URL_ATTRIBUTE);
|
||||
String rootTypeId = jarDirectory.getAttributeValue(TYPE_ATTRIBUTE);
|
||||
final JpsOrderRootType rootType = rootTypeId != null ? getRootType(rootTypeId) : JpsOrderRootType.COMPILED;
|
||||
boolean recursive = Boolean.parseBoolean(jarDirectory.getAttributeValue(RECURSIVE_ATTRIBUTE));
|
||||
jarDirectories.putValue(rootType, url);
|
||||
if (recursive) {
|
||||
recursiveJarDirectories.putValue(rootType, url);
|
||||
}
|
||||
}
|
||||
for (Element rootsElement : JDOMUtil.getChildren(libraryElement)) {
|
||||
final String rootTypeId = rootsElement.getName();
|
||||
if (!rootTypeId.equals(JAR_DIRECTORY_TAG)) {
|
||||
final JpsOrderRootType rootType = getRootType(rootTypeId);
|
||||
for (Element rootElement : JDOMUtil.getChildren(rootsElement, ROOT_TAG)) {
|
||||
String url = rootElement.getAttributeValue(URL_ATTRIBUTE);
|
||||
JpsLibraryRoot.InclusionOptions options;
|
||||
if (jarDirectories.get(rootType).contains(url)) {
|
||||
final boolean recursive = recursiveJarDirectories.get(rootType).contains(url);
|
||||
options = recursive ? JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY : JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT;
|
||||
}
|
||||
else {
|
||||
options = JpsLibraryRoot.InclusionOptions.ROOT_ITSELF;
|
||||
}
|
||||
library.addRoot(url, rootType, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
public static void saveLibrary(JpsLibrary library, Element libraryElement, final String libraryName) {
|
||||
if (libraryName != null) {
|
||||
libraryElement.setAttribute(NAME_ATTRIBUTE, libraryName);
|
||||
}
|
||||
saveProperties((JpsTypedLibrary<? extends JpsElementProperties>)library, libraryElement);
|
||||
List<Element> jarDirectoryElements = new ArrayList<Element>();
|
||||
for (JpsLibraryRootTypeSerializer serializer : getSortedSerializers()) {
|
||||
List<JpsLibraryRoot> roots = library.getRoots(serializer.getType());
|
||||
if (roots.isEmpty() && !serializer.isWriteIfEmpty()) continue;
|
||||
|
||||
Element typeElement = new Element(serializer.getTypeId());
|
||||
for (JpsLibraryRoot root : roots) {
|
||||
typeElement.addContent(new Element(ROOT_TAG).setAttribute(URL_ATTRIBUTE, root.getUrl()));
|
||||
if (root.getInclusionOptions() != JpsLibraryRoot.InclusionOptions.ROOT_ITSELF) {
|
||||
Element jarDirectoryElement = new Element(JAR_DIRECTORY_TAG).setAttribute(URL_ATTRIBUTE, root.getUrl());
|
||||
boolean recursive = root.getInclusionOptions() == JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY;
|
||||
jarDirectoryElement.setAttribute(RECURSIVE_ATTRIBUTE, Boolean.toString(recursive));
|
||||
if (!serializer.getType().equals(JpsOrderRootType.COMPILED)) {
|
||||
jarDirectoryElement.setAttribute(TYPE_ATTRIBUTE, serializer.getTypeId());
|
||||
}
|
||||
jarDirectoryElements.add(jarDirectoryElement);
|
||||
}
|
||||
}
|
||||
libraryElement.addContent(typeElement);
|
||||
}
|
||||
libraryElement.addContent(jarDirectoryElements);
|
||||
}
|
||||
|
||||
private static <P extends JpsElementProperties> void saveProperties(JpsTypedLibrary<P> library, Element libraryElement) {
|
||||
JpsLibraryType<P> type = library.getType();
|
||||
if (!type.equals(JpsJavaLibraryType.INSTANCE)) {
|
||||
JpsLibraryPropertiesSerializer<P> serializer = getLibraryPropertiesSerializer(type);
|
||||
libraryElement.setAttribute(TYPE_ATTRIBUTE, serializer.getTypeId());
|
||||
Element element = new Element(PROPERTIES_TAG);
|
||||
serializer.saveProperties(library.getProperties(), element);
|
||||
if (!element.getContent().isEmpty() || !element.getAttributes().isEmpty()) {
|
||||
libraryElement.addContent(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <P extends JpsElementProperties> JpsLibrary createLibrary(String name, JpsLibraryPropertiesSerializer<P> loader,
|
||||
final Element propertiesElement) {
|
||||
return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), loader.loadProperties(propertiesElement));
|
||||
}
|
||||
|
||||
private static JpsOrderRootType getRootType(String rootTypeId) {
|
||||
for (JpsLibraryRootTypeSerializer serializer : PREDEFINED_ROOT_TYPES_SERIALIZERS) {
|
||||
if (serializer.getTypeId().equals(rootTypeId)) {
|
||||
return serializer.getType();
|
||||
}
|
||||
}
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsLibraryRootTypeSerializer serializer : extension.getLibraryRootTypeSerializers()) {
|
||||
if (serializer.getTypeId().equals(rootTypeId)) {
|
||||
return serializer.getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
return JpsOrderRootType.COMPILED;
|
||||
}
|
||||
|
||||
private static Collection<JpsLibraryRootTypeSerializer> getSortedSerializers() {
|
||||
List<JpsLibraryRootTypeSerializer> serializers = new ArrayList<JpsLibraryRootTypeSerializer>();
|
||||
Collections.addAll(serializers, PREDEFINED_ROOT_TYPES_SERIALIZERS);
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
serializers.addAll(extension.getLibraryRootTypeSerializers());
|
||||
}
|
||||
Collections.sort(serializers);
|
||||
return serializers;
|
||||
}
|
||||
|
||||
private static JpsLibraryPropertiesSerializer<?> getLibraryPropertiesSerializer(@Nullable String typeId) {
|
||||
if (typeId != null) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsLibraryPropertiesSerializer<?> loader : extension.getLibraryPropertiesLoaders()) {
|
||||
if (loader.getTypeId().equals(typeId)) {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return JAVA_LIBRARY_PROPERTIES_SERIALIZER;
|
||||
}
|
||||
|
||||
private static <P extends JpsElementProperties> JpsLibraryPropertiesSerializer<P> getLibraryPropertiesSerializer(@NotNull JpsLibraryType<P> type) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsLibraryPropertiesSerializer<?> loader : extension.getLibraryPropertiesLoaders()) {
|
||||
if (loader.getType().equals(type)) {
|
||||
//noinspection unchecked
|
||||
return (JpsLibraryPropertiesSerializer<P>)loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("unknown type library:" + type);
|
||||
}
|
||||
}
|
||||
+28
-13
@@ -7,11 +7,11 @@ import org.jetbrains.jps.model.JpsCompositeElement;
|
||||
import org.jetbrains.jps.model.JpsElementReference;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.artifact.JpsArtifactType;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
import org.jetbrains.jps.model.module.JpsDependencyElement;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementLoader;
|
||||
import org.jetbrains.jps.model.serialization.facet.JpsModuleExtensionLoader;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -19,39 +19,59 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsModelLoaderExtension {
|
||||
public abstract class JpsModelSerializerExtension {
|
||||
public static Iterable<JpsModelSerializerExtension> getExtensions() {
|
||||
return JpsServiceManager.getInstance().getExtensions(JpsModelSerializerExtension.class);
|
||||
}
|
||||
|
||||
public void loadRootModel(@NotNull JpsModule module, @NotNull Element rootModel) {
|
||||
}
|
||||
|
||||
public void saveRootModel(@NotNull JpsModule module, @NotNull Element rootModel) {
|
||||
}
|
||||
|
||||
public void loadProjectRoots(JpsProject project, Element rootManagerElement) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JpsOrderRootType getRootType(@NotNull String typeId) {
|
||||
return null;
|
||||
public void saveProjectRoots(JpsProject project, Element rootManagerElement) {
|
||||
}
|
||||
|
||||
public List<JpsLibraryRootTypeSerializer> getLibraryRootTypeSerializers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JpsLibraryRootTypeSerializer> getSdkRootTypeSerializers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void loadModuleDependencyProperties(JpsDependencyElement dependency, Element orderEntry) {
|
||||
}
|
||||
|
||||
public void saveModuleDependencyProperties(JpsDependencyElement dependency, Element orderEntry) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JpsElementReference<? extends JpsCompositeElement> createLibraryTableReference(String tableLevel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLibraryTableLevelId(JpsElementReference<? extends JpsCompositeElement> reference) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends JpsModulePropertiesLoader<?>> getModulePropertiesLoaders() {
|
||||
public List<? extends JpsModulePropertiesSerializer<?>> getModulePropertiesSerializers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JpsLibraryPropertiesLoader<?>> getLibraryPropertiesLoaders() {
|
||||
public List<JpsLibraryPropertiesSerializer<?>> getLibraryPropertiesLoaders() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends JpsSdkPropertiesLoader<?>> getSdkPropertiesLoaders() {
|
||||
public List<? extends JpsSdkPropertiesSerializer<?>> getSdkPropertiesLoaders() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -63,11 +83,6 @@ public abstract class JpsModelLoaderExtension {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JpsOrderRootType getSdkRootType(@NotNull String typeId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JpsArtifactType getArtifactType(@NotNull String typeId) {
|
||||
return null;
|
||||
-116
@@ -1,116 +0,0 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
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.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.*;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import static com.intellij.openapi.util.JDOMUtil.getChildren;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsModuleLoader {
|
||||
private static final String URL_ATTRIBUTE = "url";
|
||||
|
||||
public static void loadRootModel(JpsModule module, Element rootModelComponent, JpsSdkType<?> projectSdkType) {
|
||||
for (Element contentElement : getChildren(rootModelComponent, "content")) {
|
||||
final String url = contentElement.getAttributeValue(URL_ATTRIBUTE);
|
||||
module.getContentRootsList().addUrl(url);
|
||||
for (Element sourceElement : getChildren(contentElement, "sourceFolder")) {
|
||||
final String sourceUrl = sourceElement.getAttributeValue(URL_ATTRIBUTE);
|
||||
final String packagePrefix = StringUtil.notNullize(sourceElement.getAttributeValue("packagePrefix"));
|
||||
final boolean testSource = Boolean.parseBoolean(sourceElement.getAttributeValue("isTestSource"));
|
||||
final JavaSourceRootType rootType = testSource ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
|
||||
module.addSourceRoot(sourceUrl, rootType, new JavaSourceRootProperties(packagePrefix));
|
||||
}
|
||||
for (Element excludeElement : getChildren(contentElement, "excludeFolder")) {
|
||||
module.getExcludeRootsList().addUrl(excludeElement.getAttributeValue(URL_ATTRIBUTE));
|
||||
}
|
||||
}
|
||||
|
||||
final JpsDependenciesList dependenciesList = module.getDependenciesList();
|
||||
final JpsElementFactory elementFactory = JpsElementFactory.getInstance();
|
||||
int moduleLibraryNum = 0;
|
||||
for (Element orderEntry : getChildren(rootModelComponent, "orderEntry")) {
|
||||
String type = orderEntry.getAttributeValue("type");
|
||||
if ("sourceFolder".equals(type)) {
|
||||
dependenciesList.addModuleSourceDependency();
|
||||
}
|
||||
else if ("jdk".equals(type)) {
|
||||
String sdkName = orderEntry.getAttributeValue("jdkName");
|
||||
String sdkTypeId = orderEntry.getAttributeValue("jdkType");
|
||||
final JpsSdkType<?> sdkType = JpsSdkTableLoader.getSdkType(sdkTypeId);
|
||||
dependenciesList.addSdkDependency(sdkType);
|
||||
JpsSdkTableLoader.setSdkReference(module.getSdkReferencesTable(), sdkName, sdkType);
|
||||
}
|
||||
else if ("inheritedJdk".equals(type)) {
|
||||
dependenciesList.addSdkDependency(projectSdkType != null ? projectSdkType : JpsJavaSdkType.INSTANCE);
|
||||
}
|
||||
else if ("library".equals(type)) {
|
||||
String name = orderEntry.getAttributeValue("name");
|
||||
String level = orderEntry.getAttributeValue("level");
|
||||
final JpsLibraryDependency dependency =
|
||||
dependenciesList.addLibraryDependency(elementFactory.createLibraryReference(name, createLibraryTableReference(level)));
|
||||
loadModuleDependencyProperties(dependency, orderEntry);
|
||||
}
|
||||
else if ("module-library".equals(type)) {
|
||||
final Element moduleLibraryElement = orderEntry.getChild("library");
|
||||
String name = moduleLibraryElement.getAttributeValue("name");
|
||||
if (name == null) {
|
||||
name = "#" + (moduleLibraryNum++);
|
||||
}
|
||||
final JpsLibrary library = JpsLibraryTableLoader.loadLibrary(moduleLibraryElement, name);
|
||||
module.addModuleLibrary(library);
|
||||
|
||||
final JpsLibraryDependency dependency = dependenciesList.addLibraryDependency(library);
|
||||
loadModuleDependencyProperties(dependency, orderEntry);
|
||||
moduleLibraryNum++;
|
||||
}
|
||||
else if ("module".equals(type)) {
|
||||
String name = orderEntry.getAttributeValue("module-name");
|
||||
final JpsModuleDependency dependency = dependenciesList.addModuleDependency(elementFactory.createModuleReference(name));
|
||||
loadModuleDependencyProperties(dependency, orderEntry);
|
||||
}
|
||||
}
|
||||
|
||||
for (JpsModelLoaderExtension extension : getLoaderExtensions()) {
|
||||
extension.loadRootModel(module, rootModelComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadModuleDependencyProperties(JpsDependencyElement dependency, Element orderEntry) {
|
||||
for (JpsModelLoaderExtension extension : getLoaderExtensions()) {
|
||||
extension.loadModuleDependencyProperties(dependency, orderEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public static JpsElementReference<? extends JpsCompositeElement> createLibraryTableReference(String level) {
|
||||
JpsElementFactory elementFactory = JpsElementFactory.getInstance();
|
||||
if (level.equals("project")) {
|
||||
return elementFactory.createProjectReference();
|
||||
}
|
||||
if (level.equals("application")) {
|
||||
return elementFactory.createGlobalReference();
|
||||
}
|
||||
for (JpsModelLoaderExtension extension : getLoaderExtensions()) {
|
||||
final JpsElementReference<? extends JpsCompositeElement> reference = extension.createLibraryTableReference(level);
|
||||
if (reference != null) {
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private static Iterable<JpsModelLoaderExtension> getLoaderExtensions() {
|
||||
return JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -8,8 +8,9 @@ import org.jetbrains.jps.model.module.JpsModuleType;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsModulePropertiesLoader<P extends JpsElementProperties> extends JpsElementPropertiesLoader<P, JpsModuleType<P>> {
|
||||
protected JpsModulePropertiesLoader(JpsModuleType<P> type, String typeId) {
|
||||
public abstract class JpsModulePropertiesSerializer<P extends JpsElementProperties> extends
|
||||
JpsElementPropertiesSerializer<P, JpsModuleType<P>> {
|
||||
protected JpsModulePropertiesSerializer(JpsModuleType<P> type, String typeId) {
|
||||
super(type, typeId);
|
||||
}
|
||||
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.jps.model.*;
|
||||
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.JpsLibraryReference;
|
||||
import org.jetbrains.jps.model.library.JpsSdkType;
|
||||
import org.jetbrains.jps.model.module.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.util.JDOMUtil.getChildren;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsModuleSerializer {
|
||||
private static final String URL_ATTRIBUTE = "url";
|
||||
private static final String CONTENT_TAG = "content";
|
||||
private static final String SOURCE_FOLDER_TAG = "sourceFolder";
|
||||
private static final String PACKAGE_PREFIX_ATTRIBUTE = "packagePrefix";
|
||||
private static final String IS_TEST_SOURCE_ATTRIBUTE = "isTestSource";
|
||||
private static final String EXCLUDE_FOLDER_TAG = "excludeFolder";
|
||||
private static final String ORDER_ENTRY_TAG = "orderEntry";
|
||||
private static final String TYPE_ATTRIBUTE = "type";
|
||||
private static final String SOURCE_FOLDER_TYPE = "sourceFolder";
|
||||
private static final String JDK_TYPE = "jdk";
|
||||
private static final String JDK_NAME_ATTRIBUTE = "jdkName";
|
||||
private static final String JDK_TYPE_ATTRIBUTE = "jdkType";
|
||||
private static final String INHERITED_JDK_TYPE = "inheritedJdk";
|
||||
private static final String LIBRARY_TYPE = "library";
|
||||
private static final String NAME_ATTRIBUTE = "name";
|
||||
private static final String LEVEL_ATTRIBUTE = "level";
|
||||
private static final String LIBRARY_TAG = "library";
|
||||
private static final String MODULE_LIBRARY_TYPE = "module-library";
|
||||
private static final String MODULE_TYPE = "module";
|
||||
private static final String MODULE_NAME_ATTRIBUTE = "module-name";
|
||||
private static final String PROJECT_LEVEL = "project";
|
||||
private static final String APPLICATION_LEVEL = "application";
|
||||
private static final String GENERATED_LIBRARY_NAME_PREFIX = "#";
|
||||
|
||||
public static void loadRootModel(JpsModule module, Element rootModelComponent, JpsSdkType<?> projectSdkType) {
|
||||
for (Element contentElement : getChildren(rootModelComponent, CONTENT_TAG)) {
|
||||
final String url = contentElement.getAttributeValue(URL_ATTRIBUTE);
|
||||
module.getContentRootsList().addUrl(url);
|
||||
for (Element sourceElement : getChildren(contentElement, SOURCE_FOLDER_TAG)) {
|
||||
final String sourceUrl = sourceElement.getAttributeValue(URL_ATTRIBUTE);
|
||||
final String packagePrefix = StringUtil.notNullize(sourceElement.getAttributeValue(PACKAGE_PREFIX_ATTRIBUTE));
|
||||
final boolean testSource = Boolean.parseBoolean(sourceElement.getAttributeValue(IS_TEST_SOURCE_ATTRIBUTE));
|
||||
final JavaSourceRootType rootType = testSource ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
|
||||
module.addSourceRoot(sourceUrl, rootType, new JavaSourceRootProperties(packagePrefix));
|
||||
}
|
||||
for (Element excludeElement : getChildren(contentElement, EXCLUDE_FOLDER_TAG)) {
|
||||
module.getExcludeRootsList().addUrl(excludeElement.getAttributeValue(URL_ATTRIBUTE));
|
||||
}
|
||||
}
|
||||
|
||||
final JpsDependenciesList dependenciesList = module.getDependenciesList();
|
||||
final JpsElementFactory elementFactory = JpsElementFactory.getInstance();
|
||||
int moduleLibraryNum = 0;
|
||||
for (Element orderEntry : getChildren(rootModelComponent, ORDER_ENTRY_TAG)) {
|
||||
String type = orderEntry.getAttributeValue(TYPE_ATTRIBUTE);
|
||||
if (SOURCE_FOLDER_TYPE.equals(type)) {
|
||||
dependenciesList.addModuleSourceDependency();
|
||||
}
|
||||
else if (JDK_TYPE.equals(type)) {
|
||||
String sdkName = orderEntry.getAttributeValue(JDK_NAME_ATTRIBUTE);
|
||||
String sdkTypeId = orderEntry.getAttributeValue(JDK_TYPE_ATTRIBUTE);
|
||||
final JpsSdkType<?> sdkType = JpsSdkTableSerializer.getSdkType(sdkTypeId);
|
||||
dependenciesList.addSdkDependency(sdkType);
|
||||
JpsSdkTableSerializer.setSdkReference(module.getSdkReferencesTable(), sdkName, sdkType);
|
||||
}
|
||||
else if (INHERITED_JDK_TYPE.equals(type)) {
|
||||
dependenciesList.addSdkDependency(projectSdkType != null ? projectSdkType : JpsJavaSdkType.INSTANCE);
|
||||
}
|
||||
else if (LIBRARY_TYPE.equals(type)) {
|
||||
String name = orderEntry.getAttributeValue(NAME_ATTRIBUTE);
|
||||
String level = orderEntry.getAttributeValue(LEVEL_ATTRIBUTE);
|
||||
final JpsLibraryDependency dependency =
|
||||
dependenciesList.addLibraryDependency(elementFactory.createLibraryReference(name, createLibraryTableReference(level)));
|
||||
loadModuleDependencyProperties(dependency, orderEntry);
|
||||
}
|
||||
else if (MODULE_LIBRARY_TYPE.equals(type)) {
|
||||
final Element moduleLibraryElement = orderEntry.getChild(LIBRARY_TAG);
|
||||
String name = moduleLibraryElement.getAttributeValue(NAME_ATTRIBUTE);
|
||||
if (name == null) {
|
||||
name = GENERATED_LIBRARY_NAME_PREFIX + (moduleLibraryNum++);
|
||||
}
|
||||
final JpsLibrary library = JpsLibraryTableSerializer.loadLibrary(moduleLibraryElement, name);
|
||||
module.addModuleLibrary(library);
|
||||
|
||||
final JpsLibraryDependency dependency = dependenciesList.addLibraryDependency(library);
|
||||
loadModuleDependencyProperties(dependency, orderEntry);
|
||||
moduleLibraryNum++;
|
||||
}
|
||||
else if (MODULE_TYPE.equals(type)) {
|
||||
String name = orderEntry.getAttributeValue(MODULE_NAME_ATTRIBUTE);
|
||||
final JpsModuleDependency dependency = dependenciesList.addModuleDependency(elementFactory.createModuleReference(name));
|
||||
loadModuleDependencyProperties(dependency, orderEntry);
|
||||
}
|
||||
}
|
||||
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
extension.loadRootModel(module, rootModelComponent);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveRootModel(JpsModule module, Element rootModelElement) {
|
||||
List<JpsModuleSourceRoot> sourceRoots = module.getSourceRoots();
|
||||
List<String> excludedUrls = getSortedList(module.getExcludeRootsList().getUrls());
|
||||
for (String url : getSortedList(module.getContentRootsList().getUrls())) {
|
||||
Element contentElement = new Element(CONTENT_TAG);
|
||||
contentElement.setAttribute(URL_ATTRIBUTE, url);
|
||||
rootModelElement.addContent(contentElement);
|
||||
for (JpsModuleSourceRoot root : sourceRoots) {
|
||||
if (FileUtil.startsWith(root.getUrl(), url)) {
|
||||
Element sourceElement = new Element(SOURCE_FOLDER_TAG);
|
||||
sourceElement.setAttribute(URL_ATTRIBUTE, root.getUrl());
|
||||
sourceElement.setAttribute(IS_TEST_SOURCE_ATTRIBUTE, Boolean.toString(root.getRootType().equals(JavaSourceRootType.TEST_SOURCE)));
|
||||
JpsElementProperties properties = root.getProperties();
|
||||
if (properties instanceof JavaSourceRootProperties) {
|
||||
String packagePrefix = ((JavaSourceRootProperties)properties).getPackagePrefix();
|
||||
if (packagePrefix.length() > 0) {
|
||||
sourceElement.setAttribute(PACKAGE_PREFIX_ATTRIBUTE, packagePrefix);
|
||||
}
|
||||
}
|
||||
contentElement.addContent(sourceElement);
|
||||
}
|
||||
}
|
||||
for (String excludedUrl : excludedUrls) {
|
||||
if (FileUtil.startsWith(excludedUrl, url)) {
|
||||
Element element = new Element(EXCLUDE_FOLDER_TAG).setAttribute(URL_ATTRIBUTE, excludedUrl);
|
||||
contentElement.addContent(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (JpsDependencyElement dependency : module.getDependenciesList().getDependencies()) {
|
||||
if (dependency instanceof JpsModuleSourceDependency) {
|
||||
rootModelElement.addContent(createDependencyElement(SOURCE_FOLDER_TYPE).setAttribute("forTests", "false"));
|
||||
}
|
||||
else if (dependency instanceof JpsSdkDependency) {
|
||||
JpsSdkType<?> sdkType = ((JpsSdkDependency)dependency).getSdkType();
|
||||
JpsLibraryReference reference = module.getSdkReferencesTable().getSdkReference(sdkType);
|
||||
if (reference == null) {
|
||||
rootModelElement.addContent(createDependencyElement(INHERITED_JDK_TYPE));
|
||||
}
|
||||
else {
|
||||
Element element = createDependencyElement(JDK_TYPE);
|
||||
element.setAttribute(JDK_NAME_ATTRIBUTE, reference.getLibraryName());
|
||||
element.setAttribute(JDK_TYPE_ATTRIBUTE, JpsSdkTableSerializer.getLoader(sdkType).getTypeId());
|
||||
rootModelElement.addContent(element);
|
||||
}
|
||||
}
|
||||
else if (dependency instanceof JpsLibraryDependency) {
|
||||
JpsLibraryReference reference = ((JpsLibraryDependency)dependency).getLibraryReference();
|
||||
JpsElementReference<? extends JpsCompositeElement> parentReference = reference.getParentReference();
|
||||
Element element;
|
||||
if (parentReference instanceof JpsModuleReference) {
|
||||
element = createDependencyElement(MODULE_LIBRARY_TYPE);
|
||||
saveModuleDependencyProperties(dependency, element);
|
||||
Element libraryElement = new Element(LIBRARY_TAG);
|
||||
JpsLibrary library = reference.resolve();
|
||||
String libraryName = library.getName();
|
||||
JpsLibraryTableSerializer
|
||||
.saveLibrary(library, libraryElement, libraryName.startsWith(GENERATED_LIBRARY_NAME_PREFIX) ? null : libraryName);
|
||||
element.addContent(libraryElement);
|
||||
}
|
||||
else {
|
||||
element = createDependencyElement(LIBRARY_TYPE);
|
||||
saveModuleDependencyProperties(dependency, element);
|
||||
element.setAttribute(NAME_ATTRIBUTE, reference.getLibraryName());
|
||||
element.setAttribute(LEVEL_ATTRIBUTE, getLevelId(parentReference));
|
||||
}
|
||||
rootModelElement.addContent(element);
|
||||
}
|
||||
else if (dependency instanceof JpsModuleDependency) {
|
||||
Element element = createDependencyElement(MODULE_TYPE);
|
||||
element.setAttribute(MODULE_NAME_ATTRIBUTE, ((JpsModuleDependency)dependency).getModuleReference().getModuleName());
|
||||
saveModuleDependencyProperties(dependency, element);
|
||||
rootModelElement.addContent(element);
|
||||
}
|
||||
}
|
||||
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
extension.saveRootModel(module, rootModelElement);
|
||||
}
|
||||
}
|
||||
|
||||
private static Element createDependencyElement(final String type) {
|
||||
return new Element(ORDER_ENTRY_TAG).setAttribute(TYPE_ATTRIBUTE, type);
|
||||
}
|
||||
|
||||
private static List<String> getSortedList(final List<String> list) {
|
||||
List<String> strings = new ArrayList<String>(list);
|
||||
Collections.sort(strings);
|
||||
return strings;
|
||||
}
|
||||
|
||||
private static void loadModuleDependencyProperties(JpsDependencyElement dependency, Element orderEntry) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
extension.loadModuleDependencyProperties(dependency, orderEntry);
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveModuleDependencyProperties(JpsDependencyElement dependency, Element orderEntry) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
extension.saveModuleDependencyProperties(dependency, orderEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public static JpsElementReference<? extends JpsCompositeElement> createLibraryTableReference(String level) {
|
||||
JpsElementFactory elementFactory = JpsElementFactory.getInstance();
|
||||
if (level.equals(PROJECT_LEVEL)) {
|
||||
return elementFactory.createProjectReference();
|
||||
}
|
||||
if (level.equals(APPLICATION_LEVEL)) {
|
||||
return elementFactory.createGlobalReference();
|
||||
}
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
final JpsElementReference<? extends JpsCompositeElement> reference = extension.createLibraryTableReference(level);
|
||||
if (reference != null) {
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private static String getLevelId(JpsElementReference<? extends JpsCompositeElement> reference) {
|
||||
JpsCompositeElement element = reference.resolve();
|
||||
if (element instanceof JpsProject) {
|
||||
return PROJECT_LEVEL;
|
||||
}
|
||||
else if (element instanceof JpsGlobal) {
|
||||
return APPLICATION_LEVEL;
|
||||
}
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
String levelId = extension.getLibraryTableLevelId(reference);
|
||||
if (levelId != null) {
|
||||
return levelId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+21
-17
@@ -15,7 +15,6 @@ import org.jetbrains.jps.model.library.JpsSdkType;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.serialization.artifact.JpsArtifactLoader;
|
||||
import org.jetbrains.jps.model.serialization.facet.JpsFacetLoader;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
@@ -32,17 +31,17 @@ import java.util.concurrent.Future;
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsProjectLoader extends JpsLoaderBase {
|
||||
private static final ExecutorService ourThreadPool = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors());
|
||||
private static final ExecutorService ourThreadPool = Executors.newFixedThreadPool(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));
|
||||
super(createProjectMacroExpander(pathVariables, baseDir));
|
||||
myProject = project;
|
||||
myPathVariables = pathVariables;
|
||||
}
|
||||
|
||||
private static JpsMacroExpander createMacroExpander(Map<String, String> pathVariables, File baseDir) {
|
||||
static JpsMacroExpander createProjectMacroExpander(Map<String, String> pathVariables, File baseDir) {
|
||||
final JpsMacroExpander expander = new JpsMacroExpander(pathVariables);
|
||||
expander.addFileHierarchyReplacements("PROJECT_DIR", baseDir);
|
||||
return expander;
|
||||
@@ -110,10 +109,10 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
String sdkName = rootManagerElement.getAttributeValue("project-jdk-name");
|
||||
String sdkTypeId = rootManagerElement.getAttributeValue("project-jdk-type");
|
||||
if (sdkName != null && sdkTypeId != null) {
|
||||
sdkType = JpsSdkTableLoader.getSdkType(sdkTypeId);
|
||||
JpsSdkTableLoader.setSdkReference(myProject.getSdkReferencesTable(), sdkName, sdkType);
|
||||
sdkType = JpsSdkTableSerializer.getSdkType(sdkTypeId);
|
||||
JpsSdkTableSerializer.setSdkReference(myProject.getSdkReferencesTable(), sdkName, sdkType);
|
||||
}
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
extension.loadProjectRoots(myProject, rootManagerElement);
|
||||
}
|
||||
}
|
||||
@@ -121,7 +120,7 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
private void loadProjectLibraries(Element libraryTableElement) {
|
||||
JpsLibraryTableLoader.loadLibraries(libraryTableElement, myProject.getLibraryCollection());
|
||||
JpsLibraryTableSerializer.loadLibraries(libraryTableElement, myProject.getLibraryCollection());
|
||||
}
|
||||
|
||||
private void loadModules(Element root, final JpsSdkType<?> projectSdkType) {
|
||||
@@ -151,30 +150,35 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
private JpsModule loadModule(String path, JpsSdkType<?> projectSdkType) {
|
||||
final File file = new File(path);
|
||||
String name = FileUtil.getNameWithoutExtension(file);
|
||||
final JpsMacroExpander expander = new JpsMacroExpander(myPathVariables);
|
||||
expander.addFileHierarchyReplacements("MODULE_DIR", file.getParentFile());
|
||||
final JpsMacroExpander expander = createModuleMacroExpander(myPathVariables, file);
|
||||
final Element moduleRoot = loadRootElement(file, expander);
|
||||
final String typeId = moduleRoot.getAttributeValue("type");
|
||||
final JpsModulePropertiesLoader<?> loader = getModulePropertiesLoader(typeId);
|
||||
final JpsModulePropertiesSerializer<?> loader = getModulePropertiesSerializer(typeId);
|
||||
final JpsModule module = createModule(name, moduleRoot, loader);
|
||||
JpsModuleLoader.loadRootModel(module, findComponent(moduleRoot, "NewModuleRootManager"), projectSdkType);
|
||||
JpsModuleSerializer.loadRootModel(module, findComponent(moduleRoot, "NewModuleRootManager"), projectSdkType);
|
||||
JpsFacetLoader.loadFacets(module, findComponent(moduleRoot, "FacetManager"), FileUtil.toSystemIndependentName(path));
|
||||
return module;
|
||||
}
|
||||
|
||||
private static <P extends JpsElementProperties> JpsModule createModule(String name, Element moduleRoot, JpsModulePropertiesLoader<P> loader) {
|
||||
static JpsMacroExpander createModuleMacroExpander(final Map<String, String> pathVariables, File moduleFile) {
|
||||
final JpsMacroExpander expander = new JpsMacroExpander(pathVariables);
|
||||
expander.addFileHierarchyReplacements("MODULE_DIR", moduleFile.getParentFile());
|
||||
return expander;
|
||||
}
|
||||
|
||||
private static <P extends JpsElementProperties> JpsModule createModule(String name, Element moduleRoot, JpsModulePropertiesSerializer<P> loader) {
|
||||
return JpsElementFactory.getInstance().createModule(name, loader.getType(), loader.loadProperties(moduleRoot));
|
||||
}
|
||||
|
||||
private static JpsModulePropertiesLoader<?> getModulePropertiesLoader(@NotNull String typeId) {
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
for (JpsModulePropertiesLoader<?> loader : extension.getModulePropertiesLoaders()) {
|
||||
private static JpsModulePropertiesSerializer<?> getModulePropertiesSerializer(@NotNull String typeId) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsModulePropertiesSerializer<?> loader : extension.getModulePropertiesSerializers()) {
|
||||
if (loader.getTypeId().equals(typeId)) {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new JpsModulePropertiesLoader<DummyJpsElementProperties>(JpsJavaModuleType.INSTANCE, "JAVA_MODULE") {
|
||||
return new JpsModulePropertiesSerializer<DummyJpsElementProperties>(JpsJavaModuleType.INSTANCE, "JAVA_MODULE") {
|
||||
@Override
|
||||
public DummyJpsElementProperties loadProperties(@Nullable Element moduleRootElement) {
|
||||
return DummyJpsElementProperties.INSTANCE;
|
||||
|
||||
+6
-2
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.library.JpsSdkProperties;
|
||||
import org.jetbrains.jps.model.library.JpsSdkType;
|
||||
@@ -8,11 +9,14 @@ import org.jetbrains.jps.model.library.JpsSdkType;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsSdkPropertiesLoader<P extends JpsSdkProperties> extends JpsElementPropertiesLoader<P, JpsSdkType<P>> {
|
||||
public abstract class JpsSdkPropertiesSerializer<P extends JpsSdkProperties> extends JpsElementPropertiesSerializer<P, JpsSdkType<P>> {
|
||||
|
||||
protected JpsSdkPropertiesLoader(String typeId, JpsSdkType<P> type) {
|
||||
protected JpsSdkPropertiesSerializer(String typeId, JpsSdkType<P> type) {
|
||||
super(type, typeId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract P loadProperties(String homePath, String version, @Nullable Element propertiesElement);
|
||||
|
||||
public abstract void saveProperties(@NotNull P properties, @NotNull Element element);
|
||||
}
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkType;
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkTypeWrapper;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
import org.jetbrains.jps.model.module.JpsSdkReferencesTable;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsSdkTableLoader {
|
||||
private static final Map<String, JpsOrderRootType> PREDEFINED_ROOT_TYPES = new HashMap<String, JpsOrderRootType>();
|
||||
|
||||
static {
|
||||
PREDEFINED_ROOT_TYPES.put("classPath", JpsOrderRootType.COMPILED);
|
||||
PREDEFINED_ROOT_TYPES.put("sourcePath", JpsOrderRootType.SOURCES);
|
||||
}
|
||||
|
||||
public static void loadSdks(@Nullable Element sdkListElement, JpsLibraryCollection result) {
|
||||
for (Element sdkElement : JDOMUtil.getChildren(sdkListElement, "jdk")) {
|
||||
result.addLibrary(loadSdk(sdkElement));
|
||||
}
|
||||
}
|
||||
|
||||
private static JpsLibrary loadSdk(Element sdkElement) {
|
||||
String name = getAttributeValue(sdkElement, "name");
|
||||
String typeId = getAttributeValue(sdkElement, "type");
|
||||
JpsSdkPropertiesLoader<?> loader = getSdkPropertiesLoader(typeId);
|
||||
final JpsLibrary library = createSdk(name, loader, sdkElement);
|
||||
final Element roots = sdkElement.getChild("roots");
|
||||
for (Element rootTypeElement : JDOMUtil.getChildren(roots)) {
|
||||
JpsOrderRootType rootType = getRootType(rootTypeElement.getName());
|
||||
if (rootType != null) {
|
||||
for (Element rootElement : JDOMUtil.getChildren(rootTypeElement)) {
|
||||
loadRoots(rootElement, library, rootType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
private static void loadRoots(Element rootElement, JpsLibrary library, JpsOrderRootType rootType) {
|
||||
final String type = rootElement.getAttributeValue("type");
|
||||
if (type.equals("composite")) {
|
||||
for (Element element : JDOMUtil.getChildren(rootElement)) {
|
||||
loadRoots(element, library, rootType);
|
||||
}
|
||||
}
|
||||
else if (type.equals("simple")) {
|
||||
library.addRoot(rootElement.getAttributeValue("url"), rootType);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JpsOrderRootType getRootType(String typeId) {
|
||||
final JpsOrderRootType rootType = PREDEFINED_ROOT_TYPES.get(typeId);
|
||||
if (rootType != null) {
|
||||
return rootType;
|
||||
}
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
final JpsOrderRootType type = extension.getSdkRootType(typeId);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <P extends JpsSdkProperties> JpsLibrary createSdk(String name, JpsSdkPropertiesLoader<P> loader, Element sdkElement) {
|
||||
String versionString = getAttributeValue(sdkElement, "version");
|
||||
String homePath = getAttributeValue(sdkElement, "homePath");
|
||||
return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), loader.loadProperties(homePath, versionString, sdkElement.getChild("additional")));
|
||||
}
|
||||
|
||||
public static JpsSdkPropertiesLoader<?> getSdkPropertiesLoader(String typeId) {
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
for (JpsSdkPropertiesLoader<?> loader : extension.getSdkPropertiesLoaders()) {
|
||||
if (loader.getTypeId().equals(typeId)) {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new JpsSdkPropertiesLoader<JpsSdkProperties>("JavaSDK", JpsJavaSdkType.INSTANCE) {
|
||||
@Override
|
||||
public JpsSdkProperties loadProperties(String homePath, String version, Element propertiesElement) {
|
||||
return new JpsSdkProperties(homePath, version);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getAttributeValue(Element element, String childName) {
|
||||
final Element child = element.getChild(childName);
|
||||
return child != null ? child.getAttributeValue("value") : null;
|
||||
}
|
||||
|
||||
public static JpsSdkType<?> getSdkType(String typeId) {
|
||||
return getSdkPropertiesLoader(typeId).getType();
|
||||
}
|
||||
|
||||
public static void setSdkReference(final JpsSdkReferencesTable table, String sdkName, JpsSdkType<?> sdkType) {
|
||||
JpsLibraryReference reference = JpsElementFactory.getInstance().createSdkReference(sdkName, sdkType);
|
||||
table.setSdkReference(sdkType, reference);
|
||||
if (sdkType instanceof JpsJavaSdkTypeWrapper) {
|
||||
JpsLibrary jpsLibrary = reference.resolve();
|
||||
if (jpsLibrary != null) {
|
||||
String name = ((JpsJavaSdkTypeWrapper)sdkType).getJavaSdkName((JpsSdkProperties)jpsLibrary.getProperties());
|
||||
if (name != null) {
|
||||
table.setSdkReference(JpsJavaSdkType.INSTANCE, JpsElementFactory.getInstance().createSdkReference(name, JpsJavaSdkType.INSTANCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkType;
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkTypeWrapper;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
import org.jetbrains.jps.model.module.JpsSdkReferencesTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsSdkTableSerializer {
|
||||
private static final JpsLibraryRootTypeSerializer[] PREDEFINED_ROOT_TYPE_SERIALIZERS = {
|
||||
new JpsLibraryRootTypeSerializer("classPath", JpsOrderRootType.COMPILED, true),
|
||||
new JpsLibraryRootTypeSerializer("sourcePath", JpsOrderRootType.SOURCES, true)
|
||||
};
|
||||
private static final JpsSdkPropertiesSerializer<JpsSdkProperties> JPS_JAVA_SDK_PROPERTIES_LOADER =
|
||||
new JpsSdkPropertiesSerializer<JpsSdkProperties>("JavaSDK", JpsJavaSdkType.INSTANCE) {
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsSdkProperties loadProperties(String homePath, String version, Element propertiesElement) {
|
||||
return new JpsSdkProperties(homePath, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProperties(@NotNull JpsSdkProperties properties, @NotNull Element element) {
|
||||
}
|
||||
};
|
||||
private static final String JDK_TAG = "jdk";
|
||||
private static final String NAME_TAG = "name";
|
||||
private static final String TYPE_TAG = "type";
|
||||
private static final String TYPE_ATTRIBUTE = "type";
|
||||
private static final String ROOTS_TAG = "roots";
|
||||
private static final String ROOT_TAG = "root";
|
||||
private static final String VERSION_TAG = "version";
|
||||
private static final String HOME_PATH_TAG = "homePath";
|
||||
private static final String VALUE_ATTRIBUTE = "value";
|
||||
private static final String COMPOSITE_TYPE = "composite";
|
||||
private static final String SIMPLE_TYPE = "simple";
|
||||
private static final String URL_ATTRIBUTE = "url";
|
||||
private static final String ADDITIONAL_TAG = "additional";
|
||||
|
||||
public static void loadSdks(@Nullable Element sdkListElement, JpsLibraryCollection result) {
|
||||
for (Element sdkElement : JDOMUtil.getChildren(sdkListElement, JDK_TAG)) {
|
||||
result.addLibrary(loadSdk(sdkElement));
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveSdks(JpsLibraryCollection libraryCollection, Element sdkListElement) {
|
||||
for (JpsLibrary library : libraryCollection.getLibraries()) {
|
||||
JpsLibraryType<?> type = library.getType();
|
||||
if (type instanceof JpsSdkType<?>) {
|
||||
Element sdkTag = new Element(JDK_TAG);
|
||||
//noinspection unchecked
|
||||
saveSdk((JpsTypedLibrary)library, (JpsSdkType)type, sdkTag);
|
||||
sdkListElement.addContent(sdkTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static JpsLibrary loadSdk(Element sdkElement) {
|
||||
String name = getAttributeValue(sdkElement, NAME_TAG);
|
||||
String typeId = getAttributeValue(sdkElement, TYPE_TAG);
|
||||
JpsSdkPropertiesSerializer<?> serializer = getSdkPropertiesSerializer(typeId);
|
||||
final JpsLibrary library = createSdk(name, serializer, sdkElement);
|
||||
final Element roots = sdkElement.getChild(ROOTS_TAG);
|
||||
for (Element rootTypeElement : JDOMUtil.getChildren(roots)) {
|
||||
JpsLibraryRootTypeSerializer rootTypeSerializer = getRootTypeSerializer(rootTypeElement.getName());
|
||||
if (rootTypeSerializer != null) {
|
||||
for (Element rootElement : JDOMUtil.getChildren(rootTypeElement)) {
|
||||
loadRoots(rootElement, library, rootTypeSerializer.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
private static <P extends JpsSdkProperties> void saveSdk(JpsTypedLibrary<P> library, JpsSdkType<P> type, Element sdkTag) {
|
||||
sdkTag.setAttribute("version", "2");
|
||||
setAttributeValue(sdkTag, NAME_TAG, library.getName());
|
||||
JpsSdkPropertiesSerializer<P> serializer = getSdkPropertiesSerializer(type);
|
||||
setAttributeValue(sdkTag, TYPE_TAG, serializer.getTypeId());
|
||||
P properties = library.getProperties();
|
||||
String versionString = properties.getVersionString();
|
||||
if (versionString != null) {
|
||||
setAttributeValue(sdkTag, VERSION_TAG, versionString);
|
||||
}
|
||||
setAttributeValue(sdkTag, HOME_PATH_TAG, properties.getHomePath());
|
||||
|
||||
Element rootsTag = new Element(ROOTS_TAG);
|
||||
for (JpsLibraryRootTypeSerializer rootTypeSerializer : getRootTypeSerializers()) {
|
||||
Element rootTypeTag = new Element(rootTypeSerializer.getTypeId());
|
||||
Element compositeTag = new Element(ROOT_TAG);
|
||||
compositeTag.setAttribute(TYPE_ATTRIBUTE, COMPOSITE_TYPE);
|
||||
List<JpsLibraryRoot> roots = library.getRoots(rootTypeSerializer.getType());
|
||||
for (JpsLibraryRoot root : roots) {
|
||||
compositeTag.addContent(new Element(ROOT_TAG).setAttribute(TYPE_ATTRIBUTE, SIMPLE_TYPE).setAttribute(URL_ATTRIBUTE, root.getUrl()));
|
||||
}
|
||||
rootTypeTag.addContent(compositeTag);
|
||||
rootsTag.addContent(rootTypeTag);
|
||||
}
|
||||
sdkTag.addContent(rootsTag);
|
||||
|
||||
Element additionalTag = new Element(ADDITIONAL_TAG);
|
||||
serializer.saveProperties(properties, additionalTag);
|
||||
sdkTag.addContent(additionalTag);
|
||||
}
|
||||
|
||||
private static void setAttributeValue(Element tag, final String tagName, final String value) {
|
||||
tag.addContent(new Element(tagName).setAttribute(VALUE_ATTRIBUTE, value));
|
||||
}
|
||||
|
||||
private static void loadRoots(Element rootElement, JpsLibrary library, JpsOrderRootType rootType) {
|
||||
final String type = rootElement.getAttributeValue(TYPE_ATTRIBUTE);
|
||||
if (type.equals(COMPOSITE_TYPE)) {
|
||||
for (Element element : JDOMUtil.getChildren(rootElement)) {
|
||||
loadRoots(element, library, rootType);
|
||||
}
|
||||
}
|
||||
else if (type.equals(SIMPLE_TYPE)) {
|
||||
library.addRoot(rootElement.getAttributeValue(URL_ATTRIBUTE), rootType);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JpsLibraryRootTypeSerializer getRootTypeSerializer(String typeId) {
|
||||
for (JpsLibraryRootTypeSerializer serializer : PREDEFINED_ROOT_TYPE_SERIALIZERS) {
|
||||
if (serializer.getTypeId().equals(typeId)) {
|
||||
return serializer;
|
||||
}
|
||||
}
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsLibraryRootTypeSerializer serializer : extension.getSdkRootTypeSerializers()) {
|
||||
if (serializer.getTypeId().equals(typeId)) {
|
||||
return serializer;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<JpsLibraryRootTypeSerializer> getRootTypeSerializers() {
|
||||
List<JpsLibraryRootTypeSerializer> serializers = new ArrayList<JpsLibraryRootTypeSerializer>(Arrays.asList(PREDEFINED_ROOT_TYPE_SERIALIZERS));
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
serializers.addAll(extension.getSdkRootTypeSerializers());
|
||||
}
|
||||
Collections.sort(serializers);
|
||||
return serializers;
|
||||
}
|
||||
|
||||
private static <P extends JpsSdkProperties> JpsLibrary createSdk(String name, JpsSdkPropertiesSerializer<P> loader, Element sdkElement) {
|
||||
String versionString = getAttributeValue(sdkElement, VERSION_TAG);
|
||||
String homePath = getAttributeValue(sdkElement, HOME_PATH_TAG);
|
||||
Element propertiesTag = sdkElement.getChild(ADDITIONAL_TAG);
|
||||
P properties = loader.loadProperties(homePath, versionString, propertiesTag);
|
||||
return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), properties);
|
||||
}
|
||||
|
||||
public static JpsSdkPropertiesSerializer<?> getSdkPropertiesSerializer(String typeId) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsSdkPropertiesSerializer<?> loader : extension.getSdkPropertiesLoaders()) {
|
||||
if (loader.getTypeId().equals(typeId)) {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
return JPS_JAVA_SDK_PROPERTIES_LOADER;
|
||||
}
|
||||
|
||||
public static <P extends JpsSdkProperties> JpsSdkPropertiesSerializer<P> getSdkPropertiesSerializer(JpsSdkType<P> type) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsSdkPropertiesSerializer<?> loader : extension.getSdkPropertiesLoaders()) {
|
||||
if (loader.getType().equals(type)) {
|
||||
//noinspection unchecked
|
||||
return (JpsSdkPropertiesSerializer<P>)loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (JpsSdkPropertiesSerializer<P>)JPS_JAVA_SDK_PROPERTIES_LOADER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getAttributeValue(Element element, String childName) {
|
||||
final Element child = element.getChild(childName);
|
||||
return child != null ? child.getAttributeValue(VALUE_ATTRIBUTE) : null;
|
||||
}
|
||||
|
||||
public static JpsSdkType<?> getSdkType(String typeId) {
|
||||
return getSdkPropertiesSerializer(typeId).getType();
|
||||
}
|
||||
|
||||
public static JpsSdkPropertiesSerializer<?> getLoader(JpsSdkType<?> type) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsSdkPropertiesSerializer<?> loader : extension.getSdkPropertiesLoaders()) {
|
||||
if (loader.getType().equals(type)) {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
}
|
||||
return JPS_JAVA_SDK_PROPERTIES_LOADER;
|
||||
}
|
||||
|
||||
public static void setSdkReference(final JpsSdkReferencesTable table, String sdkName, JpsSdkType<?> sdkType) {
|
||||
JpsLibraryReference reference = JpsElementFactory.getInstance().createSdkReference(sdkName, sdkType);
|
||||
table.setSdkReference(sdkType, reference);
|
||||
if (sdkType instanceof JpsJavaSdkTypeWrapper) {
|
||||
JpsLibrary jpsLibrary = reference.resolve();
|
||||
if (jpsLibrary != null) {
|
||||
String name = ((JpsJavaSdkTypeWrapper)sdkType).getJavaSdkName((JpsSdkProperties)jpsLibrary.getProperties());
|
||||
if (name != null) {
|
||||
table.setSdkReference(JpsJavaSdkType.INSTANCE, JpsElementFactory.getInstance().createSdkReference(name, JpsJavaSdkType.INSTANCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -13,9 +13,8 @@ import org.jetbrains.jps.model.artifact.*;
|
||||
import org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement;
|
||||
import org.jetbrains.jps.model.artifact.elements.JpsPackagingElement;
|
||||
import org.jetbrains.jps.model.artifact.elements.JpsPackagingElementFactory;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelLoaderExtension;
|
||||
import org.jetbrains.jps.model.serialization.JpsModuleLoader;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||
import org.jetbrains.jps.model.serialization.JpsModuleSerializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -87,7 +86,7 @@ public class JpsArtifactLoader {
|
||||
parentReference = JpsElementFactory.getInstance().createModuleReference(moduleName);
|
||||
}
|
||||
else {
|
||||
parentReference = JpsModuleLoader.createLibraryTableReference(level);
|
||||
parentReference = JpsModuleSerializer.createLibraryTableReference(level);
|
||||
}
|
||||
return factory.createLibraryElement(JpsElementFactory.getInstance().createLibraryReference(libraryName, parentReference));
|
||||
}
|
||||
@@ -108,7 +107,7 @@ public class JpsArtifactLoader {
|
||||
if (typeId.equals("jar")) {
|
||||
return JarArtifactType.INSTANCE;
|
||||
}
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
JpsArtifactType type = extension.getArtifactType(typeId);
|
||||
if (type != null) {
|
||||
return type;
|
||||
@@ -124,7 +123,7 @@ public class JpsArtifactLoader {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsPackagingElementLoader<?> loader : extension.getPackagingElementLoaders()) {
|
||||
if (loader.getTypeId().equals(typeId)) {
|
||||
return loader;
|
||||
|
||||
+2
-3
@@ -7,8 +7,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelLoaderExtension;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -48,7 +47,7 @@ public class JpsFacetLoader {
|
||||
|
||||
@Nullable
|
||||
private static JpsModuleExtensionLoader<?> getModuleExtensionLoader(@NotNull String typeId) {
|
||||
for (JpsModelLoaderExtension extension : JpsServiceManager.getInstance().getExtensions(JpsModelLoaderExtension.class)) {
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsModuleExtensionLoader<?> loader : extension.getModuleExtensionLoaders()) {
|
||||
if (loader.getFacetTypeId().equals(typeId)) {
|
||||
return loader;
|
||||
|
||||
-148
@@ -1,148 +0,0 @@
|
||||
package org.jetbrains.jps.model.serialization.java;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.JpsUrlList;
|
||||
import org.jetbrains.jps.model.java.*;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
import org.jetbrains.jps.model.module.JpsDependencyElement;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelLoaderExtension;
|
||||
import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementLoader;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsJavaModelLoaderExtension extends JpsModelLoaderExtension {
|
||||
@Override
|
||||
public void loadRootModel(@NotNull JpsModule module, @NotNull Element rootModel) {
|
||||
loadExplodedDirectoryExtension(module, rootModel);
|
||||
loadJavaModuleExtension(module, rootModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadProjectRoots(JpsProject project, Element rootManagerElement) {
|
||||
loadJavaProjectExtensions(project, rootManagerElement);
|
||||
}
|
||||
|
||||
private static void loadJavaProjectExtensions(JpsProject project, Element rootManagerElement) {
|
||||
JpsJavaProjectExtension extension = JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(project);
|
||||
final Element output = rootManagerElement.getChild("output");
|
||||
if (output != null) {
|
||||
String url = output.getAttributeValue("url");
|
||||
if (url != null) {
|
||||
extension.setOutputUrl(url);
|
||||
}
|
||||
}
|
||||
String languageLevel = rootManagerElement.getAttributeValue("languageLevel");
|
||||
if (languageLevel != null) {
|
||||
extension.setLanguageLevel(LanguageLevel.valueOf(languageLevel));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadModuleDependencyProperties(JpsDependencyElement dependency, Element entry) {
|
||||
boolean exported = entry.getAttributeValue("exported") != null;
|
||||
String scopeName = entry.getAttributeValue("scope");
|
||||
JpsJavaDependencyScope scope = scopeName != null ? JpsJavaDependencyScope.valueOf(scopeName) : JpsJavaDependencyScope.COMPILE;
|
||||
|
||||
final JpsJavaDependencyExtension extension = JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(dependency);
|
||||
extension.setExported(exported);
|
||||
extension.setScope(scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpsOrderRootType getRootType(@NotNull String typeId) {
|
||||
if (typeId.equals("JAVADOC")) {
|
||||
return JpsOrderRootType.DOCUMENTATION;
|
||||
}
|
||||
else if (typeId.equals("ANNOTATIONS")) {
|
||||
return JpsAnnotationRootType.INSTANCE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpsOrderRootType getSdkRootType(@NotNull String typeId) {
|
||||
if (typeId.equals("javadocPath")) {
|
||||
return JpsOrderRootType.DOCUMENTATION;
|
||||
}
|
||||
if (typeId.equals("annotationsPath")) {
|
||||
return JpsAnnotationRootType.INSTANCE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends JpsPackagingElementLoader<?>> getPackagingElementLoaders() {
|
||||
return Arrays.asList(new JpsModuleOutputPackagingElementLoader(), new JpsTestModuleOutputPackagingElementLoader());
|
||||
}
|
||||
|
||||
private static void loadExplodedDirectoryExtension(JpsModule module, Element rootModelComponent) {
|
||||
final Element exploded = rootModelComponent.getChild("exploded");
|
||||
if (exploded != null) {
|
||||
final ExplodedDirectoryModuleExtension extension =
|
||||
JpsJavaExtensionService.getInstance().getOrCreateExplodedDirectoryExtension(module);
|
||||
extension.setExcludeExploded(rootModelComponent.getChild("exclude-exploded") != null);
|
||||
extension.setExplodedUrl(exploded.getAttributeValue("url"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadJavaModuleExtension(JpsModule module, Element rootModelComponent) {
|
||||
final JpsJavaModuleExtension extension = JpsJavaExtensionService.getInstance().getOrCreateModuleExtension(module);
|
||||
final Element outputTag = rootModelComponent.getChild("output");
|
||||
if (outputTag != null) {
|
||||
extension.setOutputUrl(outputTag.getAttributeValue("url"));
|
||||
}
|
||||
final Element testOutputTag = rootModelComponent.getChild("output-test");
|
||||
if (testOutputTag != null) {
|
||||
extension.setOutputUrl(testOutputTag.getAttributeValue("url"));
|
||||
}
|
||||
extension.setInheritOutput(Boolean.parseBoolean(rootModelComponent.getAttributeValue("inherit-compiler-output")));
|
||||
extension.setExcludeOutput(rootModelComponent.getChild("exclude-output") != null);
|
||||
|
||||
loadAdditionalRoots(rootModelComponent, "annotation-paths", extension.getAnnotationRoots());
|
||||
loadAdditionalRoots(rootModelComponent, "javadoc-paths", extension.getJavadocRoots());
|
||||
|
||||
final String languageLevel = rootModelComponent.getAttributeValue("LANGUAGE_LEVEL");
|
||||
if (languageLevel != null) {
|
||||
extension.setLanguageLevel(LanguageLevel.valueOf(languageLevel));
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadAdditionalRoots(Element rootModelComponent, final String rootsTagName, final JpsUrlList result) {
|
||||
final Element roots = rootModelComponent.getChild(rootsTagName);
|
||||
for (Element root : JDOMUtil.getChildren(roots, "root")) {
|
||||
result.addUrl(root.getAttributeValue("url"));
|
||||
}
|
||||
}
|
||||
|
||||
private static class JpsModuleOutputPackagingElementLoader extends JpsPackagingElementLoader<JpsProductionModuleOutputPackagingElement> {
|
||||
private JpsModuleOutputPackagingElementLoader() {
|
||||
super("module-output");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpsProductionModuleOutputPackagingElement load(Element element) {
|
||||
return JpsJavaExtensionService.getInstance().createProductionModuleOutput(JpsElementFactory.getInstance().createModuleReference(element.getAttributeValue("name")));
|
||||
}
|
||||
}
|
||||
|
||||
private static class JpsTestModuleOutputPackagingElementLoader extends JpsPackagingElementLoader<JpsTestModuleOutputPackagingElement> {
|
||||
private JpsTestModuleOutputPackagingElementLoader() {
|
||||
super("module-test-output");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpsTestModuleOutputPackagingElement load(Element element) {
|
||||
return JpsJavaExtensionService.getInstance().createTestModuleOutput(
|
||||
JpsElementFactory.getInstance().createModuleReference(element.getAttributeValue("name")));
|
||||
}
|
||||
}
|
||||
}
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
package org.jetbrains.jps.model.serialization.java;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.JpsUrlList;
|
||||
import org.jetbrains.jps.model.java.*;
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||
import org.jetbrains.jps.model.module.JpsDependencyElement;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.module.JpsModuleReference;
|
||||
import org.jetbrains.jps.model.serialization.JpsLibraryRootTypeSerializer;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||
import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementLoader;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsJavaModelSerializerExtension extends JpsModelSerializerExtension {
|
||||
private static final String EXPORTED_ATTRIBUTE = "exported";
|
||||
private static final String SCOPE_ATTRIBUTE = "scope";
|
||||
private static final String OUTPUT_TAG = "output";
|
||||
private static final String URL_ATTRIBUTE = "url";
|
||||
private static final String LANGUAGE_LEVEL_ATTRIBUTE = "languageLevel";
|
||||
private static final String EXPLODED_TAG = "exploded";
|
||||
private static final String EXCLUDE_EXPLODED_TAG = "exclude-exploded";
|
||||
private static final String TEST_OUTPUT_TAG = "output-test";
|
||||
private static final String INHERIT_COMPILER_OUTPUT_ATTRIBUTE = "inherit-compiler-output";
|
||||
private static final String EXCLUDE_OUTPUT_TAG = "exclude-output";
|
||||
private static final String ANNOTATION_PATHS_TAG = "annotation-paths";
|
||||
private static final String JAVADOC_PATHS_TAG = "javadoc-paths";
|
||||
private static final String MODULE_LANGUAGE_LEVEL_ATTRIBUTE = "LANGUAGE_LEVEL";
|
||||
private static final String ROOT_TAG = "root";
|
||||
|
||||
@Override
|
||||
public void loadRootModel(@NotNull JpsModule module, @NotNull Element rootModel) {
|
||||
loadExplodedDirectoryExtension(module, rootModel);
|
||||
loadJavaModuleExtension(module, rootModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveRootModel(@NotNull JpsModule module, @NotNull Element rootModel) {
|
||||
saveExplodedDirectoryExtension(module, rootModel);
|
||||
saveJavaModuleExtension(module, rootModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadProjectRoots(JpsProject project, Element rootManagerElement) {
|
||||
JpsJavaProjectExtension extension = getService().getOrCreateProjectExtension(project);
|
||||
final Element output = rootManagerElement.getChild(OUTPUT_TAG);
|
||||
if (output != null) {
|
||||
String url = output.getAttributeValue(URL_ATTRIBUTE);
|
||||
if (url != null) {
|
||||
extension.setOutputUrl(url);
|
||||
}
|
||||
}
|
||||
String languageLevel = rootManagerElement.getAttributeValue(LANGUAGE_LEVEL_ATTRIBUTE);
|
||||
if (languageLevel != null) {
|
||||
extension.setLanguageLevel(LanguageLevel.valueOf(languageLevel));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProjectRoots(JpsProject project, Element rootManagerElement) {
|
||||
JpsJavaProjectExtension extension = getService().getProjectExtension(project);
|
||||
if (extension == null) return;
|
||||
|
||||
String outputUrl = extension.getOutputUrl();
|
||||
if (outputUrl != null) {
|
||||
rootManagerElement.addContent(new Element(OUTPUT_TAG).setAttribute(URL_ATTRIBUTE, outputUrl));
|
||||
}
|
||||
LanguageLevel level = extension.getLanguageLevel();
|
||||
rootManagerElement.setAttribute(LANGUAGE_LEVEL_ATTRIBUTE, level.name());
|
||||
rootManagerElement.setAttribute("assert-keyword", Boolean.toString(level.compareTo(LanguageLevel.JDK_1_4) >= 0));
|
||||
rootManagerElement.setAttribute("jdk-15", Boolean.toString(level.compareTo(LanguageLevel.JDK_1_5) >= 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadModuleDependencyProperties(JpsDependencyElement dependency, Element entry) {
|
||||
boolean exported = entry.getAttributeValue(EXPORTED_ATTRIBUTE) != null;
|
||||
String scopeName = entry.getAttributeValue(SCOPE_ATTRIBUTE);
|
||||
JpsJavaDependencyScope scope = scopeName != null ? JpsJavaDependencyScope.valueOf(scopeName) : JpsJavaDependencyScope.COMPILE;
|
||||
|
||||
final JpsJavaDependencyExtension extension = getService().getOrCreateDependencyExtension(dependency);
|
||||
extension.setExported(exported);
|
||||
extension.setScope(scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveModuleDependencyProperties(JpsDependencyElement dependency, Element orderEntry) {
|
||||
JpsJavaDependencyExtension extension = getService().getDependencyExtension(dependency);
|
||||
if (extension != null) {
|
||||
if (extension.isExported()) {
|
||||
orderEntry.setAttribute(EXPORTED_ATTRIBUTE, "");
|
||||
}
|
||||
JpsJavaDependencyScope scope = extension.getScope();
|
||||
if (scope != JpsJavaDependencyScope.COMPILE) {
|
||||
orderEntry.setAttribute(SCOPE_ATTRIBUTE, scope.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JpsLibraryRootTypeSerializer> getLibraryRootTypeSerializers() {
|
||||
return Arrays.asList(new JpsLibraryRootTypeSerializer("JAVADOC", JpsOrderRootType.DOCUMENTATION, true),
|
||||
new JpsLibraryRootTypeSerializer("ANNOTATIONS", JpsAnnotationRootType.INSTANCE, false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JpsLibraryRootTypeSerializer> getSdkRootTypeSerializers() {
|
||||
return Arrays.asList(new JpsLibraryRootTypeSerializer("javadocPath", JpsOrderRootType.DOCUMENTATION, true),
|
||||
new JpsLibraryRootTypeSerializer("annotationsPath", JpsAnnotationRootType.INSTANCE, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends JpsPackagingElementLoader<?>> getPackagingElementLoaders() {
|
||||
return Arrays.asList(new JpsModuleOutputPackagingElementLoader(), new JpsTestModuleOutputPackagingElementLoader());
|
||||
}
|
||||
|
||||
private static void loadExplodedDirectoryExtension(JpsModule module, Element rootModelComponent) {
|
||||
final Element exploded = rootModelComponent.getChild(EXPLODED_TAG);
|
||||
if (exploded != null) {
|
||||
final ExplodedDirectoryModuleExtension extension = getService().getOrCreateExplodedDirectoryExtension(module);
|
||||
extension.setExcludeExploded(rootModelComponent.getChild(EXCLUDE_EXPLODED_TAG) != null);
|
||||
extension.setExplodedUrl(exploded.getAttributeValue(URL_ATTRIBUTE));
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveExplodedDirectoryExtension(JpsModule module, Element rootModelElement) {
|
||||
ExplodedDirectoryModuleExtension extension = getService().getExplodedDirectoryExtension(module);
|
||||
if (extension != null) {
|
||||
if (extension.isExcludeExploded()) {
|
||||
rootModelElement.addContent(0, new Element(EXCLUDE_EXPLODED_TAG));
|
||||
}
|
||||
rootModelElement.addContent(0, new Element(EXPLODED_TAG).setAttribute(URL_ATTRIBUTE, extension.getExplodedUrl()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadJavaModuleExtension(JpsModule module, Element rootModelComponent) {
|
||||
final JpsJavaModuleExtension extension = getService().getOrCreateModuleExtension(module);
|
||||
final Element outputTag = rootModelComponent.getChild(OUTPUT_TAG);
|
||||
if (outputTag != null) {
|
||||
extension.setOutputUrl(outputTag.getAttributeValue(URL_ATTRIBUTE));
|
||||
}
|
||||
final Element testOutputTag = rootModelComponent.getChild(TEST_OUTPUT_TAG);
|
||||
if (testOutputTag != null) {
|
||||
extension.setTestOutputUrl(testOutputTag.getAttributeValue(URL_ATTRIBUTE));
|
||||
}
|
||||
extension.setInheritOutput(Boolean.parseBoolean(rootModelComponent.getAttributeValue(INHERIT_COMPILER_OUTPUT_ATTRIBUTE)));
|
||||
extension.setExcludeOutput(rootModelComponent.getChild(EXCLUDE_OUTPUT_TAG) != null);
|
||||
|
||||
final String languageLevel = rootModelComponent.getAttributeValue(MODULE_LANGUAGE_LEVEL_ATTRIBUTE);
|
||||
if (languageLevel != null) {
|
||||
extension.setLanguageLevel(LanguageLevel.valueOf(languageLevel));
|
||||
}
|
||||
|
||||
loadAdditionalRoots(rootModelComponent, ANNOTATION_PATHS_TAG, extension.getAnnotationRoots());
|
||||
loadAdditionalRoots(rootModelComponent, JAVADOC_PATHS_TAG, extension.getJavadocRoots());
|
||||
}
|
||||
|
||||
private static void saveJavaModuleExtension(JpsModule module, Element rootModelComponent) {
|
||||
JpsJavaModuleExtension extension = getService().getModuleExtension(module);
|
||||
if (extension == null) return;
|
||||
if (extension.isExcludeOutput()) {
|
||||
rootModelComponent.addContent(0, new Element(EXCLUDE_OUTPUT_TAG));
|
||||
}
|
||||
|
||||
String testOutputUrl = extension.getTestOutputUrl();
|
||||
if (testOutputUrl != null) {
|
||||
rootModelComponent.addContent(0, new Element(TEST_OUTPUT_TAG).setAttribute(URL_ATTRIBUTE, testOutputUrl));
|
||||
}
|
||||
|
||||
String outputUrl = extension.getOutputUrl();
|
||||
if (outputUrl != null) {
|
||||
rootModelComponent.addContent(0, new Element(OUTPUT_TAG).setAttribute(URL_ATTRIBUTE, outputUrl));
|
||||
}
|
||||
|
||||
LanguageLevel languageLevel = extension.getLanguageLevel();
|
||||
if (languageLevel != null) {
|
||||
rootModelComponent.setAttribute(MODULE_LANGUAGE_LEVEL_ATTRIBUTE, languageLevel.name());
|
||||
}
|
||||
rootModelComponent.setAttribute(INHERIT_COMPILER_OUTPUT_ATTRIBUTE, String.valueOf(extension.isInheritOutput()));
|
||||
saveAdditionalRoots(rootModelComponent, JAVADOC_PATHS_TAG, extension.getJavadocRoots());
|
||||
saveAdditionalRoots(rootModelComponent, ANNOTATION_PATHS_TAG, extension.getAnnotationRoots());
|
||||
}
|
||||
|
||||
private static void loadAdditionalRoots(Element rootModelComponent, final String rootsTagName, final JpsUrlList result) {
|
||||
final Element roots = rootModelComponent.getChild(rootsTagName);
|
||||
for (Element root : JDOMUtil.getChildren(roots, ROOT_TAG)) {
|
||||
result.addUrl(root.getAttributeValue(URL_ATTRIBUTE));
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveAdditionalRoots(Element rootModelComponent, final String rootsTagName, final JpsUrlList list) {
|
||||
List<String> urls = list.getUrls();
|
||||
if (!urls.isEmpty()) {
|
||||
Element roots = new Element(rootsTagName);
|
||||
for (String url : urls) {
|
||||
roots.addContent(new Element(ROOT_TAG).setAttribute(URL_ATTRIBUTE, url));
|
||||
}
|
||||
rootModelComponent.addContent(roots);
|
||||
}
|
||||
}
|
||||
|
||||
private static JpsJavaExtensionService getService() {
|
||||
return JpsJavaExtensionService.getInstance();
|
||||
}
|
||||
|
||||
private static class JpsModuleOutputPackagingElementLoader extends JpsPackagingElementLoader<JpsProductionModuleOutputPackagingElement> {
|
||||
private JpsModuleOutputPackagingElementLoader() {
|
||||
super("module-output");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpsProductionModuleOutputPackagingElement load(Element element) {
|
||||
JpsModuleReference reference = JpsElementFactory.getInstance().createModuleReference(element.getAttributeValue("name"));
|
||||
return getService().createProductionModuleOutput(reference);
|
||||
}
|
||||
}
|
||||
|
||||
private static class JpsTestModuleOutputPackagingElementLoader extends JpsPackagingElementLoader<JpsTestModuleOutputPackagingElement> {
|
||||
private JpsTestModuleOutputPackagingElementLoader() {
|
||||
super("module-test-output");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpsTestModuleOutputPackagingElement load(Element element) {
|
||||
JpsModuleReference reference = JpsElementFactory.getInstance().createModuleReference(element.getAttributeValue("name"));
|
||||
return getService().createTestModuleOutput(reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
|
||||
</descriptors>
|
||||
<webroots>
|
||||
<root url="file://$MODULE_DIR$/web" relative="/" />
|
||||
</webroots>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="junit" level="project" />
|
||||
<orderEntry type="library" name="jdom" level="application" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="exploded-war" name="explodedWar">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/explodedWar</output-path>
|
||||
<root id="root">
|
||||
<element id="javaee-facet-resources" facet="iprProject/web/Web" />
|
||||
<element id="directory" name="WEB-INF">
|
||||
<element id="directory" name="classes">
|
||||
<element id="module-output" name="iprProject" />
|
||||
</element>
|
||||
<element id="directory" name="lib">
|
||||
<element id="library" level="project" name="junit" />
|
||||
<element id="library" level="application" name="jdom" />
|
||||
</element>
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
<artifact type="jar" name="archive">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/archive</output-path>
|
||||
<root id="archive" name="archive.jar">
|
||||
<element id="directory" name="files">
|
||||
<element id="artifact" artifact-name="files" />
|
||||
</element>
|
||||
<element id="archive" name="sources.zip">
|
||||
<element id="dir-copy" path="$PROJECT_DIR$/src" />
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
<artifact name="files">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/files</output-path>
|
||||
<root id="root">
|
||||
<element id="file-copy" path="$PROJECT_DIR$/data/f.txt" output-file-name="g.txt" />
|
||||
<element id="file-copy" path="$PROJECT_DIR$/data/f.txt" />
|
||||
<element id="directory" name="dir">
|
||||
<element id="dir-copy" path="$PROJECT_DIR$/data" />
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/iprProject.iml" filepath="$PROJECT_DIR$/iprProject.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="libraryTable">
|
||||
<library name="junit">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/junit.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
sampleProject
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="?*.properties" />
|
||||
<entry name="?*.xml" />
|
||||
<entry name="?*.gif" />
|
||||
<entry name="?*.png" />
|
||||
<entry name="?*.jpeg" />
|
||||
<entry name="?*.jpg" />
|
||||
<entry name="?*.html" />
|
||||
<entry name="?*.dtd" />
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="false" useClasspath="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="jarDir">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib/jarDir" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/lib/jarDir/src" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/jarDir" recursive="false" />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib/jarDir/src" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
||||
@@ -0,0 +1,15 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit">
|
||||
<ANNOTATIONS>
|
||||
<root url="file://$PROJECT_DIR$/lib/junit-anno" />
|
||||
</ANNOTATIONS>
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/junit.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="file://$PROJECT_DIR$/lib/javadoc" />
|
||||
<root url="http://javadoc" />
|
||||
</JAVADOC>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="log4j">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/log4j.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/log4j.zip!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/main.iml" filepath="$PROJECT_DIR$/main.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/util/util.iml" filepath="$PROJECT_DIR$/util/util.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="log4j" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="junit" level="project" />
|
||||
<orderEntry type="library" exported="" name="jarDir" level="project" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/../out/production-util" />
|
||||
<output-test url="file://$MODULE_DIR$/../out/test-util" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="xxx" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/exc" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.5" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/junit.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library name="log4j">
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/log4j.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/log4j.zip!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<javadoc-paths>
|
||||
<root url="file://$MODULE_DIR$/../lib/javadoc" />
|
||||
</javadoc-paths>
|
||||
<annotation-paths>
|
||||
<root url="file://$MODULE_DIR$/../lib/anno" />
|
||||
</annotation-paths>
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+28
-2
@@ -1,7 +1,13 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.ide.impl.convert.JDomConvertingUtil;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,8 +15,10 @@ import java.util.List;
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
public void testLoadSdks() throws IOException {
|
||||
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), getTestDataFileAbsolutePath("jps/model-serialization/testData/config/options"));
|
||||
private static final String OPTIONS_DIR = "jps/model-serialization/testData/config/options";
|
||||
|
||||
public void testLoadSdks() {
|
||||
loadGlobalSettings();
|
||||
final List<JpsLibrary> libraries = myModel.getGlobal().getLibraryCollection().getLibraries();
|
||||
assertEquals(3, libraries.size());
|
||||
assertEquals("Gant", libraries.get(0).getName());
|
||||
@@ -19,4 +27,22 @@ public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
final JpsLibrary sdk2 = libraries.get(2);
|
||||
assertEquals("1.6", sdk2.getName());
|
||||
}
|
||||
|
||||
public void testSaveSdks() throws JDOMException, IOException {
|
||||
loadGlobalSettings();
|
||||
Element actual = new Element("component").setAttribute("name", "ProjectJdkTable");
|
||||
JpsSdkTableSerializer.saveSdks(myModel.getGlobal().getLibraryCollection(), actual);
|
||||
File jdkTableFile = new File(getTestDataFileAbsolutePath(OPTIONS_DIR), "jdk.table.xml");
|
||||
Element expected = JDomConvertingUtil.findComponent(JDOMUtil.loadDocument(jdkTableFile).getRootElement(), "ProjectJdkTable");
|
||||
PlatformTestUtil.assertElementsEqual(expected, actual);
|
||||
}
|
||||
|
||||
private void loadGlobalSettings() {
|
||||
try {
|
||||
JpsGlobalLoader.loadGlobalSettings(myModel.getGlobal(), getTestDataFileAbsolutePath(OPTIONS_DIR));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkType;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.module.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsModuleSerializationTest extends JpsSerializationTestCase {
|
||||
public void test() {
|
||||
loadProject("/jps/model-serialization/testData/iprProject/iprProject.ipr");
|
||||
final JpsModule module = assertOneElement(myModel.getProject().getModules());
|
||||
assertEquals("iprProject", module.getName());
|
||||
|
||||
final JpsLibrary library = assertOneElement(myModel.getProject().getLibraryCollection().getLibraries());
|
||||
assertEquals("junit", library.getName());
|
||||
|
||||
List<JpsDependencyElement> dependencies = module.getDependenciesList().getDependencies();
|
||||
JpsSdkDependency sdkDependency = assertInstanceOf(dependencies.get(0), JpsSdkDependency.class);
|
||||
assertSame(JpsJavaSdkType.INSTANCE, sdkDependency.getSdkType());
|
||||
assertEquals("1.6", sdkDependency.getSdkReference().getLibraryName());
|
||||
assertInstanceOf(dependencies.get(1), JpsModuleSourceDependency.class);
|
||||
assertInstanceOf(dependencies.get(2), JpsLibraryDependency.class);
|
||||
assertInstanceOf(dependencies.get(3), JpsLibraryDependency.class);
|
||||
}
|
||||
|
||||
public void _testLoadIdeaProject() {
|
||||
long start = System.currentTimeMillis();
|
||||
final JpsProject project = myModel.getProject();
|
||||
loadProject(PathManager.getHomePath());
|
||||
assertTrue(project.getModules().size() > 0);
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - start));
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.ide.impl.convert.JDomConvertingUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkType;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.module.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
private static final String SAMPLE_PROJECT_PATH = "/jps/model-serialization/testData/sampleProject";
|
||||
|
||||
public void testLoadProject() {
|
||||
loadProject(SAMPLE_PROJECT_PATH);
|
||||
List<JpsModule> modules = myModel.getProject().getModules();
|
||||
assertEquals(2, modules.size());
|
||||
JpsModule main = modules.get(0);
|
||||
assertEquals("main", main.getName());
|
||||
JpsModule util = modules.get(1);
|
||||
assertEquals("util", util.getName());
|
||||
|
||||
List<JpsLibrary> libraries = myModel.getProject().getLibraryCollection().getLibraries();
|
||||
assertEquals(3, libraries.size());
|
||||
|
||||
List<JpsDependencyElement> dependencies = util.getDependenciesList().getDependencies();
|
||||
assertEquals(4, dependencies.size());
|
||||
JpsSdkDependency sdkDependency = assertInstanceOf(dependencies.get(0), JpsSdkDependency.class);
|
||||
assertSame(JpsJavaSdkType.INSTANCE, sdkDependency.getSdkType());
|
||||
assertEquals("1.5", sdkDependency.getSdkReference().getLibraryName());
|
||||
assertInstanceOf(dependencies.get(1), JpsModuleSourceDependency.class);
|
||||
assertInstanceOf(dependencies.get(2), JpsLibraryDependency.class);
|
||||
assertInstanceOf(dependencies.get(3), JpsLibraryDependency.class);
|
||||
}
|
||||
|
||||
public void testSaveProject() {
|
||||
loadProject(SAMPLE_PROJECT_PATH);
|
||||
JpsModule main = myModel.getProject().getModules().get(0);
|
||||
doTestSaveModule(main, "main.iml");
|
||||
|
||||
JpsModule util = myModel.getProject().getModules().get(1);
|
||||
doTestSaveModule(util, "util/util.iml");
|
||||
|
||||
File[] libs = getFileInSampleProject(".idea/libraries").listFiles();
|
||||
assertNotNull(libs);
|
||||
for (File libFile : libs) {
|
||||
String libName = FileUtil.getNameWithoutExtension(libFile);
|
||||
JpsLibrary library = myModel.getProject().getLibraryCollection().findLibrary(libName);
|
||||
assertNotNull(libName, library);
|
||||
doTestSaveLibrary(libFile, libName, library);
|
||||
}
|
||||
}
|
||||
|
||||
private static void doTestSaveLibrary(File libFile, String libName, JpsLibrary library) {
|
||||
try {
|
||||
Element actual = new Element("library");
|
||||
JpsLibraryTableSerializer.saveLibrary(library, actual, libName);
|
||||
JpsMacroExpander
|
||||
macroExpander = JpsProjectLoader.createProjectMacroExpander(Collections.<String, String>emptyMap(), getFileInSampleProject(""));
|
||||
Element rootElement = JpsLoaderBase.loadRootElement(libFile, macroExpander);
|
||||
Element expected = rootElement.getChild("library");
|
||||
PlatformTestUtil.assertElementsEqual(expected, actual);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void doTestSaveModule(JpsModule util, final String moduleFilePath) {
|
||||
try {
|
||||
Element actual = new Element("component").setAttribute("name", "NewModuleRootManager");
|
||||
JpsModuleSerializer.saveRootModel(util, actual);
|
||||
File utilIml = getFileInSampleProject(moduleFilePath);
|
||||
Element rootElement = JpsLoaderBase.loadRootElement(utilIml, JpsProjectLoader.createModuleMacroExpander(Collections.<String, String>emptyMap(), utilIml));
|
||||
Element expected = JDomConvertingUtil.findComponent(rootElement, "NewModuleRootManager");
|
||||
PlatformTestUtil.assertElementsEqual(expected, actual);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static File getFileInSampleProject(String moduleFilePath) {
|
||||
return new File(getTestDataFileAbsolutePath(SAMPLE_PROJECT_PATH + "/" + moduleFilePath));
|
||||
}
|
||||
|
||||
public void _testLoadIdeaProject() {
|
||||
long start = System.currentTimeMillis();
|
||||
final JpsProject project = myModel.getProject();
|
||||
loadProject("");
|
||||
assertTrue(project.getModules().size() > 0);
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - start));
|
||||
}
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
org.jetbrains.jps.android.model.impl.JpsAndroidModelLoaderExtension
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.jps.android.model.impl.JpsAndroidModelSerializerExtension
|
||||
+19
-6
@@ -23,8 +23,8 @@ import org.jetbrains.jps.android.model.JpsAndroidModuleExtension;
|
||||
import org.jetbrains.jps.android.model.JpsAndroidSdkProperties;
|
||||
import org.jetbrains.jps.android.model.JpsAndroidSdkType;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelLoaderExtension;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkPropertiesLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkPropertiesSerializer;
|
||||
import org.jetbrains.jps.model.serialization.facet.JpsModuleExtensionLoader;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -33,7 +33,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsAndroidModelLoaderExtension extends JpsModelLoaderExtension {
|
||||
public class JpsAndroidModelSerializerExtension extends JpsModelSerializerExtension {
|
||||
private static final List<? extends JpsModuleExtensionLoader<JpsAndroidModuleExtension>> FACET_PROPERTIES_LOADERS =
|
||||
Arrays.asList(new JpsModuleExtensionLoader<JpsAndroidModuleExtension>(JpsAndroidModuleExtensionImpl.KIND, "android") {
|
||||
@Override
|
||||
@@ -44,8 +44,9 @@ public class JpsAndroidModelLoaderExtension extends JpsModelLoaderExtension {
|
||||
return new JpsAndroidModuleExtensionImpl(XmlSerializer.deserialize(facetConfigurationElement, JpsAndroidModuleProperties.class), baseModulePath);
|
||||
}
|
||||
});
|
||||
private static final JpsSdkPropertiesLoader<JpsAndroidSdkProperties> SDK_PROPERTIES_LOADER =
|
||||
new JpsSdkPropertiesLoader<JpsAndroidSdkProperties>("Android SDK", JpsAndroidSdkType.INSTANCE) {
|
||||
private static final JpsSdkPropertiesSerializer<JpsAndroidSdkProperties> SDK_PROPERTIES_LOADER =
|
||||
new JpsSdkPropertiesSerializer<JpsAndroidSdkProperties>("Android SDK", JpsAndroidSdkType.INSTANCE) {
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsAndroidSdkProperties loadProperties(String homePath, String version, @Nullable Element propertiesElement) {
|
||||
String buildTarget;
|
||||
@@ -60,6 +61,18 @@ public class JpsAndroidModelLoaderExtension extends JpsModelLoaderExtension {
|
||||
}
|
||||
return new JpsAndroidSdkProperties(homePath, version, buildTarget, jdkName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProperties(@NotNull JpsAndroidSdkProperties properties, @NotNull Element element) {
|
||||
String jdkName = properties.getJdkName();
|
||||
if (jdkName != null) {
|
||||
element.setAttribute("jdk", jdkName);
|
||||
}
|
||||
String buildTarget = properties.getBuildTargetHashString();
|
||||
if (buildTarget != null) {
|
||||
element.setAttribute("sdk", buildTarget);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
@@ -69,7 +82,7 @@ public class JpsAndroidModelLoaderExtension extends JpsModelLoaderExtension {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsSdkPropertiesLoader<?>> getSdkPropertiesLoaders() {
|
||||
public List<? extends JpsSdkPropertiesSerializer<?>> getSdkPropertiesLoaders() {
|
||||
return Arrays.asList(SDK_PROPERTIES_LOADER);
|
||||
}
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
org.jetbrains.jps.devkit.model.impl.JpsDevKitModelLoaderExtension
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.jps.devkit.model.impl.JpsDevKitModelSerializerExtension
|
||||
+24
-15
@@ -23,10 +23,9 @@ import org.jetbrains.jps.devkit.model.JpsIdeaSdkProperties;
|
||||
import org.jetbrains.jps.devkit.model.JpsIdeaSdkType;
|
||||
import org.jetbrains.jps.devkit.model.JpsPluginModuleProperties;
|
||||
import org.jetbrains.jps.devkit.model.JpsPluginModuleType;
|
||||
import org.jetbrains.jps.model.serialization.JpsLoaderBase;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelLoaderExtension;
|
||||
import org.jetbrains.jps.model.serialization.JpsModulePropertiesLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkPropertiesLoader;
|
||||
import org.jetbrains.jps.model.serialization.*;
|
||||
import org.jetbrains.jps.model.serialization.JpsModulePropertiesSerializer;
|
||||
import org.jetbrains.jps.model.serialization.JpsSdkPropertiesSerializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -34,38 +33,48 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsDevKitModelLoaderExtension extends JpsModelLoaderExtension {
|
||||
public class JpsDevKitModelSerializerExtension extends JpsModelSerializerExtension {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsModulePropertiesLoader<?>> getModulePropertiesLoaders() {
|
||||
return Arrays.asList(new JpsPluginModulePropertiesLoader());
|
||||
public List<? extends JpsModulePropertiesSerializer<?>> getModulePropertiesSerializers() {
|
||||
return Arrays.asList(new JpsPluginModulePropertiesSerializer());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsSdkPropertiesLoader<?>> getSdkPropertiesLoaders() {
|
||||
return Arrays.asList(new JpsIdeaSdkPropertiesLoader());
|
||||
public List<? extends JpsSdkPropertiesSerializer<?>> getSdkPropertiesLoaders() {
|
||||
return Arrays.asList(new JpsIdeaSdkPropertiesSerializer());
|
||||
}
|
||||
|
||||
private static class JpsIdeaSdkPropertiesLoader extends JpsSdkPropertiesLoader<JpsIdeaSdkProperties> {
|
||||
public JpsIdeaSdkPropertiesLoader() {
|
||||
private static class JpsIdeaSdkPropertiesSerializer extends JpsSdkPropertiesSerializer<JpsIdeaSdkProperties> {
|
||||
private static final String SANDBOX_HOME_FIELD = "mySandboxHome";
|
||||
private static final String JDK_NAME_ATTRIBUTE = "sdk";
|
||||
|
||||
public JpsIdeaSdkPropertiesSerializer() {
|
||||
super("IDEA JDK", JpsIdeaSdkType.INSTANCE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsIdeaSdkProperties loadProperties(String homePath, String version, @Nullable Element propertiesElement) {
|
||||
String sandboxHome = null;
|
||||
String jdkName = null;
|
||||
if (propertiesElement != null) {
|
||||
sandboxHome = JDOMExternalizerUtil.readField(propertiesElement, "mySandboxHome");
|
||||
jdkName = propertiesElement.getAttributeValue("sdk");
|
||||
sandboxHome = JDOMExternalizerUtil.readField(propertiesElement, SANDBOX_HOME_FIELD);
|
||||
jdkName = propertiesElement.getAttributeValue(JDK_NAME_ATTRIBUTE);
|
||||
}
|
||||
return new JpsIdeaSdkProperties(homePath, version, sandboxHome, jdkName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveProperties(@NotNull JpsIdeaSdkProperties properties, @NotNull Element element) {
|
||||
JDOMExternalizerUtil.writeField(element, SANDBOX_HOME_FIELD, properties.getSandboxHome());
|
||||
element.setAttribute(JDK_NAME_ATTRIBUTE, properties.getJdkName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class JpsPluginModulePropertiesLoader extends JpsModulePropertiesLoader<JpsPluginModuleProperties> {
|
||||
private JpsPluginModulePropertiesLoader() {
|
||||
private static class JpsPluginModulePropertiesSerializer extends JpsModulePropertiesSerializer<JpsPluginModuleProperties> {
|
||||
private JpsPluginModulePropertiesSerializer() {
|
||||
super(JpsPluginModuleType.INSTANCE, "PLUGIN_MODULE");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user