Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 325644 | Differences between
and this patch

Collapse All | Expand All

(-)earproject/org/eclipse/jst/j2ee/application/internal/operations/CopyArchiveIntoProjectOperation.java (-6 / +24 lines)
Lines 21-26 Link Here
21
import org.eclipse.core.commands.ExecutionException;
21
import org.eclipse.core.commands.ExecutionException;
22
import org.eclipse.core.resources.IContainer;
22
import org.eclipse.core.resources.IContainer;
23
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IFolder;
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IAdaptable;
27
import org.eclipse.core.runtime.IAdaptable;
Lines 32-37 Link Here
32
import org.eclipse.core.runtime.SubProgressMonitor;
33
import org.eclipse.core.runtime.SubProgressMonitor;
33
import org.eclipse.jst.j2ee.internal.earcreation.EARCreationResourceHandler;
34
import org.eclipse.jst.j2ee.internal.earcreation.EARCreationResourceHandler;
34
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
35
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
36
import org.eclipse.jst.j2ee.project.EarUtilities;
35
import org.eclipse.osgi.util.NLS;
37
import org.eclipse.osgi.util.NLS;
36
import org.eclipse.wst.common.componentcore.ComponentCore;
38
import org.eclipse.wst.common.componentcore.ComponentCore;
37
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
39
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
Lines 54-64 Link Here
54
			IVirtualComponent earComponent = ComponentCore.createComponent(associatedEARProject);
56
			IVirtualComponent earComponent = ComponentCore.createComponent(associatedEARProject);
55
			
57
			
56
			IContainer underlyingFolder = earComponent.getRootFolder().getUnderlyingFolder();
58
			IContainer underlyingFolder = earComponent.getRootFolder().getUnderlyingFolder();
59
			String uriMapping = getUtilityJar().getName();
60
			String earLib = EarUtilities.getEARLibDir(earComponent);
61
			IFolder libDirFolder = null;
62
 			if(earLib != null && earLib.length() > 0) {
63
 				uriMapping = (new Path(earLib)).append(uriMapping).toString(); 
64
 				if(underlyingFolder.isAccessible()) {
65
 					libDirFolder = getWorkspaceRoot().getFolder(underlyingFolder.getFullPath().append(earLib));
66
 				} else {
67
 					libDirFolder = getWorkspaceRoot().getFolder(associatedEARProject.getFullPath().append(earLib));
68
 				}
69
 			}
57
			if(underlyingFolder.isAccessible()) {
70
			if(underlyingFolder.isAccessible()) {
58
				 copiedJarFile = underlyingFolder.getFile(new Path(getUtilityJar().getName()));
71
				copiedJarFile = underlyingFolder.getFile(new Path(uriMapping));
59
			} else {
72
			} else {
60
				 copiedJarFile = associatedEARProject.getFile(getUtilityJar().getName());
73
				copiedJarFile = associatedEARProject.getFile(uriMapping);
61
			}		
74
			}
62
 			if (copiedJarFile.exists()) {
75
 			if (copiedJarFile.exists()) {
63
				if (isOverwriteIfNecessary())
76
				if (isOverwriteIfNecessary())
64
					copiedJarFile.delete(true, true, new SubProgressMonitor(monitor, 1));
77
					copiedJarFile.delete(true, true, new SubProgressMonitor(monitor, 1));
Lines 66-73 Link Here
66
					status.add(J2EEPlugin.createErrorStatus(0, NLS.bind(EARCreationResourceHandler.CopyArchiveIntoProjectOperation_Found_existing_file_0_, copiedJarFile), null));
79
					status.add(J2EEPlugin.createErrorStatus(0, NLS.bind(EARCreationResourceHandler.CopyArchiveIntoProjectOperation_Found_existing_file_0_, copiedJarFile), null));
67
					return status;
80
					return status;
68
				}
81
				}
69
			} 
82
			}
70
			
83
 			
84
 			// Create EAR's library directory folder if it doesn't exist
85
 			if(libDirFolder != null && (!libDirFolder.exists() || !libDirFolder.isAccessible())) {
86
 				mkdirs(libDirFolder);
87
 			}
88
 			
71
			FileInputStream fileInputStream = null;
89
			FileInputStream fileInputStream = null;
72
			ByteArrayOutputStream bos = null;
90
			ByteArrayOutputStream bos = null;
73
			ByteArrayInputStream jarFileInputStream = null;
91
			ByteArrayInputStream jarFileInputStream = null;
Lines 90-96 Link Here
90
108
91
				addLibraryToClasspath(associatedEARProject, copiedJarFile, monitor);
109
				addLibraryToClasspath(associatedEARProject, copiedJarFile, monitor);
92
				
110
				
93
				createVirtualArchiveComponent(associatedEARProject, getUtilityJar().getName(), copiedJarFile, monitor);
111
				createVirtualArchiveComponent(associatedEARProject, uriMapping, copiedJarFile, monitor);
94
				
112
				
95
				
113
				
96
			} catch (FileNotFoundException e) {
114
			} catch (FileNotFoundException e) {
(-)earproject/org/eclipse/jst/j2ee/application/internal/operations/CreateProjectWithExtractedJarOperation.java (-12 lines)
Lines 11-17 Link Here
11
package org.eclipse.jst.j2ee.application.internal.operations;
11
package org.eclipse.jst.j2ee.application.internal.operations;
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.lang.reflect.InvocationTargetException;
15
14
16
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IProject;
Lines 66-82 Link Here
66
			importModel.setProperty(IJavaUtilityJarImportDataModelProperties.EAR_PROJECT_NAME, getAssociatedEARProjectName());
65
			importModel.setProperty(IJavaUtilityJarImportDataModelProperties.EAR_PROJECT_NAME, getAssociatedEARProjectName());
67
66
68
			status.add(importModel.getDefaultOperation().execute(new SubProgressMonitor(monitor, 1), info)); 
67
			status.add(importModel.getDefaultOperation().execute(new SubProgressMonitor(monitor, 1), info)); 
69
			
70
			IProject associatedEARProject = getWorkspaceRoot().getProject(getAssociatedEARProjectName());
71
 			IProject utilityJarProject = getWorkspaceRoot().getProject(newProjectName);
72
			linkArchiveToEAR(associatedEARProject, getUtilityJar().getName(), utilityJarProject, new SubProgressMonitor(monitor, 1));
73
			
74
		} catch (InvocationTargetException e) {
75
			status.add(J2EEPlugin.createErrorStatus(0, e.getMessage(), e));
76
			J2EEPlugin.logError(0, e.getMessage(), e);
77
		} catch (InterruptedException e) {
78
			status.add(J2EEPlugin.createErrorStatus(0, e.getMessage(), e));
79
			J2EEPlugin.logError(0, e.getMessage(), e);
80
		} catch (CoreException e) {
68
		} catch (CoreException e) {
81
			status.add(J2EEPlugin.createErrorStatus(0, e.getMessage(), e));
69
			status.add(J2EEPlugin.createErrorStatus(0, e.getMessage(), e));
82
			J2EEPlugin.logError(0, e.getMessage(), e);
70
			J2EEPlugin.logError(0, e.getMessage(), e);
(-)earproject/org/eclipse/jst/j2ee/application/internal/operations/CreateProjectWithLinkedJarOperation.java (-8 / +1 lines)
Lines 20-26 Link Here
20
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.MultiStatus;
21
import org.eclipse.core.runtime.MultiStatus;
22
import org.eclipse.core.runtime.Status;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.core.runtime.SubProgressMonitor;
24
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IJavaProject;
25
import org.eclipse.jdt.core.IPackageFragmentRoot;
24
import org.eclipse.jdt.core.IPackageFragmentRoot;
26
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.JavaCore;
Lines 63-68 Link Here
63
				createUtilityProject.setProperty(IProjectCreationPropertiesNew.USER_DEFINED_LOCATION, projectRoot);
62
				createUtilityProject.setProperty(IProjectCreationPropertiesNew.USER_DEFINED_LOCATION, projectRoot);
64
			}
63
			}
65
 			
64
 			
65
			createUtilityProject.setProperty(IJ2EEFacetProjectCreationDataModelProperties.ADD_TO_EAR, true);
66
			createUtilityProject.setProperty(IJ2EEFacetProjectCreationDataModelProperties.EAR_PROJECT_NAME, getAssociatedEARProjectName());
66
			createUtilityProject.setProperty(IJ2EEFacetProjectCreationDataModelProperties.EAR_PROJECT_NAME, getAssociatedEARProjectName());
67
			
67
			
68
			status.add(createUtilityProject.getDefaultOperation().execute(monitor, info));
68
			status.add(createUtilityProject.getDefaultOperation().execute(monitor, info));
Lines 81-93 Link Here
81
			IVirtualComponent utilComponent = ComponentCore.createComponent(project);
81
			IVirtualComponent utilComponent = ComponentCore.createComponent(project);
82
			status.add(removeRootMapping(utilComponent, "/src", monitor)); //$NON-NLS-1$
82
			status.add(removeRootMapping(utilComponent, "/src", monitor)); //$NON-NLS-1$
83
			
83
			
84
			/* Create the /<archive> mapping */
85
			status.add(createVirtualArchiveComponent(project, getUtilityJar().getName(), project.getFile(getUtilityJar().getName()), monitor));
86
			 
87
			/* Make this project a utility jar project for the EAR */
88
			IProject associatedEARProject = getWorkspaceRoot().getProject(getAssociatedEARProjectName());			
89
			status.add(linkArchiveToEAR(associatedEARProject, getUtilityJar().getName(), utilityJarProject, new SubProgressMonitor(monitor, 1)));
90
91
		} catch (Exception e) {
84
		} catch (Exception e) {
92
			status.add(J2EEPlugin.createErrorStatus(0, EARCreationResourceHandler.J2EEUtilityJarListImportOperation_UI_2, e));
85
			status.add(J2EEPlugin.createErrorStatus(0, EARCreationResourceHandler.J2EEUtilityJarListImportOperation_UI_2, e));
93
		}		 
86
		}		 
(-)earproject/org/eclipse/jst/j2ee/application/internal/operations/J2EEUtilityJarImportAssistantOperation.java (-1 / +26 lines)
Lines 19-24 Link Here
19
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.core.commands.ExecutionException;
20
import org.eclipse.core.commands.operations.AbstractOperation;
20
import org.eclipse.core.commands.operations.AbstractOperation;
21
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IFolder;
22
import org.eclipse.core.resources.IPathVariableManager;
23
import org.eclipse.core.resources.IPathVariableManager;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.IResource;
Lines 106-116 Link Here
106
107
107
		IVirtualComponent utilcomponent = ComponentCore.createArchiveComponent(targetProject, VirtualArchiveComponent.LIBARCHIVETYPE + IPath.SEPARATOR + utilityJarIFile.getProjectRelativePath().toString());
108
		IVirtualComponent utilcomponent = ComponentCore.createArchiveComponent(targetProject, VirtualArchiveComponent.LIBARCHIVETYPE + IPath.SEPARATOR + utilityJarIFile.getProjectRelativePath().toString());
108
109
110
		IPath uriMappingPath = null;
111
		String uri = uriMapping;
112
		String deployPath = null;
113
		if(uriMapping != null) {
114
			uriMappingPath = new Path(uriMapping);
115
			uri = uriMappingPath.lastSegment();
116
			if(uriMappingPath.segmentCount() > 1)
117
				deployPath = uriMappingPath.removeLastSegments(1).toString();
118
		}
119
		
109
		addArchiveProjectToEARDataModel.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earcomponent);
120
		addArchiveProjectToEARDataModel.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earcomponent);
110
		addArchiveProjectToEARDataModel.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, Collections.singletonList(utilcomponent));
121
		addArchiveProjectToEARDataModel.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, Collections.singletonList(utilcomponent));
111
		Map uriMap = new HashMap();
122
		Map uriMap = new HashMap();
112
		uriMap.put(utilcomponent, uriMapping);
123
		uriMap.put(utilcomponent, uri);
113
		addArchiveProjectToEARDataModel.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_TO_URI_MAP, uriMap);
124
		addArchiveProjectToEARDataModel.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_TO_URI_MAP, uriMap);
125
		if(deployPath != null && deployPath.length() > 0) {
126
			Map deployMap = new HashMap();
127
			deployMap.put(utilcomponent, deployPath);
128
			addArchiveProjectToEARDataModel.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH_MAP, deployMap);
129
		}
114
		return  addArchiveProjectToEARDataModel.getDefaultOperation().execute(monitor, null);
130
		return  addArchiveProjectToEARDataModel.getDefaultOperation().execute(monitor, null);
115
	}
131
	}
116
	
132
	
Lines 191-195 Link Here
191
    	
207
    	
192
    	return baseLocation != null ? (baseLocation + File.separator + proposedProjectName) : null;
208
    	return baseLocation != null ? (baseLocation + File.separator + proposedProjectName) : null;
193
    }
209
    }
210
    
211
	protected static void mkdirs(final IFolder folder) throws CoreException {
212
		if (!folder.exists()) {
213
			if (folder.getParent() instanceof IFolder) {
214
				mkdirs((IFolder) folder.getParent());
215
			}
216
			folder.create(true, true, null);
217
		}
218
	}
194
219
195
}
220
}
(-)earproject/org/eclipse/jst/j2ee/application/internal/operations/J2EEUtilityJarImportDataModelProvider.java (+1 lines)
Lines 69-74 Link Here
69
				nestedModel = (IDataModel) nestedModels.get(i);
69
				nestedModel = (IDataModel) nestedModels.get(i);
70
				try {
70
				try {
71
					nestedModel.setProperty(IJ2EEFacetProjectCreationDataModelProperties.EAR_PROJECT_NAME, propertyValue);
71
					nestedModel.setProperty(IJ2EEFacetProjectCreationDataModelProperties.EAR_PROJECT_NAME, propertyValue);
72
					nestedModel.setProperty(IJ2EEFacetProjectCreationDataModelProperties.ADD_TO_EAR, true);
72
				} catch (Exception e) {
73
				} catch (Exception e) {
73
					J2EEPlugin.logError(e);
74
					J2EEPlugin.logError(e);
74
				}
75
				}
(-)earproject/org/eclipse/jst/j2ee/application/internal/operations/LinkArchiveIntoProjectOperation.java (-3 / +35 lines)
Lines 14-31 Link Here
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
15
16
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.resources.IContainer;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFolder;
18
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.MultiStatus;
25
import org.eclipse.core.runtime.MultiStatus;
26
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Status;
27
import org.eclipse.core.runtime.Status;
25
import org.eclipse.core.runtime.SubProgressMonitor;
28
import org.eclipse.core.runtime.SubProgressMonitor;
26
import org.eclipse.jst.j2ee.internal.earcreation.EARCreationResourceHandler;
29
import org.eclipse.jst.j2ee.internal.earcreation.EARCreationResourceHandler;
27
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
30
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
31
import org.eclipse.jst.j2ee.project.EarUtilities;
28
import org.eclipse.osgi.util.NLS;
32
import org.eclipse.osgi.util.NLS;
33
import org.eclipse.wst.common.componentcore.ComponentCore;
34
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
29
35
30
public class LinkArchiveIntoProjectOperation extends J2EEUtilityJarImportAssistantOperation {
36
public class LinkArchiveIntoProjectOperation extends J2EEUtilityJarImportAssistantOperation {
31
37
Lines 45-51 Link Here
45
		IProject project = getWorkspaceRoot().getProject(getAssociatedEARProjectName());
51
		IProject project = getWorkspaceRoot().getProject(getAssociatedEARProjectName());
46
52
47
		try {
53
		try {
48
			IFile linkedJarFile = project.getFile(getUtilityJar().getName());
54
			IVirtualComponent earComponent = ComponentCore.createComponent(project);
55
			IContainer underlyingFolder = earComponent.getRootFolder().getUnderlyingFolder();
56
			String uriMapping = getUtilityJar().getName();
57
			String earLib = EarUtilities.getEARLibDir(earComponent);
58
			IFolder libDirFolder = null;
59
 			if(earLib != null && earLib.length() > 0) {
60
 				uriMapping = (new Path(earLib)).append(uriMapping).toString();
61
 				if(underlyingFolder.isAccessible()) {
62
 					libDirFolder = getWorkspaceRoot().getFolder(underlyingFolder.getFullPath().append(earLib));
63
 				} else {
64
 					libDirFolder = getWorkspaceRoot().getFolder(project.getFullPath().append(earLib));
65
 				}
66
 			}
67
 			
68
 			IFile linkedJarFile = null;
69
 			if(underlyingFolder.isAccessible()) {				
70
				linkedJarFile = underlyingFolder.getFile(new Path(uriMapping));
71
			} else {
72
				linkedJarFile = project.getFile(uriMapping);
73
			}
74
 			
49
			if (linkedJarFile.exists()) {
75
			if (linkedJarFile.exists()) {
50
				if (isOverwriteIfNecessary())
76
				if (isOverwriteIfNecessary())
51
					linkedJarFile.delete(true, true, new SubProgressMonitor(monitor, 1));
77
					linkedJarFile.delete(true, true, new SubProgressMonitor(monitor, 1));
Lines 54-64 Link Here
54
					return status;
80
					return status;
55
				}
81
				}
56
			}
82
			}
57
			status.add(createLinkedArchive(project, getUtilityJar().getName(), getUtilityJar(), linkedPathVariable, monitor));
83
 			
84
 			// Create EAR's library directory folder if it doesn't exist
85
 			if(libDirFolder != null && (!libDirFolder.exists() || !libDirFolder.isAccessible())) {
86
 				mkdirs(libDirFolder);
87
 			}
88
 			
89
			status.add(createLinkedArchive(project, linkedJarFile.getProjectRelativePath().toString(), getUtilityJar(), linkedPathVariable, monitor));
58
90
59
			addLibraryToClasspath(project, linkedJarFile, monitor);
91
			addLibraryToClasspath(project, linkedJarFile, monitor);
60
			
92
			
61
			createVirtualArchiveComponent(project, getUtilityJar().getName(), linkedJarFile, monitor);
93
			createVirtualArchiveComponent(project, uriMapping, linkedJarFile, monitor);
62
94
63
		} catch (CoreException e) {
95
		} catch (CoreException e) {
64
			status.add(J2EEPlugin.createErrorStatus(0, e.getMessage(), e));
96
			status.add(J2EEPlugin.createErrorStatus(0, e.getMessage(), e));

Return to bug 325644