use of org.eclipse.wst.server.core.model.IModuleFolder 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.IModuleFolder 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.IModuleFolder in project webtools.servertools by eclipse.
the class PublishHelper method copy.
private IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return new IStatus[0];
}
String name = resource.getName();
if (Trace.PUBLISHING) {
Trace.trace(Trace.STRING_PUBLISHING, "Copying: " + name + " to " + path.toString());
}
List<IStatus> status = new ArrayList<IStatus>(2);
if (resource instanceof IModuleFolder) {
IModuleFolder folder = (IModuleFolder) resource;
IStatus[] stat = publishFull(folder.members(), path, monitor);
addArrayToList(status, stat);
} else {
IModuleFile mf = (IModuleFile) resource;
path = path.append(mf.getModuleRelativePath()).append(name);
File f = path.toFile().getParentFile();
if (f.exists()) {
try {
copyFile(mf, path);
} catch (CoreException ce) {
status.add(ce.getStatus());
}
} else {
// Create the parent directory.
if (f.mkdirs()) {
try {
copyFile(mf, path);
} catch (CoreException ce) {
status.add(ce.getStatus());
}
} else {
if (Trace.PUBLISHING) {
Trace.trace(Trace.STRING_PUBLISHING, "Failed to create the directory: " + f.getAbsolutePath());
}
status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, f.getAbsolutePath()), null));
}
}
}
IStatus[] stat = new IStatus[status.size()];
status.toArray(stat);
return stat;
}
use of org.eclipse.wst.server.core.model.IModuleFolder 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();
}
}
use of org.eclipse.wst.server.core.model.IModuleFolder in project webtools.servertools by eclipse.
the class ModulePublishInfo method saveResource.
protected void saveResource(DataOutput out, IModuleResource[] resources2) throws IOException {
if (resources2 == null)
return;
int size = resources2.length;
out.writeInt(size);
for (int i = 0; i < size; i++) {
if (resources2[i] instanceof IModuleFile) {
IModuleFile file = (IModuleFile) resources2[i];
out.writeByte(0);
out.writeUTF(file.getName());
out.writeLong(file.getModificationStamp());
} else {
IModuleFolder folder = (IModuleFolder) resources2[i];
out.writeByte(1);
out.writeUTF(folder.getName());
IModuleResource[] resources3 = folder.members();
saveResource(out, resources3);
}
}
}
Aggregations