From 909fe3257432ed50b996e43bec72766c83e26dce Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 12 Jan 2012 14:21:04 +0100 Subject: [PATCH 01/18] added api for repository imports --- .../repository/AbstractRepositoryHandler.java | 16 ++ .../sonia/scm/repository/ImportHandler.java | 58 ++++++++ .../scm/repository/RepositoryHandler.java | 14 ++ .../scm/repository/RepositoryManager.java | 17 +++ .../sonia/scm/repository/RepositoryUtil.java | 137 ++++++++++++++++++ .../repository/xml/XmlRepositoryManager.java | 42 +++++- 6 files changed, 281 insertions(+), 3 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/repository/ImportHandler.java diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHandler.java b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHandler.java index fa835e2803..2a459b66d6 100644 --- a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHandler.java +++ b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHandler.java @@ -39,6 +39,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sonia.scm.ConfigChangedListener; +import sonia.scm.NotSupportedFeatuerException; import sonia.scm.SCMContextProvider; import sonia.scm.store.Store; import sonia.scm.store.StoreFactory; @@ -243,6 +244,21 @@ public abstract class AbstractRepositoryHandler searchRepositoryDirectories(File directory, + String... names) + { + List repositories = new ArrayList(); + + searchRepositoryDirectories(repositories, directory, Arrays.asList(names)); + + return repositories; + } + //~--- get methods ---------------------------------------------------------- /** @@ -166,4 +192,115 @@ public class RepositoryUtil return name; } + + /** + * Method description + * + * + * @param handler + * @param directoryNames + * + * @return + * + * @throws IOException + */ + public static List getRepositoryNames( + AbstractRepositoryHandler handler, String... directoryNames) + throws IOException + { + return getRepositoryNames(handler.getConfig(), directoryNames); + } + + /** + * Method description + * + * + * @param config + * @param directoryNames + * + * @return + * + * @throws IOException + */ + public static List getRepositoryNames(SimpleRepositoryConfig config, + String... directoryNames) + throws IOException + { + return getRepositoryNames(config.getRepositoryDirectory(), directoryNames); + } + + /** + * Method description + * + * + * @param baseDirectory + * @param directoryNames + * + * @return + * + * @throws IOException + */ + public static List getRepositoryNames(File baseDirectory, + String... directoryNames) + throws IOException + { + List repositories = new ArrayList(); + List repositoryFiles = searchRepositoryDirectories(baseDirectory, + directoryNames); + + for (File file : repositoryFiles) + { + String name = getRepositoryName(baseDirectory, file); + + if (name != null) + { + repositories.add(name); + } + } + + return repositories; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param repositories + * @param directory + * @param names + */ + private static void searchRepositoryDirectories(List repositories, + File directory, List names) + { + boolean found = false; + + for (String name : names) + { + if (new File(directory, name).exists()) + { + found = true; + + break; + } + } + + if (found) + { + repositories.add(directory); + } + else + { + File[] directories = directory.listFiles(DirectoryFileFilter.instance); + + if (directories != null) + { + for (File d : directories) + { + searchRepositoryDirectories(repositories, d, names); + } + } + } + } } diff --git a/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java b/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java index 1134ee7e48..79a42a53a4 100644 --- a/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java +++ b/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java @@ -163,12 +163,12 @@ public class XmlRepositoryManager extends AbstractRepositoryManager * * * @param repository + * @param createRepository * * @throws IOException * @throws RepositoryException */ - @Override - public void create(Repository repository) + public void create(Repository repository, boolean createRepository) throws RepositoryException, IOException { if (logger.isInfoEnabled()) @@ -187,7 +187,11 @@ public class XmlRepositoryManager extends AbstractRepositoryManager repository.setId(UUID.randomUUID().toString()); repository.setCreationDate(System.currentTimeMillis()); - getHandler(repository).create(repository); + + if (createRepository) + { + getHandler(repository).create(repository); + } synchronized (XmlRepositoryDatabase.class) { @@ -198,6 +202,22 @@ public class XmlRepositoryManager extends AbstractRepositoryManager fireEvent(repository, HandlerEvent.CREATE); } + /** + * Method description + * + * + * @param repository + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void create(Repository repository) + throws RepositoryException, IOException + { + create(repository, true); + } + /** * Method description * @@ -285,6 +305,22 @@ public class XmlRepositoryManager extends AbstractRepositoryManager fireHookEvent(repository, event); } + /** + * Method description + * + * + * @param repository + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void importRepository(Repository repository) + throws RepositoryException, IOException + { + create(repository, false); + } + /** * Method description * From cf96e046b41ea8883d9d0889e8194c6fdbfbd2e5 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 12 Jan 2012 14:27:58 +0100 Subject: [PATCH 02/18] added basic git import --- .../api/rest/resources/GitImportResource.java | 97 +++++++++++ .../scm/repository/GitImportHandler.java | 152 ++++++++++++++++++ .../scm/repository/GitRepositoryHandler.java | 13 ++ 3 files changed, 262 insertions(+) create mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java create mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java new file mode 100644 index 0000000000..55092eb804 --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java @@ -0,0 +1,97 @@ +/** + * 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.api.rest.resources; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.inject.Inject; + +import sonia.scm.repository.GitRepositoryHandler; +import sonia.scm.repository.RepositoryException; +import sonia.scm.repository.RepositoryManager; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * + * @author Sebastian Sdorra + */ +@Path("import/repositories/git") +public class GitImportResource +{ + + /** + * Constructs ... + * + * + * @param repositoryManager + * @param handler + */ + @Inject + public GitImportResource(RepositoryManager repositoryManager, + GitRepositoryHandler handler) + { + this.repositoryManager = repositoryManager; + this.handler = handler; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @throws IOException + * @throws RepositoryException + */ + @GET + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public void importRepositories() throws IOException, RepositoryException + { + handler.getImportHandler().importRepositories(repositoryManager); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private GitRepositoryHandler handler; + + /** Field description */ + private RepositoryManager repositoryManager; +} diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java new file mode 100644 index 0000000000..f5a52447eb --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java @@ -0,0 +1,152 @@ +/** + * 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; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + +import java.util.List; + +/** + * + * @author Sebastian Sdorra + */ +public class GitImportHandler implements ImportHandler +{ + + /** Field description */ + public static final String GIT_DIR = ".git"; + + /** Field description */ + public static final String GIT_DIR_REFS = "refs"; + + /** + * the logger for GitImportHandler + */ + private static final Logger logger = + LoggerFactory.getLogger(GitImportHandler.class); + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + * + * @param handler + */ + public GitImportHandler(GitRepositoryHandler handler) + { + this.handler = handler; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param manager + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void importRepositories(RepositoryManager manager) + throws IOException, RepositoryException + { + if (logger.isTraceEnabled()) + { + logger.trace("search for git repositories for import"); + } + + List repositoryNames = RepositoryUtil.getRepositoryNames(handler, + GIT_DIR, GIT_DIR_REFS); + + for (String repositoryName : repositoryNames) + { + if (logger.isTraceEnabled()) + { + logger.trace("check git repository {} for import", repositoryName); + } + + Repository repository = manager.get(GitRepositoryHandler.TYPE_NAME, + repositoryName); + + if (repository == null) + { + importRepository(manager, repositoryName); + } + else if (logger.isDebugEnabled()) + { + logger.debug("repository {} is allready managed", repositoryName); + } + } + } + + /** + * Method description + * + * + * @param manager + * @param repositoryName + * + * @throws IOException + * @throws RepositoryException + */ + private void importRepository(RepositoryManager manager, + String repositoryName) + throws RepositoryException, IOException + { + if (logger.isInfoEnabled()) + { + logger.info("try to import git repository {}", repositoryName); + } + + Repository repository = new Repository(); + + repository.setName(repositoryName); + repository.setType(GitRepositoryHandler.TYPE_NAME); + repository.setPublicReadable(false); + manager.importRepository(repository); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private GitRepositoryHandler handler; +} diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java index e0ff384b91..314309ea73 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java @@ -41,6 +41,7 @@ import com.google.inject.Singleton; import org.eclipse.jgit.storage.file.FileRepository; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import sonia.scm.NotSupportedFeatuerException; import sonia.scm.Type; import sonia.scm.io.FileSystem; import sonia.scm.plugin.ext.Extension; @@ -184,6 +185,18 @@ public class GitRepositoryHandler return diffViewer; } + /** + * Method description + * + * + * @return + */ + @Override + public ImportHandler getImportHandler() + { + return new GitImportHandler(this); + } + /** * Method description * From 1d930d5537d6b99f973a578f16c42d3fc4a9a81d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 14:30:39 +0100 Subject: [PATCH 03/18] added AbstractImportHandler --- .../scm/repository/AbstactImportHandler.java | 204 ++++++++++++++++++ .../scm/repository/GitImportHandler.java | 79 ++----- 2 files changed, 224 insertions(+), 59 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java b/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java new file mode 100644 index 0000000000..acaccb0d7e --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java @@ -0,0 +1,204 @@ +/** + * 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; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +import java.util.List; + +/** + * + * @author Sebastian Sdorra + * @since 1.12 + */ +public abstract class AbstactImportHandler implements ImportHandler +{ + + /** + * the logger for AbstactImportHandler + */ + private static final Logger logger = + LoggerFactory.getLogger(AbstactImportHandler.class); + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + protected abstract String[] getDirectoryNames(); + + /** + * Method description + * + * + * @return + */ + protected abstract AbstractRepositoryHandler getRepositoryHandler(); + + /** + * Method description + * + * + * @return + */ + protected abstract String getTypeName(); + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param manager + * + * @throws IOException + * @throws RepositoryException + */ + @Override + public void importRepositories(RepositoryManager manager) + throws IOException, RepositoryException + { + if (logger.isTraceEnabled()) + { + logger.trace("search for repositories to import"); + } + + List repositoryNames = + RepositoryUtil.getRepositoryNames(getRepositoryHandler(), + getDirectoryNames()); + + for (String repositoryName : repositoryNames) + { + if (logger.isTraceEnabled()) + { + logger.trace("check repository {} for import", repositoryName); + } + + Repository repository = manager.get(getTypeName(), repositoryName); + + if (repository == null) + { + importRepository(manager, repositoryName); + } + else if (logger.isDebugEnabled()) + { + logger.debug("repository {} is allready managed", repositoryName); + } + } + } + + /** + * Method description + * + * + * @param repositoryDirectory + * @param repositoryName + * + * @return + * + * @throws IOException + * @throws RepositoryException + */ + protected Repository createRepository(File repositoryDirectory, + String repositoryName) + throws IOException, RepositoryException + { + Repository repository = new Repository(); + + repository.setName(repositoryName); + repository.setPublicReadable(false); + repository.setType(getTypeName()); + + return repository; + } + + /** + * Method description + * + * + * @param manager + * @param repositoryName + * + * @throws IOException + * @throws RepositoryException + */ + private void importRepository(RepositoryManager manager, + String repositoryName) + throws IOException, RepositoryException + { + Repository repository = + createRepository(getRepositoryDirectory(repositoryName), repositoryName); + + if (repository != null) + { + if (logger.isInfoEnabled()) + { + logger.info("import repository {} of type {}", repositoryName, + getTypeName()); + } + + manager.importRepository(repository); + } + else if (logger.isWarnEnabled()) + { + logger.warn("could not create repository object for {}", repositoryName); + } + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param repositoryName + * + * @return + */ + private File getRepositoryDirectory(String repositoryName) + { + return new File( + getRepositoryHandler().getConfig().getRepositoryDirectory(), + repositoryName); + } +} diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java index f5a52447eb..ad8aaa6cc1 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java @@ -36,17 +36,11 @@ package sonia.scm.repository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -//~--- JDK imports ------------------------------------------------------------ - -import java.io.IOException; - -import java.util.List; - /** * * @author Sebastian Sdorra */ -public class GitImportHandler implements ImportHandler +public class GitImportHandler extends AbstactImportHandler { /** Field description */ @@ -74,75 +68,42 @@ public class GitImportHandler implements ImportHandler this.handler = handler; } - //~--- methods -------------------------------------------------------------- + //~--- get methods ---------------------------------------------------------- /** * Method description * * - * @param manager - * - * @throws IOException - * @throws RepositoryException + * @return */ @Override - public void importRepositories(RepositoryManager manager) - throws IOException, RepositoryException + protected String[] getDirectoryNames() { - if (logger.isTraceEnabled()) - { - logger.trace("search for git repositories for import"); - } - - List repositoryNames = RepositoryUtil.getRepositoryNames(handler, - GIT_DIR, GIT_DIR_REFS); - - for (String repositoryName : repositoryNames) - { - if (logger.isTraceEnabled()) - { - logger.trace("check git repository {} for import", repositoryName); - } - - Repository repository = manager.get(GitRepositoryHandler.TYPE_NAME, - repositoryName); - - if (repository == null) - { - importRepository(manager, repositoryName); - } - else if (logger.isDebugEnabled()) - { - logger.debug("repository {} is allready managed", repositoryName); - } - } + return new String[] { GIT_DIR, GIT_DIR_REFS }; } /** * Method description * * - * @param manager - * @param repositoryName - * - * @throws IOException - * @throws RepositoryException + * @return */ - private void importRepository(RepositoryManager manager, - String repositoryName) - throws RepositoryException, IOException + @Override + protected AbstractRepositoryHandler getRepositoryHandler() { - if (logger.isInfoEnabled()) - { - logger.info("try to import git repository {}", repositoryName); - } + return handler; + } - Repository repository = new Repository(); - - repository.setName(repositoryName); - repository.setType(GitRepositoryHandler.TYPE_NAME); - repository.setPublicReadable(false); - manager.importRepository(repository); + /** + * Method description + * + * + * @return + */ + @Override + protected String getTypeName() + { + return GitRepositoryHandler.TYPE_NAME; } //~--- fields --------------------------------------------------------------- From 52212bb55838a6c14aadbb4b58e69871ee0b80d3 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 14:35:57 +0100 Subject: [PATCH 04/18] improve AbstractImportHandler --- .../scm/repository/AbstactImportHandler.java | 19 +++++++++++-------- .../scm/repository/GitImportHandler.java | 12 ------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java b/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java index acaccb0d7e..a4d00138b7 100644 --- a/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java +++ b/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java @@ -75,14 +75,6 @@ public abstract class AbstactImportHandler implements ImportHandler */ protected abstract AbstractRepositoryHandler getRepositoryHandler(); - /** - * Method description - * - * - * @return - */ - protected abstract String getTypeName(); - //~--- methods -------------------------------------------------------------- /** @@ -201,4 +193,15 @@ public abstract class AbstactImportHandler implements ImportHandler getRepositoryHandler().getConfig().getRepositoryDirectory(), repositoryName); } + + /** + * Method description + * + * + * @return + */ + private String getTypeName() + { + return getRepositoryHandler().getType().getName(); + } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java index ad8aaa6cc1..aebdf64441 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitImportHandler.java @@ -94,18 +94,6 @@ public class GitImportHandler extends AbstactImportHandler return handler; } - /** - * Method description - * - * - * @return - */ - @Override - protected String getTypeName() - { - return GitRepositoryHandler.TYPE_NAME; - } - //~--- fields --------------------------------------------------------------- /** Field description */ From f2e3a5b5c3b3dda5fdbacbf3b7c8a54c668f6d9e Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 14:37:06 +0100 Subject: [PATCH 05/18] implement svn import handler --- .../scm/repository/SvnImportHandler.java | 87 +++++++++++++++++++ .../scm/repository/SvnRepositoryHandler.java | 13 +++ 2 files changed, 100 insertions(+) create mode 100644 scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnImportHandler.java diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnImportHandler.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnImportHandler.java new file mode 100644 index 0000000000..a476180d1b --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnImportHandler.java @@ -0,0 +1,87 @@ +/** + * 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; + +/** + * + * @author Sebastian Sdorra + */ +public class SvnImportHandler extends AbstactImportHandler +{ + + /** Field description */ + public static final String SVN_DIR_LOCKS = "locks"; + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + * + * @param handler + */ + public SvnImportHandler(SvnRepositoryHandler handler) + { + this.handler = handler; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + protected String[] getDirectoryNames() + { + return new String[] { SVN_DIR_LOCKS }; + } + + /** + * Method description + * + * + * @return + */ + @Override + protected AbstractRepositoryHandler getRepositoryHandler() + { + return handler; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private SvnRepositoryHandler handler; +} diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java index 536586f95a..7b0dceaa7e 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java @@ -46,6 +46,7 @@ import org.tmatesoft.svn.core.internal.io.fs.FSHooks; import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; +import sonia.scm.NotSupportedFeatuerException; import sonia.scm.Type; import sonia.scm.io.FileSystem; import sonia.scm.plugin.ext.Extension; @@ -206,6 +207,18 @@ public class SvnRepositoryHandler return diffViewer; } + /** + * Method description + * + * + * @return + */ + @Override + public ImportHandler getImportHandler() + { + return new SvnImportHandler(this); + } + /** * Method description * From 79d072808d400289a7044f694c95f4dc20e93899 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 14:51:47 +0100 Subject: [PATCH 06/18] implement hg import handler --- .../sonia/scm/repository/HgImportHandler.java | 151 ++++++++++++++++++ .../scm/repository/HgRepositoryHandler.java | 140 ++++++++++++---- 2 files changed, 260 insertions(+), 31 deletions(-) create mode 100644 scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgImportHandler.java diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgImportHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgImportHandler.java new file mode 100644 index 0000000000..6960ab43e5 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgImportHandler.java @@ -0,0 +1,151 @@ +/** + * 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; + +//~--- non-JDK imports -------------------------------------------------------- + +import sonia.scm.io.INIConfiguration; +import sonia.scm.io.INIConfigurationReader; +import sonia.scm.io.INIConfigurationWriter; +import sonia.scm.io.INISection; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class HgImportHandler extends AbstactImportHandler +{ + + /** Field description */ + public static final String HG_DIR = ".hg"; + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + * + * @param handler + */ + public HgImportHandler(HgRepositoryHandler handler) + { + this.handler = handler; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param repositoryDirectory + * @param repositoryName + * + * @return + * + * @throws IOException + * @throws RepositoryException + */ + @Override + protected Repository createRepository(File repositoryDirectory, + String repositoryName) + throws IOException, RepositoryException + { + Repository repository = super.createRepository(repositoryDirectory, + repositoryName); + File hgrc = new File(repositoryDirectory, HgRepositoryHandler.PATH_HGRC); + + if (hgrc.exists()) + { + INIConfigurationReader reader = new INIConfigurationReader(); + INIConfiguration c = reader.read(hgrc); + INISection web = c.getSection("web"); + + if (web == null) + { + handler.appendWebSection(c); + } + else + { + repository.setDescription(web.getParameter("description")); + repository.setContact(web.getParameter("contact")); + handler.setWebParameter(web); + } + + INIConfigurationWriter writer = new INIConfigurationWriter(); + + writer.write(c, hgrc); + } + else + { + handler.postCreate(repository, repositoryDirectory); + } + + return repository; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + protected String[] getDirectoryNames() + { + return new String[] { HG_DIR }; + } + + /** + * Method description + * + * + * @return + */ + @Override + protected AbstractRepositoryHandler getRepositoryHandler() + { + return handler; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private HgRepositoryHandler handler; +} diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java index 3d14f27c0f..9bbdc4f044 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java @@ -293,6 +293,18 @@ public class HgRepositoryHandler return diffViewer; } + /** + * Method description + * + * + * @return + */ + @Override + public ImportHandler getImportHandler() + { + return new HgImportHandler(this); + } + /** * Method description * @@ -320,6 +332,72 @@ public class HgRepositoryHandler return TYPE; } + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param hgrc + */ + void appendHookSection(INIConfiguration hgrc) + { + INISection hooksSection = new INISection("hooks"); + + setHookParameter(hooksSection); + hgrc.addSection(hooksSection); + } + + /** + * Method description + * + * + * @param hgrc + */ + void appendWebSection(INIConfiguration hgrc) + { + INISection webSection = new INISection("web"); + + setWebParameter(webSection); + hgrc.addSection(webSection); + } + + /** + * Method description + * + * + * @param c + * @param repositoryName + * + * @return + */ + boolean registerMissingHook(INIConfiguration c, String repositoryName) + { + INISection hooks = c.getSection("hooks"); + + if (hooks == null) + { + hooks = new INISection("hooks"); + c.addSection(hooks); + } + + boolean write = false; + + if (appendHook(repositoryName, hooks, "changegroup.scm")) + { + write = true; + } + + if (appendHook(repositoryName, hooks, "pretxnchangegroup.scm")) + { + write = true; + } + + return write; + } + + //~--- get methods ---------------------------------------------------------- + /** * Method description * @@ -341,6 +419,34 @@ public class HgRepositoryHandler hgContextProvider.get(), repositoryDirectory); } + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param hooksSection + */ + void setHookParameter(INISection hooksSection) + { + hooksSection.setParameter("changegroup.scm", "python:scmhooks.callback"); + hooksSection.setParameter("pretxnchangegroup.scm", + "python:scmhooks.callback"); + } + + /** + * Method description + * + * + * @param webSection + */ + void setWebParameter(INISection webSection) + { + webSection.setParameter("push_ssl", "false"); + webSection.setParameter("allow_read", "*"); + webSection.setParameter("allow_push", "*"); + } + //~--- methods -------------------------------------------------------------- /** @@ -376,20 +482,11 @@ public class HgRepositoryHandler { File hgrcFile = new File(directory, PATH_HGRC); INIConfiguration hgrc = new INIConfiguration(); - INISection webSection = new INISection("web"); - webSection.setParameter("push_ssl", "false"); - webSection.setParameter("allow_read", "*"); - webSection.setParameter("allow_push", "*"); - hgrc.addSection(webSection); + appendWebSection(hgrc); // register hooks - INISection hooksSection = new INISection("hooks"); - - hooksSection.setParameter("changegroup.scm", "python:scmhooks.callback"); - hooksSection.setParameter("pretxnchangegroup.scm", - "python:scmhooks.callback"); - hgrc.addSection(hooksSection); + appendHookSection(hgrc); INIConfigurationWriter writer = new INIConfigurationWriter(); @@ -483,28 +580,9 @@ public class HgRepositoryHandler { INIConfigurationReader reader = new INIConfigurationReader(); INIConfiguration c = reader.read(hgrc); - INISection hooks = c.getSection("hooks"); - - if (hooks == null) - { - hooks = new INISection("hooks"); - c.addSection(hooks); - } - String repositoryName = repositoryDir.getName(); - boolean write = false; - if (appendHook(repositoryName, hooks, "changegroup.scm")) - { - write = true; - } - - if (appendHook(repositoryName, hooks, "pretxnchangegroup.scm")) - { - write = true; - } - - if (write) + if (registerMissingHook(c, repositoryName)) { if (logger.isDebugEnabled()) { From 0a3c2ef7ef133dfa9d66879292d9b8b31364c6d6 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 14:55:08 +0100 Subject: [PATCH 07/18] improve import api --- .../scm/repository/AbstactImportHandler.java | 24 +++++++++++++++---- .../sonia/scm/repository/ImportHandler.java | 6 ++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java b/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java index a4d00138b7..b9aef60e64 100644 --- a/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java +++ b/scm-core/src/main/java/sonia/scm/repository/AbstactImportHandler.java @@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; /** @@ -83,13 +84,17 @@ public abstract class AbstactImportHandler implements ImportHandler * * @param manager * + * + * @return * @throws IOException * @throws RepositoryException */ @Override - public void importRepositories(RepositoryManager manager) + public List importRepositories(RepositoryManager manager) throws IOException, RepositoryException { + List imported = new ArrayList(); + if (logger.isTraceEnabled()) { logger.trace("search for repositories to import"); @@ -110,13 +115,18 @@ public abstract class AbstactImportHandler implements ImportHandler if (repository == null) { - importRepository(manager, repositoryName); + if (importRepository(manager, repositoryName)) + { + imported.add(repositoryName); + } } else if (logger.isDebugEnabled()) { logger.debug("repository {} is allready managed", repositoryName); } } + + return imported; } /** @@ -151,13 +161,16 @@ public abstract class AbstactImportHandler implements ImportHandler * @param manager * @param repositoryName * + * + * @return * @throws IOException * @throws RepositoryException */ - private void importRepository(RepositoryManager manager, - String repositoryName) + private boolean importRepository(RepositoryManager manager, + String repositoryName) throws IOException, RepositoryException { + boolean result = false; Repository repository = createRepository(getRepositoryDirectory(repositoryName), repositoryName); @@ -170,11 +183,14 @@ public abstract class AbstactImportHandler implements ImportHandler } manager.importRepository(repository); + result = true; } else if (logger.isWarnEnabled()) { logger.warn("could not create repository object for {}", repositoryName); } + + return result; } //~--- get methods ---------------------------------------------------------- diff --git a/scm-core/src/main/java/sonia/scm/repository/ImportHandler.java b/scm-core/src/main/java/sonia/scm/repository/ImportHandler.java index aba490ca11..8ed81af6b5 100644 --- a/scm-core/src/main/java/sonia/scm/repository/ImportHandler.java +++ b/scm-core/src/main/java/sonia/scm/repository/ImportHandler.java @@ -35,6 +35,8 @@ package sonia.scm.repository; import java.io.IOException; +import java.util.List; + /** * Searches and import existing repositories. * @@ -50,9 +52,11 @@ public interface ImportHandler * * @param manager The global {@link RepositoryManager} * + * + * @return a {@link List} names of imported repositories * @throws IOException * @throws RepositoryException */ - public void importRepositories(RepositoryManager manager) + public List importRepositories(RepositoryManager manager) throws IOException, RepositoryException; } From 929a31d68431348350c00a2701a0b54422acfcca Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 15:11:58 +0100 Subject: [PATCH 08/18] start implementation of import resource --- scm-core/src/main/java/sonia/scm/Type.java | 5 + .../resources/RepositoryImportResource.java | 158 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java diff --git a/scm-core/src/main/java/sonia/scm/Type.java b/scm-core/src/main/java/sonia/scm/Type.java index b8618b0953..a864fdb0f0 100644 --- a/scm-core/src/main/java/sonia/scm/Type.java +++ b/scm-core/src/main/java/sonia/scm/Type.java @@ -38,11 +38,16 @@ package sonia.scm; import sonia.scm.util.AssertUtil; import sonia.scm.util.Util; +//~--- JDK imports ------------------------------------------------------------ + +import javax.xml.bind.annotation.XmlRootElement; + /** * Base class for all objects which supports different types. * * @author Sebastian Sdorra */ +@XmlRootElement public class Type { diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java new file mode 100644 index 0000000000..f4d3b0edff --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java @@ -0,0 +1,158 @@ +/** + * 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.api.rest.resources; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Singleton; + +import org.codehaus.enunciate.modules.jersey.SpringManagedLifecycle; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import sonia.scm.NotSupportedFeatuerException; +import sonia.scm.Type; +import sonia.scm.repository.RepositoryHandler; +import sonia.scm.repository.RepositoryManager; +import sonia.scm.util.SecurityUtil; +import sonia.scm.web.security.WebSecurityContext; + +//~--- JDK imports ------------------------------------------------------------ + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MediaType; + +/** + * + * @author Sebastian Sdorra + */ +@Singleton +@Path("import/repositories") +@SpringManagedLifecycle +public class RepositoryImportResource +{ + + /** + * the logger for RepositoryImportResource + */ + private static final Logger logger = + LoggerFactory.getLogger(RepositoryImportResource.class); + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + * + * @param manager + * @param securityContextProvider + */ + @Inject + public RepositoryImportResource( + RepositoryManager manager, + Provider securityContextProvider) + { + this.manager = manager; + this.securityContextProvider = securityContextProvider; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @GET + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public GenericEntity> getImportableTypes() + { + SecurityUtil.assertIsAdmin(securityContextProvider); + + List types = new ArrayList(); + Collection handlerTypes = manager.getTypes(); + + for (Type t : handlerTypes) + { + RepositoryHandler handler = manager.getHandler(t.getName()); + + if (handler != null) + { + try + { + if (handler.getImportHandler() != null) + { + types.add(t); + } + } + catch (NotSupportedFeatuerException ex) + { + if (logger.isTraceEnabled()) + { + logger.trace("import handler is not supported", ex); + } + else if (logger.isInfoEnabled()) + { + logger.info("{} handler does not support import of repositories", + t.getName()); + } + } + } + else if (logger.isWarnEnabled()) + { + logger.warn("could not find handler for type {}", t.getName()); + } + } + + return new GenericEntity>(types) {} + ; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private RepositoryManager manager; + + /** Field description */ + private Provider securityContextProvider; +} From 9d0970da5b402dc9b0a6dc66301f57a650c8b25d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 15:12:31 +0100 Subject: [PATCH 09/18] remove git specific import resource --- .../api/rest/resources/GitImportResource.java | 97 ------------------- 1 file changed, 97 deletions(-) delete mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java deleted file mode 100644 index 55092eb804..0000000000 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/rest/resources/GitImportResource.java +++ /dev/null @@ -1,97 +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.api.rest.resources; - -//~--- non-JDK imports -------------------------------------------------------- - -import com.google.inject.Inject; - -import sonia.scm.repository.GitRepositoryHandler; -import sonia.scm.repository.RepositoryException; -import sonia.scm.repository.RepositoryManager; - -//~--- JDK imports ------------------------------------------------------------ - -import java.io.IOException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -/** - * - * @author Sebastian Sdorra - */ -@Path("import/repositories/git") -public class GitImportResource -{ - - /** - * Constructs ... - * - * - * @param repositoryManager - * @param handler - */ - @Inject - public GitImportResource(RepositoryManager repositoryManager, - GitRepositoryHandler handler) - { - this.repositoryManager = repositoryManager; - this.handler = handler; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @throws IOException - * @throws RepositoryException - */ - @GET - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public void importRepositories() throws IOException, RepositoryException - { - handler.getImportHandler().importRepositories(repositoryManager); - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private GitRepositoryHandler handler; - - /** Field description */ - private RepositoryManager repositoryManager; -} From 96ebd201f0f0d9953e0660620737bbc087706cd2 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 15:18:58 +0100 Subject: [PATCH 10/18] implement method for import of repositories --- .../resources/RepositoryImportResource.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java index f4d3b0edff..27aacd1005 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java @@ -56,8 +56,11 @@ import java.util.Collection; import java.util.List; import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.MediaType; @@ -95,6 +98,52 @@ public class RepositoryImportResource this.securityContextProvider = securityContextProvider; } + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param type + * + * @return + */ + @POST + @Path("{type}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public GenericEntity> importRepositories( + @PathParam("type") String type) + { + SecurityUtil.assertIsAdmin(securityContextProvider); + + List repositories = null; + RepositoryHandler handler = manager.getHandler(type); + + if (handler != null) + { + try + { + repositories = handler.getImportHandler().importRepositories(manager); + } + catch (Exception ex) + { + throw new WebApplicationException(ex); + } + } + else if (logger.isWarnEnabled()) + { + logger.warn("could not find handler for type {}", type); + } + + if (repositories == null) + { + repositories = new ArrayList(); + } + + return new GenericEntity>(repositories) {} + ; + } + //~--- get methods ---------------------------------------------------------- /** From 92fc75711a3399a495a74817e98f677abfa69758 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 15:22:41 +0100 Subject: [PATCH 11/18] improve importRepositories method --- .../resources/RepositoryImportResource.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java index 27aacd1005..879e3dd558 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java @@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory; import sonia.scm.NotSupportedFeatuerException; import sonia.scm.Type; +import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryHandler; import sonia.scm.repository.RepositoryManager; import sonia.scm.util.SecurityUtil; @@ -111,19 +112,38 @@ public class RepositoryImportResource @POST @Path("{type}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public GenericEntity> importRepositories( + public GenericEntity> importRepositories( @PathParam("type") String type) { SecurityUtil.assertIsAdmin(securityContextProvider); - List repositories = null; + List repositories = new ArrayList(); RepositoryHandler handler = manager.getHandler(type); if (handler != null) { try { - repositories = handler.getImportHandler().importRepositories(manager); + List repositoryNames = + handler.getImportHandler().importRepositories(manager); + + if (repositoryNames != null) + { + for (String repositoryName : repositoryNames) + { + Repository repository = manager.get(type, repositoryName); + + if (repository != null) + { + repositories.add(repository); + } + else if (logger.isWarnEnabled()) + { + logger.warn("could not find imported repository {}", + repositoryName); + } + } + } } catch (Exception ex) { @@ -135,12 +155,7 @@ public class RepositoryImportResource logger.warn("could not find handler for type {}", type); } - if (repositories == null) - { - repositories = new ArrayList(); - } - - return new GenericEntity>(repositories) {} + return new GenericEntity>(repositories) {} ; } From be0cc51521ffcc7600d964743dbd1ee56d5aea6c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 15:23:55 +0100 Subject: [PATCH 12/18] added missing TypeHint annontations --- .../sonia/scm/api/rest/resources/RepositoryImportResource.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java index 879e3dd558..bc787f84cc 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryImportResource.java @@ -37,6 +37,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; +import org.codehaus.enunciate.jaxrs.TypeHint; import org.codehaus.enunciate.modules.jersey.SpringManagedLifecycle; import org.slf4j.Logger; @@ -111,6 +112,7 @@ public class RepositoryImportResource */ @POST @Path("{type}") + @TypeHint(Repository[].class) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public GenericEntity> importRepositories( @PathParam("type") String type) @@ -168,6 +170,7 @@ public class RepositoryImportResource * @return */ @GET + @TypeHint(Type[].class) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public GenericEntity> getImportableTypes() { From ee985c086602623295f36af8973ff72d5ba3b454 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 15:42:35 +0100 Subject: [PATCH 13/18] prepare wui for repository import function --- scm-webapp/src/main/webapp/index.html | 1 + .../sonia.repository.importwindow.js | 55 +++++++++++++++++++ .../src/main/webapp/resources/js/sonia.scm.js | 24 ++++++-- 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js diff --git a/scm-webapp/src/main/webapp/index.html b/scm-webapp/src/main/webapp/index.html index b1f82ef316..88e3329102 100644 --- a/scm-webapp/src/main/webapp/index.html +++ b/scm-webapp/src/main/webapp/index.html @@ -113,6 +113,7 @@ + diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js new file mode 100644 index 0000000000..8974922a27 --- /dev/null +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js @@ -0,0 +1,55 @@ +/** + * 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 + * + */ + + +Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ + + // TODO i18n + titleText: 'Import Repositories', + + initComponent: function(){ + var config = { + layout:'fit', + width:300, + height:170, + closable: true, + resizable: false, + plain: true, + border: false, + modal: true, + title: this.titleText, + items: [] + } + Ext.apply(this, Ext.apply(this.initialConfig, config)); + Sonia.repository.ImportWindow.superclass.initComponent.apply(this, arguments); + } + +}); \ No newline at end of file diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js index 3c9e9b7aa8..6d9dc73899 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js @@ -33,6 +33,8 @@ Ext.ns("Sonia.scm"); Sonia.scm.Main = Ext.extend(Ext.util.Observable, { tabRepositoriesText: 'Repositories', + // todo i18n + navImportRepositoriesText: 'Import Repositories', navChangePasswordText: 'Change Password', sectionMainText: 'Main', sectionSecurityText: 'Security', @@ -156,14 +158,26 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, { console.debug('create main menu'); } var panel = Ext.getCmp('navigationPanel'); + + var repositoryLinks = [{ + label: this.navRepositoriesText, + fn: this.addRepositoriesTabPanel, + scope: this + }]; + + if ( admin ){ + repositoryLinks.push({ + label: this.navImportRepositoriesText, + fn: function(){ + new Sonia.repository.ImportWindow().show(); + } + }); + } + panel.addSection({ id: 'navMain', title: this.sectionMainText, - links: [{ - label: this.navRepositoriesText, - fn: this.addRepositoriesTabPanel, - scope: this - }] + links: repositoryLinks }); var securitySection = null; From f0e7f5a938dcc9b646f30b0e98e3792d22fedb9b Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 16:43:04 +0100 Subject: [PATCH 14/18] implement basic form to import repositories --- .../sonia.repository.importwindow.js | 108 +++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js index 8974922a27..0543075930 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js @@ -34,6 +34,11 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ // TODO i18n titleText: 'Import Repositories', + okText: 'Ok', + cancelText: 'Cancel', + + // cache + importForm: null, initComponent: function(){ var config = { @@ -46,10 +51,111 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ border: false, modal: true, title: this.titleText, - items: [] + items: [{ + id: 'importRepositoryForm', + frame: true, + xtype: 'form', + defaultType: 'checkbox' + }], + buttons: [{ + id: 'startRepositoryImportButton', + text: this.okText, + formBind: true, + scope: this, + handler: this.importRepositories + },{ + text: this.cancelText, + scope: this, + handler: this.close + }], + listeners: { + afterrender: { + fn: this.readImportableTypes, + scope: this + } + } } Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.repository.ImportWindow.superclass.initComponent.apply(this, arguments); + }, + + readImportableTypes: function(){ + if (debug){ + console.debug('read importable types'); + } + + Ext.Ajax.request({ + url: restUrl + 'import/repositories.json', + method: 'GET', + scope: this, + success: function(response){ + var obj = Ext.decode(response.responseText); + this.renderTypeCheckboxes(obj); + this.doLayout(); + }, + failure: function(result){ + main.handleFailure( + result.status, + this.errorTitleText, + this.errorMsgText + ); + } + }); + + }, + + renderTypeCheckboxes: function(types){ + Ext.each(types, function(type){ + this.renderCheckbox(type); + }, this); + }, + + getImportForm: function(){ + if (!this.importForm){ + this.importForm = Ext.getCmp('importRepositoryForm'); + } + return this.importForm; + }, + + renderCheckbox: function(type){ + this.getImportForm().add({ + xtype: 'checkbox', + name: 'type', + fieldLabel: type.displayName, + inputValue: type.name + }); + }, + + importRepositories: function(){ + if (debug){ + console.debug('start import of repositories'); + } + var form = this.getImportForm().getForm(); + var values = form.getValues().type; + Ext.each(values, function(value){ + this.importRepositoriesOfType(value); + }, this); + }, + + importRepositoriesOfType: function(type){ + if (debug){ + console.debug('start import of ' + type + ' repositories'); + } + Ext.Ajax.request({ + url: restUrl + 'import/repositories/' + type + '.json', + method: 'POST', + scope: this, + success: function(response){ + var obj = Ext.decode(response.responseText); + }, + failure: function(result){ + main.handleFailure( + result.status, + this.errorTitleText, + this.errorMsgText + ); + } + }); } }); \ No newline at end of file From 7ec516f595cafa1e09cd08df4562762a511529df Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 15 Jan 2012 16:55:51 +0100 Subject: [PATCH 15/18] improve repository import wui --- .../sonia.repository.importwindow.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js index 0543075930..50354becfd 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js @@ -40,6 +40,10 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ // cache importForm: null, + imported: [], + importJobsFinished: 0, + importJobs: 0, + initComponent: function(){ var config = { layout:'fit', @@ -132,11 +136,25 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ } var form = this.getImportForm().getForm(); var values = form.getValues().type; + this.importJobs = values.length; Ext.each(values, function(value){ this.importRepositoriesOfType(value); }, this); }, + appendImported: function(repositories){ + for (var i=0; i= this.importJobs ){ + if (debug){ + console.debug( 'import of ' + this.importJobsFinished + ' jobs finished' ); + } + // print repositories + } + }, + importRepositoriesOfType: function(type){ if (debug){ console.debug('start import of ' + type + ' repositories'); @@ -147,6 +165,7 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ scope: this, success: function(response){ var obj = Ext.decode(response.responseText); + this.appendImported(obj); }, failure: function(result){ main.handleFailure( From d8f274f444febce7b5addc1aade075d2d3b5b6fc Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 16 Jan 2012 16:42:12 +0100 Subject: [PATCH 16/18] show imported repositories and fix small selection bug --- .../sonia.repository.importwindow.js | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js index 50354becfd..a9fa010acf 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js @@ -35,7 +35,7 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ // TODO i18n titleText: 'Import Repositories', okText: 'Ok', - cancelText: 'Cancel', + closeText: 'Close', // cache importForm: null, @@ -68,7 +68,7 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ scope: this, handler: this.importRepositories },{ - text: this.cancelText, + text: this.closeText, scope: this, handler: this.close }], @@ -136,7 +136,15 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ } var form = this.getImportForm().getForm(); var values = form.getValues().type; - this.importJobs = values.length; + if ( values ){ + if ( Ext.isArray(values) ){ + this.importJobs = values.length; + } else { + this.importJobs = 1; + } + } else { + this.importJobs = 0; + } Ext.each(values, function(value){ this.importRepositoriesOfType(value); }, this); @@ -151,14 +159,47 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ if (debug){ console.debug( 'import of ' + this.importJobsFinished + ' jobs finished' ); } - // print repositories + this.printImported(); } }, + printImported: function(){ + var store = new Ext.data.JsonStore({ + fields: ['type', 'name'] + }); + store.loadData(this.imported); + + var colModel = new Ext.grid.ColumnModel({ + defaults: { + sortable: true, + scope: this + }, + columns: [ + {id: 'name', header: 'Name', dataIndex: 'name'}, + {id: 'type', header: 'Type', dataIndex: 'type'} + ] + }); + + this.getImportForm().add({ + xtype: 'grid', + autoExpandColumn: 'name', + store: store, + colModel: colModel, + height: 100 + }); + var h = this.getHeight(); + this.setHeight( h + 100 ); + this.doLayout(); + }, + importRepositoriesOfType: function(type){ if (debug){ console.debug('start import of ' + type + ' repositories'); } + var b = Ext.getCmp('startRepositoryImportButton'); + if ( b ){ + b.setDisabled(true); + } Ext.Ajax.request({ url: restUrl + 'import/repositories/' + type + '.json', method: 'POST', From ea48e2adf61a35ddddefae1cd7c906ffeeb0989b Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 16 Jan 2012 16:45:30 +0100 Subject: [PATCH 17/18] reload repository panel after import --- .../js/repository/sonia.repository.importwindow.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js index a9fa010acf..825b900da9 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.importwindow.js @@ -190,6 +190,12 @@ Sonia.repository.ImportWindow = Ext.extend(Ext.Window,{ var h = this.getHeight(); this.setHeight( h + 100 ); this.doLayout(); + + // reload repositories panel + var panel = Ext.getCmp('repositories'); + if (panel){ + panel.getGrid().reload(); + } }, importRepositoriesOfType: function(type){ From ff234dc0137e289946fde81c2caa4730bc28bbdf Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 16 Jan 2012 16:52:53 +0100 Subject: [PATCH 18/18] close branch issue-59