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 299549
Collapse All | Expand All

(-)archiveops/org/eclipse/jst/j2ee/internal/archive/JavaEEArchiveUtilities.java (-56 / +77 lines)
Lines 79-84 Link Here
79
	 * specified IArchive is an EJB 3.0 jar.
79
	 * specified IArchive is an EJB 3.0 jar.
80
	 */
80
	 */
81
	public static final String DISCRIMINATE_EJB_ANNOTATIONS = "DISCRIMINATE_EJB_ANNOTATIONS"; //$NON-NLS-1$
81
	public static final String DISCRIMINATE_EJB_ANNOTATIONS = "DISCRIMINATE_EJB_ANNOTATIONS"; //$NON-NLS-1$
82
	
83
	/**
84
	 * Default value = Boolean.TRUE Valid values = Boolean.TRUE or Boolean.FALSE
85
	 * 
86
	 * An ArchiveOption used to specify whether
87
	 * {@link #openArchive(ArchiveOptions)} should attempt to fully discriminate
88
	 * a JAR file from an Application Client JAR file. This option is only relevant 
89
	 * if the {@link #DISCRIMINATE_JAVA_EE} option is also set to Boolean.TRUE. If 
90
	 * both options are set to true then as a last resort the MANIFEST.MF
91
	 * will be analyzed for a Main-Class entry in order to discriminate whether the
92
	 * specified IArchive is an Application Client jar.
93
	 */
94
	public static final String DISCRIMINATE_MAIN_CLASS = "DISCRIMINATE_MAIN_CLASS"; //$NON-NLS-1$
82
95
83
	/**
96
	/**
84
	 * Default value = null
97
	 * Default value = null
Lines 117-152 Link Here
117
130
118
	public IArchive openArchive(IVirtualComponent virtualComponent) throws ArchiveOpenFailureException {
131
	public IArchive openArchive(IVirtualComponent virtualComponent) throws ArchiveOpenFailureException {
119
		if (virtualComponent.isBinary()) {
132
		if (virtualComponent.isBinary()) {
120
			J2EEModuleVirtualArchiveComponent archiveComponent = (J2EEModuleVirtualArchiveComponent) virtualComponent;
133
			return openBinaryArchive(virtualComponent, true);
121
			JavaEEBinaryComponentLoadAdapter loadAdapter = new JavaEEBinaryComponentLoadAdapter(archiveComponent);
122
			ArchiveOptions archiveOptions = new ArchiveOptions();
123
			archiveOptions.setOption(ArchiveOptions.LOAD_ADAPTER, loadAdapter);
124
			archiveOptions.setOption(ArchiveOptions.ARCHIVE_PATH, loadAdapter.getArchivePath());
125
			IArchive parentEARArchive = null;
126
			try {
127
				if(archiveComponent.isLinkedToEAR()){
128
					try {
129
						IProject earProject = virtualComponent.getProject();
130
						if(earProject != null && EarUtilities.isEARProject(earProject)){
131
							IVirtualComponent earComponent = ComponentCore.createComponent(virtualComponent.getProject());
132
							if(earComponent != null) {
133
								parentEARArchive = openArchive(earComponent);
134
								if(parentEARArchive != null) {
135
									archiveOptions.setOption(ArchiveOptions.PARENT_ARCHIVE, parentEARArchive);
136
								}
137
							}
138
						}
139
					} catch(ArchiveOpenFailureException e) {
140
						org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e);
141
					}
142
				}
143
				return openArchive(archiveOptions);
144
			} finally {
145
				if(parentEARArchive != null){
146
					archiveOptions.removeOption(ArchiveOptions.PARENT_ARCHIVE);
147
					closeArchive(parentEARArchive);
148
				}
149
			}
150
		}
134
		}
151
		int type = J2EEVersionConstants.UNKNOWN;
135
		int type = J2EEVersionConstants.UNKNOWN;
152
		IArchiveLoadAdapter archiveLoadAdapter = null;
136
		IArchiveLoadAdapter archiveLoadAdapter = null;
Lines 239-244 Link Here
239
		return null;
223
		return null;
240
	}
224
	}
241
225
226
	public IArchive openBinaryArchive(IVirtualComponent virtualComponent, boolean descriminateMainClass) throws ArchiveOpenFailureException {
227
		J2EEModuleVirtualArchiveComponent archiveComponent = (J2EEModuleVirtualArchiveComponent) virtualComponent;
228
		JavaEEBinaryComponentLoadAdapter loadAdapter = new JavaEEBinaryComponentLoadAdapter(archiveComponent);
229
		ArchiveOptions archiveOptions = new ArchiveOptions();
230
		archiveOptions.setOption(ArchiveOptions.LOAD_ADAPTER, loadAdapter);
231
		archiveOptions.setOption(ArchiveOptions.ARCHIVE_PATH, loadAdapter.getArchivePath());
232
		archiveOptions.setOption(DISCRIMINATE_MAIN_CLASS, descriminateMainClass);
233
		IArchive parentEARArchive = null;
234
		try {
235
			if(archiveComponent.isLinkedToEAR()){
236
				try {
237
					IProject earProject = virtualComponent.getProject();
238
					if(earProject != null && EarUtilities.isEARProject(earProject)){
239
						IVirtualComponent earComponent = ComponentCore.createComponent(virtualComponent.getProject());
240
						if(earComponent != null) {
241
							parentEARArchive = openArchive(earComponent);
242
							if(parentEARArchive != null) {
243
								archiveOptions.setOption(ArchiveOptions.PARENT_ARCHIVE, parentEARArchive);
244
							}
245
						}
246
					}
247
				} catch(ArchiveOpenFailureException e) {
248
					org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e);
249
				}
250
			}
251
			return openArchive(archiveOptions);
252
		} finally {
253
			if (parentEARArchive != null){
254
				archiveOptions.removeOption(ArchiveOptions.PARENT_ARCHIVE);
255
				closeArchive(parentEARArchive);
256
			}
257
		}
258
	}
259
242
	private Map<IArchive, JavaEEQuickPeek> archiveToJavaEEQuickPeek = new WeakHashMap<IArchive, JavaEEQuickPeek>();
260
	private Map<IArchive, JavaEEQuickPeek> archiveToJavaEEQuickPeek = new WeakHashMap<IArchive, JavaEEQuickPeek>();
243
261
244
	/**
262
	/**
Lines 482-513 Link Here
482
				wrapArchive(simpleArchive, new Path(J2EEConstants.WEBAPP_DD_URI));
500
				wrapArchive(simpleArchive, new Path(J2EEConstants.WEBAPP_DD_URI));
483
				return simpleArchive;
501
				return simpleArchive;
484
			} else if (lastSegment.endsWith(IJ2EEModuleConstants.JAR_EXT)) {
502
			} else if (lastSegment.endsWith(IJ2EEModuleConstants.JAR_EXT)) {
485
				IPath manifestPath = new Path(J2EEConstants.MANIFEST_URI);
503
				Object discriminateMainClass = simpleArchive.getArchiveOptions().getOption(DISCRIMINATE_MAIN_CLASS);
486
				if (simpleArchive.containsArchiveResource(manifestPath)) {
504
				if (null == discriminateMainClass || ((Boolean) discriminateMainClass).booleanValue()) {
487
					InputStream in = null;
505
					IPath manifestPath = new Path(J2EEConstants.MANIFEST_URI);
488
					try {
506
					if (simpleArchive.containsArchiveResource(manifestPath)) {
489
						IArchiveResource manifestResource = simpleArchive.getArchiveResource(manifestPath);
507
						InputStream in = null;
490
						in = manifestResource.getInputStream();
508
						try {
491
						Manifest manifest = new Manifest(in);
509
							IArchiveResource manifestResource = simpleArchive.getArchiveResource(manifestPath);
492
						Attributes attributes = manifest.getMainAttributes();
510
							in = manifestResource.getInputStream();
493
						String mainClassName = attributes.getValue("Main-Class"); //$NON-NLS-1$
511
							Manifest manifest = new Manifest(in);
494
						if (mainClassName != null) {
512
							Attributes attributes = manifest.getMainAttributes();
495
							//EE6TODO
513
							String mainClassName = attributes.getValue("Main-Class"); //$NON-NLS-1$
496
							JavaEEQuickPeek quickPeek = new JavaEEQuickPeek(JavaEEQuickPeek.APPLICATION_CLIENT_TYPE, JavaEEQuickPeek.JEE_5_0_ID, JavaEEQuickPeek.JEE_5_0_ID);
514
							if (mainClassName != null) {
497
							archiveToJavaEEQuickPeek.put(simpleArchive, quickPeek);
515
								//EE6TODO
498
							wrapArchive(simpleArchive, new Path(J2EEConstants.APPLICATION_DD_URI));
516
								JavaEEQuickPeek quickPeek = new JavaEEQuickPeek(JavaEEQuickPeek.APPLICATION_CLIENT_TYPE, JavaEEQuickPeek.JEE_5_0_ID, JavaEEQuickPeek.JEE_5_0_ID);
499
							return simpleArchive;
517
								archiveToJavaEEQuickPeek.put(simpleArchive, quickPeek);
500
						}
518
								wrapArchive(simpleArchive, new Path(J2EEConstants.APPLICATION_DD_URI));
501
					} catch (FileNotFoundException e) {
519
								return simpleArchive;
502
						ArchiveUtil.warn(e);
520
							}
503
					} catch (IOException e) {
521
						} catch (FileNotFoundException e) {
504
						ArchiveUtil.warn(e);
522
							ArchiveUtil.warn(e);
505
					} finally {
523
						} catch (IOException e) {
506
						if (in != null) {
524
							ArchiveUtil.warn(e);
507
							try {
525
						} finally {
508
								in.close();
526
							if (in != null) {
509
							} catch (IOException e) {
527
								try {
510
								ArchiveUtil.warn(e);
528
									in.close();
529
								} catch (IOException e) {
530
									ArchiveUtil.warn(e);
531
								}
511
							}
532
							}
512
						}
533
						}
513
					}
534
					}
(-)earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java (+7 lines)
Lines 33-38 Link Here
33
import org.eclipse.jst.j2ee.internal.ICommonEMFModule;
33
import org.eclipse.jst.j2ee.internal.ICommonEMFModule;
34
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
34
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
35
import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater;
35
import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater;
36
import org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper;
36
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
37
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
37
import org.eclipse.jst.j2ee.model.IEARModelProvider;
38
import org.eclipse.jst.j2ee.model.IEARModelProvider;
38
import org.eclipse.jst.j2ee.model.IModelProvider;
39
import org.eclipse.jst.j2ee.model.IModelProvider;
Lines 221-226 Link Here
221
		
222
		
222
		String earDDVersion = JavaEEProjectUtilities.getJ2EEDDProjectVersion(earpj);
223
		String earDDVersion = JavaEEProjectUtilities.getJ2EEDDProjectVersion(earpj);
223
		boolean useNewModel = earDDVersion.equals(J2EEVersionConstants.VERSION_5_0_TEXT) || earDDVersion.equals(J2EEVersionConstants.VERSION_6_0_TEXT);
224
		boolean useNewModel = earDDVersion.equals(J2EEVersionConstants.VERSION_5_0_TEXT) || earDDVersion.equals(J2EEVersionConstants.VERSION_6_0_TEXT);
225
		if (wc.isBinary()){
226
			//[Bug 299549] open and cache archive using the DISCRIMINATE_MAIN_CLASS
227
			//option before attempting the JavaEEQuickPeek
228
			JavaEEBinaryComponentHelper.openArchive(wc, useNewModel);
229
		}
230
		
224
		//[Bug 238264] need to use component to determine type of project in-case component is binary
231
		//[Bug 238264] need to use component to determine type of project in-case component is binary
225
		if (JavaEEProjectUtilities.isDynamicWebComponent(wc)) {
232
		if (JavaEEProjectUtilities.isDynamicWebComponent(wc)) {
226
			if (useNewModel) {
233
			if (useNewModel) {
(-)j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JavaEEBinaryComponentHelper.java (-2 / +33 lines)
Lines 45-51 Link Here
45
45
46
	private IArchive archive;
46
	private IArchive archive;
47
	private EnterpriseBinaryComponentHelper legacyBinaryHelper;
47
	private EnterpriseBinaryComponentHelper legacyBinaryHelper;
48
48
	private boolean descriminateMainClass = true;
49
	private int localArchiveAccessCount = 0;
49
	private int localArchiveAccessCount = 0;
50
50
51
	public static JavaEEQuickPeek getJavaEEQuickPeek(IPath filesystemPath) {
51
	public static JavaEEQuickPeek getJavaEEQuickPeek(IPath filesystemPath) {
Lines 82-87 Link Here
82
			}
82
			}
83
		}
83
		}
84
	}
84
	}
85
	
86
	public static void openArchive(IVirtualComponent aBinaryComponent, boolean descriminateMainClass) {
87
		JavaEEBinaryComponentHelper helper = null;
88
		try {
89
			helper = new JavaEEBinaryComponentHelper(aBinaryComponent);
90
			helper.setDescriminateMainClass(descriminateMainClass);
91
			try {
92
				helper.openArchive();
93
			} catch (ArchiveOpenFailureException e) {
94
				J2EEPlugin.logError(e);
95
			}
96
		} finally {
97
			if (helper != null) {
98
				helper.dispose();
99
			}
100
		}
101
	}
85
102
86
	public JavaEEBinaryComponentHelper(IVirtualComponent aBinaryComponent) {
103
	public JavaEEBinaryComponentHelper(IVirtualComponent aBinaryComponent) {
87
		super(aBinaryComponent);
104
		super(aBinaryComponent);
Lines 391-396 Link Here
391
		ArchiveCache.getInstance().clearAllArchivesInProject(earProject);
408
		ArchiveCache.getInstance().clearAllArchivesInProject(earProject);
392
	}
409
	}
393
410
411
	public void setDescriminateMainClass(boolean archiveOption) {
412
		descriminateMainClass = archiveOption;
413
	}
414
415
	public boolean shouldDescriminateMainClass() {
416
		return descriminateMainClass;
417
	}
418
394
	/**
419
	/**
395
	 * This cache manages IArchives across all
420
	 * This cache manages IArchives across all
396
	 * {@link JavaEEBinaryComponentHelper} instances. If multiple
421
	 * {@link JavaEEBinaryComponentHelper} instances. If multiple
Lines 499-505 Link Here
499
		}
524
		}
500
525
501
		public synchronized IArchive openArchive(JavaEEBinaryComponentHelper helper) throws ArchiveOpenFailureException {
526
		public synchronized IArchive openArchive(JavaEEBinaryComponentHelper helper) throws ArchiveOpenFailureException {
502
			IArchive archive = JavaEEArchiveUtilities.INSTANCE.openArchive(helper.getComponent());
527
			IArchive archive;
528
			if (helper.getComponent().isBinary()) {
529
				archive = JavaEEArchiveUtilities.INSTANCE.openBinaryArchive(helper.getComponent(), helper.shouldDescriminateMainClass());
530
			}
531
			else {
532
				archive = JavaEEArchiveUtilities.INSTANCE.openArchive(helper.getComponent());
533
			}
503
			componentsToArchives.put(helper.getComponent(), archive);
534
			componentsToArchives.put(helper.getComponent(), archive);
504
			archiveAccessCount.put(archive, new Integer(0));
535
			archiveAccessCount.put(archive, new Integer(0));
505
			return archive;
536
			return archive;

Return to bug 299549