use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishUtilTestCase method getTestProject.
private static IProject getTestProject() throws CoreException {
if (testProject == null) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("PublishTest");
if (!project.exists())
project.create(null);
if (!project.isOpen())
project.open(null);
// Create a project with "A" and "B" files in the root of the
// project and in "A" and "B" folders. Create two module resource
// arrays, one including all resources and one omitting the "B" files.
// Prepare an array of IPaths for the "B" files to use in testing
// preservation.
testResources = new IModuleResource[4];
testResources2 = new IModuleResource[3];
preservePaths = new IPath[3];
IFile rootFileA = project.getFile("rootFileA.txt");
setFileContents(rootFileA, "rootFileA contents", true);
testResources[0] = new ModuleFile(rootFileA, "rootFileA.txt", rootFileA.getProjectRelativePath());
testResources2[0] = testResources[0];
IFile rootFileB = project.getFile("rootFileB.txt");
setFileContents(rootFileB, "rootFileB contents", true);
testResources[1] = new ModuleFile(rootFileB, "rootFileB.txt", rootFileB.getProjectRelativePath());
preservePaths[0] = rootFileB.getProjectRelativePath();
IFolder folderA = project.getFolder("FolderA");
if (!folderA.exists())
folderA.create(true, true, null);
ModuleFolder moduleFolder = new ModuleFolder(folderA, "FolderA", folderA.getProjectRelativePath());
IModuleResource[] folderFiles = new IModuleResource[2];
moduleFolder.setMembers(folderFiles);
testResources[2] = moduleFolder;
IFile folderAFileA = folderA.getFile("folderAFileA.txt");
setFileContents(folderAFileA, "folderAFileA contents", true);
folderFiles[0] = new ModuleFile(folderAFileA, "folderAFileA.txt", folderAFileA.getProjectRelativePath());
IFile folderAFileB = folderA.getFile("folderAFileB.txt");
setFileContents(folderAFileB, "folderAFileB contents", true);
folderFiles[1] = new ModuleFile(folderAFileB, "folderAFileB.txt", folderAFileB.getProjectRelativePath());
preservePaths[1] = folderAFileB.getProjectRelativePath();
moduleFolder = new ModuleFolder(folderA, "FolderA", folderA.getProjectRelativePath());
moduleFolder.setMembers(new IModuleResource[] { folderFiles[0] });
testResources2[1] = moduleFolder;
IFolder folderB = project.getFolder("FolderB");
if (!folderB.exists())
folderB.create(true, true, null);
moduleFolder = new ModuleFolder(folderB, "FolderB", folderB.getProjectRelativePath());
folderFiles = new IModuleResource[2];
moduleFolder.setMembers(folderFiles);
testResources[3] = moduleFolder;
IFile folderBFileA = folderB.getFile("folderBFileA.txt");
setFileContents(folderBFileA, "folderBFileA contents", true);
folderFiles[0] = new ModuleFile(folderBFileA, "folderBFileA.txt", folderBFileA.getProjectRelativePath());
IFile folderBFileB = folderB.getFile("folderBFileB.txt");
setFileContents(folderBFileB, "folderBFileB contents", true);
folderFiles[1] = new ModuleFile(folderBFileB, "folderBFileB.txt", folderBFileB.getProjectRelativePath());
preservePaths[2] = folderBFileB.getProjectRelativePath();
moduleFolder = new ModuleFolder(folderB, "FolderB", folderB.getProjectRelativePath());
moduleFolder.setMembers(new IModuleResource[] { folderFiles[0] });
testResources2[2] = moduleFolder;
testProject = project;
}
return testProject;
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishUtilTestCase method test01FullCopy.
public void test01FullCopy() throws Exception {
// wait to ensure time stamps differ
Thread.sleep(1000);
IProject project = getTestProject();
// Modify all file contents and time stamps
IFile rootFileA = project.getFile("rootFileA.txt");
setFileContents(rootFileA, "rootFileA contents 2", true);
IFile rootFileB = project.getFile("rootFileB.txt");
setFileContents(rootFileB, "rootFileB contents 2", true);
IFile folderAFileA = project.getFile("FolderA/folderAFileA.txt");
setFileContents(folderAFileA, "folderAFileA contents 2", true);
IFile folderAFileB = project.getFile("FolderA/folderAFileB.txt");
setFileContents(folderAFileB, "folderAFileB contents 2", true);
IFile folderBFileA = project.getFile("FolderB/folderBFileA.txt");
setFileContents(folderBFileA, "folderBFileA contents 2", true);
IFile folderBFileB = project.getFile("FolderB/folderBFileB.txt");
setFileContents(folderBFileB, "folderBFileB contents 2", true);
// Publish all resources
IPath dest = getDestination();
assertNotNull(dest);
IModuleResource[] resources = getModuleResources();
IStatus[] result = PublishUtil.publishSmart(resources, dest, null, null);
assertNotNull(result);
assertTrue(getResultMessage(result), result.length == 0);
// Verify all files were copied
String contents = getContents(dest.append(resources[0].getModuleRelativePath()));
assertEquals("rootFileA contents 2", contents);
contents = getContents(dest.append(resources[1].getModuleRelativePath()));
assertEquals("rootFileB contents 2", contents);
IModuleFolder mf = (IModuleFolder) resources[2];
contents = getContents(dest.append(mf.members()[0].getModuleRelativePath()));
assertEquals("folderAFileA contents 2", contents);
contents = getContents(dest.append(mf.members()[1].getModuleRelativePath()));
assertEquals("folderAFileB contents 2", contents);
mf = (IModuleFolder) resources[3];
contents = getContents(dest.append(mf.members()[0].getModuleRelativePath()));
assertEquals("folderBFileA contents 2", contents);
contents = getContents(dest.append(mf.members()[1].getModuleRelativePath()));
assertEquals("folderBFileB contents 2", contents);
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.sourceediting by eclipse.
the class ComponentDeployable method ensureParentExists.
protected ModuleFolder ensureParentExists(IPath path, IContainer cc) {
ModuleFolder parent = (ModuleFolder) getExistingModuleResource(members, path);
if (parent == null) {
String folderName = path.lastSegment();
IPath folderPath = Path.EMPTY;
if (path.segmentCount() > 1)
folderPath = path.removeLastSegments(1);
parent = new ModuleFolder(cc, folderName, folderPath);
if (path.segmentCount() > 1)
addMembersToModuleFolder(ensureParentExists(path.removeLastSegments(1), cc), new IModuleResource[] { parent });
else
members.add(parent);
}
return parent;
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.sourceediting by eclipse.
the class ComponentDeployable method getExistingModuleResource.
/**
* Check the current cache to see if we already have an existing module resource for
* the given path.
* @param aList
* @param path
* @return an existing moduleResource from the cached result
*/
protected IModuleResource getExistingModuleResource(List aList, IPath path) {
// If the list is empty, return null
if (aList == null || aList.isEmpty() || path == null)
return null;
// Otherwise recursively check to see if given resource matches current resource or if it is a child
String[] pathSegments = path.segments();
IModuleResource moduleResource = null;
if (pathSegments.length == 0)
return null;
for (Iterator iter = aList.iterator(); iter.hasNext(); ) {
moduleResource = (IModuleResource) iter.next();
String[] moduleSegments = moduleResource.getModuleRelativePath().segments();
// then we have a match and we return the existing moduleResource
if (pathSegments[pathSegments.length - 1].equals(moduleResource.getName()) && (moduleSegments.length + 1) == pathSegments.length && startsWith(moduleSegments, pathSegments))
return moduleResource;
// but only check if the beginning segments are a match
if (moduleResource instanceof IModuleFolder && startsWith(moduleSegments, pathSegments) && pathSegments.length > moduleSegments.length && moduleResource.getName().equals(pathSegments[moduleSegments.length > 0 ? moduleSegments.length : 0]))
if (((IModuleFolder) moduleResource).members() != null)
return getExistingModuleResource(Arrays.asList(((IModuleFolder) moduleResource).members()), path);
}
return null;
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.sourceediting by eclipse.
the class ComponentDeployable method getMembers.
/**
* Find the module resources for a given container and path. Inserts in the java containers
* at a given path if not null.
*
* @param cont a container
* @param path the current module relative path
* @param javaPath the path where Java resources fit in the root
* @param javaCont
* @return a possibly-empty array of module resources
* @throws CoreException
*/
protected IModuleResource[] getMembers(IContainer cont, IPath path, IPath javaPath, IContainer[] javaCont) throws CoreException {
IResource[] res = cont.members();
int size2 = res.length;
List<IModuleFile> list = new ArrayList<IModuleFile>(size2);
for (int j = 0; j < size2; j++) {
if (res[j] instanceof IContainer) {
IContainer cc = (IContainer) res[j];
IPath newPath = path.append(cc.getName()).makeRelative();
// Retrieve already existing module folder if applicable
ModuleFolder mf = (ModuleFolder) getExistingModuleResource(members, newPath);
if (mf == null) {
mf = new ModuleFolder(cc, cc.getName(), path);
ModuleFolder parent = (ModuleFolder) getExistingModuleResource(members, path);
if (path.isEmpty())
members.add(mf);
else {
if (parent == null)
parent = ensureParentExists(path, cc);
addMembersToModuleFolder(parent, new IModuleResource[] { mf });
}
}
IModuleResource[] mr = getMembers(cc, newPath, javaPath, javaCont);
if (javaPath != null && newPath.isPrefixOf(javaPath))
mr = handleJavaPath(path, javaPath, newPath, javaCont, mr, cc);
addMembersToModuleFolder(mf, mr);
} else {
IFile f = (IFile) res[j];
// Handle the default package case
if (path.equals(javaPath)) {
ModuleFolder mFolder = (ModuleFolder) getExistingModuleResource(members, javaPath);
IModuleFile mFile = createModuleFile(f, javaPath);
if (mFolder != null)
addMembersToModuleFolder(mFolder, new IModuleResource[] { mFile });
else
list.add(mFile);
} else {
IModuleFile mf = createModuleFile(f, path);
list.add(mf);
}
}
}
IModuleResource[] mr = new IModuleResource[list.size()];
list.toArray(mr);
return mr;
}
Aggregations