mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
Enable plugins to create config stores for repository config
Therefore we have to - add an API to create stores for repository ids, not only for repositories, - make v1 properties available in scm-core - make sure that properties are extracted from repositories before the update step of a plugin runs (this is done by sorting the update steps in a way so that "core" update steps are executed before plugin update steps with the same version)
This commit is contained in:
@@ -35,7 +35,6 @@ package sonia.scm.store;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
@@ -66,18 +65,18 @@ public abstract class FileBasedStoreFactory {
|
||||
}
|
||||
|
||||
protected File getStoreLocation(StoreParameters storeParameters) {
|
||||
return getStoreLocation(storeParameters.getName(), null, storeParameters.getRepository());
|
||||
return getStoreLocation(storeParameters.getName(), null, storeParameters.getRepositoryId());
|
||||
}
|
||||
|
||||
protected File getStoreLocation(TypedStoreParameters storeParameters) {
|
||||
return getStoreLocation(storeParameters.getName(), storeParameters.getType(), storeParameters.getRepository());
|
||||
return getStoreLocation(storeParameters.getName(), storeParameters.getType(), storeParameters.getRepositoryId());
|
||||
}
|
||||
|
||||
protected File getStoreLocation(String name, Class type, Repository repository) {
|
||||
protected File getStoreLocation(String name, Class type, String repositoryId) {
|
||||
File storeDirectory;
|
||||
if (repository != null) {
|
||||
LOG.debug("create store with type: {}, name: {} and repository: {}", type, name, repository.getNamespaceAndName());
|
||||
storeDirectory = this.getStoreDirectory(store, repository);
|
||||
if (repositoryId != null) {
|
||||
LOG.debug("create store with type: {}, name: {} and repository id: {}", type, name, repositoryId);
|
||||
storeDirectory = this.getStoreDirectory(store, repositoryId);
|
||||
} else {
|
||||
LOG.debug("create store with type: {} and name: {} ", type, name);
|
||||
storeDirectory = this.getStoreDirectory(store);
|
||||
@@ -89,11 +88,11 @@ public abstract class FileBasedStoreFactory {
|
||||
/**
|
||||
* Get the store directory of a specific repository
|
||||
* @param store the type of the store
|
||||
* @param repository the repo
|
||||
* @param repositoryId the id of the repossitory
|
||||
* @return the store directory of a specific repository
|
||||
*/
|
||||
private File getStoreDirectory(Store store, Repository repository) {
|
||||
return new File(repositoryLocationResolver.forClass(Path.class).getLocation(repository.getId()).toFile(), store.getRepositoryStoreDirectory());
|
||||
private File getStoreDirectory(Store store, String repositoryId) {
|
||||
return new File(repositoryLocationResolver.forClass(Path.class).getLocation(repositoryId).toFile(), store.getRepositoryStoreDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,7 +59,9 @@ public class JAXBConfigurationEntryStoreFactory extends FileBasedStoreFactory
|
||||
|
||||
@Override
|
||||
public <T> ConfigurationEntryStore<T> getStore(TypedStoreParameters<T> storeParameters) {
|
||||
return new JAXBConfigurationEntryStore<>(getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION), storeParameters.getType(), storeParameters.getRepository()), keyGenerator, storeParameters.getType());
|
||||
return new JAXBConfigurationEntryStore<>(
|
||||
getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION), storeParameters.getType(), storeParameters.getRepositoryId()),
|
||||
keyGenerator,
|
||||
storeParameters.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,10 @@ public class JAXBConfigurationStoreFactory extends FileBasedStoreFactory impleme
|
||||
|
||||
@Override
|
||||
public <T> JAXBConfigurationStore<T> getStore(TypedStoreParameters<T> storeParameters) {
|
||||
return new JAXBConfigurationStore<>(storeParameters.getType(), getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION), storeParameters.getType(), storeParameters.getRepository()));
|
||||
return new JAXBConfigurationStore<>(
|
||||
storeParameters.getType(),
|
||||
getStoreLocation(storeParameters.getName().concat(StoreConstants.FILE_EXTENSION),
|
||||
storeParameters.getType(),
|
||||
storeParameters.getRepositoryId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package sonia.scm.update.xml;
|
||||
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
import sonia.scm.update.V1Properties;
|
||||
import sonia.scm.update.V1PropertyDAO;
|
||||
import sonia.scm.update.V1PropertyReader;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
|
||||
public class XmlV1PropertyDAO implements V1PropertyDAO {
|
||||
|
||||
private final ConfigurationEntryStoreFactory configurationEntryStoreFactory;
|
||||
|
||||
@Inject
|
||||
public XmlV1PropertyDAO(ConfigurationEntryStoreFactory configurationEntryStoreFactory) {
|
||||
this.configurationEntryStoreFactory = configurationEntryStoreFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V1PropertyReader.Instance getProperties(V1PropertyReader reader) {
|
||||
ConfigurationEntryStore<V1Properties> propertyStore = configurationEntryStoreFactory
|
||||
.withType(V1Properties.class)
|
||||
.withName(reader.getStoreName())
|
||||
.build();
|
||||
Map<String, V1Properties> all = propertyStore.getAll();
|
||||
return reader.createInstance(all);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user