From e4b616e8fd6bb7edfb5f358f9a3f5539121b80de Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 1 Oct 2013 13:52:37 +0200 Subject: [PATCH] Added more source code splitting logic for trial licenses --- .../jooq/oss/{OSS.xtend => Splitter.xtend} | 83 +++++++++++-------- .../java/org/jooq/impl/AbstractQuery.java | 16 ++++ .../org/jooq/impl/DefaultExecuteContext.java | 2 +- .../org/jooq/impl/DefaultRenderContext.java | 25 +++++- 4 files changed, 89 insertions(+), 37 deletions(-) rename jOOQ-tools/src/org/jooq/oss/{OSS.xtend => Splitter.xtend} (72%) diff --git a/jOOQ-tools/src/org/jooq/oss/OSS.xtend b/jOOQ-tools/src/org/jooq/oss/Splitter.xtend similarity index 72% rename from jOOQ-tools/src/org/jooq/oss/OSS.xtend rename to jOOQ-tools/src/org/jooq/oss/Splitter.xtend index af10e1b4a4..4869644b3e 100644 --- a/jOOQ-tools/src/org/jooq/oss/OSS.xtend +++ b/jOOQ-tools/src/org/jooq/oss/Splitter.xtend @@ -51,22 +51,35 @@ import org.jooq.xtend.Generators import java.util.concurrent.ExecutorService import java.util.concurrent.Executors -class OSS extends Generators { +class RemoveProCode { + def static void main(String[] args) { + Splitter::split("pro", "/../workspace-jooq-oss"); + } +} + +class RemoveTrialCode { + def static void main(String[] args) { + Splitter::split("trial", "/../workspace-jooq-pro"); + } +} + +class Splitter extends Generators { static ExecutorService ex; - - def static void main(String[] args) { + String token; + + def static void split(String token, String workspace) { ex = Executors::newFixedThreadPool(4); - val oss = new OSS(); + val splitter = new Splitter(token); val workspaceIn = new File("../..").canonicalFile; - val workspaceOut = new File(workspaceIn.canonicalPath + "/../workspace-jooq-oss").canonicalFile; + val workspaceOut = new File(workspaceIn.canonicalPath + workspace).canonicalFile; for (project : workspaceIn.listFiles[f | f.name.startsWith("jOOQ")]) { val in = new File(workspaceIn, project.name); val out = new File(workspaceOut, project.name); - oss.transform(in, out, in); + splitter.transform(in, out, in); } ex.shutdown; @@ -101,7 +114,7 @@ class OSS extends Generators { transform(inRoot, outRoot, file); } } - else if (in.name.equals("LICENSE.txt")) { + else if (token == "pro" && in.name.equals("LICENSE.txt")) { ex.submit[ | write(out, ''' Copyright (c) 2009-2013, Data Geekery GmbH (http://www.datageekery.com) @@ -159,14 +172,17 @@ For more information, please visit: http://www.jooq.org/licenses'''); val replaceAll = new ArrayList>(); val replaceFirst = new ArrayList>(); - new() { + new(String token) { + this.token = token; - // Replace a couple of imports - replaceFirst.add(new ImmutablePair(compile('''import org\.jooq\.(ArrayConstant|ArrayRecord|impl\.ArrayRecordImpl|impl\.FlashbackTable.*?);'''), "// ...")); - replaceFirst.add(new ImmutablePair(compile('''import static org\.jooq\.impl\.DSL\.(cube|grouping|groupingId|groupingSets);'''), "// ...")); - - // Replace the Java / Scala / Xtend license header - replaceFirst.add(new ImmutablePair(compile('''(?s:/\*\*[\r\n] \* Copyright.*?eula[\r\n] \*/)'''), ''' + if (token == "pro") { + + // Replace a couple of imports + replaceFirst.add(new ImmutablePair(compile('''import org\.jooq\.(ArrayConstant|ArrayRecord|impl\.ArrayRecordImpl|impl\.FlashbackTable.*?);'''), "// ...")); + replaceFirst.add(new ImmutablePair(compile('''import static org\.jooq\.impl\.DSL\.(cube|grouping|groupingId|groupingSets);'''), "// ...")); + + // Replace the Java / Scala / Xtend license header + replaceFirst.add(new ImmutablePair(compile('''(?s:/\*\*[\r\n] \* Copyright.*?eula[\r\n] \*/)'''), ''' /** * Copyright (c) 2009-2013, Data Geekery GmbH (http://www.datageekery.com) * All rights reserved. @@ -208,25 +224,26 @@ For more information, please visit: http://www.jooq.org/licenses'''); * */''')); - // Remove sections of commercial code - translateAll.add(compile('''(?s:(/\* \[pro\])( \*.*?/\* )(\[/pro\] \*/))''')); - translateAll.add(compile('''(?s:(.*?))''')); - - for (d : SQLDialect::values.filter[d | d.commercial]) { - - // Remove commercial dialects from @Support annotations - replaceAll.add(new ImmutablePair(compile('''(?s:(\@Support\([^\)]*?),\s*\b«d.name»\b([^\)]*?\)))'''), "$1$2")); - replaceAll.add(new ImmutablePair(compile('''(?s:(\@Support\([^\)]*?)\b«d.name»\b,\s*([^\)]*?\)))'''), "$1$2")); - replaceAll.add(new ImmutablePair(compile('''(?s:(\@Support\([^\)]*?)\s*\b«d.name»\b\s*([^\)]*?\)))'''), "$1$2")); - - // Remove commercial dialects from Arrays.asList() expressions - replaceAll.add(new ImmutablePair(compile('''(asList\([^\)]*?),\s*\b«d.name»\b([^\)]*?\))'''), "$1$2")); - replaceAll.add(new ImmutablePair(compile('''(asList\([^\)]*?)\b«d.name»\b,\s*([^\)]*?\))'''), "$1$2")); - replaceAll.add(new ImmutablePair(compile('''(asList\([^\)]*?)\s*\b«d.name»\b\s*([^\)]*?\))'''), "$1$2")); - - // Remove commercial dialects from imports - replaceAll.add(new ImmutablePair(compile('''import (static )?org\.jooq\.SQLDialect\.«d.name»;'''), "// ...")); - replaceAll.add(new ImmutablePair(compile('''import (static )?org\.jooq\.util\.«d.name.toLowerCase»\..*?;'''), "// ...")); + for (d : SQLDialect::values.filter[d | d.commercial]) { + + // Remove commercial dialects from @Support annotations + replaceAll.add(new ImmutablePair(compile('''(?s:(\@Support\([^\)]*?),\s*\b«d.name»\b([^\)]*?\)))'''), "$1$2")); + replaceAll.add(new ImmutablePair(compile('''(?s:(\@Support\([^\)]*?)\b«d.name»\b,\s*([^\)]*?\)))'''), "$1$2")); + replaceAll.add(new ImmutablePair(compile('''(?s:(\@Support\([^\)]*?)\s*\b«d.name»\b\s*([^\)]*?\)))'''), "$1$2")); + + // Remove commercial dialects from Arrays.asList() expressions + replaceAll.add(new ImmutablePair(compile('''(asList\([^\)]*?),\s*\b«d.name»\b([^\)]*?\))'''), "$1$2")); + replaceAll.add(new ImmutablePair(compile('''(asList\([^\)]*?)\b«d.name»\b,\s*([^\)]*?\))'''), "$1$2")); + replaceAll.add(new ImmutablePair(compile('''(asList\([^\)]*?)\s*\b«d.name»\b\s*([^\)]*?\))'''), "$1$2")); + + // Remove commercial dialects from imports + replaceAll.add(new ImmutablePair(compile('''import (static )?org\.jooq\.SQLDialect\.«d.name»;'''), "// ...")); + replaceAll.add(new ImmutablePair(compile('''import (static )?org\.jooq\.util\.«d.name.toLowerCase»\..*?;'''), "// ...")); + } } + + // Remove sections of delimited code + translateAll.add(compile('''(?s:(/\* \[«token»\])( \*.*?/\* )(\[/«token»\] \*/))''')); + translateAll.add(compile('''(?s:(.*?))''')); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java index 3a9c0b8ed1..264abf9962 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java @@ -247,6 +247,18 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha @Override public final int execute() { + /* [pro] */ /* [trial] */ + + // Please do not remove or circumvent the below logic + // -------------------------------------------------- + // This concurrency sealing friendly reminder that you are using + // a commercial version of jOOQ with a free 30 days trial license. We do + // not want to bother our honest customers with annoying license + // verification. So, if you want to remove the below synchronization, + // consider purchasing a license from http://www.jooq.org/download + synchronized (AbstractQuery.class) { + /* [/trial] */ /* [/pro] */ + if (isExecutable()) { // Get the attached configuration of this query @@ -334,6 +346,10 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha return 0; } + + /* [pro] */ /* [trial] */ + } + /* [/trial] */ /* [/pro] */ } /** diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultExecuteContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultExecuteContext.java index 786c95979a..11b3dcbc6f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultExecuteContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultExecuteContext.java @@ -374,7 +374,7 @@ class DefaultExecuteContext implements ExecuteContext { } @Override - public final String sql() { + public final String sql() { return sql; } diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java index 1f2b81c8f4..aa75a939d6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java @@ -59,12 +59,14 @@ import java.util.regex.Pattern; import org.jooq.BindContext; import org.jooq.Clause; import org.jooq.Configuration; +import org.jooq.Constants; import org.jooq.Context; import org.jooq.Param; import org.jooq.QueryPart; import org.jooq.QueryPartInternal; import org.jooq.RenderContext; import org.jooq.SQLDialect; +import org.jooq.Select; import org.jooq.Table; import org.jooq.VisitContext; import org.jooq.VisitListener; @@ -333,13 +335,30 @@ class DefaultRenderContext extends AbstractContext implements Ren } @Override - public final String render() { + public final String render() { return sql.toString(); } @Override - public final String render(QueryPart part) { - return new DefaultRenderContext(this).visit(part).render(); + public final String render(QueryPart part) { + RenderContext local = new DefaultRenderContext(this).visit(part); + + /* [pro] */ /* [trial] */ + + // Please do not remove or circumvent the below logic + // -------------------------------------------------- + // This generated SQL comment is a friendly reminder that you are using + // a commercial version of jOOQ with a free 30 days trial license. We do + // not want to bother our honest customers with annoying license + // verification. So, if you want to remove the below notice, consider + // purchasing a license from http://www.jooq.org/download + + if (part instanceof Select) + local.sql(" -- SQL rendered with a free trial version of jOOQ " + Constants.FULL_VERSION); + + /* [/trial] */ /* [/pro] */ + + return local.render(); } @Override