diff --git a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/RepositoryPath.java b/scm-dao-xml/src/main/java/sonia/scm/repository/xml/RepositoryPath.java deleted file mode 100644 index db57b228f9..0000000000 --- a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/RepositoryPath.java +++ /dev/null @@ -1,101 +0,0 @@ -package sonia.scm.repository.xml; - -import org.apache.commons.lang.StringUtils; -import sonia.scm.ModelObject; -import sonia.scm.repository.Repository; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; - -@XmlRootElement(name = "repository-link") -@XmlAccessorType(XmlAccessType.FIELD) -public class RepositoryPath implements ModelObject { - - private String path; - private String id; - private Long lastModified; - private Long creationDate; - - @XmlTransient - private Repository repository; - - @XmlTransient - private boolean toBeSynchronized; - - /** - * Needed from JAXB - */ - public RepositoryPath() { - } - - public RepositoryPath(String path, String id, Repository repository) { - this.path = path; - this.id = id; - this.repository = repository; - } - - public Repository getRepository() { - return repository; - } - - public void setRepository(Repository repository) { - this.repository = repository; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - @Override - public String getId() { - return id; - } - - @Override - public void setLastModified(Long lastModified) { - this.lastModified = lastModified; - } - - @Override - public Long getCreationDate() { - return creationDate; - } - - @Override - public void setCreationDate(Long creationDate) { - this.creationDate = creationDate; - } - - public void setId(String id) { - this.id = id; - } - - @Override - public Long getLastModified() { - return lastModified; - } - - @Override - public String getType() { - return getRepository()!= null? getRepository().getType():""; - } - - @Override - public boolean isValid() { - return StringUtils.isNotEmpty(path); - } - - public boolean toBeSynchronized() { - return toBeSynchronized; - } - - public void setToBeSynchronized(boolean toBeSynchronized) { - this.toBeSynchronized = toBeSynchronized; - } -} diff --git a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryDatabase.java b/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryDatabase.java deleted file mode 100644 index c7b2af656f..0000000000 --- a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryDatabase.java +++ /dev/null @@ -1,188 +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 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 { - - private Long creationTime; - - private Long lastModified; - - @XmlJavaTypeAdapter(XmlRepositoryMapAdapter.class) - @XmlElement(name = "repositories") - private Map repositoryPathMap = new LinkedHashMap<>(); - - - public XmlRepositoryDatabase() { - 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()); - } - - @Override - public void add(RepositoryPath repositoryPath) - { - repositoryPathMap.put(createKey(repositoryPath.getRepository()), repositoryPath); - } - - public boolean contains(NamespaceAndName namespaceAndName) - { - return repositoryPathMap.containsKey(createKey(namespaceAndName)); - } - - @Override - public boolean contains(String id) - { - return get(id) != null; - } - - @Override - public RepositoryPath remove(String id) - { - return repositoryPathMap.remove(createKey(get(id).getRepository())); - } - - public Collection getRepositories() { - List repositories = new ArrayList<>(); - for (RepositoryPath repositoryPath : repositoryPathMap.values()) { - Repository repository = repositoryPath.getRepository(); - repositories.add(repository); - } - return repositories; - } - - @Override - public Collection values() - { - return repositoryPathMap.values(); - } - - public Repository get(NamespaceAndName namespaceAndName) { - RepositoryPath repositoryPath = repositoryPathMap.get(createKey(namespaceAndName)); - if (repositoryPath != null) { - return repositoryPath.getRepository(); - } - return null; - } - - - @Override - public RepositoryPath get(String id) { - return values().stream() - .filter(repoPath -> repoPath.getId().equals(id)) - .findFirst() - .orElse(null); - } - - /** - * Method description - * - * - * @return - */ - @Override - public long getCreationTime() - { - return creationTime; - } - - /** - * Method description - * - * - * @return - */ - @Override - public long getLastModified() - { - return lastModified; - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param creationTime - */ - @Override - public void setCreationTime(long creationTime) - { - this.creationTime = creationTime; - } - - /** - * Method description - * - * - * @param lastModified - */ - @Override - public void setLastModified(long lastModified) - { - this.lastModified = lastModified; - } -} diff --git a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryList.java b/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryList.java deleted file mode 100644 index b31f870a8e..0000000000 --- a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryList.java +++ /dev/null @@ -1,123 +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.Repository; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * - * @author Sebastian Sdorra - */ -@XmlRootElement(name = "repositories") -@XmlAccessorType(XmlAccessType.FIELD) -public class XmlRepositoryList implements Iterable -{ - - /** - * Constructs ... - * - */ - public XmlRepositoryList() {} - - /** - * Constructs ... - * - * - * - * @param repositoryMap - */ - public XmlRepositoryList(Map repositoryMap) - { - this.repositories = new LinkedList<>(repositoryMap.values()); - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - @Override - public Iterator iterator() - { - return repositories.iterator(); - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public LinkedList getRepositoryPaths() - { - return repositories; - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param repositories - */ - public void setRepositories(LinkedList repositories) - { - this.repositories = repositories; - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - @XmlElement(name = "repository-path") - private LinkedList repositories; -} diff --git a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryMapAdapter.java b/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryMapAdapter.java deleted file mode 100644 index 633c9a27b3..0000000000 --- a/scm-dao-xml/src/main/java/sonia/scm/repository/xml/XmlRepositoryMapAdapter.java +++ /dev/null @@ -1,112 +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; - -import sonia.scm.SCMContext; -import sonia.scm.SCMContextProvider; -import sonia.scm.repository.InternalRepositoryException; -import sonia.scm.repository.Repository; -import sonia.scm.store.StoreConstants; -import sonia.scm.store.StoreException; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.adapters.XmlAdapter; -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.LinkedHashMap; -import java.util.Map; - - -/** - * @author Sebastian Sdorra - */ -public class XmlRepositoryMapAdapter extends XmlAdapter> { - - @Override - public XmlRepositoryList marshal(Map repositoryMap) { - XmlRepositoryList repositoryPaths = new XmlRepositoryList(repositoryMap); - try { - JAXBContext context = JAXBContext.newInstance(Repository.class); - Marshaller marshaller = context.createMarshaller(); - - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - - // marshall the repo_path/metadata.xml files - for (RepositoryPath repositoryPath : repositoryPaths.getRepositoryPaths()) { - if (repositoryPath.toBeSynchronized()) { - - File baseDirectory = SCMContext.getContext().getBaseDirectory(); - Path dir = baseDirectory.toPath().resolve(repositoryPath.getPath()); - - if (!Files.isDirectory(dir)) { - throw new InternalRepositoryException(repositoryPath.getRepository(), "repository path not found"); - } - marshaller.marshal(repositoryPath.getRepository(), getRepositoryMetadataFile(dir.toFile())); - repositoryPath.setToBeSynchronized(false); - } - } - } catch (JAXBException ex) { - throw new StoreException("failed to marshal repository database", ex); - } - - return repositoryPaths; - - } - - private File getRepositoryMetadataFile(File dir) { - return new File(dir, StoreConstants.REPOSITORY_METADATA.concat(StoreConstants.FILE_EXTENSION)); - } - - @Override - public Map unmarshal(XmlRepositoryList repositoryPaths) { - Map repositoryPathMap = new LinkedHashMap<>(); - try { - JAXBContext context = JAXBContext.newInstance(Repository.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - for (RepositoryPath repositoryPath : repositoryPaths) { - SCMContextProvider contextProvider = SCMContext.getContext(); - File baseDirectory = contextProvider.getBaseDirectory(); - Repository repository = (Repository) unmarshaller.unmarshal(getRepositoryMetadataFile(baseDirectory.toPath().resolve(repositoryPath.getPath()).toFile())); - - repositoryPath.setRepository(repository); - repositoryPathMap.put(XmlRepositoryDatabase.createKey(repository), repositoryPath); - } - } catch (JAXBException ex) { - throw new StoreException("failed to unmarshal object", ex); - } - return repositoryPathMap; - } -}