[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages ...
Robert Stryker
rob.stryker at jboss.com
Fri Apr 20 19:45:16 EDT 2007
User: rawb
Date: 07/04/20 19:45:16
Modified: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages
ModulePackageTypeConverter.java
Added: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages
EarArchiveType.java J2EEArchiveType.java
WarArchiveType.java
Removed: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages
WarPackageType.java
ObscurelyNamedPackageTypeSuperclass.java
EarPackageType.java
Log:
It Compiles! Not sure on if it *works* yet
Revision Changes Path
1.3 +6 -6 jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ModulePackageTypeConverter.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ModulePackageTypeConverter.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ModulePackageTypeConverter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ModulePackageTypeConverter.java 8 Feb 2007 00:12:21 -0000 1.2
+++ ModulePackageTypeConverter.java 20 Apr 2007 23:45:16 -0000 1.3
@@ -22,22 +22,22 @@
package org.jboss.ide.eclipse.as.core.packages;
import org.eclipse.wst.server.core.IModule;
-import org.jboss.ide.eclipse.packages.core.model.PackagesCore;
-import org.jboss.ide.eclipse.packages.core.model.types.IPackageType;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.model.types.IArchiveType;
/**
*
* @author rob.stryker at jboss.com
*/
public class ModulePackageTypeConverter {
- public static IPackageType getPackageTypeFor(IModule module) {
+ public static IArchiveType getPackageTypeFor(IModule module) {
String modType = module.getModuleType().getId();
if("jst.web".equals(modType)) {
- return PackagesCore.getPackageType(WarPackageType.WAR_PACKAGE_TYPE);
+ return ArchivesCore.getArchiveType(WarArchiveType.WAR_PACKAGE_TYPE);
} else if("jst.ear".equals(modType)) {
- return PackagesCore.getPackageType(EarPackageType.EAR_PACKAGE_TYPE);
+ return ArchivesCore.getArchiveType(EarArchiveType.EAR_PACKAGE_TYPE);
} else if("jbide.ejb30".equals(modType)) {
- return PackagesCore.getPackageType("org.jboss.ide.eclipse.ejb3.wizards.core.ejbPackageType");
+ return ArchivesCore.getArchiveType("org.jboss.ide.eclipse.ejb3.wizards.core.ejbPackageType");
}
return null;
1.1 date: 2007/04/20 23:45:16; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/EarArchiveType.java
Index: EarArchiveType.java
===================================================================
/**
* JBoss, a Division of Red Hat
* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.core.packages;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jst.server.core.IEnterpriseApplication;
import org.eclipse.wst.server.core.IModule;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.core.model.types.IArchiveType;
/**
*
* @author rob.stryker at jboss.com
*/
public class EarArchiveType extends J2EEArchiveType {
public static final String EAR_PACKAGE_TYPE = "org.jboss.ide.eclipse.as.core.packages.earPackage";
public String getAssociatedModuleType() {
return "jst.ear";
}
public IArchive createDefaultConfiguration(IProject project, IProgressMonitor monitor) {
IModule mod = getModule(project);
if( mod != null )
return createDefaultConfigFromModule(mod, monitor);
else
return createDefaultConfiguration2(project, monitor);
}
public IArchive createDefaultConfiguration2(IProject project,
IProgressMonitor monitor) {
IArchive topLevel = createGenericIArchive(project, null, project.getName() + ".war");
topLevel.setDestinationPath(project.getLocation(), true);//setDestinationContainer(project);
IArchiveFolder metainf = addFolder(project, topLevel, METAINF);
IArchiveFolder lib = addFolder(project, metainf, LIB);
addFileset(project, metainf, new Path(project.getName()).append(METAINF).toOSString(), null);
return topLevel;
}
public IArchive createDefaultConfigFromModule(IModule module,
IProgressMonitor monitor) {
IProject project = module.getProject();
IContainer sourceContainer = project.getFolder(EARCONTENT);
IArchive topLevel = createGenericIArchive(project, null, project.getName() + ".ear", sourceContainer);
addFileset(project, topLevel, new Path(project.getName()).append(EARCONTENT).toOSString(), "**/*.*");
// now add children
IEnterpriseApplication earModule = (IEnterpriseApplication)module.loadAdapter(IEnterpriseApplication.class, monitor);
IModule[] childModules = earModule.getModules();
for( int i = 0; i < childModules.length; i++ ) {
IModule child = childModules[i];
IArchiveType type = ModulePackageTypeConverter.getPackageTypeFor(child);
IArchive childPack;
if( type == null ) {
childPack = createGenericIArchive(child.getProject(), null, child.getProject().getName() + ".jar");
} else {
childPack = type.createDefaultConfiguration(child.getProject(), new NullProgressMonitor());
}
topLevel.addChild(childPack);
}
return topLevel;
}
public String getId() {
// TODO Auto-generated method stub
return null;
}
public String getLabel() {
// TODO Auto-generated method stub
return null;
}
}
1.1 date: 2007/04/20 23:45:16; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/J2EEArchiveType.java
Index: J2EEArchiveType.java
===================================================================
/**
* JBoss, a Division of Red Hat
* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.core.packages;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IModuleArtifact;
import org.eclipse.wst.server.core.internal.ServerPlugin;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.types.IArchiveType;
import org.jboss.ide.eclipse.archives.core.util.ArchiveNodeFactory;
/**
*
* @author rob.stryker at jboss.com
*/
public abstract class J2EEArchiveType implements IArchiveType {
public static final String METAINF = "META-INF";
public static final String WEBINF = "WEB-INF";
public static final String CLASSES = "classes";
public static final String LIB = "lib";
public static final String WEBCONTENT = "WebContent";
public static final String EARCONTENT = "EarContent";
public static final String EJBMODULE = "ejbModule";
protected boolean isModuleType(IModule module, String moduleTypeId){
if(module.getModuleType()!=null && moduleTypeId.equals(module.getModuleType().getId()))
return true;
return false;
}
protected IModule getModule(IProject project) {
IModuleArtifact moduleArtifact = ServerPlugin.loadModuleArtifact(project);
return moduleArtifact == null ? null : moduleArtifact.getModule();
}
// Find the source folder, then create the IPackage appropriately
public static IArchive createGenericIArchive(IProject project, String deployDirectory, String packageName) {
try {
IJavaProject javaProject = JavaCore.create(project);
Assert.isNotNull(javaProject);
IPath sourcePath;
try {
sourcePath = javaProject.getOutputLocation();
} catch (JavaModelException e) {
e.printStackTrace();
return null;
}
sourcePath = sourcePath.removeFirstSegments(1);
IContainer sourcePathContainer;
if( sourcePath.segmentCount() == 0 )
sourcePathContainer = project;
else
sourcePathContainer = project.getFolder(sourcePath);
return createGenericIArchive(project, deployDirectory, packageName, sourcePathContainer);
} catch( Exception e ) {
e.printStackTrace();
}
return null;
}
// Create a detached package with some generic settings
public static IArchive createGenericIArchive(IProject project, String deployDirectory, String packageName, IContainer sourceContainer) {
IArchive jar = ArchiveNodeFactory.createArchive();
if( deployDirectory != null ) {
jar.setDestinationPath(new Path(deployDirectory), false);
jar.setExploded(false);
} else {
jar.setDestinationPath(project.getLocation(), true);
jar.setExploded(false);
}
jar.setName(packageName);
IArchiveFileSet classes = ArchiveNodeFactory.createFileset();
classes.setIncludesPattern("**/*");
classes.setSourcePath(sourceContainer.getLocation());
jar.addChild(classes);
return jar;
}
public static IArchiveFolder addFolder(IProject project, IArchiveNode parent, String name) {
IArchiveFolder folder = ArchiveNodeFactory.createFolder();
folder.setName(name);
parent.addChild(folder);
return folder;
}
public static IArchiveFileSet addFileset(IProject project, IArchiveNode parent, String sourcePath, String includePattern) {
IArchiveFileSet fs = ArchiveNodeFactory.createFileset();
Assert.isNotNull(project);
IJavaProject javaProject = JavaCore.create(project);
Assert.isNotNull(javaProject);
IContainer sourceContainer;
if( sourcePath != null && !sourcePath.equals("")) {
Path p = new Path(sourcePath);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
sourceContainer = p.segmentCount() != 1 ? (IContainer)root.getFolder(p) : root.getProject(p.segment(0));
} else {
sourceContainer = project;
}
fs.setSourcePath(sourceContainer.getLocation());
fs.setIncludesPattern( includePattern == null ? "**/*" : includePattern );
parent.addChild(fs);
return fs;
}
public abstract String getAssociatedModuleType();
}
1.1 date: 2007/04/20 23:45:16; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/WarArchiveType.java
Index: WarArchiveType.java
===================================================================
/**
* JBoss, a Division of Red Hat
* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.core.packages;
import org.apache.tools.ant.DirectoryScanner;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
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.jdt.core.JavaModelException;
import org.eclipse.jst.server.core.IWebModule;
import org.eclipse.wst.server.core.IModule;
import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
/**
*
* @author rob.stryker at jboss.com
*/
public class WarArchiveType extends J2EEArchiveType {
public static final String WAR_PACKAGE_TYPE = "org.jboss.ide.eclipse.as.core.packages.warPackage";
public String getAssociatedModuleType() {
return "jst.web";
}
public IArchive createDefaultConfiguration(IProject project, IProgressMonitor monitor) {
IModule mod = getModule(project);
if( mod == null )
return createDefaultConfiguration2(project, monitor);
else
return createDefaultConfigFromModule(mod, monitor);
}
protected IArchive createDefaultConfiguration2(IProject project, IProgressMonitor monitor) {
IArchive topLevel = createGenericIArchive(project, null, project.getName() + ".war");
return fillDefaultConfiguration(project, topLevel, monitor);
}
public IArchive fillDefaultConfiguration(IProject project, IArchive topLevel, IProgressMonitor monitor) {
IModule mod = getModule(project);
if( mod == null ) {
topLevel.setDestinationPath(new Path(project.getName()), true);
IArchiveFolder webinf = addFolder(project, topLevel, WEBINF);
IArchiveFolder lib = addFolder(project, webinf, LIB);
IArchiveFolder classes = addFolder(project, webinf, CLASSES);
addWebinfFileset(project, webinf);
addLibFileset(project, lib, true);
addReferencedProjectsAsLibs(project, lib);
addClassesFileset(project, classes);
} else {
topLevel.setDestinationPath(new Path(project.getName()), true);
IArchiveFolder webinf = addFolder(project, topLevel, WEBINF);
IArchiveFolder lib = addFolder(project, webinf, LIB);
IArchiveFolder classes = addFolder(project, webinf, CLASSES);
addWebContentFileset(project, topLevel);
addReferencedProjectsAsLibs(project, lib);
addClassesFileset(project, classes);
}
return topLevel;
}
// For modules only
protected void addWebContentFileset(IProject project, IArchiveNode packageRoot) {
IPath projectPath = project.getLocation();
DirectoryScanner scanner =
DirectoryScannerFactory.createDirectoryScanner(projectPath, "**/WEB-INF/web.xml", null, true);
String[] files = scanner.getIncludedFiles();
// just take the first
if( files.length > 0 ) {
IPath path = new Path(files[0]);
path = path.removeLastSegments(2); // remove the file name
path = new Path(project.getName()).append(path); // pre-pend project name to make workspace-relative
addFileset(project, packageRoot, path.toOSString(), "**/*");
}
}
protected void addClassesFileset(IProject project, IArchiveFolder folder) {
IJavaProject jp = JavaCore.create(project);
if( jp != null ) {
try {
IPath outputLoc = project.getWorkspace().getRoot().getLocation();
outputLoc = outputLoc.append(jp.getOutputLocation());
addFileset(project, folder, jp.getOutputLocation().toOSString(), "**/*.class");
} catch( JavaModelException jme ) {
}
}
}
protected void addWebinfFileset(IProject project, IArchiveFolder folder) {
IPath projectPath = project.getLocation();
DirectoryScanner scanner =
DirectoryScannerFactory.createDirectoryScanner(projectPath, "**/web.xml", null, true);
String[] files = scanner.getIncludedFiles();
// just take the first
if( files.length > 0 ) {
IPath path = new Path(files[0]);
path = path.removeLastSegments(1); // remove the file name
path = new Path(project.getName()).append(path); // pre-pend project name to make workspace-relative
addFileset(project, folder, path.toOSString(), "**/*");
}
}
// Lib support
protected void addLibFileset(IProject project, IArchiveFolder folder, boolean includeTopLevelJars) {
addFileset(project, folder, project.getName(), "**/*.jar"); // add default jars
}
protected void addReferencedProjectsAsLibs(IProject project, IArchiveFolder folder) {
IJavaProject jp = JavaCore.create(project);
if( jp != null ) {
try {
IClasspathEntry[] entries = jp.getRawClasspath();
for( int i = 0; i < entries.length; i++ ) {
System.out.println(entries[i].getContentKind());
if( entries[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
IPath path = entries[i].getPath();
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if( res instanceof IProject ) {
createLibFromProject((IProject)res, folder);
}
}
}
} catch( JavaModelException jme ) {
jme.printStackTrace();
}
}
}
protected void createLibFromProject(IProject project, IArchiveFolder folder) {
IArchive pack = createGenericIArchive(project, null, project.getName() + ".jar");
folder.addChild(pack);
}
protected IArchive createDefaultConfigFromModule(IModule mod, IProgressMonitor monitor) {
try {
IProject project = mod.getProject();
IArchive topLevel = createGenericIArchive(project, null, project.getName() + ".war");
topLevel.setDestinationPath(new Path(project.getName()), true);
IArchiveFolder webinf = addFolder(project, topLevel, WEBINF);
IArchiveFolder metainf = addFolder(project, topLevel, METAINF);
IArchiveFolder lib = addFolder(project, metainf, LIB);
addFileset(project, webinf,
new Path(project.getName()).append(WEBCONTENT).append(WEBINF).toOSString(), null);
IWebModule webModule = (IWebModule)mod.loadAdapter(IWebModule.class, monitor);
IModule[] childModules = webModule.getModules();
for (int i = 0; i < childModules.length; i++) {
IModule child = childModules[i];
// package each child and add
lib.addChild(createGenericIArchive(child.getProject(), null, child.getProject().getName() + ".jar"));
}
return topLevel;
} catch( Exception e ) {
e.printStackTrace();
}
return null;
}
public String getId() {
// TODO Auto-generated method stub
return null;
}
public String getLabel() {
// TODO Auto-generated method stub
return null;
}
}
More information about the jboss-cvs-commits
mailing list