Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for GAL-357, Support for feature/package stability #339

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion common-api/src/main/java/org/jboss/galleon/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -82,6 +82,12 @@ public interface Constants {
String PASSIVE = "passive";
String PASSIVE_PLUS = "passive+";

String STABILITY_LEVEL = "stability-level";
String STABILITY_EXPERIMENTAL = "experimental";
String STABILITY_PREVIEW = "preview";
String STABILITY_COMMUNITY = "community";
String STABILITY_DEFAULT = "default";

String VERSION_CONVERGENCE = "version-convergence";
String FIRST_PROCESSED = "first-processed";
String FAIL = "fail";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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
*
* http://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.jboss.galleon.api;

/**
*
* @author jdenise
*/
public class GalleonFeatureParamSpec {

private final String name;
private final String stability;

public GalleonFeatureParamSpec(String name, String stability) {
this.name = name;
this.stability = stability;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @return the stability
*/
public String getStability() {
return stability;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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
*
* http://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.jboss.galleon.api;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
*
* @author jdenise
*/
public class GalleonFeatureSpec {

private final String name;
private final String stability;
private final List<GalleonFeatureParamSpec> params = new ArrayList<>();

public GalleonFeatureSpec(String name, String stability) {
this.name = name;
this.stability = stability;
}

public void addParam(GalleonFeatureParamSpec param) {
params.add(param);
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @return the stability
*/
public String getStability() {
return stability;
}

/**
* @return the params
*/
public List<GalleonFeatureParamSpec> getParams() {
return Collections.unmodifiableList(params);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,6 +21,9 @@
import org.jboss.galleon.universe.FeaturePackLocation;

public interface GalleonPackageRuntime {

String getStability();

String getName();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,6 +18,7 @@

import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import org.jboss.galleon.ProvisioningException;
import org.jboss.galleon.api.config.GalleonProvisionedConfig;
import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec;
Expand Down Expand Up @@ -52,6 +53,8 @@ public interface GalleonProvisioningRuntime extends AutoCloseable {

void provision() throws ProvisioningException;

List<GalleonFeatureSpec> getAllFeatures() throws ProvisioningException;

@Override
void close();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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
*
* http://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.jboss.galleon.api;

import org.junit.Assert;
import org.junit.Test;

/**
*
* @author jdenise
*/
public class GalleonFeatureSpecTestCase {

@Test
public void test() {
GalleonFeatureSpec spec = new GalleonFeatureSpec("foo", "experimental");
Assert.assertEquals("foo", spec.getName());
Assert.assertEquals("experimental", spec.getStability());
spec.addParam(new GalleonFeatureParamSpec("p", null));
spec.addParam(new GalleonFeatureParamSpec("p2", null));
Assert.assertEquals(2, spec.getParams().size());
Assert.assertEquals("p", spec.getParams().get(0).getName());
Assert.assertNull(spec.getParams().get(0).getStability());
Assert.assertEquals("p2", spec.getParams().get(1).getName());
GalleonFeatureSpec spec2 = new GalleonFeatureSpec("foo", null);
Assert.assertEquals("foo", spec2.getName());
Assert.assertNull(spec2.getStability());

}
}
11 changes: 9 additions & 2 deletions core/src/main/java/org/jboss/galleon/ProvisioningOption.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -65,9 +65,16 @@ public class ProvisioningOption {
.setBooleanValueSet()
.build();

public static final ProvisioningOption STABILITY_LEVEL = ProvisioningOption.builder(Constants.STABILITY_LEVEL)
.addToValueSet(Constants.STABILITY_EXPERIMENTAL)
.addToValueSet(Constants.STABILITY_PREVIEW)
.addToValueSet(Constants.STABILITY_COMMUNITY)
.addToValueSet(Constants.STABILITY_DEFAULT)
.build();

private static final List<ProvisioningOption> stdOptions = Arrays
.asList(new ProvisioningOption[] { IGNORE_NOT_EXCLUDED_LAYERS, OPTIONAL_PACKAGES, VERSION_CONVERGENCE, PRINT_ONLY_CONFLICTS,
STORE_INPUT_PROVISIONING_CONFIG, EXPORT_SYSTEM_PATHS});
STORE_INPUT_PROVISIONING_CONFIG, EXPORT_SYSTEM_PATHS, STABILITY_LEVEL});

public static List<ProvisioningOption> getStandardList() {
return stdOptions;
Expand Down
84 changes: 84 additions & 0 deletions core/src/main/java/org/jboss/galleon/Stability.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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
*
* http://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.jboss.galleon;

import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;

/**
* Enumeration of stability levels.
* Copied from wildfly-core.
* @author Paul Ferraro
*/
public enum Stability {

DEFAULT("default"),
COMMUNITY("community"),
PREVIEW("preview"),
EXPERIMENTAL("experimental"),
;
private final String value;

public static Stability fromString(String value) {
return Enum.valueOf(Stability.class, value.toUpperCase(Locale.ENGLISH));
}

Stability(String value) {
this.value = value;
}

@Override
public String toString() {
return this.value;
}

/**
* Indicates whether this stability enables the specified stability level.
* @param stability a stability level
* @return true, if this stability level enables the specified stability level, false otherwise.
*/
public boolean enables(Stability stability) {
// Currently assumes ascending nested sets
return stability.ordinal() <= this.ordinal();
}

/**
* Returns a complete map of a feature per stability level.
* @param <F> the feature type
* @param features a function returning the feature of a given stability level
* @return a full mapping of feature per stability level
*/
public static <F> Map<Stability, F> map(Function<Stability, F> features) {
Map<Stability, F> map = new EnumMap<>(Stability.class);
F lastStability = null;
// Currently assumes ascending nested sets
for (Stability stability : EnumSet.allOf(Stability.class)) {
F feature = features.apply(stability);
if (feature != null) {
lastStability = feature;
}
if (lastStability != null) {
map.put(stability, lastStability);
}
}
return Collections.unmodifiableMap(map);
}
}
13 changes: 12 additions & 1 deletion core/src/main/java/org/jboss/galleon/config/FeatureConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -165,6 +165,17 @@ public String putParam(String name, String value) {
return prevValue;
}

// Fully disable a parameter, it is removed from the Feature fully.
public void removeParam(String name) {
params = CollectionUtils.remove(params, name);
if(!unsetParams.isEmpty()) {
unsetParams = CollectionUtils.remove(unsetParams, name);
}
if(!resetParams.isEmpty()) {
resetParams = CollectionUtils.remove(resetParams, name);
}
}

public FeatureConfig unsetParam(String name) {
unsetParams = CollectionUtils.add(unsetParams, name);
params = CollectionUtils.remove(params, name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -418,4 +418,9 @@ private static void ensureDir(Path dir) throws IOException {
throw new IllegalStateException(dir + " is not a directory.");
}
}

public FeaturePackBuilder setMinStability(String stability) {
fpBuilder.setMinStability(stability);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -59,6 +59,11 @@ public FeaturePackBuilder getFeaturePack() {
return fp;
}

public PackageBuilder setStability(String stability) {
pkg.setStability(stability);
return this;
}

public PackageBuilder setDefault() {
isDefault = true;
return this;
Expand Down
Loading
Loading