Skip to content

Commit b0c4a54

Browse files
Exclude children when computing the external references of a Package (#1211)
* Exclude children when computing the external references of a Package * Add a test for serializing repos singly vs multiply
1 parent b39aee7 commit b0c4a54

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/serialization/compiler/metadata/ConcreteElementMetadataGenerator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ class ConcreteElementMetadataGenerator
6464
private final ReferenceIdProvider referenceIdProvider;
6565
private final ContainingElementIndex containingElementIndex;
6666
private final ProcessorSupport processorSupport;
67-
private final MapIterable<String, ImmutableList<String>> backReferenceProperties = M3PropertyPaths.BACK_REFERENCE_PROPERTY_PATHS.groupByUniqueKey(ImmutableList::getLast, Maps.mutable.ofInitialCapacity(M3PropertyPaths.BACK_REFERENCE_PROPERTY_PATHS.size()));
67+
private final MapIterable<String, ImmutableList<String>> backReferenceProperties = M3PropertyPaths.BACK_REFERENCE_PROPERTY_PATHS.groupByUniqueKey(
68+
ImmutableList::getLast,
69+
Maps.mutable.ofInitialCapacity(M3PropertyPaths.BACK_REFERENCE_PROPERTY_PATHS.size() + 1))
70+
.withKeyValue(M3PropertyPaths.children.getLast(), M3PropertyPaths.children);
6871
private final ConcurrentMutableMap<CoreInstance, String> elementPathCache = ConcurrentHashMap.newMap();
6972
private final ConcurrentMutableMap<CoreInstance, BackReferenceCollector> backRefCollectorCache = ConcurrentHashMap.newMap();
7073

legend-pure-core/legend-pure-m3-core/src/test/java/org/finos/legend/pure/m3/generator/compiler/TestPureCompilerBinaryGenerator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ public void testSerializeWithExcludedModule() throws IOException
105105
assertModuleNotSerialized(deserializer, outputDirectory, OTHER_TEST_REPO);
106106
}
107107

108+
@Test
109+
public void testSerializeSingleVsMultiple() throws IOException
110+
{
111+
Path multiOutputDir = TMP.newFolder().toPath();
112+
PureCompilerBinaryGenerator.serializeModules(multiOutputDir, Lists.immutable.with(PLATFORM, TEST_REPO, OTHER_TEST_REPO));
113+
114+
Path singleOutputDir = TMP.newFolder().toPath();
115+
PureCompilerBinaryGenerator.serializeModules(singleOutputDir, Lists.immutable.with(PLATFORM));
116+
PureCompilerBinaryGenerator.serializeModules(singleOutputDir, Lists.immutable.with(TEST_REPO));
117+
PureCompilerBinaryGenerator.serializeModules(singleOutputDir, Lists.immutable.with(OTHER_TEST_REPO));
118+
119+
assertDirectoriesEquivalent(multiOutputDir, singleOutputDir);
120+
}
121+
108122
private static void assertModuleSerialized(FileDeserializer deserializer, Path outputDirectory, String moduleName)
109123
{
110124
Assert.assertTrue(moduleName + " manifest should exist", deserializer.moduleManifestExists(outputDirectory, moduleName));

legend-pure-core/legend-pure-m3-core/src/test/java/org/finos/legend/pure/m3/serialization/compiler/metadata/TestModuleMetadataGenerator.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.finos.legend.pure.m3.serialization.filesystem.repository.GenericCodeRepository;
2727
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage;
2828
import org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.composite.CompositeCodeStorage;
29+
import org.finos.legend.pure.m3.serialization.runtime.PureRuntime;
30+
import org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder;
2931
import org.finos.legend.pure.m3.tools.GraphTools;
3032
import org.junit.After;
3133
import org.junit.Assert;
@@ -123,8 +125,20 @@ public void testAllModules()
123125
{
124126
Assert.assertEquals(
125127
getAllModuleMetadata().sortThisBy(ModuleMetadata::getName),
126-
this.generator.generateAllModuleMetadata().sortThisBy(ModuleMetadata::getName)
127-
);
128+
this.generator.generateAllModuleMetadata().sortThisBy(ModuleMetadata::getName));
129+
}
130+
131+
@Test
132+
public void testIndividualVsMultiRepoGeneration()
133+
{
134+
ModuleMetadata platformFromMultiRepo = this.generator.generateModuleMetadata("platform");
135+
136+
CompositeCodeStorage platformOnlyStorage = new CompositeCodeStorage(
137+
new ClassLoaderCodeStorage(runtime.getCodeStorage().getRepository("platform")));
138+
PureRuntime platformOnlyRuntime = new PureRuntimeBuilder(platformOnlyStorage).buildAndInitialize();
139+
ModuleMetadata platformFromSingleRepo = ModuleMetadataGenerator.fromPureRuntime(platformOnlyRuntime).generateModuleMetadata("platform");
140+
141+
Assert.assertEquals(platformFromMultiRepo, platformFromSingleRepo);
128142
}
129143

130144
private ModuleMetadata getModuleMetadata(String moduleName)

0 commit comments

Comments
 (0)