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 2014/04/25 13:25:17 UTC
svn commit: r1589998 - in /sling/trunk/tooling/ide: ./ eclipse-m2e-test/
eclipse-m2e-test/META-INF/ eclipse-m2e-test/src/ eclipse-m2e-test/src/org/
eclipse-m2e-test/src/org/apache/ eclipse-m2e-test/src/org/apache/sling/
eclipse-m2e-test/src/org/apache/...
Author: rombert
Date: Fri Apr 25 11:25:16 2014
New Revision: 1589998
URL: http://svn.apache.org/r1589998
Log:
SLING-3515 - New sling bundle project wizard fails -
java.lang.NoSuchMethodError
Use reflection to access volatile Maven APIs which have changed with the
Maven 3.1.0 release.
Also add an eclipse-m2e-test project to validate that these changes did
not break anything.
Added:
sling/trunk/tooling/ide/eclipse-m2e-test/
sling/trunk/tooling/ide/eclipse-m2e-test/.gitignore
sling/trunk/tooling/ide/eclipse-m2e-test/META-INF/
sling/trunk/tooling/ide/eclipse-m2e-test/META-INF/MANIFEST.MF
sling/trunk/tooling/ide/eclipse-m2e-test/build.properties (with props)
sling/trunk/tooling/ide/eclipse-m2e-test/pom.xml (with props)
sling/trunk/tooling/ide/eclipse-m2e-test/src/
sling/trunk/tooling/ide/eclipse-m2e-test/src/org/
sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/
sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/
sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/
sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/
sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/
sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstallerTest.java (with props)
Modified:
sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstaller.java
sling/trunk/tooling/ide/pom.xml
Added: sling/trunk/tooling/ide/eclipse-m2e-test/.gitignore
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-test/.gitignore?rev=1589998&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-test/.gitignore (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-test/.gitignore Fri Apr 25 11:25:16 2014
@@ -0,0 +1 @@
+/bin/
Added: sling/trunk/tooling/ide/eclipse-m2e-test/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-test/META-INF/MANIFEST.MF?rev=1589998&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-test/META-INF/MANIFEST.MF (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-test/META-INF/MANIFEST.MF Fri Apr 25 11:25:16 2014
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Sling IDE Tools: Eclipse M2Eclipse-based tests
+Bundle-SymbolicName: org.apache.sling.ide.eclipse-m2e-test
+Bundle-Version: 0.0.1.qualifier
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.junit
+Fragment-Host: org.apache.sling.ide.eclipse-m2e-ui
Added: sling/trunk/tooling/ide/eclipse-m2e-test/build.properties
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-test/build.properties?rev=1589998&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-test/build.properties (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-test/build.properties Fri Apr 25 11:25:16 2014
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
Propchange: sling/trunk/tooling/ide/eclipse-m2e-test/build.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/trunk/tooling/ide/eclipse-m2e-test/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-test/pom.xml?rev=1589998&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-test/pom.xml (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-test/pom.xml Fri Apr 25 11:25:16 2014
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling.ide</groupId>
+ <artifactId>reactor</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>org.apache.sling.ide.eclipse-m2e-test</artifactId>
+ <packaging>eclipse-test-plugin</packaging>
+ <name>Sling IDE Tools: Eclipse M2Eclipse-based Tests</name>
+</project>
Propchange: sling/trunk/tooling/ide/eclipse-m2e-test/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-m2e-test/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstallerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstallerTest.java?rev=1589998&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstallerTest.java (added)
+++ sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstallerTest.java Fri Apr 25 11:25:16 2014
@@ -0,0 +1,83 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.sling.ide.artifacts.EmbeddedArtifact;
+import org.apache.sling.ide.artifacts.EmbeddedArtifactLocator;
+import org.apache.sling.ide.eclipse.m2e.internal.Activator;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMaven;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class EmbeddedArchetypeInstallerTest {
+
+ private final String archetypeGroupId = "org.apache.sling";
+ private final String archetypeArtifactId = "sling-bundle-archetype";
+ private final String archetypeVersion = "0.1.0-test-only";
+
+ @Before
+ @After
+ public void deleteInstalledArtifact() throws CoreException, IOException {
+
+ File artifactPathLocation = getInstalledArchetypeLocation();
+
+ File artifactDirLocation = artifactPathLocation.getParentFile();
+
+ FileUtils.deleteDirectory(artifactDirLocation);
+ }
+
+ @Test
+ public void testInstallArchetype() throws IOException, CoreException {
+
+ EmbeddedArtifactLocator artifactsLocator = Activator.getDefault().getArtifactsLocator();
+
+ EmbeddedArchetypeInstaller archetypeInstaller = new EmbeddedArchetypeInstaller(archetypeGroupId,
+ archetypeArtifactId, archetypeVersion);
+
+ EmbeddedArtifact[] archetypeArtifacts = artifactsLocator.loadSlingBundleArchetype();
+
+ archetypeInstaller.addResource("pom", archetypeArtifacts[0].openInputStream());
+ archetypeInstaller.addResource("jar", archetypeArtifacts[1].openInputStream());
+
+ archetypeInstaller.installArchetype();
+
+ File artifactPathLocation = getInstalledArchetypeLocation();
+
+ assertTrue("Archetype was not found at " + artifactPathLocation, artifactPathLocation.exists());
+ }
+
+ private File getInstalledArchetypeLocation() throws CoreException {
+
+ IMaven maven = MavenPlugin.getMaven();
+
+ String artifactPath = maven.getArtifactPath(maven.getLocalRepository(), archetypeGroupId, archetypeArtifactId,
+ archetypeVersion, "jar", null);
+
+ String localRepositoryPath = maven.getLocalRepositoryPath();
+
+ return new File(localRepositoryPath + File.separatorChar + artifactPath);
+ }
+}
Propchange: sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstallerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-m2e-test/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstallerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstaller.java?rev=1589998&r1=1589997&r2=1589998&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstaller.java (original)
+++ sling/trunk/tooling/ide/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/EmbeddedArchetypeInstaller.java Fri Apr 25 11:25:16 2014
@@ -23,9 +23,15 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -53,7 +59,6 @@ import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.embedder.MavenImpl;
-import org.sonatype.aether.RepositorySystemSession;
@SuppressWarnings("restriction")
public class EmbeddedArchetypeInstaller {
@@ -105,11 +110,11 @@ public class EmbeddedArchetypeInstaller
// now create a RepositorySystemSession
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setLocalRepository(maven.getLocalRepository());
- RepositorySystemSession repositorySession = mvn.newRepositorySession(request);
- // set the MavenSession on the LegacySupport
- MavenExecutionResult result = new DefaultMavenExecutionResult();
- MavenSession session = new MavenSession(container, repositorySession, request, result);
+ // We need to support Maven 3.0.x as well, so we use reflection to
+ // access Aether APIs in a manner which is compatible with all Maven 3.x versions
+ // See https://maven.apache.org/docs/3.1.0/release-notes.html
+ MavenSession session = reflectiveCreateMavenSession(container, mvn, request);
LegacySupport legacy = container.lookup(LegacySupport.class);
legacy.setSession(session);
@@ -179,6 +184,68 @@ public class EmbeddedArchetypeInstaller
}
+ private MavenSession reflectiveCreateMavenSession(PlexusContainer container, DefaultMaven mvn, MavenExecutionRequest request)
+ throws IllegalAccessException, InvocationTargetException, InstantiationException {
+
+ Method newRepoSessionMethod = null;
+ for (Method m : mvn.getClass().getMethods()) {
+ if ("newRepositorySession".equals(m.getName())) {
+ newRepoSessionMethod = m;
+ break;
+ }
+ }
+
+ if (newRepoSessionMethod == null) {
+ throw new IllegalArgumentException("No 'newRepositorySession' method found on object " + mvn + " of type "
+ + mvn.getClass().getName());
+ }
+
+ Object repositorySession = newRepoSessionMethod.invoke(mvn, request);
+
+ MavenExecutionResult result = new DefaultMavenExecutionResult();
+
+ Constructor<?> constructor = null;
+
+ outer: for (Constructor<?> c : MavenSession.class.getConstructors()) {
+
+ for (Class<?> klazz : getClasses(repositorySession)) {
+ Class<?>[] check = new Class<?>[] { PlexusContainer.class, klazz, MavenExecutionRequest.class,
+ MavenExecutionResult.class };
+
+ if (Arrays.equals(c.getParameterTypes(), check)) {
+ constructor = c;
+ break outer;
+ }
+ }
+ }
+
+ if (constructor == null) {
+ throw new IllegalArgumentException("Unable to found matching MavenSession constructor");
+ }
+
+ return (MavenSession) constructor.newInstance(container, repositorySession, request, result);
+ }
+
+ private Class<?>[] getClasses(Object repositorySession) {
+
+ List<Class<?>> accu = new ArrayList<Class<?>>();
+ Class<? extends Object> klazz = repositorySession.getClass();
+
+ getClasses(klazz, accu);
+ if (klazz.getSuperclass() != null) {
+ getClasses(klazz.getSuperclass(), accu);
+ }
+
+ return accu.toArray(new Class<?>[accu.size()]);
+ }
+
+ private void getClasses(Class<? extends Object> klazz, List<Class<?>> accu) {
+ accu.add(klazz);
+ for (Class<?> iface : klazz.getInterfaces()) {
+ accu.add(iface);
+ }
+ }
+
// TODO - replace with commons-io
private void copyStream(InputStream in, OutputStream os) throws IOException {
final byte[] bytes = new byte[4*1024];
Modified: sling/trunk/tooling/ide/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/pom.xml?rev=1589998&r1=1589997&r2=1589998&view=diff
==============================================================================
--- sling/trunk/tooling/ide/pom.xml (original)
+++ sling/trunk/tooling/ide/pom.xml Fri Apr 25 11:25:16 2014
@@ -22,6 +22,7 @@
<module>eclipse-ui</module>
<module>feature</module>
<module>eclipse-m2e-ui</module>
+ <module>eclipse-m2e-test</module>
<module>m2e-feature</module>
<module>p2update</module>
</modules>