Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8674C1159F for ; Fri, 25 Apr 2014 11:25:48 +0000 (UTC) Received: (qmail 67648 invoked by uid 500); 25 Apr 2014 11:25:47 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 67538 invoked by uid 500); 25 Apr 2014 11:25:41 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 67519 invoked by uid 99); 25 Apr 2014 11:25:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Apr 2014 11:25:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Apr 2014 11:25:37 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 91E81238890D; Fri, 25 Apr 2014 11:25:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/... Date: Fri, 25 Apr 2014 11:25:17 -0000 To: commits@sling.apache.org From: rombert@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140425112517.91E81238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ + + + 4.0.0 + + org.apache.sling.ide + reactor + 0.0.1-SNAPSHOT + + org.apache.sling.ide.eclipse-m2e-test + eclipse-test-plugin + Sling IDE Tools: Eclipse M2Eclipse-based Tests + 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> accu = new ArrayList>(); + Class 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 klazz, List> 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 @@ eclipse-ui feature eclipse-m2e-ui + eclipse-m2e-test m2e-feature p2update