You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/08/03 01:54:42 UTC

[GitHub] [skywalking-eyes] MoGuGuai-hzr commented on a change in pull request #50: add feature: support resolving pom.xml for maven

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



##########
File path: pkg/deps/maven.go
##########
@@ -0,0 +1,591 @@
+//
+// 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"
+	"encoding/xml"
+	"fmt"
+	"io"
+	"io/ioutil"
+	"os"
+	"os/exec"
+	"path/filepath"
+	"regexp"
+	"strings"
+
+	"golang.org/x/net/html/charset"
+
+	"github.com/apache/skywalking-eyes/license-eye/internal/logger"
+	"github.com/apache/skywalking-eyes/license-eye/pkg/license"
+)
+
+type MavenPomResolver struct {
+	maven string
+	repo  string
+}
+
+// CanResolve determine whether the file can be resolve by name of the file
+func (resolver *MavenPomResolver) CanResolve(mavenPomFile string) bool {
+	base := filepath.Base(mavenPomFile)
+	logger.Log.Debugln("Base name:", base)
+	return base == "pom.xml"
+}
+
+// Resolve resolves licenses of all dependencies declared in the pom.xml file.
+func (resolver *MavenPomResolver) Resolve(mavenPomFile string, report *Report) error {
+	if err := os.Chdir(filepath.Dir(mavenPomFile)); err != nil {
+		return err
+	}
+
+	if err := resolver.CheckMVN(); err != nil {
+		return err
+	}
+
+	deps, err := resolver.LoadDependencies()
+	if err != nil {
+		return err
+	}
+
+	if err := resolver.ResolveDependencies(deps, report); err != nil {
+		return err
+	}
+
+	return nil
+}
+
+// CheckMVN check available maven tools, find local repositories and download all dependencies
+func (resolver *MavenPomResolver) CheckMVN() error {
+	if err := resolver.FindMaven("./mvnw"); err == nil {
+		logger.Log.Debugln("mvnw is found, will use mvnw by default")
+	} else if err := resolver.FindMaven("mvn"); err != nil {
+		return fmt.Errorf("neither found mvnw nor mvn")
+	}
+
+	logger.Log.Debugln("mvnw is not found, will use mvn by default")

Review comment:
       ok, i have removed it




-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org