use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishUtilTestCase method test05DeleteFiles.
public void test05DeleteFiles() throws Exception {
// Publish all resources except the "B" files and "B" folder and don't preserve them
IModuleResource[] resources = getModuleResources();
IModuleResource[] resources2 = getModuleResources2();
IModuleResource[] resources3 = new IModuleResource[2];
System.arraycopy(resources2, 0, resources3, 0, 2);
IPath dest = getDestination();
assertNotNull(dest);
IStatus[] result = PublishUtil.publishSmart(resources3, dest, null, null);
assertNotNull(result);
assertTrue(getResultMessage(result), result.length == 0);
IPath[] paths = getPreservePaths();
// Verify "A" files are unchanged and "B" files and "B" folder have been deleted
String contents = getContents(dest.append(resources[0].getModuleRelativePath()));
assertEquals("rootFileA contents", contents);
assertFalse(dest.append(paths[0]).toFile().exists());
IModuleFolder mf = (IModuleFolder) resources[2];
contents = getContents(dest.append(mf.members()[0].getModuleRelativePath()));
assertEquals("folderAFileA contents", contents);
assertFalse(dest.append(paths[1]).toFile().exists());
mf = (IModuleFolder) resources[3];
assertFalse(dest.append(mf.getModuleRelativePath()).toFile().exists());
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishUtilTestCase method test04PreserveFolder.
public void test04PreserveFolder() throws Exception {
// Create resource array including all resources except the "B" folder
IModuleResource[] resources = getModuleResources();
IModuleResource[] resources2 = new IModuleResource[3];
System.arraycopy(resources, 0, resources2, 0, 3);
IPath[] paths = new IPath[] { resources[3].getModuleRelativePath() };
// Publish all resources except the B folder and preserve just the "B" folder
IPath dest = getDestination();
assertNotNull(dest);
IStatus[] result = PublishUtil.publishSmart(resources2, dest, paths, null);
assertNotNull(result);
assertTrue(getResultMessage(result), result.length == 0);
// Verify non-"B" folder files are unchanged and "B" folder files have not been deleted
String contents = getContents(dest.append(resources[0].getModuleRelativePath()));
assertEquals("rootFileA contents", 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", 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", 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.servertools by eclipse.
the class PublishUtilTestCase method test00FullCopy.
public void test00FullCopy() throws Exception {
IProject project = getTestProject();
assertNotNull(project);
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 file contents following initial copy of all resources
String contents = getContents(dest.append(resources[0].getModuleRelativePath()));
assertEquals("rootFileA contents", contents);
contents = getContents(dest.append(resources[1].getModuleRelativePath()));
assertEquals("rootFileB contents", contents);
IModuleFolder mf = (IModuleFolder) resources[2];
contents = getContents(dest.append(mf.members()[0].getModuleRelativePath()));
assertEquals("folderAFileA contents", contents);
contents = getContents(dest.append(mf.members()[1].getModuleRelativePath()));
assertEquals("folderAFileB contents", contents);
mf = (IModuleFolder) resources[3];
contents = getContents(dest.append(mf.members()[0].getModuleRelativePath()));
assertEquals("folderBFileA contents", contents);
contents = getContents(dest.append(mf.members()[1].getModuleRelativePath()));
assertEquals("folderBFileB contents", contents);
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishHelper method publishDelta.
/**
* Handle a delta publish.
*
* @param delta a module resource delta
* @param path the path to publish to
* @param monitor a progress monitor, or <code>null</code> if progress
* reporting and cancellation are not desired
* @return a possibly-empty array of error and warning status
*/
public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor monitor) {
List<IStatus> status = new ArrayList<IStatus>(2);
IModuleResource resource = delta.getModuleResource();
int kind2 = delta.getKind();
if (resource instanceof IModuleFile) {
IModuleFile file = (IModuleFile) resource;
try {
if (kind2 == IModuleResourceDelta.REMOVED)
deleteFile(path, file);
else {
IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
File f = path2.toFile().getParentFile();
if (!f.exists())
f.mkdirs();
copyFile(file, path2);
}
} catch (CoreException ce) {
status.add(ce.getStatus());
}
IStatus[] stat = new IStatus[status.size()];
status.toArray(stat);
return stat;
}
if (kind2 == IModuleResourceDelta.ADDED) {
IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
File file = path2.toFile();
if (!file.exists() && !file.mkdirs()) {
status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, path2), null));
IStatus[] stat = new IStatus[status.size()];
status.toArray(stat);
return stat;
}
}
IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
int size = childDeltas.length;
for (int i = 0; i < size; i++) {
IStatus[] stat = publishDelta(childDeltas[i], path, monitor);
addArrayToList(status, stat);
}
if (kind2 == IModuleResourceDelta.REMOVED) {
IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
File file = path2.toFile();
if (file.exists() && !file.delete()) {
status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null));
}
}
IStatus[] stat = new IStatus[status.size()];
status.toArray(stat);
return stat;
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishHelper method addZipEntries.
private static void addZipEntries(ZipOutputStream zout, IModuleResource[] resources) throws Exception {
if (resources == null)
return;
int size = resources.length;
for (int i = 0; i < size; i++) {
if (resources[i] instanceof IModuleFolder) {
IModuleFolder mf = (IModuleFolder) resources[i];
IModuleResource[] res = mf.members();
IPath path = mf.getModuleRelativePath().append(mf.getName());
String entryPath = path.toPortableString();
if (!entryPath.endsWith("/"))
entryPath += '/';
ZipEntry ze = new ZipEntry(entryPath);
long ts = 0;
IContainer folder = (IContainer) mf.getAdapter(IContainer.class);
if (folder != null)
ts = folder.getLocalTimeStamp();
if (ts != IResource.NULL_STAMP && ts != 0)
ze.setTime(ts);
zout.putNextEntry(ze);
zout.closeEntry();
addZipEntries(zout, res);
continue;
}
IModuleFile mf = (IModuleFile) resources[i];
IPath path = mf.getModuleRelativePath().append(mf.getName());
ZipEntry ze = new ZipEntry(path.toPortableString());
InputStream in = null;
long ts = 0;
IFile file = (IFile) mf.getAdapter(IFile.class);
if (file != null) {
ts = file.getLocalTimeStamp();
in = file.getContents();
} else {
File file2 = (File) mf.getAdapter(File.class);
ts = file2.lastModified();
in = new FileInputStream(file2);
}
if (ts != IResource.NULL_STAMP && ts != 0)
ze.setTime(ts);
zout.putNextEntry(ze);
try {
int n = 0;
while (n > -1) {
n = in.read(buf);
if (n > 0)
zout.write(buf, 0, n);
}
} finally {
in.close();
}
zout.closeEntry();
}
}
Aggregations