[jboss-cvs] jbosside/core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/packages/core/model ...

Marshall Culpepper mculpepper at jboss.com
Fri Feb 23 12:29:28 EST 2007


  User: mculpepper
  Date: 07/02/23 12:29:28

  Modified:    core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/packages/core/model 
                        PackagesCore.java
  Log:
  implemented a new API helper method, getBaseFile. see javadoc for full description
  
  Revision  Changes    Path
  1.16      +62 -0     jbosside/core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/packages/core/model/PackagesCore.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PackagesCore.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/core/plugins/org.jboss.ide.eclipse.packages.core/src/main/org/jboss/ide/eclipse/packages/core/model/PackagesCore.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- PackagesCore.java	21 Feb 2007 19:35:14 -0000	1.15
  +++ PackagesCore.java	23 Feb 2007 17:29:28 -0000	1.16
  @@ -30,12 +30,14 @@
   import org.eclipse.core.resources.IFile;
   import org.eclipse.core.resources.IProject;
   import org.eclipse.core.resources.IncrementalProjectBuilder;
  +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.NullProgressMonitor;
   import org.eclipse.core.runtime.Path;
   import org.eclipse.core.runtime.QualifiedName;
  +import org.jboss.ide.eclipse.core.util.ProjectUtil;
   import org.jboss.ide.eclipse.packages.core.Trace;
   import org.jboss.ide.eclipse.packages.core.model.internal.PackageBuildDelegate;
   import org.jboss.ide.eclipse.packages.core.model.internal.PackageImpl;
  @@ -44,6 +46,8 @@
   import org.jboss.ide.eclipse.packages.core.model.internal.xb.XbPackage;
   import org.jboss.ide.eclipse.packages.core.model.types.IPackageType;
   
  +import de.schlichtherle.io.File;
  +
   public class PackagesCore {
   
   	public static final QualifiedName PROPERTY_ANT_SCRIPT_PATH =
  @@ -333,6 +337,64 @@
   	}
   	
   	/**
  +	 * Returns the base file in this IPath (can be workspace or filesystem based).
  +	 * This is useful for finding the bottom-most literal "file" in the given path. Example:
  +	 * <code>
  +	 *   getBaseFile (new Path("/myproject/some.jar/META-INF/MANIFEST.MF"))
  +	 * </code>
  +	 * Would return "/myproject/some.jar" if some.jar is a compressed archive/package
  +	 * or return "/myproject/some.jar/META-INF/MANIFEST.MF" if some.jar is exploded (a folder).
  +	 * 
  +	 * If the passed-in IPath does not represent a file that exists, this will return null.
  +	 * If the passed-in IPath is filesystem based, the returned IPath will also be filesystem based.
  +	 * @param filePath The path to find the base file in
  +	 * @return The base file in this path
  +	 */
  +	public static IPath getBaseFile (IPath filePath)
  +	{
  +		String firstSegment = filePath.segment(0);
  +		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(firstSegment);
  +		File file = null;
  +		IPath childSegments = null;
  +		boolean workspacePath = true;
  +		
  +		if (project != null && project.isAccessible())
  +		{
  +			IPath location = ProjectUtil.getProjectLocation(project);
  +			file = new File(location.toFile().getParent(), location.lastSegment());
  +			childSegments = filePath.removeFirstSegments(1);
  +		}
  +		else {
  +			file = new File(filePath.segment(0));
  +			childSegments = filePath.removeFirstSegments(1);
  +			workspacePath = false;
  +		}
  +		
  +		if (file.exists())
  +		{
  +			while (file.getDelegate().isDirectory())
  +			{
  +				file = new File(file, childSegments.segment(0));
  +				childSegments = childSegments.removeFirstSegments(1);
  +			}
  +			
  +			if (workspacePath)
  +			{
  +				IPath location = ProjectUtil.getProjectLocation(project);
  +				IPath fileLocation = new Path(file.getAbsolutePath());
  +				
  +				fileLocation = fileLocation.removeFirstSegments(location.segmentCount());
  +				
  +				return project.getFile(fileLocation).getFullPath();
  +			} else {
  +				return new Path(file.getAbsolutePath());
  +			}
  +		}
  +		
  +		return null;
  +	}
  +	
  +	/**
   	 * Builds all of a project's packages  (performs a FULL_BUILD)
   	 * @param project The project to build
   	 * @param monitor A progress monitor
  
  
  



More information about the jboss-cvs-commits mailing list