Add some tests for maven resovler (#138)

diff --git a/.gitignore b/.gitignore
index 16cbe49..e5df3f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,4 +21,6 @@
 assets/assets.gen.go
 .DS_Store
 coverage.txt
-plantuml.jar
+
+target/
+*.jar
diff --git a/pkg/deps/config.go b/pkg/deps/config.go
index 89219ae..fcdc0f1 100644
--- a/pkg/deps/config.go
+++ b/pkg/deps/config.go
@@ -57,7 +57,9 @@
 	}
 
 	for i, file := range config.Files {
-		config.Files[i] = filepath.Join(filepath.Dir(configFileAbsPath), file)
+		if !strings.HasPrefix(file, "/") {
+			config.Files[i] = filepath.Join(filepath.Dir(configFileAbsPath), file)
+		}
 	}
 
 	if config.Threshold <= 0 {
diff --git a/pkg/deps/maven.go b/pkg/deps/maven.go
index cd7c067..0c5b146 100644
--- a/pkg/deps/maven.go
+++ b/pkg/deps/maven.go
@@ -299,7 +299,10 @@
 			queue = append(queue, depTree)
 		} else if recursive {
 			continue
+		} else {
+			queue = append(queue, depTree.TransitiveDeps...)
 		}
+
 		for len(queue) > 0 {
 			dep := queue[0]
 			queue = queue[1:]
diff --git a/pkg/deps/maven_test.go b/pkg/deps/maven_test.go
index 6a835bb..b9da207 100644
--- a/pkg/deps/maven_test.go
+++ b/pkg/deps/maven_test.go
@@ -20,13 +20,13 @@
 import (
 	"bufio"
 	"embed"
-	"fmt"
 	"io/fs"
 	"os"
 	"path/filepath"
 	"strings"
 	"testing"
 
+	"github.com/apache/skywalking-eyes/pkg/config"
 	"github.com/apache/skywalking-eyes/pkg/deps"
 )
 
@@ -69,85 +69,60 @@
 	return os.MkdirAll(dirName, 0777)
 }
 
-//go:embed testdata/maven/*
+//go:embed testdata/maven/**/*
 var testAssets embed.FS
 
-func TestResolveMaven(t *testing.T) {
-	resolver := new(deps.MavenPomResolver)
-	tempDir := t.TempDir()
-	base := "testdata/maven"
-
-	fs.WalkDir(testAssets, base, func(path string, d fs.DirEntry, err error) error {
+func copy(assetDir, destination string) error {
+	return fs.WalkDir(testAssets, assetDir, func(path string, d fs.DirEntry, err error) error {
 		if err != nil {
 			return err
 		}
 		if d.IsDir() {
 			return nil
 		}
-		filename := filepath.Join(tempDir, strings.Replace(path, base, "", 1))
+		filename := filepath.Join(destination, strings.Replace(path, assetDir, "", 1))
 		if err := ensureDir(filepath.Dir(filename)); err != nil {
 			return err
 		}
 
 		content, err := testAssets.ReadFile(path)
 		if err != nil {
-			t.Error(err)
+			return err
 		}
 		writeFile(filename, string(content))
 
 		return nil
 	})
+}
 
-	pomFile := filepath.Join(tempDir, "pom.xml")
+func TestResolveMaven(t *testing.T) {
+	resolver := new(deps.MavenPomResolver)
 
 	for _, test := range []struct {
-		pomContent string
+		workingDir string
+		testCase   string
 		cnt        int
 	}{
-		{`<?xml version="1.0" encoding="UTF-8"?>
-	<project xmlns="http://maven.apache.org/POM/4.0.0"
-		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-		<modelVersion>4.0.0</modelVersion>
-
-		<groupId>apache</groupId>
-		<artifactId>skywalking-eyes</artifactId>
-		<version>1.0</version>
-
-		<dependencies>
-			<!-- https://mvnrepository.com/artifact/junit/junit -->
-			<dependency>
-				<groupId>junit</groupId>
-				<artifactId>junit</artifactId>
-				<version>4.12</version>
-			</dependency>
-			<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
-			<dependency>
-				<groupId>commons-logging</groupId>
-				<artifactId>commons-logging</artifactId>
-				<version>1.2</version>
-			</dependency>
-			<!-- https://mvnrepository.com/artifact/org.apache.skywalking/skywalking-sharing-server-plugin -->
-			<dependency>
-				<groupId>org.apache.skywalking</groupId>
-				<artifactId>skywalking-sharing-server-plugin</artifactId>
-				<version>8.6.0</version>
-			</dependency>
-			<dependency>
-				<groupId>com.fasterxml.jackson.datatype</groupId>
-				<artifactId>jackson-datatype-jsr310</artifactId>
-				<version>2.13.3</version>
-			</dependency>
-		</dependencies>
-	</project>`, 110},
+		{t.TempDir(), "normal", 110},
+		{t.TempDir(), "exclude", 109},
+		{t.TempDir(), "exclude-recursive", 7},
 	} {
-		_ = writeFile(pomFile, test.pomContent)
+		if err := copy("testdata/maven/base", test.workingDir); err != nil {
+			t.Error(err)
+		}
+		if err := copy(filepath.Join("testdata/maven/cases", test.testCase), test.workingDir); err != nil {
+			t.Error(err)
+		}
 
-		config := deps.ConfigDeps{}
-		config.Finalize("")
+		config, err := config.NewConfigFromFile(filepath.Join(test.workingDir, "licenserc.yaml"))
+		if err != nil {
+			t.Error(err)
+		}
 
+		pomFile := filepath.Join(test.workingDir, "pom.xml")
 		if resolver.CanResolve(pomFile) {
 			report := deps.Report{}
-			if err := resolver.Resolve(pomFile, &config, &report); err != nil {
+			if err := resolver.Resolve(pomFile, config.Dependencies(), &report); err != nil {
 				t.Error(err)
 				return
 			}
@@ -155,7 +130,6 @@
 			if len(report.Resolved)+len(report.Skipped) != test.cnt {
 				t.Errorf("the expected number of jar packages is: %d, but actually: %d. result:\n%v", test.cnt, len(report.Resolved)+len(report.Skipped), report.String())
 			}
-			fmt.Println(report.String())
 		}
 	}
 }
diff --git a/pkg/deps/testdata/maven/.mvn/wrapper/maven-wrapper.properties b/pkg/deps/testdata/maven/base/.mvn/wrapper/maven-wrapper.properties
similarity index 100%
rename from pkg/deps/testdata/maven/.mvn/wrapper/maven-wrapper.properties
rename to pkg/deps/testdata/maven/base/.mvn/wrapper/maven-wrapper.properties
diff --git a/pkg/deps/testdata/maven/mvnw b/pkg/deps/testdata/maven/base/mvnw
similarity index 100%
rename from pkg/deps/testdata/maven/mvnw
rename to pkg/deps/testdata/maven/base/mvnw
diff --git a/pkg/deps/testdata/maven/base/pom.xml b/pkg/deps/testdata/maven/base/pom.xml
new file mode 100644
index 0000000..4b1dea9
--- /dev/null
+++ b/pkg/deps/testdata/maven/base/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the 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.
+  ~ The 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.
+  ~
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>apache</groupId>
+  <artifactId>skywalking-eyes</artifactId>
+  <version>1.0</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.skywalking</groupId>
+      <artifactId>skywalking-sharing-server-plugin</artifactId>
+      <version>8.6.0</version>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.datatype</groupId>
+      <artifactId>jackson-datatype-jsr310</artifactId>
+      <version>2.13.3</version>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/pkg/deps/testdata/maven/cases/exclude-recursive/licenserc.yaml b/pkg/deps/testdata/maven/cases/exclude-recursive/licenserc.yaml
new file mode 100644
index 0000000..8ea9207
--- /dev/null
+++ b/pkg/deps/testdata/maven/cases/exclude-recursive/licenserc.yaml
@@ -0,0 +1,23 @@
+# Licensed to the 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.  The 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.
+
+dependency:
+  files:
+    - pom.xml
+  excludes:
+    - name: org.apache.skywalking:skywalking-sharing-server-plugin
+      recursive: true
diff --git a/pkg/deps/testdata/maven/cases/exclude/licenserc.yaml b/pkg/deps/testdata/maven/cases/exclude/licenserc.yaml
new file mode 100644
index 0000000..a58a8bc
--- /dev/null
+++ b/pkg/deps/testdata/maven/cases/exclude/licenserc.yaml
@@ -0,0 +1,23 @@
+# Licensed to the 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.  The 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.
+
+dependency:
+  files:
+    - pom.xml
+  excludes:
+    - name: org.apache.skywalking:skywalking-sharing-server-plugin
+      recursive: false
diff --git a/pkg/deps/testdata/maven/cases/normal/licenserc.yaml b/pkg/deps/testdata/maven/cases/normal/licenserc.yaml
new file mode 100644
index 0000000..1136984
--- /dev/null
+++ b/pkg/deps/testdata/maven/cases/normal/licenserc.yaml
@@ -0,0 +1,20 @@
+# Licensed to the 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.  The 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.
+
+dependency:
+  files:
+    - pom.xml