You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2016/03/03 14:30:38 UTC

svn commit: r1733463 - in /sling/trunk/tooling/ide: eclipse-m2e-core/ eclipse-m2e-ui/ eclipse-m2e-ui/META-INF/ eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ target-definition/

Author: rombert
Date: Thu Mar  3 13:30:37 2016
New Revision: 1733463

URL: http://svn.apache.org/viewvc?rev=1733463&view=rev
Log:
SLING-3100 - Provide a m2e project configurator for packaging
"content-package" 

Applied patch from Georg Henzler, with some modifications.

Added:
    sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageLifecycleMapping.java
    sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageProjectConfigurator.java
    sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/MavenProjectUtils.java
Modified:
    sling/trunk/tooling/ide/eclipse-m2e-core/build.properties
    sling/trunk/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF
    sling/trunk/tooling/ide/eclipse-m2e-ui/lifecycle-mapping-metadata.xml
    sling/trunk/tooling/ide/eclipse-m2e-ui/plugin.xml
    sling/trunk/tooling/ide/target-definition/org.apache.sling.ide.target-definition.target

Modified: sling/trunk/tooling/ide/eclipse-m2e-core/build.properties
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-core/build.properties?rev=1733463&r1=1733462&r2=1733463&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-core/build.properties (original)
+++ sling/trunk/tooling/ide/eclipse-m2e-core/build.properties Thu Mar  3 13:30:37 2016
@@ -1,5 +1,6 @@
 output.. = bin/
 bin.includes = META-INF/,\
                .,\
-               OSGI-INF/
+               OSGI-INF/,\
+               lifecycle-mapping-metadata.xml
 source.. = src/

Modified: sling/trunk/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF?rev=1733463&r1=1733462&r2=1733463&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-m2e-ui/META-INF/MANIFEST.MF Thu Mar  3 13:30:37 2016
@@ -8,13 +8,15 @@ Bundle-RequiredExecutionEnvironment: Jav
 Bundle-ClassPath: .
 Require-Bundle: org.eclipse.m2e.core;bundle-version="1.4.0",
  org.eclipse.m2e.archetype.common;bundle-version="1.4.0",
- org.eclipse.m2e.maven.runtime;bundle-version="1.4.0"
+ org.eclipse.m2e.maven.runtime;bundle-version="1.4.0",
+ org.eclipse.jst.j2ee 
 Import-Package: org.apache.commons.httpclient;version="3.1.0",
  org.apache.commons.httpclient.auth;version="3.1.0",
  org.apache.commons.httpclient.methods;version="3.1.0",
  org.apache.commons.httpclient.methods.multipart;version="3.1.0",
  org.apache.commons.httpclient.params;version="3.1.0",
  org.apache.commons.io;version="2.0.1",
+ org.apache.commons.lang,
  org.apache.sling.ide.artifacts,
  org.apache.sling.ide.eclipse.core,
  org.apache.sling.ide.eclipse.core.debug,
@@ -36,6 +38,10 @@ Import-Package: org.apache.commons.httpc
  org.eclipse.jface.resource,
  org.eclipse.jface.viewers,
  org.eclipse.jface.wizard,
+ org.eclipse.jst.common.project.facet.core,
+ org.eclipse.jst.common.project.facet.core.internal,
+ org.eclipse.jst.j2ee.project.facet,
+ org.eclipse.jst.j2ee.web.project.facet,
  org.eclipse.swt,
  org.eclipse.swt.events,
  org.eclipse.swt.layout,
@@ -44,6 +50,7 @@ Import-Package: org.apache.commons.httpc
  org.eclipse.ui.actions,
  org.eclipse.ui.plugin,
  org.eclipse.ui.progress,
+ org.eclipse.wst.common.frameworks.datamodel,
  org.eclipse.wst.common.project.facet.core,
  org.eclipse.wst.server.core,
  org.osgi.framework;version="1.6.0",

Modified: sling/trunk/tooling/ide/eclipse-m2e-ui/lifecycle-mapping-metadata.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-ui/lifecycle-mapping-metadata.xml?rev=1733463&r1=1733462&r2=1733463&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-ui/lifecycle-mapping-metadata.xml (original)
+++ sling/trunk/tooling/ide/eclipse-m2e-ui/lifecycle-mapping-metadata.xml Thu Mar  3 13:30:37 2016
@@ -34,4 +34,46 @@
             </action>
         </pluginExecution>
     </pluginExecutions>
+  
+  <lifecycleMappings>
+    <lifecycleMapping>
+      <packagingType>content-package</packagingType>
+      <lifecycleMappingId>org.apache.sling.ide.eclipse.m2e.contentPackageLifecycleMapping</lifecycleMappingId>
+      <pluginExecutions>
+        <pluginExecution>
+          <pluginExecutionFilter>
+            <groupId>com.day.jcr.vault</groupId>
+            <artifactId>content-package-maven-plugin</artifactId>
+            <versionRange>[0.0.10,2)</versionRange>
+            <goals>
+              <goal>package</goal>
+            </goals>
+          </pluginExecutionFilter>
+          <action>
+            <configurator>
+              <id>org.apache.sling.ide.eclipse.m2e.configurator</id>
+            </configurator>
+          </action>
+        </pluginExecution>
+           
+        <pluginExecution>
+          <pluginExecutionFilter>
+          
+            <groupId>com.day.jcr.vault</groupId>
+            <artifactId>content-package-maven-plugin</artifactId>
+            <versionRange>[0.0.10,2)</versionRange>
+            <goals>
+              <goal>install</goal>
+            </goals>
+          </pluginExecutionFilter>
+          <action>
+           <ignore>
+               <message>content-package-maven-plugin goal "install" is ignored</message>
+           </ignore>
+          </action>
+        </pluginExecution>
+      </pluginExecutions>
+    </lifecycleMapping>
+    
+  </lifecycleMappings>    
 </lifecycleMappingMetadata>
\ No newline at end of file

Modified: sling/trunk/tooling/ide/eclipse-m2e-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-ui/plugin.xml?rev=1733463&r1=1733462&r2=1733463&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-m2e-ui/plugin.xml Thu Mar  3 13:30:37 2016
@@ -44,6 +44,7 @@
     <!-- marker to tell m2e that this plugin contains a lifecycle-mapping-metadata.xml -->
     <extension point="org.eclipse.m2e.core.lifecycleMappingMetadataSource">
     </extension>
+
     <extension
             point="org.eclipse.m2e.core.projectConfigurators">
         <configurator
@@ -52,7 +53,19 @@
                 name="Sling Bundle Configurator"
                 secondaryTo="maven-bundle-plugin">
         </configurator>
+        <configurator 
+                id="org.apache.sling.ide.eclipse.m2e.configurator"
+                class="org.apache.sling.ide.eclipse.m2e.internal.ContentPackageProjectConfigurator"
+                name="Sling Content Package Configurator" />        
     </extension>
+    
+    <extension point="org.eclipse.m2e.core.lifecycleMappings">  
+	    <lifecycleMapping
+	      id="org.apache.sling.ide.eclipse.m2e.contentPackageLifecycleMapping"
+	            class="org.apache.sling.ide.eclipse.m2e.internal.ContentPackageLifecycleMapping"
+	            name="Sling Content Content Package Build Lifecycle Mapping">
+	    </lifecycleMapping>            
+    </extension>         
 	<extension point="org.eclipse.m2e.core.archetypeCatalogs">
 		<remote url="http://repo1.maven.org/maven2/"
 			description="Maven Central"/>

Added: sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageLifecycleMapping.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageLifecycleMapping.java?rev=1733463&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageLifecycleMapping.java (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageLifecycleMapping.java Thu Mar  3 13:30:37 2016
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.m2e.internal;
+
+import org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping;
+
+public class ContentPackageLifecycleMapping extends AbstractCustomizableLifecycleMapping {
+
+    // intentionally left empty
+}

Added: sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageProjectConfigurator.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageProjectConfigurator.java?rev=1733463&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageProjectConfigurator.java (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/ContentPackageProjectConfigurator.java Thu Mar  3 13:30:37 2016
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.m2e.internal;
+
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.apache.sling.ide.eclipse.core.ConfigurationHelper;
+import org.apache.sling.ide.log.Logger;
+import org.eclipse.aether.util.StringUtils;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.common.project.facet.core.JavaFacet;
+import org.eclipse.jst.common.project.facet.core.internal.JavaFacetUtil;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEModuleFacetInstallDataModelProperties;
+import org.eclipse.jst.j2ee.web.project.facet.IWebFacetInstallDataModelProperties;
+import org.eclipse.jst.j2ee.web.project.facet.WebFacetInstallDataModelProvider;
+import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils;
+import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
+import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+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.IFacetedProject.Action;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+/**
+ * m2e project configurator that creates the Eclipse project files (e.g .project) from a pom.xml for 
+ * the maven packaging type "content-package". The configurator is run automatically 
+ * on "Import..." -> "Existing Maven Project" and Right-Click on Project -> "Maven" 
+ * -> "Update Project...". 
+ * 
+ *
+ */
+public class ContentPackageProjectConfigurator extends AbstractProjectConfigurator {
+
+    // Using these maven properties, the to-be-created eclipse project settings can be configured in pom.xml 
+    private static final String M2E_ACTIVE = "sling.ide.m2e.contentpackage.active";
+    private static final String M2E_JAVA_FACET_VERSION = "sling.ide.m2e.contentpackage.javaFacetVersion";
+    private static final String M2E_WEB_FACET_VERSION = "sling.ide.m2e.contentpackage.webFacetVersion";
+
+    @Override
+    public void configure(ProjectConfigurationRequest configRequest, IProgressMonitor progressMonitor) throws CoreException {
+
+        IProject project = configRequest.getProject();
+        MavenProject mavenProject = configRequest.getMavenProject();
+        boolean active = !"false".equalsIgnoreCase(mavenProject.getProperties().getProperty(M2E_ACTIVE));
+        if(!active) {
+            trace("M2E project configurer for packing type content-package was disabled with property {0}", M2E_ACTIVE);
+            return;
+        }
+        
+        String mavenGav = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion();
+       
+        trace("Configuring Maven project {0} with packaging content-package...", mavenGav);
+        
+        // core configuration for sling ide plugin
+        
+        Resource folder = MavenProjectUtils.guessJcrRootFolder(mavenProject);
+        
+        java.nio.file.Path contentSyncPath = mavenProject.getBasedir().toPath().relativize(Paths.get(folder.getDirectory()));
+        
+        String jcrRootPath = contentSyncPath.toString();
+        ConfigurationHelper.convertToContentPackageProject(project, progressMonitor, Path.fromOSString(jcrRootPath));   
+        
+        new WtpProjectConfigurer(mavenProject, project, jcrRootPath).configure(progressMonitor);
+        
+        trace("Done converting .");
+    }
+
+    /**
+     * @see Logger#trace(String, Object...)
+     */
+    private static void trace(String format, Object... arguments) {
+        Activator.getDefault().getPluginLogger().trace(format, arguments);
+    }
+
+    private void addNatures(IProject project, String[] naturesToAdd, IProgressMonitor progressMonitor)
+            throws CoreException {
+        
+        trace("Adding natures {0} to project {1} ", Arrays.toString(naturesToAdd), project);
+
+        IProjectDescription description = project.getDescription();
+        String[] currentNaturesArr = description.getNatureIds();
+        Set<String> naturesSet = new TreeSet<String>();
+        naturesSet.addAll(Arrays.asList(currentNaturesArr));
+        naturesSet.addAll(Arrays.asList(naturesToAdd));
+                
+        description.setNatureIds(naturesSet.toArray(new String[naturesSet.size()]));
+        project.setDescription(description, IResource.KEEP_HISTORY, progressMonitor);
+
+    }
+
+    // Implemented in line with the current m2e-wtp plugin, except that java/web facet version can be configured
+    private class WtpProjectConfigurer {
+
+       private final MavenProject mavenProject;
+       private final IProject project;
+       private final String jcrRootPath;
+       
+       WtpProjectConfigurer(MavenProject mavenProject,
+               IProject project, String jcrRootPath) {
+
+           this.mavenProject = mavenProject;
+           this.project = project;
+           this.jcrRootPath = jcrRootPath;
+       }
+
+
+       void configure(IProgressMonitor progressMonitor) throws CoreException {
+           
+           trace("Configuring content-package with WTP facets/natures");
+           
+           addNatures(project, getDefaultWtpNatures(), progressMonitor);
+           addWtpFacets(progressMonitor);
+       }
+
+       void addWtpFacets( IProgressMonitor progressMonitor) throws CoreException {
+           
+           String javaFacetVersion;
+           if ( !StringUtils.isEmpty(mavenProject.getProperties().getProperty(M2E_JAVA_FACET_VERSION))) {
+               javaFacetVersion = mavenProject.getProperties().getProperty(M2E_JAVA_FACET_VERSION);
+               trace("Configured Java facet version {0} from pom property {1}", javaFacetVersion, M2E_JAVA_FACET_VERSION);
+           } else {
+               javaFacetVersion = JavaFacetUtil.getCompilerLevel(project);
+               trace("Configured Java facet version {0} using JavaFacetUtil", javaFacetVersion);
+           }
+           
+           String webFacetVersion;
+           if ( !StringUtils.isEmpty(mavenProject.getProperties().getProperty(M2E_WEB_FACET_VERSION))) {
+               webFacetVersion = mavenProject.getProperties().getProperty(M2E_WEB_FACET_VERSION);
+               trace("Configured Web facet version {0} from pom property {1}", webFacetVersion, M2E_WEB_FACET_VERSION);
+           } else {
+               webFacetVersion = MavenProjectUtils.guessServletApiVersion(mavenProject);
+               trace("Configured Web facet version {0} from project dependencies", webFacetVersion);
+           }
+
+            // web facets
+            IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, progressMonitor);
+            Set<Action> actions = new LinkedHashSet<Action>();
+            installJavaFacet(actions, project, facetedProject, javaFacetVersion);
+
+            IProjectFacetVersion webFv = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.DYNAMIC_WEB).getVersion(webFacetVersion);
+            IDataModel webModelCfg = getWebModelConfig(jcrRootPath);
+            if (!facetedProject.hasProjectFacet(WebFacetUtils.WEB_FACET)) {
+                removeConflictingFacets(facetedProject, webFv, actions);
+                actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, webFv, webModelCfg));
+            } else {
+                IProjectFacetVersion projectFacetVersion = facetedProject.getProjectFacetVersion(WebFacetUtils.WEB_FACET);
+                if (webFv.getVersionString() != null && !webFv.getVersionString().equals(projectFacetVersion.getVersionString())) {
+                    actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, webFv, webModelCfg));
+                }
+            }
+            
+            if (!actions.isEmpty()) {
+                try {
+                    facetedProject.modify(actions, progressMonitor);
+                } catch (Exception e) {
+                   Activator.getDefault().getPluginLogger().warn("Could not add facets to project: "+e, e);
+                }
+
+            }
+       }
+
+        private IDataModel getWebModelConfig(String warSourceDirectory) {
+            IDataModel webModelCfg = DataModelFactory.createDataModel(new WebFacetInstallDataModelProvider());
+            webModelCfg.setProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER, warSourceDirectory);
+            webModelCfg.setProperty(IWebFacetInstallDataModelProperties.CONTEXT_ROOT, "/");
+            webModelCfg.setProperty(IJ2EEModuleFacetInstallDataModelProperties.GENERATE_DD, false);
+            return webModelCfg;
+        }
+
+        private void installJavaFacet(Set<Action> actions, IProject project, IFacetedProject facetedProject, String javaFacetVersion) {
+            IProjectFacetVersion javaFv = JavaFacet.FACET.getVersion(javaFacetVersion);
+            if (!facetedProject.hasProjectFacet(JavaFacet.FACET)) {
+                actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, javaFv, null));
+            } else if (!facetedProject.hasProjectFacet(javaFv)) {
+                actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, javaFv, null));
+            }
+        }
+
+        /**
+         * Adds uninstall actions of facets from the faceted project that conflict with the given facetVersion.
+         */
+        private void removeConflictingFacets(IFacetedProject project, IProjectFacetVersion facetVersion, Set<Action> actions) {
+            if (project == null) {
+                throw new IllegalArgumentException("project can not be null");
+            }
+            if (facetVersion == null) {
+                throw new IllegalArgumentException("Facet version can not be null");
+            }
+            if (actions == null) {
+                throw new IllegalArgumentException("actions can not be null");
+            }
+            for (IProjectFacetVersion existingFacetVersion : project.getProjectFacets()) {
+                if (facetVersion.conflictsWith(existingFacetVersion)) {
+                    actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.UNINSTALL, existingFacetVersion, null));
+                }
+            }
+        }
+       
+        
+        private String[] getDefaultWtpNatures() {
+           return new String[] {
+               "org.eclipse.wst.jsdt.core.jsNature", 
+               "org.eclipse.wst.common.project.facet.core.nature",
+               "org.eclipse.wst.common.modulecore.ModuleCoreNature",
+               "org.eclipse.jem.workbench.JavaEMFNature"
+            };
+        }
+    }
+}
\ No newline at end of file

Added: sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/MavenProjectUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/MavenProjectUtils.java?rev=1733463&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/MavenProjectUtils.java (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/MavenProjectUtils.java Thu Mar  3 13:30:37 2016
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.m2e.internal;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+
+public class MavenProjectUtils {
+
+    private static final String DEFAULT_SERVLET_API_VERSION = "2.5";
+    private static final Pattern SERVLET_API_VERSION_MATCHER = Pattern.compile("^(\\d\\.\\d)");
+
+    public static Resource guessJcrRootFolder(MavenProject project) {
+        
+        for ( Resource resource : project.getBuild().getResources() ) {
+            if ( resource.getDirectory().endsWith("jcr_root")) {
+                return resource;
+            }
+        }
+        
+        return project.getBuild().getResources().get(0);
+    }
+    
+    public static String guessServletApiVersion(MavenProject project) {
+        
+        for ( Dependency dependency :  project.getDependencies() ) {
+            
+            if ( "servlet-api".equals(dependency.getArtifactId()) || "javax.servlet-api".equals(dependency.getArtifactId())) {
+                Matcher matcher = SERVLET_API_VERSION_MATCHER.matcher(dependency.getVersion());
+                if ( matcher.matches() ) {
+                    return matcher.group(1);
+                }
+            }
+        }
+        
+        return DEFAULT_SERVLET_API_VERSION;
+    }
+    
+    private MavenProjectUtils() {
+        
+    }
+}

Modified: sling/trunk/tooling/ide/target-definition/org.apache.sling.ide.target-definition.target
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/target-definition/org.apache.sling.ide.target-definition.target?rev=1733463&r1=1733462&r2=1733463&view=diff
==============================================================================
--- sling/trunk/tooling/ide/target-definition/org.apache.sling.ide.target-definition.target (original)
+++ sling/trunk/tooling/ide/target-definition/org.apache.sling.ide.target-definition.target Thu Mar  3 13:30:37 2016
@@ -15,23 +15,13 @@
     See the License for the specific language governing permissions
     and limitations under the License.
 -->
-<?pde version="3.8"?><target name="Sling IDE Tools" sequenceNumber="45">
+<?pde version="3.8"?><target name="Sling IDE Tools" sequenceNumber="46">
 <locations>
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.sonatype.tycho.m2e.feature.feature.group" version="0.6.0.201207302152"/>
 <repository location="http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-tycho/0.6.0/N/0.6.0.201207302152/"/>
 </location>
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
-<unit id="org.junit" version="4.11.0.v201303080030"/>
-<unit id="org.hamcrest.core" version="1.3.0.v201303031735"/>
-<unit id="org.apache.commons.io" version="2.0.1.v201105210651"/>
-<unit id="org.apache.commons.httpclient" version="3.1.0.v201012070820"/>
-<unit id="org.json" version="1.0.0.v201011060100"/>
-<unit id="org.apache.commons.collections" version="3.2.0.v2013030210310"/>
-<unit id="org.slf4j.api" version="1.7.2.v20121108-1250"/>
-<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20140114142710/repository/"/>
-</location>
-<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.eclipse.m2e.feature.feature.group" version="1.5.1.20150109-1820"/>
 <unit id="org.eclipse.wst.server_adapters.feature.feature.group" version="3.2.401.v201410241731"/>
 <unit id="org.eclipse.jst.server_ui.feature.feature.group" version="3.4.101.v201410241731"/>
@@ -49,5 +39,16 @@
 <unit id="org.eclipse.swtbot.eclipse.test.junit.feature.group" version="2.3.0.201506081302"/>
 <repository location="http://download.eclipse.org/technology/swtbot/releases/2.3.0/"/>
 </location>
+<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
+<unit id="org.apache.commons.collections" version="3.2.0.v2013030210310"/>
+<unit id="org.slf4j.api" version="1.7.2.v20121108-1250"/>
+<unit id="org.apache.commons.httpclient" version="3.1.0.v201012070820"/>
+<unit id="org.json" version="1.0.0.v201011060100"/>
+<unit id="org.junit" version="4.11.0.v201303080030"/>
+<unit id="org.apache.commons.io" version="2.0.1.v201105210651"/>
+<unit id="org.hamcrest.core" version="1.3.0.v201303031735"/>
+<unit id="org.apache.commons.lang" version="2.6.0.v201205030909"/>
+<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20140114142710/repository/"/>
+</location>
 </locations>
 </target>