Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read/Write of project definitions when moving a class between packages doesn't properly delete the moved class from the original package #943

Open
dalehenrich opened this issue Feb 4, 2025 · 0 comments

Comments

@dalehenrich
Copy link
Member

The following example script run against tukanos/BitmapCharacterSet: 659c7b490 illustrates the issue:

	| loadSpec projectsHome resolvedProject definedProject pharoComponentName pharoPackageName pharoPackage testPackage className classDefinition |
	projectsHome := '/bosch1/users/dhenrich/_stones/git/'.
	loadSpec := RwSpecification fromUrl: 'file://', projectsHome, '/BitmapCharacterSet/rowan/specs/BitmapCharacterSet-Tests.ston'.
	resolvedProject := loadSpec resolveProject.
	resolvedProject := Rowan 
		projectFromUrl: 'file://', projectsHome, '/BitmapCharacterSet/rowan/specs/BitmapCharacterSet-Tests.ston'
		diskUrl: 'file://', projectsHome, '/BitmapCharacterSet'.
	"A resolved project is ready to be loaded, but we are interested in making changes to the project, 
		so we need a defined project."
	definedProject := resolvedProject defined. 
	pharoComponentName := 'Pharo'.
	definedProject 
		addLoadComponentNamed: pharoComponentName 
		comment: 'placeholder component, since packages must be managed by a component'.
	pharoPackageName := 'Collections-BitmapCharacterSet-Tests-Pharo'.
	className := 'ManifestCollectionsBitmapCharacterSetTests'.
	testPackage := definedProject packageNamed: 'Collections-BitmapCharacterSet-Tests'.
	classDefinition := testPackage removeClassNamed: className.
false ifTrue: [ 
        "workaround for issue"
	definedProject export. "export reads packages from disk to write diffs, but that ends restoring the removed class"
].
	classDefinition category: pharoPackageName.
	pharoPackage := definedProject addPackageNamed: pharoPackageName toComponentNamed: pharoComponentName.
	pharoPackage addClassDefinition: classDefinition.
	definedProject export

After running this script both the Collections-BitmapCharacterSet-Tests-Pharo and Collections-BitmapCharacterSet-Tests packages end up with a ManifestCollectionsBitmapCharacterSetTests class ...

The workaround is to export the project immediately after the class definition is removed and before the class definition is added to the new package ....

To be clear it is the MOVE of the class definition from one package to another that causes the issue ... the export package algorithm reads the packages from disk into a copy of the project (restoring the class definition that was removed) ... which is whey the workaround works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant