Skip to content

Commit 385b7ec

Browse files
authored
Merge branch 'xwikisas:master' into issue#206
2 parents c28e399 + 7b7e80c commit 385b7ec

File tree

58 files changed

+1028
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1028
-145
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Manage and enforce application licenses for paid extensions
66
* [Documentation & Download](http://store.xwiki.com/xwiki/bin/view/Extension/Licensing+Application)
77
* [JIRA Issue Tracker](https://github.com/xwikisas/application-licensing/issues)
88
* [Development Practices](http://dev.xwiki.org/xwiki/bin/view/Community/DevelopmentPractices)
9-
* Minimal XWiki version supported: XWiki 14.10
9+
* Minimal XWiki version supported: XWiki 15.10
1010
* License: LGPL 2.1
1111
* Translations: N/A
1212
* Sonar Dashboard: N/A

application-licensing-common/application-licensing-common-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<artifactId>application-licensing-common</artifactId>
2727
<groupId>com.xwiki.licensing</groupId>
28-
<version>1.30.2-SNAPSHOT</version>
28+
<version>1.32.1-SNAPSHOT</version>
2929
</parent>
3030
<artifactId>application-licensing-common-api</artifactId>
3131
<name>Licensing Application - Common - API</name>

application-licensing-common/application-licensing-common-api/src/main/java/com/xwiki/licensing/License.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public class License implements Comparable<License>
5151
*/
5252
public static final String LICENSEE_EMAIL = "email";
5353

54+
/**
55+
* The key used to store the licensee issue date.
56+
*/
57+
public static final String LICENSE_ISSUE_DATE = "issueDate";
58+
5459
/**
5560
* An empty constant object used when you need to explicitly assign no license.
5661
*/
@@ -267,7 +272,7 @@ public Map<String, String> getLicensee()
267272
}
268273

269274
/**
270-
* Set licensee informations.
275+
* Set licensee information.
271276
*
272277
* @param licensee a map of licensee information to be assigned.
273278
*/
@@ -326,6 +331,24 @@ public static License getOptimumLicense(License license1, License license2)
326331
return license1;
327332
}
328333

334+
boolean license1HasIssueDate = license1.getLicensee().containsKey(LICENSE_ISSUE_DATE);
335+
boolean license2HasIssueDate = license2.getLicensee().containsKey(LICENSE_ISSUE_DATE);
336+
337+
if (license1HasIssueDate && !license2HasIssueDate) {
338+
return license1;
339+
}
340+
341+
if (!license1HasIssueDate && license2HasIssueDate) {
342+
return license2;
343+
}
344+
345+
if (license1HasIssueDate && license2HasIssueDate) {
346+
long license1IssueDate = Long.parseLong(license1.getLicensee().get(LICENSE_ISSUE_DATE));
347+
long license2IssueDate = Long.parseLong(license2.getLicensee().get(LICENSE_ISSUE_DATE));
348+
349+
return license1IssueDate > license2IssueDate ? license1 : license2;
350+
}
351+
329352
if (license1.getExpirationDate() != license2.getExpirationDate()) {
330353
return (license1.getExpirationDate() >= license2.getExpirationDate()) ? license1 : license2;
331354
}
@@ -402,7 +425,7 @@ public int compareTo(License o)
402425
return getId().compareTo(getId());
403426
}
404427

405-
private static class CollectionEqualsBuilder extends EqualsBuilder
428+
private static final class CollectionEqualsBuilder extends EqualsBuilder
406429
{
407430
@Override
408431
public EqualsBuilder append(Object lhs, Object rhs)

application-licensing-common/application-licensing-common-api/src/test/java/com/xwiki/licensing/LicenseTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import java.util.Collections;
2323
import java.util.Date;
24+
import java.util.HashMap;
25+
import java.util.Map;
2426

2527
import org.junit.Before;
2628
import org.junit.Test;
@@ -150,6 +152,40 @@ public void getOptimumLicense()
150152
assertSame(bob, License.getOptimumLicense(bob, alice));
151153
}
152154

155+
/**
156+
* The returned license is the one with the latest issue date, even if it has an earlier expiration date. If the
157+
* issue date is not available, then the returned license is the one with the latest expiration date.
158+
*/
159+
@Test
160+
public void getOptimumLicenseBasedOnIssuedDate()
161+
{
162+
License alice = new License();
163+
alice.setExpirationDate(4L);
164+
165+
License bob = new License();
166+
bob.setExpirationDate(6L);
167+
168+
assertSame(bob, License.getOptimumLicense(alice, bob));
169+
assertSame(bob, License.getOptimumLicense(bob, alice));
170+
171+
Map<String, String> aliceLicensee = new HashMap<>();
172+
aliceLicensee.put("issueDate", "1000");
173+
alice.setLicensee(aliceLicensee);
174+
175+
assertSame(alice, License.getOptimumLicense(alice, bob));
176+
assertSame(alice, License.getOptimumLicense(bob, alice));
177+
178+
alice.setExpirationDate(6L);
179+
bob.setExpirationDate(4L);
180+
181+
Map<String, String> bobLicensee = new HashMap<>();
182+
bobLicensee.put("issueDate", "2000");
183+
bob.setLicensee(bobLicensee);
184+
185+
assertSame(bob, License.getOptimumLicense(alice, bob));
186+
assertSame(bob, License.getOptimumLicense(bob, alice));
187+
}
188+
153189
private License getSignedLicense(License license, String content)
154190
{
155191
when(this.signedDataVerified.getContent()).thenReturn(content.getBytes());

application-licensing-common/application-licensing-common-model/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<artifactId>application-licensing-common</artifactId>
2727
<groupId>com.xwiki.licensing</groupId>
28-
<version>1.30.2-SNAPSHOT</version>
28+
<version>1.32.1-SNAPSHOT</version>
2929
</parent>
3030
<artifactId>application-licensing-common-model</artifactId>
3131
<name>Licensing Application - Common - Model</name>
@@ -48,14 +48,13 @@
4848
<build>
4949
<plugins>
5050
<plugin>
51-
<groupId>org.jvnet.jaxb2.maven2</groupId>
52-
<artifactId>maven-jaxb2-plugin</artifactId>
51+
<groupId>org.jvnet.jaxb</groupId>
52+
<artifactId>jaxb-maven-plugin</artifactId>
5353
<configuration>
5454
<generatePackage>com.xwiki.licensing.model.jaxb</generatePackage>
5555
</configuration>
5656
<executions>
5757
<execution>
58-
<id>generate</id>
5958
<goals>
6059
<goal>generate</goal>
6160
</goals>

application-licensing-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<artifactId>application-licensing</artifactId>
2727
<groupId>com.xwiki.licensing</groupId>
28-
<version>1.30.2-SNAPSHOT</version>
28+
<version>1.32.1-SNAPSHOT</version>
2929
</parent>
3030
<artifactId>application-licensing-common</artifactId>
3131
<packaging>pom</packaging>

application-licensing-licensor/application-licensing-licensor-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<artifactId>application-licensing-licensor</artifactId>
2626
<groupId>com.xwiki.licensing</groupId>
27-
<version>1.30.2-SNAPSHOT</version>
27+
<version>1.32.1-SNAPSHOT</version>
2828
</parent>
2929
<modelVersion>4.0.0</modelVersion>
3030
<artifactId>application-licensing-licensor-api</artifactId>

application-licensing-licensor/application-licensing-licensor-api/src/main/java/com/xwiki/licensing/LicenseManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public interface LicenseManager
5252
/**
5353
* Add a new license to the current set of active license. The added license is checked to be applicable to the
5454
* current wiki instance, else it will not be added. The license is also checked to be more interesting than the
55-
* currently installed licenses. If the license does not provides any improvement of the licensing state of this
56-
* wiki, it will not be added. This check does not reject unsigned license, but give immediate priority to signed
55+
* currently installed licenses. If the license does not provide any improvement of the licensing state of this
56+
* wiki, it will not be added. This check does not reject unsigned license, but gives immediate priority to signed
5757
* ones over unsigned ones, even if the signed license has narrower constraints. These evaluations are done for
58-
* each licensed extension independently, whether these extension are currently installed or not.
58+
* each licensed extension independently, whether these extensions are currently installed or not.
5959
*
6060
* @param license a license to be added (could be signed or not, unsigned will be stored but not really applied)
6161
* @return true if the license has been actually added (see above).

application-licensing-licensor/application-licensing-licensor-api/src/main/java/com/xwiki/licensing/LicenseValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
public interface LicenseValidator
3131
{
3232
/**
33-
* A LicenseValidator that always reply false. Used when the license validator received is not pristine.
33+
* A LicenseValidator that always returns false. Used when the license validator received is not pristine.
3434
*/
3535
LicenseValidator INVALIDATOR = new LicenseValidator() {
3636
@Override
@@ -69,7 +69,7 @@ public boolean isValid(License license)
6969
boolean isSigned(License license);
7070

7171
/**
72-
* Check if a license is valid, its constrains are respected.
72+
* Check if a license is valid, its constraints are respected.
7373
* The instance constraint is NOT checked, see {@link #isApplicable(License)}
7474
*
7575
* @param license the license to be checked.

application-licensing-licensor/application-licensing-licensor-api/src/main/java/com/xwiki/licensing/LicensingConfiguration.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
package com.xwiki.licensing;
2121

2222
import java.io.File;
23+
import java.util.ArrayList;
24+
import java.util.HashSet;
2325
import java.util.List;
26+
import java.util.Set;
2427

2528
import org.xwiki.component.annotation.Role;
29+
import org.xwiki.stability.Unstable;
2630

2731
/**
2832
* Configuration of the licensing module.
@@ -80,4 +84,35 @@ public interface LicensingConfiguration
8084
* @return the email of the licensing owner or null if the value of the property is not filled up
8185
*/
8286
String getLicensingOwnerEmail();
87+
88+
/**
89+
* @return {@link List} with the groups whose members need to be notified about the extension
90+
* @since 1.31
91+
*/
92+
@Unstable
93+
default List<String> getNotifiedGroups()
94+
{
95+
return new ArrayList<>();
96+
}
97+
98+
/**
99+
* @return {@link Set} with the groups whose members need to be notified about the extension
100+
* @since 1.31
101+
*/
102+
@Unstable
103+
default Set<String> getNotifiedGroupsSet()
104+
{
105+
return new HashSet<>();
106+
}
107+
108+
/**
109+
* @return {@code true} if the context user is member of the groups from {@link #getNotifiedGroups}, or
110+
* {@code false} otherwise
111+
* @since 1.31
112+
*/
113+
@Unstable
114+
default boolean isMemberOfNotifiedGroups()
115+
{
116+
return false;
117+
}
83118
}

0 commit comments

Comments
 (0)