{
ISigilProjectModel sourceProject = SigilCore.create(packageFragment.getJavaProject().getProject());
IPackageFragmentRoot dest = (IPackageFragmentRoot) getArguments().getDestination();
ISigilProjectModel destProject = SigilCore.create(dest.getJavaProject().getProject());
RefactoringStatus status = new RefactoringStatus();
if (!sourceProject.equals(destProject))
{
RefactorUtil.touch(context, sourceProject);
RefactorUtil.touch(context, destProject);
final String packageName = packageFragment.getElementName();
IPackageExport oldExport = ModelHelper.findExport(sourceProject,
packageName);
if (oldExport != null)
{
IPackageExport newExport = ModelElementFactory.getInstance().newModelElement(
IPackageExport.class);
newExport.setPackageName(oldExport.getPackageName());
newExport.setVersion(oldExport.getRawVersion());
changes.add(new ExportPackageChange(destProject, null, newExport));
changes.add(new ExportPackageChange(sourceProject, oldExport,
null));
status.addWarning("Package " + packageName + " is exported from "
+ sourceProject.getSymbolicName()
+ ", this may effect client bundles that use require bundle");
}
else
{
SubMonitor sub = SubMonitor.convert(monitor);
sub.beginTask("Resolving package users", 200);
Set<String> users = JavaHelper.findLocalPackageUsers(
sourceProject, packageName, sub.newChild(100));
Set<String> dependencies = JavaHelper.findLocalPackageDependencies(
sourceProject, packageName, sub.newChild(100));
if (users.size() > 0 && dependencies.size() > 0)
{
status.addWarning("Package " + packageName
+ " is coupled to " + users + " and " + dependencies
+ " this may cause a cyclical dependency");
}
if (users.size() > 0)
{ // attempt to move an API package
IPackageExport newExport = RefactorUtil.createNewExport(status, changes,
destProject, packageName);
RefactorUtil.createNewImport(status, changes, sourceProject, newExport);
}
if (dependencies.size() > 0)
{ // moved an impl package
for (String dep : dependencies)
{
IPackageExport newExport = RefactorUtil.createNewExport(status, changes,
sourceProject, dep);
RefactorUtil.createNewImport(status, changes, destProject, newExport);
}
}
}
}
return status;
}
catch (CoreException e)
{
SigilCore.warn("Failed to create move refactor conditions", e);
throw new OperationCanceledException(e.getMessage());
}
}
else
{
return new RefactoringStatus();
}
}