use of org.eclipse.wst.server.core.util.ModuleFolder 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.util.ModuleFolder 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.util.ModuleFolder 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;
}
use of org.eclipse.wst.server.core.util.ModuleFolder in project webtools.sourceediting by eclipse.
the class ComponentDeployable method addUtilMember.
protected void addUtilMember(IVirtualComponent parent, IVirtualReference reference, IPath runtimePath) {
IModuleFile mf = null;
final String archiveName2 = reference.getArchiveName();
final String archiveName = new Path(archiveName2).lastSegment();
final IVirtualComponent virtualComp = reference.getReferencedComponent();
IFile ifile = virtualComp.getAdapter(IFile.class);
if (ifile != null) {
// In Workspace
String name = null != archiveName ? archiveName : ifile.getName();
mf = new ModuleFile(ifile, name, runtimePath.makeRelative());
} else {
File extFile = virtualComp.getAdapter(File.class);
String name = null != archiveName ? archiveName : extFile.getName();
mf = new ModuleFile(extFile, name, runtimePath.makeRelative());
}
IModuleResource moduleParent = getExistingModuleResource(members, mf.getModuleRelativePath());
if (moduleParent != null && moduleParent instanceof ModuleFolder) {
addMembersToModuleFolder((ModuleFolder) moduleParent, new IModuleResource[] { mf });
} else {
if (mf.getModuleRelativePath().isEmpty()) {
members.add(mf);
} else {
if (moduleParent == null) {
moduleParent = ensureParentExists(mf.getModuleRelativePath(), (IContainer) parent.getRootFolder().getUnderlyingResource());
}
addMembersToModuleFolder((ModuleFolder) moduleParent, new IModuleResource[] { mf });
}
}
}
use of org.eclipse.wst.server.core.util.ModuleFolder in project webtools.sourceediting by eclipse.
the class ComponentDeployable method getMembers.
protected IModuleResource[] getMembers(IVirtualContainer cont, IPath path) throws CoreException {
IVirtualResource[] 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 IVirtualContainer) {
IVirtualContainer cc = (IVirtualContainer) res[j];
// Retrieve already existing module folder if applicable
ModuleFolder mf = (ModuleFolder) getExistingModuleResource(members, path.append(new Path(cc.getName()).makeRelative()));
if (mf == null) {
mf = new ModuleFolder((IContainer) cc.getUnderlyingResource(), cc.getName(), path);
ModuleFolder parent = (ModuleFolder) getExistingModuleResource(members, path);
if (path.isEmpty())
members.add(mf);
else {
if (parent == null)
parent = ensureParentExists(path, (IContainer) cc.getUnderlyingResource());
addMembersToModuleFolder(parent, new IModuleResource[] { mf });
}
}
IModuleResource[] mr = getMembers(cc, path.append(cc.getName()));
addMembersToModuleFolder(mf, mr);
} else {
IFile f = (IFile) res[j].getUnderlyingResource();
IModuleFile mf = null;
if (shouldAddComponentFile(f)) {
mf = createModuleFile(f, path);
list.add(mf);
}
}
}
IModuleResource[] mr = new IModuleResource[list.size()];
list.toArray(mr);
return mr;
}
Aggregations