MoGuGuai-hzr commented on a change in pull request #50:
URL: https://github.com/apache/skywalking-eyes/pull/50#discussion_r677217614



##########
File path: pkg/deps/maven.go
##########
@@ -0,0 +1,229 @@
+//
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package deps
+
+import (
+       "archive/zip"
+       "bufio"
+       "bytes"
+       "fmt"
+       "io"
+       "io/fs"
+       "io/ioutil"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "regexp"
+
+       "github.com/apache/skywalking-eyes/license-eye/internal/logger"
+       "github.com/apache/skywalking-eyes/license-eye/pkg/license"
+)
+
+// TempDirGenerator Create and destroy one temporary directory
+type TempDirGenerator interface {
+       Create() (string, error)
+       Destroy()
+}
+
+func NewTempDirGenerator() TempDirGenerator {
+       return new(tempDir)
+}
+
+// tempDir an implementation of the TempDirGenerator
+type tempDir struct {
+       dir string
+}
+
+func (t *tempDir) Create() (string, error) {
+       tmpDir, err := ioutil.TempDir("", "")
+       if err != nil {
+               return "", err
+       }
+       t.dir = tmpDir
+       return tmpDir, nil
+}
+
+func (t *tempDir) Destroy() {
+       if t.dir == "" {
+               logger.Log.Errorf("the temporary directory does not exist")
+               return
+       }
+
+       err := os.RemoveAll(t.dir)
+       if err != nil {
+               logger.Log.Errorln(err)
+       }
+}
+
+var possiblePomFileName = regexp.MustCompile(`(?i)^pom\.xml|.+\.pom$`)
+
+type MavenPomResolver struct {
+       maven string
+}
+
+// CanResolve determine whether the file can be resolve by name of the file
+func (resolver *MavenPomResolver) CanResolve(mavenPomFile string) bool {
+       // switch to the directory where the file is located for searching mvnw
+       dir, base := resolver.Split(mavenPomFile)
+       if err := os.Chdir(dir); err != nil {
+               logger.Log.Errorf("an error occurred when entering dir <%s> to 
parser file <%s>:%v\n", dir, base, err)
+               return false
+       }
+
+       err := resolver.CheckMVN()
+       if err != nil {
+               logger.Log.Errorln("an error occurred when checking maven 
tool:", err)
+               return false
+       }
+
+       logger.Log.Debugln("Base name:", base)
+       return possiblePomFileName.MatchString(base)
+}
+
+// Split a simple wraper of filepath.Split
+func (resolver *MavenPomResolver) Split(path string) (dir, file string) {
+       dir, file = filepath.Split(path)
+       if dir == "" {
+               dir = "./"
+       }
+       return
+}
+
+// CheckMVN use mvn by default, use mvn if mvnw is not found
+func (resolver *MavenPomResolver) CheckMVN() error {
+       var err error
+
+       logger.Log.Debugln("searching mvnw ...")
+       _, err = exec.Command("./mvnw", "--version").Output()
+       if err == nil {
+               resolver.maven = "./mvnw"
+               logger.Log.Debugln("use mvnw")

Review comment:
       does this mean to modify the log message?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to