Written by

Question Mike Dawson · 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

Comments

Ben Spead · Mar 23, 2017

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.

0
John Murray · Mar 23, 2017

I suggest you export the package to XML, then edit the XML, then import it.

0
Dmitry Maslennikov · Mar 23, 2017

It is not so simple as would appear in the first time. Because you can have some mentions to old package in a source. In studio only possible to rename some class with refactoring feature. Unfortunately, this feature is not documented, or I have not found.

0
Tom Fitzgibbon · Mar 23, 2017

No good answer here but always wondered why this was not easier to do in Studio.

In the past I've copied/pasted classes in small packages to new package, or exported to XML, edited and imported as others have suggested.

Tom Fitzgibbon | 347-464-8531 | gototomAtG...l.com

0
Krishnamuthu Venkatachalam · May 17, 2018

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

0