Author: rob.stryker(a)jboss.com
Date: 2008-08-22 20:25:19 -0400 (Fri, 22 Aug 2008)
New Revision: 9877
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.classpath
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.project
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.settings/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.settings/org.eclipse.jdt.core.prefs
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/build.properties
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/EJBJar.gif
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/ear.gif
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/publish.gif
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/publishDetails.gif
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/war.gif
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EarArchiveType.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EjbArchiveType.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/J2EEArchiveType.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/WarArchiveType.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesBuildListener.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesModelModuleContributor.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ModulePackageTypeConverter.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagedArtifactAdapter.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/ArchivePublishWizard.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/EditPublishAction.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEARAction.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEJBJARAction.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewWARAction.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PreviewPage.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PublishAction.java
Log:
JBIDE-2677 - removing the as.core's dependency on archives by way of addding an
extension point for publishers and a new plugin for the archives / publishing integration
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.classpath
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.classpath
(rev 0)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.classpath 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.project
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.project
(rev 0)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.project 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.ide.eclipse.archives.webtools</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.settings/org.eclipse.jdt.core.prefs
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/.settings/org.eclipse.jdt.core.prefs 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,7 @@
+#Fri Aug 22 17:07:49 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/META-INF/MANIFEST.MF 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Project Archives Webtools Integration Plug-in
+Bundle-SymbolicName: org.jboss.ide.eclipse.archives.webtools;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.jboss.ide.eclipse.archives.core;bundle-version="2.0.0",
+ org.jboss.ide.eclipse.archives.ui;bundle-version="1.0.0",
+ org.eclipse.wst.server.core;bundle-version="1.1.0",
+ org.eclipse.wst.server.ui;bundle-version="1.1.0",
+ org.eclipse.core.resources;bundle-version="3.4.0",
+ org.eclipse.jdt.core;bundle-version="3.4.0",
+ org.eclipse.jst.server.core;bundle-version="1.1.0",
+ org.eclipse.wst.common.modulecore;bundle-version="1.1.200",
+ org.apache.ant;bundle-version="1.7.0",
+ org.jboss.ide.eclipse.as.core;bundle-version="1.0.0",
+ org.eclipse.ui.ide;bundle-version="3.4.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/build.properties
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/build.properties
(rev 0)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/build.properties 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/EJBJar.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/EJBJar.gif
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/ear.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/ear.gif
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/publish.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/publish.gif
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/publishDetails.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/publishDetails.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/war.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/icons/war.gif
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Added: trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml
(rev 0)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.wst.server.core.moduleTypes">
+ <moduleType
+ id="jboss.package"
+ name="Project Package"/>
+ </extension>
+
+ <extension
+ point="org.jboss.ide.eclipse.archives.core.archiveTypes">
+ <packageType
+
class="org.jboss.ide.eclipse.archives.webtools.archivetypes.WarArchiveType"
+ id="org.jboss.ide.eclipse.as.core.packages.warArchive"
+ label="WAR"/>
+ <packageType
+
class="org.jboss.ide.eclipse.archives.webtools.archivetypes.EjbArchiveType"
+ id="org.jboss.ide.eclipse.as.core.packages.ejbPackageType"
+ label="EJB JAR"/>
+ <packageType
+
class="org.jboss.ide.eclipse.archives.webtools.archivetypes.EarArchiveType"
+ id="org.jboss.ide.eclipse.as.core.packages.earPackageType"
+ label="EAR"/>
+ </extension>
+
+ <!-- Adapters and clients to make stuff 'runnable' on server -->
+ <extension
+ point="org.eclipse.wst.server.core.moduleArtifactAdapters">
+ <moduleArtifactAdapter
+
class="org.jboss.ide.eclipse.archives.webtools.modules.PackagedArtifactAdapter"
+ id="org.jboss.ide.eclipse.as.core.PackagedArtifactAdapter"
+ priority="0">
+ <enablement>
+ <or>
+ <instanceof value="org.eclipse.core.resources.IProject"/>
+ <instanceof value="org.eclipse.jdt.core.IJavaProject"/>
+ </or>
+ </enablement>
+ </moduleArtifactAdapter>
+ </extension>
+ <extension
+ point="org.eclipse.wst.server.core.moduleFactories">
+ <moduleFactory
+
class="org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory"
+ id="org.jboss.ide.eclipse.as.core.PackageModuleFactory"
+ projects="true">
+ <moduleType
+ types="jboss.package"
+ versions="1.0"/>
+ </moduleFactory>
+ </extension>
+
+ <extension
+ point="org.jboss.ide.eclipse.archives.ui.nodePopupMenus">
+ <nodeContribution
+ class="org.jboss.ide.eclipse.archives.webtools.ui.PublishAction"
+ icon="icons/publish.gif"
+ id="org.jboss.ide.eclipse.as.ui.publishNodeContextContrib"
+ label="Publish To Server"
+ weight="1"/>
+ <nodeContribution
+
class="org.jboss.ide.eclipse.archives.webtools.ui.EditPublishAction"
+ icon="icons/publishDetails.gif "
+ id="org.jboss.ide.eclipse.as.ui.modifyPublishNodeContextContrib"
+ label="Edit publish settings...">
+ </nodeContribution>
+ </extension>
+ <extension
+ point="org.jboss.ide.eclipse.archives.ui.newArchiveActions">
+ <newPackageAction
+ class="org.jboss.ide.eclipse.archives.webtools.ui.NewWARAction"
+ icon="icons/war.gif"
+ id="org.jboss.ide.eclipse.packages.ui.newWARAction"
+ label="WAR"/>
+ <newPackageAction
+ class="org.jboss.ide.eclipse.archives.webtools.ui.NewEJBJARAction"
+ icon="icons/EJBJar.gif"
+ id="org.jboss.ide.eclipse.packages.ui.newEJBJarAction"
+ label="EJB JAR"/>
+ <newPackageAction
+ class="org.jboss.ide.eclipse.archives.webtools.ui.NewEARAction"
+ icon="icons/ear.gif"
+ id="org.jboss.ide.eclipse.packages.ui.newEARAction"
+ label="EAR"/>
+ </extension>
+ <extension
+ point="org.jboss.ide.eclipse.as.core.publishers">
+ <publisher
+
class="org.jboss.ide.eclipse.archives.webtools.modules.PackagesPublisher"
+ priority="5">
+ </publisher>
+ </extension>
+</plugin>
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,52 @@
+package org.jboss.ide.eclipse.archives.webtools;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.ide.eclipse.archives.webtools.modules.ArchivesBuildListener;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class IntegrationPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID =
"org.jboss.ide.eclipse.archives.webtools";
+
+ // The shared instance
+ private static IntegrationPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public IntegrationPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ ArchivesBuildListener.getInstance();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static IntegrationPlugin getDefault() {
+ return plugin;
+ }
+
+}
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EarArchiveType.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EarArchiveType.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EarArchiveType.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,118 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.archivetypes;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.server.core.IEnterpriseApplication;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import org.jboss.ide.eclipse.archives.webtools.modules.ModulePackageTypeConverter;
+
+/**
+ * @author rob.stryker(a)redhat.com
+ */
+public class EarArchiveType extends J2EEArchiveType {
+ public final static String ID =
"org.jboss.ide.eclipse.as.core.packages.earPackageType";
+ public String getAssociatedModuleType() {
+ return "jst.ear";
+ }
+
+ public String getId() {
+ return ID;
+ }
+
+ public String getLabel() {
+ return "EAR";
+ }
+
+
+ public IArchive createDefaultConfiguration(String project, IProgressMonitor monitor) {
+ IModule mod = getModule(project);
+ if( mod != null )
+ return createDefaultConfigFromModule(mod, monitor);
+ else
+ return createDefaultConfiguration2(project, monitor);
+ }
+
+ public IArchive createDefaultConfiguration2(String projectName,
+ IProgressMonitor monitor) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ IArchive topLevel = createGenericIArchive(project, null, project.getName() +
".ear");
+ topLevel.setDestinationPath(new Path(project.getName()));
+ topLevel.setInWorkspace(true);
+
+ fillDefaultConfiguration(projectName, topLevel, monitor);
+ return topLevel;
+ }
+
+ public IArchive createDefaultConfigFromModule(IModule module,
+ IProgressMonitor monitor) {
+ IProject project = module.getProject();
+ IContainer sourceContainer = project.getFolder(EARCONTENT);
+ IArchive topLevel = createGenericIArchive(project, null, project.getName() +
".ear", sourceContainer);
+ topLevel.setDestinationPath(new Path(project.getName()));
+ topLevel.setInWorkspace(true);
+
+ fillDefaultConfiguration(project.getName(), topLevel, monitor);
+ return topLevel;
+ }
+
+ public IArchive fillDefaultConfiguration(String projectName, IArchive topLevel,
IProgressMonitor monitor) {
+ try {
+ IModule mod = getModule(projectName);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ if( mod == null ) {
+ // add fileset
+ IArchiveFolder metainf = addFolder(project, topLevel, METAINF);
+ addFileset(project, metainf, new Path(projectName).append(METAINF).toOSString(),
null);
+
+ } else {
+ // now add children
+ addFileset(project, topLevel, new
Path(project.getName()).append(EARCONTENT).toOSString(), "**/*.*");
+ IEnterpriseApplication earModule =
(IEnterpriseApplication)mod.loadAdapter(IEnterpriseApplication.class, monitor);
+ IModule[] childModules = earModule.getModules();
+ for( int i = 0; i < childModules.length; i++ ) {
+ IModule child = childModules[i];
+ IArchiveType type = ModulePackageTypeConverter.getPackageTypeFor(child);
+ IArchive childPack;
+ if( type == null ) {
+ childPack = createGenericIArchive(child.getProject(), null,
child.getProject().getName() + ".jar");
+ } else {
+ childPack = type.createDefaultConfiguration(child.getProject().getName(), new
NullProgressMonitor());
+ }
+ topLevel.addChild(childPack);
+ }
+ }
+
+ } catch( ArchivesModelException ame) {}
+ return topLevel;
+ }
+}
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EjbArchiveType.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EjbArchiveType.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/EjbArchiveType.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,81 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.archivetypes;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+
+/**
+ *
+ * @author rob.stryker(a)redhat.com
+ */
+public class EjbArchiveType extends J2EEArchiveType {
+
+ public final static String ID =
"org.jboss.ide.eclipse.as.core.packages.ejbPackageType";
+ public String getAssociatedModuleType() {
+ return "jst.ejb";
+ }
+
+ public String getId() {
+ return ID;
+ }
+
+ public String getLabel() {
+ return "EJB JAR";
+ }
+
+ public IArchive createDefaultConfiguration(String projectName, IProgressMonitor monitor)
{
+ IProject project = getProject(projectName);
+ IArchive topLevel = createGenericIArchive(project, null, project.getName() +
".jar");
+ return fillDefaultConfiguration(project, topLevel, monitor);
+ }
+
+ public IArchive fillDefaultConfiguration(String projectName, IArchive topLevel,
IProgressMonitor monitor) {
+ return fillDefaultConfiguration(getProject(projectName), topLevel, monitor);
+ }
+ public IArchive fillDefaultConfiguration(IProject project, IArchive topLevel,
IProgressMonitor monitor) {
+
+ IModule mod = getModule(project.getName());
+
+ if( mod == null ) {
+ // TODO fix me
+ } else {
+ if( mod.getModuleType().getId().equals("jst.ejb") ) {
+ try {
+ IJavaProject proj = JavaCore.create(project);
+ IPath outputLoc = proj.getOutputLocation();
+ addFileset(project, topLevel, outputLoc.toOSString(), null);
+ } catch( JavaModelException jmde) {
+ } catch( ArchivesModelException ame ) {}
+ }
+ }
+ return topLevel;
+ }
+
+}
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/J2EEArchiveType.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/J2EEArchiveType.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/J2EEArchiveType.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,163 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.archivetypes;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.internal.ServerPlugin;
+import org.jboss.ide.eclipse.archives.core.model.ArchiveNodeFactory;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import
org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+
+/**
+ *
+ * @author rob.stryker(a)jboss.com
+ */
+public abstract class J2EEArchiveType implements IArchiveType {
+ public static final String METAINF = "META-INF";
+ public static final String WEBINF = "WEB-INF";
+ public static final String CLASSES = "classes";
+ public static final String LIB = "lib";
+ public static final String WEBCONTENT = "WebContent";
+ public static final String EARCONTENT = "EarContent";
+ public static final String EJBMODULE = "ejbModule";
+
+
+ protected boolean isModuleType(IModule module, String moduleTypeId){
+ if(module.getModuleType()!=null &&
moduleTypeId.equals(module.getModuleType().getId()))
+ return true;
+ return false;
+ }
+
+ protected IModule getModule(String projectName) {
+ IModuleArtifact moduleArtifacts[] =
ServerPlugin.getModuleArtifacts(getProject(projectName));
+
+ if (moduleArtifacts != null && moduleArtifacts.length > 0)
+ return moduleArtifacts[0].getModule();
+ else return null;
+ }
+
+ protected IProject getProject(String projectName) {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ }
+ // Find the source folder, then create the IPackage appropriately
+ public static IArchive createGenericIArchive(IProject project, String deployDirectory,
String packageName) {
+ try {
+ IJavaProject javaProject = JavaCore.create(project);
+ Assert.isNotNull(javaProject);
+
+ IPath sourcePath;
+ try {
+ sourcePath = javaProject.getOutputLocation();
+ } catch (JavaModelException e) {
+ return null;
+ }
+ sourcePath = sourcePath.removeFirstSegments(1);
+ IContainer sourcePathContainer;
+ if( sourcePath.segmentCount() == 0 )
+ sourcePathContainer = project;
+ else
+ sourcePathContainer = project.getFolder(sourcePath);
+ return createGenericIArchive(project, deployDirectory, packageName,
sourcePathContainer);
+ } catch( Exception e ) {
+ IntegrationPlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
IntegrationPlugin.PLUGIN_ID, "Unexpected Exception", e));
+ }
+ return null;
+ }
+
+ // Create a detached package with some generic settings
+ public static IArchive createGenericIArchive(IProject project, String deployDirectory,
String packageName, IContainer sourceContainer) {
+ IArchive jar = ArchiveNodeFactory.createArchive();
+
+ if( deployDirectory != null ) {
+ jar.setDestinationPath(new Path(deployDirectory));
+ jar.setInWorkspace(ResourcesPlugin.getWorkspace().getRoot().getLocation().isPrefixOf(new
Path(deployDirectory)));
+ jar.setExploded(false);
+ } else {
+ jar.setDestinationPath(project.getFullPath());
+ jar.setInWorkspace(true);
+ jar.setExploded(false);
+ }
+ jar.setName(packageName);
+ return jar;
+ }
+
+
+ public static IArchiveFolder addFolder(IProject project,
+ IArchiveNode parent, String name) throws ArchivesModelException {
+ IArchiveFolder folder = ArchiveNodeFactory.createFolder();
+ folder.setName(name);
+ parent.addChild(folder);
+ return folder;
+ }
+ public static IArchiveFileSet addFileset(IProject project, IArchiveNode parent,
+ String sourcePath, String includePattern) throws ArchivesModelException {
+ IArchiveFileSet fs = ArchiveNodeFactory.createFileset();
+ Assert.isNotNull(project);
+ IJavaProject javaProject = JavaCore.create(project);
+ Assert.isNotNull(javaProject);
+
+ IContainer sourceContainer;
+ if( sourcePath != null && !sourcePath.equals("")) {
+ Path p = new Path(sourcePath);
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ sourceContainer = p.segmentCount() != 1 ? (IContainer)root.getFolder(p) :
root.getProject(p.segment(0));
+ } else {
+ sourceContainer = project;
+ }
+
+ fs.setRawSourcePath(sourceContainer.getFullPath().toString());
+ fs.setInWorkspace(true);
+ fs.setIncludesPattern( includePattern == null ? "**/*" : includePattern );
+ parent.addChild(fs);
+ return fs;
+ }
+
+ public abstract String getAssociatedModuleType();
+
+ /*
+ * Creates a directory scanner for some global path
+ */
+ public static DirectoryScannerExtension createDirectoryScanner (String rawPath, String
includes, String excludes, boolean scan) {
+ return DirectoryScannerFactory.createDirectoryScanner(rawPath, null, includes,
excludes, null, false, 1, scan);
+ }
+
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/J2EEArchiveType.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/WarArchiveType.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/WarArchiveType.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/WarArchiveType.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,246 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.archivetypes;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+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.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.server.core.IWebModule;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.archives.core.ArchivesCorePlugin;
+import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+
+/**
+ *
+ * @author rob.stryker(a)jboss.com
+ */
+public class WarArchiveType extends J2EEArchiveType {
+ public static final String WAR_PACKAGE_TYPE =
"org.jboss.ide.eclipse.as.core.packages.warPackage";
+
+ public String getAssociatedModuleType() {
+ return "jst.web";
+ }
+
+ public IArchive createDefaultConfiguration(String projectName, IProgressMonitor monitor)
{
+ IModule mod = getModule(projectName);
+ if( mod == null )
+ return createDefaultConfiguration2(projectName, monitor);
+ else
+ return createDefaultConfigFromModule(mod, monitor);
+ }
+
+ protected IArchive createDefaultConfiguration2(String projectName, IProgressMonitor
monitor) {
+ IProject project = getProject(projectName);
+ IArchive topLevel = createGenericIArchive(project, null, project.getName() +
".war");
+ return fillDefaultConfiguration(project, topLevel, monitor);
+ }
+
+ public IArchive fillDefaultConfiguration(String projectName, IArchive topLevel,
IProgressMonitor monitor) {
+ return fillDefaultConfiguration(getProject(projectName), topLevel, monitor);
+ }
+ public IArchive fillDefaultConfiguration(IProject project, IArchive topLevel,
IProgressMonitor monitor) {
+ try {
+ IModule mod = getModule(project.getName());
+ IArchiveFolder webinf = addFolder(project, topLevel, WEBINF);
+ IArchiveFolder lib = addFolder(project, webinf, LIB);
+ IArchiveFolder classes = addFolder(project, webinf, CLASSES);
+ addReferencedProjectsAsLibs(project, lib);
+ addLibFileset(project, lib, true);
+ addClassesFileset(project, classes);
+
+ if( mod == null ) {
+ addWebinfFileset(project, webinf);
+ } else {
+ addWebContentFileset(project, topLevel);
+ }
+ } catch( ArchivesModelException ame) {}
+ return topLevel;
+ }
+
+ // For modules only
+ protected void addWebContentFileset(IProject project, IArchiveNode packageRoot) throws
ArchivesModelException {
+ try {
+ IPath projectPath = project.getLocation();
+ DirectoryScanner scanner = createDirectoryScanner(projectPath.toString(),
"**/WEB-INF/web.xml", null, true);
+ String[] files = scanner.getIncludedFiles();
+ // just take the first
+ if( files.length > 0 ) {
+ IPath path = new Path(files[0]);
+ path = path.removeLastSegments(2); // remove the file name
+ path = new Path(project.getName()).append(path); // pre-pend project name to make
workspace-relative
+ IArchiveFileSet fs = addFileset(project, packageRoot, path.toOSString(),
"**/*");
+ //If we have separate file set for libraries, we do not need to duplicate jars.
+ fs.setExcludesPattern("**/WEB-INF/lib/*.jar");
+ }
+ } catch( IllegalStateException ise ) {
+ IStatus status = new Status(IStatus.WARNING, IntegrationPlugin.PLUGIN_ID,
"Directory could not be scanned", ise);
+ IntegrationPlugin.getDefault().getLog().log(status);
+ }
+ }
+
+ protected void addClassesFileset(IProject project, IArchiveFolder folder) throws
ArchivesModelException {
+ IJavaProject jp = JavaCore.create(project);
+ if( jp != null ) {
+ try {
+ IPath outputLoc = project.getWorkspace().getRoot().getLocation();
+ outputLoc = outputLoc.append(jp.getOutputLocation());
+ addFileset(project, folder, jp.getOutputLocation().toOSString(), "**/*");
+ } catch( JavaModelException jme ) {
+ // no logging
+ }
+ }
+ }
+ protected void addWebinfFileset(IProject project, IArchiveFolder folder) throws
ArchivesModelException {
+ try {
+ IPath projectPath = project.getLocation();
+ DirectoryScanner scanner = createDirectoryScanner(projectPath.toString(),
"**/web.xml", null, true);
+ String[] files = scanner.getIncludedFiles();
+ // just take the first
+ if( files.length > 0 ) {
+ IPath path = new Path(files[0]);
+ path = path.removeLastSegments(1); // remove the file name
+ path = new Path(project.getName()).append(path); // pre-pend project name to make
workspace-relative
+ addFileset(project, folder, path.toOSString(), "**/*");
+ }
+ } catch( IllegalStateException ise ) {
+ IStatus status = new Status(IStatus.WARNING, ArchivesCorePlugin.PLUGIN_ID,
"Directory could not be scanned", ise);
+ ArchivesCorePlugin.getDefault().getLog().log(status);
+ }
+ }
+
+ // Lib support
+ protected void addLibFileset(IProject project, IArchiveFolder folder, boolean
includeTopLevelJars) throws ArchivesModelException {
+ // Let us find /WEB-INF/lib directory and set it as source for the file set.
+ String sourcePath = null;
+
+ IPath projectPath = project.getLocation();
+ DirectoryScanner scanner = createDirectoryScanner(projectPath.toString(),
"**/WEB-INF/web.xml", null, true);
+ String[] files = scanner.getIncludedFiles();
+
+ if(files != null && files.length > 0) {
+ IPath path = new Path(files[0]);
+ path = path.removeLastSegments(1).append("lib");
+ sourcePath = project.getFullPath().append(path).toString();
+ addFileset(project, folder, sourcePath, "*.jar"); // add default jars
+ } else {
+ //having failed to find 'lib' directory, let us make source of the project
itself
+ sourcePath = project.getName();
+ DirectoryScanner scanner2 = createDirectoryScanner(projectPath.toString(),
"**/*.jar", null, true);
+ String[] files2 = scanner2.getIncludedFiles();
+ IPath p;
+ ArrayList list = new ArrayList();
+ for( int i = 0; i < files2.length; i++ ) {
+ p = project.getFullPath().append(files2[i]).removeLastSegments(1);
+ if( !list.contains(p)) {
+ list.add(p);
+ addFileset(project, folder, p.toString(), "*.jar"); // add default jars
+ }
+ }
+ }
+ }
+ protected void addReferencedProjectsAsLibs(IProject project, IArchiveFolder folder)
throws ArchivesModelException {
+ IJavaProject jp = JavaCore.create(project);
+ if( jp != null && jp.exists()) {
+ try {
+ IClasspathEntry[] entries = jp.getRawClasspath();
+ for( int i = 0; i < entries.length; i++ ) {
+ if( entries[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
+ IPath path = entries[i].getPath();
+ IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if( res instanceof IProject ) {
+ createLibFromProject((IProject)res, folder);
+ }
+ }
+ }
+ } catch( JavaModelException jme ) {
+ // no logging
+ }
+ }
+ }
+
+
+ protected void createLibFromProject(IProject project, IArchiveFolder folder) throws
ArchivesModelException {
+ IArchive pack = createGenericIArchive(project, null, project.getName() +
".jar");
+ folder.addChild(pack);
+ }
+
+ protected IArchive createDefaultConfigFromModule(IModule mod, IProgressMonitor monitor)
{
+ try {
+ IProject project = mod.getProject();
+
+ // create the stub
+ IArchive topLevel = createGenericIArchive(project, null, project.getName() +
".war");
+ topLevel.setDestinationPath(new Path(project.getName()));
+ topLevel.setInWorkspace(true);
+
+ // add lib folder so we can add libraries
+ IArchiveFolder webinf = addFolder(project, topLevel, WEBINF);
+ IArchiveFolder lib = addFolder(project, webinf, LIB);
+ IArchiveFolder classes = addFolder(project, webinf, CLASSES);
+
+
+ IVirtualComponent vc = ComponentCore.createComponent(project);
+ IPath webContentPath = vc.getRootFolder().getUnderlyingFolder().getFullPath();
+ addFileset(project, topLevel, webContentPath.toOSString(), "**/*");
+ addClassesFileset(project, classes);
+
+ // package each child and add to lib folder
+ IWebModule webModule = (IWebModule)mod.loadAdapter(IWebModule.class, monitor);
+ IModule[] childModules = webModule.getModules();
+ for (int i = 0; i < childModules.length; i++) {
+ IModule child = childModules[i];
+ lib.addChild(createGenericIArchive(child.getProject(), null,
child.getProject().getName() + ".jar"));
+ }
+ return topLevel;
+ } catch( Exception e ) {
+ IntegrationPlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
IntegrationPlugin.PLUGIN_ID, "Unexpected Exception", e));
+ }
+ return null;
+ }
+
+ public String getId() {
+ return WAR_PACKAGE_TYPE;
+ }
+
+ public String getLabel() {
+ return "WAR";
+ }
+}
\ No newline at end of file
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/archivetypes/WarArchiveType.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesBuildListener.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesBuildListener.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesBuildListener.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,215 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.modules;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+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.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.internal.ModuleFactory;
+import org.eclipse.wst.server.core.internal.ServerPlugin;
+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.IArchiveBuildListener;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveModelListener;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeDelta;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.PackagedModuleDelegate;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.FileUtil;
+
+/**
+ *
+ * @author rob.stryker(a)jboss.com
+ */
+public class ArchivesBuildListener implements IArchiveBuildListener,
IArchiveModelListener {
+
+ public static ArchivesBuildListener instance;
+ public static final String DEPLOY_SERVERS =
"org.jboss.ide.eclipse.as.core.model.PackagesListener.DeployServers";
+ public static final String DEPLOY_AFTER_BUILD =
"org.jboss.ide.eclipse.as.core.model.PackagesListener.DeployAfterBuild";
+
+ public static ArchivesBuildListener getInstance() {
+ if( instance == null ) {
+ instance = new ArchivesBuildListener();
+ }
+ return instance;
+ }
+
+ public ArchivesBuildListener() {
+ ArchivesModel.instance().addBuildListener(this);
+ ArchivesModel.instance().addModelListener(this); // ? , ArchivesModel.LIST_FRONT);
+ }
+
+ public void cleanArchive(IArchive pkg) {
+ }
+
+
+ public void finishedBuildingArchive(IArchive pkg) {
+ if( pkg.isTopLevel() && new
Boolean(pkg.getProperty(DEPLOY_AFTER_BUILD)).booleanValue()) {
+ publish(pkg);
+ }
+ }
+
+ public void fileRemoved(IArchive topLevelPackage, IArchiveFileSet fileset, IPath
filePath) {
+ }
+ public void fileUpdated(IArchive topLevelPackage, IArchiveFileSet fileset, IPath
filePath) {
+ }
+
+ // If we're supposed to auto-deploy, get on it
+ protected static void publish(IArchive pkg) {
+ String servers = pkg.getProperty(ArchivesBuildListener.DEPLOY_SERVERS);
+ publish(pkg, servers, IServer.PUBLISH_INCREMENTAL);
+ }
+ public static void publish(IArchive pkg, String servers, int publishType) {
+ IModule[] module = getModule(pkg);
+ if( module[0] == null ) return;
+ DeployableServerBehavior[] serverBehaviors =
ArchivesBuildListener.getServers(servers);
+ if( serverBehaviors != null ) {
+ for( int i = 0; i < serverBehaviors.length; i++ ) {
+ publish(serverBehaviors[i].getServer(), publishType, module );
+ }
+ }
+ }
+
+ protected static IStatus publish(IServer server, int publishType, IModule[] module ) {
+ try {
+ IServerWorkingCopy copy = server.createWorkingCopy();
+ copy.modifyModules(module, new IModule[0], new NullProgressMonitor());
+ IServer saved = copy.save(false, new NullProgressMonitor());
+ saved.publish(IServer.PUBLISH_INCREMENTAL, new NullProgressMonitor());
+ } catch( CoreException ce ) {
+ return new Status(Status.ERROR, IntegrationPlugin.PLUGIN_ID,
+ "Cannot deploy file " + module[0].getName(), ce);
+ }
+ return Status.OK_STATUS;
+
+ }
+ protected static IModule[] getModule(IArchive node) {
+ ModuleFactory factory =
ServerPlugin.findModuleFactory("org.jboss.ide.eclipse.as.core.PackageModuleFactory");
+ IModule mod = factory.findModule(PackageModuleFactory.getID(node), new
NullProgressMonitor());
+ return new IModule[] { mod };
+ }
+ protected static PackagedModuleDelegate getModuleDelegate(IArchive node) {
+ IModule mod = getModule(node)[0];
+ return (PackagedModuleDelegate)mod.loadAdapter(PackagedModuleDelegate.class, new
NullProgressMonitor());
+ }
+
+ protected IDeployableServer getDeployableServerFromBehavior(DeployableServerBehavior
dsb) {
+ IServer server = dsb.getServer();
+ IDeployableServer ids = (IDeployableServer)server.loadAdapter(IDeployableServer.class,
new NullProgressMonitor());
+ return ids;
+ }
+
+ public static DeployableServerBehavior[] getServers(String servers) {
+ if( servers == null || "".equals(servers))
+ return null;
+ ArrayList<DeployableServerBehavior> list = new
ArrayList<DeployableServerBehavior>();
+ String[] byId = servers.split(",");
+ for( int i = 0; i < byId.length; i++ ) {
+ IServer server = ServerCore.findServer(byId[i]);
+ if( server != null ) {
+ Object o = server.loadAdapter(DeployableServerBehavior.class, new
NullProgressMonitor());
+ if( o != null ) {
+ list.add((DeployableServerBehavior)o);
+ }
+ }
+ }
+ return list.toArray(new DeployableServerBehavior[list.size()]);
+ }
+
+ /*
+ * If a node is changing from exploded to imploded, or vice versa
+ * make sure to delete the pre-existing file or folder on the server.
+ */
+ public void packageBuildTypeChanged(IArchive topLevelPackage, boolean isExploded) {
+ String servers = topLevelPackage.getProperty(ArchivesBuildListener.DEPLOY_SERVERS);
+ DeployableServerBehavior[] serverBehaviors =
ArchivesBuildListener.getServers(servers);
+ if( serverBehaviors != null ) {
+ IPath sourcePath, destPath;
+ IDeployableServer depServer;
+ for( int i = 0; i < serverBehaviors.length; i++ ) {
+ sourcePath = topLevelPackage.getArchiveFilePath();
+ depServer = getDeployableServerFromBehavior(serverBehaviors[i]);
+ destPath = new
Path(depServer.getDeployDirectory()).append(sourcePath.lastSegment());
+ FileUtil.safeDelete(destPath.toFile());
+ FileUtil.fileSafeCopy(sourcePath.toFile(), destPath.toFile());
+ }
+ }
+ }
+
+ public void buildFailed(IArchive pkg, IStatus status) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void finishedBuild(IPath project) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void finishedCollectingFileSet(IArchiveFileSet fileset) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void startedBuild(IPath project) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void startedBuildingArchive(IArchive pkg) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void startedCollectingFileSet(IArchiveFileSet fileset) {
+ // TODO Auto-generated method stub
+ }
+ public void startedBuildingPackage(IArchive pkg) {
+ // TODO Auto-generated method stub
+ }
+
+ public void cleanProject(IPath project) {
+ }
+
+ public void modelChanged(IArchiveNodeDelta delta) {
+ IPath p ;
+ if( delta.getPreNode() == null )
+ p = delta.getPostNode().getProjectPath();
+ else
+ p = delta.getPreNode().getProjectPath();
+
+ ArchivesModelModuleContributor.getInstance().refreshProject(p);
+ }
+
+
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesBuildListener.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesModelModuleContributor.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesModelModuleContributor.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ArchivesModelModuleContributor.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,185 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.modules;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelException;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.IModuleContributor;
+import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.PackagedModuleDelegate;
+
+/**
+ *
+ * @author Rob Stryker rob.stryker(a)jboss.com
+ *
+ */
+public class ArchivesModelModuleContributor implements IModuleContributor {
+
+ private static ArchivesModelModuleContributor instance;
+ public static ArchivesModelModuleContributor getInstance() {
+ if( instance == null ) {
+ instance = new ArchivesModelModuleContributor(PackageModuleFactory.getFactory());
+ }
+ return instance;
+ }
+
+ private PackageModuleFactory factory;
+ protected ArrayList<IModule> modules = null;
+ protected HashMap<IPath, ArrayList<IModule>> projectToModules = new
HashMap<IPath, ArrayList<IModule>>(5); //IPath to IModule
+ protected HashMap<IModule, Object> moduleDelegates = new HashMap<IModule,
Object>(5);
+ protected HashMap<IArchive, IModule> packageToModule = new HashMap<IArchive,
IModule>(5);
+
+ private ArchivesModelModuleContributor(PackageModuleFactory factory) {
+ this.factory = factory;
+ }
+
+ public IModule[] getModules() {
+ if( modules == null ) {
+ modules = new ArrayList<IModule>();
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ int size = projects2.length;
+ for (int i = 0; i < size; i++) {
+ if (projects2[i].isAccessible()) {
+
+ if( !ArchivesModel.instance().isProjectRegistered(projects2[i].getLocation())) {
+ if( ArchivesModel.instance().canReregister(projects2[i].getLocation()))
+ // registration should also add this to the factory manually, so do not create the
module
+ ArchivesModel.instance().registerProject(projects2[i].getLocation(), new
NullProgressMonitor());
+ } else {
+ try {
+ // project is already registered. create the module
+ createModules(projects2[i]);
+ } catch(ArchivesModelException ame) {
+ IStatus status = new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID,
ame.getMessage(), ame);
+ IntegrationPlugin.getDefault().getLog().log(status);
+ }
+ }
+ }
+ }
+ }
+ return modules.toArray(new IModule[modules.size()]);
+ }
+
+ protected void createModules(IProject project) throws ArchivesModelException {
+ IArchive[] packages = ModelUtil.getProjectArchives(project.getLocation());
+ if( packages != null && packages.length > 0 ) {
+ IModule module;
+ boolean requiresSave = ensureArchivesHaveIDs(project, packages);
+ ArrayList<IModule> mods = new ArrayList<IModule>();
+ for( int i = 0; i < packages.length; i++ ) {
+ module = factory.createModule2(packages[i], project);
+ modules.add(module);
+ Object moduleDelegate = new PackagedModuleDelegate(packages[i]);
+ packageToModule.put(packages[i], module);
+ moduleDelegates.put(module, moduleDelegate);
+ mods.add(module);
+ }
+ projectToModules.put(project.getLocation(), mods);
+ if( requiresSave ) {
+ try {
+ ArchivesModel.instance().save(project.getLocation(),
+ new NullProgressMonitor());
+ } catch( ArchivesModelException ame ) {
+ }
+ }
+ }
+ }
+
+ public boolean containsModule(IModule module) {
+ return moduleDelegates.containsKey(module);
+ }
+
+ public PackagedModuleDelegate getModuleDelegate(IModule module) {
+ return (PackagedModuleDelegate)moduleDelegates.get(module);
+ }
+
+ public void refreshProject(IPath projectLoc) {
+ // prime, make sure all are found
+ if( modules == null )
+ getModules();
+
+ // remove old mods
+ ArrayList<IModule> mods = projectToModules.get(projectLoc);
+ IModule mod;
+ PackagedModuleDelegate delegate;
+ if (mods != null) {
+ for( Iterator<IModule> i = mods.iterator(); i.hasNext();) {
+ mod = (IModule)i.next();
+ if( modules.contains(mod)) {
+ delegate = ((PackagedModuleDelegate)moduleDelegates.get(mod));
+ moduleDelegates.remove(mod);
+ modules.remove(mod);
+ if( delegate != null )
+ packageToModule.remove(delegate.getPackage());
+ }
+ }
+ }
+ try {
+ createModules(findProject(projectLoc));
+ } catch( ArchivesModelException ame ) {
+ IStatus status = new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID,
ame.getMessage(), ame);
+ IntegrationPlugin.getDefault().getLog().log(status);
+ }
+ }
+
+ protected IProject findProject(IPath projectLoc) {
+ IProject proj = null;
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ int size = projects2.length;
+ for (int i = 0; i < size; i++) {
+ if( projects2[i].getLocation().equals(projectLoc))
+ proj = projects2[i];
+ }
+ return proj;
+ }
+
+ /**
+ * Set a property so that each module that's here in the factory
+ * has a unique ID other than it's name (which is not unique)
+ * @param archives
+ * @return returns whether a save has occurred
+ */
+ protected boolean ensureArchivesHaveIDs(IProject project, IArchive[] archives) {
+ boolean requiresSave = false;
+ for( int i = 0; i < archives.length; i++ ) {
+ if( PackageModuleFactory.getID(archives[i]) == null ) {
+ requiresSave = true;
+ archives[i].setProperty(PackageModuleFactory.MODULE_ID_PROPERTY_KEY,
+ PackageModuleFactory.getID(archives[i], true));
+ }
+ }
+ return requiresSave;
+ }
+}
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ModulePackageTypeConverter.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ModulePackageTypeConverter.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ModulePackageTypeConverter.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,48 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.modules;
+
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import org.jboss.ide.eclipse.archives.webtools.archivetypes.EarArchiveType;
+import org.jboss.ide.eclipse.archives.webtools.archivetypes.EjbArchiveType;
+import org.jboss.ide.eclipse.archives.webtools.archivetypes.WarArchiveType;
+
+/**
+ *
+ * @author rob.stryker(a)jboss.com
+ */
+public class ModulePackageTypeConverter {
+ public static IArchiveType getPackageTypeFor(IModule module) {
+ String modType = module.getModuleType().getId();
+ if("jst.web".equals(modType)) {
+ return
ArchivesCore.getInstance().getExtensionManager().getArchiveType(WarArchiveType.WAR_PACKAGE_TYPE);
+ } else if("jst.ear".equals(modType)) {
+ return
ArchivesCore.getInstance().getExtensionManager().getArchiveType(EarArchiveType.ID);
+ } else if("jst.ejb".equals(modType)) {
+ return
ArchivesCore.getInstance().getExtensionManager().getArchiveType(EjbArchiveType.ID);
+ }
+
+ return null;
+ }
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/ModulePackageTypeConverter.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,412 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.modules;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.internal.ModuleFactory;
+import org.eclipse.wst.server.core.internal.ServerPlugin;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleFolder;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.ModuleDelegate;
+import org.eclipse.wst.server.core.model.ModuleFactoryDelegate;
+import org.eclipse.wst.server.core.util.ModuleFile;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor;
+import
org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension.FileWrapper;
+import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.jboss.ide.eclipse.archives.core.util.PathUtils;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+
+/**
+ *
+ * @author rob.stryker(a)jboss.com
+ */
+public class PackageModuleFactory extends ModuleFactoryDelegate {
+
+ public static final String FACTORY_TYPE_ID =
"org.jboss.ide.eclipse.as.core.PackageModuleFactory";
+ public static final String MODULE_TYPE = "jboss.package";
+ public static final String VERSION = "1.0";
+
+ public static final String MODULE_ID_PROPERTY_KEY =
"org.jboss.ide.eclipse.as.core.packages.ModuleIDPropertyKey";
+
+ // the factory delegate and the factory respectively
+ private static PackageModuleFactory factDelegate;
+ private static ModuleFactory factory;
+
+ /**
+ * Find the module factory wrapper WTP provides for us
+ * @return
+ */
+ public static PackageModuleFactory getFactory() {
+ if( factDelegate == null ) {
+ ModuleFactory[] factories = ServerPlugin.getModuleFactories();
+
+ for( int i = 0; i < factories.length; i++ ) {
+ if( factories[i].getId().equals(PackageModuleFactory.FACTORY_TYPE_ID)) {
+ Object o = factories[i].getDelegate(new NullProgressMonitor());
+ if( o instanceof PackageModuleFactory ) {
+ factory = factories[i];
+ factDelegate = (PackageModuleFactory)o;
+ return factDelegate;
+ }
+ }
+ }
+ }
+ return factDelegate;
+ }
+
+ /**
+ * Get the module ID of this IArchive if it exists.
+ * Do not create a new one otherwise
+ * @param pack
+ * @return
+ */
+ public static String getID(IArchive pack) {
+ return getID(pack, false);
+ }
+
+ /**
+ * Get the module ID of this IArchive if it exists.
+ * If create is true, and the ID is not set, set a default ID.
+ * @param pack
+ * @param create
+ * @return
+ */
+ protected static String getID(IArchive pack, boolean create) {
+ String propVal = pack.getProperty(MODULE_ID_PROPERTY_KEY);
+ if( propVal == null && create ) {
+ return "" + new Date().getTime();
+ }
+ return propVal;
+ }
+
+ /**
+ * Return the name of the project in the workspace
+ * @param node
+ * @return
+ */
+ public static String getProjectName(IArchiveNode node) {
+ IPath projPath = node.getProjectPath();
+ if( projPath == null ) return null;
+ IProject[] list = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for( int i = 0; i < list.length; i++ )
+ if( list[i].getLocation().equals(projPath))
+ return list[i].getName();
+ return null;
+ }
+
+ /**
+ * Get the visible name of this module
+ * @param pack
+ * @return
+ */
+ public static String getName(IArchive pack) {
+ return getProjectName(pack) + "/" + pack.getName();
+ }
+
+
+
+ protected ArchivesModelModuleContributor moduleContributor;
+ public PackageModuleFactory() {
+ super();
+ }
+
+ public void initialize() {
+ moduleContributor = ArchivesModelModuleContributor.getInstance();
+ }
+
+ protected IModule createModule2(IArchive pack, IProject project) {
+ return createModule(getID(pack), getName(pack), MODULE_TYPE, VERSION, project);
+ }
+
+ public IModule[] getModules(IProject project) {
+ moduleContributor.refreshProject(project.getLocation());
+ return super.getModules(project);
+ }
+ public IModule[] getModules() {
+ return moduleContributor.getModules();
+ }
+
+ public ModuleDelegate getModuleDelegate(IModule module) {
+ return moduleContributor.getModuleDelegate(module);
+ }
+
+ public static interface IModuleContributor {
+ public IModule[] getModules();
+ public boolean containsModule(IModule module);
+ public PackagedModuleDelegate getModuleDelegate(IModule module);
+ }
+
+ public static interface IExtendedModuleResource extends IModuleResource {
+ public IPath getSourcePath();
+ public IArchiveNode getNode();
+ // deep destination is the full path this resource represents, even if it's inside
a jar
+ public IPath getDeepDestination();
+ // the concrete file this resource is part of... so the top most zipped jar or, if all
is exploded, the file itself
+ public IPath getConcreteDestFile();
+ }
+
+ public static class DelegateInitVisitor implements IArchiveNodeVisitor {
+
+ private IArchive pack;
+ private HashMap<IArchiveNode, ArchiveContainerResource> members; // node ->
imoduleresource
+ private HashMap<IPath, IArchiveNode> pathToNode; // path -> node
+ public DelegateInitVisitor(IArchive pack) {
+ this.pack = pack;
+ reset();
+ }
+ public void reset() {
+ members = new HashMap<IArchiveNode, ArchiveContainerResource>();
+ pathToNode = new HashMap<IPath, IArchiveNode>();
+ }
+ public boolean visit(IArchiveNode node) {
+ int type = node.getNodeType();
+ if( type == IArchiveNode.TYPE_ARCHIVE && ((IArchive)node).isTopLevel()) {
+ IPath rel = ((IArchive)node).getRootArchiveRelativePath();
+ members.put(node, new ArchiveContainerResource(((IArchive)node).getName(), node,
rel));
+ pathToNode.put(rel, node);
+ } else if( type == IArchiveNode.TYPE_ARCHIVE || type ==
IArchiveNode.TYPE_ARCHIVE_FOLDER) {
+ String name = type == IArchiveNode.TYPE_ARCHIVE ? ((IArchive)node).getName() :
((IArchiveFolder)node).getName();
+ // if we're any other archive or a folder, create us and add to parent
+ IArchiveNode parent = node.getParent();
+ ArchiveContainerResource parentAsResource = members.get(parent);
+ IPath rel = node.getRootArchiveRelativePath();
+ members.put(node, new ArchiveContainerResource(name, node, rel));
+ pathToNode.put(rel, node);
+ parentAsResource.addChild(members.get(node));
+ } else if( type == IArchiveNode.TYPE_ARCHIVE_FILESET ) {
+ ArchiveContainerResource parentAsResource = members.get(node.getParent());
+ parentAsResource.addFilesetAsChild((IArchiveFileSet)node);
+ }
+
+ return true;
+ }
+
+ public IModuleResource getRootResource() {
+ return members.get(pack);
+ }
+
+ public IModuleResource getResourceForNode(IArchiveNode node) {
+ return members.get(node);
+ }
+ }
+
+ public static class ArchiveContainerResource implements IModuleFolder,
IExtendedModuleResource {
+
+ protected IPath moduleRelativePath;
+ protected IPath fsRelative;
+ protected IArchiveNode node;
+ protected String name;
+ private HashMap<IPath, IModuleResource> members;
+
+ // represents source folder on disk. only used if node is fileset
+// private IPath folderGlobalPath = null;
+ public ArchiveContainerResource(String name,IArchiveNode node,IPath moduleRelativePath
) {
+ this.name = name;
+ this.node = node;
+ this.moduleRelativePath = moduleRelativePath;
+ members = new HashMap<IPath, IModuleResource>();
+ if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET ) {
+ fsRelative =
moduleRelativePath.removeFirstSegments(node.getParent().getRootArchiveRelativePath().segmentCount());
+ }
+ }
+
+ public int hashCode() {
+ return name.hashCode() * 37 + moduleRelativePath.hashCode();
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof IModuleFolder) {
+ IModuleFolder resource = (IModuleFolder) other;
+ return resource.getModuleRelativePath().equals(getModuleRelativePath());
+ }
+ return false;
+ }
+
+ public void addChild(IModuleResource resource) {
+ members.put(resource.getModuleRelativePath(), resource);
+ }
+
+ public void removeChild(IPath moduleRelativePath) {
+ members.remove(moduleRelativePath);
+ }
+ public IModuleResource getChild(IPath path) {
+ return members.get(path);
+ }
+
+ public void addFilesetAsChild(IArchiveFileSet fs) {
+ FileWrapper[] files = fs.findMatchingPaths(); // file-system based source paths
+ for( int i = 0; i < files.length; i++ ) {
+ addFilesetPathAsChild(fs, files[i]);
+ }
+ }
+
+ public void addFilesetPathAsChild(IArchiveFileSet fs, FileWrapper file) {
+ IPath fsRelative = new Path(file.getFilesetRelative());
+ ArchiveContainerResource parent = find(fs, fsRelative.removeLastSegments(1), true);
+ ExtendedModuleFile emf = new ExtendedModuleFile(file, fs);
+ parent.addChild(emf);
+ }
+
+ protected ArchiveContainerResource find(IArchiveFileSet fs, IPath fsRelative, boolean
create) {
+ ArchiveContainerResource resource = this;
+ ArchiveContainerResource tmpResource;
+ IPath tmpPath = fs.getRootArchiveRelativePath();
+ int count = fsRelative.segmentCount();
+ for( int i = 0; i < count; i++ ) {
+ tmpPath = tmpPath.append(fsRelative.segment(i));
+ tmpResource = (ArchiveContainerResource)resource.getChild(tmpPath);
+ if( tmpResource == null ) {
+ if( !create )
+ return null;
+ tmpResource = new ArchiveContainerResource(tmpPath.lastSegment(), fs, tmpPath);
+ resource.addChild(tmpResource);
+ }
+ resource = tmpResource;
+ }
+ return resource;
+ }
+
+ public IModuleResource[] members() {
+ Collection<IModuleResource> c = members.values();
+ return c.toArray(new IModuleResource[c.size()]);
+ }
+
+ public IPath getModuleRelativePath() {
+ return moduleRelativePath;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ public IPath getDeepDestination() {
+ IPath tmp = node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET
+ ? moduleRelativePath : node.getRootArchiveRelativePath();
+ return PathUtils.getGlobalLocation(node.getRootArchive()).append(tmp);
+ }
+
+ public IPath getConcreteDestFile() {
+ if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET )
+ return ModelUtil.getBaseDestinationFile((IArchiveFileSet)node,fsRelative);
+ else
+ return ModelUtil.getBaseDestinationFile((IArchiveFileSet)node);
+ }
+ public IArchiveNode getNode() {
+ return node;
+ }
+
+ public IPath getSourcePath() {
+ return null;
+ }
+
+ }
+
+ public static class ExtendedModuleFile extends ModuleFile implements
IExtendedModuleResource {
+ private FileWrapper wrapper;
+ private IArchiveFileSet node;
+ public ExtendedModuleFile(FileWrapper wrapper, IArchiveFileSet fs) {
+ super(wrapper.getOutputName(), wrapper.getRootArchiveRelative(),
wrapper.lastModified());
+ this.node = fs;
+ this.wrapper = wrapper;
+ }
+ public int hashCode() {
+ return getName().hashCode() * 37 + getPath().hashCode();
+ }
+
+ public IPath getPath() { return new Path(wrapper.getAbsolutePath()); }
+ public IArchiveNode getNode() { return node; }
+ public IPath getDeepDestination() {
+ return
PathUtils.getGlobalLocation(node.getRootArchive()).append(wrapper.getRootArchiveRelative());
+ }
+ public IPath getSourcePath() {
+ return new Path(this.wrapper.getAbsolutePath());
+ }
+
+ public IPath getConcreteDestFile() {
+ return ModelUtil.getBaseDestinationFile(node, new
Path(this.wrapper.getFilesetRelative()));
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof IModuleFile) {
+ IModuleFile resource = (IModuleFile) other;
+ return resource.getModuleRelativePath().equals(getModuleRelativePath());
+ }
+ return false;
+ }
+
+ }
+
+ public static class PackagedModuleDelegate extends ModuleDelegate {
+ private IArchive pack;
+ private IModuleResource rootResource;
+ private DelegateInitVisitor initVisitor;
+ public PackagedModuleDelegate(IArchive pack) {
+ this.pack = pack;
+ initVisitor = new DelegateInitVisitor(pack);
+ }
+
+ public IArchive getPackage() {
+ return pack;
+ }
+ public IModule[] getChildModules() {
+ return new IModule[0];
+ }
+
+ protected void init() {
+ initVisitor.reset();
+ pack.accept(initVisitor);
+ rootResource = initVisitor.getRootResource();
+ }
+
+ public IModuleResource[] members() throws CoreException {
+ init();
+ return new IModuleResource[] { rootResource };
+ }
+
+ public IStatus validate() {
+ return new Status(IStatus.OK, IntegrationPlugin.PLUGIN_ID,
+ 0, "", null);
+ }
+ }
+
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagedArtifactAdapter.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagedArtifactAdapter.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagedArtifactAdapter.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,81 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.modules;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.model.ModuleArtifactAdapterDelegate;
+/**
+ *
+ * @author Rob Stryker rob.stryker(a)redhat.com
+ *
+ */
+public class PackagedArtifactAdapter extends ModuleArtifactAdapterDelegate {
+
+ public PackagedArtifactAdapter() {
+ }
+
+ public IModuleArtifact getModuleArtifact(Object obj) {
+ if( obj instanceof IJavaProject ) {
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ boolean done = false;
+ String jpName = ((IJavaProject)obj).getElementName();
+ for( int i = 0; i < projects2.length && !done; i++ ) {
+ if( projects2[i].getName().equals(jpName)) {
+ done = true;
+ obj = projects2[i];
+ break;
+ }
+ }
+ }
+
+ if( obj instanceof IProject ) {
+ PackageModuleFactory factory = PackageModuleFactory.getFactory();
+ if( factory != null ) {
+// IModule[] mods = factory.getModulesFromProject((IProject)obj);
+// if( mods != null && mods.length != 0) {
+// return getArtifact(mods);
+// }
+ }
+ }
+ return null;
+ }
+
+ protected IModuleArtifact getArtifact(IModule[] mod) {
+ //return new PackagedArtifact(mod);
+ // TODO Blocking on eclipse bug 174372
+ return null;
+ }
+
+ public class PackagedArtifact implements IModuleArtifact{
+ protected IModule mod;
+ public PackagedArtifact(IModule module) {
+ this.mod = module;
+ }
+ public IModule getModule() {
+ return mod;
+ }
+ }
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagedArtifactAdapter.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,256 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.modules;
+
+import java.util.ArrayList;
+
+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.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+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.model.IModuleFile;
+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.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.util.PathUtils;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.ExtendedModuleFile;
+import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.IExtendedModuleResource;
+import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.PackagedModuleDelegate;
+import org.jboss.ide.eclipse.as.core.extensions.events.EventLogModel.EventLogTreeItem;
+import org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger;
+import
org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger.PublisherFileUtilListener;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
+import org.jboss.ide.eclipse.as.core.util.FileUtil;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+
+/**
+ *
+ * @author rob.stryker(a)jboss.com
+ */
+public class PackagesPublisher implements IJBossServerPublisher {
+
+ protected IDeployableServer server;
+ protected IModuleResourceDelta[] delta;
+ protected EventLogTreeItem eventRoot;
+
+ public PackagesPublisher() {
+ }
+
+ public int getPublishState() {
+ return IServer.PUBLISH_STATE_NONE;
+ }
+
+ public boolean accepts(IServer server, IModule[] module) {
+ if( module != null && module.length > 0
+ && "jboss.package".equals(module[0].getModuleType().getId()))
+ return true;
+ return false;
+ }
+ public IStatus publishModule(IServer server, IModule[] module,
+ int publishType, IModuleResourceDelta[] delta,
+ EventLogTreeItem log, IProgressMonitor monitor)
+ throws CoreException {
+ this.server = ServerConverter.getDeployableServer(server);
+ eventRoot = log;
+ this.delta = delta;
+
+ try {
+ IModule module2 = module[0];
+ // if it's being removed
+ if( publishType == REMOVE_PUBLISH ) {
+ removeModule(module2, monitor);
+ } else if( publishType == FULL_PUBLISH ) {
+ publishModule(module2, false, monitor);
+ } else if( publishType == INCREMENTAL_PUBLISH ) {
+ publishModule(module2, true, monitor);
+ }
+ }catch(Exception e) {
+ IStatus status = new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID, "Error
during publish", e);
+ IntegrationPlugin.getDefault().getLog().log(status);
+ }
+ return null;
+ }
+
+ protected void removeModule(IModule module, IProgressMonitor monitor) {
+ IArchive pack = getPackage(module);
+ // remove all of the deployed items
+ if( pack != null ) {
+ IPath sourcePath = pack.getArchiveFilePath();
+ IPath destPath = new
Path(server.getDeployDirectory()).append(sourcePath.lastSegment());
+ // remove the entire file or folder
+ PublisherFileUtilListener listener = new PublisherFileUtilListener(eventRoot);
+ FileUtil.safeDelete(destPath.toFile(), listener);
+ }
+ }
+
+
+
+ protected void publishModule(IModule module, boolean incremental, IProgressMonitor
monitor) {
+ IArchive pack = getPackage(module);
+ IPath sourcePath = pack.getArchiveFilePath();
+ IPath destPathRoot = new Path(server.getDeployDirectory());
+
+ // if destination is deploy directory... no need to re-copy!
+ if( destPathRoot.toOSString().equals(PathUtils.getGlobalLocation(pack).toOSString()))
{
+ // fire null publish event
+ return;
+ }
+
+ PublisherFileUtilListener listener = new PublisherFileUtilListener(eventRoot);
+ eventRoot.setProperty(PublisherEventLogger.CHANGED_RESOURCE_COUNT,
countChanges(delta));
+ if( incremental ) {
+ publishFromDelta(module, destPathRoot, sourcePath.removeLastSegments(1), delta,
listener);
+ } else {
+ // full publish, copy whole folder or file
+ FileUtil.fileSafeCopy(sourcePath.toFile(),
destPathRoot.append(sourcePath.lastSegment()).toFile(), listener);
+ }
+ }
+
+ protected void publishFromDelta(IModule module, IPath destPathRoot, IPath sourcePrefix,
+ IModuleResourceDelta[] delta, PublisherFileUtilListener listener) {
+ ArrayList<IPath> changedFiles = new ArrayList<IPath>();
+ for( int i = 0; i < delta.length; i++ ) {
+ publishFromDeltaHandle(delta[i], destPathRoot, sourcePrefix, changedFiles, listener);
+ }
+ }
+
+ protected int countChanges(IModuleResourceDelta[] deltas) {
+ IModuleResource res;
+ int count = 0;
+ if( deltas == null ) return 0;
+ for( int i = 0; i < deltas.length; i++ ) {
+ res = deltas[i].getModuleResource();
+ if( res != null && res instanceof IModuleFile)
+ count++;
+ count += countChanges(deltas[i].getAffectedChildren());
+ }
+ return count;
+ }
+
+ protected int countConcreteFiles(IModule module) {
+ PackagedModuleDelegate delegate =
(PackagedModuleDelegate)module.loadAdapter(PackagedModuleDelegate.class, new
NullProgressMonitor());
+ try {
+ ArrayList list = new ArrayList();
+ countConcreteFiles(delegate.members()[0], list);
+ return list.size();
+ } catch( CoreException ce ) {
+
+ }
+ return -1;
+ }
+ protected void countConcreteFiles(IModuleResource mr, ArrayList list) {
+ if( mr instanceof IExtendedModuleResource) {
+ IExtendedModuleResource emr = ((IExtendedModuleResource)mr);
+ if( mr instanceof IModuleFile ) {
+ IPath p = emr.getConcreteDestFile();
+ if( !list.contains(p))
+ list.add(p);
+ }
+ if( mr instanceof IModuleFolder) {
+ IModuleResource[] children = ((IModuleFolder)mr).members();
+ for( int i = 0; i < children.length; i++ )
+ countConcreteFiles(children[i], list);
+ }
+ }
+ }
+
+ protected void publishFromDeltaHandle(IModuleResourceDelta delta, IPath destRoot,
+ IPath sourcePrefix, ArrayList<IPath> changedFiles, PublisherFileUtilListener
listener) {
+ switch( delta.getKind()) {
+ case IModuleResourceDelta.REMOVED:
+ // removed might not be IExtendedModuleResource
+ IModuleResource imr = delta.getModuleResource();
+ if( imr instanceof IExtendedModuleResource) {
+ IExtendedModuleResource emr = ((IExtendedModuleResource)imr);
+ IPath concrete = emr.getConcreteDestFile();
+ if( !changedFiles.contains(concrete)) {
+ IPath destPath =
destRoot.append(concrete.removeFirstSegments(sourcePrefix.segmentCount()));
+
+ // file hasnt been updated yet.
+ // But we don't know whether to delete or copy this file.
+ // depends where it is in the tree and what's exploded.
+ changedFiles.add(concrete);
+ IPath concreteRelative =
concrete.removeFirstSegments(sourcePrefix.segmentCount()).setDevice(null);
+ IPath emrModRelative = emr.getModuleRelativePath();
+ boolean delete = concreteRelative.equals(emrModRelative);
+
+ if( delete ) {
+ FileUtil.safeDelete(destPath.toFile(), listener);
+ } else {
+ // copy
+ FileUtil.fileSafeCopy(concrete.toFile(), destPath.toFile(), listener);
+ }
+ }
+ return;
+ } else {
+ // TODO
+ return;
+ }
+ case IModuleResourceDelta.ADDED:
+ imr = delta.getModuleResource();
+ if( imr instanceof IExtendedModuleResource) {
+ IPath concrete = ((IExtendedModuleResource)imr).getConcreteDestFile();
+ if( !changedFiles.contains(concrete)) {
+ changedFiles.add(concrete);
+ IPath destPath =
destRoot.append(concrete.removeFirstSegments(sourcePrefix.segmentCount()));
+ FileUtil.fileSafeCopy(concrete.toFile(), destPath.toFile(), listener);
+ }
+ return;
+ } else {
+ // TODO
+ return;
+ }
+ case IModuleResourceDelta.CHANGED:
+ imr = delta.getModuleResource();
+ if( imr instanceof ExtendedModuleFile ) {
+ IPath concrete = ((ExtendedModuleFile)imr).getConcreteDestFile();
+ if( !changedFiles.contains(concrete)) {
+ changedFiles.add(concrete);
+ IPath destPath =
destRoot.append(concrete.removeFirstSegments(sourcePrefix.segmentCount()));
+ FileUtil.fileSafeCopy(concrete.toFile(), destPath.toFile(), listener);
+ }
+ }
+ break;
+ }
+
+ IModuleResourceDelta[] children = delta.getAffectedChildren();
+ if( children != null ) {
+ for( int i = 0; i < children.length; i++ ) {
+ publishFromDeltaHandle(children[i], destRoot, sourcePrefix, changedFiles, listener);
+ }
+ }
+ }
+
+ protected IArchive getPackage(IModule module) {
+ PackagedModuleDelegate delegate =
(PackagedModuleDelegate)module.loadAdapter(PackagedModuleDelegate.class, new
NullProgressMonitor());
+ return delegate == null ? null : delegate.getPackage();
+ }
+
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/ArchivePublishWizard.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/ArchivePublishWizard.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/ArchivePublishWizard.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,220 @@
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.wst.server.core.IServerType;
+import org.eclipse.wst.server.ui.internal.ImageResource;
+import org.jboss.ide.eclipse.archives.core.build.SaveArchivesJob;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.webtools.modules.ArchivesBuildListener;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+
+public class ArchivePublishWizard extends Wizard {
+
+ private ArchivePublishWizardPage page;
+ private IArchive pack;
+ public ArchivePublishWizard(IArchive pack) {
+ this.pack = pack;
+ setWindowTitle("Archive Publish Settings");
+ }
+ public boolean performFinish() {
+ boolean alwaysPublish = new Boolean(page.getAlwaysPublish()).booleanValue();
+ pack.setProperty(ArchivesBuildListener.DEPLOY_SERVERS, alwaysPublish ? getServers() :
null);
+ pack.setProperty(ArchivesBuildListener.DEPLOY_AFTER_BUILD, getAutoDeploy());
+ final IPath p = pack.getProjectPath();
+ new SaveArchivesJob(p).schedule();
+ return true;
+ }
+ public void addPages() {
+ page = new ArchivePublishWizardPage(pack);
+ addPage(page);
+ }
+
+ protected String getServers() {
+ return page.getServers();
+ }
+ protected String getAutoDeploy() {
+ return page.getAutoDeploy();
+ }
+ protected String getAlwaysPublish() {
+ return page.getAlwaysPublish();
+ }
+
+
+ public class ArchivePublishWizardPage extends WizardPage {
+ protected IArchive pack;
+ protected TableViewer viewer;
+ protected Button autoDeploy, alwaysPublish;
+ protected String viewerResult = "";
+ protected String deployResult = Boolean.toString(false);
+ protected String alwaysPublishResult = Boolean.toString(false);
+
+ protected ArchivePublishWizardPage(IArchive pack) {
+ super("Select Server Wizard");
+ setDescription("Select the server to publish the archive to.");
+ setTitle("Publish archive to a server");
+ this.pack = pack;
+ }
+
+ public void createControl(Composite parent) {
+ Composite mainComposite = new Composite(parent, SWT.NONE);
+ mainComposite.setLayout(new FormLayout());
+ mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ fillComposite(mainComposite);
+ addListeners();
+ setControl(mainComposite);
+ getContainer().updateTitleBar();
+ setPackageDefaults();
+ }
+
+ protected void setPackageDefaults() {
+ String servers = pack.getProperty(ArchivesBuildListener.DEPLOY_SERVERS);
+ viewerResult = servers;
+ String deployAfterBuild = pack.getProperty(ArchivesBuildListener.DEPLOY_AFTER_BUILD);
+ if( servers != null ) {
+ alwaysPublish.setSelection(true);
+ alwaysPublishSelected();
+ boolean depAfterBld = !(deployAfterBuild == null || new
Boolean(deployAfterBuild).booleanValue() == false);
+ autoDeploy.setSelection(depAfterBld);
+ autoDeploySelected();
+
+ IDeployableServer[] depServers = ServerConverter.getAllDeployableServers();
+ String[] serverList = servers.split(",");
+ final ArrayList<IDeployableServer> selected = new
ArrayList<IDeployableServer>();
+ for(int i = 0; i < serverList.length; i++ ) {
+ for( int j = 0; j < depServers.length; j++ ) {
+ if( serverList[i].equals(depServers[j].getServer().getId()))
+ selected.add(depServers[j]);
+ }
+ }
+ viewer.setSelection(new StructuredSelection(selected.toArray()));
+ }
+ }
+
+ protected void fillComposite(Composite mainComposite) {
+ viewer = new TableViewer(mainComposite);
+ FormData viewerData = new FormData();
+ viewerData.left = new FormAttachment(15,0);
+ viewerData.right = new FormAttachment(85,0);
+ viewerData.top = new FormAttachment(0,10);
+ viewerData.bottom = new FormAttachment(80,0);
+ viewer.getTable().setLayoutData(viewerData);
+
+ this.alwaysPublish = new Button(mainComposite, SWT.CHECK);
+ FormData always = new FormData();
+ always.left = new FormAttachment(15,0);
+ always.top = new FormAttachment(viewer.getTable(), 5);
+ alwaysPublish.setLayoutData(always);
+ alwaysPublish.setText("Always publish to these servers");
+
+ autoDeploy = new Button(mainComposite, SWT.CHECK);
+ FormData add = new FormData();
+ add.left = new FormAttachment(15,0);
+ add.top = new FormAttachment(alwaysPublish, 5);
+ autoDeploy.setLayoutData(add);
+ autoDeploy.setText("Auto-deploy to selected servers after builds");
+ }
+
+ protected void addListeners() {
+ autoDeploy.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ public void widgetSelected(SelectionEvent e) {
+ autoDeploySelected();
+ }
+ });
+ viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ viewerSelected();
+ }
+ } );
+
+ alwaysPublish.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ public void widgetSelected(SelectionEvent e) {
+ alwaysPublishSelected();
+ }
+ });
+
+ viewer.setContentProvider(new ArrayContentProvider());
+ viewer.setLabelProvider(new ArchivePublishLabelProvider());
+ viewer.setInput(ServerConverter.getAllDeployableServers());
+ autoDeploy.setEnabled(false);
+ }
+
+ protected void autoDeploySelected() {
+ deployResult = Boolean.toString(autoDeploy.getSelection() &&
autoDeploy.getEnabled());
+ }
+
+ protected void alwaysPublishSelected() {
+ autoDeploy.setEnabled(alwaysPublish.getSelection());
+ deployResult = Boolean.toString(autoDeploy.getSelection() &&
autoDeploy.getEnabled());
+ alwaysPublishResult = Boolean.toString(alwaysPublish.getSelection());
+ }
+
+ protected void viewerSelected() {
+ ISelection sel = viewer.getSelection();
+ if( sel instanceof IStructuredSelection ) {
+ IStructuredSelection sel2 = (IStructuredSelection)sel;
+ Object[] os = sel2.toArray();
+ String tmp = "";
+ for( int i = 0; i < os.length; i++ ) {
+ tmp += ((IDeployableServer)os[i]).getServer().getId() + ",";
+ }
+ viewerResult = tmp;
+ }
+ }
+ protected String getServers() {
+ return viewerResult;
+ }
+ protected String getAutoDeploy() {
+ return deployResult;
+ }
+ protected String getAlwaysPublish() {
+ return alwaysPublishResult;
+ }
+ }
+
+ protected class ArchivePublishLabelProvider extends LabelProvider {
+ public Image getImage(Object element) {
+ if( element instanceof IDeployableServer ) {
+ IServerType type = ((IDeployableServer)element).getServer().getServerType();
+ return ImageResource.getImage(type.getId());
+ }
+ return null;
+ }
+ public String getText(Object element) {
+ if( element instanceof IDeployableServer ) {
+ return ((IDeployableServer)element).getServer().getName();
+ }
+ return element == null ? "" : element.toString();//$NON-NLS-1$
+ }
+
+ }
+}
\ No newline at end of file
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/EditPublishAction.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/EditPublishAction.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/EditPublishAction.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,22 @@
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.ui.actions.INodeActionDelegate;
+
+public class EditPublishAction implements INodeActionDelegate {
+
+ public boolean isEnabledFor(IArchiveNode node) {
+ if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE)
+ return true;
+ return false;
+ }
+
+ public void run(IArchiveNode node) {
+ ArchivePublishWizard wiz = new ArchivePublishWizard((IArchive)node);
+ new WizardDialog(new Shell(), wiz).open();
+ }
+
+}
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEARAction.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEARAction.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEARAction.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,108 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
+import org.jboss.ide.eclipse.archives.ui.wizards.AbstractArchiveWizard;
+import org.jboss.ide.eclipse.archives.webtools.archivetypes.EarArchiveType;
+
+public class NewEARAction implements IActionDelegate {
+
+ private IStructuredSelection selection;
+ public void run() {
+ AbstractArchiveWizard wizard = new NewEARWizard();
+ wizard.init(PlatformUI.getWorkbench(), selection);
+ WizardDialog dialog = new
WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
+ dialog.open();
+ }
+
+
+ public void run(IAction action) {
+ run();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if( selection instanceof IStructuredSelection)
+ this.selection = (IStructuredSelection)selection;
+ }
+
+ public void init(IViewPart view) {
+ }
+
+ public static class NewEARWizard extends AbstractArchiveWizard {
+
+ private EARPreviewPage earInfoPage;
+
+ public NewEARWizard () {
+ setWindowTitle("New EAR");
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_EAR);
+ }
+
+ public WizardPage[] createWizardPages() {
+ earInfoPage = new EARPreviewPage(this);
+
+ return new WizardPage[] { earInfoPage };
+ }
+
+ public boolean performFinish(IArchive pkg) {
+ pkg.setArchiveType(ArchivesCore.getInstance().getExtensionManager().getArchiveType(EarArchiveType.ID));
+ return true;
+ }
+
+ public String getArchiveExtension() {
+ return "ear";
+ }
+ }
+
+
+ protected static class EARPreviewPage extends PreviewPage {
+ protected EARPreviewPage(NewEARWizard wiz) {
+ super(wiz, "EAR Preview", "EAR Preview",
+ ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_EAR));
+ }
+ protected void addToPackage() {
+ IArchiveType type =
ArchivesCore.getInstance().getExtensionManager().getArchiveType(EarArchiveType.ID);
+ type.fillDefaultConfiguration(wizard.getProject().getName(), wizard.getArchive(),
new NullProgressMonitor());
+ }
+
+ protected String getDescriptionMessage() {
+ return "Preview the EAR\n" +
+ "Later, you can customize this structure further.";
+ }
+ }
+}
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEJBJARAction.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEJBJARAction.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEJBJARAction.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,103 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
+import org.jboss.ide.eclipse.archives.ui.wizards.AbstractArchiveWizard;
+import org.jboss.ide.eclipse.archives.webtools.archivetypes.EjbArchiveType;
+
+public class NewEJBJARAction implements IActionDelegate {
+ private IStructuredSelection selection;
+ public void run() {
+ AbstractArchiveWizard wizard = new NewEJBWizard();
+ wizard.init(PlatformUI.getWorkbench(), selection);
+ WizardDialog dialog = new
WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
+ dialog.open();
+ }
+
+ public void run(IAction action) {
+ run();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if( selection instanceof IStructuredSelection)
+ this.selection = (IStructuredSelection)selection;
+ }
+
+ public static class NewEJBWizard extends AbstractArchiveWizard {
+
+ private EjbJarPreviewPage ejbInfoPage;
+
+ public NewEJBWizard () {
+ setWindowTitle("New EJB JAR");
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_EJB_JAR);
+ }
+
+ public WizardPage[] createWizardPages() {
+ ejbInfoPage = new EjbJarPreviewPage(this);
+
+ return new WizardPage[] { ejbInfoPage };
+ }
+
+ public boolean performFinish(IArchive pkg) {
+ pkg.setArchiveType(ArchivesCore.getInstance().getExtensionManager().getArchiveType(EjbArchiveType.ID));
+ return true;
+ }
+
+ public String getArchiveExtension() {
+ return "jar";
+ }
+ }
+
+
+ protected static class EjbJarPreviewPage extends PreviewPage {
+ protected EjbJarPreviewPage(NewEJBWizard wiz) {
+ super(wiz, "EJB JAR Preview", "EJB JAR Preview",
+ ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_NEW_JAR_WIZARD));
+ }
+ protected void addToPackage() {
+ IArchiveType type =
ArchivesCore.getInstance().getExtensionManager().getArchiveType(EjbArchiveType.ID);
+ type.fillDefaultConfiguration(wizard.getProject().getName(), wizard.getArchive(),
new NullProgressMonitor());
+ }
+
+ protected String getDescriptionMessage() {
+ return "Preview the EJB JAR \n" +
+ "Later, you can customize this structure further.";
+ }
+ }
+
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewEJBJARAction.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewWARAction.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewWARAction.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewWARAction.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,103 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
+import org.jboss.ide.eclipse.archives.ui.ArchivesSharedImages;
+import org.jboss.ide.eclipse.archives.ui.wizards.AbstractArchiveWizard;
+import org.jboss.ide.eclipse.archives.webtools.archivetypes.WarArchiveType;
+
+public class NewWARAction implements IActionDelegate {
+ private IStructuredSelection selection;
+ public void run() {
+ NewWARWizard wizard = new NewWARWizard();
+ wizard.init(PlatformUI.getWorkbench(), selection);
+ WizardDialog dialog = new
WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
+ dialog.open();
+ }
+
+ public void run(IAction action) {
+ run();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if( selection instanceof IStructuredSelection)
+ this.selection = (IStructuredSelection)selection;
+ }
+
+
+ public static class NewWARWizard extends AbstractArchiveWizard {
+
+ private WarPreviewPage warInfoPage;
+
+ public NewWARWizard ()
+ {
+ setWindowTitle("New WAR");
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public WizardPage[] createWizardPages() {
+ warInfoPage = new WarPreviewPage(this);
+
+ return new WizardPage[] { warInfoPage };
+ }
+
+ public boolean performFinish(IArchive pkg) {
+ pkg.setArchiveType(ArchivesCore.getInstance().getExtensionManager().getArchiveType(WarArchiveType.WAR_PACKAGE_TYPE));
+ return true;
+ }
+
+ public String getArchiveExtension() {
+ return "war";
+ }
+ }
+
+ protected static class WarPreviewPage extends PreviewPage {
+ protected WarPreviewPage(NewWARWizard wiz) {
+ super(wiz, "WAR Archive Stub", "WAR Archive Stub",
+ ArchivesSharedImages.getImageDescriptor(ArchivesSharedImages.IMG_NEW_WAR_WIZARD));
+ }
+ protected void addToPackage() {
+ IArchiveType type =
ArchivesCore.getInstance().getExtensionManager().getArchiveType(WarArchiveType.WAR_PACKAGE_TYPE);
+ type.fillDefaultConfiguration(wizard.getProject().getName(), wizard.getArchive(),
new NullProgressMonitor());
+ }
+
+ protected String getDescriptionMessage() {
+ return "Below is a stub archive configuration for your project. \n" +
+ "You can customize this structure further after pressing finish.";
+ }
+ }
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/NewWARAction.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PreviewPage.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PreviewPage.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PreviewPage.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,255 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.internal.ServerPlugin;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
+import org.jboss.ide.eclipse.archives.ui.providers.ArchivesContentProviderDelegate;
+import org.jboss.ide.eclipse.archives.ui.providers.ArchivesLabelProvider;
+import org.jboss.ide.eclipse.archives.ui.wizards.AbstractArchiveWizard;
+import org.jboss.ide.eclipse.archives.ui.wizards.WizardPageWithNotification;
+
+public abstract class PreviewPage extends WizardPageWithNotification {
+
+ private Group previewGroup;
+ protected AbstractArchiveWizard wizard;
+ private TreeViewer previewViewer;
+ private boolean hasCreated = false;
+ public PreviewPage (AbstractArchiveWizard wizard, String name, String title,
ImageDescriptor descriptor ) {
+ super( name, title, descriptor);
+ this.wizard = wizard;
+ }
+
+ protected abstract String getDescriptionMessage();
+ public void createControl(Composite parent) {
+
+ setMessage(getDescriptionMessage());
+ Composite main = new Composite(parent, SWT.NONE);
+ main.setLayout(new FormLayout());
+
+ layoutGroups(main);
+ fillGroups();
+
+ setControl(main);
+ }
+ protected void layoutGroups(Composite main) {
+ previewGroup = new Group(main, SWT.NONE);
+ previewGroup.setText("Preview");
+ FormData previewData = new FormData();
+ previewData.left = new FormAttachment(0,5);
+ previewData.right = new FormAttachment(100,-5);
+ previewData.top = new FormAttachment(0,5);
+ previewData.bottom = new FormAttachment(100,-5);
+ previewGroup.setLayoutData(previewData);
+ previewGroup.setLayout(new FormLayout());
+ previewViewer = new TreeViewer(previewGroup);
+ previewViewer.setLabelProvider(new ArchivesLabelProvider());
+ previewViewer.setContentProvider(new ArchivesContentProviderDelegate());
+ FormData warPreviewData = new FormData();
+ warPreviewData.left = new FormAttachment(0,5);
+ warPreviewData.right = new FormAttachment(100,-5);
+ warPreviewData.top = new FormAttachment(0,5);
+ warPreviewData.bottom = new FormAttachment(100,-5);
+ previewViewer.getTree().setLayoutData(warPreviewData);
+
+ }
+
+ protected void fillGroups() {
+ }
+ public boolean isPageComplete() {
+ return hasCreated;
+ }
+ public void pageEntered(int button) {
+ if( !hasCreated ) {
+ addToPackage();
+ hasCreated = true;
+ }
+ fillWidgets(wizard.getArchive());
+
+ // if it's already a module type project, hide the meta inf stuff
+ IModuleArtifact moduleArtifacts[] =
ServerPlugin.getModuleArtifacts(wizard.getProject());
+ if( moduleArtifacts != null && moduleArtifacts.length > 0) {
+ FormData d = (FormData)previewGroup.getLayoutData();
+ d.top = new FormAttachment(0,5);
+ previewGroup.setLayoutData(d);
+ ((Composite)getControl()).layout();
+ }
+ getWizard().getContainer().updateButtons();
+ }
+
+ protected abstract void addToPackage();
+ protected void fillWidgets(IArchive pkg) {
+ previewViewer.setInput(pkg);
+ previewViewer.expandAll();
+ }
+
+ protected IArchiveFolder getFolder(IArchive pkg, String folderName) {
+ IArchiveFolder result = null;
+ IArchiveFolder[] folders = pkg.getFolders();
+ for( int i = 0; i < folders.length; i++ ) {
+ if( folders[i].getName().equals(folderName)) {
+ result = folders[i];
+ break;
+ }
+ }
+ return result;
+ }
+
+ public void pageExited(int button) {}
+
+
+
+
+ // stuff that can be extracted
+ public static class WorkspaceFolderSelectionDialog extends ElementTreeSelectionDialog
{
+
+ public WorkspaceFolderSelectionDialog(Shell parent, boolean allowMultiple, String
selectedPaths) {
+ super(parent, new FolderLabelProvider(), new FolderContentProvider());
+ setAllowMultiple(allowMultiple);
+ setupDestinationList();
+ setupInitialSelections(selectedPaths);
+ }
+
+ private void setupDestinationList () {
+ List projects =
Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
+ setInput(projects);
+ }
+ private void setupInitialSelections(String initialSelection) {
+ ArrayList resources = new ArrayList();
+ String[] paths = initialSelection.split(",");
+ // find IResources
+ IResource res;
+ for( int i = 0; i < paths.length; i++ ) {
+ res = ResourcesPlugin.getWorkspace().getRoot().findMember(paths[i]);
+ resources.add(res);
+ }
+ setInitialSelections((IResource[]) resources.toArray(new
IResource[resources.size()]));
+ }
+
+ private static class FolderContentProvider implements ITreeContentProvider {
+ private static final Object[] NO_CHILDREN = new Object[0];
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof IContainer) {
+ IContainer container = (IContainer) parentElement;
+ try {
+ IResource members[] = container.members();
+ List folders = new ArrayList();
+ for (int i = 0; i < members.length; i++) {
+ if (members[i].getType() == IResource.FOLDER) folders.add(members[i]);
+ }
+ return folders.toArray();
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ return NO_CHILDREN;
+ }
+
+ public Object getParent(Object element) {
+ if (element instanceof IContainer) {
+ return ((IContainer) element).getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ Object[] results = getChildren(element);
+ return results != null && results.length > 0;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof Collection)
+ return ((Collection)inputElement).toArray();
+
+ return NO_CHILDREN;
+ }
+
+ public void dispose() {}
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ }
+
+ public static class FolderLabelProvider implements ILabelProvider {
+ public FolderLabelProvider () {}
+ public Image getImage(Object element) {
+ if (element instanceof IProject) {
+ return
PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
+ } else if (element instanceof IFolder) {
+ return
PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
+ }
+ return null;
+ }
+
+ public String getText(Object element) {
+ if (element instanceof IContainer) {
+ return ((IContainer)element).getName();
+ }
+ return "";
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return true;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ }
+ }
+
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PreviewPage.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PublishAction.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PublishAction.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PublishAction.java 2008-08-23
00:25:19 UTC (rev 9877)
@@ -0,0 +1,89 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * 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
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.webtools.ui;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.ui.actions.INodeActionDelegate;
+import org.jboss.ide.eclipse.archives.webtools.modules.ArchivesBuildListener;
+
+public class PublishAction implements INodeActionDelegate {
+
+
+ public PublishAction() {
+ }
+
+ public void run (IArchiveNode node) {
+ if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE
+ && ((IArchive)node).isTopLevel()) {
+ final IArchive pkg = (IArchive)node;
+ String servers = node.getProperty(ArchivesBuildListener.DEPLOY_SERVERS);
+ if( servers == null || "".equals(servers) ||
anyServerDoesntExist(servers)){
+ servers = showSelectServersDialog(pkg);
+ }
+ final String servers2 = servers;
+ if( servers != null ) {
+ Job j = new Job("Build Archive") {
+ protected IStatus run(IProgressMonitor monitor) {
+ ArchivesBuildListener.publish(pkg, servers2, IServer.PUBLISH_FULL);
+ return Status.OK_STATUS;
+ } };
+ j.schedule();
+ }
+ }
+ }
+
+ protected boolean anyServerDoesntExist(String servers) {
+ String[] asArray = servers.split(",");
+ for( int i = 0; i < asArray.length; i++ )
+ if( ServerCore.findServer(asArray[i]) == null )
+ return true;
+ return false;
+ }
+ public boolean isEnabledFor(IArchiveNode node) {
+ if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE ) {
+ IArchive pkg = (IArchive) node;
+ if (pkg.isTopLevel()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected String showSelectServersDialog(IArchive node) {
+ ArchivePublishWizard wiz = new ArchivePublishWizard(node);
+ int result = new WizardDialog(new Shell(), wiz).open();
+ if( result == Window.OK) {
+ return wiz.getServers();
+ }
+ return null;
+ }
+}
Property changes on:
trunk/core/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/PublishAction.java
___________________________________________________________________
Name: svn:executable
+ *