16
16
package projectdata
17
17
18
18
import (
19
-
"encoding/json"
20
-
"io/ioutil"
19
+
"io"
21
20
"net/http"
22
21
"os"
23
22
24
23
"github.com/arduino/arduino-cli/arduino/libraries"
24
+
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
25
25
"github.com/arduino/arduino-lint/internal/configuration"
26
26
"github.com/arduino/arduino-lint/internal/configuration/rulemode"
27
27
"github.com/arduino/arduino-lint/internal/project"
28
28
"github.com/arduino/arduino-lint/internal/project/library/libraryproperties"
29
29
"github.com/arduino/arduino-lint/internal/result/feedback"
30
30
"github.com/arduino/arduino-lint/internal/rule/schema"
31
31
"github.com/arduino/arduino-lint/internal/rule/schema/compliancelevel"
32
+
"github.com/arduino/go-paths-helper"
32
33
"github.com/arduino/go-properties-orderedmap"
33
34
"github.com/client9/misspell"
34
35
"github.com/sirupsen/logrus"
@@ -60,23 +61,34 @@ func InitializeForLibrary(project project.Type) {
60
61
61
62
// Download the Library Manager index if needed.
62
63
if !configuration.RuleModes(project.SuperprojectType)[rulemode.LibraryManagerIndexing] && libraryManagerIndex == nil {
63
-
url := "http://downloads.arduino.cc/libraries/library_index.json"
64
-
httpResponse, err := http.Get(url)
64
+
// Set up the temporary folder for the index
65
+
libraryIndexFolderPath, err := paths.TempDir().MkTempDir("arduino-lint-library-index-folder")
66
+
defer libraryIndexFolderPath.RemoveAll()
65
67
if err != nil {
66
-
feedback.Errorf("Unable to download Library Manager index from %s: %s", err, url)
68
+
panic(err)
69
+
}
70
+
libraryIndexPath := libraryIndexFolderPath.Join("library_index.json")
71
+
72
+
// Download the index data
73
+
httpResponse, err := http.Get(librariesmanager.LibraryIndexURL.String())
74
+
if err != nil {
75
+
feedback.Errorf("Unable to download Library Manager index from %s: %s", err, librariesmanager.LibraryIndexURL)
67
76
os.Exit(1)
68
77
}
69
78
defer httpResponse.Body.Close()
70
79
71
-
bytes, err := ioutil.ReadAll(httpResponse.Body)
80
+
// Write the index data to file
81
+
libraryIndexFile, err := libraryIndexPath.Create()
82
+
defer libraryIndexFile.Close()
72
83
if err != nil {
73
84
panic(err)
74
85
}
75
-
76
-
err = json.Unmarshal(bytes, &libraryManagerIndex)
77
-
if err != nil {
86
+
if _, err := io.Copy(libraryIndexFile, httpResponse.Body); err != nil {
78
87
panic(err)
79
88
}
89
+
90
+
libraryManagerIndex = librariesmanager.NewLibraryManager(libraryIndexFolderPath, nil)
91
+
libraryManagerIndex.LoadIndex()
80
92
}
81
93
82
94
if misspelledWordsReplacer == nil { // The replacer only needs to be compiled once per run.
@@ -120,10 +132,10 @@ func SourceHeaders() []string {
120
132
return sourceHeaders
121
133
}
122
134
123
-
var libraryManagerIndex map[string]interface{}
135
+
var libraryManagerIndex *librariesmanager.LibrariesManager
124
136
125
137
// LibraryManagerIndex returns the Library Manager index data.
126
-
func LibraryManagerIndex() map[string]interface{} {
138
+
func LibraryManagerIndex() *librariesmanager.LibrariesManager {
127
139
return libraryManagerIndex
128
140
}
129
141
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4