use of org.eclipse.wst.server.core.model.IModuleResource in project liferay-ide by liferay.
the class PortalPublishTask method getTasks.
@SuppressWarnings("rawtypes")
public PublishOperation[] getTasks(IServer server, int kind, List modules, List kindList) {
List<BundlePublishOperation> tasks = new ArrayList<BundlePublishOperation>();
PortalServerBehavior serverBehavior = (PortalServerBehavior) server.loadAdapter(PortalServerBehavior.class, null);
if (ListUtil.isNotEmpty(modules)) {
final int size = modules.size();
for (int i = 0; i < size; i++) {
IModule[] module = (IModule[]) modules.get(i);
Integer deltaKind = (Integer) kindList.get(i);
boolean needClean = false;
IModuleResourceDelta[] deltas = ((Server) server).getPublishedResourceDelta(module);
for (IModuleResourceDelta delta : deltas) {
final IModuleResource resource = delta.getModuleResource();
final IFile resourceFile = (IFile) resource.getAdapter(IFile.class);
if (resourceFile != null && resourceFile.getName().equals("bnd.bnd")) {
needClean = true;
break;
}
}
switch(kind) {
case IServer.PUBLISH_FULL:
case IServer.PUBLISH_INCREMENTAL:
case IServer.PUBLISH_AUTO:
final IProject project = module[0].getProject();
switch(deltaKind) {
case ServerBehaviourDelegate.ADDED:
addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
break;
case ServerBehaviourDelegate.CHANGED:
if (needClean) {
addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
} else {
addOperation(BundlePublishFullAdd.class, tasks, server, module);
}
break;
case ServerBehaviourDelegate.REMOVED:
addOperation(BundlePublishFullRemove.class, tasks, server, module);
break;
case ServerBehaviourDelegate.NO_CHANGE:
final IBundleProject bundleProject = LiferayCore.create(IBundleProject.class, project);
if (bundleProject != null) {
try {
if (isUserRedeploy(serverBehavior, module[0]) || !isDeployed(server, serverBehavior, bundleProject.getSymbolicName())) {
addOperation(BundlePublishFullAddCleanBuild.class, tasks, server, module);
}
} catch (CoreException e) {
LiferayServerCore.logError("Unable to get bsn for project " + project.getName(), e);
}
}
break;
default:
break;
}
break;
default:
break;
}
}
}
return tasks.toArray(new PublishOperation[0]);
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class AbstractModuleAssembler method doPackModule.
private void doPackModule(IModuleResource resource, ModulePackager packager) throws CoreException, IOException {
if (resource instanceof IModuleFolder) {
IModuleFolder mFolder = (IModuleFolder) resource;
IModuleResource[] resources = mFolder.members();
packager.writeFolder(resource.getModuleRelativePath().append(resource.getName()).toPortableString());
for (int i = 0; resources != null && i < resources.length; i++) {
doPackModule(resources[i], packager);
}
} else {
String destination = resource.getModuleRelativePath().append(resource.getName()).toPortableString();
IFile file = (IFile) resource.getAdapter(IFile.class);
if (file != null)
packager.write(file, destination);
else {
File file2 = (File) resource.getAdapter(File.class);
packager.write(file2, destination);
}
}
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class EarModuleAssembler method assemble.
public IPath assemble(IProgressMonitor monitor) throws CoreException {
// copy ear root to the temporary assembly directory
IPath parent = fAssembleRoot;
final IModule[] rootMod = { fModule };
boolean shouldCopy = (IServer.PUBLISH_STATE_NONE != fServer.getServer().getModulePublishState(rootMod));
if (shouldCopy)
copyModule(fModule, monitor);
IEnterpriseApplication earModule = (IEnterpriseApplication) fModule.loadAdapter(IEnterpriseApplication.class, monitor);
IModule[] childModules = earModule.getModules();
for (int i = 0; i < childModules.length; i++) {
IModule module = childModules[i];
String uri = earModule.getURI(module);
if (uri == null) {
// The bad memories of WTP 1.0
// $NON-NLS-1$
IStatus status = new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, "unable to assemble module null uri", null);
throw new CoreException(status);
}
IJ2EEModule jeeModule = (IJ2EEModule) module.loadAdapter(IJ2EEModule.class, monitor);
if (jeeModule != null && jeeModule.isBinary()) {
// Binary module
// just copy
ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
IModuleResource[] resources = pm.members();
publishHelper.publishToPath(resources, parent.append(uri), monitor);
// done! no need to go further
continue;
}
if (shouldRepack(module)) {
packModule(module, uri, parent);
}
}
return parent;
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishHelper method publishSmart.
/**
* Smart copy the given module resources to the given path.
*
* @param resources an array of module resources
* @param path an external path to copy to
* @param ignore an array of paths relative to path to ignore, i.e. not delete or copy over
* @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[] publishSmart(IModuleResource[] resources, IPath path, IPath[] ignore, IProgressMonitor monitor) {
if (resources == null)
return EMPTY_STATUS;
monitor = ProgressUtil.getMonitorFor(monitor);
List<IStatus> status = new ArrayList<IStatus>(2);
File toDir = path.toFile();
int fromSize = resources.length;
String[] fromFileNames = new String[fromSize];
for (int i = 0; i < fromSize; i++) fromFileNames[i] = resources[i].getName();
List<String> ignoreFileNames = new ArrayList<String>();
if (ignore != null) {
for (int i = 0; i < ignore.length; i++) {
if (ignore[i].segmentCount() == 1) {
ignoreFileNames.add(ignore[i].toOSString());
}
}
}
// cache files and file names for performance
File[] toFiles = null;
String[] toFileNames = null;
boolean foundExistingDir = false;
if (toDir.exists()) {
if (toDir.isDirectory()) {
foundExistingDir = true;
toFiles = toDir.listFiles();
int toSize = toFiles.length;
toFileNames = new String[toSize];
// check if this exact file exists in the new directory
for (int i = 0; i < toSize; i++) {
toFileNames[i] = toFiles[i].getName();
boolean isDir = toFiles[i].isDirectory();
boolean found = false;
for (int j = 0; j < fromSize; j++) {
if (toFileNames[i].equals(fromFileNames[j]) && isDir == resources[j] instanceof IModuleFolder) {
found = true;
break;
}
}
// delete file if it can't be found or isn't the correct type
if (!found) {
boolean delete = true;
// if should be preserved, don't delete and don't try to copy
for (String preserveFileName : ignoreFileNames) {
if (toFileNames[i].equals(preserveFileName)) {
delete = false;
break;
}
}
if (delete) {
if (isDir) {
IStatus[] stat = deleteDirectory(toFiles[i], null);
addArrayToList(status, stat);
} else {
if (!toFiles[i].delete())
status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, toFiles[i].getAbsolutePath()), null));
}
}
toFiles[i] = null;
toFileNames[i] = null;
}
}
} else {
// if (toDir.isFile())
if (!toDir.delete()) {
status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, toDir.getAbsolutePath()), null));
IStatus[] stat = new IStatus[status.size()];
status.toArray(stat);
return stat;
}
}
}
if (!foundExistingDir && !toDir.mkdirs()) {
status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, toDir.getAbsolutePath()), null));
IStatus[] stat = new IStatus[status.size()];
status.toArray(stat);
return stat;
}
if (monitor.isCanceled())
return new IStatus[] { Status.CANCEL_STATUS };
monitor.worked(50);
// or is newer
if (toFiles == null) {
toFiles = toDir.listFiles();
if (toFiles == null)
toFiles = new File[0];
}
int toSize = toFiles.length;
int dw = 0;
if (toSize > 0)
dw = 500 / toSize;
// cache file names and last modified dates for performance
if (toFileNames == null)
toFileNames = new String[toSize];
long[] toFileMod = new long[toSize];
for (int i = 0; i < toSize; i++) {
if (toFiles[i] != null) {
if (toFileNames[i] != null)
toFileNames[i] = toFiles[i].getName();
toFileMod[i] = toFiles[i].lastModified();
}
}
for (int i = 0; i < fromSize; i++) {
IModuleResource current = resources[i];
String name = fromFileNames[i];
boolean currentIsDir = current instanceof IModuleFolder;
if (!currentIsDir) {
// check if this is a new or newer file
boolean copy = true;
IModuleFile mf = (IModuleFile) current;
long mod = -1;
IFile file = (IFile) mf.getAdapter(IFile.class);
if (file != null) {
mod = file.getLocalTimeStamp();
} else {
File file2 = (File) mf.getAdapter(File.class);
mod = file2.lastModified();
}
for (int j = 0; j < toSize; j++) {
if (name.equals(toFileNames[j]) && mod == toFileMod[j]) {
copy = false;
break;
}
}
if (copy) {
try {
copyFile(mf, path.append(name));
} catch (CoreException ce) {
status.add(ce.getStatus());
}
}
monitor.worked(dw);
} else {
// if (currentIsDir) {
IModuleFolder folder = (IModuleFolder) current;
IModuleResource[] children = folder.members();
// build array of ignored Paths that apply to this folder
IPath[] ignoreChildren = null;
if (ignore != null) {
List<IPath> ignoreChildPaths = new ArrayList<IPath>();
for (int j = 0; j < ignore.length; j++) {
IPath preservePath = ignore[j];
if (preservePath.segment(0).equals(name)) {
ignoreChildPaths.add(preservePath.removeFirstSegments(1));
}
}
if (ignoreChildPaths.size() > 0)
ignoreChildren = ignoreChildPaths.toArray(new Path[ignoreChildPaths.size()]);
}
monitor.subTask(NLS.bind(Messages.copyingTask, new String[] { name, name }));
IStatus[] stat = publishSmart(children, path.append(name), ignoreChildren, ProgressUtil.getSubMonitorFor(monitor, dw));
addArrayToList(status, stat);
}
}
if (monitor.isCanceled())
return new IStatus[] { Status.CANCEL_STATUS };
monitor.worked(500 - dw * toSize);
monitor.done();
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 AbstractTomcatServerTestCase method verifyPublishedModuleFolder.
protected void verifyPublishedModuleFolder(File moduleDir, IModuleFolder mf) throws Exception {
IModuleResource[] resources = mf.members();
for (int i = 0; i < resources.length; i++) {
if (resources[i] instanceof IModuleFolder) {
verifyPublishedModuleFolder(moduleDir, (IModuleFolder) resources[i]);
} else {
String path = resources[i].getModuleRelativePath().append(resources[i].getName()).toOSString();
File file = new File(moduleDir, path);
assertTrue("Module file/folder doesn't exist: " + file.getPath(), file.exists());
}
}
}
Aggregations