import org.opendaylight.yangtools.util.RecursiveObjectLeaker;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
private void collectRequiredSourcesFromLib(
final TreeBasedTable<String, Date, SourceSpecificContext> libSourcesTable,
final Set<SourceSpecificContext> requiredLibs, final SourceSpecificContext source) {
- final Collection<ModuleIdentifier> requiredModules = source.getRequiredModules();
- for (final ModuleIdentifier requiredModule : requiredModules) {
- final SourceSpecificContext libSource = getRequiredLibSource(requiredModule, libSourcesTable);
+ for (final SourceIdentifier requiredSource : source.getRequiredSources()) {
+ final SourceSpecificContext libSource = getRequiredLibSource(requiredSource, libSourcesTable);
if (libSource != null && requiredLibs.add(libSource)) {
collectRequiredSourcesFromLib(libSourcesTable, requiredLibs, libSource);
}
}
}
- private static SourceSpecificContext getRequiredLibSource(final ModuleIdentifier requiredModule,
+ private static SourceSpecificContext getRequiredLibSource(final SourceIdentifier requiredSource,
final TreeBasedTable<String, Date, SourceSpecificContext> libSourcesTable) {
- return requiredModule.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP
- || requiredModule.getRevision() == SimpleDateFormatUtil.DEFAULT_BELONGS_TO_DATE ? getLatestRevision(
- libSourcesTable.row(requiredModule.getName())) : libSourcesTable.get(requiredModule.getName(),
- requiredModule.getRevision());
+ return requiredSource.getRevision() == null ? getLatestRevision(libSourcesTable.row(requiredSource.getName()))
+ : libSourcesTable.get(requiredSource.getName(), QName.parseRevision(requiredSource.getRevision()));
}
private static SourceSpecificContext getLatestRevision(final SortedMap<Date, SourceSpecificContext> sourceMap) {
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
private final A argument;
private YangVersion version;
- private Collection<ModuleIdentifier> requiredModules = ImmutableSet.of();
+ private Collection<SourceIdentifier> requiredSources = ImmutableSet.of();
private ModuleIdentifier identifier;
/**
}
@Override
- public void addRequiredModule(final ModuleIdentifier dependency) {
+ public void addRequiredSource(final SourceIdentifier dependency) {
checkState(sourceContext.getInProgressPhase() == ModelProcessingPhase.SOURCE_PRE_LINKAGE,
"Add required module is allowed only in ModelProcessingPhase.SOURCE_PRE_LINKAGE phase");
- if (requiredModules.isEmpty()) {
- requiredModules = new HashSet<>();
+ if (requiredSources.isEmpty()) {
+ requiredSources = new HashSet<>();
}
- requiredModules.add(dependency);
+ requiredSources.add(dependency);
}
- Collection<ModuleIdentifier> getRequiredModules() {
- return ImmutableSet.copyOf(requiredModules);
+ /**
+ * Return the set of required sources.
+ *
+ * @return Required sources.
+ */
+ Collection<SourceIdentifier> getRequiredSources() {
+ return ImmutableSet.copyOf(requiredSources);
}
@Override
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
currentContext.addMutableStmtToSeal(mutableStatement);
}
- Collection<ModuleIdentifier> getRequiredModules() {
- return root.getRequiredModules();
+ Collection<SourceIdentifier> getRequiredSources() {
+ return root.getRequiredSources();
}
ModuleIdentifier getRootIdentifier() {
import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
}
@Override
- public void addRequiredModule(final ModuleIdentifier dependency) {
- getRoot().addRequiredModule(dependency);
+ public void addRequiredSource(final SourceIdentifier dependency) {
+ getRoot().addRequiredSource(dependency);
}
@Override
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
@Override
public void onPreLinkageDeclared(final StmtContext.Mutable<String, BelongsToStatement,
EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
- belongsToCtx.addRequiredModule(getModuleIdentifier(belongsToCtx));
+ belongsToCtx.addRequiredSource(RevisionSourceIdentifier.create(belongsToCtx.getStatementArgument()));
}
@Override
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_PRE_LINKAGE;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
import com.google.common.base.Verify;
import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
* Based on this information, required modules are searched from library
* sources.
*/
- stmt.addRequiredModule(RevisionImport.getImportedModuleIdentifier(stmt));
+ stmt.addRequiredSource(RevisionImport.getImportedSourceIdentifier(stmt));
final String moduleName = stmt.getStatementArgument();
final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_PRE_LINKAGE);
return recentModuleEntry;
}
- private static ModuleIdentifier getImportedModuleIdentifier(
- final StmtContext<String, ImportStatement, ?> stmt) {
+ static ModuleIdentifier getImportedModuleIdentifier(final StmtContext<String, ImportStatement, ?> stmt) {
Date revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
if (revision == null) {
revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
return ModuleIdentifierImpl.create(stmt.getStatementArgument(), Optional.empty(), Optional.of(revision));
}
+
+ static SourceIdentifier getImportedSourceIdentifier(final StmtContext<String, ImportStatement, ?> stmt) {
+ final StmtContext<Date, ?, ?> revision = findFirstDeclaredSubstatement(stmt, RevisionDateStatement.class);
+ return revision == null ? RevisionSourceIdentifier.create(stmt.getStatementArgument())
+ : RevisionSourceIdentifier.create(stmt.getStatementArgument(), revision.rawStatementArgument());
+ }
}
private static class SemanticVersionImport {
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
import java.util.Collection;
import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
@Override
public void onPreLinkageDeclared(
final Mutable<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> stmt) {
- stmt.addRequiredModule(getIncludeSubmoduleIdentifier(stmt));
+ final StmtContext<Date, ?, ?> revision = findFirstDeclaredSubstatement(stmt, RevisionDateStatement.class);
+ stmt.addRequiredSource(revision == null ? RevisionSourceIdentifier.create(stmt.getStatementArgument())
+ : RevisionSourceIdentifier.create(stmt.getStatementArgument(), revision.rawStatementArgument()));
}
@Override
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
void addMutableStmtToSeal(MutableStatement mutableStatement);
/**
- * Add required module. Based on these dependencies are collected
- * required sources from library sources.
+ * Add required module. Based on these dependencies are collected required sources from library sources.
*
* @param dependency
- * ModuleIdentifier of module required by current root
+ * SourceIdentifier of module required by current root
* context
*/
- void addRequiredModule(ModuleIdentifier dependency);
+ /*
+ * FIXME: this method is used solely during SOURCE_PRE_LINKAGE reactor phase and does not have a corresponding
+ * getter -- which makes it rather strange. At some point this method needs to be deprecated and its
+ * users migrated to use proper global namespace.
+ */
+ void addRequiredSource(SourceIdentifier dependency);
void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);