Author: vrubezhny
Date: 2007-09-07 14:31:25 -0400 (Fri, 07 Sep 2007)
New Revision: 3495
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/WtpUtils.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-825 Seam projects shold know what version and seam
home library they are using
Create source folder method is added
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2007-09-07 18:26:01
UTC (rev 3494)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2007-09-07 18:31:25
UTC (rev 3495)
@@ -37,7 +37,8 @@
org.jboss.ide.eclipse.as.core,
org.eclipse.wst.server.core,
org.eclipse.jpt.core,
- org.eclipse.jpt.ui
+ org.eclipse.jpt.ui,
+ org.eclipse.core.filesystem
Provide-Package: org.jboss.tools.seam.core,
org.jboss.tools.seam.internal.core,
org.jboss.tools.seam.internal.core.scanner,
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/WtpUtils.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/WtpUtils.java 2007-09-07
18:26:01 UTC (rev 3494)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/project/facet/WtpUtils.java 2007-09-07
18:31:25 UTC (rev 3495)
@@ -11,22 +11,36 @@
package org.jboss.tools.seam.internal.core.project.facet;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
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.SubProgressMonitor;
import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaModelStatus;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.util.CoreUtility;
import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
@@ -114,4 +128,134 @@
}
return "";
}
+
+ public static IResource createSourceFolder (IProject project, IPath path) {
+ IJavaProject javaProject;
+ IClasspathEntry[] javaProjectEntries;
+ IPath outputLocation;
+ IWorkspaceRoot workspaceRoot;
+
+ if (project == null || !project.exists()) {
+ return null;
+ }
+ if (!project.isOpen()) {
+ return null;
+ }
+ try {
+ if (!project.hasNature(JavaCore.NATURE_ID))
+ return null;
+
+ javaProject= JavaCore.create(project);
+ javaProjectEntries= javaProject.getRawClasspath();
+ outputLocation= javaProject.getOutputLocation();
+ workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
+
+ IPath projPath= javaProject.getProject().getFullPath();
+ IPath newSourceFolderPath = projPath.append(path);
+
+ IStatus validate=
workspaceRoot.getWorkspace().validatePath(newSourceFolderPath.toString(),
IResource.FOLDER);
+ if (validate.matches(IStatus.ERROR))
+ return null;
+
+ IResource res= workspaceRoot.findMember(newSourceFolderPath);
+ if (res != null) {
+ if (res.getType() != IResource.FOLDER) {
+ return null;
+ }
+ } else {
+ URI projLocation= javaProject.getProject().getLocationURI();
+ if (projLocation != null) {
+ try {
+ IFileStore store= EFS.getStore(projLocation).getChild(path.toString());
+ if (store.fetchInfo().exists()) {
+ return null;
+ }
+ } catch (CoreException e) {
+ }
+ }
+ }
+ ArrayList newEntries= new ArrayList(javaProjectEntries.length + 1);
+ int projectEntryIndex= -1;
+
+ for (int i= 0; i < javaProjectEntries.length; i++) {
+ IClasspathEntry curr= javaProjectEntries[i];
+ if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ if (newSourceFolderPath.equals(curr.getPath())) {
+ return null;
+ }
+ if (projPath.equals(curr.getPath())) {
+ projectEntryIndex= i;
+ }
+ }
+ newEntries.add(curr);
+ }
+
+ IClasspathEntry newEntry= JavaCore.newSourceEntry(newSourceFolderPath);
+ if (projectEntryIndex != -1) {
+ newEntries.set(projectEntryIndex, newEntry);
+ } else {
+ IClasspathEntry entry= JavaCore.newSourceEntry(path);
+ insertClasspathEntry(entry, newEntries);
+ }
+
+ IClasspathEntry[] newClasspathEntries= (IClasspathEntry[]) newEntries.toArray(new
IClasspathEntry[newEntries.size()]);
+ IPath newOutputLocation= outputLocation;
+
+ IJavaModelStatus result= JavaConventions.validateClasspath(javaProject,
newClasspathEntries, newOutputLocation);
+ if (!result.isOK()) {
+ if (outputLocation.equals(projPath)) {
+ newOutputLocation=
projPath.append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
+ result= JavaConventions.validateClasspath(javaProject, newClasspathEntries,
newOutputLocation);
+ if (!result.isOK()) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ IFolder newSourceFolder= javaProject.getProject().getFolder(newSourceFolderPath);
+ if (!newSourceFolder.exists()) {
+ CoreUtility.createFolder(newSourceFolder, true, true, new SubProgressMonitor(new
NullProgressMonitor(), 1));
+ }
+
+ javaProject.setRawClasspath(newClasspathEntries, newOutputLocation, new
NullProgressMonitor());
+
+ return newSourceFolder;
+ } catch (CoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ return null;
+ }
+
+ static private void insertClasspathEntry(IClasspathEntry entry, List entries) {
+ int length= entries.size();
+ IClasspathEntry[] elements= (IClasspathEntry[])entries.toArray(new
IClasspathEntry[length]);
+ int i= 0;
+ while (i < length && elements[i].getEntryKind() != entry.getEntryKind()) {
+ i++;
+ }
+ if (i < length) {
+ i++;
+ while (i < length && elements[i].getEntryKind() == entry.getEntryKind()) {
+ i++;
+ }
+ entries.add(i, entry);
+ return;
+ }
+
+ switch (entry.getEntryKind()) {
+ case IClasspathEntry.CPE_SOURCE:
+ entries.add(0, entry);
+ break;
+ case IClasspathEntry.CPE_CONTAINER:
+ case IClasspathEntry.CPE_LIBRARY:
+ case IClasspathEntry.CPE_PROJECT:
+ case IClasspathEntry.CPE_VARIABLE:
+ default:
+ entries.add(entry);
+ break;
+ }
+ }
+
}