Skip to content

Commit

Permalink
publishing to maven central supported
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed Nov 9, 2021
1 parent 08c64ec commit a1c4908
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 186 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ plugins {

allprojects {

repositories {
maven { url 'https://jitpack.io' }
mavenCentral()
mavenLocal()
}

apply plugin: 'java'
apply plugin: 'com.github.hierynomus.license'

Expand Down
4 changes: 2 additions & 2 deletions config/common.properties
Original file line number Diff line number Diff line change
@@ -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
15 changes: 11 additions & 4 deletions subprojects/executor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ buildscript {
ext.vmfPluginIntelliJIntegration = true

repositories {
maven { url 'https://jitpack.io' }
mavenCentral()
jcenter()
mavenLocal()
}

Expand All @@ -20,24 +20,31 @@ 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()
}

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")
}

Expand Down
120 changes: 85 additions & 35 deletions subprojects/executor/gradle/publishing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -28,6 +29,7 @@ artifacts {
archives javadocJar
archives sourcesJar
}

Date buildTimeAndDate = new Date()
ext {
buildDate = new java.text.SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
Expand All @@ -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
)
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> evtQueue = new ConcurrentLinkedDeque<>();
private Thread doActionThread;
Expand All @@ -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<Executor> pathToRoot = new ArrayList<>();
private final List<FSMExecutor> 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<Executor> getLCA(Executor a, Executor b) {
private static Optional<FSMExecutor> getLCA(FSMExecutor a, FSMExecutor b) {
int start = Math.min(a.pathToRoot.size(), b.pathToRoot.size());

for(int i = start; i >=0; i++) {
Expand All @@ -66,7 +66,7 @@ private static Optional<Executor> 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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
});
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit a1c4908

Please sign in to comment.