kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/extractors/gcp/config/maven.go (about)

     1  /*
     2   * Copyright 2018 The Kythe Authors. All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *   http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package config
    18  
    19  import (
    20  	"path"
    21  	"path/filepath"
    22  
    23  	"kythe.io/kythe/go/extractors/constants"
    24  
    25  	rpb "kythe.io/kythe/proto/repo_go_proto"
    26  
    27  	"google.golang.org/api/cloudbuild/v1"
    28  )
    29  
    30  type mavenGenerator struct{}
    31  
    32  // preExtractSteps implements parts of buildSystemElaborator
    33  func (m mavenGenerator) preExtractSteps() []*cloudbuild.BuildStep {
    34  	return []*cloudbuild.BuildStep{
    35  		javaExtractorsStep(),
    36  	}
    37  }
    38  
    39  // extractSteps implements parts of buildSystemElaborator
    40  func (m mavenGenerator) extractSteps(corpus string, target *rpb.ExtractionTarget, idSuffix string) []*cloudbuild.BuildStep {
    41  	buildfile := path.Join(codeDirectory, target.Path)
    42  	targetPath, _ := filepath.Split(target.Path)
    43  	return []*cloudbuild.BuildStep{
    44  		preprocessorStep(buildfile, idSuffix),
    45  		&cloudbuild.BuildStep{
    46  			Name:       constants.MvnJDK8Image,
    47  			Entrypoint: "mvn",
    48  			Args: []string{
    49  				"clean",
    50  				// TODO(#3126): If compile-test has to be done as a separate
    51  				// step, then we also need to fix this in the same way as we do
    52  				// for multiple repo support.  Probably this would need to be
    53  				// done with multiple steps (but making sure to not clobber
    54  				// output).
    55  				// The alternative here is to fall back to using clean install,
    56  				// which should also work.
    57  				"compile",
    58  				"test-compile",
    59  				"-f", // Points directly at a specific pom.xml file:
    60  				buildfile,
    61  				"-Dmaven.compiler.forceJavacCompilerUse=true",
    62  				"-Dmaven.compiler.fork=true",
    63  				"-Dmaven.compiler.executable=" + constants.DefaultJavacWrapperLocation,
    64  			},
    65  			Volumes: []*cloudbuild.Volume{
    66  				&cloudbuild.Volume{
    67  					Name: javaVolumeName,
    68  					Path: constants.DefaultExtractorsDir,
    69  				},
    70  			},
    71  			Env: []string{
    72  				"KYTHE_CORPUS=" + corpus,
    73  				"KYTHE_OUTPUT_DIRECTORY=" + outputDirectory,
    74  				"KYTHE_ROOT_DIRECTORY=" + filepath.Join(codeDirectory, targetPath),
    75  				"JAVAC_EXTRACTOR_JAR=" + constants.DefaultJavaExtractorLocation,
    76  				"REAL_JAVAC=" + constants.DefaultJavacLocation,
    77  				"KYTHE_JAVA_RUNTIME_OPTIONS=-Xbootclasspath/p:" + constants.DefaultJava9ToolsLocation,
    78  			},
    79  			Id:      extractStepID + idSuffix,
    80  			WaitFor: []string{javaArtifactsID, preStepID + idSuffix},
    81  		},
    82  	}
    83  }
    84  
    85  // postExtractSteps implements parts of buildSystemElaborator
    86  func (m mavenGenerator) postExtractSteps(corpus string) []*cloudbuild.BuildStep {
    87  	return []*cloudbuild.BuildStep{
    88  		zipMergeStep(corpus),
    89  	}
    90  }
    91  
    92  // defaultConfigFile implements parts of buildSystemElaborator
    93  func (m mavenGenerator) defaultExtractionTarget() *rpb.ExtractionTarget {
    94  	return &rpb.ExtractionTarget{
    95  		Path: "pom.xml",
    96  	}
    97  }