summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Dimov2011-07-25 09:43:08 (EDT)
committerKaloyan Raev2011-07-25 09:43:08 (EDT)
commitc887193cd644338142dc3c067070dbadb290bb7a (patch)
tree186c72142bf10350ce327bbf934dc05d6216f898
parent55de6d19eb87242108fa75ebde68ab6fc7912427 (diff)
downloadorg.eclipse.libra-c887193cd644338142dc3c067070dbadb290bb7a.zip
org.eclipse.libra-c887193cd644338142dc3c067070dbadb290bb7a.tar.gz
org.eclipse.libra-c887193cd644338142dc3c067070dbadb290bb7a.tar.bz2
[349011] Web Context Path in PDE and WTP models is inconsistent
The bug is fixed by registering a resource change listeners that watches for changes in the web context root in both models and synchronizes them whenever necessary.
-rw-r--r--development/org.eclipse.libra.releng/pom.xml6
-rw-r--r--plugins/org.eclipse.libra.facet.ui/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.libra.facet.ui/pom.xml1
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/internal/ui/LibraFacetUIPlugin.java83
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectToBundleOperation.java27
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectsToBundlesOperation.java9
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/ConvertProjectsToBundlesAction.java65
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/Messages.java10
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/ConvertProjectsToBundlesWizardPage.java84
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/Messages.java10
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetInstallPage.java6
-rw-r--r--plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetUninstallPage.java8
-rw-r--r--plugins/org.eclipse.libra.facet/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--plugins/org.eclipse.libra.facet/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.libra.facet/plugin.xml5
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Messages.java10
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetEventHandler.java6
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallConfig.java34
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallDelegate.java291
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUninstallDelegate.java29
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUtils.java144
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/LibraFacetPlugin.java (renamed from plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Activator.java)81
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/Messages.java27
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/WebContextRootSynchonizer.java173
-rw-r--r--plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/messages.properties3
-rw-r--r--tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF17
-rw-r--r--tests/org.eclipse.libra.facet.test/resources/TestWAB.zip_bin0 -> 5129 bytes
-rw-r--r--tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/ProjectUnzipUtil.java141
-rw-r--r--tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java150
-rw-r--r--tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WebContextRootSynchronizerTest.java249
30 files changed, 1118 insertions, 568 deletions
diff --git a/development/org.eclipse.libra.releng/pom.xml b/development/org.eclipse.libra.releng/pom.xml
index d152574..970d94b 100644
--- a/development/org.eclipse.libra.releng/pom.xml
+++ b/development/org.eclipse.libra.releng/pom.xml
@@ -14,6 +14,7 @@
<emf-site>http://download.eclipse.org/modeling/emf/emf/updates/2.7milestones/</emf-site>
<dtp-site>http://download.eclipse.org/datatools/updates/</dtp-site>
<wtp-site>http://download.eclipse.org/webtools/repository/indigo/</wtp-site>
+ <wtp-tests-site>http://download.eclipse.org/webtools/downloads/drops/R3.3.0/R-3.3.0-20110607160810/repositoryunittests/</wtp-tests-site>
</properties>
<modules>
@@ -152,6 +153,11 @@
<url>${wtp-site}</url>
<layout>p2</layout>
</repository>
+ <repository>
+ <id>wtp-sdk-tests</id>
+ <url>${wtp-tests-site}</url>
+ <layout>p2</layout>
+ </repository>
</repositories>
<pluginRepositories>
diff --git a/plugins/org.eclipse.libra.facet.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.libra.facet.ui/META-INF/MANIFEST.MF
index 4481a5a..d5b9a33 100644
--- a/plugins/org.eclipse.libra.facet.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.libra.facet.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.libra.facet.ui;singleton:=true
-Bundle-Version: 0.1.0.qualifier
+Bundle-Version: 0.1.1.qualifier
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.core.databinding,
@@ -21,5 +21,6 @@ Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.libra.facet.ui.operations
Bundle-Localization: plugin
Bundle-Vendor: %Bundle-Vendor
+Bundle-Activator: org.eclipse.libra.facet.internal.ui.LibraFacetUIPlugin
diff --git a/plugins/org.eclipse.libra.facet.ui/pom.xml b/plugins/org.eclipse.libra.facet.ui/pom.xml
index f00642d..bb6d925 100644
--- a/plugins/org.eclipse.libra.facet.ui/pom.xml
+++ b/plugins/org.eclipse.libra.facet.ui/pom.xml
@@ -12,6 +12,7 @@
<artifactId>org.eclipse.libra.facet.ui</artifactId>
<packaging>eclipse-plugin</packaging>
<name>OSGi Bundle Facet UI Plug-in</name>
+ <version>0.1.1-SNAPSHOT</version>
<build>
<plugins>
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/internal/ui/LibraFacetUIPlugin.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/internal/ui/LibraFacetUIPlugin.java
new file mode 100644
index 0000000..5901513
--- /dev/null
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/internal/ui/LibraFacetUIPlugin.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.facet.internal.ui;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+public class LibraFacetUIPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.libra.facet.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static LibraFacetUIPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public LibraFacetUIPlugin() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static void logError(String msg) {
+ logError(msg, null);
+ }
+
+ /**
+ * Log the specified exception or error.
+ */
+ public static void logError(Throwable throwable) {
+ logError(throwable.getLocalizedMessage(), throwable);
+ }
+
+ /**
+ * Log the specified message and exception or error.
+ */
+ public static void logError(String msg, Throwable throwable) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, throwable));
+ }
+
+ /**
+ * Log the specified status.
+ */
+ public static void log(IStatus status) {
+ plugin.getLog().log(status);
+ }
+
+ /**
+ * Log the specified message and exception or error.
+ */
+ public static void logInfo(String msg) {
+ log(new Status(IStatus.INFO, PLUGIN_ID, IStatus.OK, msg, null));
+ }
+
+}
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectToBundleOperation.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectToBundleOperation.java
index cbc2f78..46c38f5 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectToBundleOperation.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectToBundleOperation.java
@@ -9,18 +9,19 @@
* Kaloyan Raev (SAP AG) - initial API and implementation
*******************************************************************************/
package org.eclipse.libra.facet.ui.operations;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.libra.facet.OSGiBundleFacetUtils;
-import org.eclipse.pde.core.project.IBundleProjectDescription;
-import org.eclipse.pde.core.project.IBundleProjectService;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.pde.core.project.IBundleProjectService;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
public class ConvertProjectToBundleOperation extends WorkspaceModifyOperation {
@@ -36,7 +37,7 @@ public class ConvertProjectToBundleOperation extends WorkspaceModifyOperation {
protected void execute(IProgressMonitor monitor) throws CoreException,
InvocationTargetException, InterruptedException {
IFacetedProject fproj = ProjectFacetsManager.create(fProject, true, monitor);
- fproj.installProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, null, monitor);
+ fproj.installProjectFacet(OSGI_BUNDLE_FACET_42, null, monitor);
}
}
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectsToBundlesOperation.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectsToBundlesOperation.java
index 921d924..7520243 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectsToBundlesOperation.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/operations/ConvertProjectsToBundlesOperation.java
@@ -9,13 +9,14 @@
* Kaloyan Raev (SAP AG) - initial API and implementation
*******************************************************************************/
package org.eclipse.libra.facet.ui.operations;
-
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isWebProject;
+
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.libra.facet.OSGiBundleFacetUtils;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
@@ -33,7 +34,7 @@ public class ConvertProjectsToBundlesOperation extends WorkspaceModifyOperation
// first convert non-Web projects
for (IProject project : fProjects) {
- if (!OSGiBundleFacetUtils.isWebProject(project)) {
+ if (!isWebProject(project)) {
new ConvertProjectToBundleOperation(project).execute(monitor);
}
}
@@ -41,7 +42,7 @@ public class ConvertProjectsToBundlesOperation extends WorkspaceModifyOperation
// then convert the Web projects
// this will make the dependencies from referenced libraries to be calculated correctly
for (IProject project : fProjects) {
- if (OSGiBundleFacetUtils.isWebProject(project)) {
+ if (isWebProject(project)) {
new ConvertProjectToBundleOperation(project).execute(monitor);
}
}
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/ConvertProjectsToBundlesAction.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/ConvertProjectsToBundlesAction.java
index 7aea9e6..4901c92 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/ConvertProjectsToBundlesAction.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/ConvertProjectsToBundlesAction.java
@@ -8,31 +8,35 @@
* Contributors:
* Kaloyan Raev (SAP AG) - initial API and implementation
*******************************************************************************/
-package org.eclipse.libra.facet.ui.popup.actions;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IAdapterManager;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.libra.facet.OSGiBundleFacetUtils;
-import org.eclipse.libra.facet.ui.wizards.ConvertProjectsToBundlesWizard;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IActionDelegate;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
+package org.eclipse.libra.facet.ui.popup.actions;
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.hasFeatureNature;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.hasUpdateSiteNature;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isOSGiBundle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.libra.facet.internal.ui.LibraFacetUIPlugin;
+import org.eclipse.libra.facet.ui.wizards.ConvertProjectsToBundlesWizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
public class ConvertProjectsToBundlesAction implements IObjectActionDelegate {
@@ -102,13 +106,14 @@ public class ConvertProjectsToBundlesAction implements IObjectActionDelegate {
for (IProject project : projects) {
try {
if (project.isOpen() &&
- !OSGiBundleFacetUtils.hasFeatureNature(project) &&
- !OSGiBundleFacetUtils.hasUpdateSiteNature(project) &&
- !OSGiBundleFacetUtils.isOSGiBundle(project)) {
+ !hasFeatureNature(project) &&
+ !hasUpdateSiteNature(project) &&
+ !isOSGiBundle(project)) {
unconverted.add(project);
}
- } catch (CoreException e) {
- // do nothing
+ } catch (CoreException e) {
+ LibraFacetUIPlugin.logError(e);
+ // do nothing - skip this (probably corrupted) project
}
}
return unconverted.toArray(new IProject[unconverted.size()]);
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/Messages.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/Messages.java
index 1535695..131ffa7 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/Messages.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/popup/actions/Messages.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
package org.eclipse.libra.facet.ui.popup.actions;
import org.eclipse.osgi.util.NLS;
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/ConvertProjectsToBundlesWizardPage.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/ConvertProjectsToBundlesWizardPage.java
index 7c0d7e7..cf2a2e9 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/ConvertProjectsToBundlesWizardPage.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/ConvertProjectsToBundlesWizardPage.java
@@ -8,41 +8,43 @@
* Contributors:
* Kaloyan Raev (SAP AG) - initial API and implementation
*******************************************************************************/
-package org.eclipse.libra.facet.ui.wizards;
-
-import java.util.Arrays;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.observable.set.IObservableSet;
-import org.eclipse.core.databinding.observable.set.WritableSet;
-import org.eclipse.core.databinding.observable.value.ComputedValue;
-import org.eclipse.core.databinding.validation.MultiValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.databinding.swt.SWTObservables;
-import org.eclipse.jface.databinding.viewers.ViewersObservables;
-import org.eclipse.jface.databinding.wizard.WizardPageSupport;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.libra.facet.OSGiBundleFacetUtils;
+package org.eclipse.libra.facet.ui.wizards;
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isOSGiBundle;
+
+import java.util.Arrays;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.set.WritableSet;
+import org.eclipse.core.databinding.observable.value.ComputedValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.databinding.viewers.ViewersObservables;
+import org.eclipse.jface.databinding.wizard.WizardPageSupport;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.libra.facet.internal.ui.LibraFacetUIPlugin;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.model.WorkbenchLabelProvider;
-import org.eclipse.wst.common.componentcore.ComponentCore;
-import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
-import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
public class ConvertProjectsToBundlesWizardPage extends WizardPage {
@@ -70,12 +72,13 @@ public class ConvertProjectsToBundlesWizardPage extends WizardPage {
try {
if (refProject != null &&
refProject != project &&
- !OSGiBundleFacetUtils.isOSGiBundle(refProject) &&
+ !isOSGiBundle(refProject) &&
!fSelected.contains(refProject)) {
return true;
}
- } catch (CoreException e) {
- // do nothing
+ } catch (CoreException e) {
+ LibraFacetUIPlugin.logError(e);
+ // do nothing - check the next reference
}
}
}
@@ -182,11 +185,12 @@ public class ConvertProjectsToBundlesWizardPage extends WizardPage {
for (IVirtualReference ref : references) {
IProject refProject = ref.getReferencedComponent().getProject();
try {
- if (refProject != null && refProject != project && !OSGiBundleFacetUtils.isOSGiBundle(refProject)) {
+ if (refProject != null && refProject != project && !isOSGiBundle(refProject)) {
fSelected.add(refProject);
}
- } catch (CoreException e) {
- // do nothing
+ } catch (CoreException e) {
+ LibraFacetUIPlugin.logError(e);
+ // do nothing - check the next reference
}
}
}
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/Messages.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/Messages.java
index e24340d..338b6b2 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/Messages.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/Messages.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
package org.eclipse.libra.facet.ui.wizards;
import org.eclipse.osgi.util.NLS;
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetInstallPage.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetInstallPage.java
index 0cd9974..9a3486c 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetInstallPage.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetInstallPage.java
@@ -16,8 +16,8 @@ import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.libra.facet.Activator;
import org.eclipse.libra.facet.OSGiBundleFacetInstallConfig;
+import org.eclipse.libra.facet.internal.ui.LibraFacetUIPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
@@ -27,7 +27,7 @@ import org.eclipse.wst.common.project.facet.ui.AbstractFacetWizardPage;
public class OSGiBundleFacetInstallPage extends AbstractFacetWizardPage {
-
+
private static final String WIZARD_PAGE_NAME = "osgi.bundle.facet.install.page"; //$NON-NLS-1$
private static final String IMG_PATH_BUNDLE_WIZBAN = "icons/wizban/bundle_wizban.png"; //$NON-NLS-1$
@@ -38,7 +38,7 @@ public class OSGiBundleFacetInstallPage extends AbstractFacetWizardPage {
setTitle(Messages.OSGiBundleFacetInstallPage_Title);
setDescription(Messages.OSGiBundleFacetInstallPage_Description);
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, IMG_PATH_BUNDLE_WIZBAN));
+ setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(LibraFacetUIPlugin.PLUGIN_ID, IMG_PATH_BUNDLE_WIZBAN));
}
public void setConfig(Object config) {
diff --git a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetUninstallPage.java b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetUninstallPage.java
index 96b6cbd..9d613b3 100644
--- a/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetUninstallPage.java
+++ b/plugins/org.eclipse.libra.facet.ui/src/org/eclipse/libra/facet/ui/wizards/OSGiBundleFacetUninstallPage.java
@@ -15,9 +15,9 @@ import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.libra.facet.Activator;
import org.eclipse.libra.facet.OSGiBundleFacetUninstallConfig;
import org.eclipse.libra.facet.OSGiBundleFacetUninstallStrategy;
+import org.eclipse.libra.facet.internal.ui.LibraFacetUIPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
@@ -26,8 +26,8 @@ import org.eclipse.wst.common.project.facet.ui.AbstractFacetWizardPage;
public class OSGiBundleFacetUninstallPage extends AbstractFacetWizardPage {
-
- private static final String WIZARD_PAGE_NAME = "osgi.bundle.facet.install.page"; //$NON-NLS-1$
+
+ private static final String WIZARD_PAGE_NAME = "osgi.bundle.facet.uninstall.page"; //$NON-NLS-1$
private static final String IMG_PATH_BUNDLE_WIZBAN = "icons/wizban/bundle_wizban.png"; //$NON-NLS-1$
private OSGiBundleFacetUninstallConfig config;
@@ -37,7 +37,7 @@ public class OSGiBundleFacetUninstallPage extends AbstractFacetWizardPage {
setTitle(Messages.OSGiBundleFacetUninstallPage_Title);
setDescription(Messages.OSGiBundleFacetUninstallPage_Description);
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, IMG_PATH_BUNDLE_WIZBAN));
+ setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(LibraFacetUIPlugin.PLUGIN_ID, IMG_PATH_BUNDLE_WIZBAN));
}
public void setConfig(Object config) {
diff --git a/plugins/org.eclipse.libra.facet/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.libra.facet/.settings/org.eclipse.jdt.core.prefs
index 4399ac9..8a87b68 100644
--- a/plugins/org.eclipse.libra.facet/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.libra.facet/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,12 @@
-#Tue Jan 11 18:31:43 EET 2011
+#Mon Jul 25 11:43:09 EEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/org.eclipse.libra.facet/META-INF/MANIFEST.MF b/plugins/org.eclipse.libra.facet/META-INF/MANIFEST.MF
index d976db7..aa27d04 100644
--- a/plugins/org.eclipse.libra.facet/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.libra.facet/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.libra.facet;singleton:=true
Bundle-Version: 0.1.1.qualifier
-Bundle-Activator: org.eclipse.libra.facet.Activator
+Bundle-Activator: org.eclipse.libra.facet.internal.LibraFacetPlugin
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
diff --git a/plugins/org.eclipse.libra.facet/plugin.xml b/plugins/org.eclipse.libra.facet/plugin.xml
index 65dbbb9..854b57a 100644
--- a/plugins/org.eclipse.libra.facet/plugin.xml
+++ b/plugins/org.eclipse.libra.facet/plugin.xml
@@ -2,6 +2,11 @@
<?eclipse version="3.4"?>
<plugin>
<extension
+ point="org.eclipse.ui.startup">
+ <startup></startup>
+ </extension>
+
+ <extension
point="org.eclipse.wst.common.project.facet.core.facets">
<project-facet
id="osgi.bundle">
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Messages.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Messages.java
index 5f1a29a..8b3b922 100644
--- a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Messages.java
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Messages.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
package org.eclipse.libra.facet;
import org.eclipse.osgi.util.NLS;
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetEventHandler.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetEventHandler.java
index dca92e2..0111e61 100644
--- a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetEventHandler.java
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetEventHandler.java
@@ -13,6 +13,7 @@ package org.eclipse.libra.facet;
import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_PERSISTENCE_PACKAGE;
import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JPA_FACET;
import static org.eclipse.libra.facet.OSGiBundleFacetUtils.META_PERSISTENCE_HEADER;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isOSGiBundle;
import java.util.ArrayList;
import java.util.Arrays;
@@ -20,6 +21,7 @@ import java.util.Arrays;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.libra.facet.internal.LibraFacetPlugin;
import org.eclipse.pde.core.project.IBundleProjectDescription;
import org.eclipse.pde.core.project.IBundleProjectService;
import org.eclipse.pde.core.project.IPackageImportDescription;
@@ -32,8 +34,8 @@ public class OSGiBundleFacetEventHandler implements IDelegate {
public void execute(IProject project, IProjectFacetVersion fv,
Object config, IProgressMonitor monitor) throws CoreException {
- if (JPA_FACET.equals(fv.getProjectFacet().getId()) && OSGiBundleFacetUtils.isOSGiBundle(project)) {
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
+ if (JPA_FACET.equals(fv.getProjectFacet().getId()) && isOSGiBundle(project)) {
+ IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault().getBundleProjectService();
IBundleProjectDescription bundleProjectDescription = bundleProjectService.getDescription(project);
// add the Meta-Persistence manifest header, if it already exists - keep its value
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallConfig.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallConfig.java
index 8bb9a3b..3a5d11e 100644
--- a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallConfig.java
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallConfig.java
@@ -10,22 +10,21 @@
*******************************************************************************/
package org.eclipse.libra.facet;
-import org.eclipse.core.databinding.observable.Realm;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.observable.value.WritableValue;
-import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ValidationStatus;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.pde.core.project.IBundleProjectDescription;
-import org.eclipse.pde.core.project.IBundleProjectService;
-import org.eclipse.wst.common.project.facet.core.ActionConfig;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
-import org.osgi.framework.Version;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.WritableValue;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.wst.common.project.facet.core.ActionConfig;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
+import org.osgi.framework.Version;
public class OSGiBundleFacetInstallConfig extends ActionConfig implements IFacetedProjectListener {
@@ -190,9 +189,8 @@ public class OSGiBundleFacetInstallConfig extends ActionConfig implements IFacet
return null;
IProject project = fproj.getProject();
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
try {
- return bundleProjectService.getDescription(project);
+ return OSGiBundleFacetUtils.getBundleProjectDescription(project);
} catch (CoreException e) {
return null;
}
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallDelegate.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallDelegate.java
index a32eb3f..5c58c8c 100644
--- a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallDelegate.java
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetInstallDelegate.java
@@ -1,128 +1,138 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 SAP AG and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Kaloyan Raev (SAP AG) - initial API and implementation
- *******************************************************************************/
-package org.eclipse.libra.facet;
-
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_EL_PACKAGE;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_PERSISTENCE_PACKAGE;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_HTTP_PACKAGE;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_JSP_EL_PACKAGE;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_JSP_PACKAGE;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_JSP_TAGEXT_PACKAGE;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_PACKAGE;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.META_PERSISTENCE_HEADER;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.WEB_CONTEXT_PATH_HEADER;
-import static org.eclipse.libra.facet.OSGiBundleFacetUtils.WEB_INF_CLASSES;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-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.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.osgi.service.resolver.VersionRange;
-import org.eclipse.pde.core.project.IBundleClasspathEntry;
-import org.eclipse.pde.core.project.IBundleProjectDescription;
-import org.eclipse.pde.core.project.IBundleProjectService;
-import org.eclipse.pde.core.project.IPackageExportDescription;
-import org.eclipse.pde.core.project.IPackageImportDescription;
-import org.eclipse.wst.common.componentcore.ComponentCore;
-import org.eclipse.wst.common.componentcore.internal.util.FacetedProjectUtilities;
-import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
-import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
-import org.eclipse.wst.common.project.facet.core.IDelegate;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.osgi.framework.Version;
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.facet;
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.BUILD_PROPERTIES;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_EL_PACKAGE;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_PERSISTENCE_PACKAGE;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_HTTP_PACKAGE;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_JSP_EL_PACKAGE;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_JSP_PACKAGE;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_JSP_TAGEXT_PACKAGE;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JAVAX_SERVLET_PACKAGE;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.JPA_FACET;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.META_INF;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.META_PERSISTENCE_HEADER;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.REQUIRED_PLUGINS_CONTAINER_PATH;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.WEB_CONTEXT_PATH_HEADER;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.WEB_INF_CLASSES;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getBundleProjectDescription;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getContextRootFromWTPModel;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.hasPluginNature;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.hasRequiredPlugins;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isJavaProject;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isJpaProject;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isWebProject;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+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.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.libra.facet.internal.LibraFacetPlugin;
+import org.eclipse.osgi.service.resolver.VersionRange;
+import org.eclipse.pde.core.project.IBundleClasspathEntry;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.pde.core.project.IBundleProjectService;
+import org.eclipse.pde.core.project.IPackageExportDescription;
+import org.eclipse.pde.core.project.IPackageImportDescription;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.internal.util.FacetedProjectUtilities;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+import org.eclipse.wst.common.project.facet.core.IDelegate;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.osgi.framework.Version;
public class OSGiBundleFacetInstallDelegate implements IDelegate {
-
+
public void execute(IProject project, IProjectFacetVersion fv,
Object configObject, IProgressMonitor monitor) throws CoreException {
OSGiBundleFacetInstallConfig config = (OSGiBundleFacetInstallConfig) configObject;
doExecute(project, config, monitor);
}
-
+
private void doExecute(IProject project,
OSGiBundleFacetInstallConfig config, IProgressMonitor monitor)
- throws CoreException {
+ throws CoreException {
setBundleRoot(project);
createBundleProjectDescription(project, config, monitor);
- addRequiredPluginsClasspathContainer(project, monitor);
+ addRequiredPluginsClasspathContainer(project, monitor);
- if (OSGiBundleFacetUtils.isJpaProject(project)) {
+ if (isJpaProject(project)) {
moveMetaInfToRoot(project, monitor);
}
}
private void setBundleRoot(IProject project) throws CoreException {
IPath bundleRoot = null;
- if (OSGiBundleFacetUtils.isWebProject(project)) {
+ if (isWebProject(project)) {
IVirtualComponent component = ComponentCore.createComponent(project);
bundleRoot = component.getRootFolder().getProjectRelativePath();
- }
-
+ }
+
if (bundleRoot != null) {
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
+ IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault().getBundleProjectService();
bundleProjectService.setBundleRoot(project, bundleRoot);
}
}
-
+
private void createBundleProjectDescription(IProject project,
OSGiBundleFacetInstallConfig config, IProgressMonitor monitor)
- throws CoreException {
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription bundleProjectDescription = bundleProjectService.getDescription(project);
-
+ throws CoreException {
+ IBundleProjectDescription bundleProjectDescription = getBundleProjectDescription(project);
bundleProjectDescription.setSymbolicName(config.getSymbolicName());
bundleProjectDescription.setBundleVersion(config.getVersion());
-
+
String bundleName = config.getName();
if (bundleName != null && bundleName.trim().length() > 0) {
bundleProjectDescription.setBundleName(bundleName);
}
-
+
String bundleVendor = config.getVendor();
if (bundleVendor != null && bundleVendor.trim().length() > 0) {
bundleProjectDescription.setBundleVendor(bundleVendor);
}
-
+
bundleProjectDescription.setEquinox(true);
bundleProjectDescription.setExtensionRegistry(false);
bundleProjectDescription.setNatureIds(getNatureIds(bundleProjectDescription));
bundleProjectDescription.setLaunchShortcuts(getLaunchShortcuts(project));
-
+
Map<String, String> headers = getAdditionalHeaders(project);
for (Map.Entry<String, String> entry : headers.entrySet()) {
bundleProjectDescription.setHeader(entry.getKey(), entry.getValue());
}
-
+
bundleProjectDescription.setPackageExports(getPackageExports(project));
bundleProjectDescription.setPackageImports(getPackageImports(bundleProjectDescription));
bundleProjectDescription.setBinIncludes(getBinIncludes(bundleProjectDescription));
bundleProjectDescription.setBundleClasspath(getBundleClasspath(bundleProjectDescription));
-
+
bundleProjectDescription.apply(monitor);
}
@@ -133,12 +143,12 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
newNatureIds[i] = natureIds[i];
}
newNatureIds[newNatureIds.length - 1] = IBundleProjectDescription.PLUGIN_NATURE;
-
+
return newNatureIds;
}
private String[] getLaunchShortcuts(IProject project) throws CoreException {
- if (OSGiBundleFacetUtils.isWebProject(project)) {
+ if (isWebProject(project)) {
return new String[] {
"org.eclipse.pde.ui.EquinoxLaunchShortcut", //$NON-NLS-1$
"org.eclipse.wst.server.launchShortcut" //$NON-NLS-1$
@@ -147,36 +157,26 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
// use default OSGi Framework launchers
return null;
}
-
+
private Map<String, String> getAdditionalHeaders(IProject project) throws CoreException {
Map<String, String> headers = new HashMap<String, String>();
-
- if (OSGiBundleFacetUtils.isWebProject(project)) {
- headers.put(WEB_CONTEXT_PATH_HEADER, getContextRoot(project));
+
+ if (isWebProject(project)) {
+ headers.put(WEB_CONTEXT_PATH_HEADER, getContextRootFromWTPModel(project));
}
-
- if (OSGiBundleFacetUtils.isJpaProject(project)) {
+
+ if (isJpaProject(project)) {
headers.put(META_PERSISTENCE_HEADER, ""); //$NON-NLS-1$
}
-
+
return headers;
}
- private String getContextRoot(IProject project) {
- IVirtualComponent component = ComponentCore.createComponent(project);
- String contextRoot = component.getMetaProperties().getProperty(OSGiBundleFacetUtils.CONTEXTROOT);
- // add leading slash if not available
- if (contextRoot.charAt(0) != '/') {
- contextRoot = '/' + contextRoot;
- }
- return contextRoot;
- }
-
private IPackageExportDescription[] getPackageExports(IProject project) throws CoreException {
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
+ IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault().getBundleProjectService();
List<IPackageExportDescription> list = new ArrayList<IPackageExportDescription>();
-
- if (OSGiBundleFacetUtils.isJavaProject(project)) {
+
+ if (isJavaProject(project)) {
IJavaProject javaProject = JavaCore.create(project);
IPackageFragmentRoot[] fragmentRoots = javaProject.getAllPackageFragmentRoots();
for (IPackageFragmentRoot fragmentRoot : fragmentRoots) {
@@ -191,14 +191,14 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
}
}
}
-
+
return list.toArray(new IPackageExportDescription[list.size()]);
}
private IPackageImportDescription[] getPackageImports(IBundleProjectDescription bundleProjectDescription) throws CoreException {
IProject project = bundleProjectDescription.getProject();
Map<String, IPackageImportDescription> packages = new TreeMap<String, IPackageImportDescription>();
-
+
// look for existing package imports
IPackageImportDescription[] imports = bundleProjectDescription.getPackageImports();
if (imports != null) {
@@ -207,9 +207,7 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
}
}
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
-
- if (OSGiBundleFacetUtils.isWebProject(project)) {
+ if (isWebProject(project)) {
// add the most popular servlet packages
addPackageImport(packages, JAVAX_SERVLET_PACKAGE, null, false);
addPackageImport(packages, JAVAX_SERVLET_HTTP_PACKAGE, null, false);
@@ -223,8 +221,8 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
IVirtualReference[] references = component.getReferences();
for (IVirtualReference ref : references) {
IProject refProject = ref.getReferencedComponent().getProject();
- if (refProject != null && refProject != project && OSGiBundleFacetUtils.hasPluginNature(refProject)) {
- IPackageExportDescription[] exports = bundleProjectService.getDescription(refProject).getPackageExports();
+ if (refProject != null && refProject != project && hasPluginNature(refProject)) {
+ IPackageExportDescription[] exports = getBundleProjectDescription(refProject).getPackageExports();
for (IPackageExportDescription export : exports) {
String importName = export.getName();
Version exportVersion = export.getVersion();
@@ -234,42 +232,43 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
}
}
}
- if (OSGiBundleFacetUtils.isJpaProject(project)) {
- String version = FacetedProjectUtilities.getProjectFacetVersion(project, OSGiBundleFacetUtils.JPA_FACET).getVersionString();
+
+ if (isJpaProject(project)) {
+ String version = FacetedProjectUtilities.getProjectFacetVersion(project, JPA_FACET).getVersionString();
addPackageImport(packages, String.format(JAVAX_PERSISTENCE_PACKAGE, version), null, false);
}
-
+
return packages.values().toArray(new IPackageImportDescription[packages.size()]);
}
-
+
private void addPackageImport(Map<String, IPackageImportDescription> packages, String importName, VersionRange range, boolean optional) {
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
+ IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault().getBundleProjectService();
if (!packages.containsKey(importName)) {
IPackageImportDescription imp = bundleProjectService.newPackageImport(importName, range, optional);
packages.put(importName, imp);
}
}
-
+
private IPath[] getBinIncludes(IBundleProjectDescription bundleProjectDescription) throws CoreException {
IProject project = bundleProjectDescription.getProject();
IVirtualComponent component = ComponentCore.createComponent(project);
-
- if (OSGiBundleFacetUtils.isWebProject(project)) {
+
+ if (isWebProject(project)) {
IPath bundleRoot = component.getRootFolder().getProjectRelativePath();
IResource[] resources = project.getFolder(bundleRoot).members();
List<IPath> binPaths = new ArrayList<IPath>();
-
+
for (int i = 0; i < resources.length; i++) {
String token = resources[i].getName();
if (resources[i].getType() == IResource.FOLDER) {
token += '/';
}
-
- if (!token.equals(OSGiBundleFacetUtils.BUILD_PROPERTIES)) {
+
+ if (!token.equals(BUILD_PROPERTIES)) {
binPaths.add(new Path(token));
}
}
-
+
return binPaths.toArray(new IPath[binPaths.size()]);
} else {
// don't modify bin.includes by default
@@ -281,35 +280,35 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
IProject project = bundleProjectDescription.getProject();
IBundleClasspathEntry[] bundleClasspath = bundleProjectDescription.getBundleClasspath();
- IJavaProject javaProject = JavaCore.create(project);
- if (bundleClasspath == null) {
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
-
- IPath source = getRelativePath(project, getJavaSourceFolderPaths(javaProject)[0]);
- IPath binary = getRelativePath(project, javaProject.getOutputLocation());
- IPath library = (OSGiBundleFacetUtils.isWebProject(project))
- ? new Path(WEB_INF_CLASSES) // add WEB-INF/classes for WABs
- : null; // add . for other OSGi bundles
-
- IBundleClasspathEntry classpath = bundleProjectService.newBundleClasspathEntry(
- source, binary, library);
- bundleClasspath = new IBundleClasspathEntry[] { classpath };
- } else {
- // TODO
- }
-
+ IJavaProject javaProject = JavaCore.create(project);
+ if (bundleClasspath == null) {
+ IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault().getBundleProjectService();
+
+ IPath source = getRelativePath(project, getJavaSourceFolderPaths(javaProject)[0]);
+ IPath binary = getRelativePath(project, javaProject.getOutputLocation());
+ IPath library = (isWebProject(project))
+ ? new Path(WEB_INF_CLASSES) // add WEB-INF/classes for WABs
+ : null; // add . for other OSGi bundles
+
+ IBundleClasspathEntry classpath = bundleProjectService.newBundleClasspathEntry(
+ source, binary, library);
+ bundleClasspath = new IBundleClasspathEntry[] { classpath };
+ } else {
+ // TODO
+ }
+
// don't modify bin.includes by default
return bundleClasspath;
}
-
+
private void addRequiredPluginsClasspathContainer(IProject project, IProgressMonitor monitor) throws CoreException {
- if (OSGiBundleFacetUtils.isJavaProject(project)) {
+ if (isJavaProject(project)) {
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] entries = javaProject.getRawClasspath();
- if (!OSGiBundleFacetUtils.hasRequiredPlugins(entries)) {
- IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
+ if (!hasRequiredPlugins(entries)) {
+ IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
- newEntries[newEntries.length - 1] = JavaCore.newContainerEntry(OSGiBundleFacetUtils.REQUIRED_PLUGINS_CONTAINER_PATH);
+ newEntries[newEntries.length - 1] = JavaCore.newContainerEntry(REQUIRED_PLUGINS_CONTAINER_PATH);
javaProject.setRawClasspath(newEntries, monitor);
}
}
@@ -317,21 +316,21 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
private IPath[] getJavaSourceFolderPaths(IJavaProject javaProject) throws JavaModelException {
List<IPath> paths = new ArrayList<IPath>();
-
+
IPackageFragmentRoot[] fragmentRoots = javaProject.getAllPackageFragmentRoots();
for (IPackageFragmentRoot fragmentRoot : fragmentRoots) {
if (fragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE && fragmentRoot.getParent().equals(javaProject)) {
paths.add(fragmentRoot.getPath());
}
}
-
+
return paths.toArray(new IPath[paths.size()]);
}
-
+
private IPath getRelativePath(IProject project, IPath path) {
return path.makeRelativeTo(project.getFullPath()).addTrailingSeparator();
- }
-
+ }
+
private void moveMetaInfToRoot(IProject project, IProgressMonitor monitor) throws CoreException {
// find the first META-INF folder as a second-level folder
IFolder folder = null;
@@ -339,7 +338,7 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
for (IResource r : resources) {
if (r.getType() == IResource.FOLDER) {
IFolder f = (IFolder) r;
- IResource metaInf = f.findMember(OSGiBundleFacetUtils.META_INF);
+ IResource metaInf = f.findMember(META_INF);
if (metaInf != null && metaInf.getType() == IResource.FOLDER) {
folder = (IFolder) metaInf;
break;
@@ -353,7 +352,7 @@ public class OSGiBundleFacetInstallDelegate implements IDelegate {
// copy all resources to /META-INF
IResource[] members = folder.members();
for (IResource member : members) {
- IPath destination = project.getFolder(OSGiBundleFacetUtils.META_INF).getFullPath().append(member.getName());
+ IPath destination = project.getFolder(META_INF).getFullPath().append(member.getName());
if (!project.getWorkspace().getRoot().exists(destination)) { // this check is needed for the /src/MANIFEST.MF added by the jst.utility facet
member.move(destination, true, monitor);
}
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUninstallDelegate.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUninstallDelegate.java
index 69878ff..f9bb686 100644
--- a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUninstallDelegate.java
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUninstallDelegate.java
@@ -9,7 +9,16 @@
* Kaloyan Raev (SAP AG) - initial API and implementation
*******************************************************************************/
package org.eclipse.libra.facet;
-
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.BUILD_PROPERTIES;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.MANIFEST_BUILDER_ID;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.MANIFEST_URI;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.SCHEMA_BUILDER_ID;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getBundleProjectDescription;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.hasRequiredPlugins;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isJavaProject;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isRequiredPlugins;
+
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
@@ -23,7 +32,6 @@ import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.pde.core.project.IBundleProjectDescription;
-import org.eclipse.pde.core.project.IBundleProjectService;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
@@ -65,8 +73,8 @@ public class OSGiBundleFacetUninstallDelegate implements IDelegate {
System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
description.setNatureIds(newNatures);
// workaround - see bug 344720
- removeFromBuildSpec(description, OSGiBundleFacetUtils.MANIFEST_BUILDER_ID);
- removeFromBuildSpec(description, OSGiBundleFacetUtils.SCHEMA_BUILDER_ID);
+ removeFromBuildSpec(description, MANIFEST_BUILDER_ID);
+ removeFromBuildSpec(description, SCHEMA_BUILDER_ID);
// end of workaround
project.setDescription(description, IResource.KEEP_HISTORY, monitor);
return;
@@ -90,12 +98,12 @@ public class OSGiBundleFacetUninstallDelegate implements IDelegate {
}
private void removeRequiredBundlesClasspathContainer(IProject project, IProgressMonitor monitor) throws CoreException {
- if (OSGiBundleFacetUtils.isJavaProject(project)) {
+ if (isJavaProject(project)) {
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] entries = javaProject.getRawClasspath();
- if (OSGiBundleFacetUtils.hasRequiredPlugins(entries)) {
+ if (hasRequiredPlugins(entries)) {
for (int i = 0; i < entries.length; i++) {
- if (OSGiBundleFacetUtils.isRequiredPlugins(entries[i])) {
+ if (isRequiredPlugins(entries[i])) {
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1];
System.arraycopy(entries, 0, newEntries, 0, i);
System.arraycopy(entries, i + 1, newEntries, i, entries.length - i - 1);
@@ -108,12 +116,12 @@ public class OSGiBundleFacetUninstallDelegate implements IDelegate {
}
private void deleteBuildProperties(IProject project, IProgressMonitor monitor) throws CoreException {
- IResource buildPropertiesFile = findResource(project, OSGiBundleFacetUtils.BUILD_PROPERTIES);
+ IResource buildPropertiesFile = findResource(project, BUILD_PROPERTIES);
buildPropertiesFile.delete(IResource.KEEP_HISTORY, monitor);
}
private void cleanUpManifest(IProject project, IProgressMonitor monitor) throws CoreException {
- IResource manifestFile = findResource(project, OSGiBundleFacetUtils.MANIFEST_URI);
+ IResource manifestFile = findResource(project, MANIFEST_URI);
manifestFile.delete(IResource.KEEP_HISTORY, monitor);
// delete the META-INF folder if empty
@@ -124,8 +132,7 @@ public class OSGiBundleFacetUninstallDelegate implements IDelegate {
}
private IResource findResource(IProject project, String memberURI) throws CoreException {
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription bundleProjectDescription = bundleProjectService.getDescription(project);
+ IBundleProjectDescription bundleProjectDescription = getBundleProjectDescription(project);
IPath bundleRoot = bundleProjectDescription.getBundleRoot();
IPath memberPath = bundleRoot;
if (memberPath == null) {
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUtils.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUtils.java
index 0180e8d..e7746f1 100644
--- a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUtils.java
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/OSGiBundleFacetUtils.java
@@ -1,58 +1,67 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 SAP AG and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Kaloyan Raev (SAP AG) - initial API and implementation
- *******************************************************************************/
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
package org.eclipse.libra.facet;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.pde.core.project.IBundleProjectDescription;
-import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+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.JavaCore;
+import org.eclipse.libra.facet.internal.LibraFacetPlugin;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.pde.core.project.IBundleProjectService;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
public class OSGiBundleFacetUtils {
public static final String OSGI_BUNDLE = "osgi.bundle"; //$NON-NLS-1$
public static final IProjectFacet OSGI_BUNDLE_FACET = ProjectFacetsManager.getProjectFacet(OSGI_BUNDLE);
- public static final IProjectFacetVersion OSGI_BUNDLE_FACET_42 = OSGI_BUNDLE_FACET.getVersion("4.2"); //$NON-NLS-1$
-
- public static final String WEB_FACET = "jst.web"; //$NON-NLS-1$
+ public static final IProjectFacetVersion OSGI_BUNDLE_FACET_42 = OSGI_BUNDLE_FACET.getVersion("4.2"); //$NON-NLS-1$
+
+ public static final String WEB_FACET = "jst.web"; //$NON-NLS-1$
public static final String JPA_FACET = "jpt.jpa"; //$NON-NLS-1$
-
- public static final String FEATURE_NATURE_ID = "org.eclipse.pde.FeatureNature"; //$NON-NLS-1$
- public static final String SITE_NATURE_ID = "org.eclipse.pde.UpdateSiteNature"; //$NON-NLS-1$
- public static final String MANIFEST_BUILDER_ID = "org.eclipse.pde.ManifestBuilder"; //$NON-NLS-1$
- public static final String SCHEMA_BUILDER_ID = "org.eclipse.pde.SchemaBuilder"; //$NON-NLS-1$
-
- public static final Path REQUIRED_PLUGINS_CONTAINER_PATH = new Path("org.eclipse.pde.core.requiredPlugins"); //$NON-NLS-1$
-
- public static final String BUILD_PROPERTIES = "build.properties"; //$NON-NLS-1$
- public static final String CONTEXTROOT = "context-root"; //$NON-NLS-1$
-
- public static final String WEB_INF_CLASSES = "WEB-INF/classes/"; //$NON-NLS-1$
- public static final String META_INF = "META-INF"; //$NON-NLS-1$
- public static final String MANIFEST_URI = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
-
- public static final String WEB_CONTEXT_PATH_HEADER = "Web-ContextPath"; //$NON-NLS-1$
- public static final String META_PERSISTENCE_HEADER = "Meta-Persistence"; //$NON-NLS-1$
-
- public static final String JAVAX_SERVLET_PACKAGE = "javax.servlet"; //$NON-NLS-1$
- public static final String JAVAX_SERVLET_HTTP_PACKAGE = "javax.servlet.http"; //$NON-NLS-1$
- public static final String JAVAX_SERVLET_JSP_PACKAGE = "javax.servlet.jsp"; //$NON-NLS-1$
- public static final String JAVAX_SERVLET_JSP_EL_PACKAGE = "javax.servlet.jsp.el"; //$NON-NLS-1$
- public static final String JAVAX_SERVLET_JSP_TAGEXT_PACKAGE = "javax.servlet.jsp.tagext"; //$NON-NLS-1$
- public static final String JAVAX_EL_PACKAGE = "javax.el"; //$NON-NLS-1$
+
+ public static final String FEATURE_NATURE_ID = "org.eclipse.pde.FeatureNature"; //$NON-NLS-1$
+ public static final String SITE_NATURE_ID = "org.eclipse.pde.UpdateSiteNature"; //$NON-NLS-1$
+ public static final String MANIFEST_BUILDER_ID = "org.eclipse.pde.ManifestBuilder"; //$NON-NLS-1$
+ public static final String SCHEMA_BUILDER_ID = "org.eclipse.pde.SchemaBuilder"; //$NON-NLS-1$
+
+ public static final Path REQUIRED_PLUGINS_CONTAINER_PATH = new Path("org.eclipse.pde.core.requiredPlugins"); //$NON-NLS-1$
+
+ public static final String BUILD_PROPERTIES = "build.properties"; //$NON-NLS-1$
+ public static final String CONTEXTROOT = "context-root"; //$NON-NLS-1$
+
+ public static final String WEB_INF_CLASSES = "WEB-INF/classes/"; //$NON-NLS-1$
+ public static final String META_INF = "META-INF"; //$NON-NLS-1$
+ public static final String MANIFEST_URI = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
+ public static final IPath MANIFEST_PATH = new Path(MANIFEST_URI);
+ public static final String VIRTUAL_COMPONENT_URI = ".settings/org.eclipse.wst.common.component"; //$NON-NLS-1$
+ public static final IPath VIRTUAL_COMPONENT_PATH = new Path(VIRTUAL_COMPONENT_URI);
+
+ public static final String WEB_CONTEXT_PATH_HEADER = "Web-ContextPath"; //$NON-NLS-1$
+ public static final String META_PERSISTENCE_HEADER = "Meta-Persistence"; //$NON-NLS-1$
+
+ public static final String JAVAX_SERVLET_PACKAGE = "javax.servlet"; //$NON-NLS-1$
+ public static final String JAVAX_SERVLET_HTTP_PACKAGE = "javax.servlet.http"; //$NON-NLS-1$
+ public static final String JAVAX_SERVLET_JSP_PACKAGE = "javax.servlet.jsp"; //$NON-NLS-1$
+ public static final String JAVAX_SERVLET_JSP_EL_PACKAGE = "javax.servlet.jsp.el"; //$NON-NLS-1$
+ public static final String JAVAX_SERVLET_JSP_TAGEXT_PACKAGE = "javax.servlet.jsp.tagext"; //$NON-NLS-1$
+ public static final String JAVAX_EL_PACKAGE = "javax.el"; //$NON-NLS-1$
public static final String JAVAX_PERSISTENCE_PACKAGE = "javax.persistence;jpa=\"%s\""; //$NON-NLS-1$
public static boolean hasPluginNature(IProject project) throws CoreException {
@@ -78,6 +87,10 @@ public class OSGiBundleFacetUtils {
public static boolean isWebProject(IProject project) throws CoreException {
return FacetedProjectFramework.hasProjectFacet(project, WEB_FACET);
}
+
+ public static boolean isWebApplicationBundle(IProject project) throws CoreException {
+ return isWebProject(project) && isOSGiBundle(project);
+ }
public static boolean isJpaProject(IProject project) throws CoreException {
return FacetedProjectFramework.hasProjectFacet(project, JPA_FACET);
@@ -95,5 +108,42 @@ public class OSGiBundleFacetUtils {
}
return false;
}
+
+ public static IBundleProjectDescription getBundleProjectDescription(IProject project) throws CoreException {
+ IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault().getBundleProjectService();
+ return bundleProjectService.getDescription(project);
+ }
+ public static String getContextRootFromWTPModel(IProject project) {
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ String contextRoot = component.getMetaProperties().getProperty(CONTEXTROOT);
+
+ // return null if context root is empty
+ if (contextRoot == null || contextRoot.length() == 0)
+ return null;
+
+ // add leading slash if not available
+ if (contextRoot.charAt(0) != '/') {
+ contextRoot = '/' + contextRoot;
+ }
+ return contextRoot;
+ }
+
+ public static void setContextRootInWTPModel(IProject project, String contextRoot) {
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ component.setMetaProperty(CONTEXTROOT, contextRoot);
+ }
+
+ public static String getContextRootFromPDEModel(IProject project) throws CoreException {
+ IBundleProjectDescription bundleProjectDescription = getBundleProjectDescription(project);
+ String rootContext = bundleProjectDescription.getHeader(WEB_CONTEXT_PATH_HEADER);
+ return rootContext;
+ }
+
+ public static void setContextRootInPDEModel(IProject project, String contextRoot, IProgressMonitor monitor) throws CoreException {
+ IBundleProjectDescription bundleProjectDescription = getBundleProjectDescription(project);
+ bundleProjectDescription.setHeader(WEB_CONTEXT_PATH_HEADER, contextRoot);
+ bundleProjectDescription.apply(monitor);
+ }
+
}
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Activator.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/LibraFacetPlugin.java
index af8f9f8..5f4b4ca 100644
--- a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/Activator.java
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/LibraFacetPlugin.java
@@ -1,38 +1,43 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 SAP AG and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Kaloyan Raev (SAP AG) - initial API and implementation
- *******************************************************************************/
-package org.eclipse.libra.facet;
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.facet.internal;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.pde.core.project.IBundleProjectService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.pde.core.project.IBundleProjectService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* The activator class controls the plug-in life cycle
*/
-public class Activator extends Plugin {
+public class LibraFacetPlugin extends Plugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.libra.facet"; //$NON-NLS-1$
// The shared instance
- private static Activator plugin;
+ private static LibraFacetPlugin plugin;
private ServiceReference<IBundleProjectService> ref;
private IBundleProjectService service;
+ private WebContextRootSynchonizer webContextRootListener;
/**
* The constructor
*/
- public Activator() {
+ public LibraFacetPlugin() {
}
/*
@@ -45,6 +50,9 @@ public class Activator extends Plugin {
this.ref = context.getServiceReference(IBundleProjectService.class);
this.service = (IBundleProjectService) context.getService(ref);
+
+ webContextRootListener = new WebContextRootSynchonizer();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(webContextRootListener, IResourceChangeEvent.POST_CHANGE);
}
/*
@@ -52,6 +60,8 @@ public class Activator extends Plugin {
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(webContextRootListener);
+
context.ungetService(this.ref);
plugin = null;
@@ -63,7 +73,7 @@ public class Activator extends Plugin {
*
* @return the shared instance
*/
- public static Activator getDefault() {
+ public static LibraFacetPlugin getDefault() {
return plugin;
}
@@ -71,4 +81,37 @@ public class Activator extends Plugin {
return service;
}
+ public static void logError(String msg) {
+ logError(msg, null);
+ }
+
+ /**
+ * Log the specified exception or error.
+ */
+ public static void logError(Throwable throwable) {
+ logError(throwable.getLocalizedMessage(), throwable);
+ }
+
+ /**
+ * Log the specified message and exception or error.
+ */
+ public static void logError(String msg, Throwable throwable) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, throwable));
+ }
+
+ /**
+ * Log the specified status.
+ */
+ public static void log(IStatus status) {
+ plugin.getLog().log(status);
+ }
+
+ /**
+ * Log the specified message and exception or error.
+ */
+ public static void logInfo(String msg) {
+ log(new Status(IStatus.INFO, PLUGIN_ID, IStatus.OK, msg, null));
+ }
+
}
+
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/Messages.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/Messages.java
new file mode 100644
index 0000000..37e9d2e
--- /dev/null
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/Messages.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kaloyan Raev (SAP AG) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.facet.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.libra.facet.internal.messages"; //$NON-NLS-1$
+ public static String WebContextRootSynchonizer_JobName;
+ public static String WebContextRootSynchonizer_UpdatingPDEModelFailed;
+ public static String WebContextRootSynchonizer_UpdatingWTPModelFailed;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/WebContextRootSynchonizer.java b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/WebContextRootSynchonizer.java
new file mode 100644
index 0000000..d91a230
--- /dev/null
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/WebContextRootSynchonizer.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stefan Dimov (SAP AG) - initial API and implementation
+ * Kaloyan Raev (SAP AG)
+ *******************************************************************************/
+package org.eclipse.libra.facet.internal;
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.MANIFEST_PATH;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.VIRTUAL_COMPONENT_PATH;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getContextRootFromPDEModel;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getContextRootFromWTPModel;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.isWebApplicationBundle;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.setContextRootInPDEModel;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.setContextRootInWTPModel;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.pde.core.project.IBundleProjectService;
+
+/**
+ * This class is a resource change listener that watches for changes in the
+ * "web context root" in either the WTP and PDE models and synchronizes them.
+ * Meaning, if the web context root changes in the PDE model, it is
+ * automatically changed in the WTP model, and vice versa.
+ *
+ * <p>
+ * This resource change listener is registered and unregistered for events in
+ * the bundle's activator.
+ * </p>
+ */
+public class WebContextRootSynchonizer implements IResourceChangeListener {
+
+ public void resourceChanged(IResourceChangeEvent event) {
+ // we are only interested in POST_CHANGE events
+ if (event.getType() != IResourceChangeEvent.POST_CHANGE)
+ return;
+
+ final Set<IProject> projectsWithModifiedWTPModel = new HashSet<IProject>();
+ final Set<IProject> projectsWithModifiedPDEModel = new HashSet<IProject>();
+
+ IResourceDelta rootDelta = event.getDelta();
+ IResourceDelta[] projectDeltas = rootDelta.getAffectedChildren();
+ for (IResourceDelta projectDelta : projectDeltas) {
+ IProject project = (IProject) projectDelta.getResource();
+
+ // first check if the modified project is a web application bundle
+ if (!isWAB(project))
+ continue;
+
+ // get the delta, if any, for the org.eclipse.wst.common.component file
+ IResourceDelta componentDelta = projectDelta.findMember(VIRTUAL_COMPONENT_PATH);
+ if (isContentChanged(componentDelta)) {
+ // add the project to the list of affected projects
+ projectsWithModifiedWTPModel.add(project);
+ }
+
+ // get the delta, if any, for the MANIFEST.MF file
+ IResourceDelta manifestDelta = projectDelta.findMember(getManifestPath(project));
+ if (isContentChanged(manifestDelta)) {
+ // add the project to the list of modified projects
+ projectsWithModifiedPDEModel.add(project);
+ }
+ }
+
+ if (projectsWithModifiedWTPModel.size() > 0 || projectsWithModifiedPDEModel.size() > 0) {
+ // process in a separate job that all projects are identified for possible change in the context root.
+ // reading and writing to models involves expensive I/O operation that should be executed outside the
+ // resource change listener.
+ new Job(Messages.WebContextRootSynchonizer_JobName) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ // process all projects that are identified for possible change in the context root
+ for (IProject project : projectsWithModifiedWTPModel) {
+ try {
+ // trigger a build to give opportunity to the models to refresh
+ project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
+ // get the new context root from the WTP model
+ String newContextRoot = getContextRootFromWTPModel(project);
+ // get the old context root from the PDE model
+ String oldContextRoot = getContextRootFromPDEModel(project);
+ // check the context roots and decide if updating the one in the PDE model is needed
+ if (!areEqual(newContextRoot, oldContextRoot)) {
+ setContextRootInPDEModel(project, newContextRoot, monitor);
+ }
+ } catch (CoreException e) {
+ LibraFacetPlugin.logError(NLS.bind(Messages.WebContextRootSynchonizer_UpdatingPDEModelFailed, project.getName()), e);
+ }
+ }
+
+ for (IProject project : projectsWithModifiedPDEModel) {
+ try {
+ // trigger a build to give opportunity to the models to refresh
+ project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
+ // get the new context root from the PDE model
+ String newContextRoot = getContextRootFromPDEModel(project);
+ // get the old context root from the WTP model
+ String oldContextRoot = getContextRootFromWTPModel(project);
+ // check the context roots and decide if updating the one in the WTP model is needed
+ if (!areEqual(newContextRoot, oldContextRoot)) {
+ setContextRootInWTPModel(project, newContextRoot);
+ }
+ } catch (CoreException e) {
+ LibraFacetPlugin.logError(NLS.bind(Messages.WebContextRootSynchonizer_UpdatingWTPModelFailed, project.getName()), e);
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ private boolean areEqual(String value1, String value2) {
+ if (value1 == null)
+ return value2 == null;
+ return value1.equals(value2);
+ }
+ }.schedule();
+ }
+ }
+
+ private boolean isWAB(IProject project) {
+ boolean result = false;
+ try {
+ result = isWebApplicationBundle(project);
+ } catch (CoreException e) {
+ LibraFacetPlugin.logError(e);
+ // do nothing - assume the project is not a web application bundle
+ }
+ return result;
+ }
+
+ private boolean isContentChanged(IResourceDelta delta) {
+ return delta != null && delta.getKind() == IResourceDelta.CHANGED
+ && (delta.getFlags() & IResourceDelta.CONTENT) != 0;
+ }
+
+ private IPath getManifestPath(IProject project) {
+ // get the bundle root first
+ IPath bundleRoot = null;
+ try {
+ IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault().getBundleProjectService();
+ IBundleProjectDescription bundleProjectDescription = bundleProjectService.getDescription(project);
+ bundleRoot = bundleProjectDescription.getBundleRoot();
+ } catch (CoreException e) {
+ LibraFacetPlugin.logError(e);
+ // do nothing - leave null for bundle root, which is equivalent to project root
+ }
+
+ if (bundleRoot == null) {
+ return MANIFEST_PATH;
+ } else {
+ return bundleRoot.append(MANIFEST_PATH);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/messages.properties b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/messages.properties
new file mode 100644
index 0000000..e54771d
--- /dev/null
+++ b/plugins/org.eclipse.libra.facet/src/org/eclipse/libra/facet/internal/messages.properties
@@ -0,0 +1,3 @@
+WebContextRootSynchonizer_JobName=Updating web context root in Web Application Bundles
+WebContextRootSynchonizer_UpdatingPDEModelFailed=Cannot update the web context root in the PDE model of project '{0}'
+WebContextRootSynchonizer_UpdatingWTPModelFailed=Cannot update the web context root in the WTP model of project '{0}'
diff --git a/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF b/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF
index 7003e87..140a99c 100644
--- a/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF
@@ -6,17 +6,18 @@ Bundle-Version: 0.1.1.qualifier
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jdt.core,
org.eclipse.debug.core,
- org.eclipse.libra.facet;bundle-version="0.1.0",
- org.eclipse.libra.facet.ui;bundle-version="0.1.0",
- org.eclipse.pde.core;bundle-version="3.6.1",
- org.eclipse.wst.common.project.facet.core;bundle-version="1.4.102",
- org.eclipse.core.databinding.observable;bundle-version="1.3.0",
- org.eclipse.ui.ide;bundle-version="3.6.0",
- org.eclipse.jpt.jpa.core;bundle-version="3.0.0",
+ org.eclipse.libra.facet,
+ org.eclipse.libra.facet.ui,
+ org.eclipse.pde.core,
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.core.databinding.observable,
+ org.eclipse.ui.ide,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jst.common.project.facet.core,
org.eclipse.jst.j2ee,
org.eclipse.jst.j2ee.web,
- org.eclipse.jst.j2ee.ejb
+ org.eclipse.jst.j2ee.ejb,
+ org.eclipse.wst.common.tests
Bundle-Vendor: %Bundle-Vendor
Import-Package: org.junit;version="4.5.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/tests/org.eclipse.libra.facet.test/resources/TestWAB.zip_ b/tests/org.eclipse.libra.facet.test/resources/TestWAB.zip_
new file mode 100644
index 0000000..29ba316
--- /dev/null
+++ b/tests/org.eclipse.libra.facet.test/resources/TestWAB.zip_
Binary files differ
diff --git a/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/ProjectUnzipUtil.java b/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/ProjectUnzipUtil.java
deleted file mode 100644
index 68f3123..0000000
--- a/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/ProjectUnzipUtil.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 SAP AG and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Dimo Stoilov (SAP AG) - initial API and implementation
- *******************************************************************************/
-package org.eclipse.libra.facet.test;
-
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import org.eclipse.core.internal.resources.ProjectDescription;
-import org.eclipse.core.internal.resources.ProjectDescriptionReader;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-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.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-
-@SuppressWarnings("restriction")
-public class ProjectUnzipUtil {
-
- private IPath zipLocation;
- private String[] projectNames;
- private IPath rootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
- private static final String META_PROJECT_NAME = ".project";
-
-
- public ProjectUnzipUtil(IPath aZipLocation, String[] aProjectNames) {
- zipLocation = aZipLocation;
- projectNames = aProjectNames;
-
- }
-
- public boolean createProjects() throws CoreException {
- IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable(){
-
- public void run(IProgressMonitor monitor) throws CoreException {
- try {
- expandZip();
-// ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- buildProjects();
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.libra.facet.test", e.getCause().getMessage(), e));
- }
- }
-
- };
-
- ResourcesPlugin.getWorkspace().run(workspaceRunnable, new NullProgressMonitor());
-
- return true;
-
- }
-
- private IProgressMonitor getProgessMonitor() {
- return new NullProgressMonitor();
- }
-
- private void expandZip() throws CoreException, IOException {
- IProgressMonitor monitor = getProgessMonitor();
- ZipFile zipFile = null;
- zipFile = new ZipFile(zipLocation.toFile());
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- monitor.subTask(entry.getName());
- File aFile = computeLocation(entry.getName()).toFile();
- File parentFile = null;
- if (entry.isDirectory()) {
- aFile.mkdirs();
- } else {
- parentFile = aFile.getParentFile();
- if (!parentFile.exists())
- parentFile.mkdirs();
- if (!aFile.exists())
- aFile.createNewFile();
- copy(zipFile.getInputStream(entry), new FileOutputStream(aFile));
- if (entry.getTime() > 0)
- aFile.setLastModified(entry.getTime());
- }
- monitor.worked(1);
- }
- }
-
- private IPath computeLocation(String name) {
- return rootLocation.append(name);
- }
-
-
- public static void copy(InputStream in, OutputStream out) throws IOException {
- byte[] buffer = new byte[1024];
- try {
- int n = in.read(buffer);
- while (n > 0) {
- out.write(buffer, 0, n);
- n = in.read(buffer);
- }
- } finally {
- in.close();
- out.close();
- }
- }
-
- public void setRootLocation(IPath rootLocation) {
- this.rootLocation = rootLocation;
- }
-
- private void buildProjects() throws IOException, CoreException {
- for (int i = 0; i < projectNames.length; i++) {
- ProjectDescriptionReader pd = new ProjectDescriptionReader();
- IPath projectPath = new Path("/" + projectNames[i] + "/" + META_PROJECT_NAME);
- IPath path = rootLocation.append(projectPath);
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectNames[i]);
- ProjectDescription description;
- description = pd.read(path);
- project.create(description, (getProgessMonitor()));
- project.open(getProgessMonitor());
-// project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
- }
- }
-
-
-
-}
diff --git a/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java b/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java
index 8af5189..d82cb35 100644
--- a/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java
+++ b/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java
@@ -8,7 +8,13 @@
* Contributors:
* Dimo Stoilov (SAP AG) - initial API and implementation
*******************************************************************************/
-package org.eclipse.libra.facet.test;
+package org.eclipse.libra.facet.test;
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.BUILD_PROPERTIES;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getBundleProjectDescription;
+import static org.eclipse.wst.common.tests.OperationTestCase.deleteAllProjects;
+import static org.eclipse.wst.common.tests.OperationTestCase.waitOnJobs;
import java.io.IOException;
import java.util.ArrayList;
@@ -24,19 +30,17 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.etools.common.test.apitools.ProjectUnzipUtil;
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.libra.facet.Activator;
import org.eclipse.libra.facet.OSGiBundleFacetInstallConfig;
import org.eclipse.libra.facet.OSGiBundleFacetUninstallConfig;
import org.eclipse.libra.facet.OSGiBundleFacetUninstallStrategy;
-import org.eclipse.libra.facet.OSGiBundleFacetUtils;
import org.eclipse.libra.facet.ui.operations.ConvertProjectsToBundlesOperation;
import org.eclipse.pde.core.project.IBundleClasspathEntry;
import org.eclipse.pde.core.project.IBundleProjectDescription;
-import org.eclipse.pde.core.project.IBundleProjectService;
import org.eclipse.pde.core.project.IPackageExportDescription;
import org.eclipse.pde.core.project.IPackageImportDescription;
import org.eclipse.pde.internal.core.PDECore;
@@ -47,14 +51,13 @@ import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-
-
-@SuppressWarnings("restriction")
public class WabConversionTest {
private static final NullProgressMonitor monitor = new NullProgressMonitor();
private static final String WEB_PRJ_LOCATION = "resources/testWeb.zip_";
@@ -87,41 +90,27 @@ public class WabConversionTest {
private static final String SIMPLE_CONVERTED_PRJ_NAME = "testSimpleConverted";
private static final String PLUGIN_CONVERTED_PRJ_LOCATION = "resources/testPluginConverted.zip_";
private static final String PLUGIN_CONVERTED_PRJ_NAME = "testPluginConverted";
- @SuppressWarnings("unused")
- private static final String SIMPLE_PRJ_COPY_LOCATION = "resources/testSimpleCopy.zip_";
- @SuppressWarnings("unused")
- private static final String SIMPLE_PRJ_COPY_NAME = "testSimpleCopy";
private static final String JAVA_PRJ_COPY_LOCATION = "resources/testJavaCopy.zip_";
- private static final String JAVA_PRJ_COPY_NAME = "testJavaCopy";
-
-
- @Test
- public void createJPAProject() throws Exception {
- IFacetedProjectWorkingCopy fProject = FacetedProjectFramework.createNewProject();
- fProject.setProjectName(JPA_CREATE_PRJ_NAME);
- HashSet<IProjectFacetVersion> facets = getFacets(new String[] {"java", "jpt.jpa", "osgi.bundle"});
- fProject.setProjectFacets(facets);
- fProject.commitChanges(monitor);
- checkMetaInf(fProject.getProject());
+ private static final String JAVA_PRJ_COPY_NAME = "testJavaCopy";
+
+ @Before
+ public void cleanUpWorkspace() throws Exception {
+ deleteAllProjects();
+ waitOnJobs();
}
- @Test
- public void createJPAUtilityProject() throws Exception {
- IFacetedProjectWorkingCopy fProject = FacetedProjectFramework.createNewProject();
- fProject.setProjectName(JPA_UTILITY_CREATE_PRJ_NAME);
- HashSet<IProjectFacetVersion> facets = getFacets(new String[] {"java", "jpt.jpa", "jst.utility", "osgi.bundle"});
- fProject.setProjectFacets(facets);
- fProject.commitChanges(monitor);
- checkMetaInf(fProject.getProject());
- }
-
+ @After
+ public void waitJobs() throws Exception {
+ // Wait for all validation jobs to end before ending test....
+ waitOnJobs();
+ }
+
@Test
public void convertSimpleProject() throws Exception {
IProject simpleProject = importProjectInWorkspace(SIMPLE_PRJ_LOCATION, SIMPLE_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{simpleProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(simpleProject);
+ IBundleProjectDescription description = getBundleProjectDescription(simpleProject);
checkSimpleProject(SIMPLE_PRJ_NAME, "TestSimple", null, "1.0.0.qualifier", description);
}
@@ -132,24 +121,21 @@ public class WabConversionTest {
IProject javaProject = importProjectInWorkspace(JAVA_PRJ_LOCATION, JAVA_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{javaProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(javaProject);
+ IBundleProjectDescription description = getBundleProjectDescription(javaProject);
checkJavaProject(javaProject, JAVA_PRJ_NAME, "TestJava", null, "1.0.0.qualifier", new String[] {"javapack", "javapack1"}, description);
- }
-
- @Test
- public void convertJavaProjectCustomHeaders() throws Exception {
-
- IProject javaProject = importProjectInWorkspace(JAVA_PRJ_COPY_LOCATION, JAVA_PRJ_COPY_NAME);
- OSGiBundleFacetInstallConfig osgiBundleFacetInstallConfig = setupOSGiBundleFacetInstallConfig("customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier");
- IFacetedProject fproj = ProjectFacetsManager.create(javaProject, true, monitor);
- fproj.installProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, osgiBundleFacetInstallConfig, monitor);
-
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(javaProject);
-
- checkJavaProject(javaProject, "customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier", new String[] {"javapack", "javapack1"}, description);
+ }
+
+ @Test
+ public void convertJavaProjectCustomHeaders() throws Exception {
+ IProject javaProject = importProjectInWorkspace(JAVA_PRJ_COPY_LOCATION, JAVA_PRJ_COPY_NAME);
+ OSGiBundleFacetInstallConfig osgiBundleFacetInstallConfig = setupOSGiBundleFacetInstallConfig("customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier");
+ IFacetedProject fproj = ProjectFacetsManager.create(javaProject, true, monitor);
+ fproj.installProjectFacet(OSGI_BUNDLE_FACET_42, osgiBundleFacetInstallConfig, monitor);
+
+ IBundleProjectDescription description = getBundleProjectDescription(javaProject);
+
+ checkJavaProject(javaProject, "customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier", new String[] {"javapack", "javapack1"}, description);
}
@Test
@@ -157,8 +143,7 @@ public class WabConversionTest {
IProject pluginProject = importProjectInWorkspace(PLUGIN_PRJ_LOCATION, PLUGIN_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{pluginProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(pluginProject);
+ IBundleProjectDescription description = getBundleProjectDescription(pluginProject);
checkJavaProject(pluginProject, PLUGIN_PRJ_NAME, "TestPlugin", null, "1.0.0.qualifier", new String[] {"javapack", "javapack1", "testplugin"}, description);
@@ -177,8 +162,7 @@ public class WabConversionTest {
IProject pluginProject = importProjectInWorkspace(PLUGIN_PRJ_CUSTOM_HEADERS_LOCATION, PLUGIN_PRJ_CUSTOM_HEADERS_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{pluginProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(pluginProject);
+ IBundleProjectDescription description = getBundleProjectDescription(pluginProject);
IPackageImportDescription[] packageImports = description.getPackageImports();
Assert.assertNotNull(packageImports);
@@ -197,8 +181,7 @@ public class WabConversionTest {
IProject webProject = importProjectInWorkspace(WEB_PRJ_LOCATION, WEB_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{webProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(webProject);
+ IBundleProjectDescription description = getBundleProjectDescription(webProject);
checkWebProject(webProject, WEB_PRJ_NAME, "TestWeb", null, "1.0.0.qualifier", new String[] {"test", "test1"}, "/" + WEB_PRJ_NAME, description);
}
@@ -209,8 +192,7 @@ public class WabConversionTest {
IProject jpaProject = importProjectInWorkspace(JPA_PRJ_LOCATION, JPA_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{jpaProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(jpaProject);
+ IBundleProjectDescription description = getBundleProjectDescription(jpaProject);
checkJPAProject(jpaProject, JPA_PRJ_NAME, "TestJPA", null, "1.0.0.qualifier", new String[] {"test"}, description);
}
@@ -220,8 +202,7 @@ public class WabConversionTest {
IProject jpaProject = importProjectInWorkspace(JPA_UTILITY_PRJ_LOCATION, JPA_UTILITY_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{jpaProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(jpaProject);
+ IBundleProjectDescription description = getBundleProjectDescription(jpaProject);
checkJPAProject(jpaProject, JPA_UTILITY_PRJ_NAME, "TestJPAwithUtility", null, "1.0.0.qualifier", new String[] {"test"}, description);
}
@@ -232,10 +213,9 @@ public class WabConversionTest {
OSGiBundleFacetInstallConfig osgiBundleFacetInstallConfig = setupOSGiBundleFacetInstallConfig("customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier");
IFacetedProject fproj = ProjectFacetsManager.create(webProject, true, monitor);
- fproj.installProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, osgiBundleFacetInstallConfig, monitor);
+ fproj.installProjectFacet(OSGI_BUNDLE_FACET_42, osgiBundleFacetInstallConfig, monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(webProject);
+ IBundleProjectDescription description = getBundleProjectDescription(webProject);
checkWebProject(webProject, "customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier", new String[] {"test", "test1"}, "/customWebContext", description);
}
@@ -246,9 +226,8 @@ public class WabConversionTest {
IProject javaProject = importProjectInWorkspace(JAVA_REFERRED_PRJ_LOCATION, JAVA_REFERRED_PRJ_NAME);
new ConvertProjectsToBundlesOperation(new IProject[]{webProject, javaProject}).run(monitor);
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription webPrjDescription = bundleProjectService.getDescription(webProject);
- IBundleProjectDescription javaPrjDescription = bundleProjectService.getDescription(javaProject);
+ IBundleProjectDescription webPrjDescription = getBundleProjectDescription(webProject);
+ IBundleProjectDescription javaPrjDescription = getBundleProjectDescription(javaProject);
checkWebProject(webProject, WEB_REFERRING_JAVA_PRJ_NAME, "TestWebReferringJava", null, "1.0.0.qualifier", new String[] {"test", "test1"}, "/" + WEB_REFERRING_JAVA_PRJ_NAME, webPrjDescription);
checkJavaProject(javaProject, JAVA_REFERRED_PRJ_NAME, "TestJavaReferred", null, "1.0.0.qualifier", new String[] {"javapack", "javapack1"}, javaPrjDescription);
@@ -273,12 +252,12 @@ public class WabConversionTest {
IFacetedProject fproj = ProjectFacetsManager.create(webProject, true, monitor);
OSGiBundleFacetUninstallConfig config = new OSGiBundleFacetUninstallConfig();
config.setStrategy(OSGiBundleFacetUninstallStrategy.FACET_AND_PLUGIN_NATURE_AND_MANIFEST);
- fproj.uninstallProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, config, monitor);
+ fproj.uninstallProjectFacet(OSGI_BUNDLE_FACET_42, config, monitor);
Assert.assertFalse(webProject.hasNature(IBundleProjectDescription.PLUGIN_NATURE));
Assert.assertFalse(hasBuildSpec(webProject, PDE.MANIFEST_BUILDER_ID));
Assert.assertFalse(hasBuildSpec(webProject, PDE.SCHEMA_BUILDER_ID));
Assert.assertFalse(hasPluginDependenciesCP(webProject));
- IFile buildPropertiesFile = webProject.getFile("WebContent/" + OSGiBundleFacetUtils.BUILD_PROPERTIES);
+ IFile buildPropertiesFile = webProject.getFile("WebContent/" + BUILD_PROPERTIES);
Assert.assertFalse(buildPropertiesFile.exists());
}
@@ -288,12 +267,12 @@ public class WabConversionTest {
IFacetedProject fproj = ProjectFacetsManager.create(javaProject, true, monitor);
OSGiBundleFacetUninstallConfig config = new OSGiBundleFacetUninstallConfig();
config.setStrategy(OSGiBundleFacetUninstallStrategy.FACET_AND_PLUGIN_NATURE_AND_MANIFEST);
- fproj.uninstallProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, config, monitor);
+ fproj.uninstallProjectFacet(OSGI_BUNDLE_FACET_42, config, monitor);
Assert.assertFalse(javaProject.hasNature(IBundleProjectDescription.PLUGIN_NATURE));
Assert.assertFalse(hasBuildSpec(javaProject, PDE.MANIFEST_BUILDER_ID));
Assert.assertFalse(hasBuildSpec(javaProject, PDE.SCHEMA_BUILDER_ID));
Assert.assertFalse(hasPluginDependenciesCP(javaProject));
- IFile buildPropertiesFile = javaProject.getFile(OSGiBundleFacetUtils.BUILD_PROPERTIES);
+ IFile buildPropertiesFile = javaProject.getFile(BUILD_PROPERTIES);
Assert.assertFalse(buildPropertiesFile.exists());
}
@@ -303,10 +282,10 @@ public class WabConversionTest {
IFacetedProject fproj = ProjectFacetsManager.create(pluginProject, true, monitor);
OSGiBundleFacetUninstallConfig config = new OSGiBundleFacetUninstallConfig();
config.setStrategy(OSGiBundleFacetUninstallStrategy.FACET_ONLY);
- fproj.uninstallProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, config, monitor);
+ fproj.uninstallProjectFacet(OSGI_BUNDLE_FACET_42, config, monitor);
Assert.assertTrue(pluginProject.hasNature(IBundleProjectDescription.PLUGIN_NATURE));
Assert.assertTrue(hasPluginDependenciesCP(pluginProject));
- IFile buildPropertiesFile = pluginProject.getFile(OSGiBundleFacetUtils.BUILD_PROPERTIES);
+ IFile buildPropertiesFile = pluginProject.getFile(BUILD_PROPERTIES);
Assert.assertTrue(buildPropertiesFile.exists());
}
@@ -316,14 +295,33 @@ public class WabConversionTest {
IFacetedProject fproj = ProjectFacetsManager.create(simpleProject, true, monitor);
OSGiBundleFacetUninstallConfig config = new OSGiBundleFacetUninstallConfig();
config.setStrategy(OSGiBundleFacetUninstallStrategy.FACET_AND_PLUGIN_NATURE_AND_MANIFEST);
- fproj.uninstallProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, config, monitor);
+ fproj.uninstallProjectFacet(OSGI_BUNDLE_FACET_42, config, monitor);
Assert.assertFalse(simpleProject.hasNature(IBundleProjectDescription.PLUGIN_NATURE));
Assert.assertFalse(hasBuildSpec(simpleProject, PDE.MANIFEST_BUILDER_ID));
Assert.assertFalse(hasBuildSpec(simpleProject, PDE.SCHEMA_BUILDER_ID));
- IFile buildPropertiesFile = simpleProject.getFile(OSGiBundleFacetUtils.BUILD_PROPERTIES);
+ IFile buildPropertiesFile = simpleProject.getFile(BUILD_PROPERTIES);
Assert.assertFalse(buildPropertiesFile.exists());
}
-
+
+ @Test
+ public void createJPAProject() throws Exception {
+ IFacetedProjectWorkingCopy fProject = FacetedProjectFramework.createNewProject();
+ fProject.setProjectName(JPA_CREATE_PRJ_NAME);
+ HashSet<IProjectFacetVersion> facets = getFacets(new String[] {"java", "jpt.jpa", "osgi.bundle"});
+ fProject.setProjectFacets(facets);
+ fProject.commitChanges(monitor);
+ checkMetaInf(fProject.getProject());
+ }
+
+ @Test
+ public void createJPAUtilityProject() throws Exception {
+ IFacetedProjectWorkingCopy fProject = FacetedProjectFramework.createNewProject();
+ fProject.setProjectName(JPA_UTILITY_CREATE_PRJ_NAME);
+ HashSet<IProjectFacetVersion> facets = getFacets(new String[] {"java", "jpt.jpa", "jst.utility", "osgi.bundle"});
+ fProject.setProjectFacets(facets);
+ fProject.commitChanges(monitor);
+ checkMetaInf(fProject.getProject());
+ }
private void checkWebProject(IProject project, String expectedSymbolicName, String expectedBundleName, String expectedVendor, String expectedVersion, String[] expectedPackageExports, String expectedWebContextPath, IBundleProjectDescription description) throws JavaModelException {
checkJavaProject(project, expectedSymbolicName, expectedBundleName, expectedVendor, expectedVersion, expectedPackageExports, description);
@@ -482,4 +480,4 @@ public class WabConversionTest {
return facets;
}
-} \ No newline at end of file
+}
diff --git a/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WebContextRootSynchronizerTest.java b/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WebContextRootSynchronizerTest.java
new file mode 100644
index 0000000..25676f5
--- /dev/null
+++ b/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WebContextRootSynchronizerTest.java
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stefan Dimov (SAP AG) - initial API and implementation
+ * Kaloyan Raev (SAP AG)
+ *******************************************************************************/
+package org.eclipse.libra.facet.test;
+
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.VIRTUAL_COMPONENT_PATH;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.WEB_CONTEXT_PATH_HEADER;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getContextRootFromPDEModel;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.getContextRootFromWTPModel;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.setContextRootInPDEModel;
+import static org.eclipse.libra.facet.OSGiBundleFacetUtils.setContextRootInWTPModel;
+import static org.eclipse.wst.common.tests.OperationTestCase.deleteAllProjects;
+import static org.eclipse.wst.common.tests.OperationTestCase.waitOnJobs;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class WebContextRootSynchronizerTest {
+
+ private static final String APPEND = "Changed";
+
+ private static final String WAB_PRJ_LOCATION = "resources/TestWAB.zip_";
+ private static final String WAB_PRJ_NAME = "TestWAB";
+ private static final String CHANGED_WEB_CONTEXT_ROOT = '/' + WAB_PRJ_NAME + APPEND;
+
+ private static int MAX_ATTEMPTS = 20;
+
+ private IProject wabProject;
+
+ @Before
+ public void importProject() throws Exception {
+ deleteAllProjects();
+ waitOnJobs();
+ wabProject = importProjectInWorkspace(WAB_PRJ_LOCATION, WAB_PRJ_NAME);
+ }
+
+ @After
+ public void waitJobs() throws Exception {
+ // Wait for all validation jobs to end before ending test....
+ waitOnJobs();
+ }
+
+ @Test
+ public void testPDEChangeLeadsToWTPChange() throws Exception {
+ String newPDEWebContextPath = getContextRootFromPDEModel(wabProject) + APPEND;
+ setContextRootInPDEModel(wabProject, newPDEWebContextPath, null);
+ checkModels(wabProject, CHANGED_WEB_CONTEXT_ROOT);
+ }
+
+ @Test
+ public void testWTPChangeLeadsToPDEChange() throws Exception {
+ String newWTPWebContextPath = getContextRootFromWTPModel(wabProject) + APPEND;
+ setContextRootInWTPModel(wabProject, newWTPWebContextPath);
+ checkModels(wabProject, CHANGED_WEB_CONTEXT_ROOT);
+ }
+
+ @Test
+ public void testSettingsFileChangeLeadsToModelChange() throws Exception {
+ String newWTPWebContextPath = getContextRootFromWTPModel(wabProject) + APPEND;
+ setWebContextRootInSettings(wabProject, newWTPWebContextPath);
+ checkModels(wabProject, CHANGED_WEB_CONTEXT_ROOT);
+ }
+
+ @Test
+ public void testManifetsFileChangeLeadsToModelChange() throws Exception {
+ String newPDEWebContextPath = getContextRootFromPDEModel(wabProject) + APPEND;
+ setWebContextRootInManifest(wabProject, newPDEWebContextPath);
+ checkModels(wabProject, CHANGED_WEB_CONTEXT_ROOT);
+ }
+
+ @Test
+ public void testRemoveWebContextRootFromPDEModel() throws Exception {
+ setContextRootInPDEModel(wabProject, null, null);
+ checkModels(wabProject, null);
+ }
+
+ @Test
+ public void testRemoveWebContextRootFromWTPModel() throws Exception {
+ setContextRootInWTPModel(wabProject, null);
+ checkModels(wabProject, null);
+ }
+
+
+ // ------------------------------ private helper methods ----------------------------------------------
+
+ private IProject importProjectInWorkspace(String projectZipLocation, String projectName) throws IOException, CoreException{
+ String userDir = System.getProperty("user.dir");
+ String localZipPath = userDir + IPath.SEPARATOR + projectZipLocation;
+ org.eclipse.etools.common.test.apitools.ProjectUnzipUtil util = new org.eclipse.etools.common.test.apitools.ProjectUnzipUtil(new Path(localZipPath), new String[] {projectName});
+ Assert.assertTrue(util.createProjects());
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ return project;
+ }
+
+ private boolean areModelsEqualToTheExpectedValue(IProject project, String expectedWebContextRoot) throws CoreException {
+ String pdeWebContextPath = getContextRootFromPDEModel(project);
+ String wtpWebContextPath = getContextRootFromWTPModel(project);
+
+ if (expectedWebContextRoot == null) {
+ return pdeWebContextPath == null && wtpWebContextPath == null;
+ } else {
+ return expectedWebContextRoot.equals(pdeWebContextPath) && expectedWebContextRoot.equals(wtpWebContextPath);
+ }
+ }
+
+ private void checkModels(IProject wabProject, String expectedWebContextRoot) throws CoreException {
+ boolean equal = false;
+
+ for (int attempt = 0; attempt < MAX_ATTEMPTS && !equal; attempt++) {
+ equal = areModelsEqualToTheExpectedValue(wabProject, expectedWebContextRoot);
+ if (!equal) {
+ // we need to wait for the other model to refresh
+ wabProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ try {
+ Thread.sleep(1000);// 1 second
+ } catch (InterruptedException iexc) {
+ System.out.println("Interrupted exception caught. Checking once more.");
+ wabProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ equal = areModelsEqualToTheExpectedValue(wabProject, expectedWebContextRoot);
+ }
+ }
+ }
+
+ // check that both models are set to the new context root
+ Assert.assertEquals(expectedWebContextRoot, getContextRootFromPDEModel(wabProject));
+ Assert.assertEquals(expectedWebContextRoot, getContextRootFromWTPModel(wabProject));
+ }
+
+ private void setWebContextRootInSettings(IProject wabProject, String newValue) throws ParserConfigurationException, SAXException, IOException, TransformerException, CoreException {
+ IFile settingsFile = wabProject.getFile(VIRTUAL_COMPONENT_PATH);
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ Document xmlDocument = db.parse(settingsFile.getContents());
+ changeWebContextRootFromSettings(xmlDocument, newValue);
+
+ InputStream is = new ByteArrayInputStream(saveDomToBytes(xmlDocument));
+ settingsFile.setContents(is, IResource.KEEP_HISTORY | IResource.FORCE, null);
+ }
+
+ private Element getWebModuleElement(Document xmlDocument) {
+ Element root = xmlDocument.getDocumentElement();
+ NodeList children = root.getElementsByTagName("wb-module");
+ Element webModuleElem = (Element)children.item(0);
+ return webModuleElem;
+ }
+
+ private Element getContextRootProperty(Element webModuleElement) {
+ NodeList webModuleElementProperties = webModuleElement.getElementsByTagName("property");
+ for (int i = 0; i < webModuleElementProperties.getLength(); i++) {
+ Element property = (Element) webModuleElementProperties.item(i);
+ NamedNodeMap attributes = property.getAttributes();
+ Attr nameAttribute = (Attr) attributes.getNamedItem("name");
+ if (nameAttribute.getNodeValue().equals("context-root")) {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ private Attr getValueAttribute(Element contextRootProperty) {
+ NamedNodeMap attributes = contextRootProperty.getAttributes();
+ Attr valueAttribute = (Attr) attributes.getNamedItem("value");
+ if (valueAttribute != null) {
+ return valueAttribute;
+ }
+ return null;
+ }
+
+ private void changeWebContextRootFromSettings(Document xmlDocument, String newValue) {
+ Element webModuleElement = getWebModuleElement(xmlDocument);
+ Element contextRootProperty = getContextRootProperty(webModuleElement);
+ Attr valueAttribute = getValueAttribute(contextRootProperty);
+ valueAttribute.setNodeValue(newValue);
+ }
+
+ private byte[] saveDomToBytes(Document xmlDocument) throws TransformerException {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(xmlDocument), new StreamResult(os));
+
+ return os.toByteArray();
+ }
+
+ private void setWebContextRootInManifest(IProject wabProject, String newContextRoot) throws CoreException, IOException {
+ IFile manifestFile = wabProject.getFile(new Path("WebContent/META-INF/MANIFEST.MF"));
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ PrintWriter pw = new PrintWriter(os);
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(manifestFile.getContents()));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ if (line.startsWith(WEB_CONTEXT_PATH_HEADER)) {
+ pw.println(WEB_CONTEXT_PATH_HEADER + ": " + newContextRoot);
+ } else {
+ pw.println(line);
+ }
+ }
+
+ pw.flush();
+
+ InputStream is = new ByteArrayInputStream(os.toByteArray());
+ manifestFile.setContents(is, IResource.KEEP_HISTORY | IResource.FORCE, null);
+ }
+
+}