func()

in pkg/trait/builder.go [356:478]


func (t *builderTrait) builderTask(e *Environment, taskConf *v1.BuildConfiguration) (*v1.BuilderTask, error) {
	maven := v1.MavenBuildSpec{
		MavenSpec: e.Platform.Status.Build.Maven,
	}

	// Add Maven repositories defined in the IntegrationKit or Integration
	if e.IntegrationKit != nil {
		for _, repo := range e.IntegrationKit.Spec.Repositories {
			maven.Repositories = append(maven.Repositories, mvn.NewRepository(repo))
		}
	}
	if e.Integration != nil {
		for _, repo := range e.Integration.Spec.Repositories {
			maven.Repositories = append(maven.Repositories, mvn.NewRepository(repo))
		}
	}

	if t.Strategy != "" {
		t.L.Infof("User defined build strategy %s", t.Strategy)
		found := false
		for _, s := range v1.BuildStrategies {
			if string(s) == t.Strategy {
				found = true
				taskConf.Strategy = s
				break
			}
		}
		if !found {
			var strategies []string
			for _, s := range v1.BuildStrategies {
				strategies = append(strategies, string(s))
			}
			return nil, fmt.Errorf("unknown build strategy: %s. One of [%s] is expected", t.Strategy, strings.Join(strategies, ", "))
		}
	}

	if t.OrderStrategy != "" {
		t.L.Infof("User defined build order strategy %s", t.OrderStrategy)
		found := false
		for _, s := range v1.BuildOrderStrategies {
			if string(s) == t.OrderStrategy {
				found = true
				taskConf.OrderStrategy = s
				break
			}
		}
		if !found {
			var strategies []string
			for _, s := range v1.BuildOrderStrategies {
				strategies = append(strategies, string(s))
			}
			return nil, fmt.Errorf("unknown build order strategy: %s. One of [%s] is expected", t.OrderStrategy, strings.Join(strategies, ", "))
		}
	}

	dependencies := getDependencies(e)

	task := &v1.BuilderTask{
		BaseTask: v1.BaseTask{
			Name:          "builder",
			Configuration: *taskConf,
		},
		BaseImage:    t.getBaseImage(e),
		Runtime:      e.CamelCatalog.Runtime,
		Dependencies: dependencies,
		Maven:        maven,
	}

	if e.Integration != nil && e.Integration.Spec.Git != nil {
		task.Git = e.Integration.Spec.Git
	}

	if task.Maven.Properties == nil {
		task.Maven.Properties = make(map[string]string)
	}
	// User provided build-time properties
	if t.Properties != nil {
		for _, v := range t.Properties {
			key, value := property.SplitPropertyFileEntry(v)
			if len(key) == 0 || len(value) == 0 {
				return nil, fmt.Errorf("maven property must have key=value format, it was %v", v)
			}

			task.Maven.Properties[key] = value
		}
	}

	// Build time property required by master capability
	if e.IntegrationKit != nil && e.IntegrationKit.HasCapability("master") &&
		e.CamelCatalog.Runtime.Capabilities["master"].BuildTimeProperties != nil {
		task.Maven.Properties["camel.k.master.enabled"] = boolean.TrueString
		for _, cp := range e.CamelCatalog.Runtime.Capabilities["master"].BuildTimeProperties {
			task.Maven.Properties[CapabilityPropertyKey(cp.Key, task.Maven.Properties)] = cp.Value
		}
	}

	// User provides a maven profile
	if t.MavenProfiles != nil {
		mavenProfiles := make([]v1.ValueSource, 0)
		for _, v := range t.MavenProfiles {
			if v != "" {
				mavenProfile, err := v1.DecodeValueSource(v, "profile.xml")
				if err != nil {
					return nil, fmt.Errorf("invalid maven profile: %s: %w. ", v, err)
				}
				mavenProfiles = append(mavenProfiles, mavenProfile)
			}
		}
		task.Maven.Profiles = mavenProfiles
	}

	steps := make([]builder.Step, 0)
	steps = append(steps, builder.Project.CommonSteps...)

	// sort steps by phase
	sort.SliceStable(steps, func(i, j int) bool {
		return steps[i].Phase() < steps[j].Phase()
	})

	task.Steps = builder.StepIDsFor(steps...)

	return task, nil
}