From a1c4908d8c6d4e20bc6a9b43449b989f6bbac34a Mon Sep 17 00:00:00 2001 From: miho Date: Tue, 9 Nov 2021 13:28:38 +0100 Subject: [PATCH] publishing to maven central supported --- build.gradle | 6 + config/common.properties | 4 +- subprojects/executor/build.gradle | 15 ++- subprojects/executor/gradle/publishing.gradle | 120 +++++++++++++----- .../{Executor.java => FSMExecutor.java} | 26 ++-- .../mihosoft/vsm/executor/FSMExecutors.java | 32 +++++ .../java/eu/mihosoft/vsm/model/FSMTest.java | 72 +++++------ subprojects/fsm/build.gradle | 23 ++-- subprojects/fsm/gradle/publishing.gradle | 120 +++++++++++++----- ...yncExecutor.java => AsyncFSMExecutor.java} | 2 +- .../model/{Executor.java => FSMExecutor.java} | 4 +- .../java/eu/mihosoft/vsm/model/Storage.java | 7 +- .../eu/mihosoft/vsm/model/vmfmodel/FSM.java | 4 +- subprojects/vrlfsm/build.gradle | 1 - subprojects/vrlfsm/gradle/publishing.gradle | 120 +++++++++++++----- 15 files changed, 370 insertions(+), 186 deletions(-) rename subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/{Executor.java => FSMExecutor.java} (97%) create mode 100644 subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/FSMExecutors.java rename subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/{AsyncExecutor.java => AsyncFSMExecutor.java} (97%) rename subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/{Executor.java => FSMExecutor.java} (98%) diff --git a/build.gradle b/build.gradle index 9613a37..7a3530c 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,12 @@ plugins { allprojects { + repositories { + maven { url 'https://jitpack.io' } + mavenCentral() + mavenLocal() + } + apply plugin: 'java' apply plugin: 'com.github.hierynomus.license' diff --git a/config/common.properties b/config/common.properties index 6d1287d..ca9ba32 100644 --- a/config/common.properties +++ b/config/common.properties @@ -1,4 +1,4 @@ #vmf.version = 0.3-SNAPSHOT -vmf.version = 0.2.7.19 +vmf.version = 0.2.8.1 -publication.version = 0.2.0 +publication.version = 0.3.1 diff --git a/subprojects/executor/build.gradle b/subprojects/executor/build.gradle index 7881680..a626416 100644 --- a/subprojects/executor/build.gradle +++ b/subprojects/executor/build.gradle @@ -3,8 +3,8 @@ buildscript { ext.vmfPluginIntelliJIntegration = true repositories { + maven { url 'https://jitpack.io' } mavenCentral() - jcenter() mavenLocal() } @@ -20,17 +20,19 @@ plugins { // id 'com.github.hierynomus.license' version '0.14.0' id 'maven-publish' id 'net.nemerosa.versioning' version '2.7.1' - id 'com.jfrog.bintray' version '1.8.4' id 'com.github.ben-manes.versions' version '0.13.0' } + + // load plugins -apply plugin: 'eu.mihosoft.vmf' +//apply plugin: 'eu.mihosoft.vmf' apply from: 'gradle/publishing.gradle' + repositories { + maven { url 'https://jitpack.io' } mavenCentral() - jcenter() mavenLocal() } @@ -38,6 +40,11 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.hamcrest:hamcrest:2.2' +// vmfCompile "com.github.miho:VMF:${rootProject.commonProps.get("vmf.version")}" +// vmfCompileTest "com.github.miho:VMF:${rootProject.commonProps.get("vmf.version")}" + + implementation "eu.mihosoft.vmf:vmf-runtime:${rootProject.commonProps.get("vmf.version")}" + implementation project(":subprojects:fsm") } diff --git a/subprojects/executor/gradle/publishing.gradle b/subprojects/executor/gradle/publishing.gradle index 4d8d648..a9330c8 100644 --- a/subprojects/executor/gradle/publishing.gradle +++ b/subprojects/executor/gradle/publishing.gradle @@ -7,19 +7,20 @@ ext.publishing.bintray = [:] ext.publishing.pomName = ext.publishing.artifactId apply from: "gradle/project-info.gradle" +apply plugin: 'signing' // ----------------------------------------------------------------------------- // Performs publishing // ----------------------------------------------------------------------------- task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier = 'javadoc' from javadoc.destinationDir } // create one jar for the source files task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' + archiveClassifier = 'sources' from sourceSets.main.allSource } @@ -28,6 +29,7 @@ artifacts { archives javadocJar archives sourcesJar } + Date buildTimeAndDate = new Date() ext { buildDate = new java.text.SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate) @@ -37,15 +39,15 @@ ext { jar { manifest { attributes( - 'Built-By': System.properties['user.name'], - 'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")", - 'Build-Date': project.buildDate, - 'Build-Time': project.buildTime, - 'Build-Revision': versioning.info.commit, - 'Specification-Title': project.name, - 'Specification-Version': project.version, - 'Implementation-Title': project.name, - 'Implementation-Version': project.version + 'Built-By': System.properties['user.name'], + 'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")", + 'Build-Date': project.buildDate, + 'Build-Time': project.buildTime, + 'Build-Revision': versioning.info.commit, + 'Specification-Title': project.name, + 'Specification-Version': project.version, + 'Implementation-Title': project.name, + 'Implementation-Version': project.version ) } } @@ -76,9 +78,66 @@ def pomConfig = { } } + + publishing { + + repositories { + // -------------------------------------------------------------------------------- + // Destination Repository 'GitHubPackages' + // -> call task 'publishMavenJavaPublicationToGitHubPackagesRepository' to publish + // -------------------------------------------------------------------------------- + maven { + name = "GitHubPackages" + // see https://levelup.gitconnected.com/publish-a-maven-package-to-github-with-gradle-fabc6de24d6 + // Replace OWNER and REPOSITORY with your GitHub username/repository + // (must be both lowercase according to the documenations) + // url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY") + url = uri("https://maven.pkg.github.com/miho/vsm") + credentials { + // Make sure to generate a token with write-packages and read-packages permission: + // https://github.com/settings/tokens/new + // You can either store the username and token in + // ~/.gradle/gradle.properties (use the gpr.user and gpr.key keys) + // Or you can store them as environment variables e.g. in ~/.bash_profile or ~/.zsh + // depending on your shell (GITHUB_USERNAME and GITHUB_TOKEN keys) + // Or you pass them via CLI: gradle publish -Pgpr.user=username -Pgpr.key=token + // See at EOF for examples on how to store the credentials + username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME") + password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") + } + } + + // -------------------------------------------------------------------------------- + // Destination Repository 'OSSRH' + // telling gradle to publish artifact to local directory + // -> call task 'publishMavenJavaPublicationToOSSRHRepository' to publish + // -> go to https://oss.sonatype.org/#stagingRepositories, click 'close', drink coffee and then click 'release' + // if closing was successful + // -------------------------------------------------------------------------------- + maven { + name = "OSSRH" + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + credentials { + username = project.findProperty("oss.user") ?: System.getenv("OSS_USERNAME") + password = project.findProperty("oss.pwd") ?: System.getenv("OSS_PWD") + } + } + + // -------------------------------------------------------------------------------- + // Destination Repository 'BuildDir' + // telling gradle to publish artifact to local directory + // -> call task 'publishMavenJavaPublicationToBuildDirRepository' to publish + // -------------------------------------------------------------------------------- + maven { + name = "BuildDir" + url "file:/${buildDir}/artifacts" + } + } + + publications { - mavenCustom(MavenPublication) { + mavenJava(MavenPublication) { groupId publishing.groupId artifactId publishing.artifactId version publishing.versionId @@ -95,28 +154,19 @@ publishing { } } -if (!project.hasProperty('bintrayUsername')) ext.bintrayUsername = '' -if (!project.hasProperty('bintrayApiKey')) ext.bintrayApiKey = '' - -bintray { - user = project.bintrayUsername - key = project.bintrayApiKey - publications = ['mavenCustom'] - pkg { - repo = publishing.bintray.repo - userOrg = publishing.bintray.userOrg - name = publishing.bintray.name - desc = publishing.desc - licenses = [publishing.license] - labels = publishing.labels - websiteUrl = publishing.websiteUrl - issueTrackerUrl = publishing.issueTrackerUrl - vcsUrl = publishing.vcsUrl - publicDownloadNumbers = true - - version { - name = publishing.versionId - vcsTag = 'v' + publishing.versionId +// TODO for some reason 'sign publications.publishing' is null, we search for publications manually +afterEvaluate { + // find publications + def myPublications = []; + tasks.withType(PublishToMavenRepository) { task -> + if(!myPublications.contains(task.publication)) + myPublications.add(task.publication) + } + + signing { + myPublications.each { + sign it } } -} \ No newline at end of file +} + diff --git a/subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/Executor.java b/subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/FSMExecutor.java similarity index 97% rename from subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/Executor.java rename to subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/FSMExecutor.java index ff2b2b1..3e10ff4 100644 --- a/subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/Executor.java +++ b/subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/FSMExecutor.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -public class Executor implements eu.mihosoft.vsm.model.AsyncExecutor { +class FSMExecutor implements AsyncFSMExecutor { private final Deque evtQueue = new ConcurrentLinkedDeque<>(); private Thread doActionThread; @@ -45,16 +45,16 @@ public class Executor implements eu.mihosoft.vsm.model.AsyncExecutor { private final ReentrantLock fsmLock = new ReentrantLock(); private final ReentrantLock eventLock = new ReentrantLock(); - private final List pathToRoot = new ArrayList<>(); + private final List pathToRoot = new ArrayList<>(); - private final AsyncExecutor.ExecutionMode mode; + private final AsyncFSMExecutor.ExecutionMode mode; private static final long MAX_EVT_CONSUMED_ACTION_TIMEOUT = 1000 /*ms*/; private static final long MAX_ENTER_ACTION_TIMEOUT = 1000 /*ms*/; private static final long MAX_EXIT_ACTION_TIMEOUT = 1000 /*ms*/; private static final long MAX_TRANSITION_ACTION_TIMEOUT = 1000 /*ms*/; - private static Optional getLCA(Executor a, Executor b) { + private static Optional getLCA(FSMExecutor a, FSMExecutor b) { int start = Math.min(a.pathToRoot.size(), b.pathToRoot.size()); for(int i = start; i >=0; i++) { @@ -66,7 +66,7 @@ private static Optional getLCA(Executor a, Executor b) { return Optional.empty(); } - private Executor(FSM fsm, ExecutionMode mode, int depth, Executor parent) { + private FSMExecutor(FSM fsm, ExecutionMode mode, int depth, FSMExecutor parent) { this.fsm = fsm; this.mode = mode; this.fsm.setExecutor(this); @@ -77,8 +77,8 @@ private Executor(FSM fsm, ExecutionMode mode, int depth, Executor parent) { pathToRoot.add(this); } - public static Executor newInstance(FSM fsm, ExecutionMode mode) { - return new Executor(fsm, mode, 0, null); + public static FSMExecutor newInstance(FSM fsm, ExecutionMode mode) { + return new FSMExecutor(fsm, mode, 0, null); } private int getDepth() { @@ -528,7 +528,7 @@ private void handleExecutionError(Event evt, State oldState, State newState, Exc throw new RuntimeException("Action cannot be executed", ex); } - eu.mihosoft.vsm.model.Executor parentExecutor = getCaller().getParentState().getOwningFSM().getExecutor(); + eu.mihosoft.vsm.model.FSMExecutor parentExecutor = getCaller().getParentState().getOwningFSM().getExecutor(); parentExecutor.triggerFirst(Event.newBuilder().withName(FSMEvents.ERROR.getName()). withArgs(evt, oldState, newState, ex).build()); @@ -667,7 +667,7 @@ private void performStateTransition(Event evt, State oldState, State newState, T if (childFSM.getExecutor() == null) { getCaller().getExecutor().newChild(childFSM); } - eu.mihosoft.vsm.model.Executor executor = childFSM.getExecutor(); + eu.mihosoft.vsm.model.FSMExecutor executor = childFSM.getExecutor(); executor.reset(); childFSM.setRunning(true); } finally { @@ -724,7 +724,7 @@ private void performStateTransition(Event evt, State oldState, State newState, T getCaller().getExecutor().newChild(childFSM); } - eu.mihosoft.vsm.model.Executor executor = childFSM.getExecutor(); + eu.mihosoft.vsm.model.FSMExecutor executor = childFSM.getExecutor(); executor.reset(); executor.accessFSMSafe((cfsm)->{ cfsm.setRunning(true); @@ -819,7 +819,7 @@ private boolean exitDoActionOfOldState(Event evt, State oldState, State newState if (oldState instanceof FSMState) { FSMState fsmState = (FSMState) oldState; for (FSM childFSM : fsmState.getFSMs()) { - eu.mihosoft.vsm.model.Executor executor = childFSM.getExecutor(); + eu.mihosoft.vsm.model.FSMExecutor executor = childFSM.getExecutor(); executor.accessFSMSafe(fsmc -> { executor.exitDoActionOfState(evt, childFSM.getCurrentState()); }); @@ -1033,8 +1033,8 @@ private void log(String msg) { } @Override - public eu.mihosoft.vsm.model.Executor newChild(FSM fsm) { - return new Executor(fsm,this.mode,this.depth+1, this); + public eu.mihosoft.vsm.model.FSMExecutor newChild(FSM fsm) { + return new FSMExecutor(fsm,this.mode,this.depth+1, this); } @Override diff --git a/subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/FSMExecutors.java b/subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/FSMExecutors.java new file mode 100644 index 0000000..1edb23f --- /dev/null +++ b/subprojects/executor/src/main/java/eu/mihosoft/vsm/executor/FSMExecutors.java @@ -0,0 +1,32 @@ +package eu.mihosoft.vsm.executor; + +import eu.mihosoft.vsm.model.AsyncFSMExecutor; +import eu.mihosoft.vsm.model.FSM; + +/** + * FSM Executors. + */ +public final class FSMExecutors { + private FSMExecutors() { + throw new AssertionError("Don't instantiate me!"); + } + + /** + * Creates a new async executor. + * @param fsm the fsm to execute + * @return new async executor instance + */ + public static AsyncFSMExecutor newAsyncExecutor(FSM fsm) { + return FSMExecutor.newInstance(fsm, AsyncFSMExecutor.ExecutionMode.PARALLEL_REGIONS); + } + + /** + * Creates a new async executor. + * @param fsm the fsm to execute + * @param executionMode the execution mode to use + * @return new async executor instance + */ + public static AsyncFSMExecutor newAsyncExecutor(FSM fsm, AsyncFSMExecutor.ExecutionMode executionMode) { + return FSMExecutor.newInstance(fsm, executionMode); + } +} diff --git a/subprojects/executor/src/test/java/eu/mihosoft/vsm/model/FSMTest.java b/subprojects/executor/src/test/java/eu/mihosoft/vsm/model/FSMTest.java index f183d12..81173a3 100644 --- a/subprojects/executor/src/test/java/eu/mihosoft/vsm/model/FSMTest.java +++ b/subprojects/executor/src/test/java/eu/mihosoft/vsm/model/FSMTest.java @@ -27,9 +27,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import eu.mihosoft.vsm.executor.Executor; +import eu.mihosoft.vsm.executor.FSMExecutors; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; import java.lang.management.ManagementFactory; @@ -38,15 +37,13 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; -import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.IntStream; -import java.util.stream.StreamSupport; public class FSMTest { - private static final eu.mihosoft.vsm.model.AsyncExecutor.ExecutionMode MODE - = eu.mihosoft.vsm.model.AsyncExecutor.ExecutionMode.PARALLEL_REGIONS; + private static final AsyncFSMExecutor.ExecutionMode MODE + = AsyncFSMExecutor.ExecutionMode.PARALLEL_REGIONS; private static final int NUM_ITERATIONS_LARGE_TESTS = 5; private static final int NUM_ITERATIONS_SMALL_TESTS = 10; @@ -163,7 +160,7 @@ static boolean sleepRandom(long min, long max) { } }); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); executor.startAsync(); @@ -218,7 +215,7 @@ public void nestedOrthogonalWithDoActionProcessingTest() throws InterruptedExcep FSM fsm = createNestedWithOrthogonal(actualEvtList, false); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); // executor.startAsync(); fsm.setRunning(true); executor.trigger("myEvent1", (e, t) -> System.out.println("consumed " + e.getName() + ", " + t.getOwningFSM().getName())); @@ -231,7 +228,7 @@ public void nestedOrthogonalWithDoActionProcessingTest() throws InterruptedExcep executor.processRemainingEvents(); } - if(MODE == eu.mihosoft.vsm.model.AsyncExecutor.ExecutionMode.PARALLEL_REGIONS) { + if(MODE == AsyncFSMExecutor.ExecutionMode.PARALLEL_REGIONS) { Thread.sleep(100); // TODO (hasRemainingEvents() might still be buggy) @@ -281,7 +278,7 @@ public void nestedOrthogonalWithDoActionInterruptedProcessingTest() { FSM fsm = createNestedWithOrthogonal(actualEvtList, false); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); fsm.setRunning(true); executor.trigger("myEvent1", (e, t) -> System.out.println("consumed " + e.getName() + ", " + t.getOwningFSM().getName())); @@ -335,7 +332,7 @@ public void nestedOrthogonalWithDoActionAsyncTest() throws InterruptedException FSM fsm = createNestedWithOrthogonal(actualEvtList, false); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); executor.startAsync(); executor.trigger("myEvent1", (e, t) -> System.out.println("consumed " + e.getName() + ", " + t.getOwningFSM().getName())); @@ -389,7 +386,7 @@ public void nestedOrthogonalWithDoActionInterruptAsyncTest() throws InterruptedE FSM fsm = createNestedWithOrthogonal(actualEvtList, false); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); executor.startAsync(); executor.trigger("myEvent1", (e, t) -> System.out.println("consumed " + e.getName() + ", " + t.getOwningFSM().getName())); @@ -444,7 +441,7 @@ public void nestedOrthogonalWithDoActionInterruptViaFinalStateAsyncTest() throws FSM fsm = createNestedWithOrthogonal(actualEvtList, true); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); executor.startAsync(); executor.trigger("myEvent1", (e, t) -> System.out.println("consumed " + e.getName() + ", " + t.getOwningFSM().getName())); @@ -623,8 +620,8 @@ private static FSM createNestedWithOrthogonal(List enterExitListOrig, bo .withSource(stateC) .withTarget(stateA) .withTrigger(finalStateInNested - ?eu.mihosoft.vsm.model.Executor.FSMEvents.FINAL_STATE.getName() - :eu.mihosoft.vsm.model.Executor.FSMEvents.DO_ACTION_DONE.getName()) + ? FSMExecutor.FSMEvents.FINAL_STATE.getName() + : FSMExecutor.FSMEvents.DO_ACTION_DONE.getName()) .build() ) .build(); @@ -707,7 +704,7 @@ public void enterNestedStateDirectlyTest() throws InterruptedException { fsm.getTransitions().add(a_a__a_b_a); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); fsm.setRunning(true); executor.process("myEvent1"); fsm.setRunning(false); @@ -805,7 +802,7 @@ public void lockedDoorTest() throws InterruptedException { .withTransitions(openDoor,closeDoor,lockDoor,unlockDoor) .build(); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); fsm.setRunning(true); @@ -936,7 +933,7 @@ public void lockedDoorWithLockVariableAndLocalTransitionTest() throws Interrupte .withTransitions(openDoor,closeDoor,lockDoor,unlockDoor) .build(); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); fsm.setRunning(true); @@ -1066,7 +1063,7 @@ public void lockedDoorWithLockVariableTest() throws InterruptedException { .withTransitions(openDoor,closeDoor,lockDoor,unlockDoor) .build(); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); fsm.setRunning(true); @@ -1197,7 +1194,7 @@ public void transitionPriorityTest1() throws InterruptedException, ExecutionExce System.out.println("\nCase Priority to C2:"); List actualEvtList = new ArrayList<>(); FSM fsm = createTransitionPriorityFSM(actualEvtList, true); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); executor.startAsync(); @@ -1234,7 +1231,7 @@ public void transitionPriorityTest1() throws InterruptedException, ExecutionExce System.out.println("\nCase Priority to S2:"); List actualEvtList = new ArrayList<>(); FSM fsm = createTransitionPriorityFSM(actualEvtList, false); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); executor.startAsync(); @@ -1409,7 +1406,7 @@ public void testChildrenDoneEvent() throws InterruptedException { .build(); Transition c1_c2 = Transition.newBuilder() - .withTrigger(eu.mihosoft.vsm.model.Executor.FSMEvents.STATE_DONE.getName()) + .withTrigger(FSMExecutor.FSMEvents.STATE_DONE.getName()) .withSource(c1) .withTarget(c2) .build(); @@ -1474,19 +1471,19 @@ public void testChildrenDoneEvent() throws InterruptedException { .build(); Transition s1_childFSMState = Transition.newBuilder() - .withTrigger(eu.mihosoft.vsm.model.Executor.FSMEvents.STATE_DONE.getName()) + .withTrigger(FSMExecutor.FSMEvents.STATE_DONE.getName()) .withSource(s1) .withTarget(childFSMState) .build(); Transition childFSMState_s2 = Transition.newBuilder() - .withTrigger(eu.mihosoft.vsm.model.Executor.FSMEvents.FINAL_STATE.getName()) + .withTrigger(FSMExecutor.FSMEvents.FINAL_STATE.getName()) .withSource(childFSMState) .withTarget(s2) .build(); Transition s2_s3 = Transition.newBuilder() - .withTrigger(eu.mihosoft.vsm.model.Executor.FSMEvents.STATE_DONE.getName()) + .withTrigger(FSMExecutor.FSMEvents.STATE_DONE.getName()) .withSource(s2) .withTarget(s3) .build(); @@ -1510,7 +1507,7 @@ public void testChildrenDoneEvent() throws InterruptedException { fsm.setVerbose(true); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); fsm.setRunning(true); @@ -1518,7 +1515,7 @@ public void testChildrenDoneEvent() throws InterruptedException { executor.processRemainingEvents(); } - if(MODE == eu.mihosoft.vsm.model.AsyncExecutor.ExecutionMode.PARALLEL_REGIONS) { + if(MODE == AsyncFSMExecutor.ExecutionMode.PARALLEL_REGIONS) { Thread.sleep(100); // TODO (hasRemainingEvents() might still be buggy) @@ -1614,13 +1611,13 @@ public void testStateDone() throws InterruptedException { .build(); Transition s1_s2 = Transition.newBuilder() - .withTrigger(eu.mihosoft.vsm.model.Executor.FSMEvents.STATE_DONE.getName()) + .withTrigger(FSMExecutor.FSMEvents.STATE_DONE.getName()) .withSource(s1) .withTarget(s2) .build(); Transition s2_s3 = Transition.newBuilder() - .withTrigger(eu.mihosoft.vsm.model.Executor.FSMEvents.STATE_DONE.getName()) + .withTrigger(FSMExecutor.FSMEvents.STATE_DONE.getName()) .withSource(s2) .withTarget(s3) .build(); @@ -1645,7 +1642,7 @@ public void testStateDone() throws InterruptedException { fsm.setVerbose(true); - Executor executor = Executor.newInstance(fsm, MODE); + var executor = FSMExecutors.newAsyncExecutor(fsm, MODE); fsm.setRunning(true); while(executor.hasRemainingEvents()) { @@ -1703,7 +1700,7 @@ public void errorStateTest1() { .withTransitions(s1s2) .build(); - Executor executor = Executor.newInstance(fsm, eu.mihosoft.vsm.model.AsyncExecutor.ExecutionMode.SERIAL_REGIONS); + var executor = FSMExecutors.newAsyncExecutor(fsm, AsyncFSMExecutor.ExecutionMode.SERIAL_REGIONS); fsm.setRunning(true); executor.process("myEvent1"); @@ -1757,7 +1754,7 @@ public void errorStateNestedFSMTest2() { .withErrorState(error) .build(); - Executor executor = Executor.newInstance(fsm, eu.mihosoft.vsm.model.AsyncExecutor.ExecutionMode.SERIAL_REGIONS); + var executor = FSMExecutors.newAsyncExecutor(fsm, AsyncFSMExecutor.ExecutionMode.SERIAL_REGIONS); fsm.setRunning(true); executor.process("myEvent1"); @@ -1818,8 +1815,7 @@ public void errorStateNestedFSMTest3() throws InterruptedException, ExecutionExc .withErrorState(error) .build(); - Executor executor = Executor.newInstance(fsm, AsyncExecutor.ExecutionMode.SERIAL_REGIONS); - + var executor = FSMExecutors.newAsyncExecutor(fsm, AsyncFSMExecutor.ExecutionMode.SERIAL_REGIONS); executor.startAsync(); Thread.sleep(100); executor.trigger("myEvent1"); @@ -1933,7 +1929,7 @@ public void nestedFSMEventConsumedActionTest() throws InterruptedException, Exec var s3s1F = new CompletableFuture<>(); Transition s3s1 = Transition.newBuilder() - .withTrigger(eu.mihosoft.vsm.model.Executor.FSMEvents.STATE_DONE.getName()) + .withTrigger(FSMExecutor.FSMEvents.STATE_DONE.getName()) .withSource(s3) .withTarget(s1) .withActions((t, e) -> { @@ -1950,7 +1946,7 @@ public void nestedFSMEventConsumedActionTest() throws InterruptedException, Exec .withVerbose(true) .build(); - Executor executor = Executor.newInstance(fsm, AsyncExecutor.ExecutionMode.PARALLEL_REGIONS); + var executor = FSMExecutors.newAsyncExecutor(fsm, AsyncFSMExecutor.ExecutionMode.PARALLEL_REGIONS); executor.startAsync(); @@ -2124,7 +2120,7 @@ public void nestedFSMEventConsumedActionTest2() throws InterruptedException, Exe .withVerbose(true) .build(); - Executor executor = Executor.newInstance(fsm, AsyncExecutor.ExecutionMode.PARALLEL_REGIONS); + var executor = FSMExecutors.newAsyncExecutor(fsm, AsyncFSMExecutor.ExecutionMode.PARALLEL_REGIONS); executor.startAsync(); @@ -2301,7 +2297,7 @@ public void nestedFSM() throws InterruptedException, ExecutionException { .withVerbose(true) .build(); - Executor executor = Executor.newInstance(fsm, AsyncExecutor.ExecutionMode.PARALLEL_REGIONS); + var executor = FSMExecutors.newAsyncExecutor(fsm, AsyncFSMExecutor.ExecutionMode.PARALLEL_REGIONS); executor.startAsync(); diff --git a/subprojects/fsm/build.gradle b/subprojects/fsm/build.gradle index a9869e8..75dcebf 100644 --- a/subprojects/fsm/build.gradle +++ b/subprojects/fsm/build.gradle @@ -3,8 +3,8 @@ buildscript { ext.vmfPluginIntelliJIntegration = true repositories { + maven { url 'https://jitpack.io' } mavenCentral() - jcenter() mavenLocal() } @@ -20,31 +20,26 @@ plugins { // id 'com.github.hierynomus.license' version '0.14.0' id 'maven-publish' id 'net.nemerosa.versioning' version '2.7.1' - id 'com.jfrog.bintray' version '1.8.4' id 'com.github.ben-manes.versions' version '0.13.0' } -// load plugins -apply plugin: 'eu.mihosoft.vmf' -apply from: 'gradle/publishing.gradle' - -repositories { - mavenCentral() - jcenter() - mavenLocal() -} - dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.hamcrest:hamcrest:2.2' - implementation "eu.mihosoft.vmf:vmf:${rootProject.commonProps.get("vmf.version")}" + implementation "eu.mihosoft.vmf:vmf-runtime:${rootProject.commonProps.get("vmf.version")}" } + +// load plugins +apply plugin: 'eu.mihosoft.vmf' +apply from: 'gradle/publishing.gradle' + + // set dependencies for intellij editor (otherwise vmf dir would be ignored) idea.module { dependencies { - implementation group: 'eu.mihosoft.vmf', name: 'vmf', version: rootProject.commonProps.get("vmf.version") + implementation group: 'eu.mihosoft.vmf', name: 'vmf', version: "${rootProject.commonProps.get("vmf.version")}" } } diff --git a/subprojects/fsm/gradle/publishing.gradle b/subprojects/fsm/gradle/publishing.gradle index 4d8d648..a9330c8 100644 --- a/subprojects/fsm/gradle/publishing.gradle +++ b/subprojects/fsm/gradle/publishing.gradle @@ -7,19 +7,20 @@ ext.publishing.bintray = [:] ext.publishing.pomName = ext.publishing.artifactId apply from: "gradle/project-info.gradle" +apply plugin: 'signing' // ----------------------------------------------------------------------------- // Performs publishing // ----------------------------------------------------------------------------- task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier = 'javadoc' from javadoc.destinationDir } // create one jar for the source files task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' + archiveClassifier = 'sources' from sourceSets.main.allSource } @@ -28,6 +29,7 @@ artifacts { archives javadocJar archives sourcesJar } + Date buildTimeAndDate = new Date() ext { buildDate = new java.text.SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate) @@ -37,15 +39,15 @@ ext { jar { manifest { attributes( - 'Built-By': System.properties['user.name'], - 'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")", - 'Build-Date': project.buildDate, - 'Build-Time': project.buildTime, - 'Build-Revision': versioning.info.commit, - 'Specification-Title': project.name, - 'Specification-Version': project.version, - 'Implementation-Title': project.name, - 'Implementation-Version': project.version + 'Built-By': System.properties['user.name'], + 'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")", + 'Build-Date': project.buildDate, + 'Build-Time': project.buildTime, + 'Build-Revision': versioning.info.commit, + 'Specification-Title': project.name, + 'Specification-Version': project.version, + 'Implementation-Title': project.name, + 'Implementation-Version': project.version ) } } @@ -76,9 +78,66 @@ def pomConfig = { } } + + publishing { + + repositories { + // -------------------------------------------------------------------------------- + // Destination Repository 'GitHubPackages' + // -> call task 'publishMavenJavaPublicationToGitHubPackagesRepository' to publish + // -------------------------------------------------------------------------------- + maven { + name = "GitHubPackages" + // see https://levelup.gitconnected.com/publish-a-maven-package-to-github-with-gradle-fabc6de24d6 + // Replace OWNER and REPOSITORY with your GitHub username/repository + // (must be both lowercase according to the documenations) + // url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY") + url = uri("https://maven.pkg.github.com/miho/vsm") + credentials { + // Make sure to generate a token with write-packages and read-packages permission: + // https://github.com/settings/tokens/new + // You can either store the username and token in + // ~/.gradle/gradle.properties (use the gpr.user and gpr.key keys) + // Or you can store them as environment variables e.g. in ~/.bash_profile or ~/.zsh + // depending on your shell (GITHUB_USERNAME and GITHUB_TOKEN keys) + // Or you pass them via CLI: gradle publish -Pgpr.user=username -Pgpr.key=token + // See at EOF for examples on how to store the credentials + username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME") + password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") + } + } + + // -------------------------------------------------------------------------------- + // Destination Repository 'OSSRH' + // telling gradle to publish artifact to local directory + // -> call task 'publishMavenJavaPublicationToOSSRHRepository' to publish + // -> go to https://oss.sonatype.org/#stagingRepositories, click 'close', drink coffee and then click 'release' + // if closing was successful + // -------------------------------------------------------------------------------- + maven { + name = "OSSRH" + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + credentials { + username = project.findProperty("oss.user") ?: System.getenv("OSS_USERNAME") + password = project.findProperty("oss.pwd") ?: System.getenv("OSS_PWD") + } + } + + // -------------------------------------------------------------------------------- + // Destination Repository 'BuildDir' + // telling gradle to publish artifact to local directory + // -> call task 'publishMavenJavaPublicationToBuildDirRepository' to publish + // -------------------------------------------------------------------------------- + maven { + name = "BuildDir" + url "file:/${buildDir}/artifacts" + } + } + + publications { - mavenCustom(MavenPublication) { + mavenJava(MavenPublication) { groupId publishing.groupId artifactId publishing.artifactId version publishing.versionId @@ -95,28 +154,19 @@ publishing { } } -if (!project.hasProperty('bintrayUsername')) ext.bintrayUsername = '' -if (!project.hasProperty('bintrayApiKey')) ext.bintrayApiKey = '' - -bintray { - user = project.bintrayUsername - key = project.bintrayApiKey - publications = ['mavenCustom'] - pkg { - repo = publishing.bintray.repo - userOrg = publishing.bintray.userOrg - name = publishing.bintray.name - desc = publishing.desc - licenses = [publishing.license] - labels = publishing.labels - websiteUrl = publishing.websiteUrl - issueTrackerUrl = publishing.issueTrackerUrl - vcsUrl = publishing.vcsUrl - publicDownloadNumbers = true - - version { - name = publishing.versionId - vcsTag = 'v' + publishing.versionId +// TODO for some reason 'sign publications.publishing' is null, we search for publications manually +afterEvaluate { + // find publications + def myPublications = []; + tasks.withType(PublishToMavenRepository) { task -> + if(!myPublications.contains(task.publication)) + myPublications.add(task.publication) + } + + signing { + myPublications.each { + sign it } } -} \ No newline at end of file +} + diff --git a/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/AsyncExecutor.java b/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/AsyncFSMExecutor.java similarity index 97% rename from subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/AsyncExecutor.java rename to subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/AsyncFSMExecutor.java index 3215c67..94f2878 100644 --- a/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/AsyncExecutor.java +++ b/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/AsyncFSMExecutor.java @@ -24,7 +24,7 @@ import java.util.concurrent.CompletableFuture; -public interface AsyncExecutor extends Executor { +public interface AsyncFSMExecutor extends FSMExecutor { /** * Starts the executor and waits until the state machine has stopped. */ diff --git a/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/Executor.java b/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/FSMExecutor.java similarity index 98% rename from subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/Executor.java rename to subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/FSMExecutor.java index fcf9b0b..7d3d0af 100644 --- a/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/Executor.java +++ b/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/FSMExecutor.java @@ -27,7 +27,7 @@ /** * Executor interface for executing finite state machines (FSM). */ -public interface Executor { +public interface FSMExecutor { /** * Triggers the specified event. @@ -88,7 +88,7 @@ default void trigger(String evt, Object... args) { * @param fsm the state machine to be executed * @return the requested executor instance */ - Executor newChild(FSM fsm); + FSMExecutor newChild(FSM fsm); /** * Indicates whether there are remaining events to be processed. diff --git a/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/Storage.java b/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/Storage.java index 64011d0..c56d98e 100644 --- a/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/Storage.java +++ b/subprojects/fsm/src/main/java/eu/mihosoft/vsm/model/Storage.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -44,7 +43,7 @@ public final class Storage { private final ConcurrentMap map = new ConcurrentHashMap<>(); private final ReentrantLock writeMapLock = new ReentrantLock(); - private final List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); private Storage() { // @@ -63,7 +62,7 @@ public static Storage newInstance() { * @param executor the executor to add * @return a subscription to cancel update notification for the specified listener */ - public Subscription addListener(Executor executor) { + public Subscription addListener(FSMExecutor executor) { writeMapLock.lock(); try { @@ -174,7 +173,7 @@ public boolean hasValue(String key) { private void fireDataChangedEvent(String key, Object value) { writeMapLock.lock(); try { - for(Executor listener : listeners) { + for(FSMExecutor listener : listeners) { listener.trigger(Event.newBuilder(). withName(Events.DATA_UPDATED.name()). withArgs(key)//,value) // TODO value is dangerous if not immutable diff --git a/subprojects/fsm/src/main/vmf/eu/mihosoft/vsm/model/vmfmodel/FSM.java b/subprojects/fsm/src/main/vmf/eu/mihosoft/vsm/model/vmfmodel/FSM.java index 6e140f8..76c75b0 100644 --- a/subprojects/fsm/src/main/vmf/eu/mihosoft/vsm/model/vmfmodel/FSM.java +++ b/subprojects/fsm/src/main/vmf/eu/mihosoft/vsm/model/vmfmodel/FSM.java @@ -72,7 +72,7 @@ interface Guard { } @ExternalType(pkgName = "eu.mihosoft.vsm.model") -interface Executor { +interface FSMExecutor { } @InterfaceOnly @@ -153,7 +153,7 @@ interface FSM extends WithName, StateChild { @Doc("The executor that is used to process the events sent" + " to this state machine. Synchronous as well as async executors" + " are supported.") - Executor getExecutor(); + FSMExecutor getExecutor(); // @DelegateTo(className = "eu.mihosoft.vsm.model.FSMBehavior") // int depth(); diff --git a/subprojects/vrlfsm/build.gradle b/subprojects/vrlfsm/build.gradle index a9869e8..61ebe0f 100644 --- a/subprojects/vrlfsm/build.gradle +++ b/subprojects/vrlfsm/build.gradle @@ -20,7 +20,6 @@ plugins { // id 'com.github.hierynomus.license' version '0.14.0' id 'maven-publish' id 'net.nemerosa.versioning' version '2.7.1' - id 'com.jfrog.bintray' version '1.8.4' id 'com.github.ben-manes.versions' version '0.13.0' } diff --git a/subprojects/vrlfsm/gradle/publishing.gradle b/subprojects/vrlfsm/gradle/publishing.gradle index 4d8d648..a9330c8 100644 --- a/subprojects/vrlfsm/gradle/publishing.gradle +++ b/subprojects/vrlfsm/gradle/publishing.gradle @@ -7,19 +7,20 @@ ext.publishing.bintray = [:] ext.publishing.pomName = ext.publishing.artifactId apply from: "gradle/project-info.gradle" +apply plugin: 'signing' // ----------------------------------------------------------------------------- // Performs publishing // ----------------------------------------------------------------------------- task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier = 'javadoc' from javadoc.destinationDir } // create one jar for the source files task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' + archiveClassifier = 'sources' from sourceSets.main.allSource } @@ -28,6 +29,7 @@ artifacts { archives javadocJar archives sourcesJar } + Date buildTimeAndDate = new Date() ext { buildDate = new java.text.SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate) @@ -37,15 +39,15 @@ ext { jar { manifest { attributes( - 'Built-By': System.properties['user.name'], - 'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")", - 'Build-Date': project.buildDate, - 'Build-Time': project.buildTime, - 'Build-Revision': versioning.info.commit, - 'Specification-Title': project.name, - 'Specification-Version': project.version, - 'Implementation-Title': project.name, - 'Implementation-Version': project.version + 'Built-By': System.properties['user.name'], + 'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")", + 'Build-Date': project.buildDate, + 'Build-Time': project.buildTime, + 'Build-Revision': versioning.info.commit, + 'Specification-Title': project.name, + 'Specification-Version': project.version, + 'Implementation-Title': project.name, + 'Implementation-Version': project.version ) } } @@ -76,9 +78,66 @@ def pomConfig = { } } + + publishing { + + repositories { + // -------------------------------------------------------------------------------- + // Destination Repository 'GitHubPackages' + // -> call task 'publishMavenJavaPublicationToGitHubPackagesRepository' to publish + // -------------------------------------------------------------------------------- + maven { + name = "GitHubPackages" + // see https://levelup.gitconnected.com/publish-a-maven-package-to-github-with-gradle-fabc6de24d6 + // Replace OWNER and REPOSITORY with your GitHub username/repository + // (must be both lowercase according to the documenations) + // url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY") + url = uri("https://maven.pkg.github.com/miho/vsm") + credentials { + // Make sure to generate a token with write-packages and read-packages permission: + // https://github.com/settings/tokens/new + // You can either store the username and token in + // ~/.gradle/gradle.properties (use the gpr.user and gpr.key keys) + // Or you can store them as environment variables e.g. in ~/.bash_profile or ~/.zsh + // depending on your shell (GITHUB_USERNAME and GITHUB_TOKEN keys) + // Or you pass them via CLI: gradle publish -Pgpr.user=username -Pgpr.key=token + // See at EOF for examples on how to store the credentials + username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME") + password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") + } + } + + // -------------------------------------------------------------------------------- + // Destination Repository 'OSSRH' + // telling gradle to publish artifact to local directory + // -> call task 'publishMavenJavaPublicationToOSSRHRepository' to publish + // -> go to https://oss.sonatype.org/#stagingRepositories, click 'close', drink coffee and then click 'release' + // if closing was successful + // -------------------------------------------------------------------------------- + maven { + name = "OSSRH" + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + credentials { + username = project.findProperty("oss.user") ?: System.getenv("OSS_USERNAME") + password = project.findProperty("oss.pwd") ?: System.getenv("OSS_PWD") + } + } + + // -------------------------------------------------------------------------------- + // Destination Repository 'BuildDir' + // telling gradle to publish artifact to local directory + // -> call task 'publishMavenJavaPublicationToBuildDirRepository' to publish + // -------------------------------------------------------------------------------- + maven { + name = "BuildDir" + url "file:/${buildDir}/artifacts" + } + } + + publications { - mavenCustom(MavenPublication) { + mavenJava(MavenPublication) { groupId publishing.groupId artifactId publishing.artifactId version publishing.versionId @@ -95,28 +154,19 @@ publishing { } } -if (!project.hasProperty('bintrayUsername')) ext.bintrayUsername = '' -if (!project.hasProperty('bintrayApiKey')) ext.bintrayApiKey = '' - -bintray { - user = project.bintrayUsername - key = project.bintrayApiKey - publications = ['mavenCustom'] - pkg { - repo = publishing.bintray.repo - userOrg = publishing.bintray.userOrg - name = publishing.bintray.name - desc = publishing.desc - licenses = [publishing.license] - labels = publishing.labels - websiteUrl = publishing.websiteUrl - issueTrackerUrl = publishing.issueTrackerUrl - vcsUrl = publishing.vcsUrl - publicDownloadNumbers = true - - version { - name = publishing.versionId - vcsTag = 'v' + publishing.versionId +// TODO for some reason 'sign publications.publishing' is null, we search for publications manually +afterEvaluate { + // find publications + def myPublications = []; + tasks.withType(PublishToMavenRepository) { task -> + if(!myPublications.contains(task.publication)) + myPublications.add(task.publication) + } + + signing { + myPublications.each { + sign it } } -} \ No newline at end of file +} +