Author: akazakov
Date: 2010-12-08 08:51:55 -0500 (Wed, 08 Dec 2010)
New Revision: 27230
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/templates/
trunk/cdi/plugins/org.jboss.tools.cdi.core/templates/beans.xml
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.core/build.properties
trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDataModelProvider.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDelegate.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/ICDIFacetDataModelProperties.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
Log:
https://jira.jboss.org/browse/JBIDE-7803
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2010-12-08 13:43:12
UTC (rev 27229)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2010-12-08 13:51:55
UTC (rev 27230)
@@ -15,13 +15,15 @@
org.eclipse.wst.common.modulecore,
org.eclipse.wst.common.frameworks,
org.eclipse.wst.validation,
+ org.eclipse.jst.j2ee,
org.jboss.tools.jst.web.kb,
org.jboss.tools.common.el.core,
org.eclipse.ltk.core.refactoring,
org.eclipse.jface.text,
org.eclipse.equinox.preferences,
org.eclipse.wst.sse.core,
- org.eclipse.jdt.ui
+ org.eclipse.jdt.ui,
+ org.apache.ant
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: JBoss by Red Hat
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/build.properties
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/build.properties 2010-12-08 13:43:12 UTC
(rev 27229)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/build.properties 2010-12-08 13:51:55 UTC
(rev 27230)
@@ -5,7 +5,8 @@
.,\
images/,\
plugin.properties,\
- about.html
+ about.html,\
+ templates/
src.includes = src/,\
plugin.xml,\
about.html,\
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml 2010-12-08 13:43:12 UTC (rev
27229)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml 2010-12-08 13:51:55 UTC (rev
27230)
@@ -42,10 +42,22 @@
facet="jst.cdi"
version="1.0">
<constraint>
- <requires
- facet="jst.java"
- version="[5.0">
- </requires>
+ <or>
+ <requires soft="true"
+ facet="jst.ejb"
+ version="[3.0">
+ </requires>
+ <and>
+ <requires soft="true"
+ facet="jst.web"
+ version="[2.5">
+ </requires>
+ <requires
+ facet="jst.java"
+ version="[5.0">
+ </requires>
+ </and>
+ </or>
</constraint>
</project-facet-version>
<action
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-12-08
13:43:12 UTC (rev 27229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-12-08
13:51:55 UTC (rev 27230)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.cdi.core;
+import java.io.File;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
@@ -19,9 +21,17 @@
import java.util.Map;
import java.util.Set;
+import org.apache.tools.ant.util.FileUtils;
+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.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotatable;
import org.eclipse.jdt.core.IAnnotation;
@@ -35,33 +45,58 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
import org.jboss.tools.cdi.internal.core.impl.ClassBean;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.ITextSourceReference;
+import org.jboss.tools.common.zip.UnzipOperation;
import org.jboss.tools.jst.web.kb.IKbProject;
+import org.osgi.framework.Bundle;
/**
* @author Alexey Kazakov
*/
public class CDIUtil {
+ private static File TEMPLATE_FOLDER;
+
/**
* Adds CDI and KB builders to the project.
*
* @param project
+ * @param genearteBeansXml
*/
- public static void enableCDI(IProject project) {
+ public static void enableCDI(IProject project, boolean genearteBeansXml,
IProgressMonitor monitor) {
try {
- EclipseUtil.addNatureToProject(project, CDICoreNature.NATURE_ID);
if (!project.hasNature(IKbProject.NATURE_ID)) {
EclipseResourceUtil.addNatureToProject(project, IKbProject.NATURE_ID);
}
+ EclipseUtil.addNatureToProject(project, CDICoreNature.NATURE_ID);
EclipseResourceUtil.addBuilderToProject(project,
ValidationPlugin.VALIDATION_BUILDER_ID);
+ if(genearteBeansXml) {
+ File beansXml = getBeansXml(project);
+ if(beansXml!=null && !beansXml.exists()) {
+ // Create an empty beans.xml
+ beansXml.getParentFile().mkdir();
+ try {
+ FileUtils.getFileUtils().copyFile(new File(getTemplatesFolder(),
"beans.xml"), beansXml, null, false, false);
+ } catch (IOException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
+ project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ }
} catch (CoreException e) {
CDICorePlugin.getDefault().logError(e);
}
@@ -81,6 +116,80 @@
}
/**
+ * Calculate path to templates folder
+ *
+ * @return path to templates
+ * @throws IOException if templates folder not found
+ */
+ public static File getTemplatesFolder() throws IOException {
+ if(TEMPLATE_FOLDER==null) {
+ Bundle bundle = CDICorePlugin.getDefault().getBundle();
+ String version = bundle.getVersion().toString();
+ IPath stateLocation = Platform.getStateLocation(bundle);
+ File templatesDir = FileLocator.getBundleFile(bundle);
+ if(templatesDir.isFile()) {
+ File toCopy = new File(stateLocation.toFile(),version);
+ if(!toCopy.exists()) {
+ toCopy.mkdirs();
+ UnzipOperation unZip = new UnzipOperation(templatesDir.getAbsolutePath());
+ unZip.execute(toCopy,"templates.*");
+ }
+ templatesDir = toCopy;
+ }
+ TEMPLATE_FOLDER = new File(templatesDir,"templates");
+ }
+ return TEMPLATE_FOLDER;
+ }
+
+ private static final String BEANS_XML_FILE_NAME = "beans.xml"; //$NON-NLS-1$
+
+ /**
+ * Returns java.io.File which represents beans.xml for the project.
+ * If the project is a faceted Java project then <src>/META-INF/beans.xml will be
return.
+ * If there are a few source folders then the folder which contains META-INF folder will
be return.
+ * If there are a few source folders but no any META-INF in them then null will be
return.
+ * If the project is a faceted WAR then /<WebContent>/WEB-INF/beans.xml will be
return.
+ * The beans.xml may or may not exist.
+ * @param project the project
+ * @return java.io.File which represents beans.xml for the project.
+ * @throws CoreException
+ */
+ public static File getBeansXml(IProject project) throws CoreException {
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+ if(facetedProject!=null) {
+ IProjectFacetVersion webVersion =
facetedProject.getProjectFacetVersion(IJ2EEFacetConstants.DYNAMIC_WEB_FACET);
+ if(webVersion!=null) {
+ // WAR
+ IVirtualComponent com = ComponentCore.createComponent(project);
+ if(com!=null && com.getRootFolder()!=null) {
+ IVirtualFolder webInf = com.getRootFolder().getFolder(new
Path("/WEB-INF")); //$NON-NLS-1$
+ if(webInf!=null) {
+ IContainer webInfFolder = webInf.getUnderlyingFolder();
+ if(webInfFolder.isAccessible()) {
+ File file = new File(webInfFolder.getLocation().toFile(), BEANS_XML_FILE_NAME);
+ return file;
+ }
+ }
+ }
+ } else
if(facetedProject.getProjectFacetVersion(ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.JAVA))!=null)
{
+ // JAR
+ Set<IFolder> sources = EclipseResourceUtil.getSourceFolders(project);
+ if(sources.size()==1) {
+ return new File(sources.iterator().next().getLocation().toFile(),
"META-INF/beans.xml"); //$NON-NLS-1$
+ } else {
+ for (IFolder src : sources) {
+ IFolder metaInf = src.getFolder("META-INF");
+ if(metaInf!=null && metaInf.isAccessible()) {
+ return new File(metaInf.getLocation().toFile(), BEANS_XML_FILE_NAME);
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
* Finds CDI injected point in beans for particular java element.
*
* @param beans
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDataModelProvider.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDataModelProvider.java 2010-12-08
13:43:12 UTC (rev 27229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDataModelProvider.java 2010-12-08
13:51:55 UTC (rev 27230)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.project.facet;
+import java.util.Set;
+
import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
/**
@@ -19,6 +21,13 @@
*
*/
public class CDIFacetInstallDataModelProvider extends FacetInstallDataModelProvider
implements ICDIFacetDataModelProperties {
+
+ public Set getPropertyNames() {
+ Set<String> names = super.getPropertyNames();//super.getPropertyNames();
+ names.add(GENERATE_BEANS_XML);
+ return names;
+ }
+
/**
* Returns default value for a given property
*
@@ -28,6 +37,8 @@
public Object getDefaultProperty(String propertyName) {
if (propertyName.equals(FACET_ID)) {
return ICDIFacetDataModelProperties.CDI_FACET_ID;
+ } else if (GENERATE_BEANS_XML.equals(propertyName)) {
+ return Boolean.TRUE;
}
return super.getDefaultProperty(propertyName);
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDelegate.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDelegate.java 2010-12-08
13:43:12 UTC (rev 27229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/CDIFacetInstallDelegate.java 2010-12-08
13:51:55 UTC (rev 27230)
@@ -18,6 +18,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;
+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.cdi.core.CDICoreMessages;
@@ -48,7 +49,9 @@
*/
public void execute(IProject project, IProjectFacetVersion fv,
Object config, IProgressMonitor monitor) throws CoreException {
- CDIUtil.enableCDI(project);
+ IDataModel model = (IDataModel) config;
+ boolean generateBeansXml = model.getBooleanProperty(GENERATE_BEANS_XML);
+ CDIUtil.enableCDI(project, generateBeansXml, monitor);
if(errorOccurs) {
errorOccurs = false;
Display.getDefault().syncExec(
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/ICDIFacetDataModelProperties.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/ICDIFacetDataModelProperties.java 2010-12-08
13:43:12 UTC (rev 27229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/project/facet/ICDIFacetDataModelProperties.java 2010-12-08
13:51:55 UTC (rev 27230)
@@ -29,4 +29,10 @@
* CDI 1.0 Facet Version constant
*/
String CDI_FACET_VERSION_1 = "1.0"; //$NON-NLS-1$
+
+ /**
+ * Generate beans.xml
+ */
+ String GENERATE_BEANS_XML = "cdi.project.generateBeansXml"; //$NON-NLS-1$
+
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java 2010-12-08
13:43:12 UTC (rev 27229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java 2010-12-08
13:51:55 UTC (rev 27230)
@@ -46,6 +46,7 @@
import org.jboss.tools.cdi.core.preferences.CDIPreferences;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -268,7 +269,7 @@
IStatus status = JavaConventions.validateJavaTypeName(typeName,
CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
if(status.getSeverity()!=IStatus.ERROR) {
String packagePath = typeName.replace('.', '/');
- Set<IFolder> sources = validator.getSourceFolders(beansXml.getProject());
+ Set<IFolder> sources =
EclipseResourceUtil.getSourceFolders(beansXml.getProject());
for (IFolder source : sources) {
IPath path = source.getFullPath().append(packagePath + ".java");
//$NON-NLS-1$
validator.getValidationContext().addLinkedCoreResource(beansXml.getFullPath().toOSString(),
path, false);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-08
13:43:12 UTC (rev 27229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-08
13:51:55 UTC (rev 27230)
@@ -34,10 +34,8 @@
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeParameter;
@@ -89,8 +87,8 @@
import org.jboss.tools.cdi.internal.core.impl.ParametedType;
import org.jboss.tools.cdi.internal.core.impl.Parameter;
import org.jboss.tools.cdi.internal.core.impl.SessionBean;
-import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.ITextSourceReference;
import org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper;
import org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager;
@@ -359,33 +357,12 @@
Set<IFolder> sourceFolders = null;
- static Set<IFolder> getSourceFolders(IProject project) {
- Set<IFolder> folders = new HashSet<IFolder>();
- IPackageFragmentRoot[] roots;
- try {
- // From source folders
- IJavaProject javaProject = EclipseUtil.getJavaProject(project);
- roots = javaProject.getPackageFragmentRoots();
- for (int i = 0; i < roots.length; i++) {
- if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
- IResource source = roots[i].getCorrespondingResource();
- if(source instanceof IFolder) {
- folders.add((IFolder)source);
- }
- }
- }
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
- }
- return folders;
- }
-
Set<IFolder> getSourceFoldersForProjectsSet() {
if(sourceFolders==null) {
sourceFolders = new HashSet<IFolder>();
List<IProject> projects = projectSet.getAllProjests();
for (IProject project : projects) {
- sourceFolders.addAll(getSourceFolders(project));
+ sourceFolders.addAll(EclipseResourceUtil.getSourceFolders(project));
}
}
return sourceFolders;
Added: trunk/cdi/plugins/org.jboss.tools.cdi.core/templates/beans.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/templates/beans.xml
(rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/templates/beans.xml 2010-12-08 13:51:55 UTC
(rev 27230)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://docs.jboss.org/cdi/beans_1_0.xsd">
+
+</beans>
\ No newline at end of file
Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.core/templates/beans.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain