[jbosstools-commits] JBoss Tools SVN: r9186 - in trunk/portlet/plugins/org.jboss.tools.portlet.core: META-INF and 13 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Sat Jul 19 21:46:54 EDT 2008


Author: snjeza
Date: 2008-07-19 21:46:54 -0400 (Sat, 19 Jul 2008)
New Revision: 9186

Added:
   trunk/portlet/plugins/org.jboss.tools.portlet.core/.classpath
   trunk/portlet/plugins/org.jboss.tools.portlet.core/.project
   trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF
   trunk/portlet/plugins/org.jboss.tools.portlet.core/build.properties
   trunk/portlet/plugins/org.jboss.tools.portlet.core/plugin.xml
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/1.0/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/1.0/portal-common-lib.jar
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/1.0/portal-portlet-jsr168api-lib.jar
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/2.0/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/2.0/portal-common-lib.jar
   trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/2.0/portlet-api.jar
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/BasePortletClasspathContainer.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet10LibrariesContainerInitializer.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet20LibrariesContainerInitializer.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDataModelProvider.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDelegate.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetPrimaryRuntimeChangedListener.java
   trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetUninstallDelegate.java
Log:
JBIDE-2233 Ability to create a new "Portlet" project

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/.classpath
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/.classpath	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/.classpath	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/.project
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/.project	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/.project	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.jboss.tools.portlet.core</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/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/META-INF/MANIFEST.MF	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Portlet Core Plug-in
+Bundle-SymbolicName: org.jboss.tools.portlet.core;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.jboss.tools.portlet.core.PortletCoreActivator
+Bundle-Vendor: Red Hat, Inc.
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.core.resources,
+ org.eclipse.wst.common.frameworks,
+ org.eclipse.jst.j2ee,
+ org.eclipse.jdt.core,
+ org.jboss.ide.eclipse.as.classpath.core
+Bundle-ActivationPolicy: lazy
+Export-Package: org.jboss.tools.portlet.core,
+ org.jboss.tools.portlet.core.internal,
+ org.jboss.tools.portlet.core.internal.project.facet

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/build.properties
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/build.properties	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/build.properties	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml,\
+               resources/

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/plugin.xml
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/plugin.xml	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/plugin.xml	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+   <extension point="org.eclipse.wst.common.project.facet.core.facets">
+      
+      <project-facet id="jboss.portlet">
+    	<label>JBoss Portlet</label>
+    	<description>
+      		Adds support for the Java Portlet API.
+    	</description>
+    	<default-version version="2.0"/>
+  	  </project-facet>
+  	  
+  	  <project-facet-version facet="jboss.portlet" version="1.0">
+      	<constraint>
+        	<and>
+          		<requires facet="jst.java" version="[5.0"/>
+          		<requires facet="jst.web" version="[2.3"/>
+        	</and>
+      	</constraint>
+      </project-facet-version>
+      
+      <project-facet-version facet="jboss.portlet" version="2.0">
+      	<constraint>
+        	<and>
+          		<requires facet="jst.java" version="[5.0"/>
+          		<requires facet="jst.web" version="[2.5"/>
+        	</and>
+      	</constraint>
+      </project-facet-version>
+      
+      <action id="jboss.portlet.install" facet="jboss.portlet" type="INSTALL" version="[1.0">
+      	<delegate class="org.jboss.tools.portlet.core.internal.project.facet.PortletFacetInstallDelegate"/>
+        <config-factory class="org.jboss.tools.portlet.core.internal.project.facet.PortletFacetInstallDataModelProvider"/>
+      </action>  
+      
+      <action id="jboss.portlet.uninstall" facet="jboss.portlet" type="UNINSTALL" version="[1.0" >
+	 	<delegate class="org.jboss.tools.portlet.core.internal.project.facet.PortletFacetUninstallDelegate"/>
+ 	  </action>
+      
+   </extension>
+
+   <extension
+        point="org.eclipse.wst.common.project.facet.core.presets">
+     <static-preset id="preset.jboss.portlet.v20">
+	    <label>Portlet Project v2.0</label>
+	    <facet id="jst.java" version="5.0" />
+	    <facet id="jst.web" version="2.5"/>
+	    <facet id="jboss.portlet" version="2.0" />
+        <description>Portlet Project v2.0</description>
+     </static-preset>
+   </extension>
+   
+   <extension
+        point="org.eclipse.wst.common.project.facet.core.presets">
+     <static-preset id="preset.jboss.portlet.v10">
+        <label>Portlet Project v1.0</label>
+	    <facet id="jst.java" version="5.0" />
+	    <facet id="jst.web" version="2.3"/>
+	    <facet id="jboss.portlet" version="1.0" />
+	    <description>Portlet Project v1.0</description>
+     </static-preset>
+   </extension>
+   
+   <extension point="org.eclipse.wst.common.project.facet.core.runtimes">
+    	<supported>
+			<runtime-component any="true"/>
+        		<facet id="jboss.portlet" version="1.0,2.0"/> 
+    	</supported>
+   </extension>
+    
+   <extension
+        point="org.eclipse.wst.common.project.facet.core.listeners">
+     <listener
+           class="org.jboss.tools.portlet.core.internal.project.facet.PortletFacetPrimaryRuntimeChangedListener"
+           eventTypes="PRIMARY_RUNTIME_CHANGED">
+     </listener>
+   </extension>
+   
+   <extension point="org.eclipse.jdt.core.classpathContainerInitializer">
+     <classpathContainerInitializer class="org.jboss.tools.portlet.core.internal.Portlet10LibrariesContainerInitializer"
+      id="org.jboss.tools.portlet.core.internal.portletlibrarycontainer.v10"/>
+   </extension>
+   <extension point="org.eclipse.jdt.core.classpathContainerInitializer">
+     <classpathContainerInitializer class="org.jboss.tools.portlet.core.internal.Portlet20LibrariesContainerInitializer"
+      id="org.jboss.tools.portlet.core.internal.portletlibrarycontainer.v20"/>
+   </extension>
+  
+</plugin>

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/1.0/portal-common-lib.jar
===================================================================
(Binary files differ)


Property changes on: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/1.0/portal-common-lib.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/1.0/portal-portlet-jsr168api-lib.jar
===================================================================
(Binary files differ)


Property changes on: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/1.0/portal-portlet-jsr168api-lib.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/2.0/portal-common-lib.jar
===================================================================
(Binary files differ)


Property changes on: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/2.0/portal-common-lib.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/2.0/portlet-api.jar
===================================================================
(Binary files differ)


Property changes on: trunk/portlet/plugins/org.jboss.tools.portlet.core/resources/portlet/2.0/portlet-api.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/IPortletConstants.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,36 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.portlet.core;
+
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * @author snjeza
+ * 
+ */
+
+public interface IPortletConstants {
+
+	static final String PORTLET_FACET_ID="jboss.portlet";
+	
+	static final String CONFIG_PATH = "WEB-INF/portlet.xml";
+	
+	static final String PORTLET_FACET_VERSION_10 = "1.0";
+	
+	static final String PORTLET_FACET_VERSION_20 = "2.0";
+
+	static final String PORTLET_CONTAINER_10_ID = "org.jboss.tools.portlet.core.internal.portletlibrarycontainer.v10";
+	
+	static final String PORTLET_CONTAINER_20_ID = "org.jboss.tools.portlet.core.internal.portletlibrarycontainer.v20";
+
+	static final String PORTLET_INSTANCES_FILE = "WEB-INF/portlet-instances.xml";
+	
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/PortletCoreActivator.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,176 @@
+package org.jboss.tools.portlet.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jst.j2ee.model.IModelProvider;
+import org.eclipse.jst.j2ee.model.ModelProviderManager;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class PortletCoreActivator extends Plugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "org.jboss.tools.portlet.core";
+
+	// The shared instance
+	private static PortletCoreActivator plugin;
+	
+	/**
+	 * The constructor
+	 */
+	public PortletCoreActivator() {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+		plugin = this;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.core.runtime.Plugin#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 PortletCoreActivator getDefault() {
+		return plugin;
+	}
+
+	/**
+	 * @param webProject
+	 * @return IModelProvider
+	 */
+	public static IModelProvider getModelProvider(IProject webProject) {
+		IModelProvider provider = ModelProviderManager.getModelProvider(webProject); 
+		Object webAppObj = provider.getModelObject();
+		if (webAppObj == null){			
+			return null;
+		}			
+		return provider;
+	}
+	
+	public static IStatus getStatus(String message) {
+		return new Status(IStatus.ERROR,PLUGIN_ID,message);
+		
+	}
+
+	public static void createPortletXml(String versionString,IProject project, IProgressMonitor monitor) {
+		IPath portletXmlPath = ComponentCore.createComponent(project)
+		.getRootFolder().getUnderlyingFolder().getRawLocation().append(
+				new Path(IPortletConstants.CONFIG_PATH));
+		StringBuffer buffer = new StringBuffer();
+		buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+		
+		if (IPortletConstants.PORTLET_FACET_VERSION_20.equals(versionString)) {
+			buffer.append("<portlet-app xmlns=\"http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd\"");
+			buffer.append("\n\t");
+            buffer.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
+            buffer.append("\n\t");
+            buffer.append("xsi:schemaLocation=\"http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd\" ");
+            buffer.append("\n\t");
+            buffer.append("version=\"2.0\">");
+		} else {
+			buffer.append("<portlet-app xmlns=\"http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd\"");
+			buffer.append("\n\t");
+            buffer.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
+            buffer.append("\n\t");
+            buffer.append("xsi:schemaLocation=\"http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd\"");
+            buffer.append("\n\t");
+            buffer.append("version=\"1.0\">");
+		}
+		buffer.append("\n\n");
+		buffer.append("</portlet-app>");
+		buffer.append("\n");
+		OutputStream outputStream = null;
+		try {
+			IPath directory = portletXmlPath.removeLastSegments(1);
+			directory.toFile().mkdirs();
+			File file = portletXmlPath.toFile();
+			file.createNewFile();
+			outputStream = new FileOutputStream(file);
+			PrintWriter printWriter = new PrintWriter(outputStream);
+			printWriter.write(buffer.toString());
+			printWriter.close();
+		} catch (Exception e) {
+			log(e);
+		} finally {
+			if (outputStream != null) {
+				try {
+					outputStream.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+		
+	}
+
+	public static void log(Exception e, String message) {
+		IStatus status = new Status(IStatus.ERROR,PLUGIN_ID,message,e);
+		PortletCoreActivator.getDefault().getLog().log(status);
+	}
+	
+	public static void log(Throwable e) {
+		IStatus status = new Status(IStatus.ERROR,PLUGIN_ID,e.getLocalizedMessage(),e);
+		PortletCoreActivator.getDefault().getLog().log(status);
+	}
+
+	public static void createPortletInstances(IProject project, IFile file) throws CoreException, UnsupportedEncodingException {
+		
+		StringBuffer buffer = new StringBuffer();
+		buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+		buffer.append("<!DOCTYPE deployments PUBLIC \n");
+        buffer.append("\"-//JBoss Portal//DTD Portlet Instances 2.6//EN\"\n");
+        buffer.append("\"http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd\">");
+        buffer.append("<deployments>");
+        buffer.append("</deployments>");
+		
+        ByteArrayInputStream source = new ByteArrayInputStream(buffer.toString().getBytes("UTF8"));
+        file.create(source, true, new NullProgressMonitor());
+	}
+	
+public static void createPortletObject(IProject project, IFile file) throws CoreException, UnsupportedEncodingException {
+		
+		StringBuffer buffer = new StringBuffer();
+		buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+		buffer.append("<!DOCTYPE deployments PUBLIC \n");
+        buffer.append("\"-//JBoss Portal//DTD Portal Object 2.6//EN\"\n");
+        buffer.append("\"http://www.jboss.org/portal/dtd/portal-object_2_6.dtd\">");
+        buffer.append("<deployments>");
+        buffer.append("</deployments>");
+		
+        ByteArrayInputStream source = new ByteArrayInputStream(buffer.toString().getBytes("UTF8"));
+        file.create(source, true, new NullProgressMonitor());
+	}
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/BasePortletClasspathContainer.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/BasePortletClasspathContainer.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/BasePortletClasspathContainer.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,95 @@
+package org.jboss.tools.portlet.core.internal;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.jboss.ide.eclipse.as.classpath.core.jee.AbstractClasspathContainer;
+import org.jboss.ide.eclipse.as.classpath.core.xpl.ClasspathDecorations;
+import org.jboss.tools.portlet.core.PortletCoreActivator;
+
+public abstract class BasePortletClasspathContainer extends AbstractClasspathContainer {
+		private static final String PORTLET_FOLDER = "portlet";
+		public final static String SUFFIX = PORTLET_FOLDER;//$NON-NLS-1$
+		public final static String PREFIX = "org.jboss.tools.portlet.core";
+		private static final String RESOURCES_FOLDER = "resources";
+
+		public BasePortletClasspathContainer(IPath path, String description,String suffix) {
+			super(path, description, suffix);
+		}
+
+		@Override
+		protected String getBaseDir() {
+			try {
+				URL installURL = FileLocator.toFileURL(PortletCoreActivator
+						.getDefault().getBundle().getEntry("/"));
+				return installURL.getFile().toString();
+			} catch (IOException e) {
+				PortletCoreActivator
+						.log(e, "Error loading classpath container");
+			}
+			return null;
+		}
+
+		@Override
+		protected IClasspathEntry[] computeEntries() {
+			ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
+
+			String baseDir = getBaseDir();
+			if (baseDir == null)
+				return new IClasspathEntry[0];
+
+			String version = getPortletVersion();
+			File libDir = new File(baseDir
+					+ "/" + RESOURCES_FOLDER + "/" + PORTLET_FOLDER + "/" + version);//$NON-NLS-1$ //$NON-NLS-2$
+
+			File[] jars = libDir.listFiles(new FileFilter() {
+				public boolean accept(File file) {
+					return (file.toString().endsWith(".jar"));//$NON-NLS-1$
+				}
+			});
+
+			if (jars != null) {
+				for (int i = 0; i < jars.length; i++) {
+					File jarFile = jars[i];
+
+					IPath entryPath = new Path(jarFile.toString());
+
+					IPath sourceAttachementPath = null;
+					IPath sourceAttachementRootPath = null;
+
+					final ClasspathDecorations dec = decorations
+							.getDecorations(getDecorationManagerKey(getPath()
+									.toString()), entryPath.toString());
+
+					IClasspathAttribute[] attrs = {};
+					if (dec != null) {
+						sourceAttachementPath = dec.getSourceAttachmentPath();
+						sourceAttachementRootPath = dec
+								.getSourceAttachmentRootPath();
+						attrs = dec.getExtraAttributes();
+					}
+
+					IAccessRule[] access = {};
+					IClasspathEntry entry = JavaCore.newLibraryEntry(entryPath,
+							sourceAttachementPath, sourceAttachementRootPath,
+							access, attrs, false);
+					entries.add(entry);
+				}
+			}
+
+			return entries.toArray(new IClasspathEntry[entries.size()]);
+		}
+
+		protected abstract String getPortletVersion();
+
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet10LibrariesContainerInitializer.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet10LibrariesContainerInitializer.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet10LibrariesContainerInitializer.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,54 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.portlet.core.internal;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaProject;
+import org.jboss.ide.eclipse.as.classpath.core.jee.AbstractClasspathContainer;
+import org.jboss.ide.eclipse.as.classpath.core.jee.AbstractClasspathContainerInitializer;
+import org.jboss.tools.portlet.core.IPortletConstants;
+
+/**
+ * @author snjeza
+ * 
+ */
+public class Portlet10LibrariesContainerInitializer extends
+		AbstractClasspathContainerInitializer {
+
+	public String getDescription(IPath containerPath, IJavaProject project) {
+		return "JBoss Portlet Classpath Container Initializer v1.0";
+	}
+
+	@Override
+	protected AbstractClasspathContainer createClasspathContainer(IPath path) {
+		return new Portlet10ClasspathContainer(path);
+	}
+
+	@Override
+	protected String getClasspathContainerID() {
+		return IPortletConstants.PORTLET_CONTAINER_10_ID;
+	}
+
+	private class Portlet10ClasspathContainer extends BasePortletClasspathContainer {
+
+		public final static String DESCRIPTION = "JBoss Portlet Libraries v1.0";
+
+		public Portlet10ClasspathContainer(IPath path) {
+			super(path, DESCRIPTION, SUFFIX);
+		}
+
+		@Override
+		protected String getPortletVersion() {
+			return IPortletConstants.PORTLET_FACET_VERSION_10;
+		}
+		
+	}
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet20LibrariesContainerInitializer.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet20LibrariesContainerInitializer.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/Portlet20LibrariesContainerInitializer.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,54 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.portlet.core.internal;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaProject;
+import org.jboss.ide.eclipse.as.classpath.core.jee.AbstractClasspathContainer;
+import org.jboss.ide.eclipse.as.classpath.core.jee.AbstractClasspathContainerInitializer;
+import org.jboss.tools.portlet.core.IPortletConstants;
+
+/**
+ * @author snjeza
+ * 
+ */
+public class Portlet20LibrariesContainerInitializer extends
+		AbstractClasspathContainerInitializer {
+
+	public String getDescription(IPath containerPath, IJavaProject project) {
+		return "JBoss Portlet Classpath Container Initializer v2.0";
+	}
+
+	@Override
+	protected AbstractClasspathContainer createClasspathContainer(IPath path) {
+		return new Portlet10ClasspathContainer(path);
+	}
+
+	@Override
+	protected String getClasspathContainerID() {
+		return IPortletConstants.PORTLET_CONTAINER_20_ID;
+	}
+
+	private class Portlet10ClasspathContainer extends BasePortletClasspathContainer {
+
+		public final static String DESCRIPTION = "JBoss Portlet Libraries v2.0";
+
+		public Portlet10ClasspathContainer(IPath path) {
+			super(path, DESCRIPTION, SUFFIX);
+		}
+
+		@Override
+		protected String getPortletVersion() {
+			return IPortletConstants.PORTLET_FACET_VERSION_20;
+		}
+		
+	}
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDataModelProvider.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDataModelProvider.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDataModelProvider.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,31 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.portlet.core.internal.project.facet;
+
+import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
+import org.jboss.tools.portlet.core.IPortletConstants;
+
+/**
+ * @author snjeza
+ * 
+ */
+public class PortletFacetInstallDataModelProvider extends
+		FacetInstallDataModelProvider implements IPortletConstants {
+
+	@Override
+	public Object getDefaultProperty(String propertyName) {
+		if(propertyName.equals(FACET_ID)){
+			return IPortletConstants.PORTLET_FACET_ID;
+		}
+		return super.getDefaultProperty(propertyName);
+	}
+
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDelegate.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDelegate.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetInstallDelegate.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,127 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.portlet.core.internal.project.facet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jst.j2ee.model.IModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.jboss.tools.portlet.core.IPortletConstants;
+import org.jboss.tools.portlet.core.PortletCoreActivator;
+
+/**
+ * @author snjeza
+ * 
+ */
+public class PortletFacetInstallDelegate implements IDelegate {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.eclipse.wst.common.project.facet.core.IDelegate#execute(org.eclipse
+	 * .core.resources.IProject,
+	 * org.eclipse.wst.common.project.facet.core.IProjectFacetVersion,
+	 * java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void execute(final IProject project, final IProjectFacetVersion fv,
+			final Object cfg, final IProgressMonitor monitor)
+			throws CoreException {
+
+		if (monitor != null) {
+			monitor.beginTask("", 1);
+		}
+		try {
+			IDataModel config = null;
+
+			if (cfg != null) {
+				config = (IDataModel) cfg;
+			} else {
+				throw new CoreException(
+						PortletCoreActivator
+								.getStatus("Internal Error creating JBoss Portlet Facet.  Missing configuration."));
+			}
+
+			// check whether web.xml is available for update
+			IModelProvider provider = PortletCoreActivator
+					.getModelProvider(project);
+			if (provider == null) {
+				throw new CoreException(
+						PortletCoreActivator
+								.getStatus("Cannot configure web module for JBoss Portlet Facet"));
+			} else if (!(provider.validateEdit(null, null).isOK())) {
+				if (!(provider.validateEdit(null, null).isOK())) {
+					throw new CoreException(PortletCoreActivator
+							.getStatus("The web.xml file is not updateable"));
+				}
+			}
+
+			IJavaProject javaProject = JavaCore.create(project);	
+			
+			IPath containerPath = null;
+			if (IPortletConstants.PORTLET_FACET_VERSION_10.equals(fv.getVersionString())) {
+				containerPath = new Path(IPortletConstants.PORTLET_CONTAINER_10_ID);
+			} else {
+				containerPath = new Path(IPortletConstants.PORTLET_CONTAINER_20_ID);
+			}
+			
+			IClasspathEntry entry = JavaCore.newContainerEntry(containerPath, true);
+			IClasspathEntry[] entries = javaProject.getRawClasspath();
+			IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
+			System.arraycopy( entries, 0, newEntries, 0, entries.length );
+			newEntries[entries.length] = entry;
+			javaProject.setRawClasspath(newEntries, monitor);
+			
+			
+			createPortletXml(project, fv, config, monitor);
+
+			if (monitor != null) {
+				monitor.worked(1);
+			}
+
+		} finally {
+			if (monitor != null) {
+				monitor.done();
+			}
+		}
+	}
+
+	private void createPortletXml(final IProject project,
+			final IProjectFacetVersion fv, IDataModel config,
+			final IProgressMonitor monitor) {
+
+		try {
+			final IWorkspaceRunnable op = new IWorkspaceRunnable() {
+				public void run(IProgressMonitor monitor_inner)
+						throws CoreException {
+					PortletCoreActivator
+							.createPortletXml(fv.getVersionString(),project, monitor);
+					project.refreshLocal(IResource.DEPTH_INFINITE,
+							monitor_inner);
+				}
+			};
+			op.run(monitor);
+		} catch (CoreException e) {
+			PortletCoreActivator.log(e,
+					"Exception occured while creating portlet.xml");
+		}
+	}
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetPrimaryRuntimeChangedListener.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetPrimaryRuntimeChangedListener.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetPrimaryRuntimeChangedListener.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,14 @@
+package org.jboss.tools.portlet.core.internal.project.facet;
+
+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
+
+public class PortletFacetPrimaryRuntimeChangedListener implements
+		IFacetedProjectListener {
+
+	public void handleEvent(IFacetedProjectEvent event) {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

Added: trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetUninstallDelegate.java
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetUninstallDelegate.java	                        (rev 0)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.core/src/org/jboss/tools/portlet/core/internal/project/facet/PortletFacetUninstallDelegate.java	2008-07-20 01:46:54 UTC (rev 9186)
@@ -0,0 +1,34 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.portlet.core.internal.project.facet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+
+/**
+ * @author snjeza
+ *
+ */
+public class PortletFacetUninstallDelegate implements IDelegate {
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.wst.common.project.facet.core.IDelegate#execute(org.eclipse.core.resources.IProject, org.eclipse.wst.common.project.facet.core.IProjectFacetVersion, java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void execute(IProject project, IProjectFacetVersion fv,
+			Object config, IProgressMonitor monitor) throws CoreException {
+		// TODO Auto-generated method stub
+
+	}
+
+}




More information about the jbosstools-commits mailing list