use of org.eclipse.wst.server.core.model.IModuleFile 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.IModuleFile in project webtools.servertools by eclipse.
the class PublishHelper method copyFile.
private void copyFile(IModuleFile mf, IPath path) throws CoreException {
if (Trace.PUBLISHING) {
Trace.trace(Trace.STRING_PUBLISHING, "Copying: " + mf.getName() + " to " + path.toString());
}
if (!isCopyFile(mf, path)) {
return;
}
IFile file = (IFile) mf.getAdapter(IFile.class);
if (file != null)
copyFile(file.getContents(), path, file.getLocalTimeStamp(), mf);
else {
File file2 = (File) mf.getAdapter(File.class);
InputStream in = null;
try {
in = new FileInputStream(file2);
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorReading, file2.getAbsolutePath()), e));
}
copyFile(in, path, file2.lastModified(), mf);
}
}
use of org.eclipse.wst.server.core.model.IModuleFile 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.IModuleFile 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.IModuleFile 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