Skip to content

Commit

Permalink
Merge pull request #197 from spdx/fixcompareopt
Browse files Browse the repository at this point in the history
Fix license compare
  • Loading branch information
goneall authored Jul 1, 2019
2 parents 42a6200 + a15ddfb commit 25bcaf5
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 6 deletions.
13 changes: 13 additions & 0 deletions Test/org/spdx/compare/TestCompareTemplateOutputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class TestCompareTemplateOutputHandler {
static final String LPPL_1_3_C_TEMPLATE = "TestFiles" + File.separator + "LPPL-1.3c.template.txt";
static final String ODBL_1_TEXT = "TestFiles" + File.separator + "ODbL-1.0.txt";
static final String ODBL_1_TEMPLATE = "TestFiles" + File.separator + "ODbL-1.0.template.txt";
static final String SLEEPYCAT_TEXT = "TestFiles" + File.separator + "Sleepycat.txt";
static final String SLEEPYCAT_TEMPLATE = "TestFiles" + File.separator + "Sleepycat.template.txt";

/**
* @throws java.lang.Exception
Expand Down Expand Up @@ -533,4 +535,15 @@ public void testRegressionOdbl() throws IOException, LicenseTemplateRuleExceptio
fail(templateOutputHandler.getDifferences().getDifferenceMessage());
}
}

@Test
public void testRegressionSleepycat() throws IOException, LicenseTemplateRuleException, LicenseParserException {
String compareText = UnitTestHelper.fileToText(SLEEPYCAT_TEXT);
String templateText = UnitTestHelper.fileToText(SLEEPYCAT_TEMPLATE);
CompareTemplateOutputHandler templateOutputHandler = new CompareTemplateOutputHandler(compareText);
SpdxLicenseTemplateHelper.parseTemplate(templateText, templateOutputHandler);
if (!templateOutputHandler.matches()) {
fail(templateOutputHandler.getDifferences().getDifferenceMessage());
}
}
}
15 changes: 12 additions & 3 deletions TestFiles/AAL.template.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<<beginOptional>> Attribution Assurance License<<endOptional>>
Copyright (c) <<var;name="copyright";original="2002 by AUTHOR PROFESSIONAL IDENTIFICATION * URL "PROMOTIONAL SLOGAN FOR AUTHOR'S PROFESSIONAL PRACTICE"";match=".+">>
All Rights Reserved<<beginOptional>> ATTRIBUTION ASSURANCE LICENSE (adapted from the original BSD license)<<endOptional>>
<<beginOptional>> Attribution Assurance License<<endOptional>> <<var;name="copyright";original="Copyright (c) 2002 by AUTHOR PROFESSIONAL IDENTIFICATION * URL "PROMOTIONAL SLOGAN FOR AUTHOR'S PROFESSIONAL PRACTICE"

All Rights Reserved";match=".{0,200}">><<beginOptional>> ATTRIBUTION ASSURANCE LICENSE (adapted from the original BSD license)<<endOptional>>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the conditions below are met. These conditions require a modest attribution to <<var;name="author";original="<AUTHOR>";match=".+">> (the "Author"), who hopes that its promotional value may help justify the thousands of dollars in otherwise billable time invested in writing this and other freely available, open-source software.

<<var;name="bullet";original="1.";match=".{0,20}">> Redistributions of source code, in whole or part and with or without modification (the "Code"), must prominently display this GPG-signed text in verifiable form.

<<var;name="bullet";original="2.";match=".{0,20}">> Redistributions of the Code in binary form must be accompanied by this GPG-signed text in any documentation and, each time the resulting executable program or a program dependent thereon is launched, a prominent display (e.g., splash screen or banner text) of the Author's attribution information, which includes:

<<var;name="bullet";original="(a)";match=".{0,20}">> <<var;name="author";original="Name";match=".+">> ("AUTHOR"),

<<var;name="bullet";original="(b)";match=".{0,20}">> <<var;name="profIdent";original="Professional identification";match=".+">> ("PROFESSIONAL IDENTIFICATION"), and

<<var;name="bullet";original="(c)";match=".{0,20}">> <<var;name="url";original="URL";match=".+">> ("URL").

<<var;name="bullet";original="3.";match=".{0,20}">> Neither the name nor any trademark of the Author may be used to endorse or promote products derived from this software without specific prior written permission.

<<var;name="bullet";original="4.";match=".{0,20}">> Users are entirely responsible, to the exclusion of the Author and any other persons, for compliance with (1) regulations set by owners or administrators of employed equipment, (2) licensing terms of any other software, and (3) local regulations regarding use, including those regarding import, export, and use of encryption software.

THIS FREE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR ANY CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, EFFECTS OF UNAUTHORIZED OR MALICIOUS NETWORK ACCESS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 changes: 31 additions & 0 deletions TestFiles/Sleepycat.template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<<beginOptional>> The Sleepycat License <<var;name="copyright";original="Copyright (c) 1990-1999 Sleepycat Software. All rights reserved.";match=".{0,400}">><<endOptional>>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

<<var;name="bullet";original="-";match=".{0,20}">> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

<<var;name="bullet";original="-";match=".{0,20}">> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

<<var;name="bullet";original="-";match=".{0,20}">> Redistributions in any form must be accompanied by information on how to obtain complete source code for the DB software and any accompanying software that uses the DB software. The source code must either be included in the distribution or be available for no more than the cost of distribution plus a nominal fee, and must be freely redistributable under reasonable conditions. For an executable file, complete source code means the source code for all modules it contains. It does not include source code for modules or files that typically accompany the major components of the operating system on which the executable file runs.

THIS SOFTWARE IS PROVIDED BY SLEEPYCAT SOFTWARE ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SLEEPYCAT SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <<var;name="copyright";original="Copyright (c) 1990, 1993, 1994, 1995 The Regents of the University of California. All rights reserved.";match=".{0,400}">>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

<<var;name="bullet";original="-";match=".{0,20}">> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

<<var;name="bullet";original="-";match=".{0,20}">> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

<<var;name="bullet";original="-";match=".{0,20}">> Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <<var;name="copyright";original="Copyright (c) 1995, 1996 The President and Fellows of Harvard University. All rights reserved.";match=".{0,400}">>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

<<var;name="bullet";original="-";match=".{0,20}">> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

<<var;name="bullet";original="-";match=".{0,20}">> Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

<<var;name="bullet";original="-";match=".{0,20}">> Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY HARVARD AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL HARVARD OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 changes: 37 additions & 0 deletions TestFiles/Sleepycat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
The Sleepycat License Copyright (c) 1990-1999 Sleepycat Software. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

- Redistributions in any form must be accompanied by information on how to obtain complete source code for the DB software and any accompanying software that uses the DB software. The source code must either be included in the distribution or be available for no more than the cost of distribution plus a nominal fee, and must be freely redistributable under reasonable conditions. For an executable file, complete source code means the source code for all modules it contains. It does not include source code for modules or files that typically accompany the major components of the operating system on which the executable file runs.

THIS SOFTWARE IS PROVIDED BY SLEEPYCAT SOFTWARE ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SLEEPYCAT SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Copyright (c) 1990, 1993, 1994, 1995 The Regents of the University of California. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

- Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Copyright (c) 1995, 1996 The President and Fellows of Harvard University. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

- Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY HARVARD AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL HARVARD OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.spdx</groupId>
<artifactId>spdx-tools</artifactId>
<version>2.1.17-SNAPSHOT</version>
<version>2.1.17</version>
<name>SPDX tools</name>
<description>SPDX tools</description>
<licenses>
Expand Down
4 changes: 2 additions & 2 deletions src/org/spdx/compare/CompareTemplateOutputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private int matchOptional(List<Integer> matchingStartTokens,
DifferenceDescription matchDifferences = new DifferenceDescription();
int matchLocation = startToken;
for (ParseInstruction sub:subInstructions) {
matchLocation = sub.match(matchTokens, matchLocation, matchingStartToken, originalText,
matchLocation = sub.match(matchTokens, matchLocation, matchingStartToken-1, originalText,
matchDifferences, tokenToLocation);
if (matchLocation < 0) {
break;
Expand Down Expand Up @@ -362,7 +362,7 @@ private List<Integer> findNextNonVarTextStartTokens(ParseInstruction afterChild,
}
if (optTokenAfterMatch > 0 && !tempDiffDescription.differenceFound && nextOptMatchingStart <= endToken) {
// we found a match
if (nextOptMatchingStart - optTokenAfterMatch > MIN_TOKENS_NORMAL_TEXT_SEARCH) {
if (optTokenAfterMatch - nextOptMatchingStart > MIN_TOKENS_NORMAL_TEXT_SEARCH) {
// Only add possible matches if it matched enough tokens
//TODO: This approximation of the number of tokens matched may include tokens consumed by a variable match. To make this more accurate, we should count the tokens of just the text nodes a children
retval.add(nextOptMatchingStart);
Expand Down

0 comments on commit 25bcaf5

Please sign in to comment.