-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Support asdf-vm as packager. Resolves #825
- Loading branch information
Showing
41 changed files
with
1,500 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
core/jreleaser-model/src/main/java/org/jreleaser/model/Asdf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* 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.model; | ||
|
||
import org.jreleaser.util.PlatformUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.jreleaser.model.Distribution.DistributionType.BINARY; | ||
import static org.jreleaser.model.Distribution.DistributionType.JAVA_BINARY; | ||
import static org.jreleaser.model.Distribution.DistributionType.JLINK; | ||
import static org.jreleaser.model.Distribution.DistributionType.NATIVE_IMAGE; | ||
import static org.jreleaser.util.CollectionUtils.newSet; | ||
import static org.jreleaser.util.FileType.TAR; | ||
import static org.jreleaser.util.FileType.TAR_GZ; | ||
import static org.jreleaser.util.FileType.TAR_XZ; | ||
import static org.jreleaser.util.FileType.TGZ; | ||
import static org.jreleaser.util.FileType.TXZ; | ||
import static org.jreleaser.util.FileType.ZIP; | ||
import static org.jreleaser.util.StringUtils.isBlank; | ||
import static org.jreleaser.util.StringUtils.isFalse; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 1.2.0 | ||
*/ | ||
public class Asdf extends AbstractRepositoryPackager<Asdf> { | ||
public static final String TYPE = "asdf"; | ||
public static final String SKIP_ASDF = "skipAsdf"; | ||
|
||
private static final Map<Distribution.DistributionType, Set<String>> SUPPORTED = new LinkedHashMap<>(); | ||
|
||
static { | ||
Set<String> extensions = newSet( | ||
TAR_GZ.extension(), | ||
TAR_XZ.extension(), | ||
TGZ.extension(), | ||
TXZ.extension(), | ||
TAR.extension(), | ||
ZIP.extension()); | ||
|
||
SUPPORTED.put(BINARY, extensions); | ||
SUPPORTED.put(JAVA_BINARY, extensions); | ||
SUPPORTED.put(JLINK, extensions); | ||
SUPPORTED.put(NATIVE_IMAGE, extensions); | ||
} | ||
|
||
private final AsdfRepository repository = new AsdfRepository(); | ||
|
||
private String toolCheck; | ||
|
||
public Asdf() { | ||
super(TYPE); | ||
} | ||
|
||
@Override | ||
public void merge(Asdf source) { | ||
freezeCheck(); | ||
super.merge(source); | ||
this.toolCheck = merge(this.toolCheck, source.toolCheck); | ||
setRepository(source.repository); | ||
} | ||
|
||
public String getToolCheck() { | ||
return toolCheck; | ||
} | ||
|
||
public void setToolCheck(String toolCheck) { | ||
this.toolCheck = toolCheck; | ||
} | ||
|
||
public AsdfRepository getRepository() { | ||
return repository; | ||
} | ||
|
||
public void setRepository(AsdfRepository repository) { | ||
this.repository.merge(repository); | ||
} | ||
|
||
@Override | ||
protected void asMap(boolean full, Map<String, Object> props) { | ||
super.asMap(full, props); | ||
props.put("toolcheck", toolCheck); | ||
props.put("repository", repository.asMap(full)); | ||
} | ||
|
||
@Override | ||
public RepositoryTap getRepositoryTap() { | ||
return repository; | ||
} | ||
|
||
@Override | ||
public boolean supportsPlatform(String platform) { | ||
return isBlank(platform) || | ||
PlatformUtils.isMac(platform) || | ||
PlatformUtils.isLinux(platform); | ||
} | ||
|
||
@Override | ||
public boolean supportsDistribution(Distribution distribution) { | ||
return SUPPORTED.containsKey(distribution.getType()); | ||
} | ||
|
||
@Override | ||
public Set<String> getSupportedExtensions(Distribution distribution) { | ||
return Collections.unmodifiableSet(SUPPORTED.getOrDefault(distribution.getType(), Collections.emptySet())); | ||
} | ||
|
||
@Override | ||
protected boolean isNotSkipped(Artifact artifact) { | ||
return isFalse(artifact.getExtraProperties().get(SKIP_ASDF)); | ||
} | ||
|
||
public static class AsdfRepository extends AbstractRepositoryTap<AsdfRepository> { | ||
public AsdfRepository() { | ||
super("asdf", "asdf"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
core/jreleaser-model/src/main/java/org/jreleaser/model/ExecutionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.model; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.jreleaser.util.StringUtils.isBlank; | ||
import static org.jreleaser.util.StringUtils.requireNonBlank; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 1.1.0 | ||
*/ | ||
public class ExecutionEvent { | ||
private final Type type; | ||
private final String name; | ||
|
||
private ExecutionEvent(Type type, String name) { | ||
this.type = requireNonNull(type, "'type' must not be null"); | ||
this.name = requireNonBlank(name, "'name' must not be blank"); | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public static ExecutionEvent before(String name) { | ||
return new ExecutionEvent(Type.BEFORE, name); | ||
} | ||
|
||
public static ExecutionEvent after(String name) { | ||
return new ExecutionEvent(Type.AFTER, name); | ||
} | ||
|
||
public enum Type { | ||
BEFORE, | ||
AFTER; | ||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(); | ||
} | ||
|
||
public static Type of(String str) { | ||
if (isBlank(str)) return null; | ||
return Type.valueOf(str.replaceAll(" ", "_") | ||
.replaceAll("-", "_") | ||
.toUpperCase().trim()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
core/jreleaser-model/src/main/java/org/jreleaser/model/validation/AsdfValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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.model.validation; | ||
|
||
import org.jreleaser.bundle.RB; | ||
import org.jreleaser.model.Active; | ||
import org.jreleaser.model.Artifact; | ||
import org.jreleaser.model.Asdf; | ||
import org.jreleaser.model.Distribution; | ||
import org.jreleaser.model.GitService; | ||
import org.jreleaser.model.JReleaserContext; | ||
import org.jreleaser.model.JReleaserModel; | ||
import org.jreleaser.util.Errors; | ||
|
||
import java.util.List; | ||
|
||
import static org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms; | ||
import static org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties; | ||
import static org.jreleaser.model.validation.TemplateValidator.validateTemplate; | ||
import static org.jreleaser.util.StringUtils.isBlank; | ||
import static org.jreleaser.util.StringUtils.isNotBlank; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 1.2.0 | ||
*/ | ||
public abstract class AsdfValidator extends Validator { | ||
public static void validateAsdf(JReleaserContext context, Distribution distribution, Asdf packager, Errors errors) { | ||
JReleaserModel model = context.getModel(); | ||
Asdf parentPackager = model.getPackagers().getAsdf(); | ||
|
||
if (!packager.isActiveSet() && parentPackager.isActiveSet()) { | ||
packager.setActive(parentPackager.getActive()); | ||
} | ||
if (!packager.resolveEnabled(context.getModel().getProject(), distribution)) { | ||
packager.disable(); | ||
return; | ||
} | ||
GitService service = model.getRelease().getGitService(); | ||
if (!service.isReleaseSupported()) { | ||
packager.disable(); | ||
return; | ||
} | ||
|
||
List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution); | ||
if (candidateArtifacts.size() == 0) { | ||
packager.setActive(Active.NEVER); | ||
packager.disable(); | ||
return; | ||
} else if (candidateArtifacts.stream() | ||
.filter(artifact -> isBlank(artifact.getPlatform())) | ||
.count() > 1) { | ||
errors.configuration(RB.$("validation_packager_multiple_artifacts", "distribution." + distribution.getName() + ".asdf")); | ||
packager.disable(); | ||
return; | ||
} | ||
|
||
if (isBlank(packager.getToolCheck()) && isNotBlank(parentPackager.getToolCheck())) { | ||
packager.setToolCheck(parentPackager.getToolCheck()); | ||
} | ||
if (isBlank(packager.getToolCheck())) { | ||
packager.setToolCheck("{{distributionExecutable}} --version"); | ||
} | ||
|
||
if (isBlank(packager.getRepository().getName())) { | ||
packager.getRepository().setName("asdf-" + distribution.getName()); | ||
} | ||
packager.getRepository().setTapName("asdf-" + distribution.getName()); | ||
|
||
validateCommitAuthor(packager, parentPackager); | ||
Asdf.AsdfRepository repository = packager.getRepository(); | ||
repository.resolveEnabled(model.getProject()); | ||
validateTap(context, distribution, repository, parentPackager.getRepository(), "asdf.repository"); | ||
validateTemplate(context, distribution, packager, parentPackager, errors); | ||
mergeExtraProperties(packager, parentPackager); | ||
validateContinueOnError(packager, parentPackager); | ||
if (isBlank(packager.getDownloadUrl())) { | ||
packager.setDownloadUrl(parentPackager.getDownloadUrl()); | ||
} | ||
validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors); | ||
} | ||
} |
Oops, something went wrong.