Commit d35680c8 authored by Caleb James DeLisle's avatar Caleb James DeLisle
Browse files

Merge branch 'master' into XWIKI-7748

parents 88723957 e855f544
......@@ -186,6 +186,11 @@
<artifactId>commons-configuration</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.4</version>
</dependency>
<!-- XML processing -->
<dependency>
......@@ -207,6 +212,20 @@
<classifier>jdk15</classifier>
</dependency>
<!-- Various project are using it to scan the classpath -->
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.7</version>
<exclusions>
<!-- Prevent future conflicts -->
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Everybody logs -->
<dependency>
<groupId>org.slf4j</groupId>
......
......@@ -121,6 +121,7 @@
<exclude>org/xwiki/job/event/status/JobStatus</exclude> <!-- New methods -->
<exclude>org/xwiki/job/AbstractJob</exclude> <!-- Still compatible with extends -->
<exclude>org/xwiki/extension/job/plan/ExtensionPlan</exclude> <!-- Return an extended type -->
<exclude>org/xwiki/extension/version/VersionConstraint</exclude> <!-- New method -->
</excludes>
</configuration>
</plugin>
......
......@@ -92,18 +92,12 @@
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.6</version>
<exclusions>
<!-- Useless for what we use in reflections -->
<exclusion>
<artifactId>dom4j</artifactId>
<groupId>dom4j</groupId>
</exclusion>
<!-- Prevent future conflicts -->
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
......
......@@ -51,7 +51,6 @@
import org.xwiki.extension.repository.InstalledExtensionRepository;
import org.xwiki.extension.repository.LocalExtensionRepository;
import org.xwiki.extension.version.IncompatibleVersionConstraintException;
import org.xwiki.extension.version.Version;
import org.xwiki.extension.version.VersionConstraint;
/**
......@@ -389,26 +388,13 @@ protected void installExtension(ExtensionId extensionId, boolean dependency, Str
parentBranch.add(node);
}
private boolean isCompatible(Version existingVersion, VersionConstraint versionConstraint)
{
boolean compatible = true;
if (versionConstraint.getVersion() == null) {
compatible = versionConstraint.containsVersion(existingVersion);
} else {
compatible = existingVersion.compareTo(versionConstraint.getVersion()) >= 0;
}
return compatible;
}
private boolean checkCoreExtension(ExtensionDependency extensionDependency,
List<ModifableExtensionPlanNode> parentBranch) throws InstallException
{
CoreExtension coreExtension = this.coreExtensionRepository.getCoreExtension(extensionDependency.getId());
if (coreExtension != null) {
if (!isCompatible(coreExtension.getId().getVersion(), extensionDependency.getVersionConstraint())) {
if (!extensionDependency.getVersionConstraint().isCompatible(coreExtension.getId().getVersion())) {
throw new InstallException("Dependency [" + extensionDependency
+ "] is not compatible with core extension [" + coreExtension + "]");
} else {
......@@ -436,7 +422,7 @@ private VersionConstraint checkExistingPlanNode(ExtensionDependency extensionDep
ModifableExtensionPlanNode existingNode = getExtensionNode(extensionDependency.getId(), namespace);
if (existingNode != null) {
if (isCompatible(existingNode.action.getExtension().getId().getVersion(), versionConstraint)) {
if (versionConstraint.isCompatible(existingNode.action.getExtension().getId().getVersion())) {
ModifableExtensionPlanNode node = new ModifableExtensionPlanNode(extensionDependency, existingNode);
addExtensionNode(node);
parentBranch.add(node);
......@@ -467,7 +453,7 @@ private ExtensionDependency checkInstalledExtension(InstalledExtension installed
ExtensionDependency targetDependency = extensionDependency;
if (installedExtension != null) {
if (isCompatible(installedExtension.getId().getVersion(), versionConstraint)) {
if (versionConstraint.isCompatible(installedExtension.getId().getVersion())) {
this.logger.info("There is already an installed extension [{}] covering extension dependency [{}]",
installedExtension, extensionDependency);
......
......@@ -55,11 +55,26 @@ public interface VersionConstraint extends Serializable
/**
* Indicate if the provided {@link Version} satisfies the constraint.
*
* @param version the version to test, null is invalid.
* @return true if the provided version satisfies this constraint, false otherwise.
* @param version the version to test, null is invalid
* @return true if the provided version satisfies this constraint, false otherwise
*/
boolean containsVersion(Version version);
/**
* Indicate of the provided {@link Version} is compatible with this version.
* <p>
* The difference with {@link #containsVersion(Version)} is that this method is trying to determine if this version
* should work with this constraint while {@link #containsVersion(Version)} indicate if that's the ideal version for
* this constraint. This apply with constraint not defining an exact version range but only a recommended version
* constraint, in that case the constraint indicate what is the version that would ideally be required but it should
* work with more recent version.
*
* @param version the version to test, null is invalid
* @return true if the provided version is compatible with this constraint
* @since 4.1M2
*/
boolean isCompatible(Version version);
/**
* Merge too version constraints in one.
*
......
......@@ -41,8 +41,8 @@
/**
* Default implementation of {@link VersionConstraint}.
* <p>
* Mostly based on AETHER implementation which is itself based on Maven specifications. The difference is that it can
* contains a list of ranges OR collection instead of just a OR collection to allow combining several constraints in
* Mostly based on AETHER implementation which is itself based on Maven specifications. The main difference is that it
* can contains a list of ranges OR collection instead of just a OR collection to allow combining several constraints in
* one.
* <p>
* {(,1.0],[2.0,)},{[3.0)}
......@@ -190,7 +190,7 @@ private List<VersionRangeCollection> parseRanges(String rawConstraint) throws In
@Override
public Collection<VersionRangeCollection> getRanges()
{
return (Collection) this.ranges;
return this.ranges;
}
@Override
......@@ -215,6 +215,20 @@ public boolean containsVersion(Version version)
return true;
}
@Override
public boolean isCompatible(Version version)
{
boolean compatible = true;
if (getVersion() == null) {
compatible = containsVersion(version);
} else {
compatible = version.compareTo(getVersion()) >= 0;
}
return compatible;
}
@Override
public VersionConstraint merge(VersionConstraint versionConstraint) throws IncompatibleVersionConstraintException
{
......
......@@ -72,4 +72,18 @@ public void testParse() throws InvalidVersionRangeException
Assert.assertEquals("[1.0", new DefaultVersionConstraint("[1.0").getVersion().getValue());
}
@Test
public void testContainsVersion()
{
Assert.assertTrue(new DefaultVersionConstraint("1.0").containsVersion(new DefaultVersion("1.0")));
Assert.assertFalse(new DefaultVersionConstraint("1.0").containsVersion(new DefaultVersion("2.0")));
}
@Test
public void testIsCompatible()
{
Assert.assertTrue(new DefaultVersionConstraint("1.0").isCompatible(new DefaultVersion("1.0")));
Assert.assertTrue(new DefaultVersionConstraint("1.0").isCompatible(new DefaultVersion("2.0")));
}
}
......@@ -44,7 +44,6 @@
import org.xwiki.extension.repository.aether.internal.plexus.PlexusComponentManager;
/**
*
* @version $Id$
* @since 4.0M1
*/
......@@ -91,6 +90,10 @@ public RepositorySystemSession createRepositorySystemSession()
session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
session.setConfigProperty(ConfigurationProperties.USER_AGENT, this.configuration.getUserAgent());
// Remove all system properties that could disrupt effective pom resolution
session.setSystemProperty("version", null);
session.setSystemProperty("groupId", null);
return session;
}
......
......@@ -28,7 +28,6 @@
import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
......@@ -68,6 +67,10 @@ public class AetherDefaultRepositoryManagerTest extends AbstractComponentTestCas
private ExtensionId bundleExtensionId;
private ExtensionId sextensionId;
private ExtensionId sextensionDependencyId;
private RepositoryUtil repositoryUtil;
@Override
......@@ -92,6 +95,9 @@ public void setUp() throws Exception
this.bundleExtensionId = new ExtensionId("groupid:bundleartifactid", "version");
this.sextensionId = new ExtensionId("sgroupid:sartifactid", "version");
this.sextensionDependencyId = new ExtensionId("sgroupid:sdartifactid", "version");
// lookup
this.repositoryManager = getComponentManager().getInstance(ExtensionRepositoryManager.class);
......@@ -139,6 +145,28 @@ public void testResolve() throws ResolveException, IOException
// Assert.assertEquals("modified description", extension.getSummary());
}
/**
* Make sure any <code>version</code> property coming from system properties will not be resolved instead of the
* actual pom version.
*/
@Test
public void testResolveWithVersionAsSystemProperty() throws ResolveException
{
System.setProperty("version", "systemversion");
System.setProperty("groupId", "systemgroupId");
Extension extension = this.repositoryManager.resolve(this.sextensionId);
Assert.assertNotNull(extension);
Assert.assertEquals(this.sextensionId.getId(), extension.getId().getId());
Assert.assertEquals(this.sextensionId.getVersion(), extension.getId().getVersion());
ExtensionDependency dependency = extension.getDependencies().iterator().next();
Assert.assertEquals(this.sextensionDependencyId.getId(), dependency.getId());
Assert.assertEquals(this.sextensionDependencyId.getVersion().getValue(), dependency.getVersionConstraint()
.getValue());
}
@Test
public void testResolveVersionClassifier() throws ResolveException
{
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<metadata>
<groupId>sgroupid</groupId>
<artifactId>sartifactid</artifactId>
<versioning>
<latest>version</latest>
<release>version</release>
<versions>
<version>version</version>
</versions>
<lastUpdated>20091103142109</lastUpdated>
</versioning>
</metadata>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sgroupid</groupId>
<artifactId>sartifactid</artifactId>
<version>version</version>
<packaging>type</packaging>
<dependencies>
<dependency>
<groupId>${groupId}</groupId>
<artifactId>sdartifactid</artifactId>
<version>${version}</version>
<type>type</type>
</dependency>
</dependencies>
</project>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment