Skip to content

Commit 12d544b

Browse files
Egor Martsynkovskyyulian-gaponenko
authored andcommitted
Update AGPL logging with new license mechanism
DEVSIX-5341
1 parent 3e37f0e commit 12d544b

34 files changed

+111
-2793
lines changed

kernel/src/test/java/com/itextpdf/kernel/counter/StandardOutputEventCounterTest.java renamed to commons/src/main/java/com/itextpdf/commons/actions/processors/AbstractITextProductEventProcessor.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,35 @@ This file is part of the iText (R) project.
2020
You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
23-
package com.itextpdf.kernel.counter;
23+
package com.itextpdf.commons.actions.processors;
2424

25-
import com.itextpdf.test.ExtendedITextTest;
26-
import com.itextpdf.test.annotations.type.UnitTest;
25+
import com.itextpdf.commons.actions.AbstractProductProcessITextEvent;
26+
import com.itextpdf.commons.exceptions.CommonsExceptionMessageConstant;
2727

28-
import org.junit.Assert;
29-
import org.junit.Test;
30-
import org.junit.experimental.categories.Category;
28+
public abstract class AbstractITextProductEventProcessor implements ITextProductEventProcessor {
3129

32-
@Category(UnitTest.class)
33-
public class StandardOutputEventCounterTest extends ExtendedITextTest {
30+
private final String productName;
3431

35-
@Test
36-
public void standardEventCounterFactoryTest() {
37-
StandardOutputEventCounterFactory counterFactory = new StandardOutputEventCounterFactory();
32+
public AbstractITextProductEventProcessor(String productName) {
33+
if (productName == null) {
34+
throw new IllegalArgumentException(CommonsExceptionMessageConstant.PRODUCT_NAME_CAN_NOT_BE_NULL);
35+
}
36+
this.productName = productName;
37+
}
38+
39+
@Override
40+
public abstract void onEvent(AbstractProductProcessITextEvent event);
41+
42+
@Override
43+
public abstract String getUsageType();
44+
45+
@Override
46+
public String getProducer() {
47+
return "iText\u00ae ${usedProducts:P V (T 'version')} \u00a9${copyrightSince}-${copyrightTo} iText Group NV";
48+
}
3849

39-
Assert.assertTrue(counterFactory.getCounter(getClass()) instanceof StandardOutputEventCounter);
50+
@Override
51+
public String getProductName() {
52+
return productName;
4053
}
4154
}

commons/src/main/java/com/itextpdf/commons/actions/processors/DefaultITextProductEventProcessor.java

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,85 @@ This file is part of the iText (R) project.
2323
package com.itextpdf.commons.actions.processors;
2424

2525
import com.itextpdf.commons.actions.AbstractProductProcessITextEvent;
26-
import com.itextpdf.commons.exceptions.CommonsExceptionMessageConstant;
26+
import com.itextpdf.commons.actions.confirmations.ConfirmEvent;
27+
import com.itextpdf.commons.utils.Base64;
28+
29+
import java.nio.charset.StandardCharsets;
30+
import java.util.concurrent.atomic.AtomicLong;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
2733

2834
/**
2935
* Defines a default strategy of product event processing.
3036
*/
31-
public class DefaultITextProductEventProcessor implements ITextProductEventProcessor {
37+
public class DefaultITextProductEventProcessor extends AbstractITextProductEventProcessor {
38+
39+
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultITextProductEventProcessor.class);
40+
41+
private static final byte[] messageForLogging = Base64
42+
.decode("WW91IGFyZSB1c2luZyBpVGV4dCB1bmRlciB0aGUgQUdQTC4KCklmIHRoaXMgaXMgeW9"
43+
+ "1ciBpbnRlbnRpb24sIHlvdSBoYXZlIHB1Ymxpc2hlZCB5b3VyIG93biBzb3VyY2UgY2"
44+
+ "9kZSBhcyBBR1BMIHNvZnR3YXJlIHRvby4KUGxlYXNlIGxldCB1cyBrbm93IHdoZXJlI"
45+
+ "HRvIGZpbmQgeW91ciBzb3VyY2UgY29kZSBieSBzZW5kaW5nIGEgbWFpbCB0byBhZ3Bs"
46+
+ "QGl0ZXh0cGRmLmNvbQpXZSdkIGJlIGhvbm9yZWQgdG8gYWRkIGl0IHRvIG91ciBsaXN"
47+
+ "0IG9mIEFHUEwgcHJvamVjdHMgYnVpbHQgb24gdG9wIG9mIGlUZXh0IDcKYW5kIHdlJ2"
48+
+ "xsIGV4cGxhaW4gaG93IHRvIHJlbW92ZSB0aGlzIG1lc3NhZ2UgZnJvbSB5b3VyIGVyc"
49+
+ "m9yIGxvZ3MuCgpJZiB0aGlzIHdhc24ndCB5b3VyIGludGVudGlvbiwgeW91IGFyZSBw"
50+
+ "cm9iYWJseSB1c2luZyBpVGV4dCBpbiBhIG5vbi1mcmVlIGVudmlyb25tZW50LgpJbiB"
51+
+ "0aGlzIGNhc2UsIHBsZWFzZSBjb250YWN0IHVzIGJ5IGZpbGxpbmcgb3V0IHRoaXMgZm"
52+
+ "9ybTogaHR0cDovL2l0ZXh0cGRmLmNvbS9zYWxlcwpJZiB5b3UgYXJlIGEgY3VzdG9tZ"
53+
+ "XIsIHdlJ2xsIGV4cGxhaW4gaG93IHRvIGluc3RhbGwgeW91ciBsaWNlbnNlIGtleSB0"
54+
+ "byBhdm9pZCB0aGlzIG1lc3NhZ2UuCklmIHlvdSdyZSBub3QgYSBjdXN0b21lciwgd2U"
55+
+ "nbGwgZXhwbGFpbiB0aGUgYmVuZWZpdHMgb2YgYmVjb21pbmcgYSBjdXN0b21lci4=");
56+
57+
private static final long[] REPEAT = {10000L, 5000L, 1000L};
58+
59+
private static final int MAX_LVL = REPEAT.length - 1;
3260

33-
private final String productName;
61+
private final Object lock = new Object();
62+
63+
private final AtomicLong counter = new AtomicLong(0);
64+
65+
private final AtomicLong level = new AtomicLong(0);
66+
67+
private final AtomicLong repeatLevel;
3468

3569
/**
3670
* Creates an instance of product event processor.
3771
*
3872
* @param productName is a product name
3973
*/
4074
public DefaultITextProductEventProcessor(String productName) {
41-
if (productName == null) {
42-
throw new IllegalArgumentException(CommonsExceptionMessageConstant.PRODUCT_NAME_CAN_NOT_BE_NULL);
43-
}
44-
this.productName = productName;
75+
super(productName);
76+
repeatLevel = new AtomicLong(REPEAT[(int) level.get()]);
4577
}
4678

4779
@Override
4880
public void onEvent(AbstractProductProcessITextEvent event) {
49-
// TODO: DEVSIX-5341 provide appropriate logic if any
50-
}
81+
if (!(event instanceof ConfirmEvent)) {
82+
return;
83+
}
84+
boolean isNeededToLogMessage = false;
85+
synchronized (lock) {
86+
if (counter.incrementAndGet() > repeatLevel.get()) {
87+
counter.set(0);
88+
if (level.incrementAndGet() > MAX_LVL) {
89+
level.set(MAX_LVL);
90+
}
91+
repeatLevel.set(REPEAT[(int) level.get()]);
92+
isNeededToLogMessage = true;
93+
}
94+
}
5195

52-
@Override
53-
public String getProductName() {
54-
return productName;
96+
if (isNeededToLogMessage) {
97+
String message = new String(messageForLogging, StandardCharsets.ISO_8859_1);
98+
LOGGER.info(message);
99+
System.out.println(message);
100+
}
55101
}
56102

57103
@Override
58104
public String getUsageType() {
59105
return "AGPL";
60106
}
61-
62-
@Override
63-
public String getProducer() {
64-
return "iText\u00ae ${usedProducts:P V (T 'version')} \u00a9${copyrightSince}-${copyrightTo} iText Group NV";
65-
}
66107
}

kernel/src/main/java/com/itextpdf/kernel/LicenseVersionException.java

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)