Author: rob.stryker(a)jboss.com
Date: 2007-08-24 22:44:34 -0400 (Fri, 24 Aug 2007)
New Revision: 3331
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/NestedPublishInfo.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/ModulePackager.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
Log:
JBIDE-674
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java 2007-08-25
00:53:28 UTC (rev 3330)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java 2007-08-25
02:44:34 UTC (rev 3331)
@@ -1,55 +0,0 @@
-package org.jboss.ide.eclipse.as.core.packages;
-
-import java.util.HashMap;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.QualifiedName;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-
-
-public class ProjectArchiveStorer {
- public static final String JST_ARCHIVE_CONFIGURATION =
"jst.archive.configuration";
- private static HashMap cache = new HashMap();
-
- public static IArchive getArchiveFor(IProject project) {
- if( cache.containsKey(project))
- return (IArchive)cache.get(project);
- return loadArchiveFrom(project);
- }
-
- public static IArchive loadArchiveFrom(IProject project) {
- try {
- String s = project.getPersistentProperty(new
QualifiedName(JBossServerCorePlugin.PLUGIN_ID, JST_ARCHIVE_CONFIGURATION));
- if( s != null ) {
- XbPackages packs = XMLBinding.unmarshal(s, new NullProgressMonitor());
- if( packs != null && packs.getAllChildren().size() == 1 ) {
- XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
- IArchive node =
(IArchive)ArchivesModel.instance().createPackageNodeImpl(project.getLocation(), pack,
null);
- if( node != null ) {
- cache.put(project, node);
- }
- }
- }
- } catch( CoreException ce ) {
- ce.printStackTrace();
- }
- return (IArchive)cache.get(project);
- }
-
- public static void storeArchive(IProject project, IArchive archive) {
- try {
- String s = XMLBinding.marshall(archive, new NullProgressMonitor());
- if( s != null )
- project.setPersistentProperty(new QualifiedName(JBossServerCorePlugin.PLUGIN_ID,
JST_ARCHIVE_CONFIGURATION), s);
- } catch( CoreException ce) {
- ce.printStackTrace();
- }
- }
-}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2007-08-25
00:53:28 UTC (rev 3330)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2007-08-25
02:44:34 UTC (rev 3331)
@@ -4,7 +4,7 @@
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
-* This is free software; you can redistribute it and/or modify it
+ * This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
@@ -21,195 +21,277 @@
*/
package org.jboss.ide.eclipse.as.core.publishers;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.TreeSet;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jst.server.core.IEnterpriseApplication;
+import org.eclipse.jst.server.core.IWebModule;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.internal.ModuleFile;
+import org.eclipse.wst.server.core.internal.Server;
+import org.eclipse.wst.server.core.model.IModuleFolder;
import org.eclipse.wst.server.core.model.IModuleResource;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+import org.eclipse.wst.server.core.model.ModuleDelegate;
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
-import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import org.eclipse.wst.server.core.util.ProjectModule;
+import org.eclipse.wst.server.core.util.PublishUtil;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.model.EventLogModel;
import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
-import org.jboss.ide.eclipse.as.core.packages.ModulePackageTypeConverter;
-import org.jboss.ide.eclipse.as.core.packages.ProjectArchiveStorer;
-import org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger.PublishEvent;
-import
org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger.PublisherFileUtilListener;
+import org.jboss.ide.eclipse.as.core.server.NestedPublishInfo;
+import org.jboss.ide.eclipse.as.core.server.NestedPublishInfo.OpenedModulePublishInfo;
import org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.xpl.ModulePackager;
import org.jboss.ide.eclipse.as.core.util.FileUtil;
/**
- * This class provides a default implementation for
- * packaging different types of flexible projects. It uses
- * the built-in heirarchy of the projects to do so.
- *
+ * This class provides a default implementation for packaging different types of
+ * flexible projects. It uses the built-in heirarchy of the projects to do so.
+ *
* @author rob.stryker(a)jboss.com
*/
public class JstPublisher extends PackagesPublisher {
-
- private static HashMap moduleToArchiveMap = new HashMap();
-
+
public static final int BUILD_FAILED_CODE = 100;
public static final int PACKAGE_UNDETERMINED_CODE = 101;
-
+
protected IModuleResourceDelta[] delta;
public JstPublisher(IServer server, EventLogTreeItem context) {
super(server, context);
}
-
public void setDelta(IModuleResourceDelta[] delta) {
this.delta = delta;
}
- public IStatus publishModule(int kind, int deltaKind, int modulePublishState,
- IModule module, IProgressMonitor monitor) throws CoreException {
+ public IStatus publishModule(int kind, int deltaKind,
+ int modulePublishState, IModule module, IProgressMonitor monitor)
+ throws CoreException {
IStatus status = null;
- if(ServerBehaviourDelegate.REMOVED == deltaKind){
- status = unpublish(server, module, kind, deltaKind, modulePublishState,
monitor);
- } else if( ServerBehaviourDelegate.NO_CHANGE != deltaKind || kind ==
IServer.PUBLISH_FULL || kind == IServer.PUBLISH_CLEAN ){
- // if there's no change, do nothing. Otherwise, on change or add,
re-publish
- status = publish(server, module, kind, deltaKind, modulePublishState, monitor);
- } else if( ServerBehaviourDelegate.NO_CHANGE != deltaKind && kind ==
IServer.PUBLISH_INCREMENTAL ){
- status = publish(server, module, kind, deltaKind, modulePublishState, monitor);
- }
+
+ IPath root = new Path(server.getDeployDirectory());
+ if (ServerBehaviourDelegate.REMOVED == deltaKind) {
+ status = unpublish(server, module, monitor);
+ } else if (kind == IServer.PUBLISH_FULL || kind == IServer.PUBLISH_CLEAN) {
+ status = fullPublishPackIntoFolder(module, root, monitor);
+ } else if (kind == IServer.PUBLISH_INCREMENTAL) {
+ status = incrementalPublish(new ArrayList(), root, module, monitor);
+ }
return status;
}
-
- protected IStatus publish(IDeployableServer jbServer, IModule module, int kind,
- int deltaKind, int modulePublishState, IProgressMonitor monitor) throws
CoreException {
- PublishEvent event = PublisherEventLogger.createSingleModuleTopEvent(eventRoot, module,
kind, deltaKind);
- EventLogModel.markChanged(eventRoot);
- boolean incremental = shouldPublishIncremental(module, kind, deltaKind,
modulePublishState);
-
- IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), monitor);
-
- if( topLevel != null ) {
- try {
- if( !incremental )
- new ArchiveBuildDelegate().fullArchiveBuild(topLevel);
- else {
- Set addedChanged = createDefaultTreeSet();
- Set removed = createDefaultTreeSet();
- fillDelta(delta, addedChanged, removed);
- new ArchiveBuildDelegate().incrementalBuild(topLevel, addedChanged, removed);
- }
- } catch( Exception e ) {
- return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, BUILD_FAILED_CODE,
"", e);
+ protected void fullWebPublish(IModule module, IPath root, IProgressMonitor monitor )
throws CoreException {
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, monitor);
+ IModuleResource[] members = md.members();
+ IWebModule webmodule = (IWebModule)module.loadAdapter(IWebModule.class, monitor);
+ IPath moduleDeployPath = root.append(webmodule.getContextRoot() + ".war");
+ FileUtil.safeDelete(moduleDeployPath.toFile());
+ PublishUtil.publishSmart(members, moduleDeployPath, monitor);
+ IWebModule webModule = (IWebModule)module.loadAdapter(IWebModule.class, monitor);
+ IModule[] childModules = webModule.getModules();
+ for (int i = 0; i < childModules.length; i++) {
+ IModule module2 = childModules[i];
+ packModuleIntoJar(module, webModule.getURI(module2), moduleDeployPath);
+ }
+ }
+ protected void fullEarPublish(IModule module, IPath root, IProgressMonitor monitor)
throws CoreException {
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, monitor);
+ IModuleResource[] members = md.members();
+ IEnterpriseApplication earModule =
(IEnterpriseApplication)module.loadAdapter(IEnterpriseApplication.class, monitor);
+ IPath moduleDeployPath = root.append(module.getProject().getName() +
".ear");
+ FileUtil.safeDelete(moduleDeployPath.toFile());
+ PublishUtil.publishSmart(members, moduleDeployPath, monitor);
+ IModule[] childModules = earModule.getModules();
+ for (int i = 0; i < childModules.length; i++) {
+ IModule module2 = childModules[i];
+ String uri = earModule.getURI(module2);
+ if(uri==null){
+ IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
0, "unable to assemble module null uri",null ); //$NON-NLS-1$
+ throw new CoreException(status);
}
+ if( module2.getModuleType().getId().equals("jst.utility")) {
+ packModuleIntoJar(module2, uri, moduleDeployPath);
+ } else {
+ fullPublishPackIntoFolder(module2, moduleDeployPath, monitor);
+ }
+ }
+ }
+
+ protected IStatus fullPublishPackIntoFolder(IModule module, IPath root, IProgressMonitor
monitor) throws CoreException {
+ if( module.getModuleType().getId().equals("jst.web")) {
+ fullWebPublish(module, root, monitor);
+ } else if( module.getModuleType().getId().equals("jst.ear")) {
+ fullEarPublish(module, root, monitor);
} else {
- return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
PACKAGE_UNDETERMINED_CODE, "", null);
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class,
monitor);
+ IModuleResource[] members = md.members();
+ IPath moduleDeployPath = root.append(module.getProject().getName() +
".jar");
+ FileUtil.safeDelete(moduleDeployPath.toFile());
+ PublishUtil.publishSmart(members, moduleDeployPath, monitor);
}
- return new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IStatus.OK,
"", null);
+ return null;
}
- protected IStatus unpublish(IDeployableServer jbServer, IModule module,
- int kind, int deltaKind, int modulePublishKind, IProgressMonitor monitor) throws
CoreException {
- PublishEvent event = PublisherEventLogger.createSingleModuleTopEvent(eventRoot, module,
kind, deltaKind);
-
- IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), monitor);
- if( topLevel != null ) {
- IPath path = topLevel.getArchiveFilePath();
- FileUtil.safeDelete(path.toFile(), new PublisherFileUtilListener(event));
- } else if( module.getProject() == null ){
- // this is a problem. All I know is the module name, aka project name. Not it's
suffix on the server.
+ private boolean hasDelta( IModule module, ArrayList moduleTree ) {
+ return getDelta(module, moduleTree).length > 0;
+ }
+
+ public IModuleResourceDelta[] getDelta(IModule module, ArrayList moduleTree) {
+ IModuleResourceDelta[] deltas;
+ if( moduleTree.size() == 0 ) {
+ final IModule[] modules ={module};
+ deltas = ((Server)server.getServer()).getPublishedResourceDelta( modules );
} else {
- return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
PACKAGE_UNDETERMINED_CODE, "", null);
+ deltas =
NestedPublishInfo.getDefault().getServerPublishInfo(server.getServer()).getDelta(moduleTree,
module);
}
- return new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IStatus.OK,
"", null);
+ return deltas;
}
-
- protected IArchive getTopPackage(IModule module, String deployDir, IProgressMonitor
monitor) {
- if( moduleToArchiveMap.containsKey(module.getId())) {
- return (IArchive)moduleToArchiveMap.get(module.getId());
+
+ protected void packModuleIntoJar(IModule module, String deploymentUnitName, IPath
destination)throws CoreException {
+ String dest = destination.append(deploymentUnitName).toString();
+ ModulePackager packager = null;
+ try {
+ packager = new ModulePackager(dest, false);
+ ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
+ IModuleResource[] resources = pm.members();
+ for (int i = 0; i < resources.length; i++) {
+ doPackModule(resources[i], packager);
+ }
+ } catch (IOException e) {
+ IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, 0,
+ "unable to assemble module", e); //$NON-NLS-1$
+ throw new CoreException(status);
}
-
- IProject project = module.getProject();
- IArchive top = ProjectArchiveStorer.getArchiveFor(project);
- if( top == null ) {
- top = createTopPackage(module, deployDir, monitor);
- if( top != null ) {
- ProjectArchiveStorer.storeArchive(project, top);
- moduleToArchiveMap.put(module.getId(), top);
+ finally{
+ try{
+ packager.finished();
}
+ catch(IOException e){
+ //unhandled
+ }
}
- return top;
}
+
- protected IArchive createTopPackage(IModule module, String deployDir, IProgressMonitor
monitor) {
- IArchiveType type = ModulePackageTypeConverter.getPackageTypeFor(module);
- if( type != null && module.getProject() != null ) {
- IArchive topLevel = type.createDefaultConfiguration(module.getProject().getName(),
monitor);
- topLevel.setDestinationPath(new Path(deployDir));
- topLevel.setInWorkspace(false);
- topLevel.setExploded(true);
- return topLevel;
- }
- return null;
+ /* Add one file or folder to a jar */
+ 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);
+ }
+ }
}
- protected void fillDelta(IModuleResourceDelta[] delta, Set addedChanged, Set removed) {
- for( int i = 0; i < delta.length; i++ ) {
- fillDelta(delta[i], addedChanged, removed);
+
+ protected IStatus incrementalPublish(ArrayList moduleTree, IPath root, IModule module,
IProgressMonitor monitor) throws CoreException {
+ if( module.getModuleType().getId().equals("jst.web")) {
+ incrementalWarPublish(moduleTree, module, root, monitor);
+ } else if( module.getModuleType().getId().equals("jst.ear")) {
+ incrementalEarPublish(moduleTree, module, root, monitor);
+ } else {
+ // cannot incrementally publish something unknown
+ // just package it
+ packModuleIntoJar(module, "blah" + module.getName().hashCode() +
".jar", root);
}
+ return new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID,
+ IStatus.OK, "", null);
}
- protected void fillDelta(IModuleResourceDelta delta, Set addedChanged, Set removed) {
- IModuleResourceDelta[] children = delta.getAffectedChildren();
- if( children != null ) {
- for( int i = 0; i < children.length; i++ ) {
- fillDelta(children[i], addedChanged, removed);
- }
+
+ protected void incrementalWarPublish(ArrayList moduleTree, IModule module, IPath root,
IProgressMonitor monitor) throws CoreException {
+ ArrayList newTree = new ArrayList();
+ newTree.addAll(moduleTree); newTree.add(module);
+
+ IModule[] modules = new IModule[] {module};
+ IModuleResourceDelta[] deltas = getDelta(module, moduleTree);
+ //((Server)server.getServer()).getPublishedResourceDelta( modules );
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, monitor);
+ IModuleResource[] members = md.members();
+ IWebModule webmodule = (IWebModule)module.loadAdapter(IWebModule.class, monitor);
+ IPath moduleDeployPath = root.append(webmodule.getContextRoot() + ".war");
+ PublishUtil.publishDelta(deltas, moduleDeployPath, monitor);
+ IWebModule webModule = (IWebModule)module.loadAdapter(IWebModule.class, monitor);
+ IModule[] childModules = webModule.getModules();
+ for (int i = 0; i < childModules.length; i++) {
+ IModule module2 = childModules[i];
+ // if a lib .jar needs to be repacked, repack the whole thing
+ if( hasDelta(module2, newTree))
+ packModuleIntoJar(module, webModule.getURI(module2), moduleDeployPath);
}
- handleResource(delta.getKind(), delta.getModuleResource(), addedChanged, removed);
+ if( moduleTree.size() > 0 ) {
+ // published it
+ NestedPublishInfo.getDefault().getServerPublishInfo(server.getServer()).getPublishInfo(moduleTree,
module).setResources(md.members());
+ }
}
- protected void handleResource(int kind, IModuleResource resource, Set addedChanged, Set
removed) {
- if( resource instanceof ModuleFile ) {
- ModuleFile mf = (ModuleFile)resource;
- IFile f = (IFile)resource.getAdapter(IFile.class);
- IPath p = null;
- if( f == null ) {
- IFile ifile = (IFile)resource.getAdapter(IFile.class);
- if( ifile != null )
- p = ifile.getLocation();
- } else {
- p = f.getLocation();
+ protected void incrementalEarPublish(ArrayList moduleTree, IModule module, IPath root,
IProgressMonitor monitor) throws CoreException {
+ ArrayList newTree = new ArrayList();
+ newTree.addAll(moduleTree);
+ newTree.add(module);
+
+ IModuleResourceDelta[] deltas = getDelta(module, moduleTree);
+ //((Server)server.getServer()).getPublishedResourceDelta( modules );
+ IEnterpriseApplication earModule =
(IEnterpriseApplication)module.loadAdapter(IEnterpriseApplication.class, monitor);
+ IPath moduleDeployPath = root.append(module.getProject().getName() +
".ear");
+ PublishUtil.publishDelta(deltas, moduleDeployPath, monitor);
+ IModule[] childModules = earModule.getModules();
+ for (int i = 0; i < childModules.length; i++) {
+ IModule childModule = childModules[i];
+ String uri = earModule.getURI(childModule);
+ if(uri==null){
+ IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
0, "unable to assemble module null uri",null ); //$NON-NLS-1$
+ throw new CoreException(status);
}
- if( p != null ) {
- if( kind == IModuleResourceDelta.ADDED || kind == IModuleResourceDelta.CHANGED) {
- addedChanged.add(p);
- } else if( kind == IModuleResourceDelta.REMOVED) {
- removed.add(p);
- }
- }
+ incrementalPublish(newTree, root, childModule, monitor);
}
+
}
- protected TreeSet createDefaultTreeSet() {
- return new TreeSet(new Comparator () {
- public int compare(Object o1, Object o2) {
- if (o1.equals(o2)) return 0;
- else return -1;
- }
- });
+
+ protected IStatus unpublish(IDeployableServer jbServer, IModule module,
+ IProgressMonitor monitor) throws CoreException {
+
+ IPath root = new Path(jbServer.getDeployDirectory());
+ if( module.getModuleType().getId().equals("jst.web")) {
+ // copy the module first
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class,
monitor);
+ IModuleResource[] members = md.members();
+ IWebModule webmodule = (IWebModule)module.loadAdapter(IWebModule.class, monitor);
+ IPath moduleDeployPath = root.append(webmodule.getContextRoot() + ".war");
+ FileUtil.completeDelete(moduleDeployPath.toFile());
+ } else if( module.getModuleType().getId().equals("jst.ear")) {
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class,
monitor);
+ IModuleResource[] members = md.members();
+ IEnterpriseApplication earModule =
(IEnterpriseApplication)module.loadAdapter(IEnterpriseApplication.class, monitor);
+ IPath moduleDeployPath = root.append(module.getProject().getName() +
".ear");
+ FileUtil.completeDelete(moduleDeployPath.toFile());
+ }
+
+ return new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID,
+ IStatus.OK, "", null);
}
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/NestedPublishInfo.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/NestedPublishInfo.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/NestedPublishInfo.java 2007-08-25
02:44:34 UTC (rev 3331)
@@ -0,0 +1,99 @@
+package org.jboss.ide.eclipse.as.core.server;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleType;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.internal.ModulePublishInfo;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+
+
+
+public class NestedPublishInfo {
+ public static final String PUBLISH_INFO = "publishInfo";
+ public static final String INDEX = "index.properties";
+ private static NestedPublishInfo instance;
+
+
+ public static NestedPublishInfo getDefault() {
+ if( instance == null ) {
+ instance = new NestedPublishInfo();
+ }
+ return instance;
+ }
+
+ HashMap idToSPI;
+ protected NestedPublishInfo() {
+ idToSPI = new HashMap();
+ }
+
+ public NestedServerPublishInfo getServerPublishInfo(IServer server) {
+ if( idToSPI.get(server.getId()) == null ) {
+ idToSPI.put(server.getId(), new NestedServerPublishInfo());
+ }
+ return (NestedServerPublishInfo)idToSPI.get(server.getId());
+ }
+
+ public static class NestedServerPublishInfo {
+
+ private HashMap<String, OpenedModulePublishInfo> idToModulePublishInfo;
+ public NestedServerPublishInfo() {
+ idToModulePublishInfo = new HashMap<String, OpenedModulePublishInfo>();
+ }
+
+ public ModulePublishInfo getPublishInfo(ArrayList ids, IModule module) {
+ String id = getId(ids);
+ ModulePublishInfo ret = idToModulePublishInfo.get(id);
+ if( ret == null ) {
+ ret = new OpenedModulePublishInfo(id, module.getName(), module.getModuleType());
+ idToModulePublishInfo.put(id, (OpenedModulePublishInfo) ret);
+ }
+ return ret;
+ }
+
+ // Takes a list of the nesting pattern for the modules
+ // followed by the desired module (which can share its current resources)
+ public IModuleResourceDelta[] getDelta(ArrayList ids, IModule module) {
+ return ((OpenedModulePublishInfo)getPublishInfo(ids, module)).getDelta(new
IModule[]{module});
+ }
+
+ protected String getId(ArrayList ids) {
+ String result = "";
+ Iterator i = ids.iterator();
+ while(i.hasNext()) {
+ result += i.next().hashCode() + "" + Path.SEPARATOR;
+ }
+ return result;
+ }
+ }
+
+ public static class OpenedModulePublishInfo extends ModulePublishInfo {
+
+ public OpenedModulePublishInfo(DataInput in) throws IOException {
+ super(in);
+ }
+
+ public OpenedModulePublishInfo(String moduleId, String name, IModuleType moduleType) {
+ super(moduleId, name, moduleType);
+ }
+
+ public IModuleResourceDelta[] getDelta(IModule[] module) {
+ return super.getDelta(module);
+ }
+
+ public void load(DataInput in) throws IOException {
+ super.load(in);
+ }
+
+ public void save(DataOutput out) {
+ super.save(out);
+ }
+ }
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/ModulePackager.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/ModulePackager.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/ModulePackager.java 2007-08-25
02:44:34 UTC (rev 3331)
@@ -0,0 +1,218 @@
+/***************************************************************************************************
+* Copyright (c) 2005 Eteration A.S. and Gorkem Ercan. All rights reserved. This program
and the
+* accompanying materials are made available under the terms of the Eclipse Public License
v1.0
+* which accompanies this distribution, and is available at
+*
http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors: Gorkem Ercan - initial API and implementation
+*
+**************************************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.xpl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarOutputStream;
+import java.util.zip.CRC32;
+import java.util.zip.ZipEntry;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Packages resources to a .zip file
+ */
+public class ModulePackager {
+ private static final String JAR_FILE_SEPERATOR = "/"; //$NON-NLS-1$
+ private JarOutputStream outputStream;
+// private StringBuffer manifestContents;
+
+ private boolean useCompression = true;
+
+ /**
+ * Create an instance of this class.
+ *
+ * @param filename java.lang.String
+ * @param compress boolean
+ * @exception java.io.IOException
+ */
+ public ModulePackager(String filename, boolean compress) throws IOException {
+ Path directoryPath = new Path(filename);
+ directoryPath = (Path) directoryPath.removeLastSegments(1);
+ File newZipFile = new File(directoryPath.toString());
+ newZipFile.mkdirs();
+ outputStream = new JarOutputStream(new FileOutputStream(filename));
+ useCompression = compress;
+ }
+
+ /**
+ * Do all required cleanup now that we're finished with the currently-open .zip
+ *
+ * @exception java.io.IOException
+ */
+ public void finished() throws IOException {
+ outputStream.close();
+ }
+
+ /**
+ * Create a new ZipEntry with the passed pathname and contents, and write it to the
current
+ * archive
+ *
+ * @param pathname
+ * java.lang.String
+ * @param contents
+ * byte[]
+ * @exception java.io.IOException
+ */
+ protected void write(String pathname, byte[] contents) throws IOException {
+ ZipEntry newEntry = new ZipEntry(pathname);
+
+ // if the contents are being compressed then we get the below for free.
+ if (!useCompression) {
+ newEntry.setMethod(ZipEntry.STORED);
+ newEntry.setSize(contents.length);
+ CRC32 checksumCalculator = new CRC32();
+ checksumCalculator.update(contents);
+ newEntry.setCrc(checksumCalculator.getValue());
+ }
+
+ outputStream.putNextEntry(newEntry);
+ outputStream.write(contents);
+ outputStream.closeEntry();
+ }
+
+ /**
+ * @param destinationPath
+ * @throws IOException
+ */
+ public void writeFolder(String destinationPath) throws IOException {
+ if (!destinationPath.endsWith(JAR_FILE_SEPERATOR ))
+ destinationPath = destinationPath + JAR_FILE_SEPERATOR;
+ ZipEntry newEntry = new ZipEntry(destinationPath);
+ outputStream.putNextEntry(newEntry);
+ outputStream.closeEntry();
+ }
+
+ /**
+ * Write the passed resource to the current archive
+ *
+ * @param resource
+ * org.eclipse.core.resources.IFile
+ * @param destinationPath
+ * java.lang.String
+ * @exception java.io.IOException
+ * @exception org.eclipse.core.runtime.CoreException
+ */
+ public void write(IFile resource, String destinationPath) throws IOException,
CoreException {
+ InputStream contentStream = null;
+ try {
+ contentStream = resource.getContents(false);
+ write(contentStream, destinationPath);
+ } finally {
+ if (contentStream != null)
+ contentStream.close();
+ }
+ }
+
+ /**
+ * Write the passed resource to the current archive
+ *
+ * @param resource
+ * java.io.IFile
+ * @param destinationPath
+ * java.lang.String
+ * @exception java.io.IOException
+ * @exception org.eclipse.core.runtime.CoreException
+ */
+ public void write(File resource, String destinationPath) throws IOException,
CoreException {
+ InputStream contentStream = null;
+ try {
+ contentStream = new FileInputStream(resource);
+ write(contentStream, destinationPath);
+ } finally {
+ if (contentStream != null)
+ contentStream.close();
+ }
+ }
+
+ /**
+ * @param contentStream
+ * @param destinationPath
+ * @throws IOException
+ * @throws CoreException
+ */
+ public void write(InputStream contentStream, String destinationPath) throws IOException,
CoreException {
+ ByteArrayOutputStream output = null;
+
+ try {
+ output = new ByteArrayOutputStream();
+ int chunkSize = contentStream.available();
+ byte[] readBuffer = new byte[chunkSize];
+ int n = contentStream.read(readBuffer);
+
+ while (n > 0) {
+ output.write(readBuffer);
+ n = contentStream.read(readBuffer);
+ }
+ } finally {
+ if (output != null)
+ output.close();
+ }
+
+ write(destinationPath, output.toByteArray());
+ }
+
+ /**
+ * pack directory relative to root
+ * @param directory
+ * @param root
+ * @throws CoreException
+ * @throws IOException
+ */
+ public void pack(File directory, String root) throws CoreException, IOException
+ {
+ File[] files = directory.listFiles();
+ for( int i = 0; i < files.length; i++ )
+ {
+ String relativeFolder = makeRelative( files[i].getAbsolutePath(), root );
+ if( files[i].isDirectory() )
+ {
+ if( relativeFolder != null )
+ {// should always be true
+ writeFolder( relativeFolder );
+ }
+ pack( files[i], root );
+ } else
+ {
+ if( relativeFolder != null )
+ {// should always be true
+ write( files[i], relativeFolder );
+ }
+ }
+ }
+
+ }
+ /**
+ * Make directoryname relative to root
+ * @param fileName
+ * @param root
+ * @return
+ */
+ private String makeRelative(String fileName, String root)
+ {
+ String folder=null;
+ if(fileName.startsWith(root))
+ {
+ folder=fileName.substring(root.length());
+ }
+ folder = folder.replaceAll("\\\\", "/"); //$NON-NLS-1$
//$NON-NLS-2$
+ if (folder.length() > 0 && folder.charAt(0) == '/')
+ folder = folder.substring(1);
+ return folder;
+ }
+
+}