Skip to content

Commit cae067e

Browse files
authored
Merge pull request #133 from eclipse/license-detection
Enhanced License detection
2 parents 8f9ef9c + 08433e5 commit cae067e

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

server/src/main/java/org/eclipse/openvsx/util/LicenseDetection.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
********************************************************************************/
1010
package org.eclipse.openvsx.util;
1111

12+
import java.io.IOException;
1213
import java.io.UnsupportedEncodingException;
14+
import java.net.URISyntaxException;
15+
import java.nio.file.Files;
16+
import java.nio.file.Paths;
1317
import java.util.ArrayList;
1418
import java.util.Collections;
1519
import java.util.List;
@@ -23,9 +27,8 @@
2327

2428
public class LicenseDetection {
2529

26-
protected static final String[] DEFAULT_LICENSE_IDS = {
27-
"MIT", "Apache-2.0", "Apache-1.1", "EPL-2.0", "EPL-1.0", "ISC", "BSD-2-Clause", "BSD-3-Clause"
28-
};
30+
protected static final String[] DEFAULT_LICENSE_IDS = { "MIT", "Apache-2.0", "Apache-1.1", "EPL-2.0", "EPL-1.0",
31+
"ISC", "BSD-2-Clause", "BSD-3-Clause" };
2932

3033
protected final Logger logger = LoggerFactory.getLogger(LicenseDetection.class);
3134

@@ -55,6 +58,15 @@ public String detectLicense(String content) {
5558
try {
5659
for (var licenseId : licenseIds) {
5760
var license = LicenseInfoFactory.getListedLicenseById(licenseId);
61+
var resource = getClass().getResource("/spdx-templates/" + licenseId.toLowerCase() + ".txt");
62+
if (resource != null) {
63+
try {
64+
var data = new String(Files.readAllBytes(Paths.get(resource.toURI())));
65+
license.setStandardLicenseTemplate(data);
66+
} catch (URISyntaxException | IOException e) {
67+
logger.error("Failed to load spdx template", e);
68+
}
69+
}
5870
var diff = LicenseCompareHelper.isTextStandardLicense(license, content);
5971
if (!diff.isDifferenceFound()) {
6072
return license.getLicenseId();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<<beginOptional>> MIT License<<endOptional>>
2+
3+
<<var;name="copyright";original="Copyright (c) <year> <copyright holders>";match=".{0,1000}">>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of <<var;name="software";original="this software and associated documentation files";match="this software and associated documentation files|this source file">>
7+
(the <<var;name="software2";original=""Software"";match="["]+Software["]+">>), to deal in the Software without restriction, including without
8+
limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright
10+
notice and this permission notice<<beginOptional>> (including the next paragraph)<<endOptional>> shall be included in all
11+
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED <<var;name="asis";original=""AS IS"";match="[*"]+AS IS[*"]+">>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
13+
IN NO EVENT SHALL <<var;name="copyrightHolder";original="THE AUTHORS OR COPYRIGHT HOLDERS";match=".+">> BE LIABLE FOR ANY CLAIM,
14+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
Copyright 2020 Tim Test
1+
PowerShell for Visual Studio Code
22

3-
Permission is hereby granted, free of charge, to any person obtaining a copy of
4-
this software and associated documentation files (the "Software"), to deal in
5-
the Software without restriction, including without limitation the rights to
6-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7-
of the Software, and to permit persons to whom the Software is furnished to do
3+
Copyright (c) Microsoft Corporation
4+
5+
All rights reserved.
6+
7+
MIT License
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy of
10+
this software and associated documentation files (the ""Software""), to deal in
11+
the Software without restriction, including without limitation the rights to
12+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13+
of the Software, and to permit persons to whom the Software is furnished to do
814
so, subject to the following conditions:
915

10-
The above copyright notice and this permission notice shall be included in all
16+
The above copyright notice and this permission notice shall be included in all
1117
copies or substantial portions of the Software.
1218

13-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19-
SOFTWARE.
19+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.

0 commit comments

Comments
 (0)