Author: rob.stryker(a)jboss.com
Date: 2007-05-30 14:21:53 -0400 (Wed, 30 May 2007)
New Revision: 2079
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/types/EarArchiveType.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
Log:
fixes much of the problems regarding incremental publish with wtp projects
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/types/EarArchiveType.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/types/EarArchiveType.java 2007-05-30
17:49:36 UTC (rev 2078)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/types/EarArchiveType.java 2007-05-30
18:21:53 UTC (rev 2079)
@@ -40,7 +40,7 @@
IProgressMonitor monitor) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IArchive topLevel = createGenericIArchive(project, null, project.getName() +
".ear");
- topLevel.setDestinationPath(project.getLocation());
+ topLevel.setDestinationPath(new Path(project.getName()));
topLevel.setInWorkspace(true);
fillDefaultConfiguration(projectName, topLevel, monitor);
@@ -52,7 +52,7 @@
IProject project = module.getProject();
IContainer sourceContainer = project.getFolder(EARCONTENT);
IArchive topLevel = createGenericIArchive(project, null, project.getName() +
".ear", sourceContainer);
- topLevel.setDestinationPath(project.getLocation());
+ topLevel.setDestinationPath(new Path(project.getName()));
topLevel.setInWorkspace(true);
fillDefaultConfiguration(project.getName(), topLevel, monitor);
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-05-30
17:49:36 UTC (rev 2078)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2007-05-30
18:21:53 UTC (rev 2079)
@@ -21,6 +21,13 @@
*/
package org.jboss.ide.eclipse.as.core.publishers;
+import java.io.File;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -29,6 +36,8 @@
import org.eclipse.core.runtime.Status;
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.model.IModuleResource;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
@@ -52,6 +61,8 @@
*/
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;
@@ -84,10 +95,21 @@
int deltaKind, int modulePublishState, IProgressMonitor monitor) throws
CoreException {
PublishEvent event = PublisherEventLogger.createSingleModuleTopEvent(eventRoot, module,
kind, deltaKind);
EventLogModel.markChanged(eventRoot);
- IArchive topLevel = createTopPackage(module, jbServer.getDeployDirectory(), monitor);
+ boolean incremental = shouldPublishIncremental(module, kind, deltaKind,
modulePublishState);
+
+ IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), incremental,
monitor);
+
+
if( topLevel != null ) {
try {
- new ArchiveBuildDelegate().fullArchiveBuild(topLevel);//, new
NullProgressMonitor());
+ 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);
}
@@ -100,19 +122,33 @@
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 = createTopPackage(module, jbServer.getDeployDirectory(), monitor);
+
+ IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), false,
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.
} else {
return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
PACKAGE_UNDETERMINED_CODE, "", null);
}
return new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IStatus.OK,
"", null);
}
+
+ protected IArchive getTopPackage(IModule module, String deployDir,
+ boolean incremental, IProgressMonitor monitor) {
+ if( !moduleToArchiveMap.containsKey(module.getId()) || !incremental) {
+ IArchive top = createTopPackage(module, deployDir, monitor);
+ if( top != null )
+ moduleToArchiveMap.put(module.getId(), top);
+ }
+ return (IArchive)moduleToArchiveMap.get(module.getId());
+ }
+
protected IArchive createTopPackage(IModule module, String deployDir, IProgressMonitor
monitor) {
IArchiveType type = ModulePackageTypeConverter.getPackageTypeFor(module);
- if( type != null ) {
+ if( type != null && module.getProject() != null ) {
IArchive topLevel = type.createDefaultConfiguration(module.getProject().getName(),
monitor);
topLevel.setDestinationPath(new Path(deployDir));
topLevel.setInWorkspace(false);
@@ -120,4 +156,51 @@
}
return null;
}
+
+ protected void fillDelta(IModuleResourceDelta[] delta, Set addedChanged, Set removed) {
+ for( int i = 0; i < delta.length; i++ ) {
+ fillDelta(delta[i], addedChanged, removed);
+ }
+ }
+ 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);
+ }
+ }
+ handleResource(delta.getKind(), delta.getModuleResource(), addedChanged, removed);
+ }
+
+ protected void handleResource(int kind, IModuleResource resource, Set addedChanged, Set
removed) {
+ if( resource instanceof ModuleFile ) {
+ ModuleFile mf = (ModuleFile)resource;
+ File f = (File)resource.getAdapter(java.io.File.class);
+ IPath p = null;
+ if( f == null ) {
+ IFile ifile = (IFile)resource.getAdapter(IFile.class);
+ if( ifile != null )
+ p = ifile.getLocation();
+ } else {
+ p = new Path(f.getAbsolutePath());
+ }
+
+ if( p != null ) {
+ if( kind == IModuleResourceDelta.ADDED || kind == IModuleResourceDelta.CHANGED) {
+ addedChanged.add(p);
+ } else if( kind == IModuleResourceDelta.REMOVED) {
+ removed.add(p);
+ }
+ }
+ }
+ }
+ protected TreeSet createDefaultTreeSet() {
+ return new TreeSet(new Comparator () {
+ public int compare(Object o1, Object o2) {
+ if (o1.equals(o2)) return 0;
+ else return -1;
+ }
+ });
+ }
+
}