Skip to content

Commit

Permalink
feat(core): Initial extensions support. Relates to #929
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Oct 27, 2022
1 parent a5711a2 commit 37bee34
Show file tree
Hide file tree
Showing 106 changed files with 1,521 additions and 271 deletions.
19 changes: 19 additions & 0 deletions api/jreleaser-logger-api/gradle.properties
@@ -0,0 +1,19 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2020-2022 The JReleaser authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

project_description = JReleaser logger API
37 changes: 37 additions & 0 deletions api/jreleaser-logger-api/jreleaser-logger-api.gradle
@@ -0,0 +1,37 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
dependencies {
api project(':jreleaser-model-api')
api project(':jreleaser-resource-bundle')

compileOnly "org.kordamp.jipsy:jipsy-annotations:${jipsyVersion}"
annotationProcessor "org.kordamp.jipsy:jipsy-processor:${jipsyVersion}"

api('kr.motd.maven:os-maven-plugin:1.7.0') { transitive = false }
api "com.github.spullara.mustache.java:compiler:$mustacheVersion"
api "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
api "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
api "org.bouncycastle:bcpg-jdk15on:$bouncyCastleVersion"
// checksum
api "commons-codec:commons-codec:$commonsCodecVersion"
api "org.apache.commons:commons-compress:$commonsCompressVersion"
api "org.slf4j:jcl-over-slf4j:$slf4jVersion"
api "org.zeroturnaround:zt-exec:$ztexecVersion"
api "com.github.veithen.cosmos.bootstrap:org.tukaani.xz:$xzVersion"
api "org.commonmark:commonmark:$commonmarkVersion"
}
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.util;
package org.jreleaser.logging;

import java.io.PrintWriter;
import java.util.Stack;
Expand Down
Expand Up @@ -15,14 +15,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.util;
package org.jreleaser.logging;

import java.io.PrintWriter;

/**
* @author Andres Almiray
* @since 0.1.0
*/
@org.jreleaser.infra.nativeimage.annotations.NativeImage
public interface JReleaserLogger {
PrintWriter getTracer();

Expand Down
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.util;
package org.jreleaser.logging;

import org.slf4j.helpers.MessageFormatter;

Expand Down
19 changes: 19 additions & 0 deletions api/jreleaser-model-api/gradle.properties
@@ -0,0 +1,19 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2020-2022 The JReleaser authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

project_description = JReleaser model API
21 changes: 21 additions & 0 deletions api/jreleaser-model-api/jreleaser-model-api.gradle
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

dependencies {
api project(':jreleaser-resource-bundle')
}
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.extensions.api;

import java.util.Set;

/**
* @author Andres Almiray
* @since 1.3.0
*/
public interface Extension {
String getName();

Set<? extends ExtensionPoint> provides();
}
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.extensions.api;

import java.util.Set;

/**
* @author Andres Almiray
* @since 1.3.0
*/
public interface ExtensionManager {
<T extends ExtensionPoint> Set<T> findExtensionPoints(Class<T> extensionPointType);
}
@@ -0,0 +1,76 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.extensions.api;

import org.jreleaser.bundle.RB;

import java.util.List;
import java.util.ServiceLoader;
import java.util.function.Supplier;
import java.util.stream.StreamSupport;

import static java.util.stream.Collectors.toList;

/**
* @author Andres Almiray
* @since 1.3.0
*/
@org.jreleaser.infra.nativeimage.annotations.NativeImage
public final class ExtensionManagerHolder {
private static final ThreadLocal<ExtensionManager> EXTENSION_MANAGER_THREAD_LOCAL = ThreadLocal.withInitial(new Supplier<ExtensionManager>() {
@Override
public ExtensionManager get() {
List<ExtensionManager> extensionManagers = StreamSupport
.stream(resolveServiceLoader().spliterator(), false)
.collect(toList());

if (extensionManagers.size() == 0) {
// Should never happen!
throw new IllegalStateException(RB.$("ERROR_extension_manager_load"));
} else if (extensionManagers.size() > 1) {
throw new IllegalStateException(RB.$("ERROR_extension_manager_multiple_instances", extensionManagers.size()));
}

return extensionManagers.get(0);
}
});

public static ExtensionManager get() {
return EXTENSION_MANAGER_THREAD_LOCAL.get();
}

private static ServiceLoader<ExtensionManager> resolveServiceLoader() {
// TODO: review when moving baseline to JDK11+
// Check if handlers must be loaded from a ModuleLayer
// if (null != ExtensionManager.class.getModule().getLayer()) {
// ServiceLoader<ExtensionManager> handlers = ServiceLoader.load(ExtensionManager.class.getModule().getLayer(), ExtensionManager.class);
// if (handlers.stream().count() > 0) {
// return handlers;
// }
// }

// Check if the ExtensionManager.class.classLoader works
ServiceLoader<ExtensionManager> handlers = ServiceLoader.load(ExtensionManager.class, ExtensionManager.class.getClassLoader());
if (handlers.iterator().hasNext()) {
return handlers;
}

// If *nothing* else works
return ServiceLoader.load(ExtensionManager.class);
}
}
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.extensions.api;

import java.util.Map;

/**
* @author Andres Almiray
* @since 1.3.0
*/
public interface ExtensionPoint {
default void init(Map<String, Object> properties) {
// noop
}
}
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.extensions.api.mustache;

import org.jreleaser.extensions.api.ExtensionPoint;

import java.util.Map;

/**
* @author Andres Almiray
* @since 1.3.0
*/
public interface MustacheExtensionPoint extends ExtensionPoint {
void apply(Map<String, Object> props);
}
Expand Up @@ -18,7 +18,7 @@
package org.jreleaser.cli;

import org.jreleaser.cli.internal.ColorizedJReleaserLoggerAdapter;
import org.jreleaser.util.JReleaserLogger;
import org.jreleaser.logging.JReleaserLogger;
import org.jreleaser.util.StringUtils;
import picocli.CommandLine;

Expand Down
Expand Up @@ -84,6 +84,7 @@ protected void execute() {
mappings.put("Map<String, SftpDownloader>", "SftpDownloaderMap");
mappings.put("Map<String, ScpDownloader>", "ScpDownloaderMap");
mappings.put("Map<String, HttpAnnouncer>", "HttpAnnouncerMap");
mappings.put("Map<String, Extension>", "ExtensionMap");

try {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON);
Expand Down
Expand Up @@ -17,7 +17,7 @@
*/
package org.jreleaser.cli.internal;

import org.jreleaser.util.AbstractJReleaserLogger;
import org.jreleaser.logging.AbstractJReleaserLogger;
import org.slf4j.helpers.MessageFormatter;
import picocli.CommandLine;

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -110,7 +110,7 @@ subprojects {

projects {
subprojects {
dirs(['core', 'sdks']) {
dirs(['api', 'core', 'sdks']) {
compileJava {
options.compilerArgs += ["-AprojectPath=${project.group}/${project.name}"]
}
Expand Down
1 change: 1 addition & 0 deletions core/jreleaser-engine/jreleaser-engine.gradle
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/
dependencies {
api project(':jreleaser-extensions-impl')
api project(':jreleaser-model')
api project(':git-sdk')
api project(':tool-sdk')
Expand Down
Expand Up @@ -19,10 +19,10 @@

import org.jreleaser.bundle.RB;
import org.jreleaser.config.JReleaserConfigLoader;
import org.jreleaser.logging.JReleaserLogger;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.util.JReleaserException;
import org.jreleaser.util.JReleaserLogger;
import org.jreleaser.util.PlatformUtils;

import java.nio.file.Path;
Expand Down

0 comments on commit 37bee34

Please sign in to comment.