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/11 15:48:43 UTC

[GitHub] [skywalking-eyes] kezhenxu94 commented on a change in pull request #53: add support for resolving jars' licenses

kezhenxu94 commented on a change in pull request #53:
URL: https://github.com/apache/skywalking-eyes/pull/53#discussion_r686957028



##########
File path: pkg/deps/jar.go
##########
@@ -0,0 +1,136 @@
+//
+// 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"
+	"path/filepath"
+	"regexp"
+
+	"github.com/apache/skywalking-eyes/license-eye/internal/logger"
+	"github.com/apache/skywalking-eyes/license-eye/pkg/license"
+)
+
+type JarResolver struct{}
+
+func (resolver *JarResolver) CanResolve(jarFile string) bool {
+	return filepath.Ext(jarFile) == ".jar"
+}
+
+func (resolver *JarResolver) Resolve(jarFile string, report *Report) error {
+	state := NotFound
+	if err := resolver.ResolveJar(&state, jarFile, report); err != nil {

Review comment:
       In this resolver (jar resolver), we should support a path pattern like `dist/**/*.jar` and expand all the `.jar` files and resolve their licenses, the current feature in this PR only support a singe `.jar` file, right?

##########
File path: pkg/deps/jar_test.go
##########
@@ -0,0 +1,148 @@
+//
+// 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_test
+
+import (
+	"fmt"
+	"io/ioutil"
+	"os"
+	"os/exec"
+	"path/filepath"
+	"testing"
+
+	"github.com/apache/skywalking-eyes/license-eye/pkg/deps"
+)
+
+func TestCanResolveJarFile(t *testing.T) {
+	resolver := new(deps.JarResolver)
+	for _, test := range []struct {
+		fileName string
+		exp      bool
+	}{
+		{"1.jar", true},
+		{"/tmp/1.jar", true},
+		{"1.jar2", false},
+		{"protobuf-java-3.13.0.jar", true},
+		{"slf4j-api-1.7.25.jar", true},
+	} {
+		b := resolver.CanResolve(test.fileName)
+		if b != test.exp {
+			t.Errorf("JarResolver.CanResolve(\"%v\") = %v, want %v", test.fileName, b, test.exp)
+		}
+	}
+}
+
+func copyJars(t *testing.T, pomFile, content string) ([]string, error) {
+	dir := filepath.Dir(pomFile)
+
+	if err := os.Chdir(dir); err != nil {
+		return nil, err
+	}
+
+	if err := dumpPomFile(pomFile, content); err != nil {
+		return nil, err
+	}
+
+	if _, err := exec.Command("mvn", "dependency:copy-dependencies", "-DoutputDirectory=./lib", "-DincludeScope=runtime").Output(); err != nil {

Review comment:
       This is not portable, users / developers don't have `mvn` installed won't be able to run this test




-- 
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