diff --git a/transformer/transformer.go b/transformer/transformer.go index 0ec0c51e5..017e4c087 100644 --- a/transformer/transformer.go +++ b/transformer/transformer.go @@ -409,6 +409,7 @@ func Transform(planArtifacts []plantypes.PlanArtifact, sourceDir, outputPath str var allArtifacts []transformertypes.Artifact newArtifactsToProcess := []transformertypes.Artifact{} pathMappings := []transformertypes.PathMapping{} + defaultNewArtifactsToProcess := []transformertypes.Artifact{} iteration := 1 // transform default transformers graph := graphtypes.NewGraph() @@ -419,7 +420,7 @@ func Transform(planArtifacts []plantypes.PlanArtifact, sourceDir, outputPath str if err != nil { logrus.Errorf("failed to transform using the transformer %s. Error: %q", tDefaultConfig.Name, err) } - newArtifactsToProcess = append(newArtifactsToProcess, defaultArtifacts...) + defaultNewArtifactsToProcess = append(defaultNewArtifactsToProcess, defaultArtifacts...) pathMappings = append(pathMappings, newPathMappings...) } logrus.Infof("Iteration %d", iteration) @@ -442,10 +443,11 @@ func Transform(planArtifacts []plantypes.PlanArtifact, sourceDir, outputPath str } // logging - allArtifacts = newArtifactsToProcess for _, artifact := range newArtifactsToProcess { artifact.Configs[graphtypes.GraphSourceVertexKey] = startVertexId } + newArtifactsToProcess = append(newArtifactsToProcess, defaultNewArtifactsToProcess...) + allArtifacts = newArtifactsToProcess // logging for { @@ -558,16 +560,15 @@ func transform(newArtifactsToProcess, allArtifacts []transformertypes.Artifact, return pathMappings, newArtifactsCreated, nil } -func runSingleTransform(artifactsToProcess, allArtifacts []transformertypes.Artifact, transformer Transformer, tconfig transformertypes.Transformer, env *environment.Environment, graph *graphtypes.Graph, iteration int) ([]transformertypes.PathMapping, []transformertypes.Artifact, error) { +func runSingleTransform(artifactsToProcess, allArtifacts []transformertypes.Artifact, transformer Transformer, tconfig transformertypes.Transformer, env *environment.Environment, graph *graphtypes.Graph, iteration int) (newPathMappings []transformertypes.PathMapping, newArtifacts []transformertypes.Artifact, err error) { if err := env.Reset(); err != nil { return nil, nil, fmt.Errorf("failed to reset the environment: %+v Error: %q", env, err) } - newPathMappings, newArtifacts, err := transformer.Transform( + newPathMappings, newArtifacts, err = transformer.Transform( *env.Encode(&artifactsToProcess).(*[]transformertypes.Artifact), *env.Encode(&allArtifacts).(*[]transformertypes.Artifact), ) - // logging { vertexName := fmt.Sprintf("iteration: %d\nclass: %s\nname: %s", iteration, tconfig.Spec.Class, tconfig.Name) @@ -580,6 +581,11 @@ func runSingleTransform(artifactsToProcess, allArtifacts []transformertypes.Arti "pathMappings": summarizePathMappings(newPathMappings), }, ) + // transformers that are invoked by default has source vertex as start + if tconfig.Spec.InvokedByDefault.Enabled { + edgeName := fmt.Sprintf("%d -> %d (invoked by default)", 0, targetVertexId) + graph.AddEdge(graph.SourceVertexId, targetVertexId, edgeName, nil) + } for _, artifact := range artifactsToProcess { sourceVertexId, ok := artifact.Configs[graphtypes.GraphSourceVertexKey].(int) if !ok { diff --git a/types/graph/graph.go b/types/graph/graph.go index e487bbfd1..71bf2b5bf 100644 --- a/types/graph/graph.go +++ b/types/graph/graph.go @@ -18,11 +18,12 @@ package graph // Graph contains transformers and artifacts being passed between them. type Graph struct { - vertexId int - edgeId int - Version string `json:"version"` - Vertices map[int]Vertex `json:"vertices,omitempty"` - Edges map[int]Edge `json:"edges,omitempty"` + SourceVertexId int + vertexId int + edgeId int + Version string `json:"version"` + Vertices map[int]Vertex `json:"vertices,omitempty"` + Edges map[int]Edge `json:"edges,omitempty"` } // Vertex is a single transformer. @@ -100,11 +101,12 @@ const ( // NewGraph creates a new graph. func NewGraph() *Graph { return &Graph{ - vertexId: -1, - edgeId: -1, - Version: GraphFileVersion, - Vertices: map[int]Vertex{}, - Edges: map[int]Edge{}, + SourceVertexId: -1, + vertexId: -1, + edgeId: -1, + Version: GraphFileVersion, + Vertices: map[int]Vertex{}, + Edges: map[int]Edge{}, } } @@ -112,6 +114,9 @@ func NewGraph() *Graph { func (g *Graph) AddVertex(name string, iteration int, data map[string]interface{}) int { g.vertexId++ g.Vertices[g.vertexId] = Vertex{Id: g.vertexId, Iteration: iteration, Name: name, Data: data} + if g.SourceVertexId == -1 { + g.SourceVertexId = g.vertexId + } return g.vertexId }