true if this module has a simple structure based on a
- * single root folder, and false
otherwise.
- *
- * In a single root structure, all files that are contained within the root folder
- * are part of the module, and are already in the correct module structure. No
- * module resources exist outside of this single folder.
- *
- * For J2EE, this method will check if the project is already in J2EE spec standard output form.
- * The project must follow certain rules, but in general, the project's content roots must be source folders
- * and the output folder must also be the the content root folder.
- *
- *
- * @return true
if this module has a single root structure, and
- * false
otherwise
- */
- @Override
- public boolean isSingleRootStructure() {
- return isForceSingleRoot() || getSingleRoot() != null;
- }
-
- /**
- * Will attempt to return the IContainer that counts as the "single-root".
- * If this module does not qualify as a "single-root" module, this
- * method will return null. Otherwise it will return an IContainer
- * that may be used as the single root container.
- *
- * @return
- */
-
- public IContainer getSingleRoot() {
- StructureEdit edit = null;
- try {
- edit = StructureEdit.getStructureEditForRead(getProject());
- if (edit == null || edit.getComponent() == null)
- return null;
-
- // 229650 - check to see if the property 'useSingleRoot' is defined.
- // The force status will be checked until a suitable root folder is found
- boolean forceSingleRoot = isForceSingleRoot(edit);
-
- // if there are any consumed references, this is not single root
- if( hasConsumableReferences(component) && !forceSingleRoot)
- return null;
-
- // if there are any linked resources in the workspace under this folder,
- // then this is not a single root module
- if (rootFoldersHaveLinkedContent() && !forceSingleRoot)
- return null;
-
- // Always return false for EARs so that members for EAR
- // are always calculated and j2ee modules are filtered out
- if (JavaEEProjectUtilities.isEARProject(getProject()) && !forceSingleRoot)
- return null;
-
- List resourceMaps = edit.getComponent().getResources();
-
- // No mappings at all... undefined? false for now
- if (resourceMaps.size()<1)
- return null;
-
- // One mapping, and something maps to root. That's a good sign
- if( resourceMaps.size() == 1 ) {
- ComponentResource mapping = (ComponentResource)resourceMaps.get(0);
- if( isRootMapping(mapping))
- return getOutputContainerIfExists(mapping.getSourcePath());
- // One mapping, but doesn't map to root... so there's no root to point to
- if( !forceSingleRoot)
- return null;
- }
-
- // There are several mappings to root.
- // If more than one map to root, not single root
- if( countExistingRootMappings(resourceMaps) > 1 )
- return !forceSingleRoot ? null :
- getOutputContainerIfExists(getFirstExistingRootPath(resourceMaps));
-
- // if ALL are source folders,
- if( countSourceMappings(resourceMaps) == resourceMaps.size()) {
- // then we check that they all output to the same place
- if (getJavaOutputFolders().length==1) {
- // Currently, we claim single-rooted when all source folders
- // have the same output folder. However, we know this is not
- // true because it cannot contain non Java files unless it is
- // the only source folder. But, fixing at this time would break
- // all current users.
- return getJavaOutputFolders()[0];
- }
- if( !forceSingleRoot)
- return null;
- }
-
- // Not all of them are source mappings, but there's only one root mapping
- // Lets find our root mapping container
- IContainer rootContainer = component.getRootFolder().getUnderlyingFolder();
- IPath projectRelative = component.getRootFolder().getProjectRelativePath();
- if( forceSingleRoot)
- return getOutputContainerIfExists(projectRelative);
-
- // Lets check the underlying folders of all OTHER mappings, which are all source folders,
- // and check its output folder against this root mapping. If the output is to
- // somewhere under the root mapping, then it's single root
- IContainer[] outputFolders = getJavaOutputFolders();
- IPath rootContainerProjectRelative = rootContainer.getProjectRelativePath();
- for( int i = 0; i < outputFolders.length; i++ ) {
- if( !rootContainerProjectRelative.isPrefixOf(outputFolders[i].getProjectRelativePath())) {
- return null;
- }
- }
-
- // All outputs go somewhere under the root folder, or the root folder doesn't exist (EH?)
- return getOutputContainerIfExists(projectRelative);
- } finally {
- if (edit !=null)
- edit.dispose();
- }
- }
-
- protected boolean isForceSingleRoot() {
- StructureEdit edit = StructureEdit.getStructureEditForRead(getProject());
- return isForceSingleRoot(edit);
- }
-
- protected boolean isForceSingleRoot(StructureEdit edit) {
- WorkbenchComponent wbComp = edit.getComponent();
- final List componentProperties = wbComp.getProperties();
- if (componentProperties != null) {
- final Iterator componentPropertiesIterator = componentProperties.iterator();
- while (componentPropertiesIterator.hasNext()) {
- Property wbProperty = (Property) componentPropertiesIterator.next();
- if (J2EEFlexProjDeployable.USE_SINGLE_ROOT_PROPERTY.equals(wbProperty.getName())) {
- boolean useSingleRoot = Boolean.valueOf(wbProperty.getValue()).booleanValue();
- if (useSingleRoot) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- /**
- * This method will return the container related to the given path.
- * If the container is a source path, this method will return its output
- * folder.
- * If the container is not a source path, the container itself will be returned
- * @param projectRelative
- * @return
- */
- protected IContainer getOutputContainerIfExists(IPath projectRelative) {
- IContainer container = (IContainer)getProject().findMember(projectRelative);
- if( !isSourceContainer(projectRelative))
- return container;
- return getOutputContainer(getSourceContainer(container));
- }
-
- private int countExistingRootMappings(List resourceMaps) {
- int count = 0;
- ComponentResource cr = null;
- for (int i=0; i 0)
- result = Boolean.TRUE;
- // Otherwise it is not mapped
- else
- result = Boolean.FALSE;
- // Cache the result in the map for this output container
- outputMaps.put(outputContainer, result);
- }
- return result.booleanValue();
- }
-
- /**
- * Lazy initialize the cached output mappings
- * @return HashMap
- */
- private HashMap getCachedOutputMappings() {
- if (cachedOutputMappings==null)
- cachedOutputMappings = new HashMap();
- return cachedOutputMappings;
- }
-
- /**
- * Lazy initialize the cached source - output pairings
- * @return HashMap
- */
- private HashMap getCachedSourceOutputPairs() {
- if (cachedSourceOutputPairs==null)
- cachedSourceOutputPairs = new HashMap();
- return cachedSourceOutputPairs;
- }
-
- /**
- * This file should be added to the members list from the virtual component maps only if:
- * a) it is not in a source folder
- * b) it is in a source folder, and the corresponding output folder is a mapped component resource
- *
- * @return boolean should file be added to members
- */
- @Override
- protected boolean shouldAddComponentFile(IFile file) {
- IPackageFragmentRoot sourceContainer = getSourceContainer(file);
- // If the file is not in a source container, return true
- if (sourceContainer==null) {
- return true;
- // Else if it is a source container and the output container is mapped in the component, return true
- // Otherwise, return false.
- }
- IContainer outputContainer = getOutputContainer(sourceContainer);
- return outputContainer!=null && isOutputContainerMapped(outputContainer);
- }
}
Index: j2eecreation/org/eclipse/jst/j2ee/project/SingleRootUtil.java
===================================================================
RCS file: /cvsroot/webtools/jeetools/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/SingleRootUtil.java,v
retrieving revision 1.2
diff -u -r1.2 SingleRootUtil.java
--- j2eecreation/org/eclipse/jst/j2ee/project/SingleRootUtil.java 18 Nov 2009 22:38:28 -0000 1.2
+++ j2eecreation/org/eclipse/jst/j2ee/project/SingleRootUtil.java 20 Nov 2009 21:09:05 -0000
@@ -85,7 +85,14 @@
return validateSingleRoot(INCLUDE_FIRST_ERROR).getSeverity() != IStatus.ERROR;
}
-
+ /**
+ * Will attempt to return the IContainer that counts as the "single-root".
+ * If this module does not qualify as a "single-root" module, this
+ * method will return null. Otherwise it will return an IContainer
+ * that may be used as the single-root container.
+ *
+ * @return IContainer representing single-root container
+ */
public IContainer getSingleRoot() {
IStatus status = validateSingleRoot(GET_SINGLE_ROOT_CONTAINER);
if (status.getSeverity() == IStatus.INFO) {
@@ -230,7 +237,7 @@
// Verify the java output folder is the same as one of the content roots
IPath javaOutputPath = getJavaOutputFolders()[0].getProjectRelativePath();
IContainer[] rootFolders = aComponent.getRootFolder().getUnderlyingFolders();
- for (int i=0; i/WEB-INF/classes
IPath javaOutputPath = getJavaOutputFolders()[0].getProjectRelativePath();
- IPath compRootPath = aComponent.getRootFolder().getUnderlyingFolder().getProjectRelativePath();
+ IContainer rootContainer = aComponent.getRootFolder().getUnderlyingFolder();
+ IPath compRootPath = rootContainer.getProjectRelativePath();
if (compRootPath.append(J2EEConstants.WEB_INF_CLASSES).equals(javaOutputPath)) {
- reportStatus(ISingleRootStatus.SINGLE_ROOT_CONTAINER_FOUND, javaOutputFolders[0]);
+ reportStatus(ISingleRootStatus.SINGLE_ROOT_CONTAINER_FOUND, rootContainer);
return;
}
reportStatus(ISingleRootStatus.JAVA_OUTPUT_NOT_WEBINF_CLASSES);
Index: archiveops/org/eclipse/jst/j2ee/internal/archive/ComponentArchiveLoadAdapter.java
===================================================================
RCS file: /cvsroot/webtools/jeetools/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/ComponentArchiveLoadAdapter.java,v
retrieving revision 1.17
diff -u -r1.17 ComponentArchiveLoadAdapter.java
--- archiveops/org/eclipse/jst/j2ee/internal/archive/ComponentArchiveLoadAdapter.java 9 Sep 2009 16:22:36 -0000 1.17
+++ archiveops/org/eclipse/jst/j2ee/internal/archive/ComponentArchiveLoadAdapter.java 20 Nov 2009 21:09:05 -0000
@@ -12,6 +12,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -46,6 +47,7 @@
import org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyVirtualComponent;
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
+import org.eclipse.jst.j2ee.project.SingleRootUtil;
import org.eclipse.jst.jee.archive.AbstractArchiveLoadAdapter;
import org.eclipse.jst.jee.archive.ArchiveModelLoadException;
import org.eclipse.jst.jee.archive.IArchive;
@@ -82,27 +84,29 @@
protected IVirtualComponent vComponent;
protected boolean exportSource = true;
+
+ protected boolean optimizeMembers = false;
- private List zipFiles = new ArrayList();
+ private List zipFiles = new ArrayList();
- private List javaClasspathURIs = new ArrayList();
+ private List javaClasspathURIs = new ArrayList();
protected boolean includeClasspathComponents = true;
protected class FilesHolder {
- private Map pathsToArchiveResources = new HashMap();
+ private Map pathsToArchiveResources = new HashMap();
- private Map pathsToWorkbenchResources = new HashMap();
+ private Map pathsToWorkbenchResources = new HashMap();
- private Map workbenchResourcesToPaths = new HashMap();
+ private Map workbenchResourcesToPaths = new HashMap();
- private Map pathsToDiskFiles;
+ private Map pathsToDiskFiles;
- private Map pathsToZipEntry = new HashMap();
+ private Map pathsToZipEntry = new HashMap();
public void removeIFile(IFile file) {
- IPath path = (IPath) workbenchResourcesToPaths.get(file);
+ IPath path = workbenchResourcesToPaths.get(file);
remove(path);
}
@@ -126,7 +130,7 @@
IPath path = file.getPath();
pathsToArchiveResources.put(path, file);
if (null == pathsToDiskFiles) {
- pathsToDiskFiles = new HashMap();
+ pathsToDiskFiles = new HashMap();
}
pathsToDiskFiles.put(path, externalDiskFile);
}
@@ -141,9 +145,9 @@
java.io.File diskFile = null;
if (pathsToDiskFiles != null && pathsToDiskFiles.containsKey(path)) {
- diskFile = (java.io.File) pathsToDiskFiles.get(path);
+ diskFile = pathsToDiskFiles.get(path);
} else if (pathsToWorkbenchResources != null && pathsToWorkbenchResources.containsKey(path)) {
- IResource resource = (IResource) pathsToWorkbenchResources.get(path);
+ IResource resource = pathsToWorkbenchResources.get(path);
diskFile = new java.io.File(resource.getLocation().toOSString());
}
if (diskFile != null) {
@@ -181,7 +185,7 @@
}
public IArchiveResource getArchiveResource(IPath path) {
- return (IArchiveResource) pathsToArchiveResources.get(path);
+ return pathsToArchiveResources.get(path);
}
public void addEntry(ZipEntry entry, ZipFile zipFile, IPath runtimePath) {
@@ -197,7 +201,7 @@
IArchiveResource file = createFile(innerRuntimePath);
- Map fileURIMap = new HashMap();
+ Map fileURIMap = new HashMap();
fileURIMap.put(entry.getName(), zipFile);
pathsToZipEntry.put(file.getPath(), fileURIMap);
@@ -300,6 +304,19 @@
protected void initArchiveResources() {
if (!archiveResourcesInitialized) {
archiveResourcesInitialized = true;
+ if (isOptimizeMembers()) {
+ SingleRootUtil util = new SingleRootUtil(getComponent());
+ IContainer rootContainer = util.getSingleRoot();
+ if (rootContainer != null) {
+ try {
+ aggregateMembers(Path.EMPTY, rootContainer);
+ addUtilities();
+ } catch (CoreException e) {
+ J2EEPlugin.logError(e);
+ }
+ return;
+ }
+ }
aggregateSourceFiles();
aggregateClassFiles();
addUtilities();
@@ -308,10 +325,17 @@
@Override
public List getArchiveResources() {
-
initArchiveResources();
return filesHolder.getFiles();
}
+
+ public IResource getWorkbenchResources(IPath path) {
+ return filesHolder.pathsToWorkbenchResources.get(path);
+ }
+
+ public File getExternalFiles(IPath path) {
+ return filesHolder.pathsToDiskFiles.get(path);
+ }
/**
* Adds library cp entries that point to class folders and have been tagged with the publish/export attribute.
@@ -484,7 +508,7 @@
continue;
cFile = createDirectory(runtimePath);
cFile.setLastModified(getLastModified(resources[i]));
- filesHolder.addFile(cFile);
+ filesHolder.addFile(cFile, resources[i]);
fileAdded = true;
}
}
@@ -498,6 +522,7 @@
*/
private boolean inJavaSrc = false;
+
protected boolean aggregateFiles(IVirtualResource[] virtualResources) throws CoreException {
boolean fileAdded = false;
for (int i = 0; i < virtualResources.length; i++) {
@@ -610,6 +635,36 @@
protected long getLastModified(IResource aResource) {
return aResource.getLocation().toFile().lastModified();
}
+
+ protected void aggregateMembers(IPath path, IContainer container) throws CoreException{
+ IResource[] resources;
+ resources = container.members();
+ if (resources != null) {
+ int size = resources.length;
+ for (int i = 0; i < size; i++) {
+ IResource resource = resources[i];
+ IArchiveResource cFile = null;
+ if (resource != null && resource.exists()) {
+ IPath deployPath = path.append(resource.getName());
+ if (filesHolder.contains(deployPath)) {
+ continue;
+ }
+ if (resource instanceof IContainer) {
+ IContainer container2 = (IContainer) resource;
+ cFile = createDirectory(deployPath);
+ aggregateMembers(deployPath, container2);
+
+ } else if ((resource instanceof IFile) && shouldInclude(deployPath)) {
+ cFile = createFile(deployPath);
+ }
+ }
+ if (cFile != null) {
+ cFile.setLastModified(getLastModified(resource));
+ filesHolder.addFile(cFile, resource);
+ }
+ }
+ }
+ }
public void setExportSource(boolean newExportSource) {
exportSource = newExportSource;
@@ -619,6 +674,23 @@
return exportSource;
}
+ public void setOptimizeMembers(boolean optimize) {
+ optimizeMembers = optimize;
+ }
+
+ public boolean isOptimizeMembers() {
+ return optimizeMembers;
+ }
+
+ public boolean shouldUpdateManifest(IArchiveResource archiveResource) {
+ IPath path = archiveResource.getPath();
+ if (includeClasspathComponents && path.equals(J2EEConstants.MANIFEST_URI) && !javaClasspathURIs.isEmpty() && manifestFile != null
+ && manifestFile.getUnderlyingFile() != null && manifestFile.getUnderlyingFile().exists()) {
+ return true;
+ }
+ return false;
+ }
+
protected boolean shouldInclude(IContainer aContainer) {
return true;
}
@@ -639,7 +711,7 @@
}
return isExportSource() || !isSource(path);
}
-
+
// TODO add a mechanism for ignoring specific file types
protected boolean isSource(IPath path) {
if (path == null)
@@ -665,20 +737,18 @@
@Override
public InputStream getInputStream(IArchiveResource archiveResource) throws IOException, FileNotFoundException {
- IPath path = archiveResource.getPath();
// If the MANIFEST.MF of a module component is being requested and that
// module component references
// Java build path-based components, need to dynamically update the
// manifest classpath to reflect the resolved
// contributions from the build path
- if (includeClasspathComponents && path.equals(J2EEConstants.MANIFEST_URI) && !javaClasspathURIs.isEmpty() && manifestFile != null && manifestFile.getUnderlyingFile() != null
- && manifestFile.getUnderlyingFile().exists()) {
+ if (shouldUpdateManifest(archiveResource)) {
// update the manifest classpath for the component
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ClasspathDependencyManifestUtil.updateManifestClasspath(manifestFile.getUnderlyingFile(), javaClasspathURIs, baos);
return new ByteArrayInputStream(baos.toByteArray());
}
-
+ IPath path = archiveResource.getPath();
if (filesHolder.contains(path)) {
return filesHolder.getInputStream(path);
}
Index: plugin.xml
===================================================================
RCS file: /cvsroot/webtools/jeetools/plugins/org.eclipse.jst.j2ee/plugin.xml,v
retrieving revision 1.133
diff -u -r1.133 plugin.xml
--- plugin.xml 18 Nov 2009 22:26:19 -0000 1.133
+++ plugin.xml 20 Nov 2009 21:09:04 -0000
@@ -349,19 +349,19 @@
id="org.eclipse.jst.j2ee.server">
+ versions="5.0,1.2,1.3,1.4">
+ versions="5.0,1.2,1.3,1.4">
+ versions="2.5,2.2,2.3,2.4">
+ versions="3.0,1.1,2.0,2.1">