Skip to content
Browse files

XWIKI-7163: Resolving of an extension artifact from a remote repository

seems to cause unexpected persistence of its POM information
First attempt but does not seems to be enough
XWIKI-7270: Aether handler return the summary in the description field
  • Loading branch information...
1 parent 3ad0ff3 commit a19aec36f565c5333f352a0b21f1f573a837707e @tmortagne tmortagne committed
View
14 ...pi/src/main/java/org/xwiki/extension/repository/internal/DefaultCoreExtensionScanner.java
@@ -137,7 +137,7 @@
+ mavenModel.getArtifactId(), version), packagingToType(mavenModel.getPackaging()));
coreExtension.setName(mavenModel.getName());
- coreExtension.setDescription(mavenModel.getDescription());
+ coreExtension.setSummary(mavenModel.getDescription());
for (Developer developer : mavenModel.getDevelopers()) {
URL authorURL = null;
if (developer.getUrl() != null) {
@@ -181,11 +181,15 @@
mavenModel, true)));
}
- if (mavenDependency.getGroupId().equals("${project.groupId}")) {
- mavenDependency.setGroupId(groupId);
+ if (mavenDependency.getGroupId().equals("$ mavenDepe }
+ u mavenDepe }
+ ull) {
}
- if (mavenDependency.getVersion() == null) {
- mavenDependency.setVersion(UNKNOWN);
+ ull) {
+ N);
+ sion() == null) {
+ N);
+ } else ision(UNKNOWN);
} else if (mavenDependency.getVersion().equals("${project.version}")
|| mavenDependency.getVersion().equals("${pom.version}")) {
mavenDependency.setVersion(version);
View
9 ...n/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/RepositoryUtil.java
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
-import java.net.URL;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
@@ -144,15 +143,15 @@ public void setup() throws IOException, ComponentLookupException, ExtensionRepos
// maven resource repository
- URL url = getClass().getClassLoader().getResource("repository/maven");
- if (url != null) {
- repositoryManager.addRepository(new ExtensionRepositoryId(MAVENREPOSITORY_ID, "maven", url.toURI()));
+ if (copyResourceFolder(getMavenRepository(), "repository.maven") > 0) {
+ repositoryManager.addRepository(new ExtensionRepositoryId(MAVENREPOSITORY_ID, "maven", getMavenRepository()
+ .toURI()));
}
// generated extensions
this.extensionPackager.generateExtensions();
-
+
// init
this.componentManager.lookup(ExtensionInitializer.class).initialize();
View
2 ...-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/DefaultPackager.java
@@ -69,7 +69,7 @@
/**
* Default implementation of {@link Packager}.
*
- * @version $Id$
+ * @version $Id: cc000a1f673a673bd2ba2dd287f9bd0b7b27d596 $
*/
@Component
@Singleton
View
5 ...her/src/main/java/org/xwiki/extension/repository/aether/internal/AetherExtensionFile.java
@@ -28,6 +28,7 @@
import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.resolution.ArtifactRequest;
import org.sonatype.aether.resolution.ArtifactResolutionException;
@@ -96,7 +97,9 @@ public InputStream openStream() throws IOException
ArtifactResult artifactResult;
try {
- artifactResult = repositorySystem.resolveArtifact(this.repository.getSession(), artifactRequest);
+ RepositorySystemSession session = this.repository.createRepositorySystemSession();
+
+ artifactResult = repositorySystem.resolveArtifact(session, artifactRequest);
} catch (ArtifactResolutionException e) {
throw new IOException("Failed to resolve artifact", e);
}
View
55 ...c/main/java/org/xwiki/extension/repository/aether/internal/AetherExtensionRepository.java
@@ -69,8 +69,6 @@
private PlexusComponentManager plexusComponentManager;
- private RepositorySystemSession session;
-
private RemoteRepository remoteRepository;
private ArtifactDescriptorReader mavenDescriptorReader;
@@ -85,16 +83,18 @@
private ExtensionLicenseManager licenseManager;
- public AetherExtensionRepository(ExtensionRepositoryId repositoryId, RepositorySystemSession session,
- PlexusComponentManager mavenComponentManager, ComponentManager componentManager) throws Exception
+ private AetherExtensionRepositoryFactory repositoryFactory;
+
+ public AetherExtensionRepository(ExtensionRepositoryId repositoryId,
+ AetherExtensionRepositoryFactory repositoryFactory, PlexusComponentManager mavenComponentManager,
+ ComponentManager componentManager) throws Exception
{
super(repositoryId);
+ this.repositoryFactory = repositoryFactory;
this.componentManager = componentManager;
this.plexusComponentManager = mavenComponentManager;
- this.session = session;
-
this.remoteRepository = new RemoteRepository(repositoryId.getId(), "default", repositoryId.getURI().toString());
this.converter = this.componentManager.lookup(ConverterManager.class);
@@ -128,6 +128,11 @@ public AetherExtensionRepository(ExtensionRepositoryId repositoryId, RepositoryS
}
}
+ public RepositorySystemSession createRepositorySystemSession()
+ {
+ return this.repositoryFactory.createRepositorySystemSession();
+ }
+
@Override
public Extension resolve(ExtensionId extensionId) throws ResolveException
{
@@ -145,7 +150,7 @@ public Extension resolve(ExtensionDependency extensionDependency) throws Resolve
}
}
- public Version resolveVersionRange(Artifact artifact) throws ResolveException
+ public Version resolveVersionRange(Artifact artifact, RepositorySystemSession session) throws ResolveException
{
VersionRangeResult rangeResult;
try {
@@ -153,7 +158,7 @@ public Version resolveVersionRange(Artifact artifact) throws ResolveException
rangeRequest.setArtifact(artifact);
rangeRequest.addRepository(this.remoteRepository);
- rangeResult = this.versionRangeResolver.resolveVersionRange(getSession(), rangeRequest);
+ rangeResult = this.versionRangeResolver.resolveVersionRange(session, rangeRequest);
if (rangeResult.getVersions().isEmpty()) {
throw new VersionRangeResolutionException(rangeResult, "No versions available for " + artifact
@@ -168,6 +173,8 @@ public Version resolveVersionRange(Artifact artifact) throws ResolveException
public AetherExtension resolveMaven(ExtensionDependency extensionDependency) throws ResolveException
{
+ RepositorySystemSession session = createRepositorySystemSession();
+
Artifact artifact;
if (extensionDependency instanceof AetherExtensionDependency) {
artifact = ((AetherExtensionDependency) extensionDependency).getAetherDependency().getArtifact();
@@ -177,14 +184,14 @@ public AetherExtension resolveMaven(ExtensionDependency extensionDependency) thr
// Resolve version range
- Version version = resolveVersionRange(artifact);
+ Version version = resolveVersionRange(artifact, session);
artifact = artifact.setVersion(version.toString());
// Get descriptor
Model model;
try {
- model = loadPom(artifact);
+ model = loadPom(artifact, session);
} catch (Exception e) {
throw new ResolveException("Failed to resolve extension [" + extensionDependency + "] descriptor", e);
}
@@ -207,7 +214,7 @@ public AetherExtension resolveMaven(ExtensionDependency extensionDependency) thr
AetherExtension extension = new AetherExtension(artifact, model, this, this.plexusComponentManager);
extension.setName(model.getName());
- extension.setDescription(model.getDescription());
+ extension.setSummary(model.getDescription());
for (Developer developer : model.getDevelopers()) {
URL authorURL = null;
if (developer.getUrl() != null) {
@@ -218,8 +225,8 @@ public AetherExtension resolveMaven(ExtensionDependency extensionDependency) thr
}
}
- extension.addAuthor(new DefaultExtensionAuthor(
- StringUtils.defaultIfBlank(developer.getName(), developer.getId()), authorURL));
+ extension.addAuthor(new DefaultExtensionAuthor(StringUtils.defaultIfBlank(developer.getName(),
+ developer.getId()), authorURL));
}
extension.setWebsite(model.getUrl());
@@ -236,10 +243,13 @@ public AetherExtension resolveMaven(ExtensionDependency extensionDependency) thr
// dependencies
try {
+ ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry();
+
for (org.apache.maven.model.Dependency mavenDependency : model.getDependencies()) {
if (!mavenDependency.isOptional()
&& (mavenDependency.getScope().equals("compile") || mavenDependency.getScope().equals("runtime"))) {
- extension.addDependency(new AetherExtensionDependency(convertToAether(mavenDependency)));
+ extension
+ .addDependency(new AetherExtensionDependency(convertToAether(mavenDependency, stereotypes)));
}
}
} catch (Exception e) {
@@ -249,11 +259,9 @@ public AetherExtension resolveMaven(ExtensionDependency extensionDependency) thr
return extension;
}
- private Dependency convertToAether(org.apache.maven.model.Dependency dependency) throws IllegalArgumentException,
- IllegalAccessException, InvocationTargetException
+ private Dependency convertToAether(org.apache.maven.model.Dependency dependency, ArtifactTypeRegistry stereotypes)
+ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
- ArtifactTypeRegistry stereotypes = getSession().getArtifactTypeRegistry();
-
return (Dependency) convertMethod.invoke(this.mavenDescriptorReader, dependency, stereotypes);
}
@@ -275,8 +283,8 @@ private ExtensionLicense createLicenseByName(String name)
}
- private Model loadPom(Artifact artifact) throws IllegalArgumentException, IllegalAccessException,
- InvocationTargetException
+ private Model loadPom(Artifact artifact, RepositorySystemSession session) throws IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException
{
ArtifactDescriptorRequest artifactDescriptorRequest = new ArtifactDescriptorRequest();
artifactDescriptorRequest.setArtifact(artifact);
@@ -284,15 +292,10 @@ private Model loadPom(Artifact artifact) throws IllegalArgumentException, Illega
ArtifactDescriptorResult artifactDescriptorResult = new ArtifactDescriptorResult(artifactDescriptorRequest);
- return (Model) loadPomMethod.invoke(this.mavenDescriptorReader, getSession(), artifactDescriptorRequest,
+ return (Model) loadPomMethod.invoke(this.mavenDescriptorReader, session, artifactDescriptorRequest,
artifactDescriptorResult);
}
- public RepositorySystemSession getSession()
- {
- return this.session;
- }
-
public RemoteRepository getRemoteRepository()
{
return this.remoteRepository;
View
27 ...java/org/xwiki/extension/repository/aether/internal/AetherExtensionRepositoryFactory.java
@@ -26,8 +26,10 @@
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.repository.LocalRepository;
-import org.sonatype.aether.util.DefaultRepositorySystemSession;
+import org.sonatype.aether.repository.LocalRepositoryManager;
+import org.sonatype.aether.repository.RepositoryPolicy;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.component.phase.Initializable;
@@ -53,7 +55,7 @@
@Inject
private AetherConfiguration aetherConfiguration;
- private DefaultRepositorySystemSession session;
+ private LocalRepositoryManager localRepositoryManager;
@Override
public void initialize() throws InitializationException
@@ -65,20 +67,27 @@ public void initialize() throws InitializationException
throw new InitializationException("Failed to lookup RepositorySystem", e);
}
- this.session = new MavenRepositorySystemSession();
-
LocalRepository localRepo = new LocalRepository(this.aetherConfiguration.getLocalRepository());
- this.session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(localRepo));
- this.session.setIgnoreMissingArtifactDescriptor(false);
- this.session.setIgnoreInvalidArtifactDescriptor(false);
+ this.localRepositoryManager = repositorySystem.newLocalRepositoryManager(localRepo);
+ }
+
+ public RepositorySystemSession createRepositorySystemSession()
+ {
+ MavenRepositorySystemSession session = new MavenRepositorySystemSession();
+
+ session.setLocalRepositoryManager(this.localRepositoryManager);
+ session.setIgnoreMissingArtifactDescriptor(false);
+ session.setIgnoreInvalidArtifactDescriptor(false);
+ session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
+
+ return session;
}
@Override
public ExtensionRepository createRepository(ExtensionRepositoryId repositoryId) throws ExtensionRepositoryException
{
try {
- return new AetherExtensionRepository(repositoryId, this.session, this.plexusComponentManager,
- this.componentManager);
+ return new AetherExtensionRepository(repositoryId, this, this.plexusComponentManager, this.componentManager);
} catch (Exception e) {
throw new ExtensionRepositoryException("Failed to create repository [" + repositoryId + "]", e);
}
View
33 ...va/org/xwiki/extension/repository/aether/internal/AetherDefaultRepositoryManagerTest.java
@@ -19,16 +19,16 @@
*/
package org.xwiki.extension.repository.aether.internal;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import junit.framework.Assert;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
@@ -37,7 +37,6 @@
import org.xwiki.extension.ExtensionDependency;
import org.xwiki.extension.ExtensionException;
import org.xwiki.extension.ExtensionId;
-import org.xwiki.extension.ExtensionLicense;
import org.xwiki.extension.ExtensionLicenseManager;
import org.xwiki.extension.ResolveException;
import org.xwiki.extension.repository.ExtensionRepositoryManager;
@@ -46,6 +45,10 @@
public class AetherDefaultRepositoryManagerTest extends AbstractComponentTestCase
{
+ private static final String GROUPID = "groupid";
+
+ private static final String ARTIfACTID = "artifactid";
+
private ExtensionRepositoryManager repositoryManager;
private ExtensionId extensionId;
@@ -71,8 +74,8 @@ public void setUp() throws Exception
new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
this.repositoryUtil.setup();
- this.extensionId = new ExtensionId("groupid:artifactid", "version");
- this.extensionIdClassifier = new ExtensionId("groupid:artifactid:classifier", "version");
+ this.extensionId = new ExtensionId(GROUPID + ':' + ARTIfACTID, "version");
+ this.extensionIdClassifier = new ExtensionId(GROUPID + ':' + ARTIfACTID + ":classifier", "version");
this.dependencyExtensionId = new DefaultExtensionDependency("dgroupid:dartifactid", "dversion");
this.dependencyExtensionIdRange = new DefaultExtensionDependency("dgroupid:dartifactid", "[dversion,)");
@@ -85,7 +88,7 @@ public void setUp() throws Exception
}
@Test
- public void testResolve() throws ResolveException, MalformedURLException
+ public void testResolve() throws ResolveException, IOException
{
Extension extension = this.repositoryManager.resolve(this.extensionId);
@@ -95,7 +98,7 @@ public void testResolve() throws ResolveException, MalformedURLException
Assert.assertEquals("type", extension.getType());
Assert.assertEquals(this.repositoryUtil.getRemoteRepositoryId(), extension.getRepository().getId().getId());
Assert.assertEquals("name", extension.getName());
- Assert.assertEquals("description", extension.getDescription());
+ Assert.assertEquals("summary", extension.getSummary());
Assert.assertEquals("http://website", extension.getWebSite());
Assert.assertEquals("Full Name", extension.getAuthors().get(0).getName());
Assert.assertEquals(new URL("http://profile"), extension.getAuthors().get(0).getURL());
@@ -111,6 +114,22 @@ public void testResolve() throws ResolveException, MalformedURLException
// check that a new resolve of an already resolved extension provide the proper repository
extension = this.repositoryManager.resolve(this.extensionId);
Assert.assertEquals(this.repositoryUtil.getRemoteRepositoryId(), extension.getRepository().getId().getId());
+
+ /*
+ // TODO: see http://jira.xwiki.org/browse/XWIKI-7163
+ // Modify the file on the descriptor on the repository
+
+ File pomFile =
+ new File(this.repositoryUtil.getMavenRepository(), this.extensionId.getId().replace('.', '/')
+ .replace(':', '/')
+ + '/' + this.extensionId.getVersion() + '/' + ARTIfACTID + '-' + this.extensionId.getVersion() + ".pom");
+
+ FileUtils.writeStringToFile(pomFile, FileUtils.readFileToString(pomFile, "UTF-8").replace("<description>summary</description>", "<description>modified summary</description>"), "UTF-8");
+
+ extension = this.repositoryManager.resolve(this.extensionId);
+
+ Assert.assertEquals("modified description", extension.getSummary());
+ */
}
@Test
View
2 ...rc/test/resources/repository/maven/dgroupid/dartifactid/dversion/dartifactid-dversion.pom
@@ -8,5 +8,5 @@
<version>dversion</version>
<packaging>type</packaging>
<name>dependency name</name>
- <description>dependency description</description>
+ <description>dependency summary</description>
</project>
View
2 ...her/src/test/resources/repository/maven/groupid/artifactid/version/artifactid-version.pom
@@ -8,7 +8,7 @@
<name>name</name>
<version>version</version>
<packaging>type</packaging>
- <description>description</description>
+ <description>summary</description>
<url>http://website</url>
<developers>
<developer>
View
2 .../resources/repository/maven/groupid/bundleartifactid/version/bundleartifactid-version.pom
@@ -8,6 +8,6 @@
<name>name</name>
<version>version</version>
<packaging>bundle</packaging>
- <description>description</description>
+ <description>summary</description>
<url>http://website</url>
</project>

0 comments on commit a19aec3

Please sign in to comment.
Something went wrong with that request. Please try again.