mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 17:56:17 +01:00
Backed out changeset 428510f2003d
This commit is contained in:
@@ -41,7 +41,6 @@ import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.PathBasedRepositoryDAO;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryPathNotFoundException;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.xml.AbstractXmlDAO;
|
||||
|
||||
@@ -62,7 +61,7 @@ public class XmlRepositoryDAO
|
||||
* Field description
|
||||
*/
|
||||
public static final String STORE_NAME = "repositories";
|
||||
private final InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
||||
private InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
@@ -73,10 +72,7 @@ public class XmlRepositoryDAO
|
||||
*/
|
||||
@Inject
|
||||
public XmlRepositoryDAO(ConfigurationStoreFactory storeFactory, InitialRepositoryLocationResolver initialRepositoryLocationResolver) {
|
||||
super(new SimpleStore(storeFactory.getStore(XmlRepositoryDatabasePersistence.class, STORE_NAME).get(), initialRepositoryLocationResolver));
|
||||
if (initialRepositoryLocationResolver == null) {
|
||||
throw new NullPointerException("resolver must not be null");
|
||||
}
|
||||
super(storeFactory.getStore(XmlRepositoryDatabase.class, STORE_NAME));
|
||||
this.initialRepositoryLocationResolver = initialRepositoryLocationResolver;
|
||||
}
|
||||
|
||||
@@ -105,12 +101,23 @@ public class XmlRepositoryDAO
|
||||
|
||||
@Override
|
||||
public void add(Repository repository) {
|
||||
String path = initialRepositoryLocationResolver.getDirectory(repository).getAbsolutePath();
|
||||
RepositoryPath repositoryPath = new RepositoryPath(path, repository.getId(), repository.clone());
|
||||
synchronized (store) {
|
||||
db.add(repository);
|
||||
db.add(repositoryPath);
|
||||
storeDB();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository get(String id) {
|
||||
RepositoryPath repositoryPath = db.get(id);
|
||||
if (repositoryPath != null) {
|
||||
return repositoryPath.getRepository();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Repository> getAll() {
|
||||
return db.getRepositories();
|
||||
@@ -134,7 +141,7 @@ public class XmlRepositoryDAO
|
||||
*/
|
||||
@Override
|
||||
protected XmlRepositoryDatabase createNewDatabase() {
|
||||
return new XmlRepositoryDatabase(new XmlRepositoryDatabasePersistence(), initialRepositoryLocationResolver);
|
||||
return new XmlRepositoryDatabase();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,26 +156,4 @@ public class XmlRepositoryDAO
|
||||
return Paths.get(repositoryPath.get().getPath());
|
||||
}
|
||||
}
|
||||
|
||||
private static class SimpleStore implements ConfigurationStore<XmlRepositoryDatabase> {
|
||||
private final XmlRepositoryDatabase xmlRepositoryDatabase;
|
||||
|
||||
public SimpleStore(XmlRepositoryDatabasePersistence xmlRepositoryDatabasePersistence, InitialRepositoryLocationResolver initialRepositoryLocationResolver) {
|
||||
if (xmlRepositoryDatabasePersistence == null) {
|
||||
this.xmlRepositoryDatabase = new XmlRepositoryDatabase(new XmlRepositoryDatabasePersistence(), initialRepositoryLocationResolver);
|
||||
} else {
|
||||
this.xmlRepositoryDatabase = new XmlRepositoryDatabase(xmlRepositoryDatabasePersistence, initialRepositoryLocationResolver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlRepositoryDatabase get() {
|
||||
return xmlRepositoryDatabase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(XmlRepositoryDatabase obejct) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,36 +35,40 @@ package sonia.scm.repository.xml;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.InitialRepositoryLocationResolver;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.xml.XmlDatabase;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@XmlRootElement(name = "repository-db")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class XmlRepositoryDatabase implements XmlDatabase<Repository> {
|
||||
public class XmlRepositoryDatabase implements XmlDatabase<RepositoryPath> {
|
||||
|
||||
private final InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
||||
private Long creationTime;
|
||||
|
||||
private final XmlRepositoryDatabasePersistence storage;
|
||||
private Long lastModified;
|
||||
|
||||
public XmlRepositoryDatabase(XmlRepositoryDatabasePersistence storage, InitialRepositoryLocationResolver initialRepositoryLocationResolver) {
|
||||
if (storage == null) {
|
||||
throw new NullPointerException("storage must not be null");
|
||||
}
|
||||
if (initialRepositoryLocationResolver == null) {
|
||||
throw new NullPointerException("resolver must not be null");
|
||||
}
|
||||
this.initialRepositoryLocationResolver = initialRepositoryLocationResolver;
|
||||
this.storage = storage;
|
||||
@XmlJavaTypeAdapter(XmlRepositoryMapAdapter.class)
|
||||
@XmlElement(name = "repositories")
|
||||
private Map<String, RepositoryPath> repositoryPathMap = new LinkedHashMap<>();
|
||||
|
||||
|
||||
public XmlRepositoryDatabase() {
|
||||
long c = System.currentTimeMillis();
|
||||
creationTime = c;
|
||||
lastModified = c;
|
||||
}
|
||||
|
||||
static String createKey(NamespaceAndName namespaceAndName)
|
||||
@@ -78,63 +82,71 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Repository repository)
|
||||
public void add(RepositoryPath repositoryPath)
|
||||
{
|
||||
String path = initialRepositoryLocationResolver.getDirectory(repository).getAbsolutePath();
|
||||
RepositoryPath repositoryPath = new RepositoryPath(path, repository.getId(), repository.clone());
|
||||
storage.add(repositoryPath);
|
||||
repositoryPathMap.put(createKey(repositoryPath.getRepository()), repositoryPath);
|
||||
}
|
||||
|
||||
public boolean contains(NamespaceAndName namespaceAndName)
|
||||
{
|
||||
return storage.containsKey(createKey(namespaceAndName));
|
||||
return repositoryPathMap.containsKey(createKey(namespaceAndName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String id)
|
||||
{
|
||||
return storage.get(id) != null;
|
||||
return get(id) != null;
|
||||
}
|
||||
|
||||
public boolean contains(Repository repository)
|
||||
{
|
||||
return storage.containsKey(createKey(repository));
|
||||
return repositoryPathMap.containsKey(createKey(repository));
|
||||
}
|
||||
|
||||
public void remove(Repository repository)
|
||||
{
|
||||
storage.remove(createKey(repository));
|
||||
repositoryPathMap.remove(createKey(repository));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository remove(String id)
|
||||
public RepositoryPath remove(String id)
|
||||
{
|
||||
return storage.remove(createKey(get(id)));
|
||||
return repositoryPathMap.remove(createKey(get(id).getRepository()));
|
||||
}
|
||||
|
||||
public Collection<Repository> getRepositories() {
|
||||
return storage.getRepositories();
|
||||
List<Repository> repositories = new ArrayList<>();
|
||||
for (RepositoryPath repositoryPath : repositoryPathMap.values()) {
|
||||
Repository repository = repositoryPath.getRepository();
|
||||
repositories.add(repository);
|
||||
}
|
||||
return repositories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Repository> values()
|
||||
public Collection<RepositoryPath> values()
|
||||
{
|
||||
return storage.values();
|
||||
return repositoryPathMap.values();
|
||||
}
|
||||
|
||||
public Collection<RepositoryPath> getPaths() {
|
||||
return storage.getPaths();
|
||||
return repositoryPathMap.values();
|
||||
}
|
||||
|
||||
|
||||
public Repository get(NamespaceAndName namespaceAndName) {
|
||||
return storage.get(namespaceAndName);
|
||||
RepositoryPath repositoryPath = repositoryPathMap.get(createKey(namespaceAndName));
|
||||
if (repositoryPath != null) {
|
||||
return repositoryPath.getRepository();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Repository get(String id) {
|
||||
public RepositoryPath get(String id) {
|
||||
return values().stream()
|
||||
.filter(repo -> repo.getId().equals(id))
|
||||
.filter(repoPath -> repoPath.getId().equals(id))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
@@ -148,7 +160,7 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository> {
|
||||
@Override
|
||||
public long getCreationTime()
|
||||
{
|
||||
return storage.getCreationTime();
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +172,7 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository> {
|
||||
@Override
|
||||
public long getLastModified()
|
||||
{
|
||||
return storage.getLastModified();
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
@@ -174,7 +186,7 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository> {
|
||||
@Override
|
||||
public void setCreationTime(long creationTime)
|
||||
{
|
||||
storage.setCreationTime(creationTime);
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,6 +198,6 @@ public class XmlRepositoryDatabase implements XmlDatabase<Repository> {
|
||||
@Override
|
||||
public void setLastModified(long lastModified)
|
||||
{
|
||||
storage.setLastModified(lastModified);
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.xml;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@XmlRootElement(name = "repository-db")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class XmlRepositoryDatabasePersistence {
|
||||
|
||||
private Long creationTime;
|
||||
|
||||
private Long lastModified;
|
||||
|
||||
@XmlJavaTypeAdapter(XmlRepositoryMapAdapter.class)
|
||||
@XmlElement(name = "repositories")
|
||||
private Map<String, RepositoryPath> repositoryPathMap = new LinkedHashMap<>();
|
||||
|
||||
public XmlRepositoryDatabasePersistence() {
|
||||
long c = System.currentTimeMillis();
|
||||
creationTime = c;
|
||||
lastModified = c;
|
||||
}
|
||||
|
||||
static String createKey(NamespaceAndName namespaceAndName)
|
||||
{
|
||||
return namespaceAndName.getNamespace() + ":" + namespaceAndName.getName();
|
||||
}
|
||||
|
||||
static String createKey(Repository repository)
|
||||
{
|
||||
return createKey(repository.getNamespaceAndName());
|
||||
}
|
||||
|
||||
public void add(RepositoryPath repositoryPath)
|
||||
{
|
||||
repositoryPathMap.put(createKey(repositoryPath.getRepository()), repositoryPath);
|
||||
}
|
||||
|
||||
public boolean contains(NamespaceAndName namespaceAndName)
|
||||
{
|
||||
return repositoryPathMap.containsKey(createKey(namespaceAndName));
|
||||
}
|
||||
|
||||
public boolean contains(String id)
|
||||
{
|
||||
return get(id) != null;
|
||||
}
|
||||
|
||||
public boolean contains(Repository repository)
|
||||
{
|
||||
return repositoryPathMap.containsKey(createKey(repository));
|
||||
}
|
||||
|
||||
public void remove(Repository repository)
|
||||
{
|
||||
repositoryPathMap.remove(createKey(repository));
|
||||
}
|
||||
|
||||
public Repository remove(String key)
|
||||
{
|
||||
return repositoryPathMap.remove(key).getRepository();
|
||||
}
|
||||
|
||||
public Collection<Repository> getRepositories() {
|
||||
List<Repository> repositories = new ArrayList<>();
|
||||
for (RepositoryPath repositoryPath : repositoryPathMap.values()) {
|
||||
Repository repository = repositoryPath.getRepository();
|
||||
repositories.add(repository);
|
||||
}
|
||||
return repositories;
|
||||
}
|
||||
|
||||
public Collection<Repository> values()
|
||||
{
|
||||
return repositoryPathMap.values().stream().map(RepositoryPath::getRepository).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<RepositoryPath> getPaths() {
|
||||
return repositoryPathMap.values();
|
||||
}
|
||||
|
||||
|
||||
public Repository get(NamespaceAndName namespaceAndName) {
|
||||
RepositoryPath repositoryPath = repositoryPathMap.get(createKey(namespaceAndName));
|
||||
if (repositoryPath != null) {
|
||||
return repositoryPath.getRepository();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Repository get(String id) {
|
||||
return values().stream()
|
||||
.filter(repo -> repo.getId().equals(id))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public long getCreationTime()
|
||||
{
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public long getLastModified()
|
||||
{
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
public void setCreationTime(long creationTime)
|
||||
{
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
public void setLastModified(long lastModified)
|
||||
{
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
public boolean containsKey(String key) {
|
||||
return repositoryPathMap.containsKey(key);
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class XmlRepositoryMapAdapter extends XmlAdapter<XmlRepositoryList, Map<S
|
||||
repositoryPathMap.put(XmlRepositoryDatabase.createKey(repository), repositoryPath);
|
||||
}
|
||||
} catch (JAXBException ex) {
|
||||
throw new StoreException("failed to unmarshal object", ex);
|
||||
throw new StoreException("failed to unmarshall object", ex);
|
||||
}
|
||||
return repositoryPathMap;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ import java.util.Collection;
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractXmlDAO<I extends ModelObject,
|
||||
T extends XmlDatabase<I>> implements GenericDAO<I>
|
||||
T extends XmlDatabase> implements GenericDAO<I>
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
|
||||
Reference in New Issue
Block a user