mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 20:30:52 +01:00
implement import-from-url cli sub command
This commit is contained in:
@@ -56,39 +56,13 @@ import java.util.Map;
|
||||
usage = "usageImportDirectory",
|
||||
group = "repository"
|
||||
)
|
||||
public class ImportDirectorySubCommand extends TemplateSubCommand
|
||||
public class ImportDirectorySubCommand extends ImportSubCommand
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String TEMPLATE =
|
||||
"/sonia/resources/import-from-directory.ftl";
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -100,21 +74,11 @@ public class ImportDirectorySubCommand extends TemplateSubCommand
|
||||
{
|
||||
ScmClientSession session = createSession();
|
||||
ImportResultWrapper wrapper =
|
||||
session.getRepositoryHandler().importFromDirectory(type);
|
||||
session.getRepositoryHandler().importFromDirectory(getType());
|
||||
Map<String, Object> env = Maps.newHashMap();
|
||||
|
||||
env.put("importedDirectories", wrapper.getImportedDirectories());
|
||||
env.put("failedDirectories", wrapper.getFailedDirectories());
|
||||
renderTemplate(env, TEMPLATE);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@Argument(
|
||||
usage = "optionRepositoryType",
|
||||
metaVar = "repositorytype",
|
||||
required = true
|
||||
)
|
||||
private String type;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2014, 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.cli.cmd;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.kohsuke.args4j.Argument;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.43
|
||||
*/
|
||||
public abstract class ImportSubCommand extends TemplateSubCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@Argument(
|
||||
usage = "optionRepositoryType",
|
||||
metaVar = "repositorytype",
|
||||
required = true
|
||||
)
|
||||
private String type;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright (c) 2014, 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.cli.cmd;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import sonia.scm.client.ImportUrlRequest;
|
||||
import sonia.scm.client.ScmClientSession;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Command(
|
||||
name = "import-from-url",
|
||||
usage = "usageImportUrl",
|
||||
group = "repository"
|
||||
)
|
||||
public class ImportUrlSubCommand extends ImportSubCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public URL getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
public void setUrl(URL url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected void run()
|
||||
{
|
||||
ScmClientSession session = createSession();
|
||||
|
||||
ImportUrlRequest request = new ImportUrlRequest(getType(), name,
|
||||
url.toExternalForm());
|
||||
Repository repository =
|
||||
session.getRepositoryHandler().importFromUrl(request);
|
||||
Map<String, Object> env = Maps.newHashMap();
|
||||
|
||||
env.put("repository", repository);
|
||||
renderTemplate(env, GetRepositorySubCommand.TEMPLATE);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@Option(
|
||||
name = "--name",
|
||||
required = true,
|
||||
usage = "optionRepositoryName",
|
||||
aliases = { "-n" }
|
||||
)
|
||||
private String name;
|
||||
|
||||
/** Field description */
|
||||
@Option(
|
||||
name = "--url",
|
||||
required = true,
|
||||
usage = "optionRemoteRepositoryUrl",
|
||||
aliases = { "-r" }
|
||||
)
|
||||
private URL url;
|
||||
}
|
||||
@@ -38,6 +38,7 @@ sonia.scm.cli.cmd.GetRepositorySubCommand
|
||||
sonia.scm.cli.cmd.ListRepositoriesSubCommand
|
||||
sonia.scm.cli.cmd.DeleteRepositorySubCommand
|
||||
sonia.scm.cli.cmd.ImportDirectorySubCommand
|
||||
sonia.scm.cli.cmd.ImportUrlSubCommand
|
||||
|
||||
# permission
|
||||
sonia.scm.cli.cmd.AddPermissionSubCommand
|
||||
|
||||
@@ -51,6 +51,7 @@ optionRepositoryContact = Repository contact
|
||||
optionRepositoryDescription = Repository description
|
||||
optionRepositoryPublic = Repository public readable
|
||||
optionRepositoryArchive = Repository archived
|
||||
optionRemoteRepositoryUrl = Remote repository url
|
||||
|
||||
optionPermissionGroup = Group
|
||||
optionPermissionName = Group or user name
|
||||
@@ -91,6 +92,7 @@ user = User
|
||||
security = Security
|
||||
level = Logging-Level
|
||||
boolean = true or false
|
||||
URL = url
|
||||
|
||||
options = Options
|
||||
usage = scm-cli-client [options] command [command options]
|
||||
@@ -120,6 +122,7 @@ usageStoreConfig = Stores the current configuration
|
||||
usageVersion = Show the version of scm-cli-client
|
||||
usageServerVersion = Show the version of the scm-manager
|
||||
usageImportDirectory = Import repositories from repository directory
|
||||
usageImportUrl = Import repository from remote url
|
||||
|
||||
usageEncrypt = Encrypts the given value
|
||||
usageGenerateKey = Generates a unique key
|
||||
Reference in New Issue
Block a user