Question
· Mar 23, 2017

Copying all the classes in a package to a new package

Hello ISM Community,

Is it possible to copy all the classes in a package to a new package in Studio?

If not does anyone have some ObjectScript code that does this?

Regards

Mike

Discussion (5)0
Log in or sign up to continue

Personally, I would do this via Source Control and not via Studio.  The approach to this will depend on your source control structures, etc, but the easiest way to handle this for me would be:

1) Make sure that everything in my package was checked into my branch, e.g. /MyApp/cls/MyFirstPackage/...

2) Since my source tree is structured according to package names, I would copy /MyApp/cls/MyFirstPackage/... to /MyApp/cls/MySecondPackage/... 

3) Check in /MyApp/cls/MySecondPackage/... into source control

4) Check out /MyApp/cls/MySecondPackage/... 

5) Do a Find & Replace in /MyApp/cls/MySecondPackage/... to replace all instances of "MyFirstPackage" with "MySecondPackage"

6) Diff /MyApp/cls/MySecondPackage/...  and make sure all replacements are desired

7) Check in /MyApp/cls/MySecondPackage/... 

8) Run my build routine to pull all of /MyApp/cls/MySecondPackage/...  into my namespace and Compile it (or just use $system.OBJ.LoadDir() if you don't already have a build routine)

Voila!  Package is duplicated and all checked into source control ready for further changes :) The above process should only take a couple of minutes.

The below routine can be used for it.

CLSCOPY
Q

COPY(Class,NewClass,Qual="")
; Copy a class
; Pass Qual as 'ck' to keep the source
(Class,NewClass, Qual)
;TSTART
Q:Class="" "Class Name Can't be empty"
Q:$D(^oddDEF(Class))'=11 "Class "_Class_" is not found."
^oddDEF(NewClass) = ^oddDEF(Class)
^oddDEF(NewClass,1) = NewClass
K:'(Qual["k") ^oddDEF(NewClass,"s")
$system.OBJ.Compile(NewClass,Qual,.ER)
$system.OBJ.Compile(NewClass,Qual,.ER)
;I ER TROLLBACK Q ER(1)
ER ER(1)
;TCOMMIT
1

COPYPKG(Pkg,NewPkg,Qual="") ; Copy a package
(Pkg, NewPkg, St, Qual)
St
Sub = Pkg_"."
While 1 {
Sub = $O(^oddDEF(Sub)) Q:Sub=""
Sub,!
$P(Sub,".") '= Pkg Q
St($I(St)) = Sub_"|"_$$COPY(Sub,NewPkg_"."_$P(Sub,".",2,*),Qual)
}
St