Skip to content

Commit

Permalink
[JENKINS-24515] Allow copy folders.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedam committed Sep 3, 2014
1 parent b43bb3d commit b52e0f2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Expand Up @@ -38,7 +38,6 @@
import hudson.model.ItemGroup;
import hudson.model.TopLevelItem;
import hudson.model.BuildListener;
import hudson.model.Job;
import hudson.model.AbstractBuild;
import hudson.model.AbstractItem;
import hudson.model.AbstractProject;
Expand Down Expand Up @@ -236,9 +235,9 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
listener.getLogger().println(String.format("Error: Item '%s 'was not found.", fromJob));
return false;
}
else if(!(fromJob instanceof Job<?,?>))
else if(!(fromJob instanceof AbstractItem))
{
listener.getLogger().println(String.format("Error: Item '%s' was found, but is not a job.", fromJob));
listener.getLogger().println(String.format("Error: Item '%s' was found, but cannot be copied (does not support AbstractItem).", fromJob));
return false;
}

Expand All @@ -259,7 +258,7 @@ else if(!(fromJob instanceof Job<?,?>))
// Retrieve the config.xml of the job copied from.
listener.getLogger().println(String.format("Fetching configuration of %s...", fromJobNameExpanded));

XmlFile file = ((Job<?,?>)fromJob).getConfigFile();
XmlFile file = ((AbstractItem)fromJob).getConfigFile();
String jobConfigXmlString = file.asString();
String encoding = file.sniffEncoding();
listener.getLogger().println("Original xml:");
Expand Down Expand Up @@ -504,7 +503,7 @@ public ComboBoxModel doFillFromJobNameItems(@AncestorInPath AbstractProject<?,?>
{
final ItemGroup<?> context = (project != null)?project.getParent():Jenkins.getInstance().getItemGroup();
List<String> itemList = new ArrayList<String>(Lists.transform(
Jenkins.getInstance().getAllItems(),
Jenkins.getInstance().getAllItems(AbstractItem.class),
new Function<Item, String>()
{
public String apply(Item input)
Expand Down Expand Up @@ -609,6 +608,10 @@ public FormValidation doCheckJobName(AbstractProject<?,?> project, String jobNam
{
return FormValidation.warning(Messages.JobCopyBuilder_JobName_exists());
}
if(!(job instanceof AbstractItem))
{
return FormValidation.warning(Messages.JobCopyBuilder_JobName_notAbstractItem());
}
}
else
{
Expand Down
Expand Up @@ -28,6 +28,7 @@ CopiedjobinfoAction.DisplayName=Copied Job
JobCopyBuilder.JobName.empty=Cannot be blank.
JobCopyBuilder.JobName.exists=Specified job already exists. Check "Overwrite", or a build will fail if the job exists at the execution time.
JobCopyBuilder.JobName.notExists=Spedivied job does not exist. A build will fail if the job does not exist at the execution time.
JobCopyBuilder.JobName.notAbstractItem=Specified item cannot be copied (does not implement AbstractItem).
ReplaceOperation.fromStr.empty=Cannot be empty. Empty string results in a failure of the build.
ReplaceOperation.fromStr.enclosedWithBlank=String is surrounded with white spaces. Replacement is performed without trimming white spaces, the replacement may not work as you expects.
AdditionalFileSet.includeFile.empty=Cannot be blank.
Expand Up @@ -36,6 +36,8 @@ JobCopyBuilder.JobName.empty=\u5024\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3
JobCopyBuilder.JobName.exists=\u6307\u5b9a\u306e\u30b8\u30e7\u30d6\u306f\u65e2\u306b\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u3002\u300c\u4e0a\u66f8\u304d\u3059\u308b\u300d\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u306a\u3044\u5834\u5408\u3001\u5b9f\u884c\u6642\u306b\u30b3\u30d4\u30fc\u5148\u306e\u30b8\u30e7\u30d6\u304c\u5b58\u5728\u3059\u308b\u3068\u30d3\u30eb\u30c9\u306b\u5931\u6557\u3057\u307e\u3059\u3002
# JobCopyBuilder.JobName.notExists=指定のジョブは存在しません。実行時にコピー元のジョブが存在しない場合、ビルドに失敗します。
JobCopyBuilder.JobName.notExists=\u6307\u5b9a\u306e\u30b8\u30e7\u30d6\u306f\u5b58\u5728\u3057\u307e\u305b\u3093\u3002\u5b9f\u884c\u6642\u306b\u30b3\u30d4\u30fc\u5143\u306e\u30b8\u30e7\u30d6\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u3001\u30d3\u30eb\u30c9\u306b\u5931\u6557\u3057\u307e\u3059\u3002
# JobCopyBuilder.JobName.notAbstractItem=指定されたアイテムはコピーできません (AbstractItem を実装していない)。
JobCopyBuilder.JobName.notAbstractItem=\u6307\u5b9a\u3055\u308c\u305f\u30a2\u30a4\u30c6\u30e0\u306f\u30b3\u30d4\u30fc\u3067\u304d\u307e\u305b\u3093 (AbstractItem \u3092\u5b9f\u88c5\u3057\u3066\u3044\u306a\u3044)\u3002
# ReplaceOperation.fromStr.empty=値を指定してください。置き換え前の文字列が空文字列の場合、ビルドに失敗します。
ReplaceOperation.fromStr.empty=\u5024\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u7f6e\u304d\u63db\u3048\u524d\u306e\u6587\u5b57\u5217\u304c\u7a7a\u6587\u5b57\u5217\u306e\u5834\u5408\u3001\u30d3\u30eb\u30c9\u306b\u5931\u6557\u3057\u307e\u3059\u3002
# ReplaceOperation.fromStr.enclosedWithBlank=文字列の前後に空白文字があります。前後の空白文字を含んで置き換え処理を行うので、意図した通りの動作をしない場合があります。
Expand Down
Expand Up @@ -1428,6 +1428,29 @@ public void testPerformWithFolder() throws Exception
// overwrite
assertBuildStatusSuccess(copyJob.scheduleBuild2(0));
}

// copy a folder
{
FreeStyleProject copyJob = createFreeStyleProject();
String src = "folder1";
String dest = "newfolder";
assertNotNull(jenkins.getItemByFullName(src));
assertNull(jenkins.getItemByFullName(dest));

copyJob.getBuildersList().add(
new JobcopyBuilder(
src,
dest,
true,
Collections.<JobcopyOperation>emptyList(),
Collections.<AdditionalFileset>emptyList()
)
);
assertBuildStatusSuccess(copyJob.scheduleBuild2(0));
assertNotNull(jenkins.getItemByFullName(dest));
// overwrite
assertBuildStatusSuccess(copyJob.scheduleBuild2(0));
}
}

public void testPerformWithFolderError() throws Exception
Expand Down

0 comments on commit b52e0f2

Please sign in to comment.