Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;
import java.util.Optional;

import org.aposin.gem.core.api.IRefreshable;
import org.aposin.gem.core.api.model.IEnvironment;
import org.aposin.gem.core.api.workflow.IFeatureBranch;
Expand All @@ -26,6 +27,14 @@
*/
public interface IFeatureBranchProvider extends IGemService, IRefreshable {

/**
* ID prefix to identify feature-branch providers provided by GEM Core.
* </br>
* IMPORTANT NOTE: should only be used on {@link #getId()} from plug-ins provided
* by the GEM Core (including extra plug-ins).
*/
public static final String CORE_ID_PREFIX = "org.aposin.gem.fbp.";

/**
* Get the feature-branches for the environment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ public default String getDisplayName() {
*/
public Comparator<IEnvironment> getEnvironmentComparator();

public Comparator<IFeatureBranchProvider> getFeatureBranchProviderComparator();

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public default IGemSorter getGemSorter() {
final Collection<IGemSorter> sorters = getGemServices(IGemSorter.class);
switch (sorters.size()) {
case 0:
return new DefaultGemSorter();
final DefaultGemSorter sorter = new DefaultGemSorter();
sorter.setConfig(getConfiguration());
return sorter;
case 1:
return sorters.iterator().next();
default:
Expand All @@ -61,12 +63,14 @@ public default IGemSorter getGemSorter() {

/**
* Retrieve the {@link IFeatureBranchProvider} core service.
* </br>
* Implementations should sort the result with
* {@link IGemSorter#getFeatureBranchProviderComparator()}
* after calling {@link #getGemServices(Class)}.
*
* @return {@link #getService(Class)} for {@link IFeatureBranchProvider}.
*/
public default Collection<IFeatureBranchProvider> getFeatureBranchProviders() {
return getGemServices(IFeatureBranchProvider.class);
}
public Collection<IFeatureBranchProvider> getFeatureBranchProviders();

/**
* Retrieve the {@link IEnvironmentLauncherProvider} core service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.aposin.gem.core.Activator;
import org.aposin.gem.core.api.IRefreshable;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class ServiceContainer implements IServiceContainer, IConfigurable {
private final Map<Class<? extends IGemService>, Map<? extends IGemService, GemConfigurationException>> misconfiguredServices =
new HashMap<>();

private List<IFeatureBranchProvider> featureBranchProviders;

/* package */ ServiceContainer(final ConfigurationImpl configuration) {
this.configuration = configuration;
Expand Down Expand Up @@ -106,6 +108,16 @@ public IFeatureBranchProvider getDefaultFeatureBranchProvider() {
return provider;
}

@Override
public Collection<IFeatureBranchProvider> getFeatureBranchProviders() {
if (featureBranchProviders == null) {
featureBranchProviders = getGemServices(IFeatureBranchProvider.class).stream() //
.sorted(getGemSorter().getFeatureBranchProviderComparator()) //
.collect(Collectors.toUnmodifiableList());
}
return featureBranchProviders;
}

@Override
public <T extends IGemService> T getService(Class<T> type, String id) {
return getGemServicesById(type).get(id);
Expand Down Expand Up @@ -206,5 +218,6 @@ public void refresh() {
loadedServices.clear();
misconfiguredServices.clear();
misconfiguredServiceCreators.clear();
featureBranchProviders = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public abstract class AbstractGitBranchProvider implements IFeatureBranchProvide
private IConfiguration config;
private Map<IRepository, Set<String>> blackListedBranches;

@Override
public String getId() {
return CORE_ID_PREFIX + getName();
}

@Override
public final void setConfig(final IConfiguration config) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;

import org.aposin.gem.core.api.model.IEnvironment;
import org.aposin.gem.core.api.service.IFeatureBranchProvider;
import org.aposin.gem.core.api.workflow.IFeatureBranch;
Expand All @@ -26,15 +27,15 @@
@Component(service = IFeatureBranchProvider.class)
public class GemGitBranchProvider extends AbstractGitBranchProvider {

private static final String NAME = "gem_branches";

/**
* ID for this provider, which is also the default Core provider.
*/
public static final String ID = GemGitBranchProvider.class.getName();
public static final String ID = CORE_ID_PREFIX + NAME;

/**
* {@inheritDoc}
*
* @return {@link #ID}
*/
@Override
public String getId() {
Expand All @@ -43,7 +44,7 @@ public String getId() {

@Override
public String getName() {
return "gem_branches";
return NAME;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,48 @@
import java.util.Comparator;

import org.aposin.gem.core.api.config.GemConfigurationException;
import org.aposin.gem.core.api.config.IConfigurable;
import org.aposin.gem.core.api.config.IConfiguration;
import org.aposin.gem.core.api.model.IEnvironment;
import org.aposin.gem.core.api.model.IProject;
import org.aposin.gem.core.api.service.IFeatureBranchProvider;
import org.aposin.gem.core.api.service.IGemSorter;

/**
* Default {@link IGemSorter}.
* </br>
* This sorter can be extended by plug-ins and be registered as a service (only one is allowed).
* </br>
* On the constructor, sub-classes should register the core serice comparators.
* If other services that are plug-in specific are provided, it can either be registered by the
* plug-in itself {@link #registerServiceComparator(Class, Comparator)} or by the sorter if it is
* application-specific.
*/
public class DefaultGemSorter implements IGemSorter {
public class DefaultGemSorter implements IGemSorter, IConfigurable {

private IConfiguration config;

/**
* {@inheritDoc}
*/
@Override
public void setConfig(final IConfiguration config) throws GemConfigurationException {
public final void setConfig(final IConfiguration config) throws GemConfigurationException {
this.config = config;
loadConfig();
}

/**
* Hook-method for sub-classes, to load the configuration on {@link #setConfig(IConfiguration));
*/
protected void loadConfig() {
// NO-OP
}

@Override
public final IConfiguration getConfiguration() {
return config;
}

/**
* {@inheritDoc}
*/
Expand All @@ -53,4 +75,28 @@ public Comparator<IEnvironment> getEnvironmentComparator() {
public Comparator<IProject> getProjectComparator() {
return Comparator.naturalOrder();
}

/**
* {@inheritDoc}
*/
@Override
public Comparator<IFeatureBranchProvider> getFeatureBranchProviderComparator() {
return new Comparator<IFeatureBranchProvider>() {

@Override
public int compare(IFeatureBranchProvider o1, IFeatureBranchProvider o2) {
final IFeatureBranchProvider defaultFBP = config.getServiceContainer()
.getDefaultFeatureBranchProvider();
if (o1 == defaultFBP) {
return -1;
} else if (o2 == defaultFBP) {
return 1;
} else {
return o1.compareTo(o2);
}
}

};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public JiraProviderConfigBean getConfigBean() {

@Override
public String getId() {
return this.getClass().getName() + "." + getName();
return CORE_ID_PREFIX + "jira." + getName();
}

@Override
Expand Down