Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into 183/TipsAnd…
Browse files Browse the repository at this point in the history
…Tricks2
  • Loading branch information
victor-matchenko committed Oct 24, 2018
2 parents 11dfa44 + 2af77ef commit 92ad0de
Show file tree
Hide file tree
Showing 53 changed files with 19,094 additions and 19,810 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 JetBrains s.r.o.
* Copyright 2003-2018 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,6 @@
import jetbrains.mps.tool.builder.make.ReducedMakeFacetConfiguration;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.builders.java.JavaBuilderUtil;
import org.jetbrains.jps.incremental.CompileContext;
import org.jetbrains.jps.incremental.ModuleBuildTarget;
import org.jetbrains.jps.incremental.ModuleLevelBuilder.OutputConsumer;
Expand All @@ -53,7 +52,6 @@
/**
* User: fyodor
* Date: 12/19/12
* TODO Something with {@link ReducedMakeFacetConfiguration#getFileHashes()}. It is possible to persist any caches by a jps mechanism.
*/
public class MPSMakeMediator {
@NonNls
Expand Down Expand Up @@ -109,9 +107,7 @@ private MakeSession createCleanMakeSession() {
return new MakeSession(myProject, myMessageHandler, true) {
@Override
public IScript toScript(ScriptBuilder scriptBuilder) {
scriptBuilder.withFacetNames(
new IFacet.Name("jetbrains.mps.make.reduced.ReportFiles"),
new IFacet.Name("jetbrains.mps.make.reduced.CollectHashes"));
scriptBuilder.withFacetNames(new IFacet.Name("jetbrains.mps.make.reduced.ReportFiles"));
return scriptBuilder.toScript();
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 JetBrains s.r.o.
* Copyright 2003-2018 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,7 @@
import jetbrains.mps.jps.project.JpsSolutionIdea;
import jetbrains.mps.library.ModulesMiner;
import jetbrains.mps.library.ModulesMiner.ModuleHandle;
import jetbrains.mps.persistence.DefaultModelRoot;
import jetbrains.mps.persistence.MementoImpl;
import jetbrains.mps.persistence.PersistenceRegistry;
import jetbrains.mps.project.ModuleId;
Expand Down Expand Up @@ -150,15 +151,21 @@ private void initRepository(CompileContext context, String languages, String rep
}

// use optimized implementation of default model root
PersistenceRegistry.getInstance().setModelRootFactory(PersistenceRegistry.DEFAULT_MODEL_ROOT, new ModelRootFactory() {
final PersistenceRegistry persistenceRegistry = PersistenceRegistry.getInstance();
final ModelRootFactory originalDefaultModelRootFactory = persistenceRegistry.getModelRootFactory(PersistenceRegistry.DEFAULT_MODEL_ROOT);
persistenceRegistry.setModelRootFactory(PersistenceRegistry.DEFAULT_MODEL_ROOT, new ModelRootFactory() {
@NotNull
@Override
public ModelRoot create() {
return new CachedDefaultModelRoot(myRepo);
// I know it's not nice to assume specific instance to come from the factory, but I don't like this CachedDefaultModelRoot anyway
// First, I'm not sure we earn that much with it (we save fs walk at the price of limited set of supported models).
// Second, even if we do save a lot, I'd rather avoid use of ModelRoot at all, and just feed models into SModule (or use custom MR type and
// serialize models I can not recognize (custom persistence) in a supported format, e.g. binary).
return new CachedDefaultModelRoot(myRepo, (DefaultModelRoot) originalDefaultModelRootFactory.create());
}
});

PersistenceRegistry.getInstance().setModelRootFactory(PersistenceRegistry.JAVA_CLASSES_ROOT, new ModelRootFactory() {
persistenceRegistry.setModelRootFactory(PersistenceRegistry.JAVA_CLASSES_ROOT, new ModelRootFactory() {
@NotNull
@Override
public ModelRoot create() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2014 JetBrains s.r.o.
* Copyright 2003-2018 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,9 @@
package jetbrains.mps.jps.persistence;

import jetbrains.mps.extapi.persistence.FileDataSource;
import jetbrains.mps.extapi.persistence.ModelRootBase;
import jetbrains.mps.extapi.persistence.SourceRoot;
import jetbrains.mps.extapi.persistence.SourceRootKinds;
import jetbrains.mps.idea.core.module.CachedModelData;
import jetbrains.mps.idea.core.module.CachedModelData.Kind;
import jetbrains.mps.idea.core.module.CachedModuleData;
Expand All @@ -32,8 +35,11 @@
import jetbrains.mps.util.JavaNameUtil;
import jetbrains.mps.vfs.IFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.mps.openapi.model.SModel;
import org.jetbrains.mps.openapi.model.SModelId;
import org.jetbrains.mps.openapi.module.SModule;
import org.jetbrains.mps.openapi.persistence.Memento;
import org.jetbrains.mps.openapi.persistence.ModelFactory;
import org.jetbrains.mps.openapi.persistence.PersistenceFacade;

Expand All @@ -48,12 +54,58 @@
* evgeny, 12/11/12
* XXX imo, the only justification for this class to subclass DefaultModelRoot is that there's code in MPS that does instanceof check
*/
public class CachedDefaultModelRoot extends DefaultModelRoot {
public class CachedDefaultModelRoot extends ModelRootBase {

private CachedRepositoryData myCachedRepository;
private final CachedRepositoryData myCachedRepository;
private final DefaultModelRoot myDelegate;

public CachedDefaultModelRoot(CachedRepositoryData repo) {
public CachedDefaultModelRoot(CachedRepositoryData repo, DefaultModelRoot delegate) {
myCachedRepository = repo;
myDelegate = delegate;
}

@Override
public String getType() {
return myDelegate.getType();
}

@Override
public String getPresentation() {
return getClass().getName();
}

@Nullable
@Override
public SModel getModel(@NotNull SModelId id) {
// assertCanRead(); - private in superclass
return getModels().stream().filter(m -> id.equals(m.getModelId())).findFirst().orElse(null);
}

@Override
public boolean canCreateModels() {
return false;
}

@Override
public boolean canCreateModel(@NotNull String modelName) {
return false;
}

@Nullable
@Override
public SModel createModel(@NotNull String modelName) {
return null;
}

@Override
public void save(@NotNull Memento memento) {
// intentionally no-op
}

@Override
public void load(@NotNull Memento memento) {
// get delegate ready to load models if we fail
myDelegate.load(memento);
}

@NotNull
Expand All @@ -64,35 +116,35 @@ public Iterable<SModel> loadModels() {
module = ((Generator) module).getSourceLanguage();
}
if (module == null) {
return super.loadModels();
return myDelegate.loadModels();
}

CachedModuleData moduleData = myCachedRepository.getModuleData(module.getModuleReference());
if (moduleData == null) {
return super.loadModels();
return myDelegate.loadModels();
}

List<CachedModelData> models = moduleData.getModels(this);
List<CachedModelData> models = moduleData.getModels(myDelegate);
if (models == null) {
return super.loadModels();
return myDelegate.loadModels();
}

List<SModel> result = new ArrayList<SModel>();
Map<String, String> options = new HashMap<String, String>();
options.put(ModelFactory.OPTION_MODULEREF, module.getModuleReference().toString());

for (CachedModelData mdata : models) {
IFile file = getFileSystem().getFile(mdata.getFile());
IFile file = myDelegate.getFileSystem().getFile(mdata.getFile());

Object header = mdata.getHeader();
if (mdata.getCacheKind() == CachedModelData.Kind.Binary) {
result.add(BinaryModelFactory.createFromHeader(((SModelHeader) header), new FileDataSource(file, this)));
result.add(BinaryModelFactory.createFromHeader(((SModelHeader) header), new FileDataSource(file)));
} else if (mdata.getCacheKind() == CachedModelData.Kind.Regular) {
result.add(DefaultModelPersistence.createFromHeader((SModelHeader) header, new FileDataSource(file, this)));
result.add(DefaultModelPersistence.createFromHeader((SModelHeader) header, new FileDataSource(file)));
} else if (mdata.getCacheKind() == Kind.RegularFilePerRoot) {
result.add(FilePerRootModelFactory.createFromHeader((SModelHeader) header, new FilePerRootDataSource(file, this)));
} else {
FileDataSource source = new FileDataSource(file, this);
FileDataSource source = new FileDataSource(file);
String fileName = file.getName();
String extension = FileUtil.getExtension(fileName);

Expand All @@ -115,8 +167,8 @@ public Iterable<SModel> loadModels() {
private void fillOptions(IFile file, Map<String, String> options) {
String relPath = null;
String filePath = file.getPath().replace("\\", "/");
for (String path : getFiles(SOURCE_ROOTS)) {
String normalized = FileUtil.getAbsolutePath(path).replace("\\", "/");
for (SourceRoot sr : myDelegate.getSourceRoots(SourceRootKinds.SOURCES)) {
String normalized = sr.getAbsolutePath().getPath().replace("\\", "/");
if (!normalized.endsWith("/")) {
normalized = normalized + "/";
}
Expand All @@ -126,7 +178,6 @@ private void fillOptions(IFile file, Map<String, String> options) {
}
}

options.put(ModelFactory.OPTION_RELPATH, relativize(filePath, getContentDirectory()));
options.remove(ModelFactory.OPTION_PACKAGE);
options.remove(ModelFactory.OPTION_MODELNAME);
if (relPath != null) {
Expand Down
8 changes: 4 additions & 4 deletions build/update.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
url="https://www.jetbrains.com/mps/download"
feedback="http://youtrack.jetbrains.net"
majorVersion="2018" minorVersoin="2">
<build number="182.1460" version="2018.2.3">
<message>JetBrains MPS 2018.2.3 is available.</message>
<build number="182.1542" version="2018.2.5">
<message>JetBrains MPS 2018.2.5 is available.</message>
<button name="Download" url="https://www.jetbrains.com/mps/download" download="true"/>
</build>
</channel>
Expand All @@ -222,8 +222,8 @@
url="https://www.jetbrains.com/mps/download"
feedback="http://youtrack.jetbrains.net"
majorVersion="2018" minorVersoin="2">
<build number="182.1490" version="2018.2.4">
<message>JetBrains MPS 2018.2.4 is available.</message>
<build number="182.1542" version="2018.2.5">
<message>JetBrains MPS 2018.2.5 is available.</message>
<button name="Download" url="https://www.jetbrains.com/mps/download" download="true"/>
</build>
</channel>
Expand Down
10 changes: 7 additions & 3 deletions core/kernel/source/jetbrains/mps/core/platform/MPSCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import jetbrains.mps.extapi.module.SRepositoryRegistry;
import jetbrains.mps.extapi.persistence.ModelFactoryRegistry;
import jetbrains.mps.extapi.persistence.ModelFactoryService;
import jetbrains.mps.extapi.persistence.datasource.DataSourceFactoryRuleCoreService;
import jetbrains.mps.extapi.persistence.datasource.DataSourceFactoryRuleService;
import jetbrains.mps.library.LibraryInitializer;
import jetbrains.mps.persistence.PersistenceRegistry;
Expand Down Expand Up @@ -78,6 +77,7 @@ public final class MPSCore extends ComponentPlugin implements ComponentHost {
private PathMacros myPathMacros;
private ExtensionRegistry myExtensionRegistry;
private DataSourceFactoryRuleService myDataSourceService;
private ModelFactoryService myModelFactoryService;
private ModelsAutoImportsManager myAutoImportsManager;

/**
Expand All @@ -98,6 +98,7 @@ public void init() {
public void dispose() {
super.dispose();
myAutoImportsManager = null;
myModelFactoryService = null;
myClassLoaderManager = null;
myLibraryInitializer = null;
myPersistenceFacade = null;
Expand All @@ -115,8 +116,8 @@ private void doInit() {
// in fact, could be part of PersistenceRegistry to minimize number of components. OTOH, complicates access
// to the instance, findComponent(PersistenceRegistry.class).getDataSourceService() is longer than just findComponent(DataSourceFactoryRuleService.class)
myDataSourceService = init(new DataSourceFactoryRuleService());
init(new DataSourceFactoryRuleCoreService(myDataSourceService));
myPersistenceFacade = init(new PersistenceRegistry(myDataSourceService));
myModelFactoryService = init(new ModelFactoryService());
myPersistenceFacade = init(new PersistenceRegistry(myModelFactoryService, myDataSourceService));
myModuleFacetsRegistry = init(new FacetsRegistry());

myRepositoryRegistry = init(new SRepositoryRegistry());
Expand Down Expand Up @@ -249,6 +250,9 @@ public <T extends CoreComponent> T findComponent(@NotNull Class<T> componentClas
if (DataSourceFactoryRuleService.class.isAssignableFrom(componentClass)) {
return componentClass.cast(myDataSourceService);
}
if (ModelFactoryService.class.isAssignableFrom(componentClass)) {
return componentClass.cast(myModelFactoryService);
}
if (ModelsAutoImportsManager.class.equals(componentClass)) {
return componentClass.cast(myAutoImportsManager);
}
Expand Down
Loading

0 comments on commit 92ad0de

Please sign in to comment.