### Eclipse Workspace Patch 1.0 #P org.jboss.tools.maven.portlet.feature Index: feature.xml =================================================================== --- feature.xml (revision 32782) +++ feature.xml (working copy) @@ -2,7 +2,7 @@ @@ -19,8 +19,8 @@ - - + + - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + features + 0.0.1-SNAPSHOT org.jboss.tools.maven.features - org.jboss.tools.maven.portlet.feature - 1.0.0-SNAPSHOT + org.jboss.tools.maven.portlet.feature + 1.2.0-SNAPSHOT eclipse-feature - + \ No newline at end of file Index: feature.properties =================================================================== --- feature.properties (revision 32782) +++ feature.properties (working copy) @@ -1,53 +1,53 @@ -############################################################################### -# Copyright (c) 2011 Red Hat, Inc. 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: -# JBoss by Red Hat - Initial implementation. -############################################################################## -# feature.properties -# contains externalized strings for feature.xml -# "%foo" in feature.xml corresponds to the key "foo" in this file -# java.io.Properties file (ISO 8859-1 with "\" escapes) -# This file should be translated. - -# "featureName" property - name of the feature -featureName=JBoss Maven Portlet Configurator - -# "providerName" property - name of the company that provides the feature -providerName=JBoss by Red Hat - -# "updateSiteName" property - label for the update site -updateSiteName=JBossTools Update Site - -# "description" property - description of the feature -description=JBoss Maven Portlet Integration - -# "copyright" property - text of the "Feature Update Copyright" -copyright=Copyright (c) 2011 Red Hat, Inc. and others.\n\ -All rights reserved. This program and the accompanying materials\n\ -are made available under the terms of the Eclipse Public License v1.0\n\ -which accompanies this distribution, and is available at\n\ -http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ -JBoss by Red Hat - Initial implementation. - ############### end of copyright property #################################### - -# "licenseURL" property - URL of the "Feature License" -# do not translate value - just change to point to a locale-specific HTML page -licenseURL=license.html - -# START NON-TRANSLATABLE -# "license" property - text of the "Feature Update License" -# should be plain text version of license agreement pointed to be "licenseURL" -license=Red Hat, Inc. licenses these features and plugins to you under \ -certain open source licenses (or aggregations of such licenses), which \ -in a particular case may include the Eclipse Public License, the GNU \ -Lesser General Public License, and/or certain other open source \ -licenses. For precise licensing details, consult the corresponding \ -source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ -Raleigh NC 27606 USA. -# END NON-TRANSLATABLE -########### end of license property ########################################## +############################################################################### +# Copyright (c) 2010-2011 Red Hat, Inc. 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: +# JBoss by Red Hat - Initial implementation. +############################################################################## +# feature.properties +# contains externalized strings for feature.xml +# "%foo" in feature.xml corresponds to the key "foo" in this file +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# This file should be translated. + +# "featureName" property - name of the feature +featureName=JBoss Maven Portlet Configurator + +# "providerName" property - name of the company that provides the feature +providerName=JBoss by Red Hat + +# "updateSiteName" property - label for the update site +updateSiteName=JBossTools Update Site + +# "description" property - description of the feature +description=JBoss Maven Portlet Integration + +# "copyright" property - text of the "Feature Update Copyright" +copyright=Copyright (c) 2010-2011 Red Hat, Inc. and others.\n\ +All rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\n\ +which accompanies this distribution, and is available at\n\ +http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ +JBoss by Red Hat - Initial implementation. + ############### end of copyright property #################################### + +# "licenseURL" property - URL of the "Feature License" +# do not translate value - just change to point to a locale-specific HTML page +licenseURL=license.html + +# START NON-TRANSLATABLE +# "license" property - text of the "Feature Update License" +# should be plain text version of license agreement pointed to be "licenseURL" +license=Red Hat, Inc. licenses these features and plugins to you under \ +certain open source licenses (or aggregations of such licenses), which \ +in a particular case may include the Eclipse Public License, the GNU \ +Lesser General Public License, and/or certain other open source \ +licenses. For precise licensing details, consult the corresponding \ +source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ +Raleigh NC 27606 USA. +# END NON-TRANSLATABLE +########### end of license property ########################################## #P org.jboss.tools.maven.seam Index: build.properties =================================================================== --- build.properties (revision 32782) +++ build.properties (working copy) @@ -1,12 +1,13 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - about.html,\ - about.ini,\ - about.mappings,\ - about.properties,\ - jboss_about.png,\ - poms/,\ - plugin.properties +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + about.html,\ + about.ini,\ + about.mappings,\ + about.properties,\ + jboss_about.png,\ + poms/,\ + plugin.properties,\ + lifecycle-mapping-metadata.xml Index: lifecycle-mapping-metadata.xml =================================================================== --- lifecycle-mapping-metadata.xml (revision 0) +++ lifecycle-mapping-metadata.xml (revision 0) @@ -0,0 +1,71 @@ + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + [2.0,) + + compile + testCompile + + + + + org.jboss.tools.maven.seam.configurator.fixClasspathConfigurator + + + + + + + org.apache.maven.plugins + maven-war-plugin + [1.0,) + + war + + + + + org.jboss.tools.maven.seam.configurator + + + + + + + org.apache.maven.plugins + maven-ejb-plugin + [1.0,) + + ejb + + + + + org.jboss.tools.maven.seam.configurator + + + + + + + org.apache.maven.plugins + maven-ear-plugin + [1.0,) + + ear + + + + + org.jboss.tools.maven.seam.configurator + + + + + + \ No newline at end of file Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.seam - 1.1.0-SNAPSHOT + org.jboss.tools.maven.seam + 1.2.0-SNAPSHOT eclipse-plugin - + \ No newline at end of file Index: src/org/jboss/tools/maven/seam/ParentAdder.java =================================================================== --- src/org/jboss/tools/maven/seam/ParentAdder.java (revision 32782) +++ src/org/jboss/tools/maven/seam/ParentAdder.java (working copy) @@ -1,36 +1,51 @@ -package org.jboss.tools.maven.seam; - -import org.maven.ide.components.pom.Model; -import org.maven.ide.components.pom.Parent; -import org.maven.ide.components.pom.PomFactory; -import org.maven.ide.eclipse.embedder.ProjectUpdater; - -public class ParentAdder extends ProjectUpdater { - - private static final PomFactory POM_FACTORY = PomFactory.eINSTANCE; - private final String groupId; - private final String artifactId; - private final String version; - private String relativePath; - - public ParentAdder(String groupId, String artifactId, String version, String relativePath) { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.relativePath = relativePath; - } - - public void update(Model model) { - Parent parent = model.getParent(); - if(parent==null) { - parent = POM_FACTORY.createParent(); - parent.setArtifactId(artifactId); - parent.setGroupId(groupId); - parent.setVersion(version); - if (relativePath != null) { - parent.setRelativePath(relativePath); - } - model.setParent(parent); - } - } +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.seam; + +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.Parent; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.jboss.tools.maven.core.xpl.ProjectUpdater; + +/** + * + * @author snjeza + * + */ +public class ParentAdder extends ProjectUpdater { + + private static final PomFactory POM_FACTORY = PomFactory.eINSTANCE; + private final String groupId; + private final String artifactId; + private final String version; + private String relativePath; + + public ParentAdder(String groupId, String artifactId, String version, String relativePath) { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.relativePath = relativePath; + } + + public void update(Model model) { + Parent parent = model.getParent(); + if(parent==null) { + parent = POM_FACTORY.createParent(); + parent.setArtifactId(artifactId); + parent.setGroupId(groupId); + parent.setVersion(version); + if (relativePath != null) { + parent.setRelativePath(relativePath); + } + model.setParent(parent); + } + } } \ No newline at end of file Index: src/org/jboss/tools/maven/seam/configurators/FixClasspathConfigurator.java =================================================================== --- src/org/jboss/tools/maven/seam/configurators/FixClasspathConfigurator.java (revision 32782) +++ src/org/jboss/tools/maven/seam/configurators/FixClasspathConfigurator.java (working copy) @@ -1,141 +1,141 @@ -/************************************************************************************* - * Copyright (c) 2008-2011 Red Hat, Inc. 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: - * JBoss by Red Hat - Initial implementation. - ************************************************************************************/ -package org.jboss.tools.maven.seam.configurators; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.apache.maven.model.Resource; -import org.apache.maven.project.MavenProject; -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.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.jboss.tools.maven.seam.MavenSeamActivator; -import org.maven.ide.eclipse.project.IMavenProjectFacade; -import org.maven.ide.eclipse.project.MavenProjectChangedEvent; -import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator; -import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest; - -/** - * A workaround for https://issues.sonatype.org/browse/MNGECLIPSE-2433 - * - * @author Snjeza - */ -public class FixClasspathConfigurator extends AbstractProjectConfigurator { - - @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { - MavenProject mavenProject = request.getMavenProject(); - IProject project = request.getProject(); - configureInternal(mavenProject,project, monitor); - } - - private void configureInternal(MavenProject mavenProject, IProject project, - IProgressMonitor monitor) throws CoreException { - if (!project.hasNature(JavaCore.NATURE_ID)) { - return; - } - List resources = mavenProject.getResources(); - for (Resource resource:resources) { - - File directory = new File(resource.getDirectory()); - String absolutePath = directory.getAbsolutePath(); - try { - absolutePath = directory.getCanonicalPath(); - } catch(IOException e) { - MavenSeamActivator.log(e); - } - if (! new File(absolutePath).exists()) { - continue; - } - IPath relativePath = getProjectRelativePath(project, absolutePath); - IResource r = project.findMember(relativePath); - if (r != null) { - continue; - } - String path = getWorkspaceRelativePath(absolutePath); - IJavaProject javaProject = JavaCore.create(project); - IClasspathEntry[] entries = javaProject.getRawClasspath(); - boolean exists = false; - for (IClasspathEntry entry:entries) { - if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { - IPath entryPath = entry.getPath(); - if (entryPath != null && path.equals(entryPath.toString())) { - exists = true; - break; - } - } - } - if (!exists) { - IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; - for (int i = 0; i < entries.length; i++) { - newEntries[i] = entries[i]; - } - IClasspathEntry pathEntry = JavaCore.newLibraryEntry(new Path(path), null, null); - newEntries[entries.length] = pathEntry; - javaProject.setRawClasspath(newEntries, monitor); - } - } - } - - private String getWorkspaceRelativePath(String absolutePath) { - File basedir = ResourcesPlugin.getWorkspace().getRoot().getLocation() - .toFile(); - String relative; - if (absolutePath.equals(basedir.getAbsolutePath())) { - relative = "."; //$NON-NLS-1$ - } else if (absolutePath.startsWith(basedir.getAbsolutePath())) { - relative = absolutePath.substring(basedir.getAbsolutePath() - .length() + 1); - } else { - return absolutePath; - } - relative = relative.replace("\\", "/").trim(); //$NON-NLS-1$ //$NON-NLS-2$ - if (!relative.startsWith("/")) { //$NON-NLS-1$ - relative = "/" + relative; //$NON-NLS-1$ - } - return relative; - } - - private IPath getProjectRelativePath(IProject project, String absolutePath) { - File basedir = project.getLocation().toFile(); - String relative; - if (absolutePath.equals(basedir.getAbsolutePath())) { - relative = "."; //$NON-NLS-1$ - } else if (absolutePath.startsWith(basedir.getAbsolutePath())) { - relative = absolutePath.substring(basedir.getAbsolutePath().length() + 1); - } else { - relative = absolutePath; - } - return new Path(relative.replace('\\', '/')); - } - - @Override - public void mavenProjectChanged(MavenProjectChangedEvent event, - IProgressMonitor monitor) throws CoreException { - IMavenProjectFacade facade = event.getMavenProject(); - if (facade != null) { - IProject project = facade.getProject(); - MavenProject mavenProject = facade.getMavenProject(monitor); - configureInternal(mavenProject, project, monitor); - } - super.mavenProjectChanged(event, monitor); - } -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.seam.configurators; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.maven.model.Resource; +import org.apache.maven.project.MavenProject; +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.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.jboss.tools.maven.seam.MavenSeamActivator; + +/** + * A workaround for https://issues.sonatype.org/browse/MNGECLIPSE-2433 + * + * @author snjeza + */ +public class FixClasspathConfigurator extends AbstractProjectConfigurator { + + @Override + public void configure(ProjectConfigurationRequest request, + IProgressMonitor monitor) throws CoreException { + MavenProject mavenProject = request.getMavenProject(); + IProject project = request.getProject(); + configureInternal(mavenProject,project, monitor); + } + + private void configureInternal(MavenProject mavenProject, IProject project, + IProgressMonitor monitor) throws CoreException { + if (!project.hasNature(JavaCore.NATURE_ID)) { + return; + } + List resources = mavenProject.getResources(); + for (Resource resource:resources) { + + File directory = new File(resource.getDirectory()); + String absolutePath = directory.getAbsolutePath(); + try { + absolutePath = directory.getCanonicalPath(); + } catch(IOException e) { + MavenSeamActivator.log(e); + } + if (! new File(absolutePath).exists()) { + continue; + } + IPath relativePath = getProjectRelativePath(project, absolutePath); + IResource r = project.findMember(relativePath); + if (r != null) { + continue; + } + String path = getWorkspaceRelativePath(absolutePath); + IJavaProject javaProject = JavaCore.create(project); + IClasspathEntry[] entries = javaProject.getRawClasspath(); + boolean exists = false; + for (IClasspathEntry entry:entries) { + if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { + IPath entryPath = entry.getPath(); + if (entryPath != null && path.equals(entryPath.toString())) { + exists = true; + break; + } + } + } + if (!exists) { + IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; + for (int i = 0; i < entries.length; i++) { + newEntries[i] = entries[i]; + } + IClasspathEntry pathEntry = JavaCore.newLibraryEntry(new Path(path), null, null); + newEntries[entries.length] = pathEntry; + javaProject.setRawClasspath(newEntries, monitor); + } + } + } + + private String getWorkspaceRelativePath(String absolutePath) { + File basedir = ResourcesPlugin.getWorkspace().getRoot().getLocation() + .toFile(); + String relative; + if (absolutePath.equals(basedir.getAbsolutePath())) { + relative = "."; //$NON-NLS-1$ + } else if (absolutePath.startsWith(basedir.getAbsolutePath())) { + relative = absolutePath.substring(basedir.getAbsolutePath() + .length() + 1); + } else { + return absolutePath; + } + relative = relative.replace("\\", "/").trim(); //$NON-NLS-1$ //$NON-NLS-2$ + if (!relative.startsWith("/")) { //$NON-NLS-1$ + relative = "/" + relative; //$NON-NLS-1$ + } + return relative; + } + + private IPath getProjectRelativePath(IProject project, String absolutePath) { + File basedir = project.getLocation().toFile(); + String relative; + if (absolutePath.equals(basedir.getAbsolutePath())) { + relative = "."; //$NON-NLS-1$ + } else if (absolutePath.startsWith(basedir.getAbsolutePath())) { + relative = absolutePath.substring(basedir.getAbsolutePath().length() + 1); + } else { + relative = absolutePath; + } + return new Path(relative.replace('\\', '/')); + } + + @Override + public void mavenProjectChanged(MavenProjectChangedEvent event, + IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = event.getMavenProject(); + if (facade != null) { + IProject project = facade.getProject(); + MavenProject mavenProject = facade.getMavenProject(monitor); + configureInternal(mavenProject, project, monitor); + } + super.mavenProjectChanged(event, monitor); + } +} Index: plugin.xml =================================================================== --- plugin.xml (revision 32782) +++ plugin.xml (working copy) @@ -1,26 +1,41 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/org/jboss/tools/maven/seam/configurators/SeamProjectConfigurator.java =================================================================== --- src/org/jboss/tools/maven/seam/configurators/SeamProjectConfigurator.java (revision 32782) +++ src/org/jboss/tools/maven/seam/configurators/SeamProjectConfigurator.java (working copy) @@ -1,730 +1,744 @@ -package org.jboss.tools.maven.seam.configurators; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.model.Dependency; -import org.apache.maven.project.MavenProject; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ProjectScope; -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.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.emf.common.util.EList; -import org.eclipse.jdt.core.IClasspathEntry; -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.jface.preference.IPreferenceStore; -import org.eclipse.jst.j2ee.application.Application; -import org.eclipse.jst.j2ee.application.Module; -import org.eclipse.jst.j2ee.application.internal.operations.AddComponentToEnterpriseApplicationDataModelProvider; -import org.eclipse.jst.j2ee.application.internal.operations.RemoveComponentFromEnterpriseApplicationDataModelProvider; -import org.eclipse.jst.j2ee.application.internal.operations.RemoveComponentFromEnterpriseApplicationOperation; -import org.eclipse.jst.j2ee.componentcore.util.EARArtifactEdit; -import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -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.jboss.tools.common.model.util.EclipseResourceUtil; -import org.jboss.tools.jst.web.kb.IKbProject; -import org.jboss.tools.maven.core.IJBossMavenConstants; -import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; -import org.jboss.tools.maven.jsf.MavenJSFActivator; -import org.jboss.tools.maven.seam.MavenSeamActivator; -import org.jboss.tools.maven.ui.Activator; -import org.jboss.tools.seam.core.ISeamProject; -import org.jboss.tools.seam.core.SeamCorePlugin; -import org.jboss.tools.seam.core.SeamUtil; -import org.jboss.tools.seam.core.project.facet.SeamRuntime; -import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager; -import org.jboss.tools.seam.core.project.facet.SeamVersion; -import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties; -import org.jboss.tools.seam.internal.core.project.facet.SeamFacetInstallDataModelProvider; -import org.jboss.tools.seam.ui.wizard.SeamWizardUtils; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.project.IMavenProjectFacade; -import org.maven.ide.eclipse.project.MavenProjectChangedEvent; -import org.maven.ide.eclipse.project.MavenProjectManager; -import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator; -import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest; -import org.osgi.service.prefs.BackingStoreException; - -public class SeamProjectConfigurator extends AbstractProjectConfigurator { - - private static final String JBOSS_SEAM_ARTIFACT_PREFIX = "jboss-seam"; //$NON-NLS-1$ - private static final String ORG_JBOSS_SEAM_GROUP_ID = "org.jboss.seam"; //$NON-NLS-1$ - private static final String JBOSS_SEAM_ARTIFACT_ID = "jboss-seam"; //$NON-NLS-1$ - - protected static final IProjectFacet dynamicWebFacet; - protected static final IProjectFacetVersion dynamicWebVersion; - protected static final IProjectFacet javaFacet; - protected static final IProjectFacetVersion javaVersion; - protected static final IProjectFacet jsfFacet; - protected static final IProjectFacetVersion jsfVersion; - protected static final IProjectFacet earFacet; - protected static final IProjectFacetVersion earVersion; - protected static final IProjectFacet ejbFacet; - protected static final IProjectFacetVersion ejbVersion; - protected static final IProjectFacet m2Facet; - protected static final IProjectFacetVersion m2Version; - private static final IProjectFacet seamFacet; - private static final IProjectFacet portletFacet; - private static final IProjectFacet jsfportletFacet; - private static final IProjectFacet seamPortletFacet; - private static final IProjectFacetVersion seamPortletVersion; - - static { - seamFacet = ProjectFacetsManager.getProjectFacet("jst.seam"); //$NON-NLS-1$ - javaFacet = ProjectFacetsManager.getProjectFacet("jst.java"); //$NON-NLS-1$ - javaVersion = javaFacet.getVersion("5.0"); //$NON-NLS-1$ - dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ - dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ - jsfFacet = ProjectFacetsManager.getProjectFacet("jst.jsf"); //$NON-NLS-1$ - jsfVersion = jsfFacet.getVersion("1.2"); //$NON-NLS-1$ - earFacet = ProjectFacetsManager.getProjectFacet("jst.ear"); //$NON-NLS-1$ - earVersion = earFacet.getVersion("5.0"); //$NON-NLS-1$ - m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ - m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ - ejbFacet = ProjectFacetsManager.getProjectFacet("jst.ejb"); //$NON-NLS-1$ - ejbVersion = ejbFacet.getVersion("3.0"); //$NON-NLS-1$ - portletFacet = ProjectFacetsManager.getProjectFacet("jboss.portlet"); //$NON-NLS-1$ - jsfportletFacet = ProjectFacetsManager.getProjectFacet("jboss.jsfportlet"); //$NON-NLS-1$ - seamPortletFacet = ProjectFacetsManager.getProjectFacet("jboss.seamportlet"); //$NON-NLS-1$ - seamPortletVersion = seamPortletFacet.getVersion("1.0"); //$NON-NLS-1$ - } - - @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { - // adds Seam capabilities if there are Seam dependencies - MavenProject mavenProject = request.getMavenProject(); - IProject project = request.getProject(); - configureInternal(mavenProject,project, monitor); - - } - - private boolean isSeamSettingChangedByUser(IProject project) { - IEclipsePreferences projectPreferences = SeamCorePlugin.getSeamPreferences(project); - boolean seamSettingsChangedByUser = projectPreferences.getBoolean(ISeamFacetDataModelProperties.SEAM_SETTINGS_CHANGED_BY_USER, false); - return seamSettingsChangedByUser; - } - - private void configureInternal(MavenProject mavenProject,IProject project, - IProgressMonitor monitor) throws CoreException { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - boolean configureSeam = store.getBoolean(Activator.CONFIGURE_SEAM); - if (!configureSeam) { - return; - } - if (isSeamSettingChangedByUser(project)) { - return; - } - IProject rootSeamProject = SeamWizardUtils.getRootSeamProject(project); - if (rootSeamProject != null && isSeamSettingChangedByUser(rootSeamProject)) { - return; - } - String packaging = mavenProject.getPackaging(); - String seamVersion = getSeamVersion(mavenProject); - if (seamVersion != null) { - IProject[] earProjects = J2EEProjectUtilities.getReferencingEARProjects(project); - String deploying = packaging; - if (earProjects.length > 0) { - deploying = "ear"; //$NON-NLS-1$ - } - final IFacetedProject fproj = ProjectFacetsManager.create(project); - if (fproj == null) { - return; - } - if ("war".equals(packaging)) { //$NON-NLS-1$ - IDataModel model = createSeamDataModel(deploying, seamVersion, project); - installWarFacets(fproj, model, seamVersion, monitor); - } else if ("ear".equals(packaging)) { //$NON-NLS-1$ - configureApplicationXml(project, monitor); - installEarFacets(fproj, monitor); - installM2Facet(fproj, monitor); - IProject webProject = getReferencingSeamWebProject(project); - if (webProject != null) { - IEclipsePreferences prefs = SeamCorePlugin.getSeamPreferences(webProject); - String deployingType = prefs.get(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,null); - if (deployingType == null || deployingType.equals(ISeamFacetDataModelProperties.DEPLOY_AS_WAR)) { - prefs.put(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,ISeamFacetDataModelProperties.DEPLOY_AS_EAR); - storeSettings(webProject); - } - IProject ejbProject = getReferencingSeamEJBProject(project); - if (ejbProject != null) { - prefs.put(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT, ejbProject.getName()); - IJavaProject javaProject = JavaCore.create(ejbProject); - boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); - if (configureSeamArtifacts) { - if (javaProject != null && javaProject.isOpen()) { - try { - IClasspathEntry[] entries = javaProject.getRawClasspath(); - for (int i = 0; i < entries.length; i++) { - IClasspathEntry entry = entries[i]; - if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { - String sourceFolder = entry.getPath().toString(); - prefs.put(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER, sourceFolder); - prefs.put(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER, sourceFolder); - break; - } - } - } catch (JavaModelException e) { - MavenSeamActivator.log(e); - } - } - IPackageFragment[] packageFragments = javaProject.getPackageFragments(); - for (int i = 0; i < packageFragments.length; i++) { - IPackageFragment pf = packageFragments[i]; - if (pf != null && pf.getKind() == IPackageFragmentRoot.K_SOURCE && !pf.isDefaultPackage()) { - if (pf.hasSubpackages() && !pf.hasChildren()) { - continue; - } - String packageName = pf.getElementName(); - prefs.put(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME, packageName); - prefs.put(ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME, packageName); - } - } - } - } - storeSettings(webProject); - } - - } else if ("ejb".equals(packaging)) { //$NON-NLS-1$ - installM2Facet(fproj,monitor); - installEjbFacets(fproj, monitor); - addSeamSupport(project, earProjects); - storeSettings(project); - - } -// addSeamSupport(project); -// -// storeSettings(project); - } - } - - private String getViewFolder(IProject project) { - IVirtualComponent com = ComponentCore.createComponent(project); - String viewFolder = null; - if(com!=null) { - IVirtualFolder webRootFolder = com.getRootFolder().getFolder(new Path("/")); //$NON-NLS-1$ - if(webRootFolder!=null) { - viewFolder = webRootFolder.getUnderlyingFolder().getFullPath().toString(); - } - } - return viewFolder; - } - - @Override - public void mavenProjectChanged(MavenProjectChangedEvent event, - IProgressMonitor monitor) throws CoreException { - IMavenProjectFacade facade = event.getMavenProject(); - if(facade != null) { - IProject project = facade.getProject(); - if(isWTPProject(project)) { - MavenProject mavenProject = facade.getMavenProject(monitor); - configureInternal(mavenProject, project, monitor); - } - } - super.mavenProjectChanged(event, monitor); - } - - private boolean isWTPProject(IProject project) { - return ModuleCoreNature.getModuleCoreNature(project) != null; - } - - private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) throws CoreException { - if (!fproj.hasProjectFacet(m2Facet)) { - IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider().create(); - config.setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); - fproj.installProjectFacet(m2Version, config, monitor); - } - } - - private IProjectFacetVersion getSeamFacetVersion(String seamVersion) { - String version = seamVersion.substring(0, 3); - return seamFacet.getVersion(version); - } - - private void installEarFacets(IFacetedProject fproj,IProgressMonitor monitor) throws CoreException { - if (!fproj.hasProjectFacet(earFacet)) { - fproj.installProjectFacet(earVersion, null, monitor); - } - - } - - private void installEjbFacets(IFacetedProject fproj,IProgressMonitor monitor) throws CoreException { - if (!fproj.hasProjectFacet(javaFacet)) { - fproj.installProjectFacet(javaVersion, null, monitor); - } - if (!fproj.hasProjectFacet(ejbFacet)) { - fproj.installProjectFacet(ejbVersion, null, monitor); - } - } - - private void installWarFacets(IFacetedProject fproj,IDataModel model, String seamVersion,IProgressMonitor monitor) throws CoreException { - if (!fproj.hasProjectFacet(javaFacet)) { - fproj.installProjectFacet(javaVersion, null, monitor); - } - if (!fproj.hasProjectFacet(dynamicWebFacet)) { - fproj.installProjectFacet(dynamicWebVersion, null, monitor); - } - installJSFFacet(fproj, monitor); - installM2Facet(fproj, monitor); - if (!fproj.hasProjectFacet(seamFacet)) { - IProjectFacetVersion seamFacetVersion = getSeamFacetVersion(seamVersion); - fproj.installProjectFacet(seamFacetVersion, model, monitor); - } else { - String deploying = model.getStringProperty(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS); - if (deploying != null && deploying.equals(ISeamFacetDataModelProperties.DEPLOY_AS_WAR)) { - IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); - boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); - if (!configureSeamArtifacts) { - return; - } - IEclipsePreferences prefs = SeamCorePlugin.getSeamPreferences(fproj.getProject()); - setModelProperty(model, prefs,ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER); - setModelProperty(model, prefs,ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER); - setModelProperty(model, prefs,ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME); - setModelProperty(model, prefs,ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME); - setModelProperty(model, prefs,ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER); - } - } - IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); - boolean configureSeamPortlet = store.getBoolean(Activator.CONFIGURE_SEAMPORTLET); - if (!configureSeamPortlet) { - return; - } - if (fproj.hasProjectFacet(seamFacet) && fproj.hasProjectFacet(portletFacet) && fproj.hasProjectFacet(jsfportletFacet)) { - if (!fproj.hasProjectFacet(seamPortletFacet)) { - fproj.installProjectFacet(seamPortletVersion, null, monitor); - } - } - } - - private void setModelProperty(IDataModel model, IEclipsePreferences prefs, String property) { - String value = model.getStringProperty(property); - if (value != null && value.trim().length() > 0) { - prefs.put(property, value); - } - } - - private void installJSFFacet(IFacetedProject fproj, IProgressMonitor monitor) - throws CoreException { - if (!fproj.hasProjectFacet(jsfFacet)) { - IDataModel model = MavenJSFActivator.getDefault().createJSFDataModel(fproj,jsfVersion); - fproj.installProjectFacet(jsfVersion, model, monitor); - } - } - - private void storeSettings(IProject project) { - IScopeContext projectScope = new ProjectScope(project); - IEclipsePreferences prefs = projectScope.getNode(SeamCorePlugin.PLUGIN_ID); - String version = prefs.get(ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION, null); - if (version == null) { - prefs.put(ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION, - ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION_1_1); - } - try { - prefs.flush(); - } catch (BackingStoreException e) { - MavenSeamActivator.log(e); - } - } - - private void addSeamSupport(IProject project, IProject[] earProjects) { - if(project==null) { - return; - } - try { - if (!project.hasNature(ISeamProject.NATURE_ID)) { - EclipseResourceUtil.addNatureToProject(project, ISeamProject.NATURE_ID); - } - if(!project.hasNature(IKbProject.NATURE_ID)) { - EclipseResourceUtil.addNatureToProject(project, IKbProject.NATURE_ID); - } - for (int i = 0; i < earProjects.length; i++) { - IEclipsePreferences prefs = SeamCorePlugin - .getSeamPreferences(project); - String seamParentProject = prefs.get(ISeamFacetDataModelProperties.SEAM_PARENT_PROJECT,null); - if (seamParentProject == null) { - IProject earProject = earProjects[i]; - IProject webProject = getReferencingSeamWebProject(earProject); - if (webProject != null) { - prefs.put(ISeamFacetDataModelProperties.SEAM_PARENT_PROJECT,webProject.getName()); - break; - } - } - } - - } catch (CoreException e) { - MavenSeamActivator.log(e); - } - - } - - private IProject getReferencingSeamWebProject(IProject earProject) - throws CoreException { - IVirtualComponent component = ComponentCore.createComponent(earProject); - if (component != null) { - IVirtualReference[] references = component.getReferences(); - for (int i = 0; i < references.length; i++) { - IVirtualComponent refComponent = references[i].getReferencedComponent(); - IProject refProject = refComponent.getProject(); - if (JavaEEProjectUtilities.isDynamicWebProject(refProject)) { - if (refProject.hasNature(IMavenConstants.NATURE_ID)) { - IFile pom = refProject.getFile(IMavenConstants.POM_FILE_NAME); - if (pom.exists()) { - MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); - IMavenProjectFacade facade = projectManager.create(pom, true, null); - if(facade!=null) { - MavenProject mavenProject = facade.getMavenProject(null); - if (mavenProject != null) { - String version = getSeamVersion(mavenProject); - if (version != null) { - return refProject; - } - } - } - } - - } - } - } - } - return null; - } - - private IProject getReferencingSeamEJBProject(IProject earProject) - throws CoreException { - IVirtualComponent component = ComponentCore.createComponent(earProject); - if (component != null) { - IVirtualReference[] references = component.getReferences(); - for (int i = 0; i < references.length; i++) { - IVirtualComponent refComponent = references[i] - .getReferencedComponent(); - IProject refProject = refComponent.getProject(); - if (JavaEEProjectUtilities.isEJBProject(refProject)) { - if (refProject.hasNature(IMavenConstants.NATURE_ID)) { - IFile pom = refProject - .getFile(IMavenConstants.POM_FILE_NAME); - if (pom.exists()) { - MavenProjectManager projectManager = MavenPlugin - .getDefault().getMavenProjectManager(); - IMavenProjectFacade facade = projectManager.create( - pom, true, null); - if (facade != null) { - MavenProject mavenProject = facade - .getMavenProject(null); - if (mavenProject != null) { - String version = getSeamVersion(mavenProject); - if (version != null) { - return refProject; - } - } - } - } - - } - } - } - } - return null; - } - - private String getSeamVersion(MavenProject mavenProject) { - List artifacts = new ArrayList(); - ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter( - Artifact.SCOPE_TEST); - for (Artifact artifact : mavenProject.getArtifacts()) { - if (filter.include(artifact)) { - artifacts.add(artifact); - } - } - Artifact seamArtifact = null; - for (Artifact artifact:artifacts) { - String groupId = artifact.getGroupId(); - if (groupId != null && ORG_JBOSS_SEAM_GROUP_ID.equals(groupId)) { - String artifactId = artifact.getArtifactId(); - if (artifactId != null && JBOSS_SEAM_ARTIFACT_ID.equals(artifactId)) { - return artifact.getVersion(); - } else if (artifactId != null && artifactId.startsWith(JBOSS_SEAM_ARTIFACT_PREFIX)) { - seamArtifact = artifact; - } - } - } - if (seamArtifact != null) { - return seamArtifact.getVersion(); - } - return null; - } - - private IDataModel createSeamDataModel(String deployType, String seamVersion, IProject project) { - IDataModel config = (IDataModel) new SeamFacetInstallDataModelProvider().create(); - String seamRuntimeName = getSeamRuntimeName(seamVersion); - if (seamRuntimeName != null) { - config.setStringProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME, seamRuntimeName); - } - config.setBooleanProperty(ISeamFacetDataModelProperties.DB_ALREADY_EXISTS, true); - config.setBooleanProperty(ISeamFacetDataModelProperties.RECREATE_TABLES_AND_DATA_ON_DEPLOY, false); - config.setStringProperty(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS, deployType); - config.setBooleanProperty(ISeamFacetDataModelProperties.CONFIGURE_DEFAULT_SEAM_RUNTIME, false); - config.setBooleanProperty(ISeamFacetDataModelProperties.CONFIGURE_WAR_PROJECT, false); - IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); - boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); - if (!configureSeamArtifacts) { - return config; - } - String viewFolder = getViewFolder(project); - if (viewFolder != null) { - config.setStringProperty(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER, viewFolder); - } - IJavaProject javaProject = JavaCore.create(project); - List sourcePaths = new ArrayList(); - if (javaProject != null && javaProject.isOpen()) { - try { - IClasspathEntry[] entries = javaProject.getRawClasspath(); - for (int i = 0; i < entries.length; i++) { - IClasspathEntry entry = entries[i]; - if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { - sourcePaths.add(entry.getPath()); - } - } - } catch (JavaModelException e) { - MavenSeamActivator.log(e); - } - if (sourcePaths.size() > 0) { - IPath actionSourceFolder = null; - IPath modelSourceFolder = null; - for (IPath sourcePath:sourcePaths) { - if (sourcePath.toString().contains("hot")) { //$NON-NLS-1$ - actionSourceFolder = sourcePath; - } else { - modelSourceFolder = sourcePath; - } - } - if (actionSourceFolder == null) { - actionSourceFolder = modelSourceFolder; - } - if (modelSourceFolder == null) { - modelSourceFolder = actionSourceFolder; - } - String modelSourceFolderStr = modelSourceFolder.toString(); - config.setStringProperty(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER, modelSourceFolderStr); - String actionSourceFolderStr = actionSourceFolder.toString(); - config.setStringProperty(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER, actionSourceFolderStr); - } - try { - IPackageFragment[] packageFragments = javaProject.getPackageFragments(); - for (int i = 0; i < packageFragments.length; i++) { - IPackageFragment pf = packageFragments[i]; - if (pf != null && pf.getKind() == IPackageFragmentRoot.K_SOURCE && !pf.isDefaultPackage()) { - String packageName = pf.getElementName(); - config.setStringProperty(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME, packageName); - config.setStringProperty(ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME, packageName); - } - } - } catch (JavaModelException e) { - MavenSeamActivator.log(e); - } - } - //config.setStringProperty(ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME, "org.test.beans"); - //config.setStringProperty(ISeamFacetDataModelProperties.SEAM_CONNECTION_PROFILE, "noop-connection"); - //config.setProperty(ISeamFacetDataModelProperties.JDBC_DRIVER_JAR_PATH, new String[] { "noop-driver.jar" }); - return config; - } - - private String getSeamRuntimeName(String seamVersionStr) { - if (seamVersionStr == null) { - return null; - } - IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); - boolean configureSeamRuntime = store.getBoolean(Activator.CONFIGURE_SEAM_RUNTIME); - if (!configureSeamRuntime) { - return null; - } - String seamRuntime5 = null; - String seamRuntime3 = null; - SeamRuntime[] seamRuntimes = SeamRuntimeManager.getInstance().getRuntimes(); - for (int i = 0; i < seamRuntimes.length; i++) { - SeamRuntime seamRuntime = seamRuntimes[i]; - String seamHomeDir = seamRuntime.getHomeDir(); - if (seamHomeDir == null) { - continue; - } - if ( ! (new File(seamHomeDir).exists() )) { - continue; - } - String fullVersion = SeamUtil.getSeamVersionFromManifest(seamRuntime.getHomeDir()); - if (fullVersion == null) { - continue; - } - if (fullVersion == seamVersionStr) { - return seamRuntime.getName(); - } - if (seamRuntime5 == null) { - String fullVersion5 = fullVersion.substring(0,5); - String seamVersion5 = seamVersionStr.substring(0,5); - if (seamVersion5.equals(fullVersion5)) { - seamRuntime5 = seamRuntime.getName(); - } - } - if (seamRuntime5 == null && seamRuntime3 == null) { - String fullVersion3 = fullVersion.substring(0,3); - String seamVersion3 = seamVersionStr.substring(0,3); - if (seamVersion3.equals(fullVersion3)) { - seamRuntime3 = seamRuntime.getName(); - } - } - } - if (seamRuntime5 != null) { - return seamRuntime5; - } - SeamVersion seamVersion = SeamVersion.parseFromString(seamVersionStr.substring(0,3)); - SeamRuntime defaultRuntime = SeamRuntimeManager.getInstance().getDefaultRuntime(seamVersion); - if (defaultRuntime != null) { - return defaultRuntime.getName(); - } - return seamRuntime3; - } - - private void configureApplicationXml(IProject project, IProgressMonitor monitor) { - EARArtifactEdit earArtifactEdit = null; - try { - earArtifactEdit = EARArtifactEdit.getEARArtifactEditForWrite(project); - if(earArtifactEdit!=null) { - Application application = earArtifactEdit.getApplication(); - if (application == null) { - return; - } - EList modules = application.getModules(); - for (Iterator iterator = modules.iterator(); iterator.hasNext();) { - Object object = iterator.next(); - if (object instanceof Module) { - Module module = (Module) object; - String uri = module.getUri(); - if (uri != null && (uri.startsWith("mvel14") || uri.startsWith("mvel2"))) { //$NON-NLS-1$ //$NON-NLS-2$ - iterator.remove(); - } - if (uri != null && (uri.equals("jboss-seam.jar"))) { //$NON-NLS-1$ //$NON-NLS-2$ - iterator.remove(); - } - } - } - - } - } finally { - if(earArtifactEdit!=null) { - earArtifactEdit.saveIfNecessary(monitor); - earArtifactEdit.dispose(); - } - } - try { - final IFacetedProject fproj = ProjectFacetsManager.create(project); - if (fproj != null && fproj.hasProjectFacet(earFacet)) { - IVirtualComponent earComponent = ComponentCore.createComponent(project); - IVirtualReference[] refs = earComponent.getReferences(); - IVirtualReference mvelReference = null; - for (IVirtualReference ref:refs) { - String archiveName = ref.getArchiveName(); - if (archiveName != null && archiveName.startsWith("/lib/mvel2")) { //$NON-NLS-1$ - mvelReference = ref; - break; - } - } - if (mvelReference != null) { - changeReference(earComponent, mvelReference); - } - } - } catch (CoreException e) { - MavenSeamActivator.log(e); - } - - } - - /** - * @param earComponent - * @param mvelReference - */ - private void changeReference(IVirtualComponent earComponent, - IVirtualReference mvelReference) { - List list = new ArrayList(); - list.add(mvelReference.getReferencedComponent()); - - IDataModel model = DataModelFactory.createDataModel(new RemoveComponentFromEnterpriseApplicationDataModelProvider() { - - @Override - public IDataModelOperation getDefaultOperation() { - return new RemoveComponentFromEnterpriseApplicationOperationEx(model); - } - - }); - model.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComponent); - - model.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, list); - model.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH, "/lib"); //$NON-NLS-1$ - IDataModelOperation op = model.getDefaultOperation(); - try { - op.execute(null, null); - J2EEComponentClasspathUpdater.getInstance().queueUpdateEAR(earComponent.getProject()); - } catch (ExecutionException e) { - MavenSeamActivator.log(e); - } - - - String archiveName = mvelReference.getArchiveName(); - archiveName = archiveName.substring(4); - mvelReference.setArchiveName(archiveName); - IDataModel dm = DataModelFactory.createDataModel(new AddComponentToEnterpriseApplicationDataModelProvider()); - - dm.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComponent); - dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, list); - - dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH, "/lib"); //$NON-NLS-1$ - - try { - dm.getDefaultOperation().execute(null, null); - } catch (ExecutionException e) { - MavenSeamActivator.log(e); - } - } - - private static class RemoveComponentFromEnterpriseApplicationOperationEx extends RemoveComponentFromEnterpriseApplicationOperation { - - public RemoveComponentFromEnterpriseApplicationOperationEx( - IDataModel model) { - super(model); - } - - @Override - protected void updateEARDD(IProgressMonitor monitor) { - //super.updateEARDD(monitor); - } - - - } -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.seam.configurators; + +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ProjectScope; +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.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.emf.common.util.EList; +import org.eclipse.jdt.core.IClasspathEntry; +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.jface.preference.IPreferenceStore; +import org.eclipse.jst.j2ee.application.Application; +import org.eclipse.jst.j2ee.application.Module; +import org.eclipse.jst.j2ee.application.internal.operations.AddComponentToEnterpriseApplicationDataModelProvider; +import org.eclipse.jst.j2ee.application.internal.operations.RemoveComponentFromEnterpriseApplicationDataModelProvider; +import org.eclipse.jst.j2ee.application.internal.operations.RemoveComponentFromEnterpriseApplicationOperation; +import org.eclipse.jst.j2ee.componentcore.util.EARArtifactEdit; +import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater; +import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; +import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.internal.MavenPluginActivator; +import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.ModuleCoreNature; +import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties; +import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; +import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; +import org.eclipse.wst.common.componentcore.resources.IVirtualReference; +import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +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.jboss.tools.common.model.util.EclipseResourceUtil; +import org.jboss.tools.jst.web.kb.IKbProject; +import org.jboss.tools.maven.core.IJBossMavenConstants; +import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; +import org.jboss.tools.maven.jsf.MavenJSFActivator; +import org.jboss.tools.maven.seam.MavenSeamActivator; +import org.jboss.tools.maven.ui.Activator; +import org.jboss.tools.seam.core.ISeamProject; +import org.jboss.tools.seam.core.SeamCorePlugin; +import org.jboss.tools.seam.core.SeamUtil; +import org.jboss.tools.seam.core.project.facet.SeamRuntime; +import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager; +import org.jboss.tools.seam.core.project.facet.SeamVersion; +import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties; +import org.jboss.tools.seam.internal.core.project.facet.SeamFacetInstallDataModelProvider; +import org.jboss.tools.seam.ui.wizard.SeamWizardUtils; +import org.osgi.service.prefs.BackingStoreException; + +/** + * + * @author snjeza + * + */ +public class SeamProjectConfigurator extends AbstractProjectConfigurator { + + private static final String JBOSS_SEAM_ARTIFACT_PREFIX = "jboss-seam"; //$NON-NLS-1$ + private static final String ORG_JBOSS_SEAM_GROUP_ID = "org.jboss.seam"; //$NON-NLS-1$ + private static final String JBOSS_SEAM_ARTIFACT_ID = "jboss-seam"; //$NON-NLS-1$ + + protected static final IProjectFacet dynamicWebFacet; + protected static final IProjectFacetVersion dynamicWebVersion; + protected static final IProjectFacet javaFacet; + protected static final IProjectFacetVersion javaVersion; + protected static final IProjectFacet jsfFacet; + protected static final IProjectFacetVersion jsfVersion; + protected static final IProjectFacet earFacet; + protected static final IProjectFacetVersion earVersion; + protected static final IProjectFacet ejbFacet; + protected static final IProjectFacetVersion ejbVersion; + protected static final IProjectFacet m2Facet; + protected static final IProjectFacetVersion m2Version; + private static final IProjectFacet seamFacet; + private static final IProjectFacet portletFacet; + private static final IProjectFacet jsfportletFacet; + private static final IProjectFacet seamPortletFacet; + private static final IProjectFacetVersion seamPortletVersion; + + static { + seamFacet = ProjectFacetsManager.getProjectFacet("jst.seam"); //$NON-NLS-1$ + javaFacet = ProjectFacetsManager.getProjectFacet("jst.java"); //$NON-NLS-1$ + javaVersion = javaFacet.getVersion("5.0"); //$NON-NLS-1$ + dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ + dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ + jsfFacet = ProjectFacetsManager.getProjectFacet("jst.jsf"); //$NON-NLS-1$ + jsfVersion = jsfFacet.getVersion("1.2"); //$NON-NLS-1$ + earFacet = ProjectFacetsManager.getProjectFacet("jst.ear"); //$NON-NLS-1$ + earVersion = earFacet.getVersion("5.0"); //$NON-NLS-1$ + m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ + m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ + ejbFacet = ProjectFacetsManager.getProjectFacet("jst.ejb"); //$NON-NLS-1$ + ejbVersion = ejbFacet.getVersion("3.0"); //$NON-NLS-1$ + portletFacet = ProjectFacetsManager.getProjectFacet("jboss.portlet"); //$NON-NLS-1$ + jsfportletFacet = ProjectFacetsManager.getProjectFacet("jboss.jsfportlet"); //$NON-NLS-1$ + seamPortletFacet = ProjectFacetsManager.getProjectFacet("jboss.seamportlet"); //$NON-NLS-1$ + seamPortletVersion = seamPortletFacet.getVersion("1.0"); //$NON-NLS-1$ + } + + @Override + public void configure(ProjectConfigurationRequest request, + IProgressMonitor monitor) throws CoreException { + // adds Seam capabilities if there are Seam dependencies + MavenProject mavenProject = request.getMavenProject(); + IProject project = request.getProject(); + configureInternal(mavenProject,project, monitor); + + } + + private boolean isSeamSettingChangedByUser(IProject project) { + IEclipsePreferences projectPreferences = SeamCorePlugin.getSeamPreferences(project); + boolean seamSettingsChangedByUser = projectPreferences.getBoolean(ISeamFacetDataModelProperties.SEAM_SETTINGS_CHANGED_BY_USER, false); + return seamSettingsChangedByUser; + } + + private void configureInternal(MavenProject mavenProject,IProject project, + IProgressMonitor monitor) throws CoreException { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + boolean configureSeam = store.getBoolean(Activator.CONFIGURE_SEAM); + if (!configureSeam) { + return; + } + if (isSeamSettingChangedByUser(project)) { + return; + } + IProject rootSeamProject = SeamWizardUtils.getRootSeamProject(project); + if (rootSeamProject != null && isSeamSettingChangedByUser(rootSeamProject)) { + return; + } + String packaging = mavenProject.getPackaging(); + String seamVersion = getSeamVersion(mavenProject); + if (seamVersion != null) { + IProject[] earProjects = J2EEProjectUtilities.getReferencingEARProjects(project); + String deploying = packaging; + if (earProjects.length > 0) { + deploying = "ear"; //$NON-NLS-1$ + } + final IFacetedProject fproj = ProjectFacetsManager.create(project); + if (fproj == null) { + return; + } + if ("war".equals(packaging)) { //$NON-NLS-1$ + IDataModel model = createSeamDataModel(deploying, seamVersion, project); + installWarFacets(fproj, model, seamVersion, monitor); + } else if ("ear".equals(packaging)) { //$NON-NLS-1$ + configureApplicationXml(project, monitor); + installEarFacets(fproj, monitor); + installM2Facet(fproj, monitor); + IProject webProject = getReferencingSeamWebProject(project); + if (webProject != null) { + IEclipsePreferences prefs = SeamCorePlugin.getSeamPreferences(webProject); + String deployingType = prefs.get(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,null); + if (deployingType == null || deployingType.equals(ISeamFacetDataModelProperties.DEPLOY_AS_WAR)) { + prefs.put(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,ISeamFacetDataModelProperties.DEPLOY_AS_EAR); + storeSettings(webProject); + } + IProject ejbProject = getReferencingSeamEJBProject(project); + if (ejbProject != null) { + prefs.put(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT, ejbProject.getName()); + IJavaProject javaProject = JavaCore.create(ejbProject); + boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); + if (configureSeamArtifacts) { + if (javaProject != null && javaProject.isOpen()) { + try { + IClasspathEntry[] entries = javaProject.getRawClasspath(); + for (int i = 0; i < entries.length; i++) { + IClasspathEntry entry = entries[i]; + if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { + String sourceFolder = entry.getPath().toString(); + prefs.put(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER, sourceFolder); + prefs.put(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER, sourceFolder); + break; + } + } + } catch (JavaModelException e) { + MavenSeamActivator.log(e); + } + } + IPackageFragment[] packageFragments = javaProject.getPackageFragments(); + for (int i = 0; i < packageFragments.length; i++) { + IPackageFragment pf = packageFragments[i]; + if (pf != null && pf.getKind() == IPackageFragmentRoot.K_SOURCE && !pf.isDefaultPackage()) { + if (pf.hasSubpackages() && !pf.hasChildren()) { + continue; + } + String packageName = pf.getElementName(); + prefs.put(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME, packageName); + prefs.put(ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME, packageName); + } + } + } + } + storeSettings(webProject); + } + + } else if ("ejb".equals(packaging)) { //$NON-NLS-1$ + installM2Facet(fproj,monitor); + installEjbFacets(fproj, monitor); + addSeamSupport(project, earProjects); + storeSettings(project); + + } +// addSeamSupport(project); +// +// storeSettings(project); + } + } + + private String getViewFolder(IProject project) { + IVirtualComponent com = ComponentCore.createComponent(project); + String viewFolder = null; + if(com!=null) { + IVirtualFolder webRootFolder = com.getRootFolder().getFolder(new Path("/")); //$NON-NLS-1$ + if(webRootFolder!=null) { + viewFolder = webRootFolder.getUnderlyingFolder().getFullPath().toString(); + } + } + return viewFolder; + } + + @Override + public void mavenProjectChanged(MavenProjectChangedEvent event, + IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = event.getMavenProject(); + if(facade != null) { + IProject project = facade.getProject(); + if(isWTPProject(project)) { + MavenProject mavenProject = facade.getMavenProject(monitor); + configureInternal(mavenProject, project, monitor); + } + } + super.mavenProjectChanged(event, monitor); + } + + private boolean isWTPProject(IProject project) { + return ModuleCoreNature.getModuleCoreNature(project) != null; + } + + private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) throws CoreException { + if (!fproj.hasProjectFacet(m2Facet)) { + IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider().create(); + config.setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); + fproj.installProjectFacet(m2Version, config, monitor); + } + } + + private IProjectFacetVersion getSeamFacetVersion(String seamVersion) { + String version = seamVersion.substring(0, 3); + return seamFacet.getVersion(version); + } + + private void installEarFacets(IFacetedProject fproj,IProgressMonitor monitor) throws CoreException { + if (!fproj.hasProjectFacet(earFacet)) { + fproj.installProjectFacet(earVersion, null, monitor); + } + + } + + private void installEjbFacets(IFacetedProject fproj,IProgressMonitor monitor) throws CoreException { + if (!fproj.hasProjectFacet(javaFacet)) { + fproj.installProjectFacet(javaVersion, null, monitor); + } + if (!fproj.hasProjectFacet(ejbFacet)) { + fproj.installProjectFacet(ejbVersion, null, monitor); + } + } + + private void installWarFacets(IFacetedProject fproj,IDataModel model, String seamVersion,IProgressMonitor monitor) throws CoreException { + if (!fproj.hasProjectFacet(javaFacet)) { + fproj.installProjectFacet(javaVersion, null, monitor); + } + if (!fproj.hasProjectFacet(dynamicWebFacet)) { + fproj.installProjectFacet(dynamicWebVersion, null, monitor); + } + installJSFFacet(fproj, monitor); + installM2Facet(fproj, monitor); + if (!fproj.hasProjectFacet(seamFacet)) { + IProjectFacetVersion seamFacetVersion = getSeamFacetVersion(seamVersion); + fproj.installProjectFacet(seamFacetVersion, model, monitor); + } else { + String deploying = model.getStringProperty(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS); + if (deploying != null && deploying.equals(ISeamFacetDataModelProperties.DEPLOY_AS_WAR)) { + IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); + boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); + if (!configureSeamArtifacts) { + return; + } + IEclipsePreferences prefs = SeamCorePlugin.getSeamPreferences(fproj.getProject()); + setModelProperty(model, prefs,ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER); + setModelProperty(model, prefs,ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER); + setModelProperty(model, prefs,ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME); + setModelProperty(model, prefs,ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME); + setModelProperty(model, prefs,ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER); + } + } + IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); + boolean configureSeamPortlet = store.getBoolean(Activator.CONFIGURE_SEAMPORTLET); + if (!configureSeamPortlet) { + return; + } + if (fproj.hasProjectFacet(seamFacet) && fproj.hasProjectFacet(portletFacet) && fproj.hasProjectFacet(jsfportletFacet)) { + if (!fproj.hasProjectFacet(seamPortletFacet)) { + fproj.installProjectFacet(seamPortletVersion, null, monitor); + } + } + } + + private void setModelProperty(IDataModel model, IEclipsePreferences prefs, String property) { + String value = model.getStringProperty(property); + if (value != null && value.trim().length() > 0) { + prefs.put(property, value); + } + } + + private void installJSFFacet(IFacetedProject fproj, IProgressMonitor monitor) + throws CoreException { + if (!fproj.hasProjectFacet(jsfFacet)) { + IDataModel model = MavenJSFActivator.getDefault().createJSFDataModel(fproj,jsfVersion); + fproj.installProjectFacet(jsfVersion, model, monitor); + } + } + + private void storeSettings(IProject project) { + IScopeContext projectScope = new ProjectScope(project); + IEclipsePreferences prefs = projectScope.getNode(SeamCorePlugin.PLUGIN_ID); + String version = prefs.get(ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION, null); + if (version == null) { + prefs.put(ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION, + ISeamFacetDataModelProperties.SEAM_SETTINGS_VERSION_1_1); + } + try { + prefs.flush(); + } catch (BackingStoreException e) { + MavenSeamActivator.log(e); + } + } + + private void addSeamSupport(IProject project, IProject[] earProjects) { + if(project==null) { + return; + } + try { + if (!project.hasNature(ISeamProject.NATURE_ID)) { + EclipseResourceUtil.addNatureToProject(project, ISeamProject.NATURE_ID); + } + if(!project.hasNature(IKbProject.NATURE_ID)) { + EclipseResourceUtil.addNatureToProject(project, IKbProject.NATURE_ID); + } + for (int i = 0; i < earProjects.length; i++) { + IEclipsePreferences prefs = SeamCorePlugin + .getSeamPreferences(project); + String seamParentProject = prefs.get(ISeamFacetDataModelProperties.SEAM_PARENT_PROJECT,null); + if (seamParentProject == null) { + IProject earProject = earProjects[i]; + IProject webProject = getReferencingSeamWebProject(earProject); + if (webProject != null) { + prefs.put(ISeamFacetDataModelProperties.SEAM_PARENT_PROJECT,webProject.getName()); + break; + } + } + } + + } catch (CoreException e) { + MavenSeamActivator.log(e); + } + + } + + private IProject getReferencingSeamWebProject(IProject earProject) + throws CoreException { + IVirtualComponent component = ComponentCore.createComponent(earProject); + if (component != null) { + IVirtualReference[] references = component.getReferences(); + for (int i = 0; i < references.length; i++) { + IVirtualComponent refComponent = references[i].getReferencedComponent(); + IProject refProject = refComponent.getProject(); + if (JavaEEProjectUtilities.isDynamicWebProject(refProject)) { + if (refProject.hasNature(IMavenConstants.NATURE_ID)) { + IFile pom = refProject.getFile(IMavenConstants.POM_FILE_NAME); + if (pom.exists()) { + MavenProjectManager projectManager = MavenPluginActivator.getDefault().getMavenProjectManager(); + IMavenProjectFacade facade = projectManager.create(pom, true, null); + if(facade!=null) { + MavenProject mavenProject = facade.getMavenProject(null); + if (mavenProject != null) { + String version = getSeamVersion(mavenProject); + if (version != null) { + return refProject; + } + } + } + } + + } + } + } + } + return null; + } + + private IProject getReferencingSeamEJBProject(IProject earProject) + throws CoreException { + IVirtualComponent component = ComponentCore.createComponent(earProject); + if (component != null) { + IVirtualReference[] references = component.getReferences(); + for (int i = 0; i < references.length; i++) { + IVirtualComponent refComponent = references[i] + .getReferencedComponent(); + IProject refProject = refComponent.getProject(); + if (JavaEEProjectUtilities.isEJBProject(refProject)) { + if (refProject.hasNature(IMavenConstants.NATURE_ID)) { + IFile pom = refProject + .getFile(IMavenConstants.POM_FILE_NAME); + if (pom.exists()) { + MavenProjectManager projectManager = MavenPluginActivator + .getDefault().getMavenProjectManager(); + IMavenProjectFacade facade = projectManager.create( + pom, true, null); + if (facade != null) { + MavenProject mavenProject = facade + .getMavenProject(null); + if (mavenProject != null) { + String version = getSeamVersion(mavenProject); + if (version != null) { + return refProject; + } + } + } + } + + } + } + } + } + return null; + } + + private String getSeamVersion(MavenProject mavenProject) { + List artifacts = new ArrayList(); + ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter( + Artifact.SCOPE_TEST); + for (Artifact artifact : mavenProject.getArtifacts()) { + if (filter.include(artifact)) { + artifacts.add(artifact); + } + } + Artifact seamArtifact = null; + for (Artifact artifact:artifacts) { + String groupId = artifact.getGroupId(); + if (groupId != null && ORG_JBOSS_SEAM_GROUP_ID.equals(groupId)) { + String artifactId = artifact.getArtifactId(); + if (artifactId != null && JBOSS_SEAM_ARTIFACT_ID.equals(artifactId)) { + return artifact.getVersion(); + } else if (artifactId != null && artifactId.startsWith(JBOSS_SEAM_ARTIFACT_PREFIX)) { + seamArtifact = artifact; + } + } + } + if (seamArtifact != null) { + return seamArtifact.getVersion(); + } + return null; + } + + private IDataModel createSeamDataModel(String deployType, String seamVersion, IProject project) { + IDataModel config = (IDataModel) new SeamFacetInstallDataModelProvider().create(); + String seamRuntimeName = getSeamRuntimeName(seamVersion); + if (seamRuntimeName != null) { + config.setStringProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME, seamRuntimeName); + } + config.setBooleanProperty(ISeamFacetDataModelProperties.DB_ALREADY_EXISTS, true); + config.setBooleanProperty(ISeamFacetDataModelProperties.RECREATE_TABLES_AND_DATA_ON_DEPLOY, false); + config.setStringProperty(ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS, deployType); + config.setBooleanProperty(ISeamFacetDataModelProperties.CONFIGURE_DEFAULT_SEAM_RUNTIME, false); + config.setBooleanProperty(ISeamFacetDataModelProperties.CONFIGURE_WAR_PROJECT, false); + IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); + boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); + if (!configureSeamArtifacts) { + return config; + } + String viewFolder = getViewFolder(project); + if (viewFolder != null) { + config.setStringProperty(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER, viewFolder); + } + IJavaProject javaProject = JavaCore.create(project); + List sourcePaths = new ArrayList(); + if (javaProject != null && javaProject.isOpen()) { + try { + IClasspathEntry[] entries = javaProject.getRawClasspath(); + for (int i = 0; i < entries.length; i++) { + IClasspathEntry entry = entries[i]; + if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { + sourcePaths.add(entry.getPath()); + } + } + } catch (JavaModelException e) { + MavenSeamActivator.log(e); + } + if (sourcePaths.size() > 0) { + IPath actionSourceFolder = null; + IPath modelSourceFolder = null; + for (IPath sourcePath:sourcePaths) { + if (sourcePath.toString().contains("hot")) { //$NON-NLS-1$ + actionSourceFolder = sourcePath; + } else { + modelSourceFolder = sourcePath; + } + } + if (actionSourceFolder == null) { + actionSourceFolder = modelSourceFolder; + } + if (modelSourceFolder == null) { + modelSourceFolder = actionSourceFolder; + } + String modelSourceFolderStr = modelSourceFolder.toString(); + config.setStringProperty(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER, modelSourceFolderStr); + String actionSourceFolderStr = actionSourceFolder.toString(); + config.setStringProperty(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER, actionSourceFolderStr); + } + try { + IPackageFragment[] packageFragments = javaProject.getPackageFragments(); + for (int i = 0; i < packageFragments.length; i++) { + IPackageFragment pf = packageFragments[i]; + if (pf != null && pf.getKind() == IPackageFragmentRoot.K_SOURCE && !pf.isDefaultPackage()) { + String packageName = pf.getElementName(); + config.setStringProperty(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME, packageName); + config.setStringProperty(ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME, packageName); + } + } + } catch (JavaModelException e) { + MavenSeamActivator.log(e); + } + } + //config.setStringProperty(ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME, "org.test.beans"); + //config.setStringProperty(ISeamFacetDataModelProperties.SEAM_CONNECTION_PROFILE, "noop-connection"); + //config.setProperty(ISeamFacetDataModelProperties.JDBC_DRIVER_JAR_PATH, new String[] { "noop-driver.jar" }); + return config; + } + + private String getSeamRuntimeName(String seamVersionStr) { + if (seamVersionStr == null) { + return null; + } + IPreferenceStore store = MavenSeamActivator.getDefault().getPreferenceStore(); + boolean configureSeamRuntime = store.getBoolean(Activator.CONFIGURE_SEAM_RUNTIME); + if (!configureSeamRuntime) { + return null; + } + String seamRuntime5 = null; + String seamRuntime3 = null; + SeamRuntime[] seamRuntimes = SeamRuntimeManager.getInstance().getRuntimes(); + for (int i = 0; i < seamRuntimes.length; i++) { + SeamRuntime seamRuntime = seamRuntimes[i]; + String seamHomeDir = seamRuntime.getHomeDir(); + if (seamHomeDir == null) { + continue; + } + if ( ! (new File(seamHomeDir).exists() )) { + continue; + } + String fullVersion = SeamUtil.getSeamVersionFromManifest(seamRuntime.getHomeDir()); + if (fullVersion == null) { + continue; + } + if (fullVersion == seamVersionStr) { + return seamRuntime.getName(); + } + if (seamRuntime5 == null) { + String fullVersion5 = fullVersion.substring(0,5); + String seamVersion5 = seamVersionStr.substring(0,5); + if (seamVersion5.equals(fullVersion5)) { + seamRuntime5 = seamRuntime.getName(); + } + } + if (seamRuntime5 == null && seamRuntime3 == null) { + String fullVersion3 = fullVersion.substring(0,3); + String seamVersion3 = seamVersionStr.substring(0,3); + if (seamVersion3.equals(fullVersion3)) { + seamRuntime3 = seamRuntime.getName(); + } + } + } + if (seamRuntime5 != null) { + return seamRuntime5; + } + SeamVersion seamVersion = SeamVersion.parseFromString(seamVersionStr.substring(0,3)); + SeamRuntime defaultRuntime = SeamRuntimeManager.getInstance().getDefaultRuntime(seamVersion); + if (defaultRuntime != null) { + return defaultRuntime.getName(); + } + return seamRuntime3; + } + + private void configureApplicationXml(IProject project, IProgressMonitor monitor) { + EARArtifactEdit earArtifactEdit = null; + try { + earArtifactEdit = EARArtifactEdit.getEARArtifactEditForWrite(project); + if(earArtifactEdit!=null) { + Application application = earArtifactEdit.getApplication(); + if (application == null) { + return; + } + EList modules = application.getModules(); + for (Iterator iterator = modules.iterator(); iterator.hasNext();) { + Object object = iterator.next(); + if (object instanceof Module) { + Module module = (Module) object; + String uri = module.getUri(); + if (uri != null && (uri.startsWith("mvel14") || uri.startsWith("mvel2"))) { //$NON-NLS-1$ //$NON-NLS-2$ + iterator.remove(); + } + if (uri != null && (uri.equals("jboss-seam.jar"))) { //$NON-NLS-1$ //$NON-NLS-2$ + iterator.remove(); + } + } + } + + } + } finally { + if(earArtifactEdit!=null) { + earArtifactEdit.saveIfNecessary(monitor); + earArtifactEdit.dispose(); + } + } + try { + final IFacetedProject fproj = ProjectFacetsManager.create(project); + if (fproj != null && fproj.hasProjectFacet(earFacet)) { + IVirtualComponent earComponent = ComponentCore.createComponent(project); + IVirtualReference[] refs = earComponent.getReferences(); + IVirtualReference mvelReference = null; + for (IVirtualReference ref:refs) { + String archiveName = ref.getArchiveName(); + if (archiveName != null && archiveName.startsWith("/lib/mvel2")) { //$NON-NLS-1$ + mvelReference = ref; + break; + } + } + if (mvelReference != null) { + changeReference(earComponent, mvelReference); + } + } + } catch (CoreException e) { + MavenSeamActivator.log(e); + } + + } + + /** + * @param earComponent + * @param mvelReference + */ + private void changeReference(IVirtualComponent earComponent, + IVirtualReference mvelReference) { + List list = new ArrayList(); + list.add(mvelReference.getReferencedComponent()); + + IDataModel model = DataModelFactory.createDataModel(new RemoveComponentFromEnterpriseApplicationDataModelProvider() { + + @Override + public IDataModelOperation getDefaultOperation() { + return new RemoveComponentFromEnterpriseApplicationOperationEx(model); + } + + }); + model.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComponent); + + model.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, list); + model.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH, "/lib"); //$NON-NLS-1$ + IDataModelOperation op = model.getDefaultOperation(); + try { + op.execute(null, null); + J2EEComponentClasspathUpdater.getInstance().queueUpdateEAR(earComponent.getProject()); + } catch (ExecutionException e) { + MavenSeamActivator.log(e); + } + + + String archiveName = mvelReference.getArchiveName(); + archiveName = archiveName.substring(4); + mvelReference.setArchiveName(archiveName); + IDataModel dm = DataModelFactory.createDataModel(new AddComponentToEnterpriseApplicationDataModelProvider()); + + dm.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComponent); + dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, list); + + dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH, "/lib"); //$NON-NLS-1$ + + try { + dm.getDefaultOperation().execute(null, null); + } catch (ExecutionException e) { + MavenSeamActivator.log(e); + } + } + + private static class RemoveComponentFromEnterpriseApplicationOperationEx extends RemoveComponentFromEnterpriseApplicationOperation { + + public RemoveComponentFromEnterpriseApplicationOperationEx( + IDataModel model) { + super(model); + } + + @Override + protected void updateEARDD(IProgressMonitor monitor) { + //super.updateEARDD(monitor); + } + + + } +} Index: src/org/jboss/tools/maven/seam/MavenSeamActivator.java =================================================================== --- src/org/jboss/tools/maven/seam/MavenSeamActivator.java (revision 32782) +++ src/org/jboss/tools/maven/seam/MavenSeamActivator.java (working copy) @@ -1,1154 +1,1342 @@ -package org.jboss.tools.maven.seam; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.maven.model.Build; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Exclusion; -import org.apache.maven.model.Model; -import org.apache.maven.model.Parent; -import org.apache.maven.model.Resource; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.xmi.XMIResource; -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.osgi.util.NLS; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.jboss.tools.maven.core.IJBossMavenConstants; -import org.jboss.tools.maven.core.MavenCoreActivator; -import org.jboss.tools.seam.core.SeamUtil; -import org.jboss.tools.seam.core.project.facet.SeamRuntime; -import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager; -import org.jboss.tools.seam.core.project.facet.SeamVersion; -import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties; -import org.jboss.tools.seam.internal.core.project.facet.SeamFacetAbstractInstallDelegate; -import org.maven.ide.components.pom.Configuration; -import org.maven.ide.components.pom.Plugin; -import org.maven.ide.components.pom.PluginExecution; -import org.maven.ide.components.pom.PomFactory; -import org.maven.ide.components.pom.util.PomResourceImpl; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.embedder.MavenModelManager; -import org.maven.ide.eclipse.embedder.ProjectUpdater; -import org.maven.ide.eclipse.project.MavenProjectManager; -import org.maven.ide.eclipse.project.ResolverConfiguration; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Version; -import org.w3c.dom.Node; - -/** - * The activator class controls the plug-in life cycle - */ -public class MavenSeamActivator extends AbstractUIPlugin { - - private static final String ORG_CODEHAUS_MOJO = "org.codehaus.mojo"; //$NON-NLS-1$ - - private static final String PARENT_SUFFIX = "-parent"; //$NON-NLS-1$ - - // The plug-in ID - public static final String PLUGIN_ID = "org.jboss.tools.maven.seam"; //$NON-NLS-1$ - - // The shared instance - private static MavenSeamActivator plugin; - - private String webProjectName; - private String artifactId; - - private String parentProjectName; - private String parentArtifactId; - - private String earProjectName; - private String earArtifactId; - - private String ejbProjectName; - private String ejbArtifactId; - - private String testProjectName; - private String testArtifactId; - - private String groupId; - - /** - * The constructor - */ - public MavenSeamActivator() { - } - - /* - * (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); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static MavenSeamActivator getDefault() { - return plugin; - } - - - public void configureSeamProject(IDataModel seamFacetModel, - IDataModel m2FacetModel) { - Assert.isNotNull(seamFacetModel); - Assert.isNotNull(m2FacetModel); - webProjectName = seamFacetModel.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME); - artifactId = m2FacetModel.getStringProperty(IJBossMavenConstants.ARTIFACT_ID); - groupId = m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID); - parentProjectName = webProjectName + PARENT_SUFFIX; - parentArtifactId = artifactId + PARENT_SUFFIX; - testProjectName = seamFacetModel.getStringProperty(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT); - testArtifactId = testProjectName; - earProjectName = seamFacetModel.getStringProperty(ISeamFacetDataModelProperties.SEAM_EAR_PROJECT); - earArtifactId = earProjectName; - ejbProjectName = seamFacetModel.getStringProperty(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT);; - ejbArtifactId = ejbProjectName; - configureParentProject(m2FacetModel, seamFacetModel); - configureWarProject(m2FacetModel, seamFacetModel); - configureTestProject(m2FacetModel, seamFacetModel); - if (!SeamFacetAbstractInstallDelegate - .isWarConfiguration(seamFacetModel)) { - configureEjbProject(m2FacetModel, seamFacetModel); - configureEarProject(m2FacetModel, seamFacetModel); - - } - } - - private void configureTestProject(IDataModel m2FacetModel, - IDataModel seamFacetModel) { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testProjectName); - if (project == null || !project.exists()) { - return; - } - IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); - IJavaProject javaProject = JavaCore.create(project); - if (!pom.exists()) { - Model model = new Model(); - model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); - model.setGroupId(m2FacetModel - .getStringProperty(IJBossMavenConstants.GROUP_ID)); - model.setArtifactId(testArtifactId); - model.setVersion(m2FacetModel - .getStringProperty(IJBossMavenConstants.VERSION)); - model.setName(m2FacetModel.getStringProperty(IJBossMavenConstants.NAME) + " - test"); //$NON-NLS-1$ - model.setPackaging("jar"); //$NON-NLS-1$ - model.setDescription(m2FacetModel - .getStringProperty(IJBossMavenConstants.DESCRIPTION)); - - Parent parent = new Parent(); - parent.setArtifactId(parentArtifactId); - parent.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); - parent.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - parent.setRelativePath("../" + parentProjectName); //$NON-NLS-1$ - model.setParent(parent); - - List dependencies = model.getDependencies(); - - Dependency dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam.embedded"); //$NON-NLS-1$ - dependency.setArtifactId("hibernate-all"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam.embedded"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-embedded-all"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam.embedded"); //$NON-NLS-1$ - dependency.setArtifactId("thirdparty-all"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = getSeamDependency(); - dependency.setScope("compile"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = getJSFApi(); - dependency.setScope("test"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("javax.activation"); //$NON-NLS-1$ - dependency.setArtifactId("activation"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.testng"); //$NON-NLS-1$ - dependency.setArtifactId("testng"); //$NON-NLS-1$ - // FIXME - dependency.setVersion("${testng.version}"); //$NON-NLS-1$ - dependency.setClassifier("jdk15"); //$NON-NLS-1$ - dependency.setScope("compile"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.slf4j"); //$NON-NLS-1$ - dependency.setArtifactId("slf4j-api"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.slf4j"); //$NON-NLS-1$ - dependency.setArtifactId("slf4j-nop"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("javax.el"); //$NON-NLS-1$ - dependency.setArtifactId("el-api"); //$NON-NLS-1$ - dependency.setScope("test"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId(groupId); - dependency.setArtifactId(artifactId); - dependency.setType("war"); //$NON-NLS-1$ - dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - dependency.setScope("test"); //$NON-NLS-1$ - dependencies.add(dependency); - - if (!SeamFacetAbstractInstallDelegate - .isWarConfiguration(seamFacetModel)) { - dependency = new Dependency(); - dependency.setGroupId(groupId); - dependency.setArtifactId(ejbArtifactId); - dependency.setType("ejb"); //$NON-NLS-1$ - dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - dependency.setScope("test"); //$NON-NLS-1$ - dependencies.add(dependency); - } - dependency = new Dependency(); - dependency.setGroupId("org.drools"); //$NON-NLS-1$ - dependency.setArtifactId("drools-compiler"); //$NON-NLS-1$ - dependency.setScope("test"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jbpm"); //$NON-NLS-1$ - dependency.setArtifactId("jbpm-jpdl"); //$NON-NLS-1$ - dependency.setScope("test"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.eclipse.jdt"); //$NON-NLS-1$ - dependency.setArtifactId("core"); //$NON-NLS-1$ - dependency.setVersion("3.4.2.v_883_R34x"); //$NON-NLS-1$ - dependency.setScope("test"); //$NON-NLS-1$ - dependencies.add(dependency); - - Build build = new Build(); - try { - //build.setFinalName(testProjectName); - String sourceDirectory = MavenCoreActivator.getSourceDirectory(javaProject); - if (sourceDirectory != null) { - if (isM2eclipse010()) { - build.setSourceDirectory(sourceDirectory); - } - build.setTestSourceDirectory(sourceDirectory); - } - String outputDirectory = MavenCoreActivator.getOutputDirectory(javaProject); - build.setOutputDirectory(outputDirectory); - build.setTestOutputDirectory(outputDirectory); - MavenCoreActivator.addResource(build, project, sourceDirectory); - Resource resource = new Resource(); - - resource.setDirectory(MavenCoreActivator.BASEDIR + "/bootstrap"); //$NON-NLS-1$ - List excludes = new ArrayList(); - excludes.add("**/*.java"); //$NON-NLS-1$ - resource.setExcludes(excludes); - build.getResources().add(resource); - - resource = new Resource(); - IProject webProject = ResourcesPlugin.getWorkspace().getRoot().getProject(webProjectName); - if (project == null || !project.exists()) { - return; - } - String webContent = getRootComponent(webProject); - resource.setDirectory(MavenCoreActivator.BASEDIR + "/../" + webProjectName + "/" + webContent); //$NON-NLS-1$ //$NON-NLS-2$ - excludes = new ArrayList(); - excludes.add("**/*.java"); //$NON-NLS-1$ - resource.setExcludes(excludes); - build.getResources().add(resource); - - model.setBuild(build); - MavenCoreActivator.createMavenProject(testProjectName, null, model, true); - } catch (Exception e) { - MavenSeamActivator.log(e); - } - - } - - } - - /** - * @return - */ - private boolean isM2eclipse010() { - Bundle bundle = Platform.getBundle("org.maven.ide.eclipse"); //$NON-NLS-1$ - if (bundle != null && bundle.getVersion().toString().startsWith("0.10")) { //$NON-NLS-1$ - return true; - } - return false; - } - - private void configureEarProject(IDataModel m2FacetModel, - IDataModel seamFacetModel) { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(earProjectName); - IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); - //IJavaProject javaProject = JavaCore.create(project); - if (!pom.exists()) { - Model model = new Model(); - model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); - model.setGroupId(m2FacetModel - .getStringProperty(IJBossMavenConstants.GROUP_ID)); - model.setArtifactId(earArtifactId); - model.setVersion(m2FacetModel - .getStringProperty(IJBossMavenConstants.VERSION)); - model.setName(m2FacetModel.getStringProperty(IJBossMavenConstants.NAME) + " - EAR"); //$NON-NLS-1$ - model.setPackaging("ear"); //$NON-NLS-1$ - model.setDescription(m2FacetModel - .getStringProperty(IJBossMavenConstants.DESCRIPTION)); - - Parent parent = new Parent(); - parent.setArtifactId(parentArtifactId); - parent.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); - parent.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - parent.setRelativePath("../" + parentProjectName); //$NON-NLS-1$ - model.setParent(parent); - - List dependencies = model.getDependencies(); - - Dependency dependency = new Dependency(); - dependency.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); - dependency.setArtifactId(ejbProjectName); - dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - dependency.setType("ejb"); //$NON-NLS-1$ - dependency.setScope("runtime"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); - dependency.setArtifactId(webProjectName); - dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - dependency.setType("war"); //$NON-NLS-1$ - dependency.setScope("runtime"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = getSeamDependency(); - dependency.setVersion("${seam.version}"); //$NON-NLS-1$ - dependency.setType("ejb"); //$NON-NLS-1$ - dependency.setScope("compile"); //$NON-NLS-1$ - List exclusions = dependency.getExclusions(); - Exclusion exclusion = new Exclusion(); - exclusion.setGroupId("javassist"); //$NON-NLS-1$ - exclusion.setArtifactId("javassist"); //$NON-NLS-1$ - exclusions.add(exclusion); - - exclusion = new Exclusion(); - exclusion.setGroupId("javax.el"); //$NON-NLS-1$ - exclusion.setArtifactId("el-api"); //$NON-NLS-1$ - exclusions.add(exclusion); - - exclusion = new Exclusion(); - exclusion.setGroupId("dom4j"); //$NON-NLS-1$ - exclusion.setArtifactId("dom4j"); //$NON-NLS-1$ - exclusions.add(exclusion); - - exclusion = new Exclusion(); - exclusion.setGroupId("xstream"); //$NON-NLS-1$ - exclusion.setArtifactId("xstream"); //$NON-NLS-1$ - exclusions.add(exclusion); - - exclusion = new Exclusion(); - exclusion.setGroupId("xpp3"); //$NON-NLS-1$ - exclusion.setArtifactId("xpp3_min"); //$NON-NLS-1$ - exclusions.add(exclusion); - - dependencies.add(dependency); - - dependency = getRichFacesApi(); - dependency.setType("jar"); //$NON-NLS-1$ - dependency.setScope("compile"); //$NON-NLS-1$ - exclusions = dependency.getExclusions(); - exclusion = new Exclusion(); - exclusion.setGroupId("commons-collections"); //$NON-NLS-1$ - exclusion.setArtifactId("commons-collections"); //$NON-NLS-1$ - exclusions.add(exclusion); - exclusion = new Exclusion(); - exclusion.setGroupId("commons-logging"); //$NON-NLS-1$ - exclusion.setArtifactId("commons-logging"); //$NON-NLS-1$ - exclusions.add(exclusion); - - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.drools"); //$NON-NLS-1$ - dependency.setArtifactId("drools-compiler"); //$NON-NLS-1$ - dependency.setType("jar"); //$NON-NLS-1$ - dependency.setScope("compile"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - String jbpmGroupId = "org.jbpm"; //$NON-NLS-1$ - // JBoss EAP 5.0 requires org.jbpm.jbpm3 - SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(seamFacetModel.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString()); - if(seamRuntime!=null) { - SeamVersion seamVersion = seamRuntime.getVersion(); - if (SeamVersion.SEAM_2_2.equals(seamVersion)) { - String fullVersion = SeamUtil.getSeamVersionFromManifest(seamRuntime); - if (fullVersion != null && fullVersion.contains("EAP")) { //$NON-NLS-1$ - jbpmGroupId = "org.jbpm.jbpm3"; //$NON-NLS-1$ - } - } - } - dependency.setGroupId(jbpmGroupId); - dependency.setArtifactId("jbpm-jpdl"); //$NON-NLS-1$ - dependency.setType("jar"); //$NON-NLS-1$ - dependency.setScope("compile"); //$NON-NLS-1$ - dependencies.add(dependency); - -// dependency = new Dependency(); -// dependency.setGroupId("org.mvel"); -// if ("org.jbpm.jbpm3".equals(jbpmGroupId)) { -// dependency.setArtifactId("mvel2"); -// } else { -// dependency.setArtifactId("mvel14"); -// } -// dependency.setType("jar"); -// dependency.setScope("compile"); -// dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("commons-digester"); //$NON-NLS-1$ - dependency.setArtifactId("commons-digester"); //$NON-NLS-1$ - dependencies.add(dependency); - - Build build = new Build(); - try { - build.setFinalName(earProjectName); - - String sourceDirectory = MavenCoreActivator.getEarRoot(project); - if (sourceDirectory != null) { - build.setSourceDirectory(sourceDirectory); - } - build.setOutputDirectory("target/classes"); //$NON-NLS-1$ - MavenCoreActivator.addMavenEarPlugin(build, project, m2FacetModel, ejbArtifactId, true); - model.setBuild(build); - MavenCoreActivator.createMavenProject(earProjectName, null, model, true); - removeWTPContainers(m2FacetModel, project); - } catch (Exception e) { - MavenSeamActivator.log(e); - } - - } - } - - private void removeRuntime(IProject project) throws CoreException { - IFacetedProject facetedProject = ProjectFacetsManager.create( project ); - facetedProject.setRuntime(null, null); - - } - - private void configureEjbProject(IDataModel m2FacetModel, - IDataModel seamFacetModel) { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ejbProjectName); - IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); - IJavaProject javaProject = JavaCore.create(project); - if (!pom.exists()) { - Model model = new Model(); - model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); - model.setGroupId(m2FacetModel - .getStringProperty(IJBossMavenConstants.GROUP_ID)); - model.setArtifactId(ejbArtifactId); - model.setVersion(m2FacetModel - .getStringProperty(IJBossMavenConstants.VERSION)); - model.setName(m2FacetModel.getStringProperty(IJBossMavenConstants.NAME) + " - EJB"); //$NON-NLS-1$ - model.setPackaging("ejb"); //$NON-NLS-1$ - model.setDescription(m2FacetModel - .getStringProperty(IJBossMavenConstants.DESCRIPTION)); - - Parent parent = new Parent(); - parent.setArtifactId(parentArtifactId); - parent.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); - parent.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - parent.setRelativePath("../" + parentProjectName); //$NON-NLS-1$ - model.setParent(parent); - - List dependencies = model.getDependencies(); - - Dependency dependency = getSeamDependency(); - dependency.setScope("provided"); //$NON-NLS-1$ - dependencies.add(dependency); - dependencies.add(getJSFApi()); - dependencies.add(getRichFacesApi()); - - dependency = new Dependency(); - dependency.setGroupId("javax.ejb"); //$NON-NLS-1$ - dependency.setArtifactId("ejb-api"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("javax.annotation"); //$NON-NLS-1$ - dependency.setArtifactId("jsr250-api"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependency = new Dependency(); - dependency.setGroupId("javax.persistence"); //$NON-NLS-1$ - dependency.setArtifactId("persistence-api"); //$NON-NLS-1$ - dependencies.add(dependency); - - dependencies.add(getHibernateAnnotations()); - dependencies.add(getHibernateCommonAnnotations()); - dependencies.add(getHibernateValidator()); - - Build build = new Build(); - try { - // FIXME - //build.setFinalName(ejbArtifactId); - String outputDirectory = MavenCoreActivator.getOutputDirectory(javaProject); - build.setOutputDirectory(outputDirectory); - String sourceDirectory = MavenCoreActivator.getSourceDirectory(javaProject); - if (sourceDirectory != null) { - build.setSourceDirectory(sourceDirectory); - } - MavenCoreActivator.addMavenEjbPlugin(build, project); - model.setBuild(build); - MavenCoreActivator.createMavenProject(ejbProjectName, null, model, true); - removeWTPContainers(m2FacetModel, project); - } catch (Exception e) { - MavenSeamActivator.log(e); - } - - } - - } - - private void configureWarProject(IDataModel m2FacetModel,IDataModel seamFacetModel) { - try { - IProject webProject = ResourcesPlugin.getWorkspace().getRoot().getProject(webProjectName); - - IFile pomFile = webProject.getFile(IMavenConstants.POM_FILE_NAME); - MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); - - String artifactId = parentProjectName; - String groupId = m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID); - String version = m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION); - - String relativePath = "../" + parentProjectName; //$NON-NLS-1$ - ParentAdder parentAdder = new ParentAdder(groupId, artifactId, version, relativePath); - modelManager.updateProject(pomFile, parentAdder); - - Dependency dependency = getHibernateValidator(); - //dependency.setScope("provided"); - modelManager.addDependency(pomFile,dependency); - - dependency = getHibernateAnnotations(); - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ - dependency.setArtifactId("hibernate-entitymanager"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - dependency = getSeamDependency(); - if (!SeamFacetAbstractInstallDelegate - .isWarConfiguration(seamFacetModel)) { - dependency.setScope("provided"); //$NON-NLS-1$ - } - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam-ui"); //$NON-NLS-1$ - List exclusions = dependency.getExclusions(); - Exclusion exclusion = new Exclusion(); - exclusion.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - exclusion.setArtifactId("jboss-seam"); //$NON-NLS-1$ - exclusions.add(exclusion); - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam-ioc"); //$NON-NLS-1$ - exclusions = dependency.getExclusions(); - exclusion = new Exclusion(); - exclusion.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - exclusion.setArtifactId("jboss-seam"); //$NON-NLS-1$ - exclusions.add(exclusion); - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam-debug"); //$NON-NLS-1$ - // FIXME - dependency.setVersion("${seam.version}"); //$NON-NLS-1$ - - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam-mail"); //$NON-NLS-1$ - - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam-pdf"); //$NON-NLS-1$ - - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam-remoting"); //$NON-NLS-1$ - - modelManager.addDependency(pomFile,dependency); - - if (FacetedProjectFramework.hasProjectFacet(webProject, ISeamFacetDataModelProperties.SEAM_FACET_ID, ISeamFacetDataModelProperties.SEAM_FACET_VERSION_21)) { - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam-excel"); //$NON-NLS-1$ - - modelManager.addDependency(pomFile,dependency); - } - - dependency = new Dependency(); - dependency.setGroupId("javax.servlet"); //$NON-NLS-1$ - dependency.setArtifactId("servlet-api"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.richfaces.ui"); //$NON-NLS-1$ - dependency.setArtifactId("richfaces-ui"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - dependency = getRichFacesApi(); - if (!SeamFacetAbstractInstallDelegate - .isWarConfiguration(seamFacetModel)) { - dependency.setScope("provided"); //$NON-NLS-1$ - } - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.richfaces.framework"); //$NON-NLS-1$ - dependency.setArtifactId("richfaces-impl"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - dependency = getJSFApi(); - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("javax.faces"); //$NON-NLS-1$ - dependency.setArtifactId("jsf-impl"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("javax.el"); //$NON-NLS-1$ - dependency.setArtifactId("el-api"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - if (SeamFacetAbstractInstallDelegate - .isWarConfiguration(seamFacetModel)) { - dependency = new Dependency(); - dependency.setGroupId("org.drools"); //$NON-NLS-1$ - dependency.setArtifactId("drools-compiler"); //$NON-NLS-1$ - dependency.setType("jar"); //$NON-NLS-1$ - dependency.setScope("compile"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("org.jbpm"); //$NON-NLS-1$ - dependency.setArtifactId("jbpm-jpdl"); //$NON-NLS-1$ - dependency.setType("jar"); //$NON-NLS-1$ - dependency.setScope("compile"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - - dependency = new Dependency(); - dependency.setGroupId("commons-digester"); //$NON-NLS-1$ - dependency.setArtifactId("commons-digester"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - modelManager.updateProject(pomFile, new WarProjectUpdater(webProject)); - } - - // ejb project - - if (!SeamFacetAbstractInstallDelegate - .isWarConfiguration(seamFacetModel)) { - dependency = new Dependency(); - dependency.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); - dependency.setArtifactId(ejbProjectName); - dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); - dependency.setType("ejb"); //$NON-NLS-1$ - dependency.setScope("provided"); //$NON-NLS-1$ - modelManager.addDependency(pomFile,dependency); - } - - modelManager.updateProject(pomFile, new WarProjectUpdater(webProject)); - removeWTPContainers(m2FacetModel, webProject); - } catch (Exception e) { - MavenSeamActivator.log(e); - } - } - - - - private static String getRootComponent(IProject webProject) { - IVirtualComponent component = ComponentCore.createComponent(webProject); - IVirtualFolder rootFolder = component.getRootFolder(); - IContainer root = rootFolder.getUnderlyingFolder(); - String webContentRoot = root.getProjectRelativePath().toString(); - return webContentRoot; - } - - private static Plugin getPlugin(org.maven.ide.components.pom.Build build, - String groupId, String artifactId) { - EList plugins = build.getPlugins(); - for (Plugin plugin : plugins) { - String group = plugin.getGroupId(); - if (group == null) { - group = ORG_CODEHAUS_MOJO; - } - String artifact = plugin.getArtifactId(); - if (group.equals(groupId) && artifactId.equals(artifact)) { - return plugin; - } - } - Plugin newPlugin = PomFactory.eINSTANCE.createPlugin(); - newPlugin.setGroupId(groupId); - newPlugin.setArtifactId(artifactId); - build.getPlugins().add(newPlugin); - return newPlugin; - } - - private void removeWTPContainers(IDataModel m2FacetModel, - IProject webProject) throws JavaModelException { - if (m2FacetModel.getBooleanProperty(IJBossMavenConstants.REMOVE_WTP_CLASSPATH_CONTAINERS)) { - IJavaProject javaProject = JavaCore.create(webProject); - IClasspathEntry[] entries = javaProject.getRawClasspath(); - List newEntries = new ArrayList(); - for (int i = 0; i < entries.length; i++) { - IClasspathEntry entry = entries[i]; - boolean add = true; - if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { - // FIXME - IPath path = entry.getPath(); - if (path != null) { - String value = path.toString(); - if (value.startsWith("org.eclipse.jst")) { //$NON-NLS-1$ - add = false; - } - } - } - if (add) { - newEntries.add(entry); - } - } - javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); - } - } - - private Dependency getHibernateValidator() { - Dependency dependency = new Dependency(); - dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ - dependency.setArtifactId("hibernate-validator"); //$NON-NLS-1$ - return dependency; - } - - private Dependency getHibernateAnnotations() { - Dependency dependency; - dependency = new Dependency(); - dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ - dependency.setArtifactId("hibernate-annotations"); //$NON-NLS-1$ - return dependency; - } - - private Dependency getHibernateCommonAnnotations() { - Dependency dependency; - dependency = new Dependency(); - dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ - dependency.setArtifactId("hibernate-commons-annotations"); //$NON-NLS-1$ - return dependency; - } - - private Dependency getRichFacesApi() { - Dependency dependency; - dependency = new Dependency(); - dependency.setGroupId("org.richfaces.framework"); //$NON-NLS-1$ - dependency.setArtifactId("richfaces-api"); //$NON-NLS-1$ - return dependency; - } - - private Dependency getJSFApi() { - Dependency dependency; - dependency = new Dependency(); - dependency.setGroupId("javax.faces"); //$NON-NLS-1$ - dependency.setArtifactId("jsf-api"); //$NON-NLS-1$ - return dependency; - } - - private Dependency getSeamDependency() { - Dependency dependency; - dependency = new Dependency(); - dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ - dependency.setArtifactId("jboss-seam"); //$NON-NLS-1$ - return dependency; - } - - private void configureParentProject(IDataModel m2FacetModel, IDataModel seamFacetModel) { - Bundle bundle = getDefault().getBundle(); - URL parentPomEntryURL = bundle.getEntry("/poms/parent-pom.xml"); //$NON-NLS-1$ - InputStream inputStream = null; - try { - URL resolvedURL = FileLocator.resolve(parentPomEntryURL); - MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); - inputStream = resolvedURL.openStream(); - Model model = modelManager.readMavenModel(inputStream); - model.setArtifactId(parentArtifactId); - model.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); - String projectVersion = m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION); - String name = m2FacetModel.getStringProperty(IJBossMavenConstants.NAME); - if (name != null && name.trim().length() > 0) { - model.setName(name + " - parent"); //$NON-NLS-1$ - } - String description= m2FacetModel.getStringProperty(IJBossMavenConstants.DESCRIPTION); - if (description != null && description.trim().length() > 0) { - model.setDescription(description + " - parent"); //$NON-NLS-1$ - } - model.setVersion(projectVersion); - - Properties properties = model.getProperties(); - properties.put(IJBossMavenConstants.PROJECT_VERSION, projectVersion); - SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(seamFacetModel.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString()); - if(seamRuntime==null) { - getDefault().log(Messages.MavenSeamActivator_Cannot_get_seam_runtime + seamFacetModel.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString()); - } - String seamVersion = m2FacetModel.getStringProperty(IJBossMavenConstants.SEAM_MAVEN_VERSION); - if (seamVersion != null && seamVersion.trim().length() > 0) { - properties.put(IJBossMavenConstants.SEAM_VERSION, seamVersion); - } - String seamHomePath = seamRuntime.getHomeDir(); - File seamHomeDir = new File(seamHomePath); - if (seamHomeDir.exists()) { - //String seamVersion = SeamUtil.getSeamVersionFromManifest(seamRuntime.getHomeDir()); - //properties.put(IJBossMavenConstants.SEAM_VERSION, seamVersion); - File buildDir = new File(seamHomeDir,"build"); //$NON-NLS-1$ - File rootPom = new File(buildDir,"root.pom.xml"); //$NON-NLS-1$ - if (!rootPom.exists()) { - MavenSeamActivator.log(NLS.bind(Messages.MavenSeamActivator_The_file_does_not_exist, rootPom.getAbsolutePath())); - } else { - try { - Model rootPomModel = modelManager.readMavenModel(rootPom); - List seamDependencies = rootPomModel.getDependencyManagement().getDependencies(); - setArtifactVersion("jsf.version", properties, "javax.faces", "jsf-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - String richfacesVersion = setArtifactVersion("richfaces.version", properties, "org.richfaces.framework", "richfaces-impl", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (richfacesVersion == null) { - Properties seamProperties = rootPomModel.getProperties(); - richfacesVersion = seamProperties.getProperty("version.richfaces"); //$NON-NLS-1$ - if (richfacesVersion != null) { - properties.put("richfaces.version", richfacesVersion); //$NON-NLS-1$ - } - } - setArtifactVersion("hibernate-validator.version", properties, "org.hibernate", "hibernate-validator", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("hibernate-annotations.version", properties, "org.hibernate", "hibernate-annotations", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("hibernate-entitymanager.version", properties, "org.hibernate", "hibernate-entitymanager", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - //setArtifactVersion("testng.version", properties, "org.hibernate", "hibernate-entitymanager", seamDependencies); - //if (seamVersion != null && "2.2".equals(seamVersion.subSequence(0, 3))) { - // properties.put("testng.version", "5.9"); - //} - setArtifactVersion("jboss.embedded.version", properties, "org.jboss.seam.embedded", "jboss-embedded-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("slf4j.version", properties, "org.slf4j", "slf4j-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("ejb.api.version", properties, "javax.ejb", "ejb-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("jsr250-api.version", properties, "javax.annotation", "jsr250-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("persistence-api.version", properties, "javax.persistence", "persistence-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("servlet.version", properties, "javax.servlet", "servlet-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - setArtifactVersion("javax.el.version", properties, "javax.el", "el-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - String droolsVersion = setArtifactVersion("drools.version", properties, "org.drools", "drools-core", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (droolsVersion == null) { - Properties seamProperties = rootPomModel.getProperties(); - droolsVersion = seamProperties.getProperty("version.drools"); //$NON-NLS-1$ - if (droolsVersion != null) { - properties.put("drools.version", droolsVersion); //$NON-NLS-1$ - } - } - String jbpmVersion = setArtifactVersion("jbpm.version", properties, "org.jbpm", "jbpm-jpdl", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (jbpmVersion == null) { - setArtifactVersion("jbpm3.version", properties, "org.jbpm.jbpm3", "jbpm-jpdl", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - //setArtifactVersion("mvel.version", properties, "org.mvel", "mvel14", seamDependencies); - -// 1.1 -// 3.3.0.ga -// 1.8 -// 1.2.21 - - } catch (Exception e) { - getDefault().log(e); - } - } - } else { - MavenSeamActivator.log(NLS.bind(Messages.MavenSeamActivator_The_folder_does_not_exist, seamHomePath)); - } - - List modules = model.getModules(); - modules.add("../" + artifactId); //$NON-NLS-1$ - if (!SeamFacetAbstractInstallDelegate - .isWarConfiguration(seamFacetModel)) { - modules.add("../" + ejbArtifactId); //$NON-NLS-1$ - modules.add("../" + earArtifactId); //$NON-NLS-1$ - } - webProjectName = seamFacetModel.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME); - - IProject seamWebProject = ResourcesPlugin.getWorkspace().getRoot().getProject(webProjectName); - IPath location = seamWebProject.getLocation().removeLastSegments(1); - location = location.append(parentProjectName); - MavenCoreActivator.createMavenProject(parentProjectName, null, model, false, location); - // disable workspace resolution - MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(parentProjectName); - ResolverConfiguration configuration = projectManager.getResolverConfiguration(project); - configuration.setResolveWorkspaceProjects(false); - projectManager.setResolverConfiguration(project, configuration); - } catch (Exception e) { - log(e); - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException ignore) {} - } - } - } - - private String setArtifactVersion(String property, Properties properties, String groupId, String artifactId, - List seamDependencies) { - for (Dependency dependency:seamDependencies) { - if (groupId.equals(dependency.getGroupId()) && artifactId.equals(dependency.getArtifactId())) { - String version = dependency.getVersion(); - if (version != null && !version.startsWith("${")) { //$NON-NLS-1$ - properties.put(property, version); - return version; - } - } - } - return null; - } - - public static void log(Throwable e) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e - .getLocalizedMessage(), e); - getDefault().getLog().log(status); - } - - public static void log(String message) { - IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message, null); - getDefault().getLog().log(status); - } - - public static class WarProjectUpdater extends ProjectUpdater { - - private static final String WAR_SOURCE_DIRECTORY = "warSourceDirectory"; //$NON-NLS-1$ - private static final String WAR_SOURCE_EXCLUDES = "warSourceExcludes"; //$NON-NLS-1$ - private IProject webProject; - - public WarProjectUpdater(IProject project) { - webProject = project; - } - - public void update(org.maven.ide.components.pom.Model projectModel) { - org.maven.ide.components.pom.Build build = projectModel.getBuild(); - if (build == null) { - // FIXME - return; - } - IJavaProject javaProject = JavaCore.create(webProject); - if (javaProject == null) { - return; - } - if (!javaProject.isOpen()) { - try { - javaProject.open(new NullProgressMonitor()); - } catch (JavaModelException e) { - MavenSeamActivator.log(e); - return; - } - } - IPath projectOutput; - IClasspathEntry[] entries; - try { - projectOutput = javaProject.getOutputLocation(); - entries = javaProject.getRawClasspath(); - } catch (JavaModelException e) { - MavenSeamActivator.log(e); - return; - } - List sources = new ArrayList(); - List outputs = new ArrayList(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { - IPath path = entries[i].getPath(); - sources.add(path); - IPath output = entries[i].getOutputLocation(); - if (output != null && !output.equals(projectOutput)) { - outputs.add(output); - } - } - } - int indexSource = 0; - for (IPath source:sources) { - if (source != null && source.toString().contains("main")) { //$NON-NLS-1$ - indexSource = sources.indexOf(source); - } - } - if (sources.size() > 0) { - - IPath path = sources.get(indexSource); - path = path.makeRelativeTo(javaProject.getPath()); - String value = path.toString(); - if (value.startsWith(MavenCoreActivator.SEPARATOR)) { - value = MavenCoreActivator.BASEDIR + value; - } else { - value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; - } - build.setSourceDirectory(value); - } - - if (projectOutput != null) { - String value = projectOutput.toString(); - if (value.startsWith(MavenCoreActivator.SEPARATOR)) { - value = MavenCoreActivator.BASEDIR + value; - } else { - value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; - } - build.setOutputDirectory(value); - } - - EList resources = build.getResources(); - resources.clear(); - for (IPath source:sources) { - org.maven.ide.components.pom.Resource resource = PomFactory.eINSTANCE.createResource(); - String value = source.makeRelativeTo(javaProject.getPath()).toString(); - if (value.startsWith(MavenCoreActivator.SEPARATOR)) { - value = MavenCoreActivator.BASEDIR + value; - } else { - value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; - } - resource.setDirectory(value); - resource.getExcludes().add("**/*.java"); //$NON-NLS-1$ - resources.add(resource); - } - - if (outputs.size() > 0) { - Plugin plugin = getPlugin(build, ORG_CODEHAUS_MOJO, "maven-war-plugin"); //$NON-NLS-1$ - Configuration configuration = plugin.getConfiguration(); - - if (configuration == null) { - configuration = PomFactory.eINSTANCE.createConfiguration(); - plugin.setConfiguration(configuration); - configuration.createNode(WAR_SOURCE_DIRECTORY); - String value = getRootComponent(webProject); - if (value.startsWith(MavenCoreActivator.SEPARATOR)) { - value = MavenCoreActivator.BASEDIR + value; - } else { - value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; - } - configuration.setStringValue(WAR_SOURCE_DIRECTORY, value); - } - StringBuffer buffer = new StringBuffer(); - boolean first = true; - for (IPath output:outputs) { - if (first) { - first = false; - } else { - buffer.append(","); //$NON-NLS-1$ - } - String root = getRootComponent(webProject); - output=output.makeRelativeTo(javaProject.getPath()); - String outputString = output.toString(); - if (outputString.startsWith(root)) { - outputString = outputString.substring(root.length()); - } - outputString = outputString.trim(); - buffer.append(outputString); - buffer.append("/**"); //$NON-NLS-1$ - - } - String excludeString = buffer.toString().trim(); - if (excludeString.startsWith(MavenCoreActivator.SEPARATOR)) { - excludeString = excludeString.substring(1); - } - configuration.setStringValue(WAR_SOURCE_EXCLUDES, excludeString); - } - sources.remove(indexSource); - if (sources.size() > 0) { - - Plugin plugin = getPlugin(build, ORG_CODEHAUS_MOJO , "build-helper-maven-plugin"); //$NON-NLS-1$ - plugin.setVersion("1.5"); //$NON-NLS-1$ - plugin.getExecutions().clear(); - - PluginExecution execution = PomFactory.eINSTANCE.createPluginExecution(); - execution.setId("add-source"); //$NON-NLS-1$ - execution.setPhase("generate-sources"); //$NON-NLS-1$ - execution.getGoals().add("add-source"); //$NON-NLS-1$ - plugin.getExecutions().add(execution); - Configuration configuration = PomFactory.eINSTANCE.createConfiguration(); - execution.setConfiguration(configuration); - Node n = configuration.createNode("sources"); //$NON-NLS-1$ - for (IPath source:sources) { - Node node = n.getOwnerDocument().createElement("source"); //$NON-NLS-1$ - n.appendChild(node); - source = source.makeRelativeTo(javaProject.getPath()); - String value = source.toString(); - if (value.startsWith(MavenCoreActivator.SEPARATOR)) { - value = MavenCoreActivator.BASEDIR + value; - } else { - value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; - } - node.appendChild(node.getOwnerDocument().createTextNode(value)); - } - } - } - } -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.seam; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Exclusion; +import org.apache.maven.model.Model; +import org.apache.maven.model.Parent; +import org.apache.maven.model.Resource; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.EList; +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.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.MavenModelManager; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.internal.MavenPluginActivator; +import org.eclipse.m2e.core.internal.project.ResolverConfigurationIO; +import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager; +import org.eclipse.m2e.core.project.ResolverConfiguration; +import org.eclipse.m2e.model.edit.pom.Configuration; +import org.eclipse.m2e.model.edit.pom.Plugin; +import org.eclipse.m2e.model.edit.pom.PluginExecution; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.util.PomResourceImpl; +import org.eclipse.osgi.util.NLS; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; +import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; +import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.jboss.tools.maven.core.IJBossMavenConstants; +import org.jboss.tools.maven.core.MavenCoreActivator; +import org.jboss.tools.maven.core.xpl.ProjectUpdater; +import org.jboss.tools.seam.core.SeamUtil; +import org.jboss.tools.seam.core.project.facet.SeamRuntime; +import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager; +import org.jboss.tools.seam.core.project.facet.SeamVersion; +import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties; +import org.jboss.tools.seam.internal.core.project.facet.SeamFacetAbstractInstallDelegate; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.w3c.dom.Node; + +/** + * The activator class controls the plug-in life cycle + */ +public class MavenSeamActivator extends AbstractUIPlugin { + + private static final String ORG_CODEHAUS_MOJO = "org.codehaus.mojo"; //$NON-NLS-1$ + + private static final String PARENT_SUFFIX = "-parent"; //$NON-NLS-1$ + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.maven.seam"; //$NON-NLS-1$ + + // The shared instance + private static MavenSeamActivator plugin; + + private String webProjectName; + private String artifactId; + + private String parentProjectName; + private String parentArtifactId; + + private String earProjectName; + private String earArtifactId; + + private String ejbProjectName; + private String ejbArtifactId; + + private String testProjectName; + private String testArtifactId; + + private String groupId; + + /** + * The constructor + */ + public MavenSeamActivator() { + } + + /* + * (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); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static MavenSeamActivator getDefault() { + return plugin; + } + + + public void configureSeamProject(IDataModel seamFacetModel, + IDataModel m2FacetModel) { + Assert.isNotNull(seamFacetModel); + Assert.isNotNull(m2FacetModel); + webProjectName = seamFacetModel.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME); + artifactId = m2FacetModel.getStringProperty(IJBossMavenConstants.ARTIFACT_ID); + groupId = m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID); + parentProjectName = webProjectName + PARENT_SUFFIX; + parentArtifactId = artifactId + PARENT_SUFFIX; + testProjectName = seamFacetModel.getStringProperty(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT); + testArtifactId = testProjectName; + earProjectName = seamFacetModel.getStringProperty(ISeamFacetDataModelProperties.SEAM_EAR_PROJECT); + earArtifactId = earProjectName; + ejbProjectName = seamFacetModel.getStringProperty(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT);; + ejbArtifactId = ejbProjectName; + configureParentProject(m2FacetModel, seamFacetModel); + configureWarProject(m2FacetModel, seamFacetModel); + configureTestProject(m2FacetModel, seamFacetModel); + if (!SeamFacetAbstractInstallDelegate + .isWarConfiguration(seamFacetModel)) { + configureEjbProject(m2FacetModel, seamFacetModel); + configureEarProject(m2FacetModel, seamFacetModel); + + } + } + + private void configureTestProject(IDataModel m2FacetModel, + IDataModel seamFacetModel) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testProjectName); + if (project == null || !project.exists()) { + return; + } + IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); + IJavaProject javaProject = JavaCore.create(project); + if (!pom.exists()) { + Model model = new Model(); + model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); + model.setGroupId(m2FacetModel + .getStringProperty(IJBossMavenConstants.GROUP_ID)); + model.setArtifactId(testArtifactId); + model.setVersion(m2FacetModel + .getStringProperty(IJBossMavenConstants.VERSION)); + model.setName(m2FacetModel.getStringProperty(IJBossMavenConstants.NAME) + " - test"); //$NON-NLS-1$ + model.setPackaging("jar"); //$NON-NLS-1$ + model.setDescription(m2FacetModel + .getStringProperty(IJBossMavenConstants.DESCRIPTION)); + + Parent parent = new Parent(); + parent.setArtifactId(parentArtifactId); + parent.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); + parent.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + parent.setRelativePath("../" + parentProjectName); //$NON-NLS-1$ + model.setParent(parent); + + List dependencies = model.getDependencies(); + + Dependency dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam.embedded"); //$NON-NLS-1$ + dependency.setArtifactId("hibernate-all"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam.embedded"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-embedded-all"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam.embedded"); //$NON-NLS-1$ + dependency.setArtifactId("thirdparty-all"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = getSeamDependency(); + dependency.setScope("compile"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = getJSFApi(); + dependency.setScope("test"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("javax.activation"); //$NON-NLS-1$ + dependency.setArtifactId("activation"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.testng"); //$NON-NLS-1$ + dependency.setArtifactId("testng"); //$NON-NLS-1$ + // FIXME + dependency.setVersion("${testng.version}"); //$NON-NLS-1$ + dependency.setClassifier("jdk15"); //$NON-NLS-1$ + dependency.setScope("compile"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.slf4j"); //$NON-NLS-1$ + dependency.setArtifactId("slf4j-api"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.slf4j"); //$NON-NLS-1$ + dependency.setArtifactId("slf4j-nop"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("javax.el"); //$NON-NLS-1$ + dependency.setArtifactId("el-api"); //$NON-NLS-1$ + dependency.setScope("test"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId(groupId); + dependency.setArtifactId(artifactId); + dependency.setType("war"); //$NON-NLS-1$ + dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + dependency.setScope("test"); //$NON-NLS-1$ + dependencies.add(dependency); + + if (!SeamFacetAbstractInstallDelegate + .isWarConfiguration(seamFacetModel)) { + dependency = new Dependency(); + dependency.setGroupId(groupId); + dependency.setArtifactId(ejbArtifactId); + dependency.setType("ejb"); //$NON-NLS-1$ + dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + dependency.setScope("test"); //$NON-NLS-1$ + dependencies.add(dependency); + } + dependency = new Dependency(); + dependency.setGroupId("org.drools"); //$NON-NLS-1$ + dependency.setArtifactId("drools-compiler"); //$NON-NLS-1$ + dependency.setScope("test"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jbpm"); //$NON-NLS-1$ + dependency.setArtifactId("jbpm-jpdl"); //$NON-NLS-1$ + dependency.setScope("test"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.eclipse.jdt"); //$NON-NLS-1$ + dependency.setArtifactId("core"); //$NON-NLS-1$ + dependency.setVersion("3.4.2.v_883_R34x"); //$NON-NLS-1$ + dependency.setScope("test"); //$NON-NLS-1$ + dependencies.add(dependency); + + Build build = new Build(); + try { + //build.setFinalName(testProjectName); + String sourceDirectory = MavenCoreActivator.getSourceDirectory(javaProject); + if (sourceDirectory != null) { + build.setTestSourceDirectory(sourceDirectory); + } + String outputDirectory = MavenCoreActivator.getOutputDirectory(javaProject); + build.setOutputDirectory(outputDirectory); + build.setTestOutputDirectory(outputDirectory); + MavenCoreActivator.addResource(build, project, sourceDirectory); + Resource resource = new Resource(); + + resource.setDirectory(MavenCoreActivator.BASEDIR + "/bootstrap"); //$NON-NLS-1$ + List excludes = new ArrayList(); + excludes.add("**/*.java"); //$NON-NLS-1$ + resource.setExcludes(excludes); + build.getResources().add(resource); + + resource = new Resource(); + IProject webProject = ResourcesPlugin.getWorkspace().getRoot().getProject(webProjectName); + if (project == null || !project.exists()) { + return; + } + String webContent = getRootComponent(webProject); + resource.setDirectory(MavenCoreActivator.BASEDIR + "/../" + webProjectName + "/" + webContent); //$NON-NLS-1$ //$NON-NLS-2$ + excludes = new ArrayList(); + excludes.add("**/*.java"); //$NON-NLS-1$ + resource.setExcludes(excludes); + build.getResources().add(resource); + + model.setBuild(build); + MavenCoreActivator.createMavenProject(testProjectName, null, model, true); + } catch (Exception e) { + MavenSeamActivator.log(e); + } + + } + + } + + private void configureEarProject(IDataModel m2FacetModel, + IDataModel seamFacetModel) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(earProjectName); + IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); + //IJavaProject javaProject = JavaCore.create(project); + if (!pom.exists()) { + Model model = new Model(); + model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); + model.setGroupId(m2FacetModel + .getStringProperty(IJBossMavenConstants.GROUP_ID)); + model.setArtifactId(earArtifactId); + model.setVersion(m2FacetModel + .getStringProperty(IJBossMavenConstants.VERSION)); + model.setName(m2FacetModel.getStringProperty(IJBossMavenConstants.NAME) + " - EAR"); //$NON-NLS-1$ + model.setPackaging("ear"); //$NON-NLS-1$ + model.setDescription(m2FacetModel + .getStringProperty(IJBossMavenConstants.DESCRIPTION)); + + Parent parent = new Parent(); + parent.setArtifactId(parentArtifactId); + parent.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); + parent.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + parent.setRelativePath("../" + parentProjectName); //$NON-NLS-1$ + model.setParent(parent); + + List dependencies = model.getDependencies(); + + Dependency dependency = new Dependency(); + dependency.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); + dependency.setArtifactId(ejbProjectName); + dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + dependency.setType("ejb"); //$NON-NLS-1$ + dependency.setScope("runtime"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); + dependency.setArtifactId(webProjectName); + dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + dependency.setType("war"); //$NON-NLS-1$ + dependency.setScope("runtime"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = getSeamDependency(); + dependency.setVersion("${seam.version}"); //$NON-NLS-1$ + dependency.setType("ejb"); //$NON-NLS-1$ + dependency.setScope("compile"); //$NON-NLS-1$ + List exclusions = dependency.getExclusions(); + Exclusion exclusion = new Exclusion(); + exclusion.setGroupId("javassist"); //$NON-NLS-1$ + exclusion.setArtifactId("javassist"); //$NON-NLS-1$ + exclusions.add(exclusion); + + exclusion = new Exclusion(); + exclusion.setGroupId("javax.el"); //$NON-NLS-1$ + exclusion.setArtifactId("el-api"); //$NON-NLS-1$ + exclusions.add(exclusion); + + exclusion = new Exclusion(); + exclusion.setGroupId("dom4j"); //$NON-NLS-1$ + exclusion.setArtifactId("dom4j"); //$NON-NLS-1$ + exclusions.add(exclusion); + + exclusion = new Exclusion(); + exclusion.setGroupId("xstream"); //$NON-NLS-1$ + exclusion.setArtifactId("xstream"); //$NON-NLS-1$ + exclusions.add(exclusion); + + exclusion = new Exclusion(); + exclusion.setGroupId("xpp3"); //$NON-NLS-1$ + exclusion.setArtifactId("xpp3_min"); //$NON-NLS-1$ + exclusions.add(exclusion); + + dependencies.add(dependency); + + dependency = getRichFacesApi(); + dependency.setType("jar"); //$NON-NLS-1$ + dependency.setScope("compile"); //$NON-NLS-1$ + exclusions = dependency.getExclusions(); + exclusion = new Exclusion(); + exclusion.setGroupId("commons-collections"); //$NON-NLS-1$ + exclusion.setArtifactId("commons-collections"); //$NON-NLS-1$ + exclusions.add(exclusion); + exclusion = new Exclusion(); + exclusion.setGroupId("commons-logging"); //$NON-NLS-1$ + exclusion.setArtifactId("commons-logging"); //$NON-NLS-1$ + exclusions.add(exclusion); + + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.drools"); //$NON-NLS-1$ + dependency.setArtifactId("drools-compiler"); //$NON-NLS-1$ + dependency.setType("jar"); //$NON-NLS-1$ + dependency.setScope("compile"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + String jbpmGroupId = "org.jbpm"; //$NON-NLS-1$ + // JBoss EAP 5.0 requires org.jbpm.jbpm3 + SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(seamFacetModel.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString()); + if(seamRuntime!=null) { + SeamVersion seamVersion = seamRuntime.getVersion(); + if (SeamVersion.SEAM_2_2.equals(seamVersion)) { + String fullVersion = SeamUtil.getSeamVersionFromManifest(seamRuntime); + if (fullVersion != null && fullVersion.contains("EAP")) { //$NON-NLS-1$ + jbpmGroupId = "org.jbpm.jbpm3"; //$NON-NLS-1$ + } + } + } + dependency.setGroupId(jbpmGroupId); + dependency.setArtifactId("jbpm-jpdl"); //$NON-NLS-1$ + dependency.setType("jar"); //$NON-NLS-1$ + dependency.setScope("compile"); //$NON-NLS-1$ + dependencies.add(dependency); + +// dependency = new Dependency(); +// dependency.setGroupId("org.mvel"); +// if ("org.jbpm.jbpm3".equals(jbpmGroupId)) { +// dependency.setArtifactId("mvel2"); +// } else { +// dependency.setArtifactId("mvel14"); +// } +// dependency.setType("jar"); +// dependency.setScope("compile"); +// dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("commons-digester"); //$NON-NLS-1$ + dependency.setArtifactId("commons-digester"); //$NON-NLS-1$ + dependencies.add(dependency); + + Build build = new Build(); + try { + build.setFinalName(earProjectName); + + String sourceDirectory = MavenCoreActivator.getEarRoot(project); + if (sourceDirectory != null) { + build.setSourceDirectory(sourceDirectory); + } + build.setOutputDirectory("target/classes"); //$NON-NLS-1$ + MavenCoreActivator.addMavenEarPlugin(build, project, m2FacetModel, ejbArtifactId, true); + model.setBuild(build); + MavenCoreActivator.createMavenProject(earProjectName, null, model, true); + removeWTPContainers(m2FacetModel, project); + } catch (Exception e) { + MavenSeamActivator.log(e); + } + + } + } + + private void removeRuntime(IProject project) throws CoreException { + IFacetedProject facetedProject = ProjectFacetsManager.create( project ); + facetedProject.setRuntime(null, null); + + } + + private void configureEjbProject(IDataModel m2FacetModel, + IDataModel seamFacetModel) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ejbProjectName); + IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); + IJavaProject javaProject = JavaCore.create(project); + if (!pom.exists()) { + Model model = new Model(); + model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); + model.setGroupId(m2FacetModel + .getStringProperty(IJBossMavenConstants.GROUP_ID)); + model.setArtifactId(ejbArtifactId); + model.setVersion(m2FacetModel + .getStringProperty(IJBossMavenConstants.VERSION)); + model.setName(m2FacetModel.getStringProperty(IJBossMavenConstants.NAME) + " - EJB"); //$NON-NLS-1$ + model.setPackaging("ejb"); //$NON-NLS-1$ + model.setDescription(m2FacetModel + .getStringProperty(IJBossMavenConstants.DESCRIPTION)); + + Parent parent = new Parent(); + parent.setArtifactId(parentArtifactId); + parent.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); + parent.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + parent.setRelativePath("../" + parentProjectName); //$NON-NLS-1$ + model.setParent(parent); + + List dependencies = model.getDependencies(); + + Dependency dependency = getSeamDependency(); + dependency.setScope("provided"); //$NON-NLS-1$ + dependencies.add(dependency); + dependencies.add(getJSFApi()); + dependencies.add(getRichFacesApi()); + + dependency = new Dependency(); + dependency.setGroupId("javax.ejb"); //$NON-NLS-1$ + dependency.setArtifactId("ejb-api"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("javax.annotation"); //$NON-NLS-1$ + dependency.setArtifactId("jsr250-api"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependency = new Dependency(); + dependency.setGroupId("javax.persistence"); //$NON-NLS-1$ + dependency.setArtifactId("persistence-api"); //$NON-NLS-1$ + dependencies.add(dependency); + + dependencies.add(getHibernateAnnotations()); + dependencies.add(getHibernateCommonAnnotations()); + dependencies.add(getHibernateValidator()); + + Build build = new Build(); + try { + // FIXME + //build.setFinalName(ejbArtifactId); + String outputDirectory = MavenCoreActivator.getOutputDirectory(javaProject); + build.setOutputDirectory(outputDirectory); + String sourceDirectory = MavenCoreActivator.getSourceDirectory(javaProject); + if (sourceDirectory != null) { + build.setSourceDirectory(sourceDirectory); + } + MavenCoreActivator.addMavenEjbPlugin(build, project); + model.setBuild(build); + MavenCoreActivator.createMavenProject(ejbProjectName, null, model, true); + removeWTPContainers(m2FacetModel, project); + } catch (Exception e) { + MavenSeamActivator.log(e); + } + + } + + } + + public void updateProject(IFile pomFile, ProjectUpdater updater) { + File pom = pomFile.getLocation().toFile(); + PomResourceImpl resource = null; + try { + resource = MavenCoreActivator.loadResource(pomFile); + updater.update(resource.getModel()); + resource.save(Collections.EMPTY_MAP); + } catch (Exception ex) { + String msg = "Unable to update " + pom; + log(ex, msg); + } finally { + if (resource != null) { + resource.unload(); + } + } + } + + public void addDependency(IFile pomFile, + org.apache.maven.model.Dependency dependency) { + updateProject(pomFile, new DependencyAdder(dependency)); + } + + private void configureWarProject(IDataModel m2FacetModel,IDataModel seamFacetModel) { + try { + IProject webProject = ResourcesPlugin.getWorkspace().getRoot().getProject(webProjectName); + + IFile pomFile = webProject.getFile(IMavenConstants.POM_FILE_NAME); + + String artifactId = parentProjectName; + String groupId = m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID); + String version = m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION); + + String relativePath = "../" + parentProjectName; //$NON-NLS-1$ + ParentAdder parentAdder = new ParentAdder(groupId, artifactId, version, relativePath); + updateProject(pomFile, parentAdder); + + Dependency dependency = getHibernateValidator(); + //dependency.setScope("provided"); + addDependency(pomFile,dependency); + + dependency = getHibernateAnnotations(); + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ + dependency.setArtifactId("hibernate-entitymanager"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + dependency = getSeamDependency(); + if (!SeamFacetAbstractInstallDelegate + .isWarConfiguration(seamFacetModel)) { + dependency.setScope("provided"); //$NON-NLS-1$ + } + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam-ui"); //$NON-NLS-1$ + List exclusions = dependency.getExclusions(); + Exclusion exclusion = new Exclusion(); + exclusion.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + exclusion.setArtifactId("jboss-seam"); //$NON-NLS-1$ + exclusions.add(exclusion); + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam-ioc"); //$NON-NLS-1$ + exclusions = dependency.getExclusions(); + exclusion = new Exclusion(); + exclusion.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + exclusion.setArtifactId("jboss-seam"); //$NON-NLS-1$ + exclusions.add(exclusion); + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam-debug"); //$NON-NLS-1$ + // FIXME + dependency.setVersion("${seam.version}"); //$NON-NLS-1$ + + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam-mail"); //$NON-NLS-1$ + + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam-pdf"); //$NON-NLS-1$ + + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam-remoting"); //$NON-NLS-1$ + + addDependency(pomFile,dependency); + + if (FacetedProjectFramework.hasProjectFacet(webProject, ISeamFacetDataModelProperties.SEAM_FACET_ID, ISeamFacetDataModelProperties.SEAM_FACET_VERSION_21)) { + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam-excel"); //$NON-NLS-1$ + + addDependency(pomFile,dependency); + } + + dependency = new Dependency(); + dependency.setGroupId("javax.servlet"); //$NON-NLS-1$ + dependency.setArtifactId("servlet-api"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.richfaces.ui"); //$NON-NLS-1$ + dependency.setArtifactId("richfaces-ui"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + dependency = getRichFacesApi(); + if (!SeamFacetAbstractInstallDelegate + .isWarConfiguration(seamFacetModel)) { + dependency.setScope("provided"); //$NON-NLS-1$ + } + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.richfaces.framework"); //$NON-NLS-1$ + dependency.setArtifactId("richfaces-impl"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + dependency = getJSFApi(); + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("javax.faces"); //$NON-NLS-1$ + dependency.setArtifactId("jsf-impl"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("javax.el"); //$NON-NLS-1$ + dependency.setArtifactId("el-api"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + if (SeamFacetAbstractInstallDelegate + .isWarConfiguration(seamFacetModel)) { + dependency = new Dependency(); + dependency.setGroupId("org.drools"); //$NON-NLS-1$ + dependency.setArtifactId("drools-compiler"); //$NON-NLS-1$ + dependency.setType("jar"); //$NON-NLS-1$ + dependency.setScope("compile"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("org.jbpm"); //$NON-NLS-1$ + dependency.setArtifactId("jbpm-jpdl"); //$NON-NLS-1$ + dependency.setType("jar"); //$NON-NLS-1$ + dependency.setScope("compile"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + + dependency = new Dependency(); + dependency.setGroupId("commons-digester"); //$NON-NLS-1$ + dependency.setArtifactId("commons-digester"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + updateProject(pomFile, new WarProjectUpdater(webProject)); + } + + // ejb project + + if (!SeamFacetAbstractInstallDelegate + .isWarConfiguration(seamFacetModel)) { + dependency = new Dependency(); + dependency.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); + dependency.setArtifactId(ejbProjectName); + dependency.setVersion(m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION)); + dependency.setType("ejb"); //$NON-NLS-1$ + dependency.setScope("provided"); //$NON-NLS-1$ + addDependency(pomFile,dependency); + } + + updateProject(pomFile, new WarProjectUpdater(webProject)); + removeWTPContainers(m2FacetModel, webProject); + } catch (Exception e) { + MavenSeamActivator.log(e); + } + } + + + + private static String getRootComponent(IProject webProject) { + IVirtualComponent component = ComponentCore.createComponent(webProject); + IVirtualFolder rootFolder = component.getRootFolder(); + IContainer root = rootFolder.getUnderlyingFolder(); + String webContentRoot = root.getProjectRelativePath().toString(); + return webContentRoot; + } + + private static Plugin getPlugin(org.eclipse.m2e.model.edit.pom.Build build, + String groupId, String artifactId) { + EList plugins = build.getPlugins(); + for (Plugin plugin : plugins) { + String group = plugin.getGroupId(); + if (group == null) { + group = ORG_CODEHAUS_MOJO; + } + String artifact = plugin.getArtifactId(); + if (group.equals(groupId) && artifactId.equals(artifact)) { + return plugin; + } + } + Plugin newPlugin = PomFactory.eINSTANCE.createPlugin(); + newPlugin.setGroupId(groupId); + newPlugin.setArtifactId(artifactId); + build.getPlugins().add(newPlugin); + return newPlugin; + } + + private void removeWTPContainers(IDataModel m2FacetModel, + IProject webProject) throws JavaModelException { + if (m2FacetModel.getBooleanProperty(IJBossMavenConstants.REMOVE_WTP_CLASSPATH_CONTAINERS)) { + IJavaProject javaProject = JavaCore.create(webProject); + IClasspathEntry[] entries = javaProject.getRawClasspath(); + List newEntries = new ArrayList(); + for (int i = 0; i < entries.length; i++) { + IClasspathEntry entry = entries[i]; + boolean add = true; + if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { + // FIXME + IPath path = entry.getPath(); + if (path != null) { + String value = path.toString(); + if (value.startsWith("org.eclipse.jst")) { //$NON-NLS-1$ + add = false; + } + } + } + if (add) { + newEntries.add(entry); + } + } + javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); + } + } + + private Dependency getHibernateValidator() { + Dependency dependency = new Dependency(); + dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ + dependency.setArtifactId("hibernate-validator"); //$NON-NLS-1$ + return dependency; + } + + private Dependency getHibernateAnnotations() { + Dependency dependency; + dependency = new Dependency(); + dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ + dependency.setArtifactId("hibernate-annotations"); //$NON-NLS-1$ + return dependency; + } + + private Dependency getHibernateCommonAnnotations() { + Dependency dependency; + dependency = new Dependency(); + dependency.setGroupId("org.hibernate"); //$NON-NLS-1$ + dependency.setArtifactId("hibernate-commons-annotations"); //$NON-NLS-1$ + return dependency; + } + + private Dependency getRichFacesApi() { + Dependency dependency; + dependency = new Dependency(); + dependency.setGroupId("org.richfaces.framework"); //$NON-NLS-1$ + dependency.setArtifactId("richfaces-api"); //$NON-NLS-1$ + return dependency; + } + + private Dependency getJSFApi() { + Dependency dependency; + dependency = new Dependency(); + dependency.setGroupId("javax.faces"); //$NON-NLS-1$ + dependency.setArtifactId("jsf-api"); //$NON-NLS-1$ + return dependency; + } + + private Dependency getSeamDependency() { + Dependency dependency; + dependency = new Dependency(); + dependency.setGroupId("org.jboss.seam"); //$NON-NLS-1$ + dependency.setArtifactId("jboss-seam"); //$NON-NLS-1$ + return dependency; + } + + private void configureParentProject(IDataModel m2FacetModel, IDataModel seamFacetModel) { + Bundle bundle = getDefault().getBundle(); + URL parentPomEntryURL = bundle.getEntry("/poms/parent-pom.xml"); //$NON-NLS-1$ + InputStream inputStream = null; + try { + URL resolvedURL = FileLocator.resolve(parentPomEntryURL); + MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); + inputStream = resolvedURL.openStream(); + Model model = modelManager.readMavenModel(inputStream); + model.setArtifactId(parentArtifactId); + model.setGroupId(m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID)); + String projectVersion = m2FacetModel.getStringProperty(IJBossMavenConstants.VERSION); + String name = m2FacetModel.getStringProperty(IJBossMavenConstants.NAME); + if (name != null && name.trim().length() > 0) { + model.setName(name + " - parent"); //$NON-NLS-1$ + } + String description= m2FacetModel.getStringProperty(IJBossMavenConstants.DESCRIPTION); + if (description != null && description.trim().length() > 0) { + model.setDescription(description + " - parent"); //$NON-NLS-1$ + } + model.setVersion(projectVersion); + + Properties properties = model.getProperties(); + properties.put(IJBossMavenConstants.PROJECT_VERSION, projectVersion); + SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(seamFacetModel.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString()); + if(seamRuntime==null) { + getDefault().log(Messages.MavenSeamActivator_Cannot_get_seam_runtime + seamFacetModel.getProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME).toString()); + } + String seamVersion = m2FacetModel.getStringProperty(IJBossMavenConstants.SEAM_MAVEN_VERSION); + if (seamVersion != null && seamVersion.trim().length() > 0) { + properties.put(IJBossMavenConstants.SEAM_VERSION, seamVersion); + } + String seamHomePath = seamRuntime.getHomeDir(); + File seamHomeDir = new File(seamHomePath); + if (seamHomeDir.exists()) { + //String seamVersion = SeamUtil.getSeamVersionFromManifest(seamRuntime.getHomeDir()); + //properties.put(IJBossMavenConstants.SEAM_VERSION, seamVersion); + File buildDir = new File(seamHomeDir,"build"); //$NON-NLS-1$ + File rootPom = new File(buildDir,"root.pom.xml"); //$NON-NLS-1$ + if (!rootPom.exists()) { + MavenSeamActivator.log(NLS.bind(Messages.MavenSeamActivator_The_file_does_not_exist, rootPom.getAbsolutePath())); + } else { + try { + Model rootPomModel = modelManager.readMavenModel(rootPom); + List seamDependencies = rootPomModel.getDependencyManagement().getDependencies(); + setArtifactVersion("jsf.version", properties, "javax.faces", "jsf-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String richfacesVersion = setArtifactVersion("richfaces.version", properties, "org.richfaces.framework", "richfaces-impl", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (richfacesVersion == null) { + Properties seamProperties = rootPomModel.getProperties(); + richfacesVersion = seamProperties.getProperty("version.richfaces"); //$NON-NLS-1$ + if (richfacesVersion != null) { + properties.put("richfaces.version", richfacesVersion); //$NON-NLS-1$ + } + } + setArtifactVersion("hibernate-validator.version", properties, "org.hibernate", "hibernate-validator", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("hibernate-annotations.version", properties, "org.hibernate", "hibernate-annotations", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("hibernate-entitymanager.version", properties, "org.hibernate", "hibernate-entitymanager", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + //setArtifactVersion("testng.version", properties, "org.hibernate", "hibernate-entitymanager", seamDependencies); + //if (seamVersion != null && "2.2".equals(seamVersion.subSequence(0, 3))) { + // properties.put("testng.version", "5.9"); + //} + setArtifactVersion("jboss.embedded.version", properties, "org.jboss.seam.embedded", "jboss-embedded-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("slf4j.version", properties, "org.slf4j", "slf4j-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("ejb.api.version", properties, "javax.ejb", "ejb-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("jsr250-api.version", properties, "javax.annotation", "jsr250-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("persistence-api.version", properties, "javax.persistence", "persistence-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("servlet.version", properties, "javax.servlet", "servlet-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + setArtifactVersion("javax.el.version", properties, "javax.el", "el-api", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String droolsVersion = setArtifactVersion("drools.version", properties, "org.drools", "drools-core", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (droolsVersion == null) { + Properties seamProperties = rootPomModel.getProperties(); + droolsVersion = seamProperties.getProperty("version.drools"); //$NON-NLS-1$ + if (droolsVersion != null) { + properties.put("drools.version", droolsVersion); //$NON-NLS-1$ + } + } + String jbpmVersion = setArtifactVersion("jbpm.version", properties, "org.jbpm", "jbpm-jpdl", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (jbpmVersion == null) { + setArtifactVersion("jbpm3.version", properties, "org.jbpm.jbpm3", "jbpm-jpdl", seamDependencies); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + //setArtifactVersion("mvel.version", properties, "org.mvel", "mvel14", seamDependencies); + +// 1.1 +// 3.3.0.ga +// 1.8 +// 1.2.21 + + } catch (Exception e) { + getDefault().log(e); + } + } + } else { + MavenSeamActivator.log(NLS.bind(Messages.MavenSeamActivator_The_folder_does_not_exist, seamHomePath)); + } + + List modules = model.getModules(); + modules.add("../" + artifactId); //$NON-NLS-1$ + if (!SeamFacetAbstractInstallDelegate + .isWarConfiguration(seamFacetModel)) { + modules.add("../" + ejbArtifactId); //$NON-NLS-1$ + modules.add("../" + earArtifactId); //$NON-NLS-1$ + } + webProjectName = seamFacetModel.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME); + + IProject seamWebProject = ResourcesPlugin.getWorkspace().getRoot().getProject(webProjectName); + IPath location = seamWebProject.getLocation().removeLastSegments(1); + location = location.append(parentProjectName); + MavenCoreActivator.createMavenProject(parentProjectName, null, model, false, location); + // disable workspace resolution + MavenProjectManager projectManager = MavenPluginActivator.getDefault().getMavenProjectManager(); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(parentProjectName); + ResolverConfiguration configuration = ResolverConfigurationIO.readResolverConfiguration(project); + configuration.setResolveWorkspaceProjects(false); + ResolverConfigurationIO.saveResolverConfiguration(project, configuration); + } catch (Exception e) { + log(e); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException ignore) {} + } + } + } + + private String setArtifactVersion(String property, Properties properties, String groupId, String artifactId, + List seamDependencies) { + for (Dependency dependency:seamDependencies) { + if (groupId.equals(dependency.getGroupId()) && artifactId.equals(dependency.getArtifactId())) { + String version = dependency.getVersion(); + if (version != null && !version.startsWith("${")) { //$NON-NLS-1$ + properties.put(property, version); + return version; + } + } + } + return null; + } + + public static void log(Throwable e) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e + .getLocalizedMessage(), e); + getDefault().getLog().log(status); + } + + public static void log(Throwable e, String message) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e); + getDefault().getLog().log(status); + } + + public static void log(String message) { + IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message, null); + getDefault().getLog().log(status); + } + + public static class WarProjectUpdater extends ProjectUpdater { + + private static final String WAR_SOURCE_DIRECTORY = "warSourceDirectory"; //$NON-NLS-1$ + private static final String WAR_SOURCE_EXCLUDES = "warSourceExcludes"; //$NON-NLS-1$ + private IProject webProject; + + public WarProjectUpdater(IProject project) { + webProject = project; + } + + public void update(org.eclipse.m2e.model.edit.pom.Model projectModel) { + org.eclipse.m2e.model.edit.pom.Build build = projectModel.getBuild(); + if (build == null) { + return; + } + IJavaProject javaProject = JavaCore.create(webProject); + if (javaProject == null) { + return; + } + if (!javaProject.isOpen()) { + try { + javaProject.open(new NullProgressMonitor()); + } catch (JavaModelException e) { + MavenSeamActivator.log(e); + return; + } + } + IPath projectOutput; + IClasspathEntry[] entries; + try { + projectOutput = javaProject.getOutputLocation(); + entries = javaProject.getRawClasspath(); + } catch (JavaModelException e) { + MavenSeamActivator.log(e); + return; + } + List sources = new ArrayList(); + List outputs = new ArrayList(); + for (int i = 0; i < entries.length; i++) { + if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { + IPath path = entries[i].getPath(); + sources.add(path); + IPath output = entries[i].getOutputLocation(); + if (output != null && !output.equals(projectOutput)) { + outputs.add(output); + } + } + } + int indexSource = 0; + for (IPath source:sources) { + if (source != null && source.toString().contains("main")) { //$NON-NLS-1$ + indexSource = sources.indexOf(source); + } + } + if (sources.size() > 0) { + + IPath path = sources.get(indexSource); + path = path.makeRelativeTo(javaProject.getPath()); + String value = path.toString(); + if (value.startsWith(MavenCoreActivator.SEPARATOR)) { + value = MavenCoreActivator.BASEDIR + value; + } else { + value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; + } + build.setSourceDirectory(value); + } + + if (projectOutput != null) { + String value = projectOutput.toString(); + if (value.startsWith(MavenCoreActivator.SEPARATOR)) { + value = MavenCoreActivator.BASEDIR + value; + } else { + value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; + } + build.setOutputDirectory(value); + } + + EList resources = build.getResources(); + resources.clear(); + for (IPath source:sources) { + org.eclipse.m2e.model.edit.pom.Resource resource = PomFactory.eINSTANCE.createResource(); + String value = source.makeRelativeTo(javaProject.getPath()).toString(); + if (value.startsWith(MavenCoreActivator.SEPARATOR)) { + value = MavenCoreActivator.BASEDIR + value; + } else { + value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; + } + resource.setDirectory(value); + resource.getExcludes().add("**/*.java"); //$NON-NLS-1$ + resources.add(resource); + } + + if (outputs.size() > 0) { + Plugin plugin = getPlugin(build, ORG_CODEHAUS_MOJO, "maven-war-plugin"); //$NON-NLS-1$ + Configuration configuration = plugin.getConfiguration(); + + if (configuration == null) { + configuration = PomFactory.eINSTANCE.createConfiguration(); + plugin.setConfiguration(configuration); + configuration.createNode(WAR_SOURCE_DIRECTORY); + String value = getRootComponent(webProject); + if (value.startsWith(MavenCoreActivator.SEPARATOR)) { + value = MavenCoreActivator.BASEDIR + value; + } else { + value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; + } + configuration.setStringValue(WAR_SOURCE_DIRECTORY, value); + } + StringBuffer buffer = new StringBuffer(); + boolean first = true; + for (IPath output:outputs) { + if (first) { + first = false; + } else { + buffer.append(","); //$NON-NLS-1$ + } + String root = getRootComponent(webProject); + output=output.makeRelativeTo(javaProject.getPath()); + String outputString = output.toString(); + if (outputString.startsWith(root)) { + outputString = outputString.substring(root.length()); + } + outputString = outputString.trim(); + buffer.append(outputString); + buffer.append("/**"); //$NON-NLS-1$ + + } + String excludeString = buffer.toString().trim(); + if (excludeString.startsWith(MavenCoreActivator.SEPARATOR)) { + excludeString = excludeString.substring(1); + } + configuration.setStringValue(WAR_SOURCE_EXCLUDES, excludeString); + } + sources.remove(indexSource); + if (sources.size() > 0) { + + Plugin plugin = getPlugin(build, ORG_CODEHAUS_MOJO , "build-helper-maven-plugin"); //$NON-NLS-1$ + plugin.setVersion("1.5"); //$NON-NLS-1$ + plugin.getExecutions().clear(); + + PluginExecution execution = PomFactory.eINSTANCE.createPluginExecution(); + execution.setId("add-source"); //$NON-NLS-1$ + execution.setPhase("generate-sources"); //$NON-NLS-1$ + execution.getGoals().add("add-source"); //$NON-NLS-1$ + plugin.getExecutions().add(execution); + Configuration configuration = PomFactory.eINSTANCE.createConfiguration(); + execution.setConfiguration(configuration); + Node n = configuration.createNode("sources"); //$NON-NLS-1$ + for (IPath source:sources) { + Node node = n.getOwnerDocument().createElement("source"); //$NON-NLS-1$ + n.appendChild(node); + source = source.makeRelativeTo(javaProject.getPath()); + String value = source.toString(); + if (value.startsWith(MavenCoreActivator.SEPARATOR)) { + value = MavenCoreActivator.BASEDIR + value; + } else { + value = MavenCoreActivator.BASEDIR + MavenCoreActivator.SEPARATOR + value; + } + node.appendChild(node.getOwnerDocument().createTextNode(value)); + } + } + } + } + + + public static class DependencyAdder extends ProjectUpdater { + + private final org.apache.maven.model.Dependency dependency; + + public DependencyAdder(org.apache.maven.model.Dependency dependency) { + this.dependency = dependency; + } + + public void update(org.eclipse.m2e.model.edit.pom.Model model) { + org.eclipse.m2e.model.edit.pom.Dependency dependency = PomFactory.eINSTANCE + .createDependency(); + + dependency.setGroupId(this.dependency.getGroupId()); + dependency.setArtifactId(this.dependency.getArtifactId()); + + if (this.dependency.getVersion() != null) { + dependency.setVersion(this.dependency.getVersion()); + } + + if (this.dependency.getClassifier() != null) { + dependency.setClassifier(this.dependency.getClassifier()); + } + + if (this.dependency.getType() != null // + && !"jar".equals(this.dependency.getType()) // + && !"null".equals(this.dependency.getType())) { // guard + // against + // MNGECLIPSE-622 + dependency.setType(this.dependency.getType()); + } + + if (this.dependency.getScope() != null + && !"compile".equals(this.dependency.getScope())) { + dependency.setScope(this.dependency.getScope()); + } + + if (this.dependency.getSystemPath() != null) { + dependency.setSystemPath(this.dependency.getSystemPath()); + } + + if (this.dependency.isOptional()) { + dependency.setOptional("true"); + } + + if (!this.dependency.getExclusions().isEmpty()) { + + Iterator it = this.dependency + .getExclusions().iterator(); + while (it.hasNext()) { + Exclusion e = it.next(); + org.eclipse.m2e.model.edit.pom.Exclusion exclusion = PomFactory.eINSTANCE + .createExclusion(); + exclusion.setGroupId(e.getGroupId()); + exclusion.setArtifactId(e.getArtifactId()); + dependency.getExclusions().add(exclusion); + } + } + + // search for dependency with same GAC and remove if found + Iterator it = model + .getDependencies().iterator(); + boolean mergeScope = false; + String oldScope = Artifact.SCOPE_COMPILE; + while (it.hasNext()) { + org.eclipse.m2e.model.edit.pom.Dependency dep = it.next(); + if (dep.getGroupId().equals(dependency.getGroupId()) + && dep.getArtifactId().equals( + dependency.getArtifactId()) + && compareNulls(dep.getClassifier(), + dependency.getClassifier())) { + oldScope = dep.getScope(); + it.remove(); + mergeScope = true; + } + } + + if (mergeScope) { + // merge scopes + if (oldScope == null) { + oldScope = Artifact.SCOPE_COMPILE; + } + + String newScope = this.dependency.getScope(); + if (newScope == null) { + newScope = Artifact.SCOPE_COMPILE; + } + + if (!oldScope.equals(newScope)) { + boolean systemScope = false; + boolean providedScope = false; + boolean compileScope = false; + boolean runtimeScope = false; + boolean testScope = false; + + // test old scope + if (Artifact.SCOPE_COMPILE.equals(oldScope)) { + systemScope = true; + providedScope = true; + compileScope = true; + runtimeScope = false; + testScope = false; + } else if (Artifact.SCOPE_RUNTIME.equals(oldScope)) { + systemScope = false; + providedScope = false; + compileScope = true; + runtimeScope = true; + testScope = false; + } else if (Artifact.SCOPE_TEST.equals(oldScope)) { + systemScope = true; + providedScope = true; + compileScope = true; + runtimeScope = true; + testScope = true; + } + + // merge with new one + if (Artifact.SCOPE_COMPILE.equals(newScope)) { + systemScope = systemScope || true; + providedScope = providedScope || true; + compileScope = compileScope || true; + runtimeScope = runtimeScope || false; + testScope = testScope || false; + } else if (Artifact.SCOPE_RUNTIME.equals(newScope)) { + systemScope = systemScope || false; + providedScope = providedScope || false; + compileScope = compileScope || true; + runtimeScope = runtimeScope || true; + testScope = testScope || false; + } else if (Artifact.SCOPE_TEST.equals(newScope)) { + systemScope = systemScope || true; + providedScope = providedScope || true; + compileScope = compileScope || true; + runtimeScope = runtimeScope || true; + testScope = testScope || true; + } + + if (testScope) { + newScope = Artifact.SCOPE_TEST; + } else if (runtimeScope) { + newScope = Artifact.SCOPE_RUNTIME; + } else if (compileScope) { + newScope = Artifact.SCOPE_COMPILE; + } else { + // unchanged + } + + dependency.setScope(newScope); + } + } + + model.getDependencies().add(dependency); + } + + @SuppressWarnings("null") + private boolean compareNulls(String s1, String s2) { + if (s1 == null && s2 == null) { + return true; + } + if ((s1 == null && s2 != null) || (s2 == null && s1 != null)) { + return false; + } + return s1.equals(s2); + } + } + +} Index: src/org/jboss/tools/maven/seam/SeamLifecycleMapping.java =================================================================== --- src/org/jboss/tools/maven/seam/SeamLifecycleMapping.java (revision 0) +++ src/org/jboss/tools/maven/seam/SeamLifecycleMapping.java (revision 0) @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.seam; + +import org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping; + +/** + * @author snjeza + */ +public class SeamLifecycleMapping extends AbstractCustomizableLifecycleMapping { + +} Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.jboss.tools.maven.seam;singleton:=true -Bundle-Version: 1.1.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Localization: plugin Bundle-Activator: org.jboss.tools.maven.seam.MavenSeamActivator Require-Bundle: org.eclipse.ui, @@ -13,7 +13,6 @@ org.jboss.tools.seam.core, org.jboss.tools.seam.ui, org.jboss.tools.common.model, - org.maven.ide.eclipse.maven_model_edit;bundle-version="0.10.0";visibility:=reexport, org.eclipse.jst.j2ee.core, org.eclipse.jst.j2ee, org.eclipse.wst.common.emfworkbench.integration, #P maven-site Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,14 +1,15 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom + maven 0.0.1-SNAPSHOT org.jboss.tools.maven - maven.site + maven.site maven.site 0.0.1-SNAPSHOT eclipse-update-site - + \ No newline at end of file #P org.jboss.tools.maven.core Index: src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderInstallOperation.java =================================================================== --- src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderInstallOperation.java (revision 32782) +++ src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderInstallOperation.java (working copy) @@ -1,110 +1,142 @@ -package org.jboss.tools.maven.core.libprov; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.ecore.resource.URIConverter; -import org.eclipse.emf.ecore.xmi.XMIResource; -import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperation; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectBase; -import org.jboss.tools.maven.core.MavenCoreActivator; -import org.maven.ide.components.pom.Model; -import org.maven.ide.components.pom.util.PomResourceImpl; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.embedder.MavenModelManager; - -public class MavenLibraryProviderInstallOperation extends - LibraryProviderOperation { - - @Override - public void execute(LibraryProviderOperationConfig config, - IProgressMonitor monitor) throws CoreException { - IFacetedProjectBase facetedProject = config.getFacetedProject(); - IProject project = facetedProject.getProject(); - IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); - MavenLibraryProviderInstallOperationConfig mavenConfig = (MavenLibraryProviderInstallOperationConfig) config; - if (mavenConfig.getModel() == null) { - return; - } - if (pom.exists()) { - // JBoss Maven Integration facet has been executed - MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); - PomResourceImpl resource = modelManager.loadResource(pom); - Model projectModel = resource.getModel(); - Model libraryModel = mavenConfig.getModel(); - MavenCoreActivator.mergeModel(projectModel, libraryModel); - try { - Map options = new HashMap(); - options.put(XMIResource.OPTION_ENCODING, MavenCoreActivator.ENCODING); - resource.save(options); - } catch (IOException e) { - MavenCoreActivator.log(e); - } finally { - resource.unload(); - } - ILibraryProvider provider = config.getLibraryProvider(); - File providerFile = MavenCoreActivator.getProviderFile(provider); - URL url = null; - PomResourceImpl libraryResource = null; - URIConverter.WriteableOutputStream uws = null; - FileWriter fw = null; - try { - Map params = provider.getParams(); - String pomURLString = params.get("template"); //$NON-NLS-1$ - URL platformURL = new URL(pomURLString); - url = FileLocator.resolve(platformURL); - - libraryResource = MavenCoreActivator.loadResource(url); - libraryResource.getContents().clear(); - libraryResource.getContents().add(libraryModel); - - Map options = new HashMap(); - options.put(XMIResource.OPTION_ENCODING, - MavenCoreActivator.ENCODING); - fw = new FileWriter(providerFile); - uws = new URIConverter.WriteableOutputStream( - fw, MavenCoreActivator.ENCODING); - libraryResource.save(uws, options); - } catch (IOException e) { - MavenCoreActivator.log(e); - } finally { - if (uws != null) { - try { - uws.flush(); - uws.close(); - } catch (IOException e) { - MavenCoreActivator.log(e); - } - } - if (fw != null) { - try { - fw.close(); - } catch (IOException e) { - MavenCoreActivator.log(e); - } - } - if (libraryResource != null) { - libraryResource.unload(); - } - } - - } else { - MavenCoreActivator.addLibraryProviderOperationConfig(config); - } - - } - - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core.libprov; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.URIConverter; +import org.eclipse.emf.ecore.xmi.XMIResource; +import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperation; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl; +import org.eclipse.m2e.model.edit.pom.util.PomResourceImpl; +import org.eclipse.wst.common.project.facet.core.IFacetedProjectBase; +import org.jboss.tools.maven.core.MavenCoreActivator; + +/** + * @author snjeza + * + */ +public class MavenLibraryProviderInstallOperation extends + LibraryProviderOperation { + + @Override + public void execute(LibraryProviderOperationConfig config, + IProgressMonitor monitor) throws CoreException { + IFacetedProjectBase facetedProject = config.getFacetedProject(); + IProject project = facetedProject.getProject(); + IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); + MavenLibraryProviderInstallOperationConfig mavenConfig = (MavenLibraryProviderInstallOperationConfig) config; + if (mavenConfig.getModel() == null) { + return; + } + if (pom.exists()) { + // JBoss Maven Integration facet has been executed + //MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); + PomResourceImpl resource = loadResource(pom); + Model projectModel = resource.getModel(); + Model libraryModel = mavenConfig.getModel(); + MavenCoreActivator.mergeModel(projectModel, libraryModel); + try { + Map options = new HashMap(); + options.put(XMIResource.OPTION_ENCODING, MavenCoreActivator.ENCODING); + resource.save(options); + } catch (IOException e) { + MavenCoreActivator.log(e); + } finally { + resource.unload(); + } + ILibraryProvider provider = config.getLibraryProvider(); + File providerFile = MavenCoreActivator.getProviderFile(provider); + URL url = null; + PomResourceImpl libraryResource = null; + URIConverter.WriteableOutputStream uws = null; + FileWriter fw = null; + try { + Map params = provider.getParams(); + String pomURLString = params.get("template"); //$NON-NLS-1$ + URL platformURL = new URL(pomURLString); + url = FileLocator.resolve(platformURL); + + libraryResource = MavenCoreActivator.loadResource(url); + libraryResource.getContents().clear(); + libraryResource.getContents().add(libraryModel); + + Map options = new HashMap(); + options.put(XMIResource.OPTION_ENCODING, + MavenCoreActivator.ENCODING); + fw = new FileWriter(providerFile); + uws = new URIConverter.WriteableOutputStream( + fw, MavenCoreActivator.ENCODING); + libraryResource.save(uws, options); + } catch (IOException e) { + MavenCoreActivator.log(e); + } finally { + if (uws != null) { + try { + uws.flush(); + uws.close(); + } catch (IOException e) { + MavenCoreActivator.log(e); + } + } + if (fw != null) { + try { + fw.close(); + } catch (IOException e) { + MavenCoreActivator.log(e); + } + } + if (libraryResource != null) { + libraryResource.unload(); + } + } + + } else { + MavenCoreActivator.addLibraryProviderOperationConfig(config); + } + } + + public static PomResourceImpl loadResource(IFile pomFile) + throws CoreException { + String path = pomFile.getFullPath().toOSString(); + URI uri = URI.createPlatformResourceURI(path, true); + try { + Resource resource = new PomResourceFactoryImpl() + .createResource(uri); + resource.load(new HashMap()); + return (PomResourceImpl) resource; + + } catch (Exception ex) { + String msg = "Can't load model " + pomFile; + MavenCoreActivator.log(ex); + throw new CoreException(new Status(IStatus.ERROR, + MavenCoreActivator.PLUGIN_ID, -1, msg, ex)); + } + } +} Index: src/org/jboss/tools/maven/core/MavenCoreActivator.java =================================================================== --- src/org/jboss/tools/maven/core/MavenCoreActivator.java (revision 32782) +++ src/org/jboss/tools/maven/core/MavenCoreActivator.java (working copy) @@ -1,781 +1,765 @@ -package org.jboss.tools.maven.core; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; - -import org.apache.maven.model.Build; -import org.apache.maven.model.Model; -import org.apache.maven.model.Resource; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -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.Plugin; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jdt.core.IClasspathAttribute; -import org.eclipse.jdt.core.IClasspathContainer; -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.jdt.launching.JavaRuntime; -import org.eclipse.jst.common.project.facet.JavaFacetUtils; -import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; -import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; -import org.maven.ide.components.pom.Dependency; -import org.maven.ide.components.pom.PomFactory; -import org.maven.ide.components.pom.PropertyElement; -import org.maven.ide.components.pom.Repository; -import org.maven.ide.components.pom.util.PomResourceFactoryImpl; -import org.maven.ide.components.pom.util.PomResourceImpl; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.embedder.IMavenConfiguration; -import org.maven.ide.eclipse.embedder.MavenModelManager; -import org.maven.ide.eclipse.jdt.BuildPathManager; -import org.maven.ide.eclipse.project.IProjectConfigurationManager; -import org.maven.ide.eclipse.project.ResolverConfiguration; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class MavenCoreActivator extends Plugin { - - public static final String SEPARATOR = "/"; //$NON-NLS-1$ - - // The plug-in ID - public static final String PLUGIN_ID = "org.jboss.tools.maven.core"; //$NON-NLS-1$ - - public static final String OWNER_PROJECT_FACETS_ATTR = "owner.project.facets"; //$NON-NLS-1$ - - public static final String BASEDIR = "${basedir}"; //$NON-NLS-1$ - - public static final String ENCODING = "UTF-8"; //$NON-NLS-1$ - - public static final List libraryProviderOperationConfigs = new ArrayList(); - - // The shared instance - private static MavenCoreActivator plugin; - - private static PomResourceImpl resource; - - /** - * The constructor - */ - public MavenCoreActivator() { - } - - /* - * (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); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static MavenCoreActivator getDefault() { - return plugin; - } - - public static IStatus getStatus(String message) { - return new Status(IStatus.ERROR, PLUGIN_ID, message); - - } - - public static IStatus getStatus(String message, Throwable e) { - return new Status(IStatus.ERROR, PLUGIN_ID, message,e); - } - - public static IProject createMavenProject(String projectName, IProgressMonitor monitor, Model model, boolean force) throws CoreException { - return createMavenProject(projectName, monitor, model, force, null); - } - - public static IProject createMavenProject(String projectName, IProgressMonitor monitor, Model model, boolean force, IPath location) throws CoreException { - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IProject project = root.getProject(projectName); - if (project.exists() && !force ) { - return project; - } - if (!project.exists()) { - if (location != null) { - IPath workspacePath = project.getWorkspace().getRoot().getLocation(); - location = location.makeRelativeTo(workspacePath); - if (projectName.equals(location.toString())) { - project.create(monitor); - } else { - IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName()); - desc.setLocation(location); - project.create(desc, monitor); - } - } else { - project.create(monitor); - } - project.open(monitor); - } - IJavaProject javaProject = JavaCore.create(project); - IProjectDescription description = project.getDescription(); - String[] natureIds = description.getNatureIds(); - boolean hasJavaNature = false; - for (int i = 0; i < natureIds.length; i++) { - if (JavaCore.NATURE_ID.equals(natureIds[i])) { - hasJavaNature = true; - break; - } - } - if (!hasJavaNature) { - // EAR project - createFolder("target",monitor, project); //$NON-NLS-1$ - IFolder binFolder = createFolder("target/classes",monitor, project); //$NON-NLS-1$ - String[] newNatureIds = new String[natureIds.length + 1]; - for (int i = 0; i < natureIds.length; i++) { - newNatureIds[i]=natureIds[i]; - } - newNatureIds[natureIds.length] = JavaCore.NATURE_ID; - description.setNatureIds(newNatureIds); - project.setDescription(description, monitor); - javaProject.setRawClasspath(new IClasspathEntry[0], monitor); - javaProject.setOutputLocation(binFolder.getFullPath(), monitor); - IClasspathEntry entry = JavaRuntime.getDefaultJREContainerEntry(); - IClasspathEntry[] entries = javaProject.getRawClasspath(); - IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; - System.arraycopy(entries, 0, newEntries, 0, entries.length); - newEntries[entries.length] = entry; - javaProject.setRawClasspath(newEntries, monitor); - } - if (FacetedProjectFramework.hasProjectFacet(project, IJ2EEFacetConstants.ENTERPRISE_APPLICATION)) { - String sourceDirectory = getSourceDirectory(javaProject); - if (sourceDirectory == null || sourceDirectory.trim().length() <= 0) { - IVirtualComponent component = ComponentCore.createComponent(project); - IVirtualFolder rootVFolder = component.getRootFolder(); - IContainer rootFolder = rootVFolder.getUnderlyingFolder(); - IPath path = rootFolder.getFullPath(); - IClasspathEntry[] entries = javaProject.getRawClasspath(); - IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; - System.arraycopy(entries, 0, newEntries, 0, entries.length); - newEntries[entries.length] = JavaCore.newSourceEntry(path); - javaProject.setRawClasspath(newEntries, monitor); - } - } - addMavenCapabilities(project, monitor, model); - return project; - } - - public static void addMavenCapabilities(IProject project, IProgressMonitor monitor, Model model) throws CoreException { - IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); - if (!pom.exists() && model != null) { - MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); - modelManager.createMavenModel(pom, model); - } - - boolean hasMavenNature = MavenCoreActivator.addMavenNature(project, monitor); - boolean hasJavaNature = project.hasNature(JavaCore.NATURE_ID); - if (!hasMavenNature && hasJavaNature) { - IClasspathAttribute attribute = JavaCore.newClasspathAttribute( - MavenCoreActivator.OWNER_PROJECT_FACETS_ATTR, - IJBossMavenConstants.M2_FACET_ID); - IJavaProject javaProject = JavaCore.create(project); - MavenCoreActivator.addClasspathAttribute(javaProject, attribute, monitor); - MavenCoreActivator.updateMavenProjectConfiguration(project); - } - } - - private static IFolder createFolder(String folderName,IProgressMonitor monitor, - IProject project) throws CoreException { - IFolder folder = project.getFolder(folderName); - folder.create(false, true, monitor); - return folder; - } - - public static boolean addMavenNature(IProject project, - IProgressMonitor monitor) throws CoreException { - boolean hasMavenNature = project.hasNature(IMavenConstants.NATURE_ID); - if (!hasMavenNature) { - IProjectDescription description = project.getDescription(); - String[] prevNatures = description.getNatureIds(); - String[] newNatures = new String[prevNatures.length + 1]; - System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length); - newNatures[0] = IMavenConstants.NATURE_ID; - description.setNatureIds(newNatures); - project.setDescription(description, monitor); - } - boolean hasJavaNature = project.hasNature(JavaCore.NATURE_ID); - if (hasJavaNature) { - IJavaProject javaProject = JavaCore.create(project); - IClasspathContainer mavenContainer = BuildPathManager - .getMaven2ClasspathContainer(javaProject); - if (mavenContainer == null) { - IPath path = new Path(BuildPathManager.CONTAINER_ID); - setContainerPath(monitor, javaProject, path); - } - } - return hasMavenNature; - } - - public static String getSourceDirectory(IJavaProject javaProject) throws JavaModelException { - IClasspathEntry[] entries = javaProject.getRawClasspath(); - IPath path = null; - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { - path = entries[i].getPath(); - break; - } - } - if (path == null) { - return null; - } - path = path.makeRelativeTo(javaProject.getPath()); - String value = path.toString(); - if (value.startsWith(SEPARATOR)) { - return BASEDIR + path.toString(); - } else { - return BASEDIR + SEPARATOR + path.toString(); - } - } - - public static void addClasspathAttribute(IJavaProject javaProject, - IClasspathAttribute attribute, IProgressMonitor monitor) throws JavaModelException { - IClasspathEntry[] cp = javaProject.getRawClasspath(); - for (int i = 0; i < cp.length; i++) { - if (IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind() - && BuildPathManager.isMaven2ClasspathContainer(cp[i] - .getPath())) { - LinkedHashMap attrs = new LinkedHashMap(); - for (IClasspathAttribute attr : cp[i].getExtraAttributes()) { - attrs.put(attr.getName(), attr); - } - attrs.put(attribute.getName(), attribute); - IClasspathAttribute[] newAttrs = attrs.values().toArray( - new IClasspathAttribute[attrs.size()]); - cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i] - .getAccessRules(), newAttrs, cp[i].isExported()); - break; - } - } - javaProject.setRawClasspath(cp, monitor); - - } - - public static void setContainerPath(IProgressMonitor monitor, - IJavaProject javaProject, IPath containerPath) throws CoreException { - IClasspathEntry entry = JavaCore - .newContainerEntry(containerPath, false); - IClasspathEntry[] entries = javaProject.getRawClasspath(); - IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; - System.arraycopy(entries, 0, newEntries, 0, entries.length); - newEntries[entries.length] = entry; - javaProject.setRawClasspath(newEntries, monitor); - } - - public static void updateMavenProjectConfiguration(IProject project) - throws CoreException { - ResolverConfiguration resolverConfiguration = new ResolverConfiguration(); - //resolverConfiguration.setIncludeModules(false); - // FIXME - resolverConfiguration.setResolveWorkspaceProjects(true); - resolverConfiguration.setActiveProfiles(""); //$NON-NLS-1$ - IProjectConfigurationManager configurationManager = MavenPlugin - .getDefault().getProjectConfigurationManager(); - //IMavenConfiguration mavenConfiguration = MavenPlugin.lookup(IMavenConfiguration.class); - //IMavenConfiguration mavenConfiguration = MavenPlugin.getDefault().getMavenConfiguration(); - IMavenConfiguration mavenConfiguration = getMavenConfiguration(); - - configurationManager.updateProjectConfiguration(project, - resolverConfiguration, mavenConfiguration.getGoalOnUpdate(), - new NullProgressMonitor()); - } - - private static IMavenConfiguration getMavenConfiguration() { - Class clazz = MavenPlugin.class; - try { - Method method = clazz.getMethod ("getMavenConfiguration", new Class[0]); //$NON-NLS-1$ - Object configuration = method.invoke (MavenPlugin.getDefault(), new Object[0]); - return (IMavenConfiguration) configuration; - } catch (SecurityException e) { - log(e); - } catch (NoSuchMethodException e) { - try { - Method method = clazz.getMethod ("lookup", new Class[] {Class.class}); //$NON-NLS-1$ - Object configuration = method.invoke (null, new Object[] {IMavenConfiguration.class}); - return (IMavenConfiguration) configuration; - } catch (SecurityException e1) { - log(e1); - } catch (IllegalArgumentException e1) { - log(e1); - } catch (NoSuchMethodException e1) { - log(e1); - } catch (IllegalAccessException e1) { - log(e1); - } catch (InvocationTargetException e1) { - log(e1); - } - } catch (IllegalArgumentException e) { - log(e); - } catch (IllegalAccessException e) { - log(e); - } catch (InvocationTargetException e) { - log(e); - } - return null; - } - - public static void addMavenWarPlugin(Build build, IProject project) throws JavaModelException { - org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); - plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ - plugin.setArtifactId("maven-war-plugin"); //$NON-NLS-1$ - - Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ - IVirtualComponent component = ComponentCore.createComponent(project); - IVirtualFolder rootFolder = component.getRootFolder(); - IContainer root = rootFolder.getUnderlyingFolder(); - String webContentRoot = root.getProjectRelativePath().toString(); - Xpp3Dom warSourceDirectory = new Xpp3Dom("warSourceDirectory"); //$NON-NLS-1$ - if (webContentRoot.startsWith(SEPARATOR)) { - warSourceDirectory.setValue(MavenCoreActivator.BASEDIR + webContentRoot); - } else { - warSourceDirectory.setValue(MavenCoreActivator.BASEDIR + SEPARATOR + webContentRoot); - } - - configuration.addChild(warSourceDirectory); - plugin.setConfiguration(configuration); - build.getPlugins().add(plugin); - - addResource(build, project, null); - } - - public static void addResource(Build build, IProject project, String sourceDirectory) - throws JavaModelException { - Resource resource = new Resource(); - if (sourceDirectory == null) { - IJavaProject javaProject = JavaCore.create(project); - if (javaProject != null && javaProject.exists()) { - sourceDirectory = getSourceDirectory(javaProject); - } - } - if (sourceDirectory != null) { - resource.setDirectory(sourceDirectory); - List excludes = new ArrayList(); - excludes.add("**/*.java"); //$NON-NLS-1$ - resource.setExcludes(excludes); - } - build.getResources().add(resource); - } - - public static void addMavenEarPlugin(Build build, IProject project, IDataModel m2FacetModel, String ejbArtifactId, boolean addModule) throws JavaModelException { - String sourceDirectory = getEarRoot(project); - build.setSourceDirectory(sourceDirectory); - org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); - plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ - plugin.setArtifactId("maven-ear-plugin"); //$NON-NLS-1$ - - Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ - Xpp3Dom version = new Xpp3Dom("version"); //$NON-NLS-1$ - version.setValue("5"); //$NON-NLS-1$ - configuration.addChild(version); - Xpp3Dom generateApplicationXml = new Xpp3Dom("generateApplicationXml"); //$NON-NLS-1$ - generateApplicationXml.setValue("true"); //$NON-NLS-1$ - configuration.addChild(generateApplicationXml); - Xpp3Dom defaultLibBundleDir = new Xpp3Dom("defaultLibBundleDir"); //$NON-NLS-1$ - defaultLibBundleDir.setValue("lib"); //$NON-NLS-1$ - configuration.addChild(defaultLibBundleDir); - Xpp3Dom earSourceDirectory = new Xpp3Dom("earSourceDirectory"); //$NON-NLS-1$ - earSourceDirectory.setValue(sourceDirectory); - configuration.addChild(earSourceDirectory); - - if (addModule) { - Xpp3Dom modules = new Xpp3Dom("modules"); //$NON-NLS-1$ - configuration.addChild(modules); - - if (ejbArtifactId != null) { - String ejbModuleName = ejbArtifactId + ".jar"; //$NON-NLS-1$ - Xpp3Dom ejbProject = getEarModule( - "ejbModule", //$NON-NLS-1$ - m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID), - ejbArtifactId, "/", ejbModuleName); //$NON-NLS-1$ - modules.addChild(ejbProject); - } - - Xpp3Dom seamModule = getEarModule("ejbModule", "org.jboss.seam", //$NON-NLS-1$ //$NON-NLS-2$ - "jboss-seam", "/", null); //$NON-NLS-1$ //$NON-NLS-2$ - modules.addChild(seamModule); - - String webModuleName = m2FacetModel.getStringProperty(IJBossMavenConstants.ARTIFACT_ID) + ".war"; //$NON-NLS-1$ - - Xpp3Dom webProject = getEarModule( - "webModule", //$NON-NLS-1$ - m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID), - m2FacetModel.getStringProperty(IJBossMavenConstants.ARTIFACT_ID), - "/", webModuleName); //$NON-NLS-1$ - Xpp3Dom contextRoot = new Xpp3Dom("contextRoot"); //$NON-NLS-1$ - contextRoot.setValue(m2FacetModel - .getStringProperty(IJBossMavenConstants.ARTIFACT_ID)); - webProject.addChild(contextRoot); - modules.addChild(webProject); - - Xpp3Dom richFacesApi = getEarModule("jarModule", //$NON-NLS-1$ - "org.richfaces.framework", "richfaces-api", "/lib", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - modules.addChild(richFacesApi); - - Xpp3Dom commonDigester = getEarModule("jarModule", //$NON-NLS-1$ - "commons-digester", "commons-digester", "/lib", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - modules.addChild(commonDigester); - - //Xpp3Dom mvel14 = getEarModule("jarModule", //$NON-NLS-1$ - // "org.mvel", "mvel14", "/", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - //modules.addChild(mvel14); - } - plugin.setConfiguration(configuration); - - build.getPlugins().add(plugin); - - addResource(build, project, sourceDirectory); - } - - private static Xpp3Dom getEarModule(String module, - String groupIdString,String artifactIdString, String bundleDirString, String bundleFileNameString) { - Xpp3Dom earModule = new Xpp3Dom(module); - //modules.addChild(earModule); - Xpp3Dom groupId = new Xpp3Dom("groupId"); //$NON-NLS-1$ - groupId.setValue(groupIdString); - earModule.addChild(groupId); - Xpp3Dom artifactId = new Xpp3Dom("artifactId"); //$NON-NLS-1$ - artifactId.setValue(artifactIdString); - earModule.addChild(artifactId); - Xpp3Dom bundleDir = new Xpp3Dom("bundleDir"); //$NON-NLS-1$ - bundleDir.setValue(bundleDirString); - earModule.addChild(bundleDir); - if (bundleFileNameString != null) { - Xpp3Dom bundleFileName = new Xpp3Dom("bundleFileName"); //$NON-NLS-1$ - bundleFileName.setValue(bundleFileNameString); - earModule.addChild(bundleFileName); - - } - return earModule; - } - - public static void addMavenEjbPlugin(Build build, IProject project) throws JavaModelException { - org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); - plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ - plugin.setArtifactId("maven-ejb-plugin"); //$NON-NLS-1$ - plugin.setInherited("true"); //$NON-NLS-1$ - - Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ - Xpp3Dom ejbVersion = new Xpp3Dom("ejbVersion"); //$NON-NLS-1$ - ejbVersion.setValue("3.0"); //$NON-NLS-1$ - configuration.addChild(ejbVersion); - plugin.setConfiguration(configuration); - build.getPlugins().add(plugin); - - addResource(build, project, null); - } - - public static String getOutputDirectory(IJavaProject javaProject) throws CoreException { - IPath path = javaProject.getOutputLocation(); - path = path.makeRelativeTo(javaProject.getPath()); - if (path == null) { - return null; - } - String value = path.toString(); - if (value.startsWith(SEPARATOR)) { - return MavenCoreActivator.BASEDIR + path.toString(); - } else { - return MavenCoreActivator.BASEDIR + SEPARATOR + path.toString(); - } - } - - public static String getEarRoot(IProject project) { - IVirtualComponent component = ComponentCore.createComponent(project); - IVirtualFolder rootFolder = component.getRootFolder(); - IContainer root = rootFolder.getUnderlyingFolder(); - String sourceDirectory = root.getProjectRelativePath().toString(); - return sourceDirectory; - } - - public static void mergeModel(org.maven.ide.components.pom.Model projectModel, org.maven.ide.components.pom.Model libraryModel) { - if (projectModel == null || libraryModel == null) { - return; - } - addProperties(projectModel,libraryModel); - addRepositories(projectModel,libraryModel); - addPlugins(projectModel,libraryModel); - addDependencies(projectModel,libraryModel); - } - - private static void addDependencies(org.maven.ide.components.pom.Model projectModel, org.maven.ide.components.pom.Model libraryModel) { - List projectDependencies = projectModel.getDependencies(); - List libraryDependencies = libraryModel.getDependencies(); - for (Dependency dependency:libraryDependencies) { - if (!dependencyExists(dependency,projectDependencies)) { - Dependency newDependency = (Dependency) EcoreUtil.copy(dependency); - projectDependencies.add(newDependency); - } - } - - } - - private static boolean dependencyExists(Dependency dependency, - List projectDependencies) { - String groupId = dependency.getGroupId(); - String artifactId = dependency.getArtifactId(); - if (artifactId == null) { - return false; - } - for (Dependency projectDependency:projectDependencies) { - String projectGroupId = projectDependency.getGroupId(); - String projectArtifactId = projectDependency.getArtifactId(); - if (!artifactId.equals(projectArtifactId)) { - return false; - } - if (groupId == null && projectGroupId == null) { - return true; - } - if (groupId != null && groupId.equals(projectGroupId)) { - return true; - } - } - return false; - } - - private static void addPlugins(org.maven.ide.components.pom.Model projectModel, org.maven.ide.components.pom.Model libraryModel) { - org.maven.ide.components.pom.Build libraryBuild = libraryModel.getBuild(); - if (libraryBuild == null) { - return; - } - List libraryPlugins = projectModel.getBuild().getPlugins(); - for (org.maven.ide.components.pom.Plugin plugin:libraryPlugins) { - org.maven.ide.components.pom.Build projectBuild = projectModel.getBuild(); - if (projectBuild == null) { - projectBuild = PomFactory.eINSTANCE.createBuild(); - projectModel.setBuild(projectBuild); - } - List projectPlugins = projectBuild.getPlugins(); - if (!pluginExists(plugin,projectPlugins)) { - org.maven.ide.components.pom.Plugin newPlugin = (org.maven.ide.components.pom.Plugin) EcoreUtil.copy(plugin); - projectPlugins.add(newPlugin); - } - } - } - - private static boolean pluginExists(org.maven.ide.components.pom.Plugin plugin, List projectPlugins) { - String groupId = plugin.getGroupId(); - String artifactId = plugin.getArtifactId(); - if (artifactId == null) { - return false; - } - for (org.maven.ide.components.pom.Plugin projectPlugin:projectPlugins) { - String projectGroupId = projectPlugin.getGroupId(); - String projectArtifactId = projectPlugin.getArtifactId(); - if (!artifactId.equals(projectArtifactId)) { - return false; - } - if (groupId == null && projectGroupId == null) { - return true; - } - if (groupId != null && groupId.equals(projectGroupId)) { - return true; - } - } - return false; - } - - private static void addRepositories(org.maven.ide.components.pom.Model projectModel, org.maven.ide.components.pom.Model libraryModel) { - List projectRepositories = projectModel.getRepositories(); - List libraryRepositories = libraryModel.getRepositories(); - for (Repository repository:libraryRepositories) { - if (!repositoryExists(repository,projectRepositories)) { - Repository newRepository = (Repository) EcoreUtil.copy(repository); - projectRepositories.add(newRepository); - } - } - } - - private static boolean repositoryExists(Repository repository, - List projectRepositories) { - String url = repository.getUrl(); - if (url == null) { - return false; - } - for(Repository projectRepository:projectRepositories) { - if (url.equals(projectRepository.getUrl())) { - return true; - } - } - return false; - } - - private static void addProperties(org.maven.ide.components.pom.Model projectModel, org.maven.ide.components.pom.Model libraryModel) { - List projectProperties = projectModel.getProperties(); - List libraryProperties = libraryModel.getProperties(); - for (PropertyElement libraryProperty:libraryProperties) { - String propertyName = libraryProperty.getName(); - if (!propertyExists(propertyName,projectProperties)) { - PropertyElement newProperty = (PropertyElement) EcoreUtil.copy(libraryProperty); - projectProperties.add(newProperty); - } - } - } - - private static boolean propertyExists(String propertyName, - List projectProperties) { - if (propertyName == null) { - return false; - } - for (PropertyElement propertyElement:projectProperties) { - if (propertyName.equals(propertyElement.getName())) { - return true; - } - } - return false; - } - - public static void log(Throwable e) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); - getDefault().getLog().log(status); - } - - public static void log(String message) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message); - getDefault().getLog().log(status); - } - - public static File getProviderFile(ILibraryProvider provider) { - String id = provider.getId(); - IPath providerDir = MavenCoreActivator.getDefault().getStateLocation().append(id); - File providerDirFile = providerDir.toFile(); - providerDirFile.mkdir(); - File providerFile = new File(providerDirFile, "template.xml"); //$NON-NLS-1$ - return providerFile; - } - - public static PomResourceImpl loadResource(URL url) throws CoreException { - try { - URI uri = URI.createURI(url.toString()); - if ( !( uri.isFile() || uri.isPlatformResource()) ) { - // the m2eclipse pom model can read only a file URL or platform resource URL - // see https://jira.jboss.org/jira/browse/JBIDE-4972 - InputStream is = null; - OutputStream os = null; - try { - File temp = File.createTempFile("mavenCoreActivator", ".pom"); //$NON-NLS-1$//$NON-NLS-2$ - temp.deleteOnExit(); - os = new FileOutputStream(temp); - is = url.openStream(); - copy(is,os); - URL tempURL = temp.toURL(); - uri = URI.createURI(tempURL.toString()); - } catch (Exception e) { - log(e); - throw new CoreException(new Status(IStatus.ERROR, - PLUGIN_ID, -1, e.getMessage(), e)); - } finally { - if (is != null) { - try { - is.close(); - } catch (Exception ignore) {} - } - if (os != null) { - try { - os.close(); - } catch (Exception ignore) {} - } - } - } - org.eclipse.emf.ecore.resource.Resource resource = new PomResourceFactoryImpl() - .createResource(uri); - resource.load(Collections.EMPTY_MAP); - return (PomResourceImpl) resource; - } catch (Exception ex) { - log(ex); - throw new CoreException(new Status(IStatus.ERROR, - PLUGIN_ID, -1, ex.getMessage(), ex)); - } - } - - private static void copy(InputStream is, OutputStream os) - throws IOException { - byte[] buffer = new byte[1024]; - int count; - while ( (count = is.read(buffer)) > 0) { - os.write(buffer,0,count); - } - } - - public static void addLibraryProviderOperationConfig( - LibraryProviderOperationConfig config) { - libraryProviderOperationConfigs.add(config); - } - - public static List getLibraryProviderOperationConfigs() { - return libraryProviderOperationConfigs; - } - - public static PomResourceImpl getResource() { - return resource; - } - - public static void setResource(PomResourceImpl resource2) { - resource = resource2; - } - - public static void addCompilerPlugin(Build build, IProject project) { - String compilerLevel = JavaFacetUtils.getCompilerLevel(project); - if (compilerLevel == null) { - return; - } - org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); - plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ - plugin.setArtifactId("maven-compiler-plugin"); //$NON-NLS-1$ - Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ - Xpp3Dom source = new Xpp3Dom("source"); //$NON-NLS-1$ - source.setValue(compilerLevel); //$NON-NLS-1$ - configuration.addChild(source); - Xpp3Dom target = new Xpp3Dom("target"); //$NON-NLS-1$ - target.setValue(compilerLevel); //$NON-NLS-1$ - configuration.addChild(target); - plugin.setConfiguration(configuration); - build.getPlugins().add(plugin); - } -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Model; +import org.apache.maven.model.Resource; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +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.Plugin; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathContainer; +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.jdt.launching.JavaRuntime; +import org.eclipse.jst.common.project.facet.JavaFacetUtils; +import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; +import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.MavenModelManager; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.project.IProjectConfigurationManager; +import org.eclipse.m2e.jdt.internal.BuildPathManager; +import org.eclipse.m2e.model.edit.pom.Dependency; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PropertyElement; +import org.eclipse.m2e.model.edit.pom.Repository; +import org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl; +import org.eclipse.m2e.model.edit.pom.util.PomResourceImpl; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; +import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class MavenCoreActivator extends Plugin { + + private static final String ROOT_DIR = "/"; //$NON-NLS-1$ + + public static final String SEPARATOR = "/"; //$NON-NLS-1$ + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.maven.core"; //$NON-NLS-1$ + + public static final String OWNER_PROJECT_FACETS_ATTR = "owner.project.facets"; //$NON-NLS-1$ + + public static final String BASEDIR = "${basedir}"; //$NON-NLS-1$ + + public static final String ENCODING = "UTF-8"; //$NON-NLS-1$ + + public static final List libraryProviderOperationConfigs = new ArrayList(); + + // The shared instance + private static MavenCoreActivator plugin; + + private static PomResourceImpl resource; + + /** + * The constructor + */ + public MavenCoreActivator() { + } + + /* + * (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); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static MavenCoreActivator getDefault() { + return plugin; + } + + public static IStatus getStatus(String message) { + return new Status(IStatus.ERROR, PLUGIN_ID, message); + + } + + public static IStatus getStatus(String message, Throwable e) { + return new Status(IStatus.ERROR, PLUGIN_ID, message,e); + } + + public static IProject createMavenProject(String projectName, IProgressMonitor monitor, Model model, boolean force) throws CoreException { + return createMavenProject(projectName, monitor, model, force, null); + } + + public static IProject createMavenProject(String projectName, IProgressMonitor monitor, Model model, boolean force, IPath location) throws CoreException { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject project = root.getProject(projectName); + if (project.exists() && !force ) { + return project; + } + if (!project.exists()) { + if (location != null) { + IPath workspacePath = project.getWorkspace().getRoot().getLocation(); + location = location.makeRelativeTo(workspacePath); + if (projectName.equals(location.toString())) { + project.create(monitor); + } else { + IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName()); + desc.setLocation(location); + project.create(desc, monitor); + } + } else { + project.create(monitor); + } + project.open(monitor); + } + IJavaProject javaProject = JavaCore.create(project); + IProjectDescription description = project.getDescription(); + String[] natureIds = description.getNatureIds(); + boolean hasJavaNature = false; + for (int i = 0; i < natureIds.length; i++) { + if (JavaCore.NATURE_ID.equals(natureIds[i])) { + hasJavaNature = true; + break; + } + } + if (!hasJavaNature) { + // EAR project + createFolder("target",monitor, project); //$NON-NLS-1$ + IFolder binFolder = createFolder("target/classes",monitor, project); //$NON-NLS-1$ + String[] newNatureIds = new String[natureIds.length + 1]; + for (int i = 0; i < natureIds.length; i++) { + newNatureIds[i]=natureIds[i]; + } + newNatureIds[natureIds.length] = JavaCore.NATURE_ID; + description.setNatureIds(newNatureIds); + project.setDescription(description, monitor); + javaProject.setRawClasspath(new IClasspathEntry[0], monitor); + javaProject.setOutputLocation(binFolder.getFullPath(), monitor); + IClasspathEntry entry = JavaRuntime.getDefaultJREContainerEntry(); + IClasspathEntry[] entries = javaProject.getRawClasspath(); + IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; + System.arraycopy(entries, 0, newEntries, 0, entries.length); + newEntries[entries.length] = entry; + javaProject.setRawClasspath(newEntries, monitor); + } + if (FacetedProjectFramework.hasProjectFacet(project, IJ2EEFacetConstants.ENTERPRISE_APPLICATION)) { + String sourceDirectory = getSourceDirectory(javaProject); + if (sourceDirectory == null || sourceDirectory.trim().length() <= 0) { + IVirtualComponent component = ComponentCore.createComponent(project); + IVirtualFolder rootVFolder = component.getRootFolder(); + IContainer rootFolder = rootVFolder.getUnderlyingFolder(); + IPath path = rootFolder.getFullPath(); + IClasspathEntry[] entries = javaProject.getRawClasspath(); + IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; + System.arraycopy(entries, 0, newEntries, 0, entries.length); + newEntries[entries.length] = JavaCore.newSourceEntry(path); + javaProject.setRawClasspath(newEntries, monitor); + } + } + addMavenCapabilities(project, monitor, model); + return project; + } + + public static void addMavenCapabilities(IProject project, IProgressMonitor monitor, Model model) throws CoreException { + IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); + if (!pom.exists() && model != null) { + MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); + modelManager.createMavenModel(pom, model); + } + + boolean hasMavenNature = MavenCoreActivator.addMavenNature(project, monitor); + boolean hasJavaNature = project.hasNature(JavaCore.NATURE_ID); + if (!hasMavenNature && hasJavaNature) { + IClasspathAttribute attribute = JavaCore.newClasspathAttribute( + MavenCoreActivator.OWNER_PROJECT_FACETS_ATTR, + IJBossMavenConstants.M2_FACET_ID); + IJavaProject javaProject = JavaCore.create(project); + MavenCoreActivator.addClasspathAttribute(javaProject, attribute, monitor); + MavenCoreActivator.updateMavenProjectConfiguration(project); + } + } + + private static IFolder createFolder(String folderName,IProgressMonitor monitor, + IProject project) throws CoreException { + IFolder folder = project.getFolder(folderName); + folder.create(false, true, monitor); + return folder; + } + + public static boolean addMavenNature(IProject project, + IProgressMonitor monitor) throws CoreException { + boolean hasMavenNature = project.hasNature(IMavenConstants.NATURE_ID); + if (!hasMavenNature) { + IProjectDescription description = project.getDescription(); + String[] prevNatures = description.getNatureIds(); + String[] newNatures = new String[prevNatures.length + 1]; + System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length); + newNatures[0] = IMavenConstants.NATURE_ID; + description.setNatureIds(newNatures); + project.setDescription(description, monitor); + } + boolean hasJavaNature = project.hasNature(JavaCore.NATURE_ID); + if (hasJavaNature) { + IJavaProject javaProject = JavaCore.create(project); + IClasspathContainer mavenContainer = BuildPathManager + .getMaven2ClasspathContainer(javaProject); + if (mavenContainer == null) { + IPath path = new Path(BuildPathManager.CONTAINER_ID); + setContainerPath(monitor, javaProject, path); + } + } + return hasMavenNature; + } + + public static String getSourceDirectory(IJavaProject javaProject) throws JavaModelException { + IClasspathEntry[] entries = javaProject.getRawClasspath(); + IPath path = null; + for (int i = 0; i < entries.length; i++) { + if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { + path = entries[i].getPath(); + break; + } + } + if (path == null) { + return null; + } + path = path.makeRelativeTo(javaProject.getPath()); + String value = path.toString(); + if (value.startsWith(SEPARATOR)) { + return BASEDIR + path.toString(); + } else { + return BASEDIR + SEPARATOR + path.toString(); + } + } + + public static void addClasspathAttribute(IJavaProject javaProject, + IClasspathAttribute attribute, IProgressMonitor monitor) throws JavaModelException { + IClasspathEntry[] cp = javaProject.getRawClasspath(); + for (int i = 0; i < cp.length; i++) { + if (IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind() + && BuildPathManager.CONTAINER_ID.equals(cp[i] + .getPath())) { + LinkedHashMap attrs = new LinkedHashMap(); + for (IClasspathAttribute attr : cp[i].getExtraAttributes()) { + attrs.put(attr.getName(), attr); + } + attrs.put(attribute.getName(), attribute); + IClasspathAttribute[] newAttrs = attrs.values().toArray( + new IClasspathAttribute[attrs.size()]); + cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i] + .getAccessRules(), newAttrs, cp[i].isExported()); + break; + } + } + javaProject.setRawClasspath(cp, monitor); + + } + + public static void setContainerPath(IProgressMonitor monitor, + IJavaProject javaProject, IPath containerPath) throws CoreException { + IClasspathEntry entry = JavaCore + .newContainerEntry(containerPath, false); + IClasspathEntry[] entries = javaProject.getRawClasspath(); + IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; + System.arraycopy(entries, 0, newEntries, 0, entries.length); + newEntries[entries.length] = entry; + javaProject.setRawClasspath(newEntries, monitor); + } + + public static void updateMavenProjectConfiguration(IProject project) + throws CoreException { + IProjectConfigurationManager configurationManager = MavenPlugin + .getDefault().getProjectConfigurationManager(); + configurationManager.updateProjectConfiguration(project, + new NullProgressMonitor()); + } + + public static void addMavenWarPlugin(Build build, IProject project) throws JavaModelException { + org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); + plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ + plugin.setArtifactId("maven-war-plugin"); //$NON-NLS-1$ + + Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ + IVirtualComponent component = ComponentCore.createComponent(project); + IVirtualFolder rootFolder = component.getRootFolder(); + IContainer root = rootFolder.getUnderlyingFolder(); + String webContentRoot = root.getProjectRelativePath().toString(); + Xpp3Dom warSourceDirectory = new Xpp3Dom("warSourceDirectory"); //$NON-NLS-1$ + if (webContentRoot.startsWith(SEPARATOR)) { + warSourceDirectory.setValue(MavenCoreActivator.BASEDIR + webContentRoot); + } else { + warSourceDirectory.setValue(MavenCoreActivator.BASEDIR + SEPARATOR + webContentRoot); + } + + configuration.addChild(warSourceDirectory); + plugin.setConfiguration(configuration); + build.getPlugins().add(plugin); + + addResource(build, project, null); + } + + public static void addResource(Build build, IProject project, String sourceDirectory) + throws JavaModelException { + Resource resource = new Resource(); + if (sourceDirectory == null) { + IJavaProject javaProject = JavaCore.create(project); + if (javaProject != null && javaProject.exists()) { + sourceDirectory = getSourceDirectory(javaProject); + } + } + if (sourceDirectory != null) { + resource.setDirectory(sourceDirectory); + List excludes = new ArrayList(); + excludes.add("**/*.java"); //$NON-NLS-1$ + resource.setExcludes(excludes); + } + build.getResources().add(resource); + } + + public static void addMavenEarPlugin(Build build, IProject project, IDataModel m2FacetModel, String ejbArtifactId, boolean addModule) throws JavaModelException { + String sourceDirectory = getEarRoot(project); + build.setSourceDirectory(sourceDirectory); + org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); + plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ + plugin.setArtifactId("maven-ear-plugin"); //$NON-NLS-1$ + + Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ + Xpp3Dom version = new Xpp3Dom("version"); //$NON-NLS-1$ + version.setValue("5"); //$NON-NLS-1$ + configuration.addChild(version); + Xpp3Dom generateApplicationXml = new Xpp3Dom("generateApplicationXml"); //$NON-NLS-1$ + generateApplicationXml.setValue("true"); //$NON-NLS-1$ + configuration.addChild(generateApplicationXml); + Xpp3Dom defaultLibBundleDir = new Xpp3Dom("defaultLibBundleDir"); //$NON-NLS-1$ + defaultLibBundleDir.setValue("lib"); //$NON-NLS-1$ + configuration.addChild(defaultLibBundleDir); + Xpp3Dom earSourceDirectory = new Xpp3Dom("earSourceDirectory"); //$NON-NLS-1$ + earSourceDirectory.setValue(sourceDirectory); + configuration.addChild(earSourceDirectory); + + if (addModule) { + Xpp3Dom modules = new Xpp3Dom("modules"); //$NON-NLS-1$ + configuration.addChild(modules); + + Xpp3Dom seamModule = getEarModule("ejbModule", "org.jboss.seam", //$NON-NLS-1$ //$NON-NLS-2$ + "jboss-seam", ROOT_DIR, null); //$NON-NLS-1$ //$NON-NLS-2$ + modules.addChild(seamModule); + + if (ejbArtifactId != null) { + String ejbModuleName = ejbArtifactId + ".jar"; //$NON-NLS-1$ + Xpp3Dom ejbProject = getEarModule( + "ejbModule", //$NON-NLS-1$ + m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID), + ejbArtifactId, ROOT_DIR, ejbModuleName); //$NON-NLS-1$ + modules.addChild(ejbProject); + } + + String webModuleName = m2FacetModel.getStringProperty(IJBossMavenConstants.ARTIFACT_ID) + ".war"; //$NON-NLS-1$ + + Xpp3Dom webProject = getEarModule( + "webModule", //$NON-NLS-1$ + m2FacetModel.getStringProperty(IJBossMavenConstants.GROUP_ID), + m2FacetModel.getStringProperty(IJBossMavenConstants.ARTIFACT_ID), + ROOT_DIR, webModuleName); //$NON-NLS-1$ + Xpp3Dom contextRoot = new Xpp3Dom("contextRoot"); //$NON-NLS-1$ + contextRoot.setValue(m2FacetModel + .getStringProperty(IJBossMavenConstants.ARTIFACT_ID)); + webProject.addChild(contextRoot); + modules.addChild(webProject); + + Xpp3Dom richFacesApi = getEarModule("jarModule", //$NON-NLS-1$ + "org.richfaces.framework", "richfaces-api", "/lib", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + modules.addChild(richFacesApi); + + Xpp3Dom commonDigester = getEarModule("jarModule", //$NON-NLS-1$ + "commons-digester", "commons-digester", "/lib", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + modules.addChild(commonDigester); + + //Xpp3Dom mvel14 = getEarModule("jarModule", //$NON-NLS-1$ + // "org.mvel", "mvel14", "/", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + //modules.addChild(mvel14); + } + plugin.setConfiguration(configuration); + + build.getPlugins().add(plugin); + + addResource(build, project, sourceDirectory); + } + + private static Xpp3Dom getEarModule(String module, + String groupIdString,String artifactIdString, String bundleDirString, String bundleFileNameString) { + Xpp3Dom earModule = new Xpp3Dom(module); + //modules.addChild(earModule); + Xpp3Dom groupId = new Xpp3Dom("groupId"); //$NON-NLS-1$ + groupId.setValue(groupIdString); + earModule.addChild(groupId); + Xpp3Dom artifactId = new Xpp3Dom("artifactId"); //$NON-NLS-1$ + artifactId.setValue(artifactIdString); + earModule.addChild(artifactId); + if (!ROOT_DIR.equals(bundleDirString)) { + Xpp3Dom bundleDir = new Xpp3Dom("bundleDir"); //$NON-NLS-1$ + bundleDir.setValue(bundleDirString); + earModule.addChild(bundleDir); + } + if (bundleFileNameString != null) { + Xpp3Dom bundleFileName = new Xpp3Dom("bundleFileName"); //$NON-NLS-1$ + bundleFileName.setValue(bundleFileNameString); + earModule.addChild(bundleFileName); + + } + return earModule; + } + + public static void addMavenEjbPlugin(Build build, IProject project) throws JavaModelException { + org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); + plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ + plugin.setArtifactId("maven-ejb-plugin"); //$NON-NLS-1$ + plugin.setInherited("true"); //$NON-NLS-1$ + + Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ + Xpp3Dom ejbVersion = new Xpp3Dom("ejbVersion"); //$NON-NLS-1$ + ejbVersion.setValue("3.0"); //$NON-NLS-1$ + configuration.addChild(ejbVersion); + plugin.setConfiguration(configuration); + build.getPlugins().add(plugin); + + addResource(build, project, null); + } + + public static String getOutputDirectory(IJavaProject javaProject) throws CoreException { + IPath path = javaProject.getOutputLocation(); + path = path.makeRelativeTo(javaProject.getPath()); + if (path == null) { + return null; + } + String value = path.toString(); + if (value.startsWith(SEPARATOR)) { + return MavenCoreActivator.BASEDIR + path.toString(); + } else { + return MavenCoreActivator.BASEDIR + SEPARATOR + path.toString(); + } + } + + public static String getEarRoot(IProject project) { + IVirtualComponent component = ComponentCore.createComponent(project); + IVirtualFolder rootFolder = component.getRootFolder(); + IContainer root = rootFolder.getUnderlyingFolder(); + String sourceDirectory = root.getProjectRelativePath().toString(); + return sourceDirectory; + } + + public static void mergeModel(org.eclipse.m2e.model.edit.pom.Model projectModel, org.eclipse.m2e.model.edit.pom.Model libraryModel) { + if (projectModel == null || libraryModel == null) { + return; + } + addProperties(projectModel,libraryModel); + addRepositories(projectModel,libraryModel); + addPlugins(projectModel,libraryModel); + addDependencies(projectModel,libraryModel); + } + + private static void addDependencies(org.eclipse.m2e.model.edit.pom.Model projectModel, org.eclipse.m2e.model.edit.pom.Model libraryModel) { + List projectDependencies = projectModel.getDependencies(); + List libraryDependencies = libraryModel.getDependencies(); + for (Dependency dependency:libraryDependencies) { + if (!dependencyExists(dependency,projectDependencies)) { + Dependency newDependency = (Dependency) EcoreUtil.copy(dependency); + projectDependencies.add(newDependency); + } + } + + } + + private static boolean dependencyExists(Dependency dependency, + List projectDependencies) { + String groupId = dependency.getGroupId(); + String artifactId = dependency.getArtifactId(); + if (artifactId == null) { + return false; + } + for (Dependency projectDependency:projectDependencies) { + String projectGroupId = projectDependency.getGroupId(); + String projectArtifactId = projectDependency.getArtifactId(); + if (!artifactId.equals(projectArtifactId)) { + return false; + } + if (groupId == null && projectGroupId == null) { + return true; + } + if (groupId != null && groupId.equals(projectGroupId)) { + return true; + } + } + return false; + } + + private static void addPlugins(org.eclipse.m2e.model.edit.pom.Model projectModel, org.eclipse.m2e.model.edit.pom.Model libraryModel) { + org.eclipse.m2e.model.edit.pom.Build libraryBuild = libraryModel.getBuild(); + if (libraryBuild == null) { + return; + } + List libraryPlugins = projectModel.getBuild().getPlugins(); + for (org.eclipse.m2e.model.edit.pom.Plugin plugin:libraryPlugins) { + org.eclipse.m2e.model.edit.pom.Build projectBuild = projectModel.getBuild(); + if (projectBuild == null) { + projectBuild = PomFactory.eINSTANCE.createBuild(); + projectModel.setBuild(projectBuild); + } + List projectPlugins = projectBuild.getPlugins(); + if (!pluginExists(plugin,projectPlugins)) { + org.eclipse.m2e.model.edit.pom.Plugin newPlugin = (org.eclipse.m2e.model.edit.pom.Plugin) EcoreUtil.copy(plugin); + projectPlugins.add(newPlugin); + } + } + } + + private static boolean pluginExists(org.eclipse.m2e.model.edit.pom.Plugin plugin, List projectPlugins) { + String groupId = plugin.getGroupId(); + String artifactId = plugin.getArtifactId(); + if (artifactId == null) { + return false; + } + for (org.eclipse.m2e.model.edit.pom.Plugin projectPlugin:projectPlugins) { + String projectGroupId = projectPlugin.getGroupId(); + String projectArtifactId = projectPlugin.getArtifactId(); + if (!artifactId.equals(projectArtifactId)) { + return false; + } + if (groupId == null && projectGroupId == null) { + return true; + } + if (groupId != null && groupId.equals(projectGroupId)) { + return true; + } + } + return false; + } + + private static void addRepositories(org.eclipse.m2e.model.edit.pom.Model projectModel, org.eclipse.m2e.model.edit.pom.Model libraryModel) { + List projectRepositories = projectModel.getRepositories(); + List libraryRepositories = libraryModel.getRepositories(); + for (Repository repository:libraryRepositories) { + if (!repositoryExists(repository,projectRepositories)) { + Repository newRepository = (Repository) EcoreUtil.copy(repository); + projectRepositories.add(newRepository); + } + } + } + + private static boolean repositoryExists(Repository repository, + List projectRepositories) { + String url = repository.getUrl(); + if (url == null) { + return false; + } + for(Repository projectRepository:projectRepositories) { + if (url.equals(projectRepository.getUrl())) { + return true; + } + } + return false; + } + + private static void addProperties(org.eclipse.m2e.model.edit.pom.Model projectModel, org.eclipse.m2e.model.edit.pom.Model libraryModel) { + List projectProperties = projectModel.getProperties(); + List libraryProperties = libraryModel.getProperties(); + for (PropertyElement libraryProperty:libraryProperties) { + String propertyName = libraryProperty.getName(); + if (!propertyExists(propertyName,projectProperties)) { + PropertyElement newProperty = (PropertyElement) EcoreUtil.copy(libraryProperty); + projectProperties.add(newProperty); + } + } + } + + private static boolean propertyExists(String propertyName, + List projectProperties) { + if (propertyName == null) { + return false; + } + for (PropertyElement propertyElement:projectProperties) { + if (propertyName.equals(propertyElement.getName())) { + return true; + } + } + return false; + } + + public static void log(Throwable e) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); + getDefault().getLog().log(status); + } + + public static void log(String message) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message); + getDefault().getLog().log(status); + } + + public static File getProviderFile(ILibraryProvider provider) { + String id = provider.getId(); + IPath providerDir = MavenCoreActivator.getDefault().getStateLocation().append(id); + File providerDirFile = providerDir.toFile(); + providerDirFile.mkdir(); + File providerFile = new File(providerDirFile, "template.xml"); //$NON-NLS-1$ + return providerFile; + } + + public static PomResourceImpl loadResource(URL url) throws CoreException { + try { + URI uri = URI.createURI(url.toString()); + if ( !( uri.isFile() || uri.isPlatformResource()) ) { + // the m2eclipse pom model can read only a file URL or platform resource URL + // see https://jira.jboss.org/jira/browse/JBIDE-4972 + InputStream is = null; + OutputStream os = null; + try { + File temp = File.createTempFile("mavenCoreActivator", ".pom"); //$NON-NLS-1$//$NON-NLS-2$ + temp.deleteOnExit(); + os = new FileOutputStream(temp); + is = url.openStream(); + copy(is,os); + URL tempURL = temp.toURL(); + uri = URI.createURI(tempURL.toString()); + } catch (Exception e) { + log(e); + throw new CoreException(new Status(IStatus.ERROR, + PLUGIN_ID, -1, e.getMessage(), e)); + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception ignore) {} + } + if (os != null) { + try { + os.close(); + } catch (Exception ignore) {} + } + } + } + org.eclipse.emf.ecore.resource.Resource resource = new PomResourceFactoryImpl() + .createResource(uri); + resource.load(Collections.EMPTY_MAP); + return (PomResourceImpl) resource; + } catch (Exception ex) { + log(ex); + throw new CoreException(new Status(IStatus.ERROR, + PLUGIN_ID, -1, ex.getMessage(), ex)); + } + } + + private static void copy(InputStream is, OutputStream os) + throws IOException { + byte[] buffer = new byte[1024]; + int count; + while ( (count = is.read(buffer)) > 0) { + os.write(buffer,0,count); + } + } + + public static void addLibraryProviderOperationConfig( + LibraryProviderOperationConfig config) { + libraryProviderOperationConfigs.add(config); + } + + public static List getLibraryProviderOperationConfigs() { + return libraryProviderOperationConfigs; + } + + public static PomResourceImpl getResource() { + return resource; + } + + public static void setResource(PomResourceImpl resource2) { + resource = resource2; + } + + public static void addCompilerPlugin(Build build, IProject project) { + String compilerLevel = JavaFacetUtils.getCompilerLevel(project); + if (compilerLevel == null) { + return; + } + org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); + plugin.setGroupId("org.apache.maven.plugins"); //$NON-NLS-1$ + plugin.setArtifactId("maven-compiler-plugin"); //$NON-NLS-1$ + Xpp3Dom configuration = new Xpp3Dom( "configuration" ); //$NON-NLS-1$ + Xpp3Dom source = new Xpp3Dom("source"); //$NON-NLS-1$ + source.setValue(compilerLevel); //$NON-NLS-1$ + configuration.addChild(source); + Xpp3Dom target = new Xpp3Dom("target"); //$NON-NLS-1$ + target.setValue(compilerLevel); //$NON-NLS-1$ + configuration.addChild(target); + plugin.setConfiguration(configuration); + build.getPlugins().add(plugin); + } + + public static PomResourceImpl loadResource(IFile pomFile) + throws CoreException { + String path = pomFile.getFullPath().toOSString(); + URI uri = URI.createPlatformResourceURI(path, true); + try { + org.eclipse.emf.ecore.resource.Resource pomResource = new PomResourceFactoryImpl() + .createResource(uri); + pomResource.load(new HashMap()); + return (PomResourceImpl) pomResource; + } catch (Exception ex) { + String msg = "Can't load model " + pomFile; + log(ex); + throw new CoreException(new Status(IStatus.ERROR, + IMavenConstants.PLUGIN_ID, -1, msg, ex)); + } + } +} Index: src/org/jboss/tools/maven/core/IJBossMavenConstants.java =================================================================== --- src/org/jboss/tools/maven/core/IJBossMavenConstants.java (revision 32782) +++ src/org/jboss/tools/maven/core/IJBossMavenConstants.java (working copy) @@ -1,35 +1,32 @@ -/************************************************************************************* - * Copyright (c) 2009-2011 Red Hat, Inc. 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: - * JBoss by Red Hat - Initial implementation. - ************************************************************************************/ -package org.jboss.tools.maven.core; - - - -/** - * @author snjeza - * - */ - -public interface IJBossMavenConstants { - - static final String M2_FACET_ID="jboss.m2"; //$NON-NLS-1$ - static final String ARTIFACT_ID = "artifactId"; //$NON-NLS-1$ - static final String GROUP_ID = "groupId"; //$NON-NLS-1$ - static final String VERSION = "version"; //$NON-NLS-1$ - static final String NAME = "name"; //$NON-NLS-1$ - static final String DESCRIPTION = "description"; //$NON-NLS-1$ - static final String PACKAGING = "packaging"; //$NON-NLS-1$ - static final String MAVEN_MODEL_VERSION = "4.0.0"; //$NON-NLS-1$ - static final String PROJECT_VERSION = "project.version"; //$NON-NLS-1$ - static final String SEAM_MAVEN_VERSION = "seamMavenVersion"; //$NON-NLS-1$ - static final String SEAM_VERSION = "seam.version"; //$NON-NLS-1$ - static final String REMOVE_WTP_CLASSPATH_CONTAINERS = "removeWTPClasspathContainers"; //$NON-NLS-1$ - static final String MAVEN_PROJECT_EXISTS = "mavenProjectExists"; //$NON-NLS-1$ +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core; + +/** + * @author snjeza + * + */ +public interface IJBossMavenConstants { + + static final String M2_FACET_ID="jboss.m2"; //$NON-NLS-1$ + static final String ARTIFACT_ID = "artifactId"; //$NON-NLS-1$ + static final String GROUP_ID = "groupId"; //$NON-NLS-1$ + static final String VERSION = "version"; //$NON-NLS-1$ + static final String NAME = "name"; //$NON-NLS-1$ + static final String DESCRIPTION = "description"; //$NON-NLS-1$ + static final String PACKAGING = "packaging"; //$NON-NLS-1$ + static final String MAVEN_MODEL_VERSION = "4.0.0"; //$NON-NLS-1$ + static final String PROJECT_VERSION = "project.version"; //$NON-NLS-1$ + static final String SEAM_MAVEN_VERSION = "seamMavenVersion"; //$NON-NLS-1$ + static final String SEAM_VERSION = "seam.version"; //$NON-NLS-1$ + static final String REMOVE_WTP_CLASSPATH_CONTAINERS = "removeWTPClasspathContainers"; //$NON-NLS-1$ + static final String MAVEN_PROJECT_EXISTS = "mavenProjectExists"; //$NON-NLS-1$ } \ No newline at end of file Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.jboss.tools.maven.core; singleton:=true -Bundle-Version: 1.1.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Localization: plugin Bundle-Activator: org.jboss.tools.maven.core.MavenCoreActivator Require-Bundle: org.eclipse.core.runtime, @@ -12,21 +12,22 @@ org.eclipse.wst.common.frameworks;visibility:=reexport, org.eclipse.jst.common.frameworks;visibility:=reexport, org.eclipse.wst.common.modulecore;visibility:=reexport, - org.maven.ide.eclipse;bundle-version="0.10.0";visibility:=reexport, - org.maven.ide.eclipse.maven_embedder;bundle-version="0.10.0";visibility:=reexport, + org.eclipse.m2e.core;bundle-version="[1.0,1.1)";visibility:=reexport, + org.eclipse.m2e.maven.runtime;bundle-version="[1.0,1.1)";visibility:=reexport, org.eclipse.jdt.core;visibility:=reexport, - org.maven.ide.eclipse.jdt;bundle-version="0.10.0";visibility:=reexport, + org.eclipse.m2e.jdt;bundle-version="[1.0,1.1)";visibility:=reexport, org.eclipse.jst.j2ee;visibility:=reexport, org.eclipse.jst.j2ee.web;visibility:=reexport, org.jboss.tools.common;visibility:=reexport, org.eclipse.jdt.launching;visibility:=reexport, org.eclipse.ui.workbench;visibility:=reexport, - org.maven.ide.eclipse.maven_model_edit;bundle-version="0.10.0";visibility:=reexport, + org.eclipse.m2e.model.edit;bundle-version="[1.0,1.1)";visibility:=reexport, org.eclipse.core.expressions, - org.maven.ide.eclipse.wtp;bundle-version="0.10.0";visibility:=reexport + org.maven.ide.eclipse.wtp;bundle-version="[0.13.0,0.15.0)";visibility:=reexport Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-Vendor: %Bundle-Vendor Export-Package: org.jboss.tools.maven.core, org.jboss.tools.maven.core.internal.project.facet, - org.jboss.tools.maven.core.libprov + org.jboss.tools.maven.core.libprov, + org.jboss.tools.maven.core.xpl Index: src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderUninstallOperation.java =================================================================== --- src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderUninstallOperation.java (revision 32782) +++ src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderUninstallOperation.java (working copy) @@ -1,18 +1,30 @@ -package org.jboss.tools.maven.core.libprov; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperation; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; - -public class MavenLibraryProviderUninstallOperation extends LibraryProviderOperation { - - @Override - public void execute(LibraryProviderOperationConfig config, - IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core.libprov; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperation; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; + +/** + * @author snjeza + * + */ +public class MavenLibraryProviderUninstallOperation extends LibraryProviderOperation { + + @Override + public void execute(LibraryProviderOperationConfig config, + IProgressMonitor monitor) throws CoreException { + + } + +} Index: src/org/jboss/tools/maven/core/PluginUpdater.java =================================================================== --- src/org/jboss/tools/maven/core/PluginUpdater.java (revision 32782) +++ src/org/jboss/tools/maven/core/PluginUpdater.java (working copy) @@ -1,32 +1,45 @@ -package org.jboss.tools.maven.core; - - -import org.apache.maven.model.Plugin; -import org.maven.ide.components.pom.Build; -import org.maven.ide.components.pom.Model; -import org.maven.ide.components.pom.PomFactory; -import org.maven.ide.eclipse.embedder.ProjectUpdater; - -public class PluginUpdater extends ProjectUpdater { - - private static final PomFactory POM_FACTORY = PomFactory.eINSTANCE; - private Plugin plugin; - - public PluginUpdater(Plugin plugin) { - this.plugin = plugin; - } - - public void update(Model model) { - Build build = model.getBuild(); - if(build==null) { - build = POM_FACTORY.createBuild(); - model.setBuild(build); - } - org.maven.ide.components.pom.Plugin newPlugin = POM_FACTORY.createPlugin(); - newPlugin.setArtifactId(plugin.getArtifactId()); - newPlugin.setGroupId(plugin.getGroupId()); - newPlugin.setVersion(plugin.getVersion()); - newPlugin.setExtensions(plugin.getExtensions()); - // FIXME - } - } +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core; + +import org.apache.maven.model.Plugin; +import org.eclipse.m2e.model.edit.pom.Build; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.jboss.tools.maven.core.xpl.ProjectUpdater; + +/** +* @author snjeza +* +*/ +public class PluginUpdater extends ProjectUpdater { + + private static final PomFactory POM_FACTORY = PomFactory.eINSTANCE; + private Plugin plugin; + + public PluginUpdater(Plugin plugin) { + this.plugin = plugin; + } + + public void update(Model model) { + Build build = model.getBuild(); + if(build==null) { + build = POM_FACTORY.createBuild(); + model.setBuild(build); + } + org.eclipse.m2e.model.edit.pom.Plugin newPlugin = POM_FACTORY.createPlugin(); + newPlugin.setArtifactId(plugin.getArtifactId()); + newPlugin.setGroupId(plugin.getGroupId()); + newPlugin.setVersion(plugin.getVersion()); + newPlugin.setExtensions(plugin.getExtensions()); + // FIXME + } + } Index: src/org/jboss/tools/maven/core/xpl/ProjectUpdater.java =================================================================== --- src/org/jboss/tools/maven/core/xpl/ProjectUpdater.java (revision 0) +++ src/org/jboss/tools/maven/core/xpl/ProjectUpdater.java (revision 0) @@ -0,0 +1,14 @@ +package org.jboss.tools.maven.core.xpl; + +import org.eclipse.m2e.model.edit.pom.Model; + +/** + * Project updater + * + * @author Eugene Kuleshov + */ +public abstract class ProjectUpdater { + + public abstract void update(Model model); + +} Index: src/org/jboss/tools/maven/core/ProjectFacetsFactoryTester.java =================================================================== --- src/org/jboss/tools/maven/core/ProjectFacetsFactoryTester.java (revision 32782) +++ src/org/jboss/tools/maven/core/ProjectFacetsFactoryTester.java (working copy) @@ -1,44 +1,58 @@ -package org.jboss.tools.maven.core; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.wst.common.project.facet.core.internal.ProjectFacetVersion; - -public class ProjectFacetsFactoryTester extends PropertyTester { - - public boolean test(Object receiver, String property, Object[] args, - Object expectedValue) { - - if (! (receiver instanceof Collection)) { - return false; - } - if (! (expectedValue instanceof String)) { - return false; - } - String requiredFacets = (String) expectedValue; - Collection collection = (Collection) receiver; - List facets = new ArrayList(); - for (Iterator iterator = collection.iterator(); iterator.hasNext();) { - Object object = iterator.next(); - if ( ! (object instanceof ProjectFacetVersion)) { - return false; - } - ProjectFacetVersion projectFacetVersion = (ProjectFacetVersion) object; - facets.add(projectFacetVersion.getProjectFacet().getId()); - } - StringTokenizer tokenizer = new StringTokenizer(requiredFacets,","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String requiredFacet = tokenizer.nextToken().trim(); - if (!facets.contains(requiredFacet)) { - return false; - } - } - return true; - } - -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.wst.common.project.facet.core.internal.ProjectFacetVersion; + +/** + * @author snjeza + * + */ +public class ProjectFacetsFactoryTester extends PropertyTester { + + public boolean test(Object receiver, String property, Object[] args, + Object expectedValue) { + + if (! (receiver instanceof Collection)) { + return false; + } + if (! (expectedValue instanceof String)) { + return false; + } + String requiredFacets = (String) expectedValue; + Collection collection = (Collection) receiver; + List facets = new ArrayList(); + for (Iterator iterator = collection.iterator(); iterator.hasNext();) { + Object object = iterator.next(); + if ( ! (object instanceof ProjectFacetVersion)) { + return false; + } + ProjectFacetVersion projectFacetVersion = (ProjectFacetVersion) object; + facets.add(projectFacetVersion.getProjectFacet().getId()); + } + StringTokenizer tokenizer = new StringTokenizer(requiredFacets,","); //$NON-NLS-1$ + while (tokenizer.hasMoreTokens()) { + String requiredFacet = tokenizer.nextToken().trim(); + if (!facets.contains(requiredFacet)) { + return false; + } + } + return true; + } + +} Index: src/org/jboss/tools/maven/core/Messages.java =================================================================== --- src/org/jboss/tools/maven/core/Messages.java (revision 32782) +++ src/org/jboss/tools/maven/core/Messages.java (working copy) @@ -1,20 +1,34 @@ -package org.jboss.tools.maven.core; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.jboss.tools.maven.core.messages"; //$NON-NLS-1$ - public static String MavenFacetInstallDelegate_Internal_Error_creating_JBoss_Maven_Facet; - public static String MavenFacetInstallPage_The_artifactId_field_is_required; - public static String MavenFacetInstallPage_The_groupId_field_is_required; - public static String MavenFacetInstallPage_The_packaging_field_is_required; - public static String MavenFacetInstallPage_The_version_field_is_required; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core; + +import org.eclipse.osgi.util.NLS; + +/** + * @author snjeza + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.jboss.tools.maven.core.messages"; //$NON-NLS-1$ + public static String MavenFacetInstallDelegate_Internal_Error_creating_JBoss_Maven_Facet; + public static String MavenFacetInstallPage_The_artifactId_field_is_required; + public static String MavenFacetInstallPage_The_groupId_field_is_required; + public static String MavenFacetInstallPage_The_packaging_field_is_required; + public static String MavenFacetInstallPage_The_version_field_is_required; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.core - 1.1.0-SNAPSHOT + org.jboss.tools.maven.core + 1.2.0-SNAPSHOT eclipse-plugin - + \ No newline at end of file Index: src/org/jboss/tools/maven/core/internal/project/facet/MavenFacetInstallDelegate.java =================================================================== --- src/org/jboss/tools/maven/core/internal/project/facet/MavenFacetInstallDelegate.java (revision 32782) +++ src/org/jboss/tools/maven/core/internal/project/facet/MavenFacetInstallDelegate.java (working copy) @@ -1,155 +1,164 @@ -package org.jboss.tools.maven.core.internal.project.facet; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.model.Build; -import org.apache.maven.model.Model; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.Resource; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IClasspathAttribute; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jst.common.project.facet.core.JavaFacet; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; -import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil; -import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants; -import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; -import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IDelegate; -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.jboss.tools.maven.core.MavenCoreActivator; -import org.jboss.tools.maven.core.IJBossMavenConstants; -import org.jboss.tools.maven.core.Messages; -import org.jboss.tools.maven.core.libprov.MavenLibraryProviderInstallOperation; -import org.jboss.tools.maven.core.libprov.MavenLibraryProviderInstallOperationConfig; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.embedder.MavenModelManager; - -public class MavenFacetInstallDelegate implements IDelegate { - - private static final String SEAM_FACET_ID = "jst.seam"; //$NON-NLS-1$ - - public void execute(IProject project, IProjectFacetVersion fv, Object cfg, - IProgressMonitor monitor) throws CoreException { - IDataModel config = null; - - if (cfg != null) { - config = (IDataModel) cfg; - } else { - throw new CoreException( - MavenCoreActivator - .getStatus(Messages.MavenFacetInstallDelegate_Internal_Error_creating_JBoss_Maven_Facet)); - } - - IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); - IJavaProject javaProject = JavaCore.create(project); - IFacetedProjectWorkingCopy fpwc = null; - try { - fpwc = (IFacetedProjectWorkingCopy) config.getProperty(IFacetDataModelProperties.FACETED_PROJECT_WORKING_COPY); - if (!pom.exists()) { - Model model = new Model(); - model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); - model.setGroupId(config - .getStringProperty(IJBossMavenConstants.GROUP_ID)); - String artifactId = config - .getStringProperty(IJBossMavenConstants.ARTIFACT_ID); - model.setArtifactId(artifactId); - model.setVersion(config - .getStringProperty(IJBossMavenConstants.VERSION)); - model.setName(config - .getStringProperty(IJBossMavenConstants.NAME)); - model.setPackaging(config - .getStringProperty(IJBossMavenConstants.PACKAGING)); - model.setDescription(config - .getStringProperty(IJBossMavenConstants.DESCRIPTION)); - Build build = new Build(); - model.setBuild(build); - - // build.setFinalName(artifactId); - if (fpwc.hasProjectFacet(JavaFacet.FACET)) { - String outputDirectory = MavenCoreActivator - .getOutputDirectory(javaProject); - build.setOutputDirectory(outputDirectory); - String sourceDirectory = MavenCoreActivator - .getSourceDirectory(javaProject); - if (sourceDirectory != null) { - build.setSourceDirectory(sourceDirectory); - } - } - - if (fpwc.hasProjectFacet(WebFacetUtils.WEB_FACET)) { - - MavenCoreActivator.addMavenWarPlugin(build, project); - } - if (fpwc.hasProjectFacet(IJ2EEFacetConstants.EJB_FACET)) { - - MavenCoreActivator.addMavenEjbPlugin(build, project); - } - if (fpwc - .hasProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION_FACET)) { - MavenCoreActivator.addMavenEarPlugin(build, project, - config, null, false); - MavenCoreActivator.createMavenProject(project.getName(), - monitor, model, true); - } - IProjectFacet seamFacet = ProjectFacetsManager - .getProjectFacet(SEAM_FACET_ID); - if (!fpwc.hasProjectFacet(seamFacet)) { - MavenCoreActivator.addCompilerPlugin(build, project); - } - - if (!pom.exists()) { - MavenModelManager modelManager = MavenPlugin.getDefault() - .getMavenModelManager(); - modelManager.createMavenModel(pom, model); - } - } - - boolean hasMavenNature = MavenCoreActivator.addMavenNature(project, - monitor); - - if (fpwc.hasProjectFacet(WebFacetUtils.WEB_FACET)) { - IClasspathAttribute attribute = JavaCore - .newClasspathAttribute( - IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY, - ClasspathDependencyUtil.getDefaultRuntimePath( - true).toString()); - MavenCoreActivator.addClasspathAttribute(javaProject, - attribute, monitor); - } - // FIXME - IClasspathAttribute attribute = JavaCore.newClasspathAttribute( - MavenCoreActivator.OWNER_PROJECT_FACETS_ATTR, - IJBossMavenConstants.M2_FACET_ID); - MavenCoreActivator.addClasspathAttribute(javaProject, attribute, - monitor); - - List configs = MavenCoreActivator - .getLibraryProviderOperationConfigs(); - if (configs.size() > 0) { - MavenLibraryProviderInstallOperation operation = new MavenLibraryProviderInstallOperation(); - for (LibraryProviderOperationConfig libraryProviderOperationConfig : configs) { - operation.execute(libraryProviderOperationConfig, monitor); - } - configs.clear(); - } - } finally { - if (fpwc != null) { - fpwc.dispose(); - } - } - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core.internal.project.facet; + +import java.util.List; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Model; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jst.common.project.facet.core.JavaFacet; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; +import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil; +import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants; +import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; +import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.MavenModelManager; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.IDelegate; +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.jboss.tools.maven.core.IJBossMavenConstants; +import org.jboss.tools.maven.core.MavenCoreActivator; +import org.jboss.tools.maven.core.Messages; +import org.jboss.tools.maven.core.libprov.MavenLibraryProviderInstallOperation; + +/** + * @author snjeza + * + */ +public class MavenFacetInstallDelegate implements IDelegate { + + private static final String SEAM_FACET_ID = "jst.seam"; //$NON-NLS-1$ + + public void execute(IProject project, IProjectFacetVersion fv, Object cfg, + IProgressMonitor monitor) throws CoreException { + IDataModel config = null; + + if (cfg != null) { + config = (IDataModel) cfg; + } else { + throw new CoreException( + MavenCoreActivator + .getStatus(Messages.MavenFacetInstallDelegate_Internal_Error_creating_JBoss_Maven_Facet)); + } + + IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); + IJavaProject javaProject = JavaCore.create(project); + IFacetedProjectWorkingCopy fpwc = null; + try { + fpwc = (IFacetedProjectWorkingCopy) config.getProperty(IFacetDataModelProperties.FACETED_PROJECT_WORKING_COPY); + if (!pom.exists()) { + Model model = new Model(); + model.setModelVersion(IJBossMavenConstants.MAVEN_MODEL_VERSION); + model.setGroupId(config + .getStringProperty(IJBossMavenConstants.GROUP_ID)); + String artifactId = config + .getStringProperty(IJBossMavenConstants.ARTIFACT_ID); + model.setArtifactId(artifactId); + model.setVersion(config + .getStringProperty(IJBossMavenConstants.VERSION)); + model.setName(config + .getStringProperty(IJBossMavenConstants.NAME)); + model.setPackaging(config + .getStringProperty(IJBossMavenConstants.PACKAGING)); + model.setDescription(config + .getStringProperty(IJBossMavenConstants.DESCRIPTION)); + Build build = new Build(); + model.setBuild(build); + + // build.setFinalName(artifactId); + if (fpwc.hasProjectFacet(JavaFacet.FACET)) { + String outputDirectory = MavenCoreActivator + .getOutputDirectory(javaProject); + build.setOutputDirectory(outputDirectory); + String sourceDirectory = MavenCoreActivator + .getSourceDirectory(javaProject); + if (sourceDirectory != null) { + build.setSourceDirectory(sourceDirectory); + } + } + + if (fpwc.hasProjectFacet(WebFacetUtils.WEB_FACET)) { + + MavenCoreActivator.addMavenWarPlugin(build, project); + } + if (fpwc.hasProjectFacet(IJ2EEFacetConstants.EJB_FACET)) { + + MavenCoreActivator.addMavenEjbPlugin(build, project); + } + if (fpwc + .hasProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION_FACET)) { + MavenCoreActivator.addMavenEarPlugin(build, project, + config, null, false); + MavenCoreActivator.createMavenProject(project.getName(), + monitor, model, true); + } + IProjectFacet seamFacet = ProjectFacetsManager + .getProjectFacet(SEAM_FACET_ID); + if (!fpwc.hasProjectFacet(seamFacet)) { + MavenCoreActivator.addCompilerPlugin(build, project); + } + + if (!pom.exists()) { + MavenModelManager modelManager = MavenPlugin.getDefault() + .getMavenModelManager(); + modelManager.createMavenModel(pom, model); + } + } + + boolean hasMavenNature = MavenCoreActivator.addMavenNature(project, + monitor); + + if (fpwc.hasProjectFacet(WebFacetUtils.WEB_FACET)) { + IClasspathAttribute attribute = JavaCore + .newClasspathAttribute( + IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY, + ClasspathDependencyUtil.getDefaultRuntimePath( + true).toString()); + MavenCoreActivator.addClasspathAttribute(javaProject, + attribute, monitor); + } + // FIXME + IClasspathAttribute attribute = JavaCore.newClasspathAttribute( + MavenCoreActivator.OWNER_PROJECT_FACETS_ATTR, + IJBossMavenConstants.M2_FACET_ID); + MavenCoreActivator.addClasspathAttribute(javaProject, attribute, + monitor); + + List configs = MavenCoreActivator + .getLibraryProviderOperationConfigs(); + if (configs.size() > 0) { + MavenLibraryProviderInstallOperation operation = new MavenLibraryProviderInstallOperation(); + for (LibraryProviderOperationConfig libraryProviderOperationConfig : configs) { + operation.execute(libraryProviderOperationConfig, monitor); + } + configs.clear(); + } + } finally { + if (fpwc != null) { + fpwc.dispose(); + } + } + } + +} Index: src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderInstallOperationConfig.java =================================================================== --- src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderInstallOperationConfig.java (revision 32782) +++ src/org/jboss/tools/maven/core/libprov/MavenLibraryProviderInstallOperationConfig.java (working copy) @@ -1,19 +1,33 @@ -package org.jboss.tools.maven.core.libprov; - -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderInstallOperationConfig; -import org.maven.ide.components.pom.Model; - -public class MavenLibraryProviderInstallOperationConfig extends - LibraryProviderInstallOperationConfig { - - private Model model; - - public void setModel(Model model) { - this.model = model; - } - - public Model getModel() { - return model; - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.core.libprov; + +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderInstallOperationConfig; +import org.eclipse.m2e.model.edit.pom.Model; + +/** + * @author snjeza + * + */ +public class MavenLibraryProviderInstallOperationConfig extends + LibraryProviderInstallOperationConfig { + + private Model model; + + public void setModel(Model model) { + this.model = model; + } + + public Model getModel() { + return model; + } + +} #P org.jboss.tools.maven.seam.feature Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + features + 0.0.1-SNAPSHOT org.jboss.tools.maven.features - org.jboss.tools.maven.seam.feature - 1.1.0-SNAPSHOT + org.jboss.tools.maven.seam.feature + 1.2.0-SNAPSHOT eclipse-feature - + \ No newline at end of file Index: feature.xml =================================================================== --- feature.xml (revision 32782) +++ feature.xml (working copy) @@ -2,7 +2,7 @@ @@ -19,8 +19,8 @@ - - + + @@ -19,8 +19,8 @@ - - + + - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + features + 0.0.1-SNAPSHOT org.jboss.tools.maven.features - org.jboss.tools.maven.hibernate.feature - 1.0.0-SNAPSHOT + org.jboss.tools.maven.hibernate.feature + 1.2.0-SNAPSHOT eclipse-feature - + \ No newline at end of file #P org.jboss.tools.maven.ui.bot.test Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -27,25 +27,17 @@ org.eclipse.datatools.connectivity.db.generic, org.jboss.tools.common, org.jboss.tools.tests, - org.maven.ide.eclipse;bundle-version="0.12.0", org.jboss.ide.eclipse.as.core, - org.maven.ide.eclipse.maven_model_edit;bundle-version="0.12.0", org.hamcrest, org.eclipse.datatools.enablement.hsqldb, org.eclipse.datatools.enablement.hsqldb.dbdefinition, org.eclipse.datatools.enablement.hsqldb.ui, - org.maven.ide.eclipse.archetype_common;bundle-version="0.12.0", - org.maven.ide.eclipse.dependency_tree;bundle-version="0.12.0", - org.maven.ide.eclipse.editor;bundle-version="0.12.0", - org.maven.ide.eclipse.editor.xml;bundle-version="0.12.0", - org.maven.ide.eclipse.launching;bundle-version="0.12.0", - org.maven.ide.eclipse.nexus_indexer;bundle-version="0.12.0", - org.maven.ide.eclipse.pr;bundle-version="0.12.0", - org.maven.ide.eclipse.refactoring;bundle-version="0.12.0", org.eclipse.jst.jee, org.eclipse.jst.jee.ejb, org.eclipse.jst.jee.ui, - org.eclipse.jst.jee.web + org.eclipse.jst.jee.web, + org.eclipse.m2e.lifecyclemapping.defaults;bundle-version="[1.0,1.1)", + org.eclipse.m2e.launching;bundle-version="[1.0,1.1)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Eclipse-RegisterBuddy: org.apache.log4j Index: src/org/jboss/tools/maven/ui/bot/test/CreateMavenizedSeamProjectTest.java =================================================================== --- src/org/jboss/tools/maven/ui/bot/test/CreateMavenizedSeamProjectTest.java (revision 32782) +++ src/org/jboss/tools/maven/ui/bot/test/CreateMavenizedSeamProjectTest.java (working copy) @@ -1,604 +1,674 @@ -/************************************************************************************* - * Copyright (c) 2008-2011 Red Hat, Inc. 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: - * JBoss by Red Hat - Initial implementation. - ************************************************************************************/ - -package org.jboss.tools.maven.ui.bot.test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.datatools.connectivity.ConnectionProfileConstants; -import org.eclipse.datatools.connectivity.ConnectionProfileException; -import org.eclipse.datatools.connectivity.ProfileManager; -import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants; -import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants; -import org.eclipse.datatools.connectivity.drivers.DriverInstance; -import org.eclipse.datatools.connectivity.drivers.DriverManager; -import org.eclipse.datatools.connectivity.drivers.IDriverMgmtConstants; -import org.eclipse.datatools.connectivity.drivers.IPropertySet; -import org.eclipse.datatools.connectivity.drivers.PropertySetImpl; -import org.eclipse.datatools.connectivity.drivers.models.TemplateDescriptor; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotViewMenu; -import org.eclipse.swtbot.swt.finder.SWTBot; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; -import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; -import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.eclipse.swtbot.swt.finder.results.Result; -import org.eclipse.swtbot.swt.finder.results.VoidResult; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.eclipse.ui.IPerspectiveDescriptor; -import org.eclipse.ui.IPerspectiveRegistry; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferenceConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.internal.IPreferenceConstants; -import org.eclipse.ui.internal.WorkbenchPlugin; -import org.eclipse.ui.internal.util.PrefUtil; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IRuntime; -import org.eclipse.wst.server.core.IRuntimeType; -import org.eclipse.wst.server.core.IRuntimeWorkingCopy; -import org.eclipse.wst.server.core.IServer; -import org.eclipse.wst.server.core.IServerType; -import org.eclipse.wst.server.core.IServerWorkingCopy; -import org.eclipse.wst.server.core.ServerCore; -import org.eclipse.wst.server.core.ServerUtil; -import org.eclipse.wst.server.core.internal.RuntimeWorkingCopy; -import org.eclipse.wst.server.core.internal.ServerWorkingCopy; -import org.eclipse.wst.validation.ValidationFramework; -import org.jboss.tools.seam.core.project.facet.SeamRuntime; -import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager; -import org.jboss.tools.seam.core.project.facet.SeamVersion; -import org.jboss.tools.test.util.JobUtils; -import org.jboss.tools.test.util.ResourcesUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.maven.ide.components.pom.Model; -import org.maven.ide.components.pom.Parent; -import org.maven.ide.components.pom.util.PomResourceImpl; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.embedder.MavenModelManager; - -/** - * @author Snjeza - * - */ -@RunWith(SWTBotJunit4ClassRunner.class) -public class CreateMavenizedSeamProjectTest { - - protected static final int IDLE_TIME = 60000; - - private static final String CONNECTION_PROFILE_NAME = "DefaultDS"; - - private static final String SEAM_RUNTIME_NAME = "Seam 2.2"; - - private static final String JBOSS_AS_RUNTIME_NAME = "JBoss AS 5.1 Runtime"; - - public static final String PACKAGE_EXPLORER = "Package Explorer"; //$NON-NLS-1$ - - private static final String JBOSS_AS_SERVER_NAME = "JBoss AS 5.1 Server"; - - public static final String JBOSS_AS_HOST = "localhost"; //$NON-NLS-1$ - - public static final String JBOSS_AS_DEFAULT_CONFIGURATION_NAME = "default"; //$NON-NLS-1$ - - public static final String HSQL_DRIVER_DEFINITION_ID - = "DriverDefn.Hypersonic DB"; //$NON-NLS-1$ - - public static final String HSQL_DRIVER_NAME = "Hypersonic DB"; //$NON-NLS-1$ - - public static final String HSQL_DRIVER_TEMPLATE_ID - = "org.eclipse.datatools.enablement.hsqldb.1_8.driver"; //$NON-NLS-1$ - - public static final String DTP_DB_URL_PROPERTY_ID - = "org.eclipse.datatools.connectivity.db.URL"; //$NON-NLS-1$ - - public static final String HSQL_PROFILE_ID = "org.eclipse.datatools.enablement.hsqldb.connectionProfile"; - - public static final String JBOSS_AS_HOME = System.getProperty("jbosstools.test.jboss.home.5.1", "E:\\JBossRuntimes\\jboss-5.1.0.GA"); - - public static final String JBOSS_AS_RUNTIME_ID = "org.jboss.ide.eclipse.as.runtime.51"; - - public static final String JBOSS_AS_SERVER_ID = "org.jboss.ide.eclipse.as.51"; - - public static final String SEAM_HOME_PROPERTY = System.getProperty("jbosstools.test.seam.2.0.1.GA.home", "E:\\JBossRuntimes\\jboss-seam-2.2.1.CR3"); - - public static final String HSQLDB_DRIVER_JAR_NAME = "hsqldb.jar"; //$NON-NLS-1$ - - public static final String HSQLDB_DRIVER_LOCATION = "/common/lib/" + HSQLDB_DRIVER_JAR_NAME; //$NON-NLS-1$ - - public static final String PROJECT_NAME_WAR = "MavenizedSeamProjectWar"; - - public static final String TEST_PROJECT_NAME_WAR = "MavenizedSeamProjectWar-test"; - - public static final String PARENT_PROJECT_NAME_WAR = "MavenizedSeamProjectWar-parent"; - - - public static final String PROJECT_NAME = "MavenizedSeamProject"; - - public static final String EAR_PROJECT_NAME = "MavenizedSeamProject-ear"; - - public static final String EJB_PROJECT_NAME = "MavenizedSeamProject-ejb"; - - public static final String TEST_PROJECT_NAME = "MavenizedSeamProject-test"; - - public static final String PARENT_PROJECT_NAME = "MavenizedSeamProject-parent"; - - public static final String DEPLOY_TYPE_EAR = "EAR"; - - public static final String DEPLOY_TYPE_WAR = "WAR"; - - protected static SWTWorkbenchBot bot; - - @BeforeClass - public final static void beforeClass() throws Exception { - initSWTBot(); - - switchPerspective("org.jboss.tools.seam.ui.SeamPerspective"); - - String asLocation = JBOSS_AS_HOME; - - String runtimeType = JBOSS_AS_RUNTIME_ID; - String serverType = JBOSS_AS_SERVER_ID; - - createJBossServer(new File(asLocation), serverType, runtimeType, JBOSS_AS_SERVER_NAME, JBOSS_AS_RUNTIME_NAME); - - String seamPath = SEAM_HOME_PROPERTY; - createSeamRuntime(SEAM_RUNTIME_NAME, seamPath, SeamVersion.SEAM_2_2); - - createDriver(asLocation, HSQLDB_DRIVER_LOCATION); - - activateSchell(); - - createNewSeamWebProjectWizard(PROJECT_NAME, DEPLOY_TYPE_EAR); - - createNewSeamWebProjectWizard(PROJECT_NAME_WAR, DEPLOY_TYPE_WAR); - } - - private static void initSWTBot() throws CoreException { - bot = new SWTWorkbenchBot(); - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; - SWTBotPreferences.TIMEOUT = 1000; - SWTBotPreferences.PLAYBACK_DELAY = 5; - JobUtils.waitForIdle(60000); - try { - SWTBotView view = bot.viewByTitle("Welcome"); - if (view != null) { - view.close(); - } - } catch (WidgetNotFoundException ignore) { - } - - SWTBotShell[] shells = bot.shells(); - for (SWTBotShell shell : shells) { - final Shell widget = shell.widget; - Object parent = UIThreadRunnable.syncExec(shell.display, - new Result() { - public Object run() { - return widget.isDisposed() ? null : widget.getParent(); - } - }); - if (parent == null) { - continue; - } - shell.close(); - } - - List editors = bot.editors(); - for (SWTBotEditor e : editors) { - e.close(); - } - - removeProjects(); - - WorkbenchPlugin.getDefault().getPreferenceStore() - .setValue(IPreferenceConstants.RUN_IN_BACKGROUND, true); - - PrefUtil.getAPIPreferenceStore().setValue( - IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS, false); - } - - private static void removeProjects() throws CoreException { - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - workspace.run(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - IProject[] projects = workspace.getRoot().getProjects(); - for (int i = 0; i < projects.length; i++) { - projects[i].delete(true, true, monitor); - } - } - }, new NullProgressMonitor()); - } - - private static void removeServers() throws CoreException { - IServer server = ServerCore.findServer(JBOSS_AS_SERVER_NAME); - IServerWorkingCopy wc = server.createWorkingCopy(); - IModule[] modules = wc.getModules(); - IProgressMonitor monitor = new NullProgressMonitor(); - wc.modifyModules(new IModule[] {} , modules, monitor); - wc.save(true, monitor); - server.publish(IServer.PUBLISH_INCREMENTAL, monitor); - JobUtils.waitForIdle(IDLE_TIME); - server.getRuntime().delete(); - server.delete(); - JobUtils.waitForIdle(IDLE_TIME); - } - - protected static void switchPerspective(final String pid) { - Display.getDefault().syncExec(new Runnable() { - - public void run() { - IWorkbench workbench = PlatformUI.getWorkbench(); - IPerspectiveRegistry perspectiveRegistry = workbench - .getPerspectiveRegistry(); - IPerspectiveDescriptor perspective = perspectiveRegistry - .findPerspectiveWithId(pid); - workbench.getActiveWorkbenchWindow().getActivePage() - .setPerspective(perspective); - } - }); - } - - @Before - public void setUp() throws Exception { - activateSchell(); - } - - private static void activateSchell() { - UIThreadRunnable.syncExec(new VoidResult() { - public void run() { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() - .forceActive(); - } - }); - } - - @After - public void tearDown() throws Exception { - - } - - @AfterClass - public final static void afterClass() throws Exception { - boolean buildAutomatically = ResourcesUtils.setBuildAutomatically(false); - ValidationFramework.getDefault().suspendAllValidation(true); - try { - removeServers(); - removeProjects(); - } finally { - ResourcesUtils.setBuildAutomatically(buildAutomatically); - ValidationFramework.getDefault().suspendAllValidation(false); - } - JobUtils.waitForIdle(IDLE_TIME); - } - - protected static void createJBossServer(File asLocation, String serverType, String runtimeType, String name, String runtimeName) throws CoreException { - if (!asLocation.isDirectory()) { - return; - } - IPath jbossAsLocationPath = new Path(asLocation.getAbsolutePath()); - - IServer[] servers = ServerCore.getServers(); - for (int i = 0; i < servers.length; i++) { - IRuntime runtime = servers[i].getRuntime(); - if(runtime != null && runtime.getLocation().equals(jbossAsLocationPath)) { - return; - } - } - - IRuntime runtime = null; - IRuntime[] runtimes = ServerCore.getRuntimes(); - for (int i = 0; i < runtimes.length; i++) { - if (runtimes[0].getLocation().equals(jbossAsLocationPath)) { - runtime = runtimes[0].createWorkingCopy(); - break; - } - } - - IProgressMonitor progressMonitor = new NullProgressMonitor(); - if (runtime == null) { - runtime = createRuntime(runtimeName, asLocation.getAbsolutePath(), progressMonitor, runtimeType); - } - if (runtime != null) { - createServer( runtime, serverType, name, progressMonitor); - } - } - - protected static IRuntime createRuntime(String runtimeName, String jbossASLocation, IProgressMonitor progressMonitor, String runtimeType) throws CoreException { - IRuntimeWorkingCopy runtime = null; - String type = null; - String version = null; - String runtimeId = null; - IPath jbossAsLocationPath = new Path(jbossASLocation); - IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(type, version, runtimeType); - if (runtimeTypes.length > 0) { - runtime = runtimeTypes[0].createRuntime(runtimeId, progressMonitor); - runtime.setLocation(jbossAsLocationPath); - if(runtimeName!=null) { - runtime.setName(runtimeName); - } - ((RuntimeWorkingCopy) runtime).setAttribute("org.jboss.ide.eclipse.as.core.runtime.configurationName", JBOSS_AS_DEFAULT_CONFIGURATION_NAME); //$NON-NLS-1$ - - return runtime.save(false, progressMonitor); - } - return runtime; - } - - protected static void createDriver(String jbossASLocation, String driverLocation) throws ConnectionProfileException, IOException { - if(ProfileManager.getInstance().getProfileByName(CONNECTION_PROFILE_NAME) != null) { - return; - } - String driverPath = new File(jbossASLocation + driverLocation).getCanonicalPath(); //$NON-NLS-1$ - - DriverInstance driver = DriverManager.getInstance().getDriverInstanceByName(HSQL_DRIVER_NAME); - if (driver == null) { - TemplateDescriptor descr = TemplateDescriptor.getDriverTemplateDescriptor(HSQL_DRIVER_TEMPLATE_ID); - IPropertySet instance = new PropertySetImpl(HSQL_DRIVER_NAME, HSQL_DRIVER_DEFINITION_ID); - instance.setName(HSQL_DRIVER_NAME); - instance.setID(HSQL_DRIVER_DEFINITION_ID); - Properties props = new Properties(); - - IConfigurationElement[] template = descr.getProperties(); - for (int i = 0; i < template.length; i++) { - IConfigurationElement prop = template[i]; - String id = prop.getAttribute("id"); //$NON-NLS-1$ - - String value = prop.getAttribute("value"); //$NON-NLS-1$ - props.setProperty(id, value == null ? "" : value); //$NON-NLS-1$ - } - props.setProperty(DTP_DB_URL_PROPERTY_ID, "jdbc:hsqldb:."); //$NON-NLS-1$ - props.setProperty(IDriverMgmtConstants.PROP_DEFN_TYPE, descr.getId()); - props.setProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST, driverPath); - - instance.setBaseProperties(props); - DriverManager.getInstance().removeDriverInstance(instance.getID()); - System.gc(); - DriverManager.getInstance().addDriverInstance(instance); - } - - driver = DriverManager.getInstance().getDriverInstanceByName(HSQL_DRIVER_NAME); - if (driver != null && ProfileManager.getInstance().getProfileByName(CONNECTION_PROFILE_NAME) == null) { //$NON-NLS-1$ - // create profile - Properties props = new Properties(); - props.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID, HSQL_DRIVER_DEFINITION_ID); - props.setProperty(IDBConnectionProfileConstants.CONNECTION_PROPERTIES_PROP_ID, ""); //$NON-NLS-1$ - props.setProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID)); - props.setProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID)); - props.setProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID)); - props.setProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID, "Default"); //$NON-NLS-1$ - props.setProperty(IDBDriverDefinitionConstants.PASSWORD_PROP_ID, ""); //$NON-NLS-1$ - props.setProperty(IDBConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, "false"); //$NON-NLS-1$ - props.setProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID)); - props.setProperty(IDBDriverDefinitionConstants.URL_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID)); - - ProfileManager.getInstance().createProfile(CONNECTION_PROFILE_NAME, "The JBoss AS Hypersonic embedded database", HSQL_PROFILE_ID, props, "", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - } - - protected static IServerWorkingCopy createServer(IRuntime runtime, String runtimeType, String name, IProgressMonitor progressMonitor) throws CoreException { - IServerType serverType = ServerCore.findServerType(runtimeType); - IServerWorkingCopy server = serverType.createServer(null, null, runtime, progressMonitor); - - server.setHost(JBOSS_AS_HOST); - server.setName(name); - - // JBossServer.DEPLOY_DIRECTORY - String deployVal = runtime.getLocation().append("server").append(JBOSS_AS_DEFAULT_CONFIGURATION_NAME).append("deploy").toOSString(); //$NON-NLS-1$ //$NON-NLS-2$ - ((ServerWorkingCopy) server).setAttribute("org.jboss.ide.eclipse.as.core.server.deployDirectory", deployVal); //$NON-NLS-1$ - - // IDeployableServer.TEMP_DEPLOY_DIRECTORY - String deployTmpFolderVal = runtime.getLocation().append("server").append(JBOSS_AS_DEFAULT_CONFIGURATION_NAME).append("tmp").append("jbosstoolsTemp").toOSString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ((ServerWorkingCopy) server).setAttribute("org.jboss.ide.eclipse.as.core.server.tempDeployDirectory", deployTmpFolderVal); //$NON-NLS-1$ - - // If we'd need to set up a username / pw for JMX, do it here. -// ((ServerWorkingCopy)serverWC).setAttribute(JBossServer.SERVER_USERNAME, authUser); -// ((ServerWorkingCopy)serverWC).setAttribute(JBossServer.SERVER_PASSWORD, authPass); - - server.save(false, progressMonitor); - return server; - } - - protected static void createSeamRuntime(String name, String seamPath, SeamVersion seamVersion) { - SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(name); - if (seamRuntime != null) { - return; - } - File seamFolder = new File(seamPath); - if(seamFolder.exists() && seamFolder.isDirectory()) { - SeamRuntime rt = new SeamRuntime(); - rt.setHomeDir(seamPath); - rt.setName(name); - rt.setDefault(true); - rt.setVersion(seamVersion); - SeamRuntimeManager.getInstance().addRuntime(rt); - } - } - - public static void createNewSeamWebProjectWizard(String projectName, String deployType) throws Exception { - JobUtils.waitForIdle(60000); - bot.menu("File").menu("New").menu("Seam Web Project").click(); - - SWTBotShell mainShell = bot.shell("New Seam Project"); - mainShell.activate(); - - bot.textWithLabel("Project name:").setText(projectName); - bot.button("Modify...").click(); - SWTBotShell shell = bot.shell("Project Facets"); - shell.activate(); - - SWTBotTree treeWidget = bot.tree(); - SWTBotTreeItem jmi = treeWidget.getTreeItem("JBoss Maven Integration"); - jmi.check(); - - bot.button("OK").click(); - - mainShell.activate(); - - bot.comboBox(0).setSelection(JBOSS_AS_RUNTIME_NAME); - bot.comboBox(2).setSelection(JBOSS_AS_SERVER_NAME); - - bot.button("Next >").click(); - bot.button("Next >").click(); - bot.button("Next >").click(); - bot.button("Next >").click(); - - bot.comboBox(0).setSelection("Library Provided by Target Runtime"); - bot.button("Next >").click(); - - bot.comboBox(0).setSelection(SEAM_RUNTIME_NAME); - bot.radio(deployType).click(); - bot.comboBox(1).setSelection("HSQL"); - bot.comboBox(2).setSelection(CONNECTION_PROFILE_NAME); - bot.button("Finish").click(); - - JobUtils.waitForIdle(60000); - - } - - @Test - public void testErrors() throws Exception { - checkErrors(PROJECT_NAME); - checkErrors(EAR_PROJECT_NAME); - checkErrors(EJB_PROJECT_NAME); - checkErrors(TEST_PROJECT_NAME); - checkErrors(PARENT_PROJECT_NAME); - checkErrors(PROJECT_NAME_WAR); - checkErrors(TEST_PROJECT_NAME_WAR); - checkErrors(PARENT_PROJECT_NAME_WAR); - } - - private void checkErrors(String projectName) throws CoreException { - List markers = new ArrayList(); - IProject project = ResourcesPlugin.getWorkspace().getRoot() - .getProject(projectName); - IMarker[] projectMarkers = project.findMarkers(IMarker.PROBLEM, true, - IResource.DEPTH_INFINITE); - for (int i = 0; i < projectMarkers.length; i++) { - if (projectMarkers[i].getAttribute(IMarker.SEVERITY, - IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR) { - markers.add(projectMarkers[i]); - } - } - assertTrue("The '" + projectName + "' contains errors.", markers.size() == 0); - } - - @Test - public void testMavenProjects() throws Exception { - isMavenProject(PROJECT_NAME); - isMavenProject(EAR_PROJECT_NAME); - isMavenProject(EJB_PROJECT_NAME); - isMavenProject(TEST_PROJECT_NAME); - isMavenProject(PARENT_PROJECT_NAME); - isMavenProject(PROJECT_NAME_WAR); - isMavenProject(TEST_PROJECT_NAME_WAR); - isMavenProject(PARENT_PROJECT_NAME_WAR); - } - - private void isMavenProject(String projectName) throws CoreException { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - assertTrue("The '" + projectName + "' project isn't a Maven project.", project.hasNature(IMavenConstants.NATURE_ID)); - } - - // see https://jira.jboss.org/browse/JBIDE-6587 - @Test - public void testMavenWarArchive() throws Exception { - final SWTBotView packageExplorer = bot.viewByTitle(PACKAGE_EXPLORER); - SWTBot innerBot = packageExplorer.bot(); - innerBot.activeShell().activate(); - final SWTBotTree tree = innerBot.tree(); - final SWTBotTreeItem warProjectItem = tree.getTreeItem(PROJECT_NAME_WAR); - warProjectItem.select(); - - SWTBotMenu runAs = tree.contextMenu("Run As"); - runAs.menu("6 Maven build...").click(); - - SWTBotShell shell = bot.shell("Edit Configuration"); - shell.activate(); - - bot.textWithLabel("Goals:").setText("clean package"); - bot.button("Run").click(); - - JobUtils.waitForIdle(IDLE_TIME); - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME_WAR); - project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); - IPath webInfPath = new Path("target/" + PROJECT_NAME_WAR + "-0.0.1-SNAPSHOT/WEB-INF"); - assertFalse(project.getFolder(webInfPath.append("src")).exists()); - assertFalse(project.getFolder(webInfPath.append("dev")).exists()); - assertTrue(project.getFolder(webInfPath.append("lib")).exists()); - - } - - // see https://jira.jboss.org/browse/JBIDE-6767 - @Test - public void testLibraries() throws Exception { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(EAR_PROJECT_NAME); - File rootDirectory = new File(project.getLocation().toOSString(), "EarContent"); - String[] libs = rootDirectory.list(new FilenameFilter() { - - public boolean accept(File dir, String name) { - if (name.endsWith(".jar")) { - return true; - } - return false; - } - }); - assertTrue(libs.length == 0); - File libDirectory = new File (rootDirectory,"lib"); - if (libDirectory.isDirectory()) { - libs = libDirectory.list(new FilenameFilter() { - - public boolean accept(File dir, String name) { - if (name.endsWith(".jar")) { - return true; - } - return false; - } - }); - assertTrue(libs.length == 0); - } - } - -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ + +package org.jboss.tools.maven.ui.bot.test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.datatools.connectivity.ConnectionProfileConstants; +import org.eclipse.datatools.connectivity.ConnectionProfileException; +import org.eclipse.datatools.connectivity.ProfileManager; +import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants; +import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants; +import org.eclipse.datatools.connectivity.drivers.DriverInstance; +import org.eclipse.datatools.connectivity.drivers.DriverManager; +import org.eclipse.datatools.connectivity.drivers.IDriverMgmtConstants; +import org.eclipse.datatools.connectivity.drivers.IPropertySet; +import org.eclipse.datatools.connectivity.drivers.PropertySetImpl; +import org.eclipse.datatools.connectivity.drivers.models.TemplateDescriptor; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.results.Result; +import org.eclipse.swtbot.swt.finder.results.VoidResult; +import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IPerspectiveRegistry; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferenceConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.IPreferenceConstants; +import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.internal.util.PrefUtil; +import org.eclipse.wst.server.core.IModule; +import org.eclipse.wst.server.core.IRuntime; +import org.eclipse.wst.server.core.IRuntimeType; +import org.eclipse.wst.server.core.IRuntimeWorkingCopy; +import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.IServerType; +import org.eclipse.wst.server.core.IServerWorkingCopy; +import org.eclipse.wst.server.core.ServerCore; +import org.eclipse.wst.server.core.ServerUtil; +import org.eclipse.wst.server.core.internal.RuntimeWorkingCopy; +import org.eclipse.wst.server.core.internal.ServerWorkingCopy; +import org.eclipse.wst.validation.ValidationFramework; +import org.jboss.tools.seam.core.project.facet.SeamRuntime; +import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager; +import org.jboss.tools.seam.core.project.facet.SeamVersion; +import org.jboss.tools.test.util.ResourcesUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author Snjeza + * + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class CreateMavenizedSeamProjectTest { + + protected static final long IDLE_TIME = 20 * 60 * 1000L; + + private static final String CONNECTION_PROFILE_NAME = "DefaultDS"; + + private static final String SEAM_RUNTIME_NAME = "Seam 2.2"; + + private static final String JBOSS_AS_RUNTIME_NAME = "JBoss AS 5.1 Runtime"; + + public static final String PACKAGE_EXPLORER = "Package Explorer"; //$NON-NLS-1$ + + private static final String JBOSS_AS_SERVER_NAME = "JBoss AS 5.1 Server"; + + public static final String JBOSS_AS_HOST = "localhost"; //$NON-NLS-1$ + + public static final String JBOSS_AS_DEFAULT_CONFIGURATION_NAME = "default"; //$NON-NLS-1$ + + public static final String HSQL_DRIVER_DEFINITION_ID + = "DriverDefn.Hypersonic DB"; //$NON-NLS-1$ + + public static final String HSQL_DRIVER_NAME = "Hypersonic DB"; //$NON-NLS-1$ + + public static final String HSQL_DRIVER_TEMPLATE_ID + = "org.eclipse.datatools.enablement.hsqldb.1_8.driver"; //$NON-NLS-1$ + + public static final String DTP_DB_URL_PROPERTY_ID + = "org.eclipse.datatools.connectivity.db.URL"; //$NON-NLS-1$ + + public static final String HSQL_PROFILE_ID = "org.eclipse.datatools.enablement.hsqldb.connectionProfile"; + + public static final String JBOSS_AS_HOME = System.getProperty("jbosstools.test.jboss.home.5.1", "E:\\JBossRuntimes\\jboss-5.1.0.GA"); + + public static final String JBOSS_AS_RUNTIME_ID = "org.jboss.ide.eclipse.as.runtime.51"; + + public static final String JBOSS_AS_SERVER_ID = "org.jboss.ide.eclipse.as.51"; + + public static final String SEAM_HOME_PROPERTY = System.getProperty("jbosstools.test.seam.2.0.1.GA.home", "E:\\JBossRuntimes\\jboss-seam-2.2.1.CR3"); + + public static final String HSQLDB_DRIVER_JAR_NAME = "hsqldb.jar"; //$NON-NLS-1$ + + public static final String HSQLDB_DRIVER_LOCATION = "/common/lib/" + HSQLDB_DRIVER_JAR_NAME; //$NON-NLS-1$ + + public static final String PROJECT_NAME_WAR = "MavenizedSeamProjectWar"; + + public static final String TEST_PROJECT_NAME_WAR = "MavenizedSeamProjectWar-test"; + + public static final String PARENT_PROJECT_NAME_WAR = "MavenizedSeamProjectWar-parent"; + + + public static final String PROJECT_NAME = "MavenizedSeamProject"; + + public static final String EAR_PROJECT_NAME = "MavenizedSeamProject-ear"; + + public static final String EJB_PROJECT_NAME = "MavenizedSeamProject-ejb"; + + public static final String TEST_PROJECT_NAME = "MavenizedSeamProject-test"; + + public static final String PARENT_PROJECT_NAME = "MavenizedSeamProject-parent"; + + public static final String DEPLOY_TYPE_EAR = "EAR"; + + public static final String DEPLOY_TYPE_WAR = "WAR"; + + protected static SWTWorkbenchBot bot; + + @BeforeClass + public final static void beforeClass() throws Exception { + initSWTBot(); + + switchPerspective("org.jboss.tools.seam.ui.SeamPerspective"); + + String asLocation = JBOSS_AS_HOME; + + String runtimeType = JBOSS_AS_RUNTIME_ID; + String serverType = JBOSS_AS_SERVER_ID; + System.out.println("Creating a server from "+asLocation); + createJBossServer(new File(asLocation), serverType, runtimeType, JBOSS_AS_SERVER_NAME, JBOSS_AS_RUNTIME_NAME); + + String seamPath = SEAM_HOME_PROPERTY; + System.out.println("Using seam from "+seamPath); + createSeamRuntime(SEAM_RUNTIME_NAME, seamPath, SeamVersion.SEAM_2_2); + + createDriver(asLocation, HSQLDB_DRIVER_LOCATION); + + activateSchell(); + + createNewSeamWebProjectWizard(PROJECT_NAME, DEPLOY_TYPE_EAR); + + createNewSeamWebProjectWizard(PROJECT_NAME_WAR, DEPLOY_TYPE_WAR); + } + + private static void initSWTBot() throws CoreException { + bot = new SWTWorkbenchBot(); + SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; + SWTBotPreferences.TIMEOUT = 1000; + SWTBotPreferences.PLAYBACK_DELAY = 5; + waitForIdle(); + try { + SWTBotView view = bot.viewByTitle("Welcome"); + if (view != null) { + view.close(); + } + } catch (WidgetNotFoundException ignore) { + } + + SWTBotShell[] shells = bot.shells(); + for (SWTBotShell shell : shells) { + final Shell widget = shell.widget; + Object parent = UIThreadRunnable.syncExec(shell.display, + new Result() { + public Object run() { + return widget.isDisposed() ? null : widget.getParent(); + } + }); + if (parent == null) { + continue; + } + shell.close(); + } + + List editors = bot.editors(); + for (SWTBotEditor e : editors) { + e.close(); + } + + removeProjects(); + + WorkbenchPlugin.getDefault().getPreferenceStore() + .setValue(IPreferenceConstants.RUN_IN_BACKGROUND, true); + + PrefUtil.getAPIPreferenceStore().setValue( + IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS, false); + } + + private static void removeProjects() throws CoreException { + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + IProject[] projects = workspace.getRoot().getProjects(); + for (int i = 0; i < projects.length; i++) { + projects[i].delete(true, true, monitor); + } + } + }, new NullProgressMonitor()); + } + + private static void removeServers() throws CoreException { + IServer server = ServerCore.findServer(JBOSS_AS_SERVER_NAME); + IServerWorkingCopy wc = server.createWorkingCopy(); + IModule[] modules = wc.getModules(); + IProgressMonitor monitor = new NullProgressMonitor(); + wc.modifyModules(new IModule[] {} , modules, monitor); + wc.save(true, monitor); + server.publish(IServer.PUBLISH_INCREMENTAL, monitor); + waitForIdle(); + server.getRuntime().delete(); + server.delete(); + waitForIdle(); + } + + protected static void switchPerspective(final String pid) { + Display.getDefault().syncExec(new Runnable() { + + public void run() { + IWorkbench workbench = PlatformUI.getWorkbench(); + IPerspectiveRegistry perspectiveRegistry = workbench + .getPerspectiveRegistry(); + IPerspectiveDescriptor perspective = perspectiveRegistry + .findPerspectiveWithId(pid); + workbench.getActiveWorkbenchWindow().getActivePage() + .setPerspective(perspective); + } + }); + } + + @Before + public void setUp() throws Exception { + activateSchell(); + } + + private static void activateSchell() { + UIThreadRunnable.syncExec(new VoidResult() { + public void run() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() + .forceActive(); + } + }); + } + + @After + public void tearDown() throws Exception { + + } + + @AfterClass + public final static void afterClass() throws Exception { + boolean buildAutomatically = ResourcesUtils.setBuildAutomatically(false); + ValidationFramework.getDefault().suspendAllValidation(true); + try { + removeServers(); + removeProjects(); + } finally { + ResourcesUtils.setBuildAutomatically(buildAutomatically); + ValidationFramework.getDefault().suspendAllValidation(false); + } + waitForIdle(); + } + + protected static void createJBossServer(File asLocation, String serverType, String runtimeType, String name, String runtimeName) throws CoreException { + if (!asLocation.isDirectory()) { + return; + } + IPath jbossAsLocationPath = new Path(asLocation.getAbsolutePath()); + + IServer[] servers = ServerCore.getServers(); + for (int i = 0; i < servers.length; i++) { + IRuntime runtime = servers[i].getRuntime(); + if(runtime != null && runtime.getLocation().equals(jbossAsLocationPath)) { + return; + } + } + + IRuntime runtime = null; + IRuntime[] runtimes = ServerCore.getRuntimes(); + for (int i = 0; i < runtimes.length; i++) { + if (runtimes[0].getLocation().equals(jbossAsLocationPath)) { + runtime = runtimes[0].createWorkingCopy(); + break; + } + } + + IProgressMonitor progressMonitor = new NullProgressMonitor(); + if (runtime == null) { + runtime = createRuntime(runtimeName, asLocation.getAbsolutePath(), progressMonitor, runtimeType); + } + if (runtime != null) { + createServer( runtime, serverType, name, progressMonitor); + } + } + + protected static IRuntime createRuntime(String runtimeName, String jbossASLocation, IProgressMonitor progressMonitor, String runtimeType) throws CoreException { + IRuntimeWorkingCopy runtime = null; + String type = null; + String version = null; + String runtimeId = null; + IPath jbossAsLocationPath = new Path(jbossASLocation); + IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(type, version, runtimeType); + if (runtimeTypes.length > 0) { + runtime = runtimeTypes[0].createRuntime(runtimeId, progressMonitor); + runtime.setLocation(jbossAsLocationPath); + if(runtimeName!=null) { + runtime.setName(runtimeName); + } + ((RuntimeWorkingCopy) runtime).setAttribute("org.jboss.ide.eclipse.as.core.runtime.configurationName", JBOSS_AS_DEFAULT_CONFIGURATION_NAME); //$NON-NLS-1$ + + return runtime.save(false, progressMonitor); + } + return runtime; + } + + protected static void createDriver(String jbossASLocation, String driverLocation) throws ConnectionProfileException, IOException { + if(ProfileManager.getInstance().getProfileByName(CONNECTION_PROFILE_NAME) != null) { + return; + } + String driverPath = new File(jbossASLocation + driverLocation).getCanonicalPath(); //$NON-NLS-1$ + + DriverInstance driver = DriverManager.getInstance().getDriverInstanceByName(HSQL_DRIVER_NAME); + if (driver == null) { + TemplateDescriptor descr = TemplateDescriptor.getDriverTemplateDescriptor(HSQL_DRIVER_TEMPLATE_ID); + IPropertySet instance = new PropertySetImpl(HSQL_DRIVER_NAME, HSQL_DRIVER_DEFINITION_ID); + instance.setName(HSQL_DRIVER_NAME); + instance.setID(HSQL_DRIVER_DEFINITION_ID); + Properties props = new Properties(); + + IConfigurationElement[] template = descr.getProperties(); + for (int i = 0; i < template.length; i++) { + IConfigurationElement prop = template[i]; + String id = prop.getAttribute("id"); //$NON-NLS-1$ + + String value = prop.getAttribute("value"); //$NON-NLS-1$ + props.setProperty(id, value == null ? "" : value); //$NON-NLS-1$ + } + props.setProperty(DTP_DB_URL_PROPERTY_ID, "jdbc:hsqldb:."); //$NON-NLS-1$ + props.setProperty(IDriverMgmtConstants.PROP_DEFN_TYPE, descr.getId()); + props.setProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST, driverPath); + + instance.setBaseProperties(props); + DriverManager.getInstance().removeDriverInstance(instance.getID()); + System.gc(); + DriverManager.getInstance().addDriverInstance(instance); + } + + driver = DriverManager.getInstance().getDriverInstanceByName(HSQL_DRIVER_NAME); + if (driver != null && ProfileManager.getInstance().getProfileByName(CONNECTION_PROFILE_NAME) == null) { //$NON-NLS-1$ + // create profile + Properties props = new Properties(); + props.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID, HSQL_DRIVER_DEFINITION_ID); + props.setProperty(IDBConnectionProfileConstants.CONNECTION_PROPERTIES_PROP_ID, ""); //$NON-NLS-1$ + props.setProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID)); + props.setProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID)); + props.setProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID)); + props.setProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID, "Default"); //$NON-NLS-1$ + props.setProperty(IDBDriverDefinitionConstants.PASSWORD_PROP_ID, ""); //$NON-NLS-1$ + props.setProperty(IDBConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, "false"); //$NON-NLS-1$ + props.setProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID)); + props.setProperty(IDBDriverDefinitionConstants.URL_PROP_ID, driver.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID)); + + ProfileManager.getInstance().createProfile(CONNECTION_PROFILE_NAME, "The JBoss AS Hypersonic embedded database", HSQL_PROFILE_ID, props, "", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + } + + protected static IServerWorkingCopy createServer(IRuntime runtime, String runtimeType, String name, IProgressMonitor progressMonitor) throws CoreException { + IServerType serverType = ServerCore.findServerType(runtimeType); + IServerWorkingCopy server = serverType.createServer(null, null, runtime, progressMonitor); + + server.setHost(JBOSS_AS_HOST); + server.setName(name); + + // JBossServer.DEPLOY_DIRECTORY + String deployVal = runtime.getLocation().append("server").append(JBOSS_AS_DEFAULT_CONFIGURATION_NAME).append("deploy").toOSString(); //$NON-NLS-1$ //$NON-NLS-2$ + ((ServerWorkingCopy) server).setAttribute("org.jboss.ide.eclipse.as.core.server.deployDirectory", deployVal); //$NON-NLS-1$ + + // IDeployableServer.TEMP_DEPLOY_DIRECTORY + String deployTmpFolderVal = runtime.getLocation().append("server").append(JBOSS_AS_DEFAULT_CONFIGURATION_NAME).append("tmp").append("jbosstoolsTemp").toOSString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + ((ServerWorkingCopy) server).setAttribute("org.jboss.ide.eclipse.as.core.server.tempDeployDirectory", deployTmpFolderVal); //$NON-NLS-1$ + + // If we'd need to set up a username / pw for JMX, do it here. +// ((ServerWorkingCopy)serverWC).setAttribute(JBossServer.SERVER_USERNAME, authUser); +// ((ServerWorkingCopy)serverWC).setAttribute(JBossServer.SERVER_PASSWORD, authPass); + + server.save(false, progressMonitor); + return server; + } + + protected static void createSeamRuntime(String name, String seamPath, SeamVersion seamVersion) { + SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(name); + if (seamRuntime != null) { + return; + } + File seamFolder = new File(seamPath); + if(seamFolder.exists() && seamFolder.isDirectory()) { + SeamRuntime rt = new SeamRuntime(); + rt.setHomeDir(seamPath); + rt.setName(name); + rt.setDefault(true); + rt.setVersion(seamVersion); + SeamRuntimeManager.getInstance().addRuntime(rt); + } + } + + public static void createNewSeamWebProjectWizard(String projectName, String deployType) throws Exception { + waitForIdle(); + bot.menu("File").menu("New").menu("Seam Web Project").click(); + + SWTBotShell mainShell = bot.shell("New Seam Project"); + mainShell.activate(); + + bot.textWithLabel("Project name:").setText(projectName); + bot.button("Modify...").click(); + SWTBotShell shell = bot.shell("Project Facets"); + shell.activate(); + + SWTBotTree treeWidget = bot.tree(); + SWTBotTreeItem jmi = treeWidget.getTreeItem("JBoss Maven Integration"); + jmi.check(); + + bot.button("OK").click(); + + mainShell.activate(); + + bot.comboBox(0).setSelection(JBOSS_AS_RUNTIME_NAME); + bot.comboBox(2).setSelection(JBOSS_AS_SERVER_NAME); + + bot.button("Next >").click(); + bot.button("Next >").click(); + bot.button("Next >").click(); + bot.button("Next >").click(); + + bot.comboBox(0).setSelection("Library Provided by Target Runtime"); + bot.button("Next >").click(); + + bot.comboBox(0).setSelection(SEAM_RUNTIME_NAME); + String otherType = DEPLOY_TYPE_EAR; + if (DEPLOY_TYPE_EAR.equals(deployType)) { + otherType = DEPLOY_TYPE_WAR; + } + final SWTBotRadio radio = bot.radio(deployType); + final SWTBotRadio otherRadio = bot.radio(otherType); + radio.click(); + Display.getDefault().syncExec(new Runnable() { + + public void run() { + radio.widget.setSelection(true); + otherRadio.widget.setSelection(false); + Event event = new Event(); + event.time = (int) System.currentTimeMillis(); + event.widget = radio.widget; + event.display = Display.getCurrent(); + radio.widget.notifyListeners(SWT.Selection, event); + } + }); + + bot.comboBox(1).setSelection("HSQL"); + bot.comboBox(2).setSelection(CONNECTION_PROFILE_NAME); + bot.button("Finish").click(); + + waitForIdle(); + + } + + @Test + public void testAsLocation() { + String asLocation = JBOSS_AS_HOME; + assertTrue("Invalid JBoss AS location:" + asLocation, new File(asLocation).isDirectory()); + } + + @Test + public void testSeamLocation() { + String seamLocation = SEAM_HOME_PROPERTY; + assertTrue("Invalid Seam Runtime location:" + seamLocation, new File(seamLocation).isDirectory()); + } + + @Test + public void testErrors() throws Exception { + checkErrors(PROJECT_NAME); + checkErrors(EAR_PROJECT_NAME); + checkErrors(EJB_PROJECT_NAME); + checkErrors(TEST_PROJECT_NAME); + checkErrors(PARENT_PROJECT_NAME); + checkErrors(PROJECT_NAME_WAR); + checkErrors(TEST_PROJECT_NAME_WAR); + checkErrors(PARENT_PROJECT_NAME_WAR); + } + + private void checkErrors(String projectName) throws CoreException { + List markers = new ArrayList(); + IProject project = ResourcesPlugin.getWorkspace().getRoot() + .getProject(projectName); + IMarker[] projectMarkers = project.findMarkers(IMarker.PROBLEM, true, + IResource.DEPTH_INFINITE); + for (int i = 0; i < projectMarkers.length; i++) { + if (projectMarkers[i].getAttribute(IMarker.SEVERITY, + IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR) { + if (!"org.eclipse.m2e.core.maven2Problem.lifecycleMapping".equals(projectMarkers[i].getType())) { + markers.add(projectMarkers[i]); + } + } + } + assertTrue("The '" + projectName + "' contains errors.", markers.size() == 0); + } + + @Test + public void testMavenProjects() throws Exception { + isMavenProject(PROJECT_NAME); + isMavenProject(EAR_PROJECT_NAME); + isMavenProject(EJB_PROJECT_NAME); + isMavenProject(TEST_PROJECT_NAME); + isMavenProject(PARENT_PROJECT_NAME); + isMavenProject(PROJECT_NAME_WAR); + isMavenProject(TEST_PROJECT_NAME_WAR); + isMavenProject(PARENT_PROJECT_NAME_WAR); + } + + private void isMavenProject(String projectName) throws CoreException { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + assertTrue("The '" + projectName + "' project isn't a Maven project.", project.hasNature(IMavenConstants.NATURE_ID)); + } + + // see https://jira.jboss.org/browse/JBIDE-6587 + @Test + public void testMavenWarArchive() throws Exception { + final SWTBotView packageExplorer = bot.viewByTitle(PACKAGE_EXPLORER); + SWTBot innerBot = packageExplorer.bot(); + innerBot.activeShell().activate(); + final SWTBotTree tree = innerBot.tree(); + final SWTBotTreeItem warProjectItem = tree.getTreeItem(PROJECT_NAME_WAR); + warProjectItem.select(); + + SWTBotMenu runAs = tree.contextMenu("Run As"); + runAs.menu("5 Maven build...").click(); + + SWTBotShell shell = bot.shell("Edit Configuration"); + shell.activate(); + + bot.textWithLabel("Goals:").setText("clean package"); + bot.button("Run").click(); + + waitForIdle(); + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME_WAR); + project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + IPath webInfPath = new Path("target/" + PROJECT_NAME_WAR + "-0.0.1-SNAPSHOT/WEB-INF"); + assertFalse(project.getFolder(webInfPath.append("src")).exists()); + assertFalse(project.getFolder(webInfPath.append("dev")).exists()); + assertTrue(project.getFolder(webInfPath.append("lib")).exists()); + + } + + private static void waitForIdle() { + long start = System.currentTimeMillis(); + int delay = 50; + while (!Job.getJobManager().isIdle()) { + delay(delay); + if ((System.currentTimeMillis() - start) > IDLE_TIME) { + Job[] jobs = Job.getJobManager().find(null); + StringBuffer str = new StringBuffer(); + for (Job job : jobs) { + if (job.getThread() != null) { + str.append("\n").append(job.getName()).append(" (") + .append(job.getClass()).append(")"); + } + } + throw new RuntimeException( + "Long running tasks detected:" + str.toString()); //$NON-NLS-1$ + } + } + } + + public static void delay(long waitTimeMillis) { + Display display = Display.getCurrent(); + if (display != null) { + long endTimeMillis = System.currentTimeMillis() + waitTimeMillis; + while (System.currentTimeMillis() < endTimeMillis) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.update(); + } + // Otherwise, perform a simple sleep. + else { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + // Ignored. + } + } + } + + // see https://jira.jboss.org/browse/JBIDE-6767 + @Test + public void testLibraries() throws Exception { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(EAR_PROJECT_NAME); + File rootDirectory = new File(project.getLocation().toOSString(), "EarContent"); + String[] libs = rootDirectory.list(new FilenameFilter() { + + public boolean accept(File dir, String name) { + if (name.endsWith(".jar")) { + return true; + } + return false; + } + }); + assertTrue(libs.length == 0); + File libDirectory = new File (rootDirectory,"lib"); + if (libDirectory.isDirectory()) { + libs = libDirectory.list(new FilenameFilter() { + + public boolean accept(File dir, String name) { + if (name.endsWith(".jar")) { + return true; + } + return false; + } + }); + assertTrue(libs.length == 0); + } + } + +} Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,15 +1,17 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + tests + 0.0.1-SNAPSHOT org.jboss.tools.maven.tests - org.jboss.tools.maven.ui.bot.test + org.jboss.tools.maven.ui.bot.test 1.0.0-SNAPSHOT eclipse-test-plugin + -Djbosstools.test.jboss.home.5.1=${requirement.build.root}/jboss-5.1.0.GA -Djbosstools.test.seam.2.0.1.GA.home=${requirement.build.root}/jboss-seam-2.2.0.GA @@ -23,9 +25,9 @@ false true org.jboss.tools.maven.ui.bot.test - org.jboss.tools.maven.ui.bot.test.MavenAllBotTests + org.jboss.tools.maven.ui.bot.test.MavenAllBotTests - + \ No newline at end of file #P org.jboss.tools.maven.portlet Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.portlet - 1.0.0-SNAPSHOT + org.jboss.tools.maven.portlet + 1.2.0-SNAPSHOT eclipse-plugin - + \ No newline at end of file Index: src/org/jboss/tools/maven/portlet/MavenPortletActivator.java =================================================================== --- src/org/jboss/tools/maven/portlet/MavenPortletActivator.java (revision 32782) +++ src/org/jboss/tools/maven/portlet/MavenPortletActivator.java (working copy) @@ -1,63 +1,73 @@ -package org.jboss.tools.maven.portlet; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class MavenPortletActivator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.jboss.tools.maven.portlet"; //$NON-NLS-1$ - - // The shared instance - private static MavenPortletActivator plugin; - - /** - * The constructor - */ - public MavenPortletActivator() { - } - - /* - * (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); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static MavenPortletActivator getDefault() { - return plugin; - } - - - public static void log(Throwable e) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e - .getLocalizedMessage(), e); - getDefault().getLog().log(status); - } - - public static void log(String message) { - IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message, null); - getDefault().getLog().log(status); - } -} +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.portlet; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class MavenPortletActivator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.maven.portlet"; //$NON-NLS-1$ + + // The shared instance + private static MavenPortletActivator plugin; + + /** + * The constructor + */ + public MavenPortletActivator() { + } + + /* + * (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); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static MavenPortletActivator getDefault() { + return plugin; + } + + + public static void log(Throwable e) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e + .getLocalizedMessage(), e); + getDefault().getLog().log(status); + } + + public static void log(String message) { + IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message, null); + getDefault().getLog().log(status); + } +} Index: build.properties =================================================================== --- build.properties (revision 32782) +++ build.properties (working copy) @@ -1,11 +1,12 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - plugin.properties,\ - about.html,\ - about.ini,\ - about.mappings,\ - about.properties,\ - jboss_about.png +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html,\ + about.ini,\ + about.mappings,\ + about.properties,\ + jboss_about.png,\ + lifecycle-mapping-metadata.xml Index: lifecycle-mapping-metadata.xml =================================================================== --- lifecycle-mapping-metadata.xml (revision 0) +++ lifecycle-mapping-metadata.xml (revision 0) @@ -0,0 +1,22 @@ + + + + + + + org.apache.maven.plugins + maven-war-plugin + [1.0,) + + war + + + + + org.jboss.tools.maven.portlet.configurator + + + + + + \ No newline at end of file Index: src/org/jboss/tools/maven/portlet/configurators/PortletProjectConfigurator.java =================================================================== --- src/org/jboss/tools/maven/portlet/configurators/PortletProjectConfigurator.java (revision 32782) +++ src/org/jboss/tools/maven/portlet/configurators/PortletProjectConfigurator.java (working copy) @@ -1,170 +1,185 @@ -package org.jboss.tools.maven.portlet.configurators; - -import org.apache.maven.project.MavenProject; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -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.jboss.tools.maven.core.IJBossMavenConstants; -import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; -import org.jboss.tools.maven.ui.Activator; -import org.jboss.tools.maven.portlet.MavenPortletActivator; -import org.jboss.tools.maven.portlet.Messages; -import org.jboss.tools.portlet.core.IPortletConstants; -import org.jboss.tools.portlet.core.internal.project.facet.JSFPortletFacetInstallDataModelProvider; -import org.jboss.tools.portlet.core.internal.project.facet.PortletFacetInstallDataModelProvider; -import org.maven.ide.eclipse.project.IMavenProjectFacade; -import org.maven.ide.eclipse.project.MavenProjectChangedEvent; -import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator; -import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest; - -public class PortletProjectConfigurator extends AbstractProjectConfigurator { - - private static final String PORTLET_API_GROUP_ID = "javax.portlet"; //$NON-NLS-1$ - private static final String PORTLET_API_ARTIFACT_ID = "portlet-api"; //$NON-NLS-1$ - - private static final String PORTLETBRIDGE_API_GROUP_ID = "org.jboss.portletbridge"; //$NON-NLS-1$ - private static final String PORTLETBRIDGE_API_ARTIFACT_ID = "portletbridge-api"; //$NON-NLS-1$ - - protected static final IProjectFacet dynamicWebFacet; - protected static final IProjectFacetVersion dynamicWebVersion; - - protected static final IProjectFacet jsfFacet; - protected static final IProjectFacet portletFacet; - protected static final IProjectFacetVersion portletVersion10; - protected static final IProjectFacetVersion portletVersion20; - protected static final IProjectFacet m2Facet; - protected static final IProjectFacetVersion m2Version; - protected static final IProjectFacetVersion jsfportletFacetVersion; - - static { - dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ - dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ - portletFacet = ProjectFacetsManager.getProjectFacet("jboss.portlet"); //$NON-NLS-1$ - portletVersion20 = portletFacet.getVersion("2.0"); //$NON-NLS-1$ - portletVersion10 = portletFacet.getVersion("1.0"); //$NON-NLS-1$ - m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ - m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ - jsfFacet = ProjectFacetsManager.getProjectFacet("jst.jsf"); //$NON-NLS-1$ - jsfportletFacetVersion = ProjectFacetsManager.getProjectFacet("jboss.jsfportlet").getVersion("1.0"); //$NON-NLS-1$//$NON-NLS-2$ - } - - @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { - MavenProject mavenProject = request.getMavenProject(); - IProject project = request.getProject(); - configureInternal(mavenProject,project, monitor); - } - - private void configureInternal(MavenProject mavenProject,IProject project, - IProgressMonitor monitor) throws CoreException { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - boolean configurePortlet = store.getBoolean(Activator.CONFIGURE_PORTLET); - if (!configurePortlet) { - return; - } - - String packaging = mavenProject.getPackaging(); - String portletVersion = Activator.getDefault().getDependencyVersion(mavenProject, PORTLET_API_GROUP_ID, PORTLET_API_ARTIFACT_ID); - String jsfportletVersion = Activator.getDefault().getDependencyVersion(mavenProject, PORTLETBRIDGE_API_GROUP_ID, PORTLETBRIDGE_API_ARTIFACT_ID); - if (portletVersion != null) { - final IFacetedProject fproj = ProjectFacetsManager.create(project); - if (fproj != null && "war".equals(packaging)) { //$NON-NLS-1$ - installWarFacets(fproj, portletVersion, jsfportletVersion, monitor); - } - } - } - - - @Override - public void mavenProjectChanged(MavenProjectChangedEvent event, - IProgressMonitor monitor) throws CoreException { - IMavenProjectFacade facade = event.getMavenProject(); - if(facade != null) { - IProject project = facade.getProject(); - if(isWTPProject(project)) { - MavenProject mavenProject = facade.getMavenProject(monitor); - configureInternal(mavenProject, project, monitor); - } - } - super.mavenProjectChanged(event, monitor); - } - - private boolean isWTPProject(IProject project) { - return ModuleCoreNature.getModuleCoreNature(project) != null; - } - - private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) throws CoreException { - if (!fproj.hasProjectFacet(m2Facet)) { - IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider().create(); - config.setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); - fproj.installProjectFacet(m2Version, config, monitor); - } - } - - - private void installWarFacets(IFacetedProject fproj, String portletVersion, String jsfportletVersion, IProgressMonitor monitor) throws CoreException { - - if (!fproj.hasProjectFacet(dynamicWebFacet)) { - MavenPortletActivator.log(Messages.PortletProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet); - } - installM2Facet(fproj, monitor); - installPortletFacet(fproj, portletVersion, jsfportletVersion, monitor); - } - - - private void installPortletFacet(IFacetedProject fproj, String portletVersionString, String jsfportletVersion, IProgressMonitor monitor) - throws CoreException { - if (!fproj.hasProjectFacet(portletFacet)) { - if (portletVersionString.startsWith("1.0")) { //$NON-NLS-1$ - IDataModel model = createPortletDataModel(fproj, portletVersion10); - fproj.installProjectFacet(portletVersion10, model, monitor); - } - if (portletVersionString.startsWith("2.0")) { //$NON-NLS-1$ - IDataModel model = createPortletDataModel(fproj, portletVersion20); - fproj.installProjectFacet(portletVersion20, model, monitor); - } - } - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - boolean configureJSFPortlet = store.getBoolean(Activator.CONFIGURE_JSFPORTLET); - if (!configureJSFPortlet) { - return; - } - if (fproj.hasProjectFacet(portletFacet) && fproj.hasProjectFacet(jsfFacet) && jsfportletVersion != null) { - - if (!fproj.hasProjectFacet(jsfportletFacetVersion)) { - IDataModel model = createJSFPortletDataModel(fproj, jsfportletFacetVersion); - fproj.installProjectFacet(jsfportletFacetVersion, model, monitor); - } - - } - } - - private IDataModel createPortletDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { - IDataModel config = (IDataModel) new PortletFacetInstallDataModelProvider().create(); - LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(fproj, facetVersion); - ILibraryProvider provider = LibraryProviderFramework.getProvider("portlet-no-op-library-provider"); //$NON-NLS-1$ - libraryDelegate.setLibraryProvider(provider); - config.setProperty(IPortletConstants.PORTLET_LIBRARY_PROVIDER_DELEGATE, libraryDelegate); - return config; - } - - private IDataModel createJSFPortletDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { - IDataModel config = (IDataModel) new JSFPortletFacetInstallDataModelProvider().create(); - LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(fproj, facetVersion); - ILibraryProvider provider = LibraryProviderFramework.getProvider("jsfportlet-no-op-library-provider"); //$NON-NLS-1$ - libraryDelegate.setLibraryProvider(provider); - config.setProperty(IPortletConstants.JSFPORTLET_LIBRARY_PROVIDER_DELEGATE, libraryDelegate); - return config; - } -} +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.portlet.configurators; + +import org.apache.maven.project.MavenProject; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.eclipse.wst.common.componentcore.ModuleCoreNature; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +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.jboss.tools.maven.core.IJBossMavenConstants; +import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; +import org.jboss.tools.maven.portlet.MavenPortletActivator; +import org.jboss.tools.maven.portlet.Messages; +import org.jboss.tools.maven.ui.Activator; +import org.jboss.tools.portlet.core.IPortletConstants; +import org.jboss.tools.portlet.core.internal.project.facet.JSFPortletFacetInstallDataModelProvider; +import org.jboss.tools.portlet.core.internal.project.facet.PortletFacetInstallDataModelProvider; + +/** + * + * @author snjeza + * + */ +public class PortletProjectConfigurator extends AbstractProjectConfigurator { + + private static final String PORTLET_API_GROUP_ID = "javax.portlet"; //$NON-NLS-1$ + private static final String PORTLET_API_ARTIFACT_ID = "portlet-api"; //$NON-NLS-1$ + + private static final String PORTLETBRIDGE_API_GROUP_ID = "org.jboss.portletbridge"; //$NON-NLS-1$ + private static final String PORTLETBRIDGE_API_ARTIFACT_ID = "portletbridge-api"; //$NON-NLS-1$ + + protected static final IProjectFacet dynamicWebFacet; + protected static final IProjectFacetVersion dynamicWebVersion; + + protected static final IProjectFacet jsfFacet; + protected static final IProjectFacet portletFacet; + protected static final IProjectFacetVersion portletVersion10; + protected static final IProjectFacetVersion portletVersion20; + protected static final IProjectFacet m2Facet; + protected static final IProjectFacetVersion m2Version; + protected static final IProjectFacetVersion jsfportletFacetVersion; + + static { + dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ + dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ + portletFacet = ProjectFacetsManager.getProjectFacet("jboss.portlet"); //$NON-NLS-1$ + portletVersion20 = portletFacet.getVersion("2.0"); //$NON-NLS-1$ + portletVersion10 = portletFacet.getVersion("1.0"); //$NON-NLS-1$ + m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ + m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ + jsfFacet = ProjectFacetsManager.getProjectFacet("jst.jsf"); //$NON-NLS-1$ + jsfportletFacetVersion = ProjectFacetsManager.getProjectFacet("jboss.jsfportlet").getVersion("1.0"); //$NON-NLS-1$//$NON-NLS-2$ + } + + @Override + public void configure(ProjectConfigurationRequest request, + IProgressMonitor monitor) throws CoreException { + MavenProject mavenProject = request.getMavenProject(); + IProject project = request.getProject(); + configureInternal(mavenProject,project, monitor); + } + + private void configureInternal(MavenProject mavenProject,IProject project, + IProgressMonitor monitor) throws CoreException { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + boolean configurePortlet = store.getBoolean(Activator.CONFIGURE_PORTLET); + if (!configurePortlet) { + return; + } + + String packaging = mavenProject.getPackaging(); + String portletVersion = Activator.getDefault().getDependencyVersion(mavenProject, PORTLET_API_GROUP_ID, PORTLET_API_ARTIFACT_ID); + String jsfportletVersion = Activator.getDefault().getDependencyVersion(mavenProject, PORTLETBRIDGE_API_GROUP_ID, PORTLETBRIDGE_API_ARTIFACT_ID); + if (portletVersion != null) { + final IFacetedProject fproj = ProjectFacetsManager.create(project); + if (fproj != null && "war".equals(packaging)) { //$NON-NLS-1$ + installWarFacets(fproj, portletVersion, jsfportletVersion, monitor); + } + } + } + + + @Override + public void mavenProjectChanged(MavenProjectChangedEvent event, + IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = event.getMavenProject(); + if(facade != null) { + IProject project = facade.getProject(); + if(isWTPProject(project)) { + MavenProject mavenProject = facade.getMavenProject(monitor); + configureInternal(mavenProject, project, monitor); + } + } + super.mavenProjectChanged(event, monitor); + } + + private boolean isWTPProject(IProject project) { + return ModuleCoreNature.getModuleCoreNature(project) != null; + } + + private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) throws CoreException { + if (!fproj.hasProjectFacet(m2Facet)) { + IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider().create(); + config.setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); + fproj.installProjectFacet(m2Version, config, monitor); + } + } + + + private void installWarFacets(IFacetedProject fproj, String portletVersion, String jsfportletVersion, IProgressMonitor monitor) throws CoreException { + + if (!fproj.hasProjectFacet(dynamicWebFacet)) { + MavenPortletActivator.log(Messages.PortletProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet); + } + installM2Facet(fproj, monitor); + installPortletFacet(fproj, portletVersion, jsfportletVersion, monitor); + } + + + private void installPortletFacet(IFacetedProject fproj, String portletVersionString, String jsfportletVersion, IProgressMonitor monitor) + throws CoreException { + if (!fproj.hasProjectFacet(portletFacet)) { + if (portletVersionString.startsWith("1.0")) { //$NON-NLS-1$ + IDataModel model = createPortletDataModel(fproj, portletVersion10); + fproj.installProjectFacet(portletVersion10, model, monitor); + } + if (portletVersionString.startsWith("2.0")) { //$NON-NLS-1$ + IDataModel model = createPortletDataModel(fproj, portletVersion20); + fproj.installProjectFacet(portletVersion20, model, monitor); + } + } + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + boolean configureJSFPortlet = store.getBoolean(Activator.CONFIGURE_JSFPORTLET); + if (!configureJSFPortlet) { + return; + } + if (fproj.hasProjectFacet(portletFacet) && fproj.hasProjectFacet(jsfFacet) && jsfportletVersion != null) { + + if (!fproj.hasProjectFacet(jsfportletFacetVersion)) { + IDataModel model = createJSFPortletDataModel(fproj, jsfportletFacetVersion); + fproj.installProjectFacet(jsfportletFacetVersion, model, monitor); + } + + } + } + + private IDataModel createPortletDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { + IDataModel config = (IDataModel) new PortletFacetInstallDataModelProvider().create(); + LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(fproj, facetVersion); + ILibraryProvider provider = LibraryProviderFramework.getProvider("portlet-no-op-library-provider"); //$NON-NLS-1$ + libraryDelegate.setLibraryProvider(provider); + config.setProperty(IPortletConstants.PORTLET_LIBRARY_PROVIDER_DELEGATE, libraryDelegate); + return config; + } + + private IDataModel createJSFPortletDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { + IDataModel config = (IDataModel) new JSFPortletFacetInstallDataModelProvider().create(); + LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(fproj, facetVersion); + ILibraryProvider provider = LibraryProviderFramework.getProvider("jsfportlet-no-op-library-provider"); //$NON-NLS-1$ + libraryDelegate.setLibraryProvider(provider); + config.setProperty(IPortletConstants.JSFPORTLET_LIBRARY_PROVIDER_DELEGATE, libraryDelegate); + return config; + } +} Index: src/org/jboss/tools/maven/portlet/Messages.java =================================================================== --- src/org/jboss/tools/maven/portlet/Messages.java (revision 32782) +++ src/org/jboss/tools/maven/portlet/Messages.java (working copy) @@ -1,15 +1,30 @@ -package org.jboss.tools.maven.portlet; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.jboss.tools.maven.jsf.messages"; //$NON-NLS-1$ - public static String PortletProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.portlet; + +import org.eclipse.osgi.util.NLS; + +/** + * + * @author snjeza + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.jboss.tools.maven.jsf.messages"; //$NON-NLS-1$ + public static String PortletProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.jboss.tools.maven.portlet;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Activator: org.jboss.tools.maven.portlet.MavenPortletActivator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, @@ -10,7 +10,6 @@ org.jboss.tools.maven.ui, org.jboss.tools.portlet.core, org.jboss.tools.common.model, - org.maven.ide.eclipse.maven_model_edit;bundle-version="0.10.0";visibility:=reexport, org.eclipse.jst.j2ee.core, org.eclipse.jst.j2ee, org.eclipse.wst.common.emfworkbench.integration Index: src/org/jboss/tools/maven/portlet/PortletLifecycleMapping.java =================================================================== --- src/org/jboss/tools/maven/portlet/PortletLifecycleMapping.java (revision 0) +++ src/org/jboss/tools/maven/portlet/PortletLifecycleMapping.java (revision 0) @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2010 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.portlet; + +import org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping; + +/** + * @author snjeza + */ +public class PortletLifecycleMapping extends AbstractCustomizableLifecycleMapping { + +} Index: plugin.xml =================================================================== --- plugin.xml (revision 32782) +++ plugin.xml (working copy) @@ -1,11 +1,25 @@ - - - - - - - - + + + + + + + + + + + + + + + + #P org.jboss.tools.maven.hibernate Index: build.properties =================================================================== --- build.properties (revision 32782) +++ build.properties (working copy) @@ -1,11 +1,12 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - plugin.properties,\ - about.html,\ - about.ini,\ - about.mappings,\ - about.properties,\ - jboss_about.png +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html,\ + about.ini,\ + about.mappings,\ + about.properties,\ + jboss_about.png,\ + lifecycle-mapping-metadata.xml Index: src/org/jboss/tools/maven/hibernate/configurators/HibernateProjectConfigurator.java =================================================================== --- src/org/jboss/tools/maven/hibernate/configurators/HibernateProjectConfigurator.java (revision 32782) +++ src/org/jboss/tools/maven/hibernate/configurators/HibernateProjectConfigurator.java (working copy) @@ -1,108 +1,107 @@ -/************************************************************************************* - * Copyright (c) 2008-2011 Red Hat, Inc. 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: - * JBoss by Red Hat - Initial implementation. - ************************************************************************************/ -package org.jboss.tools.maven.hibernate.configurators; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.model.Dependency; -import org.apache.maven.project.MavenProject; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ProjectScope; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jface.preference.IPreferenceStore; -import org.hibernate.eclipse.console.properties.HibernatePropertiesConstants; -import org.hibernate.eclipse.console.utils.ProjectUtils; -import org.jboss.tools.maven.ui.Activator; -import org.maven.ide.eclipse.project.IMavenProjectFacade; -import org.maven.ide.eclipse.project.MavenProjectChangedEvent; -import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator; -import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest; -import org.osgi.service.prefs.Preferences; - -/** - * - * @author snjeza - * - */ -public class HibernateProjectConfigurator extends AbstractProjectConfigurator { - - private static final String HIBERNATE_GROUP_ID = "org.hibernate"; //$NON-NLS-1$ - private static final String HIBERNATE_ARTIFACT_ID_PREFIX = "hibernate"; //$NON-NLS-1$ - - @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { - MavenProject mavenProject = request.getMavenProject(); - IProject project = request.getProject(); - configureInternal(mavenProject,project, monitor); - } - - private void configureInternal(MavenProject mavenProject,IProject project, - IProgressMonitor monitor) throws CoreException { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - boolean configureHibernate = store.getBoolean(Activator.CONFIGURE_HIBERNATE); - if (!configureHibernate) { - return; - } - - if (project.hasNature(JavaCore.NATURE_ID) && isHibernateProject(mavenProject)) { - IScopeContext scope = new ProjectScope(project); - Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE); - if (node != null) { - boolean enabled = node.getBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, false); - if (enabled) { - return; - } - } - ProjectUtils.toggleHibernateOnProject(project, true, ""); //$NON-NLS-1$ - } - } - - - @Override - public void mavenProjectChanged(MavenProjectChangedEvent event, - IProgressMonitor monitor) throws CoreException { - IMavenProjectFacade facade = event.getMavenProject(); - if(facade != null) { - IProject project = facade.getProject(); - MavenProject mavenProject = facade.getMavenProject(monitor); - configureInternal(mavenProject, project, monitor); - } - super.mavenProjectChanged(event, monitor); - } - - private boolean isHibernateProject(MavenProject mavenProject) { - List artifacts = new ArrayList(); - ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter( - Artifact.SCOPE_TEST); - for (Artifact artifact : mavenProject.getArtifacts()) { - if (filter.include(artifact)) { - artifacts.add(artifact); - } - } - for (Artifact artifact:artifacts) { - String groupId = artifact.getGroupId(); - if (HIBERNATE_GROUP_ID.equals(groupId)) { - String artifactId = artifact.getArtifactId(); - if (artifactId != null && artifactId.startsWith(HIBERNATE_ARTIFACT_ID_PREFIX)) { - return true; - } - } - } - return false; - } -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.hibernate.configurators; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.hibernate.eclipse.console.properties.HibernatePropertiesConstants; +import org.hibernate.eclipse.console.utils.ProjectUtils; +import org.jboss.tools.maven.ui.Activator; +import org.osgi.service.prefs.Preferences; + +/** + * + * @author snjeza + * + */ +public class HibernateProjectConfigurator extends AbstractProjectConfigurator { + + private static final String HIBERNATE_GROUP_ID = "org.hibernate"; //$NON-NLS-1$ + private static final String HIBERNATE_ARTIFACT_ID_PREFIX = "hibernate"; //$NON-NLS-1$ + + @Override + public void configure(ProjectConfigurationRequest request, + IProgressMonitor monitor) throws CoreException { + MavenProject mavenProject = request.getMavenProject(); + IProject project = request.getProject(); + configureInternal(mavenProject,project, monitor); + } + + private void configureInternal(MavenProject mavenProject,IProject project, + IProgressMonitor monitor) throws CoreException { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + boolean configureHibernate = store.getBoolean(Activator.CONFIGURE_HIBERNATE); + if (!configureHibernate) { + return; + } + + if (project.hasNature(JavaCore.NATURE_ID) && isHibernateProject(mavenProject)) { + IScopeContext scope = new ProjectScope(project); + Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE); + if (node != null) { + boolean enabled = node.getBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, false); + if (enabled) { + return; + } + } + ProjectUtils.toggleHibernateOnProject(project, true, ""); //$NON-NLS-1$ + } + } + + + @Override + public void mavenProjectChanged(MavenProjectChangedEvent event, + IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = event.getMavenProject(); + if(facade != null) { + IProject project = facade.getProject(); + MavenProject mavenProject = facade.getMavenProject(monitor); + configureInternal(mavenProject, project, monitor); + } + super.mavenProjectChanged(event, monitor); + } + + private boolean isHibernateProject(MavenProject mavenProject) { + List artifacts = new ArrayList(); + ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter( + Artifact.SCOPE_TEST); + for (Artifact artifact : mavenProject.getArtifacts()) { + if (filter.include(artifact)) { + artifacts.add(artifact); + } + } + for (Artifact artifact:artifacts) { + String groupId = artifact.getGroupId(); + if (HIBERNATE_GROUP_ID.equals(groupId)) { + String artifactId = artifact.getArtifactId(); + if (artifactId != null && artifactId.startsWith(HIBERNATE_ARTIFACT_ID_PREFIX)) { + return true; + } + } + } + return false; + } +} Index: src/org/jboss/tools/maven/hibernate/MavenHibernateActivator.java =================================================================== --- src/org/jboss/tools/maven/hibernate/MavenHibernateActivator.java (revision 32782) +++ src/org/jboss/tools/maven/hibernate/MavenHibernateActivator.java (working copy) @@ -1,50 +1,60 @@ -package org.jboss.tools.maven.hibernate; - -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class MavenHibernateActivator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.jboss.tools.maven.hibernate"; //$NON-NLS-1$ - - // The shared instance - private static MavenHibernateActivator plugin; - - /** - * The constructor - */ - public MavenHibernateActivator() { - } - - /* - * (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); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static MavenHibernateActivator getDefault() { - return plugin; - } - -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.hibernate; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class MavenHibernateActivator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.maven.hibernate"; //$NON-NLS-1$ + + // The shared instance + private static MavenHibernateActivator plugin; + + /** + * The constructor + */ + public MavenHibernateActivator() { + } + + /* + * (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); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static MavenHibernateActivator getDefault() { + return plugin; + } + +} Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -2,14 +2,13 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.jboss.tools.maven.hibernate;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Activator: org.jboss.tools.maven.hibernate.MavenHibernateActivator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.jboss.tools.maven.core, org.jboss.tools.maven.ui, org.jboss.tools.common.model, - org.maven.ide.eclipse.maven_model_edit;bundle-version="0.10.0";visibility:=reexport, org.eclipse.jst.j2ee.core, org.eclipse.jst.j2ee, org.eclipse.wst.common.emfworkbench.integration, Index: src/org/jboss/tools/maven/hibernate/HibernateLifecycleMapping.java =================================================================== --- src/org/jboss/tools/maven/hibernate/HibernateLifecycleMapping.java (revision 0) +++ src/org/jboss/tools/maven/hibernate/HibernateLifecycleMapping.java (revision 0) @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2010 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.hibernate; + +import org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping; + +/** + * @author snjeza + */ +public class HibernateLifecycleMapping extends AbstractCustomizableLifecycleMapping { + +} Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.hibernate - 1.0.0-SNAPSHOT + org.jboss.tools.maven.hibernate + 1.2.0-SNAPSHOT eclipse-plugin Index: plugin.xml =================================================================== --- plugin.xml (revision 32782) +++ plugin.xml (working copy) @@ -1,12 +1,26 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + Index: lifecycle-mapping-metadata.xml =================================================================== --- lifecycle-mapping-metadata.xml (revision 0) +++ lifecycle-mapping-metadata.xml (revision 0) @@ -0,0 +1,23 @@ + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + [2.0,) + + compile + testCompile + + + + + org.jboss.tools.maven.hibernate.configurator + + + + + + \ No newline at end of file #P org.jboss.tools.maven.cdi Index: plugin.xml =================================================================== --- plugin.xml (revision 32782) +++ plugin.xml (working copy) @@ -1,12 +1,34 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + Index: src/org/jboss/tools/maven/cdi/messages.properties =================================================================== --- src/org/jboss/tools/maven/cdi/messages.properties (revision 32782) +++ src/org/jboss/tools/maven/cdi/messages.properties (working copy) @@ -1 +1 @@ -CDIProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet=The project doesn't contain the Web Module facet. +CDIProjectConfigurator_The_project_does_not_contain_required_facets=The {0} project does not contain the Dynamic Web Module facet or the EJB Module facet. Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -2,14 +2,13 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.jboss.tools.maven.cdi;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Activator: org.jboss.tools.maven.cdi.MavenCDIActivator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.jboss.tools.maven.core, org.jboss.tools.maven.ui, org.jboss.tools.common.model, - org.maven.ide.eclipse.maven_model_edit;bundle-version="0.10.0";visibility:=reexport, org.eclipse.jst.j2ee.core, org.eclipse.jst.j2ee, org.eclipse.wst.common.emfworkbench.integration, Index: src/org/jboss/tools/maven/cdi/configurators/CDIProjectConfigurator.java =================================================================== --- src/org/jboss/tools/maven/cdi/configurators/CDIProjectConfigurator.java (revision 32782) +++ src/org/jboss/tools/maven/cdi/configurators/CDIProjectConfigurator.java (working copy) @@ -1,132 +1,198 @@ -package org.jboss.tools.maven.cdi.configurators; - -import org.apache.maven.project.MavenProject; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -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.jboss.tools.cdi.core.CDIUtil; -import org.jboss.tools.maven.cdi.MavenCDIActivator; -import org.jboss.tools.maven.core.IJBossMavenConstants; -import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; -import org.jboss.tools.maven.ui.Activator; -import org.jboss.tools.maven.cdi.Messages; -import org.maven.ide.eclipse.project.IMavenProjectFacade; -import org.maven.ide.eclipse.project.MavenProjectChangedEvent; -import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator; -import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest; - -public class CDIProjectConfigurator extends AbstractProjectConfigurator { - - private static final String CDI_API_GROUP_ID = "javax.enterprise"; //$NON-NLS-1$ - private static final String CDI_API_ARTIFACT_ID = "cdi-api"; //$NON-NLS-1$ - - protected static final IProjectFacet dynamicWebFacet; - protected static final IProjectFacetVersion dynamicWebVersion; - - protected static final IProjectFacet cdiFacet; - protected static final IProjectFacetVersion cdiVersion; - - protected static final IProjectFacet m2Facet; - protected static final IProjectFacetVersion m2Version; - - static { - dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ - dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ - cdiFacet = ProjectFacetsManager.getProjectFacet("jst.cdi"); //$NON-NLS-1$ - cdiVersion = cdiFacet.getVersion("1.0"); //$NON-NLS-1$ - m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ - m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ - } - - @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { - MavenProject mavenProject = request.getMavenProject(); - IProject project = request.getProject(); - configureInternal(mavenProject,project, monitor); - } - - private void configureInternal(MavenProject mavenProject,IProject project, - IProgressMonitor monitor) throws CoreException { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - boolean configureCDI = store.getBoolean(Activator.CONFIGURE_CDI); - if (!configureCDI) { - return; - } - - String packaging = mavenProject.getPackaging(); - String cdiVersion = getCDIVersion(mavenProject); - if (cdiVersion != null) { - final IFacetedProject fproj = ProjectFacetsManager.create(project); - if ( (fproj != null) && ("war".equals(packaging) || "ejb".equals(packaging)) ) { //$NON-NLS-1$ - installWarFacets(fproj, cdiVersion, monitor); - } - CDIUtil.enableCDI(project, false, new NullProgressMonitor()); - } - } - - - @Override - public void mavenProjectChanged(MavenProjectChangedEvent event, - IProgressMonitor monitor) throws CoreException { - IMavenProjectFacade facade = event.getMavenProject(); - if(facade != null) { - IProject project = facade.getProject(); - if(isWTPProject(project)) { - MavenProject mavenProject = facade.getMavenProject(monitor); - configureInternal(mavenProject, project, monitor); - } - } - super.mavenProjectChanged(event, monitor); - } - - private boolean isWTPProject(IProject project) { - return ModuleCoreNature.getModuleCoreNature(project) != null; - } - - private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) throws CoreException { - if (!fproj.hasProjectFacet(m2Facet)) { - IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider().create(); - config.setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); - fproj.installProjectFacet(m2Version, config, monitor); - } - } - - - private void installWarFacets(IFacetedProject fproj, String cdiVersion,IProgressMonitor monitor) throws CoreException { - - if (!fproj.hasProjectFacet(dynamicWebFacet)) { - MavenCDIActivator.log(Messages.CDIProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet); - } - installCDIFacet(fproj, cdiVersion, monitor); - installM2Facet(fproj, monitor); - - } - - - private void installCDIFacet(IFacetedProject fproj, String cdiVersionString, IProgressMonitor monitor) - throws CoreException { - if (!fproj.hasProjectFacet(cdiFacet)) { - if (cdiVersionString.startsWith("1.0")) { //$NON-NLS-1$ - IDataModel model = MavenCDIActivator.getDefault().createCDIDataModel(fproj,cdiVersion); - fproj.installProjectFacet(cdiVersion, model, monitor); - } - } - } - - private String getCDIVersion(MavenProject mavenProject) { - String version = null; - version = Activator.getDefault().getDependencyVersion(mavenProject, CDI_API_GROUP_ID, CDI_API_ARTIFACT_ID); - - return version; - } - -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.cdi.configurators; + +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.eclipse.osgi.util.NLS; +import org.eclipse.wst.common.componentcore.ModuleCoreNature; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +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.jboss.tools.cdi.core.CDICoreNature; +import org.jboss.tools.cdi.core.CDIUtil; +import org.jboss.tools.maven.cdi.MavenCDIActivator; +import org.jboss.tools.maven.cdi.Messages; +import org.jboss.tools.maven.core.IJBossMavenConstants; +import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; +import org.jboss.tools.maven.ui.Activator; + +/** + * + * @author snjeza + * + */ +public class CDIProjectConfigurator extends AbstractProjectConfigurator { + + private static final String CDI_API_GROUP_ID = "javax.enterprise"; //$NON-NLS-1$ + private static final String CDI_API_ARTIFACT_ID = "cdi-api"; //$NON-NLS-1$ + + protected static final IProjectFacet dynamicWebFacet; + protected static final IProjectFacet ejbFacet; + protected static final IProjectFacetVersion dynamicWebVersion; + protected static final IProjectFacetVersion ejbVersion; + + protected static final IProjectFacet cdiFacet; + protected static final IProjectFacetVersion cdiVersion; + + protected static final IProjectFacet m2Facet; + protected static final IProjectFacetVersion m2Version; + private static final String DEFAULT_CDI_VERSION = "1.0"; + + static { + dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ + dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ + ejbFacet = ProjectFacetsManager.getProjectFacet("jst.ejb"); //$NON-NLS-1$ + ejbVersion = ejbFacet.getVersion("3.0"); //$NON-NLS-1$ + cdiFacet = ProjectFacetsManager.getProjectFacet("jst.cdi"); //$NON-NLS-1$ + cdiVersion = cdiFacet.getVersion(DEFAULT_CDI_VERSION); //$NON-NLS-1$ + m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ + m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ + } + + @Override + public void configure(ProjectConfigurationRequest request, + IProgressMonitor monitor) throws CoreException { + MavenProject mavenProject = request.getMavenProject(); + IProject project = request.getProject(); + configureInternal(mavenProject,project, monitor); + } + + private void configureInternal(MavenProject mavenProject,IProject project, + IProgressMonitor monitor) throws CoreException { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + boolean configureCDI = store.getBoolean(Activator.CONFIGURE_CDI); + if (!configureCDI) { + return; + } + final IFacetedProject fproj = ProjectFacetsManager.create(project); + if (project.hasNature(CDICoreNature.NATURE_ID) + && (fproj == null || (fproj.hasProjectFacet(cdiFacet) && fproj.hasProjectFacet(m2Facet)))) { + //everything already installed. Since there's no support for version update -yet- we stop here + return; + } + String packaging = mavenProject.getPackaging(); + String cdiVersion = getCDIVersion(mavenProject); + if (cdiVersion != null) { + if ( (fproj != null) && ("war".equals(packaging) || "ejb".equals(packaging)) ) { //$NON-NLS-1$ + installDefaultFacets(fproj, cdiVersion, monitor); + } + CDIUtil.enableCDI(project, false, new NullProgressMonitor()); + } + } + + + @Override + public void mavenProjectChanged(MavenProjectChangedEvent event, + IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = event.getMavenProject(); + if(facade != null) { + IProject project = facade.getProject(); + if(isWTPProject(project)) { + MavenProject mavenProject = facade.getMavenProject(monitor); + configureInternal(mavenProject, project, monitor); + } + } + super.mavenProjectChanged(event, monitor); + } + + private boolean isWTPProject(IProject project) { + return ModuleCoreNature.getModuleCoreNature(project) != null; + } + + private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) throws CoreException { + if (!fproj.hasProjectFacet(m2Facet)) { + IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider().create(); + config.setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); + fproj.installProjectFacet(m2Version, config, monitor); + } + } + + + @SuppressWarnings("unchecked") + private void installDefaultFacets(IFacetedProject fproj, String cdiVersion,IProgressMonitor monitor) throws CoreException { + IProjectFacetVersion currentWebVersion = fproj.getProjectFacetVersion(dynamicWebFacet); + IProjectFacetVersion currentEjbVersion = fproj.getProjectFacetVersion(ejbFacet); + + if ((currentWebVersion != null && currentWebVersion.compareTo(dynamicWebVersion)> -1) + || (currentEjbVersion != null && currentEjbVersion.compareTo(ejbVersion)> -1)) { + installCDIFacet(fproj, cdiVersion, monitor); + } else { + String name = ""; + if (fproj.getProject() != null) { + name = fproj.getProject().getName(); + } + MavenCDIActivator.log(NLS.bind(Messages.CDIProjectConfigurator_The_project_does_not_contain_required_facets, name)); + } + installM2Facet(fproj, monitor); + + } + + + private void installCDIFacet(IFacetedProject fproj, String cdiVersionString, IProgressMonitor monitor) + throws CoreException { + if (!fproj.hasProjectFacet(cdiFacet)) { + if (cdiVersionString.startsWith("1.0")) { //$NON-NLS-1$ + IDataModel model = MavenCDIActivator.getDefault().createCDIDataModel(fproj,cdiVersion); + fproj.installProjectFacet(cdiVersion, model, monitor); + } + } + } + + private String getCDIVersion(MavenProject mavenProject) { + String version = Activator.getDefault().getDependencyVersion(mavenProject, CDI_API_GROUP_ID, CDI_API_ARTIFACT_ID); + if (version == null) { + version = inferCdiVersionFromDependencies(mavenProject); + } + return version; + } + + private String inferCdiVersionFromDependencies(MavenProject mavenProject) { + boolean hasCandidates = false; + String cdiVersion = null; + List repos = mavenProject.getRemoteArtifactRepositories(); + for (Artifact artifact : mavenProject.getArtifacts()) { + if (isKnownCdiExtension(artifact)) { + hasCandidates = true; + cdiVersion = Activator.getDefault().getDependencyVersion(artifact, repos, CDI_API_GROUP_ID, CDI_API_ARTIFACT_ID); + if (cdiVersion != null) { + //TODO should probably not break and take the highest version returned from all dependencies + break; + } + } + } + //Fallback to default CDI version + if (hasCandidates && cdiVersion == null) { + return DEFAULT_CDI_VERSION; + } + return cdiVersion; + } + + private boolean isKnownCdiExtension(Artifact artifact) { + return artifact.getGroupId().startsWith("org.jboss.seam.") + && artifact.getVersion().startsWith("3."); + } + +} Index: lifecycle-mapping-metadata.xml =================================================================== --- lifecycle-mapping-metadata.xml (revision 0) +++ lifecycle-mapping-metadata.xml (revision 0) @@ -0,0 +1,53 @@ + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + [2.0,) + + compile + testCompile + + + + + org.jboss.tools.maven.cdi.configurator.jdt + + + + + + org.apache.maven.plugins + maven-war-plugin + [1.0,) + + war + + + + + org.jboss.tools.maven.cdi.configurator.wtp + + + + + + org.apache.maven.plugins + maven-ejb-plugin + [1.0,) + + ejb + + + + + org.jboss.tools.maven.cdi.configurator.wtp + + + + + + \ No newline at end of file Index: src/org/jboss/tools/maven/cdi/MavenCDIActivator.java =================================================================== --- src/org/jboss/tools/maven/cdi/MavenCDIActivator.java (revision 32782) +++ src/org/jboss/tools/maven/cdi/MavenCDIActivator.java (working copy) @@ -1,73 +1,83 @@ -package org.jboss.tools.maven.cdi; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.jboss.tools.cdi.internal.core.project.facet.CDIFacetInstallDataModelProvider; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class MavenCDIActivator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.jboss.tools.maven.cdi"; //$NON-NLS-1$ - - // The shared instance - private static MavenCDIActivator plugin; - - /** - * The constructor - */ - public MavenCDIActivator() { - } - - /* - * (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); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static MavenCDIActivator getDefault() { - return plugin; - } - - public static void log(Throwable e) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e - .getLocalizedMessage(), e); - getDefault().getLog().log(status); - } - - public static void log(String message) { - IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message, null); - getDefault().getLog().log(status); - } - - public IDataModel createCDIDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { - IDataModel config = (IDataModel) new CDIFacetInstallDataModelProvider().create(); - config.setBooleanProperty(CDIFacetInstallDataModelProvider.GENERATE_BEANS_XML,false); - return config; - } - -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.cdi; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.jboss.tools.cdi.internal.core.project.facet.CDIFacetInstallDataModelProvider; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class MavenCDIActivator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.maven.cdi"; //$NON-NLS-1$ + + // The shared instance + private static MavenCDIActivator plugin; + + /** + * The constructor + */ + public MavenCDIActivator() { + } + + /* + * (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); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static MavenCDIActivator getDefault() { + return plugin; + } + + public static void log(Throwable e) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e + .getLocalizedMessage(), e); + getDefault().getLog().log(status); + } + + public static void log(String message) { + IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message, null); + getDefault().getLog().log(status); + } + + public IDataModel createCDIDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { + IDataModel config = (IDataModel) new CDIFacetInstallDataModelProvider().create(); + config.setBooleanProperty(CDIFacetInstallDataModelProvider.GENERATE_BEANS_XML,false); + return config; + } + +} Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.cdi - 1.0.0-SNAPSHOT + org.jboss.tools.maven.cdi + 1.2.0-SNAPSHOT eclipse-plugin - + \ No newline at end of file Index: src/org/jboss/tools/maven/cdi/CDILifecycleMapping.java =================================================================== --- src/org/jboss/tools/maven/cdi/CDILifecycleMapping.java (revision 0) +++ src/org/jboss/tools/maven/cdi/CDILifecycleMapping.java (revision 0) @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.cdi; + +import org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping; + +/** + * @author snjeza + */ +public class CDILifecycleMapping extends AbstractCustomizableLifecycleMapping { + +} Index: src/org/jboss/tools/maven/cdi/Messages.java =================================================================== --- src/org/jboss/tools/maven/cdi/Messages.java (revision 32782) +++ src/org/jboss/tools/maven/cdi/Messages.java (working copy) @@ -1,15 +1,30 @@ -package org.jboss.tools.maven.cdi; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.jboss.tools.maven.cdi.messages"; //$NON-NLS-1$ - public static String CDIProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.cdi; + +import org.eclipse.osgi.util.NLS; + +/** + * + * @author snjeza + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.jboss.tools.maven.cdi.messages"; //$NON-NLS-1$ + public static String CDIProjectConfigurator_The_project_does_not_contain_required_facets; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} Index: plugin.properties =================================================================== --- plugin.properties (revision 32782) +++ plugin.properties (working copy) @@ -1,3 +1,4 @@ -Bundle-Vendor = JBoss by Red Hat -Bundle-Name = JBoss Maven CDI Configurator -CDI_Project_configurator = CDI +Bundle-Vendor = JBoss by Red Hat +Bundle-Name = JBoss Maven CDI Configurator +CDI_Project_configurator_WTP = CDI (WTP) +CDI_Project_configurator_JDT = CDI (JDT) Index: build.properties =================================================================== --- build.properties (revision 32782) +++ build.properties (working copy) @@ -1,11 +1,12 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - plugin.properties,\ - about.html,\ - about.ini,\ - about.mappings,\ - about.properties,\ - jboss_about.png +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html,\ + about.ini,\ + about.mappings,\ + about.properties,\ + jboss_about.png,\ + lifecycle-mapping-metadata.xml #P org.jboss.tools.maven.project.examples.feature Index: feature.xml =================================================================== --- feature.xml (revision 32782) +++ feature.xml (working copy) @@ -1,34 +1,34 @@ - - - - - %description - - - - %copyright - - - - %license - - - - - - - - - - - + + + + + %description + + + + %copyright + + + + %license + + + + + + + + + + + Index: feature.properties =================================================================== --- feature.properties (revision 32782) +++ feature.properties (working copy) @@ -1,53 +1,53 @@ -############################################################################### -# Copyright (c) 2011 Red Hat, Inc. 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: -# JBoss by Red Hat - Initial implementation. -############################################################################## -# feature.properties -# contains externalized strings for feature.xml -# "%foo" in feature.xml corresponds to the key "foo" in this file -# java.io.Properties file (ISO 8859-1 with "\" escapes) -# This file should be translated. - -# "featureName" property - name of the feature -featureName=JBoss Maven Project Examples - -# "providerName" property - name of the company that provides the feature -providerName=JBoss by Red Hat - -# "updateSiteName" property - label for the update site -updateSiteName=JBossTools Update Site - -# "description" property - description of the feature -description=JBoss Maven Project Examples - -# "copyright" property - text of the "Feature Update Copyright" -copyright=Copyright (c) 2011 Red Hat, Inc. and others.\n\ -All rights reserved. This program and the accompanying materials\n\ -are made available under the terms of the Eclipse Public License v1.0\n\ -which accompanies this distribution, and is available at\n\ -http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ -JBoss by Red Hat - Initial implementation. - ############### end of copyright property #################################### - -# "licenseURL" property - URL of the "Feature License" -# do not translate value - just change to point to a locale-specific HTML page -licenseURL=license.html - -# START NON-TRANSLATABLE -# "license" property - text of the "Feature Update License" -# should be plain text version of license agreement pointed to be "licenseURL" -license=Red Hat, Inc. licenses these features and plugins to you under \ -certain open source licenses (or aggregations of such licenses), which \ -in a particular case may include the Eclipse Public License, the GNU \ -Lesser General Public License, and/or certain other open source \ -licenses. For precise licensing details, consult the corresponding \ -source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ -Raleigh NC 27606 USA. -# END NON-TRANSLATABLE -########### end of license property ########################################## +############################################################################### +# Copyright (c) 2010-2011 Red Hat, Inc. 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: +# JBoss by Red Hat - Initial implementation. +############################################################################## +# feature.properties +# contains externalized strings for feature.xml +# "%foo" in feature.xml corresponds to the key "foo" in this file +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# This file should be translated. + +# "featureName" property - name of the feature +featureName=JBoss Maven Project Examples + +# "providerName" property - name of the company that provides the feature +providerName=JBoss by Red Hat + +# "updateSiteName" property - label for the update site +updateSiteName=JBossTools Update Site + +# "description" property - description of the feature +description=JBoss Maven Project Examples + +# "copyright" property - text of the "Feature Update Copyright" +copyright=Copyright (c) 2010-2011 Red Hat, Inc. and others.\n\ +All rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\n\ +which accompanies this distribution, and is available at\n\ +http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ +JBoss by Red Hat - Initial implementation. + ############### end of copyright property #################################### + +# "licenseURL" property - URL of the "Feature License" +# do not translate value - just change to point to a locale-specific HTML page +licenseURL=license.html + +# START NON-TRANSLATABLE +# "license" property - text of the "Feature Update License" +# should be plain text version of license agreement pointed to be "licenseURL" +license=Red Hat, Inc. licenses these features and plugins to you under \ +certain open source licenses (or aggregations of such licenses), which \ +in a particular case may include the Eclipse Public License, the GNU \ +Lesser General Public License, and/or certain other open source \ +licenses. For precise licensing details, consult the corresponding \ +source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ +Raleigh NC 27606 USA. +# END NON-TRANSLATABLE +########### end of license property ########################################## Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + features + 0.0.1-SNAPSHOT org.jboss.tools.maven.features - org.jboss.tools.maven.project.examples.feature - 1.0.0-SNAPSHOT + org.jboss.tools.maven.project.examples.feature + 1.2.0-SNAPSHOT eclipse-feature - + \ No newline at end of file #P org.jboss.tools.maven.sdk.feature Index: feature.xml =================================================================== --- feature.xml (revision 32782) +++ feature.xml (working copy) @@ -1,32 +1,32 @@ - - - - - %description - - - - %copyright - - - - %license - - - - - - - - - - - + + + + + %description + + + + %copyright + + + + %license + + + + + + + + + + + Index: feature.properties =================================================================== --- feature.properties (revision 32782) +++ feature.properties (working copy) @@ -1,49 +1,49 @@ -############################################################################### -# Copyright (c) 2011 Red Hat, Inc. 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: -# JBoss by Red Hat - Initial implementation. -############################################################################## -# feature.properties -# contains externalized strings for feature.xml -# "%foo" in feature.xml corresponds to the key "foo" in this file -# java.io.Properties file (ISO 8859-1 with "\" escapes) -# This file should be translated. - -# "featureName" property - name of the feature -featureName=JBoss Maven SDK - -# "providerName" property - name of the company that provides the feature -providerName=JBoss by Red Hat - -# "updateSiteName" property - label for the update site -updateSiteName=JBossTools Update Site - -# "description" property - description of the feature -description=JBoss Maven Integration - -# "copyright" property - text of the "Feature Update Copyright" -copyright=Copyright (c) 2011 Red Hat, Inc. and others.\nAll rights reserved. This program and the accompanying materials\n\ -are made available under the terms of the Eclipse Public License v1.0\nwhich accompanies this distribution, and is available at\nhttp\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\nJBoss by Red Hat - Initial implementation. - ############### end of copyright property #################################### - -# "licenseURL" property - URL of the "Feature License" -# do not translate value - just change to point to a locale-specific HTML page -licenseURL=license.html - -# START NON-TRANSLATABLE -# "license" property - text of the "Feature Update License" -# should be plain text version of license agreement pointed to be "licenseURL" -license=Red Hat, Inc. licenses these features and plugins to you under \ -certain open source licenses (or aggregations of such licenses), which \ -in a particular case may include the Eclipse Public License, the GNU \ -Lesser General Public License, and/or certain other open source \ -licenses. For precise licensing details, consult the corresponding \ -source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ -Raleigh NC 27606 USA. -# END NON-TRANSLATABLE -########### end of license property ########################################## +############################################################################### +# Copyright (c) 2010-2011 Red Hat, Inc. 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: +# JBoss by Red Hat - Initial implementation. +############################################################################## +# feature.properties +# contains externalized strings for feature.xml +# "%foo" in feature.xml corresponds to the key "foo" in this file +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# This file should be translated. + +# "featureName" property - name of the feature +featureName=JBoss Maven SDK + +# "providerName" property - name of the company that provides the feature +providerName=JBoss by Red Hat + +# "updateSiteName" property - label for the update site +updateSiteName=JBossTools Update Site + +# "description" property - description of the feature +description=JBoss Maven Integration + +# "copyright" property - text of the "Feature Update Copyright" +copyright=Copyright (c) 2010-2011 Red Hat, Inc. and others.\nAll rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\nwhich accompanies this distribution, and is available at\nhttp\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\nJBoss by Red Hat - Initial implementation. + ############### end of copyright property #################################### + +# "licenseURL" property - URL of the "Feature License" +# do not translate value - just change to point to a locale-specific HTML page +licenseURL=license.html + +# START NON-TRANSLATABLE +# "license" property - text of the "Feature Update License" +# should be plain text version of license agreement pointed to be "licenseURL" +license=Red Hat, Inc. licenses these features and plugins to you under \ +certain open source licenses (or aggregations of such licenses), which \ +in a particular case may include the Eclipse Public License, the GNU \ +Lesser General Public License, and/or certain other open source \ +licenses. For precise licensing details, consult the corresponding \ +source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ +Raleigh NC 27606 USA. +# END NON-TRANSLATABLE +########### end of license property ########################################## #P org.jboss.tools.maven.jsf Index: build.properties =================================================================== --- build.properties (revision 32782) +++ build.properties (working copy) @@ -1,11 +1,12 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - plugin.properties,\ - about.html,\ - about.ini,\ - about.mappings,\ - about.properties,\ - jboss_about.png +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html,\ + about.ini,\ + about.mappings,\ + about.properties,\ + jboss_about.png,\ + lifecycle-mapping-metadata.xml Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -2,14 +2,13 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.jboss.tools.maven.jsf;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Activator: org.jboss.tools.maven.jsf.MavenJSFActivator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.jboss.tools.maven.core, org.jboss.tools.maven.ui, org.jboss.tools.common.model, - org.maven.ide.eclipse.maven_model_edit;bundle-version="0.10.0";visibility:=reexport, org.eclipse.jst.j2ee.core, org.eclipse.jst.j2ee, org.eclipse.wst.common.emfworkbench.integration, Index: plugin.xml =================================================================== --- plugin.xml (revision 32782) +++ plugin.xml (working copy) @@ -1,10 +1,24 @@ - - - - - - - + + + + + + + + + + + + + + + Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.jsf - 1.0.0-SNAPSHOT + org.jboss.tools.maven.jsf + 1.2.0-SNAPSHOT eclipse-plugin - + \ No newline at end of file Index: src/org/jboss/tools/maven/jsf/Messages.java =================================================================== --- src/org/jboss/tools/maven/jsf/Messages.java (revision 32782) +++ src/org/jboss/tools/maven/jsf/Messages.java (working copy) @@ -1,15 +1,30 @@ -package org.jboss.tools.maven.jsf; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.jboss.tools.maven.jsf.messages"; //$NON-NLS-1$ - public static String JSFProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.jsf; + +import org.eclipse.osgi.util.NLS; + +/** + * + * @author snjeza + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.jboss.tools.maven.jsf.messages"; //$NON-NLS-1$ + public static String JSFProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} Index: src/org/jboss/tools/maven/jsf/JSFLifecycleMapping.java =================================================================== --- src/org/jboss/tools/maven/jsf/JSFLifecycleMapping.java (revision 0) +++ src/org/jboss/tools/maven/jsf/JSFLifecycleMapping.java (revision 0) @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.jsf; + +import org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping; + +/** + * @author snjeza + */ +public class JSFLifecycleMapping extends AbstractCustomizableLifecycleMapping { + +} Index: src/org/jboss/tools/maven/jsf/MavenJSFActivator.java =================================================================== --- src/org/jboss/tools/maven/jsf/MavenJSFActivator.java (revision 32782) +++ src/org/jboss/tools/maven/jsf/MavenJSFActivator.java (working copy) @@ -1,75 +1,90 @@ -package org.jboss.tools.maven.jsf; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework; -import org.eclipse.jst.jsf.core.internal.project.facet.IJSFFacetInstallDataModelProperties; -import org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.osgi.framework.BundleContext; - -public class MavenJSFActivator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.jboss.tools.maven.jsf"; //$NON-NLS-1$ - - private static BundleContext context; - - // The shared instance - private static MavenJSFActivator plugin; - - static BundleContext getContext() { - return context; - } - - /* - * (non-Javadoc) - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext bundleContext) throws Exception { - super.start(bundleContext); - MavenJSFActivator.plugin = this; - MavenJSFActivator.context = bundleContext; - } - - /* - * (non-Javadoc) - * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext bundleContext) throws Exception { - MavenJSFActivator.context = null; - MavenJSFActivator.plugin = null; - super.stop(bundleContext); - } - - public static MavenJSFActivator getDefault() { - return plugin; - } - - public static void log(Throwable e) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); - getDefault().getLog().log(status); - } - - public static void log(String message) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message); - getDefault().getLog().log(status); - } - - public IDataModel createJSFDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { - IDataModel config = (IDataModel) new JSFFacetInstallDataModelProvider().create(); - LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(fproj, facetVersion); - ILibraryProvider provider = LibraryProviderFramework.getProvider("jsf-no-op-library-provider"); //$NON-NLS-1$ - libraryDelegate.setLibraryProvider(provider); - config.setProperty(IJSFFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE, libraryDelegate); - config.setProperty(IJSFFacetInstallDataModelProperties.SERVLET_NAME, ""); //$NON-NLS-1$ - config.setProperty(IJSFFacetInstallDataModelProperties.SERVLET_URL_PATTERNS, new String[0]); - - return config; - } -} +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.jsf; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework; +import org.eclipse.jst.jsf.core.internal.project.facet.IJSFFacetInstallDataModelProperties; +import org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; +import org.osgi.framework.BundleContext; + +/** + * + * @author snjeza + * + */ +public class MavenJSFActivator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.maven.jsf"; //$NON-NLS-1$ + + private static BundleContext context; + + // The shared instance + private static MavenJSFActivator plugin; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + super.start(bundleContext); + MavenJSFActivator.plugin = this; + MavenJSFActivator.context = bundleContext; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + MavenJSFActivator.context = null; + MavenJSFActivator.plugin = null; + super.stop(bundleContext); + } + + public static MavenJSFActivator getDefault() { + return plugin; + } + + public static void log(Throwable e) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); + getDefault().getLog().log(status); + } + + public static void log(String message) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message); + getDefault().getLog().log(status); + } + + public IDataModel createJSFDataModel(IFacetedProject fproj, IProjectFacetVersion facetVersion) { + IDataModel config = (IDataModel) new JSFFacetInstallDataModelProvider().create(); + LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(fproj, facetVersion); + ILibraryProvider provider = LibraryProviderFramework.getProvider("jsf-no-op-library-provider"); //$NON-NLS-1$ + libraryDelegate.setLibraryProvider(provider); + config.setProperty(IJSFFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE, libraryDelegate); + config.setProperty(IJSFFacetInstallDataModelProperties.SERVLET_NAME, ""); //$NON-NLS-1$ + config.setProperty(IJSFFacetInstallDataModelProperties.SERVLET_URL_PATTERNS, new String[0]); + + return config; + } +} Index: lifecycle-mapping-metadata.xml =================================================================== --- lifecycle-mapping-metadata.xml (revision 0) +++ lifecycle-mapping-metadata.xml (revision 0) @@ -0,0 +1,22 @@ + + + + + + + org.apache.maven.plugins + maven-war-plugin + [1.0,) + + war + + + + + org.jboss.tools.maven.jsf.configurator + + + + + + \ No newline at end of file Index: src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java =================================================================== --- src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java (revision 32782) +++ src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java (working copy) @@ -1,301 +1,368 @@ -/************************************************************************************* - * Copyright (c) 2008-2011 Red Hat, Inc. 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: - * JBoss by Red Hat - Initial implementation. - ************************************************************************************/ -package org.jboss.tools.maven.jsf.configurators; - -import java.io.File; -import java.io.IOException; - -import org.apache.maven.model.Plugin; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.core.resources.IFile; -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.jface.preference.IPreferenceStore; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -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.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.jboss.tools.maven.core.IJBossMavenConstants; -import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; -import org.jboss.tools.maven.jsf.MavenJSFActivator; -import org.jboss.tools.maven.jsf.Messages; -import org.jboss.tools.maven.ui.Activator; -import org.maven.ide.eclipse.project.IMavenProjectFacade; -import org.maven.ide.eclipse.project.MavenProjectChangedEvent; -import org.maven.ide.eclipse.project.configurator.AbstractProjectConfigurator; -import org.maven.ide.eclipse.project.configurator.ProjectConfigurationRequest; -import org.maven.ide.eclipse.wtp.WTPProjectsUtil; - -/** - * - * @author snjeza - * - */ -public class JSFProjectConfigurator extends AbstractProjectConfigurator { - - private static final String JSF_API_GROUP_ID = "javax.faces"; //$NON-NLS-1$ - private static final String JSF_API2_GROUP_ID = "com.sun.faces"; //$NON-NLS-1$ - private static final String JSF_API_ARTIFACT_ID = "jsf-api"; //$NON-NLS-1$ - - private static final String WEB_XML = "WEB-INF/web.xml"; - private static final String WAR_SOURCE_FOLDER = "/src/main/webapp"; - - protected static final IProjectFacet dynamicWebFacet; - protected static final IProjectFacetVersion dynamicWebVersion; - - protected static final IProjectFacet jsfFacet; - protected static final IProjectFacetVersion jsfVersion20; - protected static final IProjectFacetVersion jsfVersion12; - protected static final IProjectFacetVersion jsfVersion11; - protected static final IProjectFacet m2Facet; - protected static final IProjectFacetVersion m2Version; - - static { - dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ - dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ - jsfFacet = ProjectFacetsManager.getProjectFacet("jst.jsf"); //$NON-NLS-1$ - jsfVersion20 = jsfFacet.getVersion("2.0"); //$NON-NLS-1$ - jsfVersion12 = jsfFacet.getVersion("1.2"); //$NON-NLS-1$ - jsfVersion11 = jsfFacet.getVersion("1.1"); //$NON-NLS-1$ - m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ - m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ - } - - @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { - MavenProject mavenProject = request.getMavenProject(); - IProject project = request.getProject(); - configureInternal(mavenProject, project, monitor); - } - - private void configureInternal(MavenProject mavenProject, IProject project, - IProgressMonitor monitor) throws CoreException { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - boolean configureJSF = store.getBoolean(Activator.CONFIGURE_JSF); - if (!configureJSF) { - return; - } - - String packaging = mavenProject.getPackaging(); - String jsfVersion = getJSFVersion(mavenProject); - if (jsfVersion != null) { - final IFacetedProject fproj = ProjectFacetsManager.create(project); - if (fproj != null && "war".equals(packaging)) { //$NON-NLS-1$ - installWarFacets(fproj, jsfVersion, mavenProject, monitor); - } - } - } - - @Override - public void mavenProjectChanged(MavenProjectChangedEvent event, - IProgressMonitor monitor) throws CoreException { - IMavenProjectFacade facade = event.getMavenProject(); - if (facade != null) { - IProject project = facade.getProject(); - if (isWTPProject(project)) { - MavenProject mavenProject = facade.getMavenProject(monitor); - configureInternal(mavenProject, project, monitor); - } - } - super.mavenProjectChanged(event, monitor); - } - - private boolean isWTPProject(IProject project) { - return ModuleCoreNature.getModuleCoreNature(project) != null; - } - - private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) - throws CoreException { - if (!fproj.hasProjectFacet(m2Facet)) { - IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider() - .create(); - config.setBooleanProperty( - IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); - fproj.installProjectFacet(m2Version, config, monitor); - } - } - - private void installWarFacets(IFacetedProject fproj, String jsfVersion, - MavenProject mavenProject, IProgressMonitor monitor) - throws CoreException { - - if (!fproj.hasProjectFacet(dynamicWebFacet)) { - Activator - .log(Messages.JSFProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet); - } - installJSFFacet(fproj, jsfVersion, mavenProject, monitor); - installM2Facet(fproj, monitor); - - } - - private void installJSFFacet(IFacetedProject fproj, - String jsfVersionString, MavenProject mavenProject, - IProgressMonitor monitor) throws CoreException { - if (!fproj.hasProjectFacet(jsfFacet)) { - if (jsfVersionString.startsWith("1.1")) { //$NON-NLS-1$ - IDataModel model = MavenJSFActivator.getDefault() - .createJSFDataModel(fproj, jsfVersion11); - fproj.installProjectFacet(jsfVersion11, model, monitor); - } - if (jsfVersionString.startsWith("1.2")) { //$NON-NLS-1$ - IDataModel model = MavenJSFActivator.getDefault() - .createJSFDataModel(fproj, jsfVersion12); - fproj.installProjectFacet(jsfVersion12, model, monitor); - } - if (jsfVersionString.startsWith("2.0")) { //$NON-NLS-1$ - String webXmlString = null; - IFile webXml = null; - webXml = getWebXml(fproj, mavenProject); - boolean webXmlExists = webXml != null && webXml.exists(); - if (!configureWebxml() && webXmlExists) { - IStructuredModel webXmlModel = null; - try { - webXmlModel = StructuredModelManager.getModelManager().getModelForRead(webXml); - IStructuredDocument doc = webXmlModel.getStructuredDocument(); - webXmlString = doc.get(); - } catch (IOException e) { - MavenJSFActivator.log(e); - } finally { - if (webXmlModel != null) { - webXmlModel.releaseFromRead(); - } - } - } - IDataModel model = MavenJSFActivator.getDefault() - .createJSFDataModel(fproj, jsfVersion20); - fproj.installProjectFacet(jsfVersion20, model, monitor); - if (!configureWebxml() && webXmlExists && webXmlString != null) { - IStructuredModel webXmlModel = null; - try { - webXmlModel = StructuredModelManager.getModelManager().getModelForEdit(webXml); - IStructuredDocument doc = webXmlModel.getStructuredDocument(); - doc.set(webXmlString); - webXmlModel.save(); - } catch (IOException e) { - MavenJSFActivator.log(e); - } finally { - if (webXmlModel != null) { - webXmlModel.releaseFromEdit(); - } - } - } - } - } - } - - private IFile getWebXml(IFacetedProject fproj, MavenProject mavenProject) { - IFile webXml; - String customWebXml = getCustomWebXml(mavenProject, - fproj.getProject()); - if (customWebXml == null) { - webXml = fproj.getProject().getFolder(getWarSourceDirectory(mavenProject,fproj.getProject())).getFile(WEB_XML); - } else { - webXml = fproj.getProject().getFile(customWebXml); - } - return webXml; - } - - private String getWarSourceDirectory(MavenProject mavenProject, - IProject project) { - Plugin plugin = mavenProject - .getPlugin("org.apache.maven.plugins:maven-war-plugin"); - if (plugin == null) { - return null; - } - Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration(); - if (config == null) { - return WAR_SOURCE_FOLDER; - } - Xpp3Dom[] warSourceDirectory = config.getChildren("warSourceDirectory"); - if (warSourceDirectory != null && warSourceDirectory.length > 0) { - String dir = warSourceDirectory[0].getValue(); - if (project != null) { - return tryProjectRelativePath(project, dir).toOSString(); - } - return dir; - } - return WAR_SOURCE_FOLDER; - } - - private IPath tryProjectRelativePath(IProject project, - String resourceLocation) { - if (resourceLocation == null) { - return null; - } - IPath projectLocation = project.getLocation(); - IPath directory = Path.fromOSString(resourceLocation); - if (projectLocation == null || !projectLocation.isPrefixOf(directory)) { - return directory; - } - return directory.removeFirstSegments(projectLocation.segmentCount()) - .makeRelative().setDevice(null); - } - - - public String getCustomWebXml(MavenProject mavenProject, IProject project) { - Plugin plugin = mavenProject - .getPlugin("org.apache.maven.plugins:maven-war-plugin"); - if (plugin == null) { - return null; - } - Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration(); - if (config != null) { - Xpp3Dom webXmlDom = config.getChild("webXml"); - if (webXmlDom != null && webXmlDom.getValue() != null) { - String webXmlFile = webXmlDom.getValue().trim(); - webXmlFile = getRelativePath(project, webXmlFile); - return webXmlFile; - } - } - return null; - } - - private static String getRelativePath(IProject project, String absolutePath) { - File basedir = project.getLocation().toFile(); - String relative; - if (absolutePath.equals(basedir.getAbsolutePath())) { - relative = "."; - } else if (absolutePath.startsWith(basedir.getAbsolutePath())) { - relative = absolutePath.substring(basedir.getAbsolutePath() - .length() + 1); - } else { - relative = absolutePath; - } - return relative.replace('\\', '/'); //$NON-NLS-1$ //$NON-NLS-2$ - } - - private boolean configureWebxml() { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - return store.getBoolean(Activator.CONFIGURE_WEBXML_JSF20); - } - - private String getJSFVersion(MavenProject mavenProject) { - String version = null; - version = Activator.getDefault().getDependencyVersion(mavenProject, - JSF_API_GROUP_ID, JSF_API_ARTIFACT_ID); - if (version == null) { - version = Activator.getDefault().getDependencyVersion(mavenProject, - JSF_API2_GROUP_ID, JSF_API_ARTIFACT_ID); - } - return version; - } - -} +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is 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: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.maven.jsf.configurators; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Plugin; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +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.jface.preference.IPreferenceStore; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.ModuleCoreNature; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.project.facet.core.IFacetedProject; +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.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.jboss.tools.maven.core.IJBossMavenConstants; +import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider; +import org.jboss.tools.maven.jsf.MavenJSFActivator; +import org.jboss.tools.maven.jsf.Messages; +import org.jboss.tools.maven.ui.Activator; + +/** + * + * @author snjeza + * + */ +public class JSFProjectConfigurator extends AbstractProjectConfigurator { + + private static final String JSF_API_GROUP_ID = "javax.faces"; //$NON-NLS-1$ + private static final String JSF_API2_GROUP_ID = "com.sun.faces"; //$NON-NLS-1$ + private static final String JSF_API_ARTIFACT_ID = "jsf-api"; //$NON-NLS-1$ + + private static final String WEB_XML = "WEB-INF/web.xml"; + private static final String WAR_SOURCE_FOLDER = "/src/main/webapp"; + + protected static final IProjectFacet dynamicWebFacet; + protected static final IProjectFacetVersion dynamicWebVersion; + + protected static final IProjectFacet jsfFacet; + protected static final IProjectFacetVersion jsfVersion20; + protected static final IProjectFacetVersion jsfVersion12; + protected static final IProjectFacetVersion jsfVersion11; + protected static final IProjectFacet m2Facet; + protected static final IProjectFacetVersion m2Version; + + private static final String JSF_VERSION_2_0 = "2.0"; + + static { + dynamicWebFacet = ProjectFacetsManager.getProjectFacet("jst.web"); //$NON-NLS-1$ + dynamicWebVersion = dynamicWebFacet.getVersion("2.5"); //$NON-NLS-1$ + jsfFacet = ProjectFacetsManager.getProjectFacet("jst.jsf"); //$NON-NLS-1$ + jsfVersion20 = jsfFacet.getVersion(JSF_VERSION_2_0); + jsfVersion12 = jsfFacet.getVersion("1.2"); //$NON-NLS-1$ + jsfVersion11 = jsfFacet.getVersion("1.1"); //$NON-NLS-1$ + m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$ + m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$ + } + + @Override + public void configure(ProjectConfigurationRequest request, + IProgressMonitor monitor) throws CoreException { + MavenProject mavenProject = request.getMavenProject(); + IProject project = request.getProject(); + configureInternal(mavenProject,project, monitor); + } + + private void configureInternal(MavenProject mavenProject,IProject project, + IProgressMonitor monitor) throws CoreException { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + boolean configureJSF = store.getBoolean(Activator.CONFIGURE_JSF); + if (!configureJSF) { + return; + } + + final IFacetedProject fproj = ProjectFacetsManager.create(project); + if (fproj != null && fproj.hasProjectFacet(jsfFacet) && fproj.hasProjectFacet(m2Facet)) { + //everything already installed. Since there's no support for version update -yet- we bail + return; + } + + String packaging = mavenProject.getPackaging(); + String jsfVersion = getJSFVersion(mavenProject); + if (fproj != null && jsfVersion != null && "war".equals(packaging)) { //$NON-NLS-1$ + installWarFacets(fproj, jsfVersion, mavenProject, monitor); + } + } + + + @Override + public void mavenProjectChanged(MavenProjectChangedEvent event, + IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = event.getMavenProject(); + if(facade != null) { + IProject project = facade.getProject(); + if(isWTPProject(project)) { + MavenProject mavenProject = facade.getMavenProject(monitor); + configureInternal(mavenProject, project, monitor); + } + } + super.mavenProjectChanged(event, monitor); + } + + private boolean isWTPProject(IProject project) { + return ModuleCoreNature.getModuleCoreNature(project) != null; + } + + private void installM2Facet(IFacetedProject fproj, IProgressMonitor monitor) throws CoreException { + if (!fproj.hasProjectFacet(m2Facet)) { + IDataModel config = (IDataModel) new MavenFacetInstallDataModelProvider().create(); + config.setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); + fproj.installProjectFacet(m2Version, config, monitor); + } + } + + + private void installWarFacets(IFacetedProject fproj, + String jsfVersion, MavenProject mavenProject, + IProgressMonitor monitor) throws CoreException { + + if (!fproj.hasProjectFacet(dynamicWebFacet)) { + Activator.log(Messages.JSFProjectConfigurator_The_project_does_not_contain_the_Web_Module_facet); + } + installJSFFacet(fproj, jsfVersion, mavenProject, monitor); + installM2Facet(fproj, monitor); + + } + + + private void installJSFFacet(IFacetedProject fproj, + String jsfVersionString, MavenProject mavenProject, + IProgressMonitor monitor) + throws CoreException { + if (!fproj.hasProjectFacet(jsfFacet)) { + String warSourceDir = getWarSourceDirectory(mavenProject,fproj.getProject()); + IPath facesConfigPath = new Path("WEB-INF/faces-config.xml"); + IFile facesConfig = fproj.getProject().getFolder(warSourceDir).getFile(facesConfigPath); + IFile generatedFacesConfig = getFileFromUnderlyingresources(fproj.getProject(), facesConfigPath); + + //faces-config.xml will not be created in the source folder and it doesn't exist yet + // => We'll have to fix it after setting the JSF facet + boolean shouldFixFacesConfig = !generatedFacesConfig.getLocation().equals(facesConfig.getLocation()) + && !generatedFacesConfig.exists(); + + if (jsfVersionString.startsWith("1.1")) { //$NON-NLS-1$ + IDataModel model = MavenJSFActivator.getDefault().createJSFDataModel(fproj,jsfVersion11); + fproj.installProjectFacet(jsfVersion11, model, monitor); + } + else if (jsfVersionString.startsWith("1.2")) { //$NON-NLS-1$ + IDataModel model = MavenJSFActivator.getDefault().createJSFDataModel(fproj,jsfVersion12); + fproj.installProjectFacet(jsfVersion12, model, monitor); + } + else if (jsfVersionString.startsWith("2.0")) { //$NON-NLS-1$ + String webXmlString = null; + IFile webXml = null; + webXml = getWebXml(fproj, mavenProject); + boolean webXmlExists = webXml != null && webXml.exists(); + if (!configureWebxml() && webXmlExists) { + IStructuredModel webXmlModel = null; + try { + webXmlModel = StructuredModelManager.getModelManager().getModelForRead(webXml); + IStructuredDocument doc = webXmlModel.getStructuredDocument(); + webXmlString = doc.get(); + } catch (IOException e) { + MavenJSFActivator.log(e); + } finally { + if (webXmlModel != null) { + webXmlModel.releaseFromRead(); + } + } + } + IDataModel model = MavenJSFActivator.getDefault() + .createJSFDataModel(fproj, jsfVersion20); + fproj.installProjectFacet(jsfVersion20, model, monitor); + if (!configureWebxml() && webXmlExists && webXmlString != null) { + IStructuredModel webXmlModel = null; + try { + webXmlModel = StructuredModelManager.getModelManager().getModelForEdit(webXml); + IStructuredDocument doc = webXmlModel.getStructuredDocument(); + doc.set(webXmlString); + webXmlModel.save(); + } catch (IOException e) { + MavenJSFActivator.log(e); + } finally { + if (webXmlModel != null) { + webXmlModel.releaseFromEdit(); + } + } + } + } + + if (shouldFixFacesConfig && generatedFacesConfig.exists()) { + if (facesConfig.exists()) { + //We have 2 config files. Delete the gen'd one + generatedFacesConfig.delete(true, monitor); + } + else { + //move the gen'd config file to the appropriate source folder + IContainer destination = facesConfig.getParent(); + if (destination != null && !destination.exists()) { + destination.getLocation().toFile().mkdirs(); + } + generatedFacesConfig.move(facesConfig.getFullPath(), true, monitor); + } + } + + } + } + + private IFile getFileFromUnderlyingresources(final IProject project, final IPath filePath) { + IContainer underlyingFolder = ComponentCore.createComponent(project).getRootFolder().getUnderlyingFolder(); + return project.getFile(underlyingFolder.getProjectRelativePath().append(filePath)); + } + + private IFile getWebXml(IFacetedProject fproj, MavenProject mavenProject) { + IFile webXml; + String customWebXml = getCustomWebXml(mavenProject, + fproj.getProject()); + if (customWebXml == null) { + webXml = fproj.getProject().getFolder(getWarSourceDirectory(mavenProject,fproj.getProject())).getFile(WEB_XML); + } else { + webXml = fproj.getProject().getFile(customWebXml); + } + return webXml; + } + + private String getWarSourceDirectory(MavenProject mavenProject, + IProject project) { + Plugin plugin = mavenProject + .getPlugin("org.apache.maven.plugins:maven-war-plugin"); + if (plugin == null) { + return null; + } + Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration(); + if (config == null) { + return WAR_SOURCE_FOLDER; + } + Xpp3Dom[] warSourceDirectory = config.getChildren("warSourceDirectory"); + if (warSourceDirectory != null && warSourceDirectory.length > 0) { + String dir = warSourceDirectory[0].getValue(); + if (project != null) { + return tryProjectRelativePath(project, dir).toOSString(); + } + return dir; + } + return WAR_SOURCE_FOLDER; + } + + private IPath tryProjectRelativePath(IProject project, + String resourceLocation) { + if (resourceLocation == null) { + return null; + } + IPath projectLocation = project.getLocation(); + IPath directory = Path.fromOSString(resourceLocation); + if (projectLocation == null || !projectLocation.isPrefixOf(directory)) { + return directory; + } + return directory.removeFirstSegments(projectLocation.segmentCount()) + .makeRelative().setDevice(null); + } + + + public String getCustomWebXml(MavenProject mavenProject, IProject project) { + Plugin plugin = mavenProject + .getPlugin("org.apache.maven.plugins:maven-war-plugin"); + if (plugin == null) { + return null; + } + Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration(); + if (config != null) { + Xpp3Dom webXmlDom = config.getChild("webXml"); + if (webXmlDom != null && webXmlDom.getValue() != null) { + String webXmlFile = webXmlDom.getValue().trim(); + webXmlFile = getRelativePath(project, webXmlFile); + return webXmlFile; + } + } + return null; + } + + private static String getRelativePath(IProject project, String absolutePath) { + File basedir = project.getLocation().toFile(); + String relative; + if (absolutePath.equals(basedir.getAbsolutePath())) { + relative = "."; + } else if (absolutePath.startsWith(basedir.getAbsolutePath())) { + relative = absolutePath.substring(basedir.getAbsolutePath() + .length() + 1); + } else { + relative = absolutePath; + } + return relative.replace('\\', '/'); //$NON-NLS-1$ //$NON-NLS-2$ + } + + private boolean configureWebxml() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + return store.getBoolean(Activator.CONFIGURE_WEBXML_JSF20); + } + + private String getJSFVersion(MavenProject mavenProject) { + String version = null; + version = Activator.getDefault().getDependencyVersion(mavenProject, JSF_API_GROUP_ID, JSF_API_ARTIFACT_ID); + if (version == null) { + version = Activator.getDefault().getDependencyVersion(mavenProject, JSF_API2_GROUP_ID, JSF_API_ARTIFACT_ID); + } + if (version == null) { + version = inferJsfVersionFromDependencies(mavenProject, JSF_API2_GROUP_ID, JSF_API_ARTIFACT_ID, JSF_VERSION_2_0); + } + return version; + } + + private String inferJsfVersionFromDependencies(MavenProject mavenProject, String groupId, String artifactId, String defaultVersion) { + boolean hasCandidates = false; + String jsfVersion = null; + List repos = mavenProject.getRemoteArtifactRepositories(); + for (Artifact artifact : mavenProject.getArtifacts()) { + if (isKnownJsfBasedArtifact(artifact)) { + hasCandidates = true; + jsfVersion = Activator.getDefault().getDependencyVersion(artifact, repos, groupId, artifactId); + if (jsfVersion != null) { + //TODO should probably not break and take the highest version returned from all dependencies + break; + } + } + } + //Fallback to default JSF version + if (hasCandidates && jsfVersion == null) { + return defaultVersion; + } + return jsfVersion; + } + + private boolean isKnownJsfBasedArtifact(Artifact artifact) { + return artifact.getGroupId().startsWith("org.jboss.seam.") //$NON-NLS-1$ + && artifact.getArtifactId().equals("seam-faces") //$NON-NLS-1$ + && artifact.getVersion().startsWith("3."); //$NON-NLS-1$ + } + + +} #P org.jboss.tools.maven.cdi.feature Index: feature.xml =================================================================== --- feature.xml (revision 32782) +++ feature.xml (working copy) @@ -2,7 +2,7 @@ @@ -19,10 +19,10 @@ - - + + - + - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + features + 0.0.1-SNAPSHOT org.jboss.tools.maven.features - org.jboss.tools.maven.cdi.feature - 1.0.0-SNAPSHOT + org.jboss.tools.maven.cdi.feature + 1.2.0-SNAPSHOT eclipse-feature - + \ No newline at end of file Index: feature.properties =================================================================== --- feature.properties (revision 32782) +++ feature.properties (working copy) @@ -1,53 +1,53 @@ -############################################################################### -# Copyright (c) 2011 Red Hat, Inc. 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: -# JBoss by Red Hat - Initial implementation. -############################################################################## -# feature.properties -# contains externalized strings for feature.xml -# "%foo" in feature.xml corresponds to the key "foo" in this file -# java.io.Properties file (ISO 8859-1 with "\" escapes) -# This file should be translated. - -# "featureName" property - name of the feature -featureName=JBoss Maven CDI Configurator - -# "providerName" property - name of the company that provides the feature -providerName=JBoss by Red Hat - -# "updateSiteName" property - label for the update site -updateSiteName=JBossTools Update Site - -# "description" property - description of the feature -description=JBoss Maven Seam Integration - -# "copyright" property - text of the "Feature Update Copyright" -copyright=Copyright (c) 2011 Red Hat, Inc. and others.\n\ -All rights reserved. This program and the accompanying materials\n\ -are made available under the terms of the Eclipse Public License v1.0\n\ -which accompanies this distribution, and is available at\n\ -http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ -JBoss by Red Hat - Initial implementation. - ############### end of copyright property #################################### - -# "licenseURL" property - URL of the "Feature License" -# do not translate value - just change to point to a locale-specific HTML page -licenseURL=license.html - -# START NON-TRANSLATABLE -# "license" property - text of the "Feature Update License" -# should be plain text version of license agreement pointed to be "licenseURL" -license=Red Hat, Inc. licenses these features and plugins to you under \ -certain open source licenses (or aggregations of such licenses), which \ -in a particular case may include the Eclipse Public License, the GNU \ -Lesser General Public License, and/or certain other open source \ -licenses. For precise licensing details, consult the corresponding \ -source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ -Raleigh NC 27606 USA. -# END NON-TRANSLATABLE -########### end of license property ########################################## +############################################################################### +# Copyright (c) 2010-2011 Red Hat, Inc. 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: +# JBoss by Red Hat - Initial implementation. +############################################################################## +# feature.properties +# contains externalized strings for feature.xml +# "%foo" in feature.xml corresponds to the key "foo" in this file +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# This file should be translated. + +# "featureName" property - name of the feature +featureName=JBoss Maven CDI Configurator + +# "providerName" property - name of the company that provides the feature +providerName=JBoss by Red Hat + +# "updateSiteName" property - label for the update site +updateSiteName=JBossTools Update Site + +# "description" property - description of the feature +description=JBoss Maven Seam Integration + +# "copyright" property - text of the "Feature Update Copyright" +copyright=Copyright (c) 2010-2011 Red Hat, Inc. and others.\n\ +All rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\n\ +which accompanies this distribution, and is available at\n\ +http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ +JBoss by Red Hat - Initial implementation. + ############### end of copyright property #################################### + +# "licenseURL" property - URL of the "Feature License" +# do not translate value - just change to point to a locale-specific HTML page +licenseURL=license.html + +# START NON-TRANSLATABLE +# "license" property - text of the "Feature Update License" +# should be plain text version of license agreement pointed to be "licenseURL" +license=Red Hat, Inc. licenses these features and plugins to you under \ +certain open source licenses (or aggregations of such licenses), which \ +in a particular case may include the Eclipse Public License, the GNU \ +Lesser General Public License, and/or certain other open source \ +licenses. For precise licensing details, consult the corresponding \ +source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ +Raleigh NC 27606 USA. +# END NON-TRANSLATABLE +########### end of license property ########################################## #P org.jboss.tools.maven.ui Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.jboss.tools.maven.ui; singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Localization: plugin Bundle-Activator: org.jboss.tools.maven.ui.Activator Require-Bundle: org.eclipse.ui, Index: src/org/jboss/tools/maven/ui/preferences/ConfiguratorPreferencePage.java =================================================================== --- src/org/jboss/tools/maven/ui/preferences/ConfiguratorPreferencePage.java (revision 32782) +++ src/org/jboss/tools/maven/ui/preferences/ConfiguratorPreferencePage.java (working copy) @@ -1,226 +1,241 @@ -package org.jboss.tools.maven.ui.preferences; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.jboss.tools.maven.ui.Activator; -import org.jboss.tools.maven.ui.Messages; -import org.osgi.framework.Bundle; - -public class ConfiguratorPreferencePage extends PreferencePage implements - IWorkbenchPreferencePage { - - - private static final String ORG_JBOSS_TOOLS_MAVEN_JSF = "org.jboss.tools.maven.jsf"; //$NON-NLS-1$ - private static final String ORG_JBOSS_TOOLS_MAVEN_PORTLET = "org.jboss.tools.maven.portlet"; //$NON-NLS-1$ - private static final String ORG_JBOSS_TOOLS_MAVEN_CDI = "org.jboss.tools.maven.cdi"; //$NON-NLS-1$ - private static final String ORG_JBOSS_TOOLS_MAVEN_HIBERNATE = "org.jboss.tools.maven.hibernate"; //$NON-NLS-1$ - private static final String ORG_JBOSS_TOOLS_MAVEN_SEAM = "org.jboss.tools.maven.seam"; //$NON-NLS-1$ - - private Button configureSeamButton; - private Button configureSeamRuntimeButton; - private Button configureSeamArtifactsButton; - private Button configureJSFButton; - private Button configureWebxmlJSF20Button; - private Button configurePortletButton; - private Button configureJSFPortletButton; - private Button configureSeamPortletButton; - private Button configureCDIButton; - private Button configureHibernateButton; - - @Override - protected Control createContents(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(1, false); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Label label = new Label(composite, SWT.NONE); - label.setText(Messages.ConfiguratorPreferencePage_When_importing_Maven_projects_configure_the_following); - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { - configureSeamButton = new Button(composite,SWT.CHECK); - configureSeamButton.setText(Messages.ConfiguratorPreferencePage_Configure_Seam_when_importing_Maven_projects); - boolean configureSeam = store.getBoolean(Activator.CONFIGURE_SEAM); - configureSeamButton.setSelection(configureSeam); - - configureSeamRuntimeButton = new Button(composite,SWT.CHECK); - configureSeamRuntimeButton.setText(Messages.ConfiguratorPreferencePage_Configure_Seam_Runtime); - boolean configureSeamRuntime = store.getBoolean(Activator.CONFIGURE_SEAM_RUNTIME); - configureSeamRuntimeButton.setSelection(configureSeamRuntime); - configureSeamRuntimeButton.setEnabled(configureSeam); - - configureSeamArtifactsButton = new Button(composite,SWT.CHECK); - configureSeamArtifactsButton.setText(Messages.ConfiguratorPreferencePage_Configure_Seam_Artifacts); - boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); - configureSeamArtifactsButton.setSelection(configureSeamArtifacts); - configureSeamArtifactsButton.setEnabled(configureSeam); - - configureSeamButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - configureSeamRuntimeButton.setEnabled(configureSeamButton.getSelection()); - configureSeamArtifactsButton.setEnabled(configureSeamButton.getSelection()); - } - - }); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { - configureJSFButton = new Button(composite,SWT.CHECK); - configureJSFButton.setText(Messages.ConfiguratorPreferencePage_Configure_JSF_facet); - boolean configureJSF = store.getBoolean(Activator.CONFIGURE_JSF); - configureJSFButton.setSelection(configureJSF); - - configureWebxmlJSF20Button = new Button(composite,SWT.CHECK); - configureWebxmlJSF20Button.setText(Messages.ConfiguratorPreferencePage_Configure_Webxml_JSF20); - boolean configureWebxml = store.getBoolean(Activator.CONFIGURE_WEBXML_JSF20); - configureWebxmlJSF20Button.setSelection(configureWebxml); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { - configurePortletButton = new Button(composite,SWT.CHECK); - configurePortletButton.setText(Messages.ConfiguratorPreferencePage_Configure_JBoss_Portlet_Core_facet); - boolean configurePortlet = store.getBoolean(Activator.CONFIGURE_PORTLET); - configurePortletButton.setSelection(configurePortlet); - - - configureJSFPortletButton = new Button(composite,SWT.CHECK); - configureJSFPortletButton.setText(Messages.ConfiguratorPreferencePage_Configure_JBoss_JSF_Portlet_facet); - boolean configureJSFPortlet = store.getBoolean(Activator.CONFIGURE_JSFPORTLET); - configureJSFPortletButton.setSelection(configureJSFPortlet); - - configureSeamPortletButton = new Button(composite,SWT.CHECK); - configureSeamPortletButton.setText(Messages.ConfiguratorPreferencePage_Configure_JBoss_Seam_Portlet_facet); - boolean configureSeamPortlet = store.getBoolean(Activator.CONFIGURE_SEAMPORTLET); - configureSeamPortletButton.setSelection(configureSeamPortlet); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { - configureCDIButton = new Button(composite,SWT.CHECK); - configureCDIButton.setText(Messages.ConfiguratorPreferencePage_Configure_CDI_facet); - boolean configureCDI = store.getBoolean(Activator.CONFIGURE_CDI); - configureCDIButton.setSelection(configureCDI); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { - configureHibernateButton = new Button(composite,SWT.CHECK); - configureHibernateButton.setText(Messages.ConfiguratorPreferencePage_Configure_Hibernate); - boolean configureHibernate = store.getBoolean(Activator.CONFIGURE_HIBERNATE); - configureHibernateButton.setSelection(configureHibernate); - } - - return composite; - } - - private boolean bundleExists(String bundleId) { - Bundle bundle = Platform.getBundle(bundleId); - return bundle != null; - } - - public void init(IWorkbench workbench) { - } - - @Override - protected void performDefaults() { - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { - configureJSFButton.setSelection(Activator.CONFIGURE_JSF_VALUE); - configureWebxmlJSF20Button.setSelection(Activator.CONFIGURE_WEBXML_JSF20_VALUE); - } - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { - configureSeamButton.setSelection(Activator.CONFIGURE_SEAM_VALUE); - configureSeamRuntimeButton.setSelection(Activator.CONFIGURE_SEAM_RUNTIME_VALUE); - configureSeamArtifactsButton.setSelection(Activator.CONFIGURE_SEAM_ARTIFACTS_VALUE); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { - configurePortletButton.setSelection(Activator.CONFIGURE_PORTLET_VALUE); - configureJSFPortletButton.setSelection(Activator.CONFIGURE_JSFPORTLET_VALUE); - configureSeamPortletButton.setSelection(Activator.CONFIGURE_SEAMPORTLET_VALUE); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { - configureCDIButton.setSelection(Activator.CONFIGURE_CDI_VALUE); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { - configureHibernateButton.setSelection(Activator.CONFIGURE_HIBERNATE_VALUE); - } - - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { - store.setValue(Activator.CONFIGURE_JSF, Activator.CONFIGURE_JSF_VALUE); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { - store.setValue(Activator.CONFIGURE_JSFPORTLET, Activator.CONFIGURE_JSFPORTLET_VALUE); - store.setValue(Activator.CONFIGURE_SEAMPORTLET, Activator.CONFIGURE_SEAMPORTLET_VALUE); - store.setValue(Activator.CONFIGURE_PORTLET, Activator.CONFIGURE_PORTLET_VALUE); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { - store.setValue(Activator.CONFIGURE_SEAM, Activator.CONFIGURE_SEAM_VALUE); - store.setValue(Activator.CONFIGURE_SEAM_RUNTIME, Activator.CONFIGURE_SEAM_RUNTIME_VALUE); - store.setValue(Activator.CONFIGURE_SEAM_ARTIFACTS, Activator.CONFIGURE_SEAM_ARTIFACTS_VALUE); - configureSeamRuntimeButton.setEnabled(configureSeamButton.getSelection()); - configureSeamArtifactsButton.setEnabled(configureSeamButton.getSelection()); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { - store.setValue(Activator.CONFIGURE_CDI, Activator.CONFIGURE_CDI_VALUE); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { - store.setValue(Activator.CONFIGURE_HIBERNATE, Activator.CONFIGURE_HIBERNATE_VALUE); - } - - super.performDefaults(); - } - - @Override - public boolean performOk() { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { - store.setValue(Activator.CONFIGURE_JSF, configureJSFButton.getSelection()); - store.setValue(Activator.CONFIGURE_WEBXML_JSF20, configureWebxmlJSF20Button.getSelection()); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { - store.setValue(Activator.CONFIGURE_PORTLET, configurePortletButton.getSelection()); - store.setValue(Activator.CONFIGURE_JSFPORTLET, configureJSFPortletButton.getSelection()); - store.setValue(Activator.CONFIGURE_SEAMPORTLET, configureSeamPortletButton.getSelection()); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { - store.setValue(Activator.CONFIGURE_SEAM, configureSeamButton.getSelection()); - store.setValue(Activator.CONFIGURE_SEAM_RUNTIME, configureSeamRuntimeButton.getSelection()); - store.setValue(Activator.CONFIGURE_SEAM_ARTIFACTS, configureSeamArtifactsButton.getSelection()); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { - store.setValue(Activator.CONFIGURE_CDI, configureCDIButton.getSelection()); - } - - if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { - store.setValue(Activator.CONFIGURE_HIBERNATE, configureHibernateButton.getSelection()); - } - - return super.performOk(); - } - - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui.preferences; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.jboss.tools.maven.ui.Activator; +import org.jboss.tools.maven.ui.Messages; +import org.osgi.framework.Bundle; + +/** + * + * @author snjeza + * + */ +public class ConfiguratorPreferencePage extends PreferencePage implements + IWorkbenchPreferencePage { + + + private static final String ORG_JBOSS_TOOLS_MAVEN_JSF = "org.jboss.tools.maven.jsf"; //$NON-NLS-1$ + private static final String ORG_JBOSS_TOOLS_MAVEN_PORTLET = "org.jboss.tools.maven.portlet"; //$NON-NLS-1$ + private static final String ORG_JBOSS_TOOLS_MAVEN_CDI = "org.jboss.tools.maven.cdi"; //$NON-NLS-1$ + private static final String ORG_JBOSS_TOOLS_MAVEN_HIBERNATE = "org.jboss.tools.maven.hibernate"; //$NON-NLS-1$ + private static final String ORG_JBOSS_TOOLS_MAVEN_SEAM = "org.jboss.tools.maven.seam"; //$NON-NLS-1$ + + private Button configureSeamButton; + private Button configureSeamRuntimeButton; + private Button configureSeamArtifactsButton; + private Button configureJSFButton; + private Button configureWebxmlJSF20Button; + private Button configurePortletButton; + private Button configureJSFPortletButton; + private Button configureSeamPortletButton; + private Button configureCDIButton; + private Button configureHibernateButton; + + @Override + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(1, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + composite.setLayout(layout); + + Label label = new Label(composite, SWT.NONE); + label.setText(Messages.ConfiguratorPreferencePage_When_importing_Maven_projects_configure_the_following); + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { + configureSeamButton = new Button(composite,SWT.CHECK); + configureSeamButton.setText(Messages.ConfiguratorPreferencePage_Configure_Seam_when_importing_Maven_projects); + boolean configureSeam = store.getBoolean(Activator.CONFIGURE_SEAM); + configureSeamButton.setSelection(configureSeam); + + configureSeamRuntimeButton = new Button(composite,SWT.CHECK); + configureSeamRuntimeButton.setText(Messages.ConfiguratorPreferencePage_Configure_Seam_Runtime); + boolean configureSeamRuntime = store.getBoolean(Activator.CONFIGURE_SEAM_RUNTIME); + configureSeamRuntimeButton.setSelection(configureSeamRuntime); + configureSeamRuntimeButton.setEnabled(configureSeam); + + configureSeamArtifactsButton = new Button(composite,SWT.CHECK); + configureSeamArtifactsButton.setText(Messages.ConfiguratorPreferencePage_Configure_Seam_Artifacts); + boolean configureSeamArtifacts = store.getBoolean(Activator.CONFIGURE_SEAM_ARTIFACTS); + configureSeamArtifactsButton.setSelection(configureSeamArtifacts); + configureSeamArtifactsButton.setEnabled(configureSeam); + + configureSeamButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + configureSeamRuntimeButton.setEnabled(configureSeamButton.getSelection()); + configureSeamArtifactsButton.setEnabled(configureSeamButton.getSelection()); + } + + }); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { + configureJSFButton = new Button(composite,SWT.CHECK); + configureJSFButton.setText(Messages.ConfiguratorPreferencePage_Configure_JSF_facet); + boolean configureJSF = store.getBoolean(Activator.CONFIGURE_JSF); + configureJSFButton.setSelection(configureJSF); + + configureWebxmlJSF20Button = new Button(composite,SWT.CHECK); + configureWebxmlJSF20Button.setText(Messages.ConfiguratorPreferencePage_Configure_Webxml_JSF20); + boolean configureWebxml = store.getBoolean(Activator.CONFIGURE_WEBXML_JSF20); + configureWebxmlJSF20Button.setSelection(configureWebxml); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { + configurePortletButton = new Button(composite,SWT.CHECK); + configurePortletButton.setText(Messages.ConfiguratorPreferencePage_Configure_JBoss_Portlet_Core_facet); + boolean configurePortlet = store.getBoolean(Activator.CONFIGURE_PORTLET); + configurePortletButton.setSelection(configurePortlet); + + + configureJSFPortletButton = new Button(composite,SWT.CHECK); + configureJSFPortletButton.setText(Messages.ConfiguratorPreferencePage_Configure_JBoss_JSF_Portlet_facet); + boolean configureJSFPortlet = store.getBoolean(Activator.CONFIGURE_JSFPORTLET); + configureJSFPortletButton.setSelection(configureJSFPortlet); + + configureSeamPortletButton = new Button(composite,SWT.CHECK); + configureSeamPortletButton.setText(Messages.ConfiguratorPreferencePage_Configure_JBoss_Seam_Portlet_facet); + boolean configureSeamPortlet = store.getBoolean(Activator.CONFIGURE_SEAMPORTLET); + configureSeamPortletButton.setSelection(configureSeamPortlet); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { + configureCDIButton = new Button(composite,SWT.CHECK); + configureCDIButton.setText(Messages.ConfiguratorPreferencePage_Configure_CDI_facet); + boolean configureCDI = store.getBoolean(Activator.CONFIGURE_CDI); + configureCDIButton.setSelection(configureCDI); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { + configureHibernateButton = new Button(composite,SWT.CHECK); + configureHibernateButton.setText(Messages.ConfiguratorPreferencePage_Configure_Hibernate); + boolean configureHibernate = store.getBoolean(Activator.CONFIGURE_HIBERNATE); + configureHibernateButton.setSelection(configureHibernate); + } + + return composite; + } + + private boolean bundleExists(String bundleId) { + Bundle bundle = Platform.getBundle(bundleId); + return bundle != null; + } + + public void init(IWorkbench workbench) { + } + + @Override + protected void performDefaults() { + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { + configureJSFButton.setSelection(Activator.CONFIGURE_JSF_VALUE); + configureWebxmlJSF20Button.setSelection(Activator.CONFIGURE_WEBXML_JSF20_VALUE); + } + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { + configureSeamButton.setSelection(Activator.CONFIGURE_SEAM_VALUE); + configureSeamRuntimeButton.setSelection(Activator.CONFIGURE_SEAM_RUNTIME_VALUE); + configureSeamArtifactsButton.setSelection(Activator.CONFIGURE_SEAM_ARTIFACTS_VALUE); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { + configurePortletButton.setSelection(Activator.CONFIGURE_PORTLET_VALUE); + configureJSFPortletButton.setSelection(Activator.CONFIGURE_JSFPORTLET_VALUE); + configureSeamPortletButton.setSelection(Activator.CONFIGURE_SEAMPORTLET_VALUE); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { + configureCDIButton.setSelection(Activator.CONFIGURE_CDI_VALUE); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { + configureHibernateButton.setSelection(Activator.CONFIGURE_HIBERNATE_VALUE); + } + + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { + store.setValue(Activator.CONFIGURE_JSF, Activator.CONFIGURE_JSF_VALUE); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { + store.setValue(Activator.CONFIGURE_JSFPORTLET, Activator.CONFIGURE_JSFPORTLET_VALUE); + store.setValue(Activator.CONFIGURE_SEAMPORTLET, Activator.CONFIGURE_SEAMPORTLET_VALUE); + store.setValue(Activator.CONFIGURE_PORTLET, Activator.CONFIGURE_PORTLET_VALUE); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { + store.setValue(Activator.CONFIGURE_SEAM, Activator.CONFIGURE_SEAM_VALUE); + store.setValue(Activator.CONFIGURE_SEAM_RUNTIME, Activator.CONFIGURE_SEAM_RUNTIME_VALUE); + store.setValue(Activator.CONFIGURE_SEAM_ARTIFACTS, Activator.CONFIGURE_SEAM_ARTIFACTS_VALUE); + configureSeamRuntimeButton.setEnabled(configureSeamButton.getSelection()); + configureSeamArtifactsButton.setEnabled(configureSeamButton.getSelection()); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { + store.setValue(Activator.CONFIGURE_CDI, Activator.CONFIGURE_CDI_VALUE); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { + store.setValue(Activator.CONFIGURE_HIBERNATE, Activator.CONFIGURE_HIBERNATE_VALUE); + } + + super.performDefaults(); + } + + @Override + public boolean performOk() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_JSF)) { + store.setValue(Activator.CONFIGURE_JSF, configureJSFButton.getSelection()); + store.setValue(Activator.CONFIGURE_WEBXML_JSF20, configureWebxmlJSF20Button.getSelection()); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_PORTLET)) { + store.setValue(Activator.CONFIGURE_PORTLET, configurePortletButton.getSelection()); + store.setValue(Activator.CONFIGURE_JSFPORTLET, configureJSFPortletButton.getSelection()); + store.setValue(Activator.CONFIGURE_SEAMPORTLET, configureSeamPortletButton.getSelection()); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_SEAM)) { + store.setValue(Activator.CONFIGURE_SEAM, configureSeamButton.getSelection()); + store.setValue(Activator.CONFIGURE_SEAM_RUNTIME, configureSeamRuntimeButton.getSelection()); + store.setValue(Activator.CONFIGURE_SEAM_ARTIFACTS, configureSeamArtifactsButton.getSelection()); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_CDI)) { + store.setValue(Activator.CONFIGURE_CDI, configureCDIButton.getSelection()); + } + + if (bundleExists(ORG_JBOSS_TOOLS_MAVEN_HIBERNATE)) { + store.setValue(Activator.CONFIGURE_HIBERNATE, configureHibernateButton.getSelection()); + } + + return super.performOk(); + } + + +} Index: src/org/jboss/tools/maven/ui/Activator.java =================================================================== --- src/org/jboss/tools/maven/ui/Activator.java (revision 32782) +++ src/org/jboss/tools/maven/ui/Activator.java (working copy) @@ -1,136 +1,215 @@ -package org.jboss.tools.maven.ui; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.model.Dependency; -import org.apache.maven.project.MavenProject; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.jboss.tools.maven.ui"; //$NON-NLS-1$ - - public static final String CONFIGURE_SEAM = "configureSeam"; //$NON-NLS-1$ - - public static final String CONFIGURE_PORTLET = "configurePortlet"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_SEAM_VALUE = true; - - public static final String CONFIGURE_SEAM_RUNTIME = "configureSeamRuntime"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_SEAM_RUNTIME_VALUE = true; - - public static final String CONFIGURE_SEAM_ARTIFACTS = "configureSeamArtifacts"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_SEAM_ARTIFACTS_VALUE = true; - - public static final String CONFIGURE_JSF = "configureJSF"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_JSF_VALUE = true; - - public static final String CONFIGURE_WEBXML_JSF20 = "configureWebxmlJSF20"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_WEBXML_JSF20_VALUE = false; - - public static final boolean CONFIGURE_PORTLET_VALUE = true; - - public static final String CONFIGURE_JSFPORTLET = "configureJSFPortlet"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_JSFPORTLET_VALUE = true; - - public static final String CONFIGURE_SEAMPORTLET = "configureSeamPortlet"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_SEAMPORTLET_VALUE = true; - - public static final String CONFIGURE_CDI = "configureCDI"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_CDI_VALUE = true; - - public static final String CONFIGURE_HIBERNATE = "configureHibernate"; //$NON-NLS-1$ - - public static final boolean CONFIGURE_HIBERNATE_VALUE = true; - - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (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); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - - public static void log(Throwable e) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); - getDefault().getLog().log(status); - } - - public static void log(String message) { - IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message); - getDefault().getLog().log(status); - } - - public String getDependencyVersion(MavenProject mavenProject, String gid, String aid) { - List artifacts = new ArrayList(); - ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter( - Artifact.SCOPE_TEST); - for (Artifact artifact : mavenProject.getArtifacts()) { - if (filter.include(artifact)) { - artifacts.add(artifact); - } - } - for (Artifact artifact:artifacts) { - String groupId = artifact.getGroupId(); - if (groupId != null && (groupId.equals(gid)) ) { - String artifactId = artifact.getArtifactId(); - if (artifactId != null && artifactId.equals(aid)) { - return artifact.getVersion(); - } - } - } - return null; - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.internal.embedder.MavenImpl; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.maven.ui"; //$NON-NLS-1$ + + public static final String CONFIGURE_SEAM = "configureSeam"; //$NON-NLS-1$ + + public static final String CONFIGURE_PORTLET = "configurePortlet"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_SEAM_VALUE = true; + + public static final String CONFIGURE_SEAM_RUNTIME = "configureSeamRuntime"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_SEAM_RUNTIME_VALUE = true; + + public static final String CONFIGURE_SEAM_ARTIFACTS = "configureSeamArtifacts"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_SEAM_ARTIFACTS_VALUE = true; + + public static final String CONFIGURE_JSF = "configureJSF"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_JSF_VALUE = true; + + public static final String CONFIGURE_WEBXML_JSF20 = "configureWebxmlJSF20"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_WEBXML_JSF20_VALUE = false; + + public static final boolean CONFIGURE_PORTLET_VALUE = true; + + public static final String CONFIGURE_JSFPORTLET = "configureJSFPortlet"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_JSFPORTLET_VALUE = true; + + public static final String CONFIGURE_SEAMPORTLET = "configureSeamPortlet"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_SEAMPORTLET_VALUE = true; + + public static final String CONFIGURE_CDI = "configureCDI"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_CDI_VALUE = true; + + public static final String CONFIGURE_HIBERNATE = "configureHibernate"; //$NON-NLS-1$ + + public static final boolean CONFIGURE_HIBERNATE_VALUE = true; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (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); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + public static void log(Throwable e) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); + getDefault().getLog().log(status); + } + + public static void log(String message) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message); + getDefault().getLog().log(status); + } + + public String getDependencyVersion(MavenProject mavenProject, String gid, String aid) { + List artifacts = new ArrayList(); + ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter( + Artifact.SCOPE_TEST); + for (Artifact artifact : mavenProject.getArtifacts()) { + if (filter.include(artifact)) { + artifacts.add(artifact); + } + } + for (Artifact artifact:artifacts) { + String groupId = artifact.getGroupId(); + if (groupId != null && (groupId.equals(gid)) ) { + String artifactId = artifact.getArtifactId(); + if (artifactId != null && artifactId.equals(aid)) { + return artifact.getVersion(); + } + } + } + return null; + } + + @SuppressWarnings("restriction") + public String getDependencyVersion(Artifact artifact, List remoteRepos, String gid, String aid) { + IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject( + artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); + //If the artifact is a workspace dependency, the mavenProject is already loaded + if (facade != null) { + return getDependencyVersion(facade.getMavenProject(), gid, aid); + } + + //look at the artifact pom file and if it exists, load the corresponding MavenProject + File pom = getPomFile(artifact); + String version = null; + if (pom != null) { + MavenProject mavenProject = null; + MavenImpl maven = (MavenImpl)MavenPlugin.getMaven(); + try { + //Create a custom execution request + IProgressMonitor monitor = new NullProgressMonitor(); + MavenExecutionRequest request = maven.createExecutionRequest(monitor); + for (ArtifactRepository repo : remoteRepos) { + request.addRemoteRepository(repo); + } + request.setPom(pom); + request.getProjectBuildingRequest().setResolveDependencies(true); + + //Load the MavenProject + MavenExecutionResult result = maven.readProject(request, monitor); + //log errors + if (result.hasExceptions()) { + for (Throwable e : result.getExceptions()) { + log(e); + } + } else { + mavenProject = result.getProject(); + if (mavenProject != null) { + //finally look at the dependency version + version = getDependencyVersion(mavenProject , gid, aid); + //Detach the mavenProject from the maven session to avoid memory leaks + maven.detachFromSession(mavenProject); + } + } + } catch (CoreException e) { + //Don't crash on failures to read the dependency version + log(e); + } + } + return version; + } + + private File getPomFile(Artifact artifact) { + File artifactFile = artifact.getFile(); + if (artifactFile != null) { + String path = artifactFile.getAbsolutePath(); + int lastIndexOfDot = path.lastIndexOf("."); //$NON-NLS-1$ + if (lastIndexOfDot > 0) { + String pomPath = path.substring(0, lastIndexOfDot)+".pom"; //$NON-NLS-1$ + File pomFile = new File(pomPath); + if (pomFile.exists() && pomFile.canRead()) { + return pomFile; + } + } + //TODO look inside the artifact jar if pom isn't available + } + return null; + } + +} Index: src/org/jboss/tools/maven/ui/Messages.java =================================================================== --- src/org/jboss/tools/maven/ui/Messages.java (revision 32782) +++ src/org/jboss/tools/maven/ui/Messages.java (working copy) @@ -1,50 +1,65 @@ -package org.jboss.tools.maven.ui; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.jboss.tools.maven.ui.messages"; //$NON-NLS-1$ - public static String ConfiguratorPreferencePage_Configure_Webxml_JSF20; - public static String AutoResizeTableLayout_Unknown_column_layout_data; - public static String MavenFacetInstallPage_Add_M2_capabilities_to_this_Web_Project; - public static String MavenFacetInstallPage_Artifact_Id; - public static String MavenFacetInstallPage_Description; - public static String MavenFacetInstallPage_Group_Id; - public static String MavenFacetInstallPage_JBoss_M2_capabilities; - public static String MavenFacetInstallPage_Name; - public static String MavenFacetInstallPage_Packaging; - public static String MavenFacetInstallPage_Remove_WTP_Classpath_containers; - public static String MavenFacetInstallPage_Seam_Maven_version; - public static String MavenFacetInstallPage_Version; - public static String MavenUserLibraryProviderInstallPanel_Add; - public static String MavenUserLibraryProviderInstallPanel_Are_you_sure_you_want_to_remove_the_artifact; - public static String MavenUserLibraryProviderInstallPanel_ArtifactId; - public static String MavenUserLibraryProviderInstallPanel_Dependencies; - public static String MavenUserLibraryProviderInstallPanel_Exclusions; - public static String MavenUserLibraryProviderInstallPanel_GroupId; - public static String MavenUserLibraryProviderInstallPanel_Remove; - public static String MavenUserLibraryProviderInstallPanel_Remove_dependency; - public static String MavenUserLibraryProviderInstallPanel_Remove_exclusion; - public static String MavenUserLibraryProviderInstallPanel_Restore_Defaults; - public static String MavenUserLibraryProviderInstallPanel_Scope; - public static String MavenUserLibraryProviderInstallPanel_Type; - public static String MavenUserLibraryProviderInstallPanel_Version; - public static String ConfiguratorPreferencePage_Configure_JBoss_JSF_Portlet_facet; - public static String ConfiguratorPreferencePage_Configure_JBoss_Portlet_Core_facet; - public static String ConfiguratorPreferencePage_Configure_JBoss_Seam_Portlet_facet; - public static String ConfiguratorPreferencePage_Configure_JSF_facet; - public static String ConfiguratorPreferencePage_Configure_CDI_facet; - public static String ConfiguratorPreferencePage_Configure_Hibernate; - public static String ConfiguratorPreferencePage_Configure_Seam_Artifacts; - public static String ConfiguratorPreferencePage_Configure_Seam_Runtime; - public static String ConfiguratorPreferencePage_Configure_Seam_when_importing_Maven_projects; - public static String ConfiguratorPreferencePage_When_importing_Maven_projects_configure_the_following; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui; + +import org.eclipse.osgi.util.NLS; + +/** + * + * @author snjeza + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.jboss.tools.maven.ui.messages"; //$NON-NLS-1$ + public static String ConfiguratorPreferencePage_Configure_Webxml_JSF20; + public static String AutoResizeTableLayout_Unknown_column_layout_data; + public static String MavenFacetInstallPage_Add_M2_capabilities_to_this_Web_Project; + public static String MavenFacetInstallPage_Artifact_Id; + public static String MavenFacetInstallPage_Description; + public static String MavenFacetInstallPage_Group_Id; + public static String MavenFacetInstallPage_JBoss_M2_capabilities; + public static String MavenFacetInstallPage_Name; + public static String MavenFacetInstallPage_Packaging; + public static String MavenFacetInstallPage_Remove_WTP_Classpath_containers; + public static String MavenFacetInstallPage_Seam_Maven_version; + public static String MavenFacetInstallPage_Version; + public static String MavenUserLibraryProviderInstallPanel_Add; + public static String MavenUserLibraryProviderInstallPanel_Are_you_sure_you_want_to_remove_the_artifact; + public static String MavenUserLibraryProviderInstallPanel_ArtifactId; + public static String MavenUserLibraryProviderInstallPanel_Dependencies; + public static String MavenUserLibraryProviderInstallPanel_Exclusions; + public static String MavenUserLibraryProviderInstallPanel_GroupId; + public static String MavenUserLibraryProviderInstallPanel_Remove; + public static String MavenUserLibraryProviderInstallPanel_Remove_dependency; + public static String MavenUserLibraryProviderInstallPanel_Remove_exclusion; + public static String MavenUserLibraryProviderInstallPanel_Restore_Defaults; + public static String MavenUserLibraryProviderInstallPanel_Scope; + public static String MavenUserLibraryProviderInstallPanel_Type; + public static String MavenUserLibraryProviderInstallPanel_Version; + public static String ConfiguratorPreferencePage_Configure_JBoss_JSF_Portlet_facet; + public static String ConfiguratorPreferencePage_Configure_JBoss_Portlet_Core_facet; + public static String ConfiguratorPreferencePage_Configure_JBoss_Seam_Portlet_facet; + public static String ConfiguratorPreferencePage_Configure_JSF_facet; + public static String ConfiguratorPreferencePage_Configure_CDI_facet; + public static String ConfiguratorPreferencePage_Configure_Hibernate; + public static String ConfiguratorPreferencePage_Configure_Seam_Artifacts; + public static String ConfiguratorPreferencePage_Configure_Seam_Runtime; + public static String ConfiguratorPreferencePage_Configure_Seam_when_importing_Maven_projects; + public static String ConfiguratorPreferencePage_When_importing_Maven_projects_configure_the_following; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} Index: src/org/jboss/tools/maven/ui/internal/libprov/MavenUserLibraryProviderInstallPanel.java =================================================================== --- src/org/jboss/tools/maven/ui/internal/libprov/MavenUserLibraryProviderInstallPanel.java (revision 32782) +++ src/org/jboss/tools/maven/ui/internal/libprov/MavenUserLibraryProviderInstallPanel.java (working copy) @@ -1,499 +1,514 @@ -package org.jboss.tools.maven.ui.internal.libprov; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.ColumnLayoutData; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; -import org.eclipse.jst.common.project.facet.ui.libprov.LibraryProviderOperationPanel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.jboss.tools.maven.core.MavenCoreActivator; -import org.jboss.tools.maven.core.libprov.MavenLibraryProviderInstallOperationConfig; -import org.jboss.tools.maven.ui.Messages; -import org.maven.ide.components.pom.Dependency; -import org.maven.ide.components.pom.Exclusion; -import org.maven.ide.components.pom.Model; -import org.maven.ide.components.pom.PomFactory; -import org.maven.ide.components.pom.util.PomResourceImpl; - -public class MavenUserLibraryProviderInstallPanel extends - LibraryProviderOperationPanel { - - private TableViewer dependencyViewer; - protected ColumnLayoutData[] dependencyTableColumnLayouts= { - new ColumnWeightData(80,80), - new ColumnWeightData(80,80), - new ColumnWeightData(60,60), - new ColumnWeightData(60,60), - new ColumnWeightData(60,60) - }; - protected ColumnLayoutData[] exclusionTableColumnLayouts= { - new ColumnWeightData(80,80), - new ColumnWeightData(60,60) - }; - private List dependencies; - private TableViewer exclusionViewer; - private List exclusions; - private PomResourceImpl resource; - - @Override - public Control createControl(final Composite parent) { - resource = MavenCoreActivator.getResource(); - if (resource != null) { - resource.unload(); - MavenCoreActivator.setResource(null); - } - MavenLibraryProviderInstallOperationConfig config = (MavenLibraryProviderInstallOperationConfig) getOperationConfig(); - ILibraryProvider provider = config.getLibraryProvider(); - File providerFile = MavenCoreActivator.getProviderFile(provider); - URL url = null; - try { - if (providerFile.exists()) { - url = providerFile.toURL(); - } else { - Map params = provider.getParams(); - String pomURLString = params.get("template"); //$NON-NLS-1$ - URL platformURL = new URL(pomURLString); - url = FileLocator.resolve(platformURL); - } - - resource = MavenCoreActivator.loadResource(url); - MavenCoreActivator.setResource(resource); - Model model = resource.getModel(); - dependencies = model.getDependencies(); - config.setModel(model); - parent.addDisposeListener(new DisposeListener() { - - public void widgetDisposed(DisposeEvent e) { - parent.removeDisposeListener(this); - resource.unload(); - MavenCoreActivator.setResource(null); - } - }); - } catch (CoreException e) { - MavenCoreActivator.log(e); - } catch (IOException e) { - MavenCoreActivator.log(e); - } - - if (dependencies == null) { - dependencies = new ArrayList(); - } - - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label dependencyLabel = new Label(composite, SWT.NONE); - dependencyLabel.setText(Messages.MavenUserLibraryProviderInstallPanel_Dependencies); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.horizontalSpan=2; - dependencyLabel.setLayoutData(gd); - - createDependencyViewer(composite); - dependencyViewer.addSelectionChangedListener(new ISelectionChangedListener() { - - public void selectionChanged(SelectionChangedEvent event) { - ISelection sel = event.getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; - Object object = selection.getFirstElement(); - if (object instanceof Dependency) { - Dependency dependency = (Dependency) object; - exclusions = dependency.getExclusions(); - exclusionViewer.setInput(exclusions); - } - } - } - }); - - Label exclusionLabel = new Label(composite, SWT.NONE); - exclusionLabel.setText(Messages.MavenUserLibraryProviderInstallPanel_Exclusions); - gd = new GridData(GridData.FILL_BOTH); - gd.horizontalSpan=2; - exclusionLabel.setLayoutData(gd); - - createExclusionViewer(composite); - - if (dependencies.size() > 0) { - dependencyViewer.getTable().select(0); - exclusions = dependencies.get(0).getExclusions(); - exclusionViewer.setInput(exclusions); - } - return composite; - } - - private void createExclusionViewer(Composite parent) { - exclusionViewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.BORDER); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.heightHint = 60; - exclusionViewer.getTable().setLayoutData(gd); - //viewer.setLabelProvider(new TableLabelProvider()); - exclusionViewer.setContentProvider(new TableContentProvider()); - Table table = exclusionViewer.getTable(); - table.setHeaderVisible(true); - table.setLinesVisible(true); - table.setFont(parent.getFont()); - - String[] columnHeaders = {Messages.MavenUserLibraryProviderInstallPanel_GroupId,Messages.MavenUserLibraryProviderInstallPanel_ArtifactId}; - - for (int i = 0; i < columnHeaders.length; i++) { - TableViewerColumn column = new TableViewerColumn(exclusionViewer, SWT.NONE); - column.setLabelProvider(new ExclusionColumnLabelProvider(i)); - column.getColumn().setText(columnHeaders[i]); - column.getColumn().setResizable(true); - column.getColumn().setMoveable(true); - column.setEditingSupport(new ExclusionEditingSupport(exclusionViewer, i)); - - } - - - TableLayout layout = new AutoResizeTableLayout(table); - for (int i = 0; i < exclusionTableColumnLayouts.length; i++) { - layout.addColumnData(exclusionTableColumnLayouts[i]); - } - exclusionViewer.getTable().setLayout(layout); - - createExclusionButtons(parent); - - } - - private void createDependencyViewer(Composite parent) { - dependencyViewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.BORDER); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.heightHint = 80; - dependencyViewer.getTable().setLayoutData(gd); - //viewer.setLabelProvider(new TableLabelProvider()); - dependencyViewer.setContentProvider(new TableContentProvider()); - Table table = dependencyViewer.getTable(); - table.setHeaderVisible(true); - table.setLinesVisible(true); - table.setFont(parent.getFont()); - - String[] columnHeaders = {Messages.MavenUserLibraryProviderInstallPanel_GroupId,Messages.MavenUserLibraryProviderInstallPanel_ArtifactId,Messages.MavenUserLibraryProviderInstallPanel_Version,Messages.MavenUserLibraryProviderInstallPanel_Scope,Messages.MavenUserLibraryProviderInstallPanel_Type}; - - for (int i = 0; i < columnHeaders.length; i++) { - TableViewerColumn column = new TableViewerColumn(dependencyViewer, SWT.NONE); - column.setLabelProvider(new DependencyColumnLabelProvider(i)); - column.getColumn().setText(columnHeaders[i]); - column.getColumn().setResizable(true); - column.getColumn().setMoveable(true); - column.setEditingSupport(new DependencyEditingSupport(dependencyViewer, i)); - - } - - - TableLayout layout = new AutoResizeTableLayout(table); - for (int i = 0; i < dependencyTableColumnLayouts.length; i++) { - layout.addColumnData(dependencyTableColumnLayouts[i]); - } - - dependencyViewer.getTable().setLayout(layout); - dependencyViewer.setInput(dependencies); - createDependencyButtons(parent); - } - - private void createDependencyButtons(Composite parent) { - Composite buttonComposite = new Composite(parent, SWT.NONE); - buttonComposite.setLayout(new GridLayout(1,false)); - buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); - - Button addButton = new Button(buttonComposite, SWT.PUSH); - addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - addButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Add); - addButton.addSelectionListener(new SelectionListener(){ - - public void widgetDefaultSelected(SelectionEvent e) { - - } - - public void widgetSelected(SelectionEvent e) { - Dependency dependency = PomFactory.eINSTANCE.createDependency(); - dependency.setGroupId("?"); //$NON-NLS-1$ - dependency.setArtifactId("?"); //$NON-NLS-1$ - dependencies.add(dependency); - dependencyViewer.refresh(); - } - - }); - - final Button removeButton = new Button(buttonComposite, SWT.PUSH); - removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - removeButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Remove); - removeButton.setEnabled(false); - - removeButton.addSelectionListener(new SelectionListener(){ - - public void widgetSelected(SelectionEvent e) { - ISelection sel = dependencyViewer.getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; - Object object = selection.getFirstElement(); - if (object instanceof Dependency) { - Dependency dependency = (Dependency) object; - boolean ok = MessageDialog.openQuestion(getShell(), Messages.MavenUserLibraryProviderInstallPanel_Remove_dependency, NLS.bind(Messages.MavenUserLibraryProviderInstallPanel_Are_you_sure_you_want_to_remove_the_artifact, dependency.getGroupId(), dependency.getArtifactId())); - if (ok) { - dependencies.remove(object); - dependencyViewer.refresh(); - } - } - } - } - - public void widgetDefaultSelected(SelectionEvent e) { - - } - }); - - final Button restoreDefaults = new Button(buttonComposite, SWT.PUSH); - restoreDefaults.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - restoreDefaults.setText(Messages.MavenUserLibraryProviderInstallPanel_Restore_Defaults); - - restoreDefaults.addSelectionListener(new SelectionListener(){ - - public void widgetSelected(SelectionEvent e) { - resource.unload(); - MavenLibraryProviderInstallOperationConfig config = (MavenLibraryProviderInstallOperationConfig) getOperationConfig(); - ILibraryProvider provider = config.getLibraryProvider(); - Map params = provider.getParams(); - String pomURLString = params.get("template"); //$NON-NLS-1$ - try { - URL platformURL = new URL(pomURLString); - URL url = FileLocator.resolve(platformURL); - resource = MavenCoreActivator.loadResource(url); - Model model = resource.getModel(); - dependencies = model.getDependencies(); - dependencyViewer.setInput(dependencies); - config.setModel(model); - dependencyViewer.refresh(); - if (dependencies.size() > 0) { - dependencyViewer.getTable().select(0); - exclusions = dependencies.get(0).getExclusions(); - } else { - exclusions = null; - } - exclusionViewer.setInput(exclusions); - exclusionViewer.refresh(); - } catch (MalformedURLException e1) { - MavenCoreActivator.log(e1); - } catch (IOException e1) { - MavenCoreActivator.log(e1); - } catch (CoreException e1) { - MavenCoreActivator.log(e1); - } - } - - public void widgetDefaultSelected(SelectionEvent e) { - - } - }); - - dependencyViewer.addSelectionChangedListener(new ISelectionChangedListener() { - - public void selectionChanged(SelectionChangedEvent event) { - ISelection sel = dependencyViewer.getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; - Object object = selection.getFirstElement(); - removeButton.setEnabled(object instanceof Dependency); - } else { - removeButton.setEnabled(false); - } - } - }); - } - - protected Shell getShell() { - // TODO Auto-generated method stub - return null; - } - - private void createExclusionButtons(Composite parent) { - Composite buttonComposite = new Composite(parent, SWT.NONE); - buttonComposite.setLayout(new GridLayout(1,false)); - buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); - - Button addButton = new Button(buttonComposite, SWT.PUSH); - addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - addButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Add); - addButton.addSelectionListener(new SelectionListener(){ - - public void widgetDefaultSelected(SelectionEvent e) { - - } - - public void widgetSelected(SelectionEvent e) { - Exclusion exclusion = PomFactory.eINSTANCE.createExclusion(); - exclusion.setGroupId("?"); //$NON-NLS-1$ - exclusion.setArtifactId("?"); //$NON-NLS-1$ - if (exclusions == null) { - ISelection sel = dependencyViewer.getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; - Object object = selection.getFirstElement(); - if (object instanceof Dependency) { - exclusions = ((Dependency) object).getExclusions(); - exclusionViewer.setInput(exclusions); - } - } - } - if (exclusions != null) { - exclusions.add(exclusion); - } - exclusionViewer.refresh(); - } - - }); - - final Button removeButton = new Button(buttonComposite, SWT.PUSH); - removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - removeButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Remove); - removeButton.setEnabled(false); - - removeButton.addSelectionListener(new SelectionListener(){ - - public void widgetSelected(SelectionEvent e) { - ISelection sel = exclusionViewer.getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; - Object object = selection.getFirstElement(); - if (object instanceof Exclusion) { - Exclusion exclusion = (Exclusion) object; - boolean ok = MessageDialog.openQuestion(getShell(), Messages.MavenUserLibraryProviderInstallPanel_Remove_exclusion, NLS.bind(Messages.MavenUserLibraryProviderInstallPanel_Are_you_sure_you_want_to_remove_the_artifact, exclusion.getGroupId(), exclusion.getArtifactId())); - if (ok && exclusions != null) { - exclusions.remove(object); - } - } - exclusionViewer.refresh(); - } - } - - public void widgetDefaultSelected(SelectionEvent e) { - - } - }); - exclusionViewer.addSelectionChangedListener(new ISelectionChangedListener() { - - public void selectionChanged(SelectionChangedEvent event) { - ISelection sel = exclusionViewer.getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; - Object object = selection.getFirstElement(); - removeButton.setEnabled(object instanceof Exclusion); - } else { - removeButton.setEnabled(false); - } - } - }); - } - - private static class TableContentProvider implements - IStructuredContentProvider { - - public Object[] getElements(Object inputElement) { - if (inputElement instanceof Object[]) { - return (Object[]) inputElement; - } - if (inputElement instanceof Collection) { - return ((Collection) inputElement).toArray(); - } - return new Object[0]; - } - - public void dispose() { - - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - - } - } - - private static class DependencyColumnLabelProvider extends ColumnLabelProvider { - - private int columnIndex; - - public DependencyColumnLabelProvider(int columnIndex) { - this.columnIndex = columnIndex; - } - - public String getText(Object element) { - if (element instanceof Dependency) { - Dependency dependency = (Dependency) element; - switch (columnIndex) { - case 0: - return dependency.getGroupId(); - case 1: - return dependency.getArtifactId(); - case 2: - return dependency.getVersion(); - case 3: - return dependency.getScope(); - case 4: - return dependency.getType(); - } - } - return null; - } - } - - private static class ExclusionColumnLabelProvider extends ColumnLabelProvider { - - private int columnIndex; - - public ExclusionColumnLabelProvider(int columnIndex) { - this.columnIndex = columnIndex; - } - - public String getText(Object element) { - if (element instanceof Exclusion) { - Exclusion exclusion = (Exclusion) element; - switch (columnIndex) { - case 0: - return exclusion.getGroupId(); - case 1: - return exclusion.getArtifactId(); - } - } - return null; - } - } -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui.internal.libprov; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnLayoutData; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; +import org.eclipse.jst.common.project.facet.ui.libprov.LibraryProviderOperationPanel; +import org.eclipse.m2e.model.edit.pom.Dependency; +import org.eclipse.m2e.model.edit.pom.Exclusion; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.util.PomResourceImpl; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.jboss.tools.maven.core.MavenCoreActivator; +import org.jboss.tools.maven.core.libprov.MavenLibraryProviderInstallOperationConfig; +import org.jboss.tools.maven.ui.Messages; + +/** + * + * @author snjeza + * + */ +public class MavenUserLibraryProviderInstallPanel extends + LibraryProviderOperationPanel { + + private TableViewer dependencyViewer; + protected ColumnLayoutData[] dependencyTableColumnLayouts= { + new ColumnWeightData(80,80), + new ColumnWeightData(80,80), + new ColumnWeightData(60,60), + new ColumnWeightData(60,60), + new ColumnWeightData(60,60) + }; + protected ColumnLayoutData[] exclusionTableColumnLayouts= { + new ColumnWeightData(80,80), + new ColumnWeightData(60,60) + }; + private List dependencies; + private TableViewer exclusionViewer; + private List exclusions; + private PomResourceImpl resource; + + @Override + public Control createControl(final Composite parent) { + resource = MavenCoreActivator.getResource(); + if (resource != null) { + resource.unload(); + MavenCoreActivator.setResource(null); + } + MavenLibraryProviderInstallOperationConfig config = (MavenLibraryProviderInstallOperationConfig) getOperationConfig(); + ILibraryProvider provider = config.getLibraryProvider(); + File providerFile = MavenCoreActivator.getProviderFile(provider); + URL url = null; + try { + if (providerFile.exists()) { + url = providerFile.toURL(); + } else { + Map params = provider.getParams(); + String pomURLString = params.get("template"); //$NON-NLS-1$ + URL platformURL = new URL(pomURLString); + url = FileLocator.resolve(platformURL); + } + + resource = MavenCoreActivator.loadResource(url); + MavenCoreActivator.setResource(resource); + Model model = resource.getModel(); + dependencies = model.getDependencies(); + config.setModel(model); + parent.addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + parent.removeDisposeListener(this); + resource.unload(); + MavenCoreActivator.setResource(null); + } + }); + } catch (CoreException e) { + MavenCoreActivator.log(e); + } catch (IOException e) { + MavenCoreActivator.log(e); + } + + if (dependencies == null) { + dependencies = new ArrayList(); + } + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label dependencyLabel = new Label(composite, SWT.NONE); + dependencyLabel.setText(Messages.MavenUserLibraryProviderInstallPanel_Dependencies); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan=2; + dependencyLabel.setLayoutData(gd); + + createDependencyViewer(composite); + dependencyViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + ISelection sel = event.getSelection(); + if (sel instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) sel; + Object object = selection.getFirstElement(); + if (object instanceof Dependency) { + Dependency dependency = (Dependency) object; + exclusions = dependency.getExclusions(); + exclusionViewer.setInput(exclusions); + } + } + } + }); + + Label exclusionLabel = new Label(composite, SWT.NONE); + exclusionLabel.setText(Messages.MavenUserLibraryProviderInstallPanel_Exclusions); + gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan=2; + exclusionLabel.setLayoutData(gd); + + createExclusionViewer(composite); + + if (dependencies.size() > 0) { + dependencyViewer.getTable().select(0); + exclusions = dependencies.get(0).getExclusions(); + exclusionViewer.setInput(exclusions); + } + return composite; + } + + private void createExclusionViewer(Composite parent) { + exclusionViewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL + | SWT.V_SCROLL | SWT.BORDER); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 60; + exclusionViewer.getTable().setLayoutData(gd); + //viewer.setLabelProvider(new TableLabelProvider()); + exclusionViewer.setContentProvider(new TableContentProvider()); + Table table = exclusionViewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + table.setFont(parent.getFont()); + + String[] columnHeaders = {Messages.MavenUserLibraryProviderInstallPanel_GroupId,Messages.MavenUserLibraryProviderInstallPanel_ArtifactId}; + + for (int i = 0; i < columnHeaders.length; i++) { + TableViewerColumn column = new TableViewerColumn(exclusionViewer, SWT.NONE); + column.setLabelProvider(new ExclusionColumnLabelProvider(i)); + column.getColumn().setText(columnHeaders[i]); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(true); + column.setEditingSupport(new ExclusionEditingSupport(exclusionViewer, i)); + + } + + + TableLayout layout = new AutoResizeTableLayout(table); + for (int i = 0; i < exclusionTableColumnLayouts.length; i++) { + layout.addColumnData(exclusionTableColumnLayouts[i]); + } + exclusionViewer.getTable().setLayout(layout); + + createExclusionButtons(parent); + + } + + private void createDependencyViewer(Composite parent) { + dependencyViewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL + | SWT.V_SCROLL | SWT.BORDER); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 80; + dependencyViewer.getTable().setLayoutData(gd); + //viewer.setLabelProvider(new TableLabelProvider()); + dependencyViewer.setContentProvider(new TableContentProvider()); + Table table = dependencyViewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + table.setFont(parent.getFont()); + + String[] columnHeaders = {Messages.MavenUserLibraryProviderInstallPanel_GroupId,Messages.MavenUserLibraryProviderInstallPanel_ArtifactId,Messages.MavenUserLibraryProviderInstallPanel_Version,Messages.MavenUserLibraryProviderInstallPanel_Scope,Messages.MavenUserLibraryProviderInstallPanel_Type}; + + for (int i = 0; i < columnHeaders.length; i++) { + TableViewerColumn column = new TableViewerColumn(dependencyViewer, SWT.NONE); + column.setLabelProvider(new DependencyColumnLabelProvider(i)); + column.getColumn().setText(columnHeaders[i]); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(true); + column.setEditingSupport(new DependencyEditingSupport(dependencyViewer, i)); + + } + + + TableLayout layout = new AutoResizeTableLayout(table); + for (int i = 0; i < dependencyTableColumnLayouts.length; i++) { + layout.addColumnData(dependencyTableColumnLayouts[i]); + } + + dependencyViewer.getTable().setLayout(layout); + dependencyViewer.setInput(dependencies); + createDependencyButtons(parent); + } + + private void createDependencyButtons(Composite parent) { + Composite buttonComposite = new Composite(parent, SWT.NONE); + buttonComposite.setLayout(new GridLayout(1,false)); + buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + + Button addButton = new Button(buttonComposite, SWT.PUSH); + addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + addButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Add); + addButton.addSelectionListener(new SelectionListener(){ + + public void widgetDefaultSelected(SelectionEvent e) { + + } + + public void widgetSelected(SelectionEvent e) { + Dependency dependency = PomFactory.eINSTANCE.createDependency(); + dependency.setGroupId("?"); //$NON-NLS-1$ + dependency.setArtifactId("?"); //$NON-NLS-1$ + dependencies.add(dependency); + dependencyViewer.refresh(); + } + + }); + + final Button removeButton = new Button(buttonComposite, SWT.PUSH); + removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + removeButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Remove); + removeButton.setEnabled(false); + + removeButton.addSelectionListener(new SelectionListener(){ + + public void widgetSelected(SelectionEvent e) { + ISelection sel = dependencyViewer.getSelection(); + if (sel instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) sel; + Object object = selection.getFirstElement(); + if (object instanceof Dependency) { + Dependency dependency = (Dependency) object; + boolean ok = MessageDialog.openQuestion(getShell(), Messages.MavenUserLibraryProviderInstallPanel_Remove_dependency, NLS.bind(Messages.MavenUserLibraryProviderInstallPanel_Are_you_sure_you_want_to_remove_the_artifact, dependency.getGroupId(), dependency.getArtifactId())); + if (ok) { + dependencies.remove(object); + dependencyViewer.refresh(); + } + } + } + } + + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + + final Button restoreDefaults = new Button(buttonComposite, SWT.PUSH); + restoreDefaults.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + restoreDefaults.setText(Messages.MavenUserLibraryProviderInstallPanel_Restore_Defaults); + + restoreDefaults.addSelectionListener(new SelectionListener(){ + + public void widgetSelected(SelectionEvent e) { + resource.unload(); + MavenLibraryProviderInstallOperationConfig config = (MavenLibraryProviderInstallOperationConfig) getOperationConfig(); + ILibraryProvider provider = config.getLibraryProvider(); + Map params = provider.getParams(); + String pomURLString = params.get("template"); //$NON-NLS-1$ + try { + URL platformURL = new URL(pomURLString); + URL url = FileLocator.resolve(platformURL); + resource = MavenCoreActivator.loadResource(url); + Model model = resource.getModel(); + dependencies = model.getDependencies(); + dependencyViewer.setInput(dependencies); + config.setModel(model); + dependencyViewer.refresh(); + if (dependencies.size() > 0) { + dependencyViewer.getTable().select(0); + exclusions = dependencies.get(0).getExclusions(); + } else { + exclusions = null; + } + exclusionViewer.setInput(exclusions); + exclusionViewer.refresh(); + } catch (MalformedURLException e1) { + MavenCoreActivator.log(e1); + } catch (IOException e1) { + MavenCoreActivator.log(e1); + } catch (CoreException e1) { + MavenCoreActivator.log(e1); + } + } + + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + + dependencyViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + ISelection sel = dependencyViewer.getSelection(); + if (sel instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) sel; + Object object = selection.getFirstElement(); + removeButton.setEnabled(object instanceof Dependency); + } else { + removeButton.setEnabled(false); + } + } + }); + } + + protected Shell getShell() { + // TODO Auto-generated method stub + return null; + } + + private void createExclusionButtons(Composite parent) { + Composite buttonComposite = new Composite(parent, SWT.NONE); + buttonComposite.setLayout(new GridLayout(1,false)); + buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + + Button addButton = new Button(buttonComposite, SWT.PUSH); + addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + addButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Add); + addButton.addSelectionListener(new SelectionListener(){ + + public void widgetDefaultSelected(SelectionEvent e) { + + } + + public void widgetSelected(SelectionEvent e) { + Exclusion exclusion = PomFactory.eINSTANCE.createExclusion(); + exclusion.setGroupId("?"); //$NON-NLS-1$ + exclusion.setArtifactId("?"); //$NON-NLS-1$ + if (exclusions == null) { + ISelection sel = dependencyViewer.getSelection(); + if (sel instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) sel; + Object object = selection.getFirstElement(); + if (object instanceof Dependency) { + exclusions = ((Dependency) object).getExclusions(); + exclusionViewer.setInput(exclusions); + } + } + } + if (exclusions != null) { + exclusions.add(exclusion); + } + exclusionViewer.refresh(); + } + + }); + + final Button removeButton = new Button(buttonComposite, SWT.PUSH); + removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + removeButton.setText(Messages.MavenUserLibraryProviderInstallPanel_Remove); + removeButton.setEnabled(false); + + removeButton.addSelectionListener(new SelectionListener(){ + + public void widgetSelected(SelectionEvent e) { + ISelection sel = exclusionViewer.getSelection(); + if (sel instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) sel; + Object object = selection.getFirstElement(); + if (object instanceof Exclusion) { + Exclusion exclusion = (Exclusion) object; + boolean ok = MessageDialog.openQuestion(getShell(), Messages.MavenUserLibraryProviderInstallPanel_Remove_exclusion, NLS.bind(Messages.MavenUserLibraryProviderInstallPanel_Are_you_sure_you_want_to_remove_the_artifact, exclusion.getGroupId(), exclusion.getArtifactId())); + if (ok && exclusions != null) { + exclusions.remove(object); + } + } + exclusionViewer.refresh(); + } + } + + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + exclusionViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + ISelection sel = exclusionViewer.getSelection(); + if (sel instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) sel; + Object object = selection.getFirstElement(); + removeButton.setEnabled(object instanceof Exclusion); + } else { + removeButton.setEnabled(false); + } + } + }); + } + + private static class TableContentProvider implements + IStructuredContentProvider { + + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Object[]) { + return (Object[]) inputElement; + } + if (inputElement instanceof Collection) { + return ((Collection) inputElement).toArray(); + } + return new Object[0]; + } + + public void dispose() { + + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + } + } + + private static class DependencyColumnLabelProvider extends ColumnLabelProvider { + + private int columnIndex; + + public DependencyColumnLabelProvider(int columnIndex) { + this.columnIndex = columnIndex; + } + + public String getText(Object element) { + if (element instanceof Dependency) { + Dependency dependency = (Dependency) element; + switch (columnIndex) { + case 0: + return dependency.getGroupId(); + case 1: + return dependency.getArtifactId(); + case 2: + return dependency.getVersion(); + case 3: + return dependency.getScope(); + case 4: + return dependency.getType(); + } + } + return null; + } + } + + private static class ExclusionColumnLabelProvider extends ColumnLabelProvider { + + private int columnIndex; + + public ExclusionColumnLabelProvider(int columnIndex) { + this.columnIndex = columnIndex; + } + + public String getText(Object element) { + if (element instanceof Exclusion) { + Exclusion exclusion = (Exclusion) element; + switch (columnIndex) { + case 0: + return exclusion.getGroupId(); + case 1: + return exclusion.getArtifactId(); + } + } + return null; + } + } +} Index: src/org/jboss/tools/maven/ui/internal/libprov/DependencyEditingSupport.java =================================================================== --- src/org/jboss/tools/maven/ui/internal/libprov/DependencyEditingSupport.java (revision 32782) +++ src/org/jboss/tools/maven/ui/internal/libprov/DependencyEditingSupport.java (working copy) @@ -1,140 +1,154 @@ -package org.jboss.tools.maven.ui.internal.libprov; - -import org.jboss.tools.maven.ui.Messages; -import org.maven.ide.components.pom.Dependency; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.ComboBoxCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; - -public class DependencyEditingSupport extends EditingSupport { - - private static String[] scopes = {"","provided", "compile", "test", "runtime", "system","import"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - private static String[] types = {"","jar","war","rar","ear","par","ejb","ejb3","ejb-client","test-jar","java-source","javadoc","maven-plugin","pom"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$ - - private CellEditor editor; - private int column; - - public DependencyEditingSupport(ColumnViewer viewer, int column) { - super(viewer); - switch (column) { - case 3: - editor = new ComboBoxCellEditor(((TableViewer) viewer).getTable(), - scopes); - break; - case 4: - editor = new ComboBoxCellEditor(((TableViewer) viewer).getTable(), - types); - break; - default: - editor = new TextCellEditor(((TableViewer) viewer).getTable()); - } - - - this.column = column; - } - - - @Override - protected boolean canEdit(Object element) { - return true; - } - - @Override - protected CellEditor getCellEditor(Object element) { - return editor; - } - - @Override - protected Object getValue(Object element) { - Dependency dependency = (Dependency) element; - String value = null; - switch (this.column) { - case 0: - value = dependency.getGroupId(); - if (value == null) { - value = ""; //$NON-NLS-1$ - } - return value; - case 1: - value = dependency.getArtifactId(); - if (value == null) { - value = ""; //$NON-NLS-1$ - } - return value; - case 2: - value = dependency.getVersion(); - if (value == null) { - value = ""; //$NON-NLS-1$ - } - return value; - case 3: - for (int i = 0; i < scopes.length; i++) { - if (scopes[i].equals(dependency.getScope())) { - return i; - } - } - return 0; - case 4: - for (int i = 0; i < types.length; i++) { - if (types[i].equals(dependency.getType())) { - return i; - } - } - return 0; - default: - break; - } - return null; - - } - - @Override - protected void setValue(Object element, Object value) { - Dependency dependency = (Dependency) element; - - String valueString = null; - int intValue = 0; - if (column < 3) { - if (value == null) { - valueString = null; - } else { - valueString = value.toString(); - } - } else { - intValue = (Integer)value; - } - switch (this.column) { - case 0: - dependency.setGroupId(valueString); - break; - case 1: - dependency.setArtifactId(valueString); - break; - case 2: - dependency.setVersion(valueString); - break; - case 3: - if (intValue > scopes.length) { - intValue = 0; - } - dependency.setScope(scopes[intValue]); - break; - case 4: - if (intValue > types.length) { - intValue = 0; - } - dependency.setType(types[intValue]); - break; - - default: - break; - } - - getViewer().update(element, null); - - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui.internal.libprov; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.m2e.model.edit.pom.Dependency; + +/** + * + * @author snjeza + * + */ +public class DependencyEditingSupport extends EditingSupport { + + private static String[] scopes = {"","provided", "compile", "test", "runtime", "system","import"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + private static String[] types = {"","jar","war","rar","ear","par","ejb","ejb3","ejb-client","test-jar","java-source","javadoc","maven-plugin","pom"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$ + + private CellEditor editor; + private int column; + + public DependencyEditingSupport(ColumnViewer viewer, int column) { + super(viewer); + switch (column) { + case 3: + editor = new ComboBoxCellEditor(((TableViewer) viewer).getTable(), + scopes); + break; + case 4: + editor = new ComboBoxCellEditor(((TableViewer) viewer).getTable(), + types); + break; + default: + editor = new TextCellEditor(((TableViewer) viewer).getTable()); + } + + + this.column = column; + } + + + @Override + protected boolean canEdit(Object element) { + return true; + } + + @Override + protected CellEditor getCellEditor(Object element) { + return editor; + } + + @Override + protected Object getValue(Object element) { + Dependency dependency = (Dependency) element; + String value = null; + switch (this.column) { + case 0: + value = dependency.getGroupId(); + if (value == null) { + value = ""; //$NON-NLS-1$ + } + return value; + case 1: + value = dependency.getArtifactId(); + if (value == null) { + value = ""; //$NON-NLS-1$ + } + return value; + case 2: + value = dependency.getVersion(); + if (value == null) { + value = ""; //$NON-NLS-1$ + } + return value; + case 3: + for (int i = 0; i < scopes.length; i++) { + if (scopes[i].equals(dependency.getScope())) { + return i; + } + } + return 0; + case 4: + for (int i = 0; i < types.length; i++) { + if (types[i].equals(dependency.getType())) { + return i; + } + } + return 0; + default: + break; + } + return null; + + } + + @Override + protected void setValue(Object element, Object value) { + Dependency dependency = (Dependency) element; + + String valueString = null; + int intValue = 0; + if (column < 3) { + if (value == null) { + valueString = null; + } else { + valueString = value.toString(); + } + } else { + intValue = (Integer)value; + } + switch (this.column) { + case 0: + dependency.setGroupId(valueString); + break; + case 1: + dependency.setArtifactId(valueString); + break; + case 2: + dependency.setVersion(valueString); + break; + case 3: + if (intValue > scopes.length) { + intValue = 0; + } + dependency.setScope(scopes[intValue]); + break; + case 4: + if (intValue > types.length) { + intValue = 0; + } + dependency.setType(types[intValue]); + break; + + default: + break; + } + + getViewer().update(element, null); + + } + +} Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.ui - 1.0.0-SNAPSHOT + org.jboss.tools.maven.ui + 1.2.0-SNAPSHOT eclipse-plugin - + \ No newline at end of file Index: src/org/jboss/tools/maven/ui/internal/project/facet/MavenFacetInstallPage.java =================================================================== --- src/org/jboss/tools/maven/ui/internal/project/facet/MavenFacetInstallPage.java (revision 32782) +++ src/org/jboss/tools/maven/ui/internal/project/facet/MavenFacetInstallPage.java (working copy) @@ -1,233 +1,243 @@ -package org.jboss.tools.maven.ui.internal.project.facet; - -import java.util.Map; -import java.util.SortedSet; - -import javax.swing.JButton; - -import org.apache.maven.model.Model; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; -import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelListener; -import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage; -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.eclipse.wst.common.project.facet.ui.IFacetWizardPage; -import org.eclipse.wst.common.project.facet.ui.IWizardContext; -import org.jboss.tools.maven.core.IJBossMavenConstants; -import org.jboss.tools.maven.ui.Activator; -import org.jboss.tools.maven.ui.Messages; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.embedder.MavenModelManager; - -public class MavenFacetInstallPage extends DataModelWizardPage implements -IFacetWizardPage { - - private static final String SEAM_FACET_ID = "jst.seam"; //$NON-NLS-1$ - private Text groupId; - private Text artifactId; - private Text version; - private Combo packaging; - private Text description; - private Text name; - public static final IProjectFacet SEAM_FACET = ProjectFacetsManager.getProjectFacet(SEAM_FACET_ID); - - public MavenFacetInstallPage() { - super(DataModelFactory.createDataModel(new AbstractDataModelProvider() { - }), "jboss.m2.facet.install.page"); //$NON-NLS-1$ - setTitle(Messages.MavenFacetInstallPage_JBoss_M2_capabilities); - setDescription(Messages.MavenFacetInstallPage_Add_M2_capabilities_to_this_Web_Project); - - } - - @Override - protected Composite createTopLevelComposite(Composite parent) { - initializeDialogUnits(parent); - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - GridData gd = new GridData(GridData.FILL_BOTH); - composite.setLayoutData(gd); - - String projectName = getDataModel().getStringProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME); - IProject project = null; - if (projectName != null && projectName.trim().length() > 0) { - project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - } - boolean mavenProjectExists = false; - if (project != null && project.isOpen()) { - try { - boolean hasMavenNature = project.hasNature(IMavenConstants.NATURE_ID); - IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); - if (hasMavenNature && pom.exists()) { - getDataModel().setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); - mavenProjectExists = true; - MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); - Model mavenModel = modelManager.readMavenModel(pom); - String groupId = mavenModel.getGroupId(); - model.setStringProperty(IJBossMavenConstants.GROUP_ID, groupId); - String artifactId = mavenModel.getArtifactId(); - model.setStringProperty(IJBossMavenConstants.ARTIFACT_ID, artifactId); - String version = mavenModel.getVersion(); - model.setStringProperty(IJBossMavenConstants.VERSION, version); - String packaging = mavenModel.getPackaging(); - model.setStringProperty(IJBossMavenConstants.PACKAGING, packaging); - String name = mavenModel.getName(); - model.setStringProperty(IJBossMavenConstants.NAME, name); - String description = mavenModel.getDescription(); - model.setStringProperty(IJBossMavenConstants.DESCRIPTION, description); - } - } catch (CoreException e) { - Activator.log(e); - } - - } - - groupId = createField(composite,Messages.MavenFacetInstallPage_Group_Id,IJBossMavenConstants.GROUP_ID); - artifactId = createField(composite, Messages.MavenFacetInstallPage_Artifact_Id, IJBossMavenConstants.ARTIFACT_ID); - if (!mavenProjectExists) { - artifactId.setText(projectName); - } - - version = createField(composite, Messages.MavenFacetInstallPage_Version, IJBossMavenConstants.VERSION); - - Label packagingLabel = new Label(composite, SWT.NONE); - packagingLabel.setText(Messages.MavenFacetInstallPage_Packaging); - packaging = new Combo(composite, SWT.READ_ONLY); - gd = new GridData(GridData.FILL_HORIZONTAL); - packaging.setLayoutData(gd); - String[] items = { "war","ear", "ejb", "jar" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - packaging.setItems(items); - - IFacetedProjectWorkingCopy fpwc = null; - try { - fpwc = (IFacetedProjectWorkingCopy) getDataModel().getProperty(IFacetDataModelProperties.FACETED_PROJECT_WORKING_COPY); - if (!mavenProjectExists) { - if (fpwc.hasProjectFacet(WebFacetUtils.WEB_FACET)) { - packaging.select(0); - } else if (fpwc - .hasProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION_FACET)) { - packaging.select(1); - } else if (fpwc.hasProjectFacet(IJ2EEFacetConstants.EJB_FACET)) { - packaging.select(2); - } else { - packaging.select(3); - } - } else { - String mavenPackaging = getDataModel().getStringProperty(IJBossMavenConstants.PACKAGING); - packaging.setText(mavenPackaging); - } - synchHelper.synchCombo(packaging, IJBossMavenConstants.PACKAGING, null); - - name = createField(composite, Messages.MavenFacetInstallPage_Name, IJBossMavenConstants.NAME); - name.setText(projectName); - description = createField(composite, Messages.MavenFacetInstallPage_Description, IJBossMavenConstants.DESCRIPTION); - - if (!mavenProjectExists && fpwc.hasProjectFacet(SEAM_FACET)) { - Text seamVersion = createField(composite, Messages.MavenFacetInstallPage_Seam_Maven_version, IJBossMavenConstants.SEAM_MAVEN_VERSION); - IProjectFacetVersion seamFacetVersion = fpwc.getProjectFacetVersion(SEAM_FACET); - if ("2.0".equals(seamFacetVersion.getVersionString())) { //$NON-NLS-1$ - seamVersion.setText("2.0.2.SP1"); //$NON-NLS-1$ - } else if ("2.1".equals(seamFacetVersion.getVersionString())) { //$NON-NLS-1$ - seamVersion.setText("2.1.1.GA"); //$NON-NLS-1$ - } else if ("2.2".equals(seamFacetVersion.getVersionString())) { //$NON-NLS-1$ - seamVersion.setText("2.2.0.GA"); //$NON-NLS-1$ - } - Button removeWTPContainers = new Button(composite,SWT.CHECK); - removeWTPContainers.setText(Messages.MavenFacetInstallPage_Remove_WTP_Classpath_containers); - synchHelper.synchCheckbox(removeWTPContainers, IJBossMavenConstants.REMOVE_WTP_CLASSPATH_CONTAINERS, null); - // FIXME add the Validate button - } - } catch (Exception e) { - Activator.log(e); - } finally { - if (fpwc != null) { - fpwc.dispose(); - } - } - - if (mavenProjectExists) { - artifactId.setEditable(false); - groupId.setEditable(false); - version.setEditable(false); - name.setEditable(false); - description.setEditable(false); - packaging.setEnabled(false); - } - getDataModel().addListener(new IDataModelListener() { - - public void propertyChanged(DataModelEvent event) { - String propertyName = event.getPropertyName(); - if (IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME.equals(propertyName)) { - String projectName = getDataModel().getStringProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME); - if (projectName != null) { - artifactId.setText(projectName); - } - } - } - }); - - return composite; - } - - private Text createField(Composite composite, String labelText,String property) { - Label label = new Label(composite, SWT.NONE); - label.setText(labelText); - Text text = new Text(composite, SWT.SINGLE | SWT.BORDER); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - text.setLayoutData(gd); - synchHelper.synchText(text, property, null); - return text; - } - - @Override - protected String[] getValidationPropertyNames() { - return new String[] { IJBossMavenConstants.GROUP_ID, - IJBossMavenConstants.ARTIFACT_ID, - IJBossMavenConstants.VERSION, - IJBossMavenConstants.PACKAGING }; - } - - public void setConfig(Object config) { - model.removeListener(this); - synchHelper.dispose(); - - model = (IDataModel) config; - model.addListener(this); - synchHelper = initializeSynchHelper(model); - } - - @Override - public void dispose() { - model.removeListener(this); - super.dispose(); - } - - public void setWizardContext(IWizardContext context) { - - } - public void transferStateToConfig() { - - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui.internal.project.facet; + +import org.apache.maven.model.Model; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; +import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.MavenModelManager; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; +import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties; +import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; +import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent; +import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.frameworks.datamodel.IDataModelListener; +import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage; +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.eclipse.wst.common.project.facet.ui.IFacetWizardPage; +import org.eclipse.wst.common.project.facet.ui.IWizardContext; +import org.jboss.tools.maven.core.IJBossMavenConstants; +import org.jboss.tools.maven.ui.Activator; +import org.jboss.tools.maven.ui.Messages; + +/** + * + * @author snjeza + * + */ +public class MavenFacetInstallPage extends DataModelWizardPage implements +IFacetWizardPage { + + private static final String SEAM_FACET_ID = "jst.seam"; //$NON-NLS-1$ + private Text groupId; + private Text artifactId; + private Text version; + private Combo packaging; + private Text description; + private Text name; + public static final IProjectFacet SEAM_FACET = ProjectFacetsManager.getProjectFacet(SEAM_FACET_ID); + + public MavenFacetInstallPage() { + super(DataModelFactory.createDataModel(new AbstractDataModelProvider() { + }), "jboss.m2.facet.install.page"); //$NON-NLS-1$ + setTitle(Messages.MavenFacetInstallPage_JBoss_M2_capabilities); + setDescription(Messages.MavenFacetInstallPage_Add_M2_capabilities_to_this_Web_Project); + + } + + @Override + protected Composite createTopLevelComposite(Composite parent) { + initializeDialogUnits(parent); + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + GridData gd = new GridData(GridData.FILL_BOTH); + composite.setLayoutData(gd); + + String projectName = getDataModel().getStringProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME); + IProject project = null; + if (projectName != null && projectName.trim().length() > 0) { + project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + } + boolean mavenProjectExists = false; + if (project != null && project.isOpen()) { + try { + boolean hasMavenNature = project.hasNature(IMavenConstants.NATURE_ID); + IFile pom = project.getFile(IMavenConstants.POM_FILE_NAME); + if (hasMavenNature && pom.exists()) { + getDataModel().setBooleanProperty(IJBossMavenConstants.MAVEN_PROJECT_EXISTS, true); + mavenProjectExists = true; + MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); + Model mavenModel = modelManager.readMavenModel(pom); + String groupId = mavenModel.getGroupId(); + model.setStringProperty(IJBossMavenConstants.GROUP_ID, groupId); + String artifactId = mavenModel.getArtifactId(); + model.setStringProperty(IJBossMavenConstants.ARTIFACT_ID, artifactId); + String version = mavenModel.getVersion(); + model.setStringProperty(IJBossMavenConstants.VERSION, version); + String packaging = mavenModel.getPackaging(); + model.setStringProperty(IJBossMavenConstants.PACKAGING, packaging); + String name = mavenModel.getName(); + model.setStringProperty(IJBossMavenConstants.NAME, name); + String description = mavenModel.getDescription(); + model.setStringProperty(IJBossMavenConstants.DESCRIPTION, description); + } + } catch (CoreException e) { + Activator.log(e); + } + + } + + groupId = createField(composite,Messages.MavenFacetInstallPage_Group_Id,IJBossMavenConstants.GROUP_ID); + artifactId = createField(composite, Messages.MavenFacetInstallPage_Artifact_Id, IJBossMavenConstants.ARTIFACT_ID); + if (!mavenProjectExists) { + artifactId.setText(projectName); + } + + version = createField(composite, Messages.MavenFacetInstallPage_Version, IJBossMavenConstants.VERSION); + + Label packagingLabel = new Label(composite, SWT.NONE); + packagingLabel.setText(Messages.MavenFacetInstallPage_Packaging); + packaging = new Combo(composite, SWT.READ_ONLY); + gd = new GridData(GridData.FILL_HORIZONTAL); + packaging.setLayoutData(gd); + String[] items = { "war","ear", "ejb", "jar" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + packaging.setItems(items); + + IFacetedProjectWorkingCopy fpwc = null; + try { + fpwc = (IFacetedProjectWorkingCopy) getDataModel().getProperty(IFacetDataModelProperties.FACETED_PROJECT_WORKING_COPY); + if (!mavenProjectExists) { + if (fpwc.hasProjectFacet(WebFacetUtils.WEB_FACET)) { + packaging.select(0); + } else if (fpwc + .hasProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION_FACET)) { + packaging.select(1); + } else if (fpwc.hasProjectFacet(IJ2EEFacetConstants.EJB_FACET)) { + packaging.select(2); + } else { + packaging.select(3); + } + } else { + String mavenPackaging = getDataModel().getStringProperty(IJBossMavenConstants.PACKAGING); + packaging.setText(mavenPackaging); + } + synchHelper.synchCombo(packaging, IJBossMavenConstants.PACKAGING, null); + + name = createField(composite, Messages.MavenFacetInstallPage_Name, IJBossMavenConstants.NAME); + name.setText(projectName); + description = createField(composite, Messages.MavenFacetInstallPage_Description, IJBossMavenConstants.DESCRIPTION); + + if (!mavenProjectExists && fpwc.hasProjectFacet(SEAM_FACET)) { + Text seamVersion = createField(composite, Messages.MavenFacetInstallPage_Seam_Maven_version, IJBossMavenConstants.SEAM_MAVEN_VERSION); + IProjectFacetVersion seamFacetVersion = fpwc.getProjectFacetVersion(SEAM_FACET); + if ("2.0".equals(seamFacetVersion.getVersionString())) { //$NON-NLS-1$ + seamVersion.setText("2.0.2.SP1"); //$NON-NLS-1$ + } else if ("2.1".equals(seamFacetVersion.getVersionString())) { //$NON-NLS-1$ + seamVersion.setText("2.1.1.GA"); //$NON-NLS-1$ + } else if ("2.2".equals(seamFacetVersion.getVersionString())) { //$NON-NLS-1$ + seamVersion.setText("2.2.1.Final"); //$NON-NLS-1$ + } + Button removeWTPContainers = new Button(composite,SWT.CHECK); + removeWTPContainers.setText(Messages.MavenFacetInstallPage_Remove_WTP_Classpath_containers); + synchHelper.synchCheckbox(removeWTPContainers, IJBossMavenConstants.REMOVE_WTP_CLASSPATH_CONTAINERS, null); + // FIXME add the Validate button + } + } catch (Exception e) { + Activator.log(e); + } finally { + if (fpwc != null) { + fpwc.dispose(); + } + } + + if (mavenProjectExists) { + artifactId.setEditable(false); + groupId.setEditable(false); + version.setEditable(false); + name.setEditable(false); + description.setEditable(false); + packaging.setEnabled(false); + } + getDataModel().addListener(new IDataModelListener() { + + public void propertyChanged(DataModelEvent event) { + String propertyName = event.getPropertyName(); + if (IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME.equals(propertyName)) { + String projectName = getDataModel().getStringProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME); + if (projectName != null) { + artifactId.setText(projectName); + } + } + } + }); + + return composite; + } + + private Text createField(Composite composite, String labelText,String property) { + Label label = new Label(composite, SWT.NONE); + label.setText(labelText); + Text text = new Text(composite, SWT.SINGLE | SWT.BORDER); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + text.setLayoutData(gd); + synchHelper.synchText(text, property, null); + return text; + } + + @Override + protected String[] getValidationPropertyNames() { + return new String[] { IJBossMavenConstants.GROUP_ID, + IJBossMavenConstants.ARTIFACT_ID, + IJBossMavenConstants.VERSION, + IJBossMavenConstants.PACKAGING }; + } + + public void setConfig(Object config) { + model.removeListener(this); + synchHelper.dispose(); + + model = (IDataModel) config; + model.addListener(this); + synchHelper = initializeSynchHelper(model); + } + + @Override + public void dispose() { + model.removeListener(this); + super.dispose(); + } + + public void setWizardContext(IWizardContext context) { + + } + public void transferStateToConfig() { + + } + +} Index: src/org/jboss/tools/maven/ui/preferences/ConfiguratorPreferencesInitializer.java =================================================================== --- src/org/jboss/tools/maven/ui/preferences/ConfiguratorPreferencesInitializer.java (revision 32782) +++ src/org/jboss/tools/maven/ui/preferences/ConfiguratorPreferencesInitializer.java (working copy) @@ -1,48 +1,62 @@ -package org.jboss.tools.maven.ui.preferences; - - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.core.runtime.preferences.DefaultScope; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.jboss.tools.maven.ui.Activator; - -public class ConfiguratorPreferencesInitializer extends - AbstractPreferenceInitializer { - - @Override - public void initializeDefaultPreferences() { - IEclipsePreferences node = new DefaultScope().getNode(Activator.PLUGIN_ID); - - node.putBoolean( - Activator.CONFIGURE_SEAM, - Activator.CONFIGURE_SEAM_VALUE); - node.putBoolean( - Activator.CONFIGURE_SEAM_RUNTIME, - Activator.CONFIGURE_SEAM_RUNTIME_VALUE); - node.putBoolean( - Activator.CONFIGURE_SEAM_ARTIFACTS, - Activator.CONFIGURE_SEAM_ARTIFACTS_VALUE); - node.putBoolean( - Activator.CONFIGURE_JSF, - Activator.CONFIGURE_JSF_VALUE); - node.putBoolean( - Activator.CONFIGURE_WEBXML_JSF20, - Activator.CONFIGURE_WEBXML_JSF20_VALUE); - node.putBoolean( - Activator.CONFIGURE_PORTLET, - Activator.CONFIGURE_PORTLET_VALUE); - node.putBoolean( - Activator.CONFIGURE_JSFPORTLET, - Activator.CONFIGURE_JSFPORTLET_VALUE); - node.putBoolean( - Activator.CONFIGURE_SEAMPORTLET, - Activator.CONFIGURE_SEAMPORTLET_VALUE); - node.putBoolean( - Activator.CONFIGURE_CDI, - Activator.CONFIGURE_CDI_VALUE); - node.putBoolean( - Activator.CONFIGURE_HIBERNATE, - Activator.CONFIGURE_HIBERNATE_VALUE); - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.jboss.tools.maven.ui.Activator; + +/** + * + * @author snjeza + * + */ +public class ConfiguratorPreferencesInitializer extends + AbstractPreferenceInitializer { + + @Override + public void initializeDefaultPreferences() { + IEclipsePreferences node = new DefaultScope().getNode(Activator.PLUGIN_ID); + + node.putBoolean( + Activator.CONFIGURE_SEAM, + Activator.CONFIGURE_SEAM_VALUE); + node.putBoolean( + Activator.CONFIGURE_SEAM_RUNTIME, + Activator.CONFIGURE_SEAM_RUNTIME_VALUE); + node.putBoolean( + Activator.CONFIGURE_SEAM_ARTIFACTS, + Activator.CONFIGURE_SEAM_ARTIFACTS_VALUE); + node.putBoolean( + Activator.CONFIGURE_JSF, + Activator.CONFIGURE_JSF_VALUE); + node.putBoolean( + Activator.CONFIGURE_WEBXML_JSF20, + Activator.CONFIGURE_WEBXML_JSF20_VALUE); + node.putBoolean( + Activator.CONFIGURE_PORTLET, + Activator.CONFIGURE_PORTLET_VALUE); + node.putBoolean( + Activator.CONFIGURE_JSFPORTLET, + Activator.CONFIGURE_JSFPORTLET_VALUE); + node.putBoolean( + Activator.CONFIGURE_SEAMPORTLET, + Activator.CONFIGURE_SEAMPORTLET_VALUE); + node.putBoolean( + Activator.CONFIGURE_CDI, + Activator.CONFIGURE_CDI_VALUE); + node.putBoolean( + Activator.CONFIGURE_HIBERNATE, + Activator.CONFIGURE_HIBERNATE_VALUE); + } + +} Index: src/org/jboss/tools/maven/ui/internal/libprov/ExclusionEditingSupport.java =================================================================== --- src/org/jboss/tools/maven/ui/internal/libprov/ExclusionEditingSupport.java (revision 32782) +++ src/org/jboss/tools/maven/ui/internal/libprov/ExclusionEditingSupport.java (working copy) @@ -1,77 +1,91 @@ -package org.jboss.tools.maven.ui.internal.libprov; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; -import org.jboss.tools.maven.ui.Messages; -import org.maven.ide.components.pom.Exclusion; - -public class ExclusionEditingSupport extends EditingSupport { - - private CellEditor editor; - private int column; - - public ExclusionEditingSupport(ColumnViewer viewer, int column) { - super(viewer); - editor = new TextCellEditor(((TableViewer) viewer).getTable()); - this.column = column; - } - - @Override - protected boolean canEdit(Object element) { - return true; - } - - @Override - protected CellEditor getCellEditor(Object element) { - return editor; - } - - @Override - protected Object getValue(Object element) { - Exclusion exclusion = (Exclusion) element; - String value = null; - switch (this.column) { - case 0: - value = exclusion.getGroupId(); - if (value == null) { - value = ""; //$NON-NLS-1$ - } - return value; - case 1: - value = exclusion.getArtifactId(); - if (value == null) { - value = ""; //$NON-NLS-1$ - } - return value; - } - return null; - } - - @Override - protected void setValue(Object element, Object value) { - Exclusion exclusion = (Exclusion) element; - - String valueString = null; - if (value == null) { - valueString = null; - } else { - valueString = value.toString(); - } - switch (this.column) { - case 0: - exclusion.setGroupId(valueString); - break; - case 1: - exclusion.setArtifactId(valueString); - break; - default: - break; - } - getViewer().update(element, null); - - } - -} +/************************************************************************************* + * Copyright (c) 2009-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ +package org.jboss.tools.maven.ui.internal.libprov; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.m2e.model.edit.pom.Exclusion; + +/** + * + * @author snjeza + * + */ +public class ExclusionEditingSupport extends EditingSupport { + + private CellEditor editor; + private int column; + + public ExclusionEditingSupport(ColumnViewer viewer, int column) { + super(viewer); + editor = new TextCellEditor(((TableViewer) viewer).getTable()); + this.column = column; + } + + @Override + protected boolean canEdit(Object element) { + return true; + } + + @Override + protected CellEditor getCellEditor(Object element) { + return editor; + } + + @Override + protected Object getValue(Object element) { + Exclusion exclusion = (Exclusion) element; + String value = null; + switch (this.column) { + case 0: + value = exclusion.getGroupId(); + if (value == null) { + value = ""; //$NON-NLS-1$ + } + return value; + case 1: + value = exclusion.getArtifactId(); + if (value == null) { + value = ""; //$NON-NLS-1$ + } + return value; + } + return null; + } + + @Override + protected void setValue(Object element, Object value) { + Exclusion exclusion = (Exclusion) element; + + String valueString = null; + if (value == null) { + valueString = null; + } else { + valueString = value.toString(); + } + switch (this.column) { + case 0: + exclusion.setGroupId(valueString); + break; + case 1: + exclusion.setArtifactId(valueString); + break; + default: + break; + } + getViewer().update(element, null); + + } + +} #P org.jboss.tools.maven.jsf.feature Index: feature.properties =================================================================== --- feature.properties (revision 32782) +++ feature.properties (working copy) @@ -1,53 +1,53 @@ -############################################################################### -# Copyright (c) 2011 Red Hat, Inc. 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: -# JBoss by Red Hat - Initial implementation. -############################################################################## -# feature.properties -# contains externalized strings for feature.xml -# "%foo" in feature.xml corresponds to the key "foo" in this file -# java.io.Properties file (ISO 8859-1 with "\" escapes) -# This file should be translated. - -# "featureName" property - name of the feature -featureName=JBoss Maven JSF Configurator - -# "providerName" property - name of the company that provides the feature -providerName=JBoss by Red Hat - -# "updateSiteName" property - label for the update site -updateSiteName=JBossTools Update Site - -# "description" property - description of the feature -description=JBoss Maven Seam Integration - -# "copyright" property - text of the "Feature Update Copyright" -copyright=Copyright (c) 2011 Red Hat, Inc. and others.\n\ -All rights reserved. This program and the accompanying materials\n\ -are made available under the terms of the Eclipse Public License v1.0\n\ -which accompanies this distribution, and is available at\n\ -http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ -JBoss by Red Hat - Initial implementation. - ############### end of copyright property #################################### - -# "licenseURL" property - URL of the "Feature License" -# do not translate value - just change to point to a locale-specific HTML page -licenseURL=license.html - -# START NON-TRANSLATABLE -# "license" property - text of the "Feature Update License" -# should be plain text version of license agreement pointed to be "licenseURL" -license=Red Hat, Inc. licenses these features and plugins to you under \ -certain open source licenses (or aggregations of such licenses), which \ -in a particular case may include the Eclipse Public License, the GNU \ -Lesser General Public License, and/or certain other open source \ -licenses. For precise licensing details, consult the corresponding \ -source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ -Raleigh NC 27606 USA. -# END NON-TRANSLATABLE -########### end of license property ########################################## +############################################################################### +# Copyright (c) 2010-2011 Red Hat, Inc. 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: +# JBoss by Red Hat - Initial implementation. +############################################################################## +# feature.properties +# contains externalized strings for feature.xml +# "%foo" in feature.xml corresponds to the key "foo" in this file +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# This file should be translated. + +# "featureName" property - name of the feature +featureName=JBoss Maven JSF Configurator + +# "providerName" property - name of the company that provides the feature +providerName=JBoss by Red Hat + +# "updateSiteName" property - label for the update site +updateSiteName=JBossTools Update Site + +# "description" property - description of the feature +description=JBoss Maven Seam Integration + +# "copyright" property - text of the "Feature Update Copyright" +copyright=Copyright (c) 2010-2011 Red Hat, Inc. and others.\n\ +All rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\n\ +which accompanies this distribution, and is available at\n\ +http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ +JBoss by Red Hat - Initial implementation. + ############### end of copyright property #################################### + +# "licenseURL" property - URL of the "Feature License" +# do not translate value - just change to point to a locale-specific HTML page +licenseURL=license.html + +# START NON-TRANSLATABLE +# "license" property - text of the "Feature Update License" +# should be plain text version of license agreement pointed to be "licenseURL" +license=Red Hat, Inc. licenses these features and plugins to you under \ +certain open source licenses (or aggregations of such licenses), which \ +in a particular case may include the Eclipse Public License, the GNU \ +Lesser General Public License, and/or certain other open source \ +licenses. For precise licensing details, consult the corresponding \ +source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ +Raleigh NC 27606 USA. +# END NON-TRANSLATABLE +########### end of license property ########################################## Index: feature.xml =================================================================== --- feature.xml (revision 32782) +++ feature.xml (working copy) @@ -2,7 +2,7 @@ @@ -19,8 +19,8 @@ - - + + - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + features + 0.0.1-SNAPSHOT org.jboss.tools.maven.features - org.jboss.tools.maven.jsf.feature - 1.0.0-SNAPSHOT + org.jboss.tools.maven.jsf.feature + 1.2.0-SNAPSHOT eclipse-feature - + \ No newline at end of file #P org.jboss.tools.maven.project.examples Index: pom.xml =================================================================== --- pom.xml (revision 32782) +++ pom.xml (working copy) @@ -1,13 +1,14 @@ - - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + plugins + 0.0.1-SNAPSHOT org.jboss.tools.maven.plugins - org.jboss.tools.maven.project.examples + org.jboss.tools.maven.project.examples 1.0.0-SNAPSHOT eclipse-plugin - + \ No newline at end of file Index: src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java =================================================================== --- src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java (revision 32782) +++ src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java (working copy) @@ -1,414 +1,401 @@ -/************************************************************************************* - * Copyright (c) 2008-2011 Red Hat, Inc. 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: - * JBoss by Red Hat - Initial implementation. - ************************************************************************************/ - -package org.jboss.tools.maven.project.examples; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.apache.maven.model.Model; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.WorkspaceJob; -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.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.progress.IProgressConstants; -import org.jboss.tools.project.examples.model.AbstractImportProjectExample; -import org.jboss.tools.project.examples.model.Project; -import org.maven.ide.eclipse.MavenPlugin; -import org.maven.ide.eclipse.actions.OpenMavenConsoleAction; -import org.maven.ide.eclipse.core.IMavenConstants; -import org.maven.ide.eclipse.core.MavenConsole; -import org.maven.ide.eclipse.embedder.IMaven; -import org.maven.ide.eclipse.embedder.MavenModelManager; -import org.maven.ide.eclipse.project.AbstractProjectScanner; -import org.maven.ide.eclipse.project.IMavenProjectImportResult; -import org.maven.ide.eclipse.project.LocalProjectScanner; -import org.maven.ide.eclipse.project.MavenProjectInfo; -import org.maven.ide.eclipse.project.ProjectImportConfiguration; -import org.maven.ide.eclipse.project.ResolverConfiguration; - -/** - * @author snjeza - * - */ -public class ImportMavenProjectExample extends AbstractImportProjectExample { - - private static final String UNNAMED_PROJECTS = "UnnamedProjects"; //$NON-NLS-1$ - - private static final String JBOSS_TOOLS_MAVEN_PROJECTS = "/.JBossToolsMavenProjects"; //$NON-NLS-1$ - - private boolean confirm; - - @Override - public List importProject(Project projectDescription, File file, - IProgressMonitor monitor) throws Exception { - List projects = new ArrayList(); - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IPath rootPath = workspaceRoot.getLocation(); - IPath mavenProjectsRoot = rootPath.append(JBOSS_TOOLS_MAVEN_PROJECTS); - String projectName = projectDescription.getName(); - if (projectName == null || projectName.isEmpty()) { - projectName = UNNAMED_PROJECTS; - } - IPath path = mavenProjectsRoot.append(projectName); - final File destination = new File(path.toOSString()); - if (destination.exists()) { - final List existingProjects = getExistingProjects(destination); - if (existingProjects.size() > 0) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - String title = "Overwrite"; - String msg = getMessage(destination, existingProjects); - confirm = MessageDialog.openQuestion(getActiveShell(), - title, msg); - } - }); - if (confirm) { - monitor.setTaskName("Deleting ..."); - for (IProject project:existingProjects) { - monitor.setTaskName("Deleting " + project.getName()); - project.delete(false, true, monitor); - } - } else { - return projects; - } - } - boolean deleted = deleteDirectory(destination, monitor); - if (monitor.isCanceled()) { - return projects; - } - if (!deleted) { - Display.getDefault().syncExec(new Runnable() { - - @Override - public void run() { - MessageDialog.openError(getActiveShell(), - "Error", "Cannot delete the '" + destination + "' file."); - } - }); - return projects; - } - } - boolean ok = extractFile(file, destination, monitor); - monitor.setTaskName(""); - if (monitor.isCanceled()) { - return projects; - } - if (!ok) { - Display.getDefault().syncExec(new Runnable() { - - @Override - public void run() { - MessageDialog.openError(getActiveShell(), - "Error", - "Cannot extract the archive."); - } - }); - return projects; - } - - importMavenProjects(destination); - return projects; - } - - private void importMavenProjects(final File destination) { - Job job = new WorkspaceJob("Importing Maven projects") { - public IStatus runInWorkspace(IProgressMonitor monitor) { - setProperty(IProgressConstants.ACTION_PROPERTY, - new OpenMavenConsoleAction()); - MavenPlugin plugin = MavenPlugin.getDefault(); - try { - AbstractProjectScanner projectScanner = getProjectScanner(destination); - projectScanner.run(monitor); - List mavenProjects = projectScanner - .getProjects(); - List infos = new ArrayList(); - infos.addAll(mavenProjects); - addMavenProjects(infos, mavenProjects); - final List existingProjects = new ArrayList(); - ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration(); - for(MavenProjectInfo info:infos) { - String projectName = getProjectName(info, importConfiguration); - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - if (project != null && project.exists()) { - existingProjects.add(project); - } - } - if (existingProjects.size() > 0) { - Display.getDefault().syncExec(new Runnable() { - - @Override - public void run() { - String message = getWorkspaceMessage(existingProjects); - - confirm = MessageDialog.openConfirm(getActiveShell(), - "Confirmation", message); - } - }); - if (confirm) { - for (IProject project:existingProjects) { - try { - project.refreshLocal(IResource.DEPTH_INFINITE, monitor); - } catch (Exception e) { - // ignore - } - project.delete(true, true, monitor); - } - } else { - return Status.CANCEL_STATUS; - } - } - plugin.getProjectConfigurationManager().importProjects( - infos, importConfiguration, monitor); - } catch (CoreException ex) { - plugin.getConsole().logError("Projects imported with errors"); - return ex.getStatus(); - } catch (InterruptedException e) { - return Status.CANCEL_STATUS; - } - return Status.OK_STATUS; - } - }; - job.setRule(MavenPlugin.getDefault().getProjectConfigurationManager() - .getRule()); - job.schedule(); - } - - private List addMavenProjects(List infos, List mavenProjects) { - if (mavenProjects == null || mavenProjects.isEmpty()) { - return mavenProjects; - } - for (MavenProjectInfo projectInfo:mavenProjects) { - Collection projects = projectInfo.getProjects(); - if (projects != null && !projects.isEmpty()) { - for(MavenProjectInfo info:projects) { - infos.add(info); - } - List childProjects = new ArrayList(); - childProjects.addAll(projects); - addMavenProjects(infos, childProjects); - } - } - return mavenProjects; - } - - private AbstractProjectScanner getProjectScanner( - File folder) { - File root = ResourcesPlugin.getWorkspace().getRoot().getLocation() - .toFile(); - MavenPlugin mavenPlugin = MavenPlugin.getDefault(); - MavenModelManager modelManager = mavenPlugin.getMavenModelManager(); - MavenConsole console = mavenPlugin.getConsole(); - return new LocalProjectScanner(root, folder.getAbsolutePath(), false, - modelManager, console); - } - - private static Shell getActiveShell() { - return Display.getDefault().getActiveShell(); - } - - public boolean extractFile(File file, File destination, - IProgressMonitor monitor) { - ZipFile zipFile = null; - destination.mkdirs(); - try { - zipFile = new ZipFile(file); - Enumeration entries = zipFile.entries(); - while (entries.hasMoreElements()) { - if (monitor.isCanceled()) { - return false; - } - ZipEntry entry = (ZipEntry) entries.nextElement(); - if (entry.isDirectory()) { - monitor.setTaskName("Extracting " + entry.getName()); - File dir = new File(destination, entry.getName()); - dir.mkdirs(); - continue; - } - monitor.setTaskName("Extracting " + entry.getName()); - File entryFile = new File(destination, entry.getName()); - entryFile.getParentFile().mkdirs(); - InputStream in = null; - OutputStream out = null; - try { - in = zipFile.getInputStream(entry); - out = new FileOutputStream(entryFile); - copy(in, out); - } finally { - if (in != null) { - try { - in.close(); - } catch (Exception e) { - // ignore - } - } - if (out != null) { - try { - out.close(); - } catch (Exception e) { - // ignore - } - } - } - } - } catch (IOException e) { - MavenProjectExamplesActivator.log(e); - return false; - } finally { - if (zipFile != null) { - try { - zipFile.close(); - } catch (IOException e) { - // ignore - } - } - } - return true; - } - - public static void copy(InputStream in, OutputStream out) throws IOException { - byte[] buffer = new byte[16 * 1024]; - int len; - while ((len = in.read(buffer)) >= 0) { - out.write(buffer, 0, len); - } - } - - private static boolean deleteDirectory(File path, IProgressMonitor monitor) { - if (path.exists()) { - File[] files = path.listFiles(); - for (File file : files) { - if (monitor.isCanceled()) { - return false; - } - monitor.setTaskName("Deleting " + file); - if (file.isDirectory()) { - deleteDirectory(file, monitor); - } else { - file.delete(); - } - } - } - return (path.delete()); - } - - private String getProjectName(MavenProjectInfo projectInfo, - ProjectImportConfiguration configuration) throws CoreException { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IWorkspaceRoot root = workspace.getRoot(); - - File pomFile = projectInfo.getPomFile(); - Model model = projectInfo.getModel(); - IMaven maven = MavenPlugin.getDefault().getMaven(); - if (model == null) { - model = maven.readModel(pomFile); - projectInfo.setModel(model); - } - - String projectName = configuration.getProjectName(model); - - File projectDir = pomFile.getParentFile(); - String projectParent = projectDir.getParentFile().getAbsolutePath(); - - if (projectInfo.getBasedirRename() == MavenProjectInfo.RENAME_REQUIRED) { - File newProject = new File(projectDir.getParent(), projectName); - if (!projectDir.equals(newProject)) { - projectDir = newProject; - } - } else { - if (projectParent.equals(root.getLocation().toFile() - .getAbsolutePath())) { - projectName = projectDir.getName(); - } - } - return projectName; - } - - private List getExistingProjects(final File destination) { - List existingProjects = new ArrayList(); - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (IProject project:projects) { - if (project != null && project.exists()) { - File projectFile = project.getLocation().toFile(); - if (projectFile.getAbsolutePath().startsWith(destination.getAbsolutePath())) { - existingProjects.add(project); - } - } - } - return existingProjects; - } - - private String getMessage(final File destination, List projects) { - if (projects.size() > 0) { - StringBuilder builder = new StringBuilder(); - if (projects.size() == 1) { - builder.append("\nThere is the '" + projects.get(0).getName() + - "' project on the destination location:\n\n"); - builder.append("Would you like to overwrite it?"); - } else { - builder.append("\nThere are the following projects on the destination location:\n\n"); - for (IProject project : projects) { - builder.append(project.getName()); - builder.append("\n"); //$NON-NLS-1$ - } - builder.append("\n"); //$NON-NLS-1$ - builder.append("Would you like to overwrite them?"); - } - return builder.toString(); - } - return null; - } - - private String getWorkspaceMessage( - final List existingProjects) { - StringBuilder builder = new StringBuilder(); - if (existingProjects.size() == 1) { - builder.append("There is the '" + existingProjects.get(0).getName() + - "' project in the workspace.\n\n"); - builder.append("Would you like to delete it?"); - } else { - builder.append("There are the following projects in the workspace:\n\n"); - for (IProject project:existingProjects) { - builder.append(project.getName()); - builder.append("\n"); //$NON-NLS-1$ - } - builder.append("\n"); //$NON-NLS-1$ - builder.append("Would you like to delete them?"); - } - return builder.toString(); - } - -} +/************************************************************************************* + * Copyright (c) 2008-2011 Red Hat, Inc. 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: + * JBoss by Red Hat - Initial implementation. + ************************************************************************************/ + +package org.jboss.tools.maven.project.examples; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.maven.model.Model; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.resources.WorkspaceJob; +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.jface.dialogs.MessageDialog; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.embedder.MavenModelManager; +import org.eclipse.m2e.core.project.AbstractProjectScanner; +import org.eclipse.m2e.core.project.LocalProjectScanner; +import org.eclipse.m2e.core.project.MavenProjectInfo; +import org.eclipse.m2e.core.project.ProjectImportConfiguration; +import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.progress.IProgressConstants; +import org.jboss.tools.project.examples.model.AbstractImportProjectExample; +import org.jboss.tools.project.examples.model.Project; + +/** + * @author snjeza + * + */ +public class ImportMavenProjectExample extends AbstractImportProjectExample { + + private static final String UNNAMED_PROJECTS = "UnnamedProjects"; //$NON-NLS-1$ + + private static final String JBOSS_TOOLS_MAVEN_PROJECTS = "/.JBossToolsMavenProjects"; //$NON-NLS-1$ + + private boolean confirm; + + @Override + public List importProject(Project projectDescription, File file, + IProgressMonitor monitor) throws Exception { + List projects = new ArrayList(); + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IPath rootPath = workspaceRoot.getLocation(); + IPath mavenProjectsRoot = rootPath.append(JBOSS_TOOLS_MAVEN_PROJECTS); + String projectName = projectDescription.getName(); + if (projectName == null || projectName.isEmpty()) { + projectName = UNNAMED_PROJECTS; + } + IPath path = mavenProjectsRoot.append(projectName); + final File destination = new File(path.toOSString()); + if (destination.exists()) { + final List existingProjects = getExistingProjects(destination); + if (existingProjects.size() > 0) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + String title = "Overwrite"; + String msg = getMessage(destination, existingProjects); + confirm = MessageDialog.openQuestion(getActiveShell(), + title, msg); + } + }); + if (confirm) { + monitor.setTaskName("Deleting ..."); + for (IProject project:existingProjects) { + monitor.setTaskName("Deleting " + project.getName()); + project.delete(false, true, monitor); + } + } else { + return projects; + } + } + boolean deleted = deleteDirectory(destination, monitor); + if (monitor.isCanceled()) { + return projects; + } + if (!deleted) { + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + MessageDialog.openError(getActiveShell(), + "Error", "Cannot delete the '" + destination + "' file."); + } + }); + return projects; + } + } + boolean ok = extractFile(file, destination, monitor); + monitor.setTaskName(""); + if (monitor.isCanceled()) { + return projects; + } + if (!ok) { + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + MessageDialog.openError(getActiveShell(), + "Error", + "Cannot extract the archive."); + } + }); + return projects; + } + + importMavenProjects(destination); + return projects; + } + + private void importMavenProjects(final File destination) { + Job job = new WorkspaceJob("Importing Maven projects") { + public IStatus runInWorkspace(IProgressMonitor monitor) { + setProperty(IProgressConstants.ACTION_PROPERTY, + new OpenMavenConsoleAction()); + try { + AbstractProjectScanner projectScanner = getProjectScanner(destination); + projectScanner.run(monitor); + List mavenProjects = projectScanner + .getProjects(); + List infos = new ArrayList(); + infos.addAll(mavenProjects); + addMavenProjects(infos, mavenProjects); + final List existingProjects = new ArrayList(); + ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration(); + for(MavenProjectInfo info:infos) { + String projectName = getProjectName(info, importConfiguration); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (project != null && project.exists()) { + existingProjects.add(project); + } + } + if (existingProjects.size() > 0) { + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + String message = getWorkspaceMessage(existingProjects); + + confirm = MessageDialog.openConfirm(getActiveShell(), + "Confirmation", message); + } + }); + if (confirm) { + for (IProject project:existingProjects) { + try { + project.refreshLocal(IResource.DEPTH_INFINITE, monitor); + } catch (Exception e) { + // ignore + } + project.delete(true, true, monitor); + } + } else { + return Status.CANCEL_STATUS; + } + } + MavenPlugin.getProjectConfigurationManager().importProjects( + infos, importConfiguration, monitor); + } catch (CoreException ex) { + MavenProjectExamplesActivator.log(ex, "Projects imported with errors"); + return ex.getStatus(); + } catch (InterruptedException e) { + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } + }; + job.setRule(MavenPlugin.getProjectConfigurationManager().getRule()); + job.schedule(); + } + + private List addMavenProjects(List infos, List mavenProjects) { + if (mavenProjects == null || mavenProjects.isEmpty()) { + return mavenProjects; + } + for (MavenProjectInfo projectInfo:mavenProjects) { + Collection projects = projectInfo.getProjects(); + if (projects != null && !projects.isEmpty()) { + for(MavenProjectInfo info:projects) { + infos.add(info); + } + List childProjects = new ArrayList(); + childProjects.addAll(projects); + addMavenProjects(infos, childProjects); + } + } + return mavenProjects; + } + + private AbstractProjectScanner getProjectScanner( + File folder) { + File root = ResourcesPlugin.getWorkspace().getRoot().getLocation() + .toFile(); + MavenModelManager modelManager = MavenPlugin.getMavenModelManager(); + return new LocalProjectScanner(root, folder.getAbsolutePath(), false, + modelManager); + } + + private static Shell getActiveShell() { + return Display.getDefault().getActiveShell(); + } + + public boolean extractFile(File file, File destination, + IProgressMonitor monitor) { + ZipFile zipFile = null; + destination.mkdirs(); + try { + zipFile = new ZipFile(file); + Enumeration entries = zipFile.entries(); + while (entries.hasMoreElements()) { + if (monitor.isCanceled()) { + return false; + } + ZipEntry entry = (ZipEntry) entries.nextElement(); + if (entry.isDirectory()) { + monitor.setTaskName("Extracting " + entry.getName()); + File dir = new File(destination, entry.getName()); + dir.mkdirs(); + continue; + } + monitor.setTaskName("Extracting " + entry.getName()); + File entryFile = new File(destination, entry.getName()); + entryFile.getParentFile().mkdirs(); + InputStream in = null; + OutputStream out = null; + try { + in = zipFile.getInputStream(entry); + out = new FileOutputStream(entryFile); + copy(in, out); + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + // ignore + } + } + if (out != null) { + try { + out.close(); + } catch (Exception e) { + // ignore + } + } + } + } + } catch (IOException e) { + MavenProjectExamplesActivator.log(e); + return false; + } finally { + if (zipFile != null) { + try { + zipFile.close(); + } catch (IOException e) { + // ignore + } + } + } + return true; + } + + public static void copy(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[16 * 1024]; + int len; + while ((len = in.read(buffer)) >= 0) { + out.write(buffer, 0, len); + } + } + + private static boolean deleteDirectory(File path, IProgressMonitor monitor) { + if (path.exists()) { + File[] files = path.listFiles(); + for (File file : files) { + if (monitor.isCanceled()) { + return false; + } + monitor.setTaskName("Deleting " + file); + if (file.isDirectory()) { + deleteDirectory(file, monitor); + } else { + file.delete(); + } + } + } + return (path.delete()); + } + + private String getProjectName(MavenProjectInfo projectInfo, + ProjectImportConfiguration configuration) throws CoreException { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot root = workspace.getRoot(); + + File pomFile = projectInfo.getPomFile(); + Model model = projectInfo.getModel(); + IMaven maven = MavenPlugin.getDefault().getMaven(); + if (model == null) { + model = maven.readModel(pomFile); + projectInfo.setModel(model); + } + + String projectName = configuration.getProjectName(model); + + File projectDir = pomFile.getParentFile(); + String projectParent = projectDir.getParentFile().getAbsolutePath(); + + if (projectInfo.getBasedirRename() == MavenProjectInfo.RENAME_REQUIRED) { + File newProject = new File(projectDir.getParent(), projectName); + if (!projectDir.equals(newProject)) { + projectDir = newProject; + } + } else { + if (projectParent.equals(root.getLocation().toFile() + .getAbsolutePath())) { + projectName = projectDir.getName(); + } + } + return projectName; + } + + private List getExistingProjects(final File destination) { + List existingProjects = new ArrayList(); + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + for (IProject project:projects) { + if (project != null && project.exists()) { + File projectFile = project.getLocation().toFile(); + if (projectFile.getAbsolutePath().startsWith(destination.getAbsolutePath())) { + existingProjects.add(project); + } + } + } + return existingProjects; + } + + private String getMessage(final File destination, List projects) { + if (projects.size() > 0) { + StringBuilder builder = new StringBuilder(); + if (projects.size() == 1) { + builder.append("\nThere is the '" + projects.get(0).getName() + + "' project on the destination location:\n\n"); + builder.append("Would you like to overwrite it?"); + } else { + builder.append("\nThere are the following projects on the destination location:\n\n"); + for (IProject project : projects) { + builder.append(project.getName()); + builder.append("\n"); //$NON-NLS-1$ + } + builder.append("\n"); //$NON-NLS-1$ + builder.append("Would you like to overwrite them?"); + } + return builder.toString(); + } + return null; + } + + private String getWorkspaceMessage( + final List existingProjects) { + StringBuilder builder = new StringBuilder(); + if (existingProjects.size() == 1) { + builder.append("There is the '" + existingProjects.get(0).getName() + + "' project in the workspace.\n\n"); + builder.append("Would you like to delete it?"); + } else { + builder.append("There are the following projects in the workspace:\n\n"); + for (IProject project:existingProjects) { + builder.append(project.getName()); + builder.append("\n"); //$NON-NLS-1$ + } + builder.append("\n"); //$NON-NLS-1$ + builder.append("Would you like to delete them?"); + } + return builder.toString(); + } + +} Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 32782) +++ META-INF/MANIFEST.MF (working copy) @@ -9,7 +9,9 @@ org.eclipse.core.runtime, org.jboss.tools.maven.core, org.jboss.tools.project.examples, - org.eclipse.ui.ide + org.eclipse.ui.ide, + org.eclipse.m2e.archetype.common;bundle-version="[1.0,1.1)", + org.eclipse.m2e.core.ui;bundle-version="[1.0,1.1)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: %Bundle-Vendor Index: plugin.xml =================================================================== --- plugin.xml (revision 32782) +++ plugin.xml (working copy) @@ -1,13 +1,13 @@ - - - - - - - - - + + + + + + + + + #P org.jboss.tools.maven.feature Index: feature.properties =================================================================== --- feature.properties (revision 32782) +++ feature.properties (working copy) @@ -1,53 +1,53 @@ -############################################################################### -# Copyright (c) 2011 Red Hat, Inc. 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: -# JBoss by Red Hat - Initial implementation. -############################################################################## -# feature.properties -# contains externalized strings for feature.xml -# "%foo" in feature.xml corresponds to the key "foo" in this file -# java.io.Properties file (ISO 8859-1 with "\" escapes) -# This file should be translated. - -# "featureName" property - name of the feature -featureName=JBoss Maven Integration - -# "providerName" property - name of the company that provides the feature -providerName=JBoss by Red Hat - -# "updateSiteName" property - label for the update site -updateSiteName=JBossTools Update Site - -# "description" property - description of the feature -description=JBoss Maven Integration - -# "copyright" property - text of the "Feature Update Copyright" -copyright=Copyright (c) 2011 Red Hat, Inc. and others.\n\ -All rights reserved. This program and the accompanying materials\n\ -are made available under the terms of the Eclipse Public License v1.0\n\ -which accompanies this distribution, and is available at\n\ -http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ -JBoss by Red Hat - Initial implementation.\n - ############### end of copyright property #################################### - -# "licenseURL" property - URL of the "Feature License" -# do not translate value - just change to point to a locale-specific HTML page -licenseURL=license.html - -# START NON-TRANSLATABLE -# "license" property - text of the "Feature Update License" -# should be plain text version of license agreement pointed to be "licenseURL" -license=Red Hat, Inc. licenses these features and plugins to you under \ -certain open source licenses (or aggregations of such licenses), which \ -in a particular case may include the Eclipse Public License, the GNU \ -Lesser General Public License, and/or certain other open source \ -licenses. For precise licensing details, consult the corresponding \ -source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ -Raleigh NC 27606 USA. -# END NON-TRANSLATABLE -########### end of license property ########################################## +############################################################################### +# Copyright (c) 2010-2011 Red Hat, Inc. 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: +# JBoss by Red Hat - Initial implementation. +############################################################################## +# feature.properties +# contains externalized strings for feature.xml +# "%foo" in feature.xml corresponds to the key "foo" in this file +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# This file should be translated. + +# "featureName" property - name of the feature +featureName=JBoss Maven Integration + +# "providerName" property - name of the company that provides the feature +providerName=JBoss by Red Hat + +# "updateSiteName" property - label for the update site +updateSiteName=JBossTools Update Site + +# "description" property - description of the feature +description=JBoss Maven Integration + +# "copyright" property - text of the "Feature Update Copyright" +copyright=Copyright (c) 2010-2011 Red Hat, Inc. and others.\n\ +All rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\n\ +which accompanies this distribution, and is available at\n\ +http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ +JBoss by Red Hat - Initial implementation.\n + ############### end of copyright property #################################### + +# "licenseURL" property - URL of the "Feature License" +# do not translate value - just change to point to a locale-specific HTML page +licenseURL=license.html + +# START NON-TRANSLATABLE +# "license" property - text of the "Feature Update License" +# should be plain text version of license agreement pointed to be "licenseURL" +license=Red Hat, Inc. licenses these features and plugins to you under \ +certain open source licenses (or aggregations of such licenses), which \ +in a particular case may include the Eclipse Public License, the GNU \ +Lesser General Public License, and/or certain other open source \ +licenses. For precise licensing details, consult the corresponding \ +source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ +Raleigh NC 27606 USA. +# END NON-TRANSLATABLE +########### end of license property ########################################## Index: feature.xml =================================================================== --- feature.xml (revision 32782) +++ feature.xml (working copy) @@ -2,7 +2,7 @@ @@ -19,8 +19,8 @@ - - + + - 4.0.0 + + + 4.0.0 - org.jboss.tools - org.jboss.tools.parent.pom - 0.0.1-SNAPSHOT + org.jboss.tools.maven + features + 0.0.1-SNAPSHOT org.jboss.tools.maven.features - org.jboss.tools.maven.feature - 1.1.0-SNAPSHOT + org.jboss.tools.maven.feature + 1.2.0-SNAPSHOT eclipse-feature - + \ No newline at end of file